Skip to content

tests/ui: A New Order [24/N] #143299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Sanity check for out-of-bounds read caused by copying the entire original buffer on shrink.
//!
//! Regression test for: <https://github.com/rust-lang/rust/issues/16687>
//@ run-pass
// alloc::heap::reallocate test.
//
// Ideally this would be revised to use no_std, but for now it serves
// well enough to reproduce (and illustrate) the bug from #16687.

#![feature(allocator_api)]
#![feature(slice_ptr_get)]

use std::alloc::{handle_alloc_error, Allocator, Global, Layout};
use std::alloc::{Allocator, Global, Layout, handle_alloc_error};
use std::ptr::{self, NonNull};

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Ensure that auto trait checks `T` when it encounters a `PhantomData<T>` field, instead of
// checking the `PhantomData<T>` type itself (which almost always implements an auto trait).
//! Ensure that auto trait checks `T` when it encounters a `PhantomData<T>` field, instead of
//! checking the `PhantomData<T>` type itself (which almost always implements an auto trait).
#![feature(auto_traits)]

use std::marker::{PhantomData};
use std::marker::PhantomData;

unsafe auto trait Zen {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
error[E0277]: `T` cannot be shared between threads safely
--> $DIR/phantom-auto-trait.rs:21:12
--> $DIR/auto-trait-phantom-data-bounds.rs:21:12
|
LL | is_zen(x)
| ------ ^ `T` cannot be shared between threads safely
| |
| required by a bound introduced by this call
|
note: required for `&T` to implement `Zen`
--> $DIR/phantom-auto-trait.rs:10:24
--> $DIR/auto-trait-phantom-data-bounds.rs:10:24
|
LL | unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {}
| ^^^ ^^^^^ ---- unsatisfied trait bound introduced here
note: required because it appears within the type `PhantomData<&T>`
--> $SRC_DIR/core/src/marker.rs:LL:COL
note: required because it appears within the type `Guard<'_, T>`
--> $DIR/phantom-auto-trait.rs:12:8
--> $DIR/auto-trait-phantom-data-bounds.rs:12:8
|
LL | struct Guard<'a, T: 'a> {
| ^^^^^
note: required by a bound in `is_zen`
--> $DIR/phantom-auto-trait.rs:18:14
--> $DIR/auto-trait-phantom-data-bounds.rs:18:14
|
LL | fn is_zen<T: Zen>(_: T) {}
| ^^^ required by this bound in `is_zen`
Expand All @@ -29,32 +29,32 @@ LL | fn not_sync<T: std::marker::Sync>(x: Guard<T>) {
| +++++++++++++++++++

error[E0277]: `T` cannot be shared between threads safely
--> $DIR/phantom-auto-trait.rs:26:12
--> $DIR/auto-trait-phantom-data-bounds.rs:26:12
|
LL | is_zen(x)
| ------ ^ `T` cannot be shared between threads safely
| |
| required by a bound introduced by this call
|
note: required for `&T` to implement `Zen`
--> $DIR/phantom-auto-trait.rs:10:24
--> $DIR/auto-trait-phantom-data-bounds.rs:10:24
|
LL | unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {}
| ^^^ ^^^^^ ---- unsatisfied trait bound introduced here
note: required because it appears within the type `PhantomData<&T>`
--> $SRC_DIR/core/src/marker.rs:LL:COL
note: required because it appears within the type `Guard<'_, T>`
--> $DIR/phantom-auto-trait.rs:12:8
--> $DIR/auto-trait-phantom-data-bounds.rs:12:8
|
LL | struct Guard<'a, T: 'a> {
| ^^^^^
note: required because it appears within the type `Nested<Guard<'_, T>>`
--> $DIR/phantom-auto-trait.rs:16:8
--> $DIR/auto-trait-phantom-data-bounds.rs:16:8
|
LL | struct Nested<T>(T);
| ^^^^^^
note: required by a bound in `is_zen`
--> $DIR/phantom-auto-trait.rs:18:14
--> $DIR/auto-trait-phantom-data-bounds.rs:18:14
|
LL | fn is_zen<T: Zen>(_: T) {}
| ^^^ required by this bound in `is_zen`
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/binop/binop-evaluation-order-primitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Test evaluation order in binary operations with primitive types.
//@ run-pass

fn main() {
let x = Box::new(0);
assert_eq!(
0,
*x + {
drop(x);
let _ = Box::new(main);
0
}
);
}
24 changes: 24 additions & 0 deletions tests/ui/coercion/basic-ptr-coercions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Tests basic pointer coercions
//@ run-pass

pub fn main() {
// &mut -> &
let x: &mut isize = &mut 42;
let _x: &isize = x;
let _x: &isize = &mut 42;

// & -> *const
let x: &isize = &42;
let _x: *const isize = x;
let _x: *const isize = &42;

// &mut -> *const
let x: &mut isize = &mut 42;
let _x: *const isize = x;
let _x: *const isize = &mut 42;

// *mut -> *const
let _x: *mut isize = &mut 42;
let _x: *const isize = x;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Test coercions between pointers which don't do anything fancy like unsizing.
// These are testing that we don't lose mutability when converting to raw pointers.
//! Tests that pointer coercions preserving mutability are enforced:

//@ dont-require-annotations: NOTE

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/ptr-coercion.rs:9:25
--> $DIR/ptr-mutability-errors.rs:8:25
|
LL | let x: *mut isize = x;
| ---------- ^ types differ in mutability
Expand All @@ -10,7 +10,7 @@ LL | let x: *mut isize = x;
found raw pointer `*const isize`

error[E0308]: mismatched types
--> $DIR/ptr-coercion.rs:15:25
--> $DIR/ptr-mutability-errors.rs:14:25
|
LL | let x: *mut isize = &42;
| ---------- ^^^ types differ in mutability
Expand All @@ -21,7 +21,7 @@ LL | let x: *mut isize = &42;
found reference `&isize`

error[E0308]: mismatched types
--> $DIR/ptr-coercion.rs:21:25
--> $DIR/ptr-mutability-errors.rs:20:25
|
LL | let x: *mut isize = x;
| ---------- ^ types differ in mutability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Test that print!/println! output to stdout and eprint!/eprintln!
//! output to stderr correctly.
//@ run-pass
//@ needs-subprocess

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Test closure parameter type inference and type mismatch errors.
//!
//! Related to <https://github.com/rust-lang/rust/issues/2093>.
//@ dont-require-annotations: NOTE

fn let_in<T, F>(x: T, f: F)
where
F: FnOnce(T),
{
}

fn main() {
let_in(3u32, |i| {
assert!(i == 3i32);
//~^ ERROR mismatched types
//~| NOTE expected `u32`, found `i32`
});

let_in(3i32, |i| {
assert!(i == 3u32);
//~^ ERROR mismatched types
//~| NOTE expected `i32`, found `u32`
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error[E0308]: mismatched types
--> $DIR/closure-parameter-type-inference-mismatch.rs:15:22
|
LL | assert!(i == 3i32);
| - ^^^^ expected `u32`, found `i32`
| |
| expected because this is `u32`
|
help: change the type of the numeric literal from `i32` to `u32`
|
LL - assert!(i == 3i32);
LL + assert!(i == 3u32);
|

error[E0308]: mismatched types
--> $DIR/closure-parameter-type-inference-mismatch.rs:21:22
|
LL | assert!(i == 3u32);
| - ^^^^ expected `i32`, found `u32`
| |
| expected because this is `i32`
|
help: change the type of the numeric literal from `u32` to `i32`
|
LL - assert!(i == 3u32);
LL + assert!(i == 3i32);
|

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
fn unrelated() -> Result<(), std::string::ParseError> { // #57664
//! Regression test for <https://github.com/rust-lang/rust/issues/57664>.
//! Checks that compiler doesn't get confused by `?` operator and complex
//! return types when reporting type mismatches.

fn unrelated() -> Result<(), std::string::ParseError> {
let x = 0;

match x {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/point-to-type-err-cause-on-impl-trait-return-2.rs:9:41
--> $DIR/type-error-diagnostic-in-complex-return.rs:13:41
|
LL | let value: &bool = unsafe { &42 };
| ^^^ expected `&bool`, found `&{integer}`
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/parser/doc-comment-in-generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Tests correct parsing of doc comments on generic parameters in traits.
//! Checks that compiler doesn't panic when processing this.
//@ check-pass

#![crate_type = "lib"]

pub trait Layer<
/// Documentation for generic parameter.
Input,
>
{
}
Binary file added tests/ui/parser/raw/raw-string-literals.rs
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Tests how we behave when the user attempts to mutate an immutable
//! binding that was introduced by either `ref` or `ref mut`
//! patterns.
//!
//! Such bindings cannot be made mutable via the mere addition of the
//! `mut` keyword, and thus we want to check that the compiler does not
//! suggest doing so.
fn main() {
let (mut one_two, mut three_four) = ((1, 2), (3, 4));

// Bind via pattern:
// - `a` as immutable reference (`ref`)
// - `b` as mutable reference (`ref mut`)
let &mut (ref a, ref mut b) = &mut one_two;

// Attempt to reassign immutable `ref`-bound variable
a = &three_four.0;
//~^ ERROR cannot assign twice to immutable variable `a`

// Attempt to reassign mutable `ref mut`-bound variable
b = &mut three_four.1;
//~^ ERROR cannot assign twice to immutable variable `b`
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/reassign-ref-mut.rs:12:5
--> $DIR/pattern-ref-bindings-reassignment.rs:18:5
|
LL | let &mut (ref a, ref mut b) = &mut one_two;
| ----- first assignment to `a`
...
LL | a = &three_four.0;
| ^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable

error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/reassign-ref-mut.rs:14:5
--> $DIR/pattern-ref-bindings-reassignment.rs:22:5
|
LL | let &mut (ref a, ref mut b) = &mut one_two;
| --------- first assignment to `b`
Expand Down
13 changes: 0 additions & 13 deletions tests/ui/pptypedef.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/ui/pptypedef.stderr

This file was deleted.

6 changes: 0 additions & 6 deletions tests/ui/primitive-binop-lhs-mut.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/ui/print-calling-conventions.rs

This file was deleted.

4 changes: 4 additions & 0 deletions tests/ui/print-request/print-calling-conventions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Test that `--print calling-conventions` outputs all supported calling conventions.
//@ compile-flags: --print calling-conventions
//@ build-pass
Loading
Loading