diff options
Diffstat (limited to 'tests')
407 files changed, 8925 insertions, 1938 deletions
diff --git a/tests/assembly/asm-comments.rs b/tests/assembly/asm-comments.rs new file mode 100644 index 00000000000..557009975dd --- /dev/null +++ b/tests/assembly/asm-comments.rs @@ -0,0 +1,12 @@ +//@ assembly-output: emit-asm +//@ only-x86_64 +// Check that comments in assembly get passed + +#![crate_type = "lib"] + +// CHECK-LABEL: test_comments: +#[no_mangle] +pub fn test_comments() { + // CHECK: example comment + unsafe { core::arch::asm!("nop // example comment") }; +} diff --git a/tests/coverage-run-rustdoc/doctest.coverage b/tests/coverage-run-rustdoc/doctest.coverage index 1bbf364759b..396811c5487 100644 --- a/tests/coverage-run-rustdoc/doctest.coverage +++ b/tests/coverage-run-rustdoc/doctest.coverage @@ -34,10 +34,10 @@ $DIR/doctest.rs: LL| |//! LL| |//! doctest returning a result: LL| 1|//! ``` - LL| 1|//! #[derive(Debug, PartialEq)] - LL| 1|//! struct SomeError { - LL| 1|//! msg: String, - LL| 1|//! } + LL| |//! #[derive(Debug, PartialEq)] + LL| |//! struct SomeError { + LL| |//! msg: String, + LL| |//! } LL| 1|//! let mut res = Err(SomeError { msg: String::from("a message") }); LL| 1|//! if res.is_ok() { LL| 0|//! res?; diff --git a/tests/coverage/async.cov-map b/tests/coverage/async.cov-map index 7d16372375a..9e5a4bdc60f 100644 --- a/tests/coverage/async.cov-map +++ b/tests/coverage/async.cov-map @@ -167,15 +167,16 @@ Number of file 0 mappings: 14 = ((c6 + c7) + c8) Function name: async::j -Raw bytes (53): 0x[01, 01, 02, 07, 0d, 05, 09, 09, 01, 35, 01, 13, 0c, 05, 14, 09, 00, 0a, 01, 00, 0e, 00, 1b, 05, 00, 1f, 00, 27, 09, 01, 09, 00, 0a, 11, 00, 0e, 00, 1a, 09, 00, 1e, 00, 20, 0d, 01, 0e, 00, 10, 03, 02, 01, 00, 02] +Raw bytes (58): 0x[01, 01, 02, 07, 0d, 05, 09, 0a, 01, 35, 01, 00, 0d, 01, 0b, 0b, 00, 0c, 05, 01, 09, 00, 0a, 01, 00, 0e, 00, 1b, 05, 00, 1f, 00, 27, 09, 01, 09, 00, 0a, 11, 00, 0e, 00, 1a, 09, 00, 1e, 00, 20, 0d, 01, 0e, 00, 10, 03, 02, 01, 00, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 2 - expression 0 operands: lhs = Expression(1, Add), rhs = Counter(3) - expression 1 operands: lhs = Counter(1), rhs = Counter(2) -Number of file 0 mappings: 9 -- Code(Counter(0)) at (prev + 53, 1) to (start + 19, 12) -- Code(Counter(1)) at (prev + 20, 9) to (start + 0, 10) +Number of file 0 mappings: 10 +- Code(Counter(0)) at (prev + 53, 1) to (start + 0, 13) +- Code(Counter(0)) at (prev + 11, 11) to (start + 0, 12) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 0, 14) to (start + 0, 27) - Code(Counter(1)) at (prev + 0, 31) to (start + 0, 39) - Code(Counter(2)) at (prev + 1, 9) to (start + 0, 10) @@ -186,7 +187,7 @@ Number of file 0 mappings: 9 = ((c1 + c2) + c3) Function name: async::j::c -Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 37, 05, 01, 12, 05, 02, 0d, 00, 0e, 02, 0a, 0d, 00, 0e, 01, 02, 05, 00, 06] +Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 37, 05, 01, 12, 05, 02, 0d, 00, 0e, 02, 02, 0d, 00, 0e, 01, 02, 05, 00, 06] Number of files: 1 - file 0 => global file 1 Number of expressions: 1 @@ -194,40 +195,40 @@ Number of expressions: 1 Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 55, 5) to (start + 1, 18) - Code(Counter(1)) at (prev + 2, 13) to (start + 0, 14) -- Code(Expression(0, Sub)) at (prev + 10, 13) to (start + 0, 14) +- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 14) = (c0 - c1) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 6) Function name: async::j::d -Raw bytes (9): 0x[01, 01, 00, 01, 01, 46, 05, 00, 17] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 3e, 05, 00, 17] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 70, 5) to (start + 0, 23) +- Code(Counter(0)) at (prev + 62, 5) to (start + 0, 23) Function name: async::j::f -Raw bytes (9): 0x[01, 01, 00, 01, 01, 47, 05, 00, 17] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 3f, 05, 00, 17] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 71, 5) to (start + 0, 23) +- Code(Counter(0)) at (prev + 63, 5) to (start + 0, 23) Function name: async::k (unused) -Raw bytes (29): 0x[01, 01, 00, 05, 00, 4f, 01, 01, 0c, 00, 02, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02] +Raw bytes (29): 0x[01, 01, 00, 05, 00, 47, 01, 01, 0c, 00, 02, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 5 -- Code(Zero) at (prev + 79, 1) to (start + 1, 12) +- Code(Zero) at (prev + 71, 1) to (start + 1, 12) - Code(Zero) at (prev + 2, 14) to (start + 0, 16) - Code(Zero) at (prev + 1, 14) to (start + 0, 16) - Code(Zero) at (prev + 1, 14) to (start + 0, 16) - Code(Zero) at (prev + 2, 1) to (start + 0, 2) Function name: async::l -Raw bytes (37): 0x[01, 01, 04, 01, 07, 05, 09, 0f, 02, 09, 05, 05, 01, 57, 01, 01, 0c, 02, 02, 0e, 00, 10, 05, 01, 0e, 00, 10, 09, 01, 0e, 00, 10, 0b, 02, 01, 00, 02] +Raw bytes (37): 0x[01, 01, 04, 01, 07, 05, 09, 0f, 02, 09, 05, 05, 01, 4f, 01, 01, 0c, 02, 02, 0e, 00, 10, 05, 01, 0e, 00, 10, 09, 01, 0e, 00, 10, 0b, 02, 01, 00, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 4 @@ -236,7 +237,7 @@ Number of expressions: 4 - expression 2 operands: lhs = Expression(3, Add), rhs = Expression(0, Sub) - expression 3 operands: lhs = Counter(2), rhs = Counter(1) Number of file 0 mappings: 5 -- Code(Counter(0)) at (prev + 87, 1) to (start + 1, 12) +- Code(Counter(0)) at (prev + 79, 1) to (start + 1, 12) - Code(Expression(0, Sub)) at (prev + 2, 14) to (start + 0, 16) = (c0 - (c1 + c2)) - Code(Counter(1)) at (prev + 1, 14) to (start + 0, 16) @@ -245,26 +246,26 @@ Number of file 0 mappings: 5 = ((c2 + c1) + (c0 - (c1 + c2))) Function name: async::m -Raw bytes (9): 0x[01, 01, 00, 01, 01, 5f, 01, 00, 19] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 57, 01, 00, 19] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 95, 1) to (start + 0, 25) +- Code(Counter(0)) at (prev + 87, 1) to (start + 0, 25) Function name: async::m::{closure#0} (unused) -Raw bytes (9): 0x[01, 01, 00, 01, 00, 5f, 19, 00, 22] +Raw bytes (9): 0x[01, 01, 00, 01, 00, 57, 19, 00, 22] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 1 -- Code(Zero) at (prev + 95, 25) to (start + 0, 34) +- Code(Zero) at (prev + 87, 25) to (start + 0, 34) Function name: async::main -Raw bytes (9): 0x[01, 01, 00, 01, 01, 61, 01, 08, 02] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 59, 01, 08, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 97, 1) to (start + 8, 2) +- Code(Counter(0)) at (prev + 89, 1) to (start + 8, 2) diff --git a/tests/coverage/async.coverage b/tests/coverage/async.coverage index e943911d310..f5473829b02 100644 --- a/tests/coverage/async.coverage +++ b/tests/coverage/async.coverage @@ -53,25 +53,15 @@ LL| 1|} LL| | LL| 1|fn j(x: u8) { - LL| 1| // non-async versions of `c()`, `d()`, and `f()` to make it similar to async `i()`. + LL| | // non-async versions of `c()`, `d()`, and `f()` to make it similar to async `i()`. LL| 1| fn c(x: u8) -> u8 { LL| 1| if x == 8 { - LL| 1| 1 // This line appears covered, but the 1-character expression span covering the `1` - ^0 - LL| 1| // is not executed. (`llvm-cov show` displays a `^0` below the `1` ). This is because - LL| 1| // `fn j()` executes the open brace for the function body, followed by the function's - LL| 1| // first executable statement, `match x`. Inner function declarations are not - LL| 1| // "visible" to the MIR for `j()`, so the code region counts all lines between the - LL| 1| // open brace and the first statement as executed, which is, in a sense, true. - LL| 1| // `llvm-cov show` overcomes this kind of situation by showing the actual counts - LL| 1| // of the enclosed coverages, (that is, the `1` expression was not executed, and - LL| 1| // accurately displays a `0`). - LL| 1| } else { + LL| 0| 1 + LL| | } else { LL| 1| 0 - LL| 1| } + LL| | } LL| 1| } - LL| 1| fn d() -> u8 { 1 } // inner function is defined in-line, but the function is not executed - ^0 + LL| 0| fn d() -> u8 { 1 } // inner function is defined in-line, but the function is not executed LL| 1| fn f() -> u8 { 1 } LL| 1| match x { LL| 1| y if c(x) == y + 1 => { d(); } diff --git a/tests/coverage/async.rs b/tests/coverage/async.rs index 5018ade0125..7e6ad761ecd 100644 --- a/tests/coverage/async.rs +++ b/tests/coverage/async.rs @@ -54,15 +54,7 @@ fn j(x: u8) { // non-async versions of `c()`, `d()`, and `f()` to make it similar to async `i()`. fn c(x: u8) -> u8 { if x == 8 { - 1 // This line appears covered, but the 1-character expression span covering the `1` - // is not executed. (`llvm-cov show` displays a `^0` below the `1` ). This is because - // `fn j()` executes the open brace for the function body, followed by the function's - // first executable statement, `match x`. Inner function declarations are not - // "visible" to the MIR for `j()`, so the code region counts all lines between the - // open brace and the first statement as executed, which is, in a sense, true. - // `llvm-cov show` overcomes this kind of situation by showing the actual counts - // of the enclosed coverages, (that is, the `1` expression was not executed, and - // accurately displays a `0`). + 1 } else { 0 } diff --git a/tests/coverage/attr/nested.cov-map b/tests/coverage/attr/nested.cov-map index 0f2d5542f75..466aec8956e 100644 --- a/tests/coverage/attr/nested.cov-map +++ b/tests/coverage/attr/nested.cov-map @@ -1,18 +1,18 @@ Function name: nested::closure_expr -Raw bytes (14): 0x[01, 01, 00, 02, 01, 44, 01, 01, 0f, 01, 0b, 05, 01, 02] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 3f, 01, 01, 0f, 01, 0b, 05, 01, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 2 -- Code(Counter(0)) at (prev + 68, 1) to (start + 1, 15) +- Code(Counter(0)) at (prev + 63, 1) to (start + 1, 15) - Code(Counter(0)) at (prev + 11, 5) to (start + 1, 2) Function name: nested::closure_tail -Raw bytes (14): 0x[01, 01, 00, 02, 01, 53, 01, 01, 0f, 01, 11, 05, 01, 02] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 4e, 01, 01, 0f, 01, 11, 05, 01, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 2 -- Code(Counter(0)) at (prev + 83, 1) to (start + 1, 15) +- Code(Counter(0)) at (prev + 78, 1) to (start + 1, 15) - Code(Counter(0)) at (prev + 17, 5) to (start + 1, 2) diff --git a/tests/coverage/attr/nested.coverage b/tests/coverage/attr/nested.coverage index bdd117b7dfa..2d64fe698ea 100644 --- a/tests/coverage/attr/nested.coverage +++ b/tests/coverage/attr/nested.coverage @@ -4,11 +4,6 @@ LL| |// Demonstrates the interaction between #[coverage(off)] and various kinds of LL| |// nested function. LL| | - LL| |// FIXME(#126625): Coverage attributes should apply recursively to nested functions. - LL| |// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`, - LL| |// its lines can still be marked with misleading execution counts from its enclosing - LL| |// function. - LL| | LL| |#[coverage(off)] LL| |fn do_stuff() {} LL| | diff --git a/tests/coverage/attr/nested.rs b/tests/coverage/attr/nested.rs index c7ff835f44f..8213e29b6fc 100644 --- a/tests/coverage/attr/nested.rs +++ b/tests/coverage/attr/nested.rs @@ -4,11 +4,6 @@ // Demonstrates the interaction between #[coverage(off)] and various kinds of // nested function. -// FIXME(#126625): Coverage attributes should apply recursively to nested functions. -// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`, -// its lines can still be marked with misleading execution counts from its enclosing -// function. - #[coverage(off)] fn do_stuff() {} diff --git a/tests/coverage/attr/off-on-sandwich.cov-map b/tests/coverage/attr/off-on-sandwich.cov-map index ed77d7d17e6..d5fbac6ebf7 100644 --- a/tests/coverage/attr/off-on-sandwich.cov-map +++ b/tests/coverage/attr/off-on-sandwich.cov-map @@ -1,24 +1,27 @@ Function name: off_on_sandwich::dense_a::dense_b -Raw bytes (9): 0x[01, 01, 00, 01, 01, 14, 05, 07, 06] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 0f, 05, 02, 12, 01, 07, 05, 00, 06] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 20, 5) to (start + 7, 6) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 15, 5) to (start + 2, 18) +- Code(Counter(0)) at (prev + 7, 5) to (start + 0, 6) Function name: off_on_sandwich::sparse_a::sparse_b::sparse_c -Raw bytes (9): 0x[01, 01, 00, 01, 01, 26, 09, 0b, 0a] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 21, 09, 02, 17, 01, 0b, 09, 00, 0a] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 38, 9) to (start + 11, 10) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 33, 9) to (start + 2, 23) +- Code(Counter(0)) at (prev + 11, 9) to (start + 0, 10) Function name: off_on_sandwich::sparse_a::sparse_b::sparse_c::sparse_d -Raw bytes (9): 0x[01, 01, 00, 01, 01, 29, 0d, 07, 0e] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 24, 0d, 02, 1b, 01, 07, 0d, 00, 0e] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 41, 13) to (start + 7, 14) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 36, 13) to (start + 2, 27) +- Code(Counter(0)) at (prev + 7, 13) to (start + 0, 14) diff --git a/tests/coverage/attr/off-on-sandwich.coverage b/tests/coverage/attr/off-on-sandwich.coverage index 58c128b8342..675697906ee 100644 --- a/tests/coverage/attr/off-on-sandwich.coverage +++ b/tests/coverage/attr/off-on-sandwich.coverage @@ -4,11 +4,6 @@ LL| |// Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]` LL| |// in nested functions. LL| | - LL| |// FIXME(#126625): Coverage attributes should apply recursively to nested functions. - LL| |// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`, - LL| |// its lines can still be marked with misleading execution counts from its enclosing - LL| |// function. - LL| | LL| |#[coverage(off)] LL| |fn do_stuff() {} LL| | @@ -20,10 +15,10 @@ LL| 2| fn dense_b() { LL| 2| dense_c(); LL| 2| dense_c(); - LL| 2| #[coverage(off)] - LL| 2| fn dense_c() { - LL| 2| do_stuff(); - LL| 2| } + LL| | #[coverage(off)] + LL| | fn dense_c() { + LL| | do_stuff(); + LL| | } LL| 2| } LL| |} LL| | @@ -41,10 +36,10 @@ LL| 8| fn sparse_d() { LL| 8| sparse_e(); LL| 8| sparse_e(); - LL| 8| #[coverage(off)] - LL| 8| fn sparse_e() { - LL| 8| do_stuff(); - LL| 8| } + LL| | #[coverage(off)] + LL| | fn sparse_e() { + LL| | do_stuff(); + LL| | } LL| 8| } LL| 4| } LL| | } diff --git a/tests/coverage/attr/off-on-sandwich.rs b/tests/coverage/attr/off-on-sandwich.rs index 6b21b180223..261634e0029 100644 --- a/tests/coverage/attr/off-on-sandwich.rs +++ b/tests/coverage/attr/off-on-sandwich.rs @@ -4,11 +4,6 @@ // Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]` // in nested functions. -// FIXME(#126625): Coverage attributes should apply recursively to nested functions. -// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`, -// its lines can still be marked with misleading execution counts from its enclosing -// function. - #[coverage(off)] fn do_stuff() {} diff --git a/tests/coverage/closure_macro.cov-map b/tests/coverage/closure_macro.cov-map index 156947f4e21..eb5f94d1080 100644 --- a/tests/coverage/closure_macro.cov-map +++ b/tests/coverage/closure_macro.cov-map @@ -7,15 +7,16 @@ Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 29, 1) to (start + 2, 2) Function name: closure_macro::main -Raw bytes (31): 0x[01, 01, 01, 01, 05, 05, 01, 21, 01, 01, 21, 02, 02, 09, 00, 0f, 05, 00, 54, 00, 55, 02, 02, 09, 02, 0b, 01, 03, 01, 00, 02] +Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 21, 01, 01, 21, 02, 02, 09, 00, 0f, 01, 00, 12, 00, 54, 05, 00, 54, 00, 55, 02, 02, 09, 02, 0b, 01, 03, 01, 00, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 5 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 33, 1) to (start + 1, 33) - Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 15) = (c0 - c1) +- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 84) - Code(Counter(1)) at (prev + 0, 84) to (start + 0, 85) - Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 2, 11) = (c0 - c1) diff --git a/tests/coverage/closure_macro_async.cov-map b/tests/coverage/closure_macro_async.cov-map index 0f2b4e01748..1286d663bd4 100644 --- a/tests/coverage/closure_macro_async.cov-map +++ b/tests/coverage/closure_macro_async.cov-map @@ -15,15 +15,16 @@ Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 35, 1) to (start + 0, 43) Function name: closure_macro_async::test::{closure#0} -Raw bytes (31): 0x[01, 01, 01, 01, 05, 05, 01, 23, 2b, 01, 21, 02, 02, 09, 00, 0f, 05, 00, 54, 00, 55, 02, 02, 09, 02, 0b, 01, 03, 01, 00, 02] +Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 23, 2b, 01, 21, 02, 02, 09, 00, 0f, 01, 00, 12, 00, 54, 05, 00, 54, 00, 55, 02, 02, 09, 02, 0b, 01, 03, 01, 00, 02] Number of files: 1 - file 0 => global file 1 Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 5 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 35, 43) to (start + 1, 33) - Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 15) = (c0 - c1) +- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 84) - Code(Counter(1)) at (prev + 0, 84) to (start + 0, 85) - Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 2, 11) = (c0 - c1) diff --git a/tests/coverage/holes.cov-map b/tests/coverage/holes.cov-map new file mode 100644 index 00000000000..9350bd9a405 --- /dev/null +++ b/tests/coverage/holes.cov-map @@ -0,0 +1,47 @@ +Function name: <holes::main::MyStruct>::_method (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 00, 25, 09, 00, 1d] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Zero) at (prev + 37, 9) to (start + 0, 29) + +Function name: holes::main +Raw bytes (44): 0x[01, 01, 00, 08, 01, 08, 01, 06, 11, 01, 0f, 05, 00, 12, 01, 04, 05, 00, 12, 01, 07, 05, 00, 12, 01, 06, 05, 00, 12, 01, 06, 05, 03, 0f, 01, 0a, 05, 03, 0f, 01, 0a, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 8 +- Code(Counter(0)) at (prev + 8, 1) to (start + 6, 17) +- Code(Counter(0)) at (prev + 15, 5) to (start + 0, 18) +- Code(Counter(0)) at (prev + 4, 5) to (start + 0, 18) +- Code(Counter(0)) at (prev + 7, 5) to (start + 0, 18) +- Code(Counter(0)) at (prev + 6, 5) to (start + 0, 18) +- Code(Counter(0)) at (prev + 6, 5) to (start + 3, 15) +- Code(Counter(0)) at (prev + 10, 5) to (start + 3, 15) +- Code(Counter(0)) at (prev + 10, 5) to (start + 1, 2) + +Function name: holes::main::_unused_fn (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 00, 19, 05, 00, 17] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Zero) at (prev + 25, 5) to (start + 0, 23) + +Function name: holes::main::{closure#0} (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 00, 12, 09, 02, 0a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Zero) at (prev + 18, 9) to (start + 2, 10) + +Function name: holes::main::{closure#1} (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 00, 3d, 09, 02, 0a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Zero) at (prev + 61, 9) to (start + 2, 10) + diff --git a/tests/coverage/holes.coverage b/tests/coverage/holes.coverage new file mode 100644 index 00000000000..6e65435f7e3 --- /dev/null +++ b/tests/coverage/holes.coverage @@ -0,0 +1,68 @@ + LL| |//@ edition: 2021 + LL| | + LL| |// Nested items/closures should be treated as "holes", so that their spans are + LL| |// not displayed as executable code in the enclosing function. + LL| | + LL| |use core::hint::black_box; + LL| | + LL| 1|fn main() { + LL| 1| black_box(()); + LL| 1| + LL| 1| // Splitting this across multiple lines makes it easier to see where the + LL| 1| // coverage mapping regions begin and end. + LL| 1| #[rustfmt::skip] + LL| 1| let _closure = + LL| | | + LL| | _arg: (), + LL| | | + LL| 0| { + LL| 0| black_box(()); + LL| 0| } + LL| | ; + LL| | + LL| 1| black_box(()); + LL| | + LL| 0| fn _unused_fn() {} + LL| | + LL| 1| black_box(()); + LL| | + LL| | struct MyStruct { + LL| | _x: u32, + LL| | _y: u32, + LL| | } + LL| | + LL| 1| black_box(()); + LL| | + LL| | impl MyStruct { + LL| 0| fn _method(&self) {} + LL| | } + LL| | + LL| 1| black_box(()); + LL| | + LL| | macro_rules! _my_macro { + LL| | () => {}; + LL| | } + LL| | + LL| 1| black_box(()); + LL| 1| + LL| 1| #[rustfmt::skip] + LL| 1| let _const = + LL| | const + LL| | { + LL| | 7 + 4 + LL| | } + LL| | ; + LL| | + LL| 1| black_box(()); + LL| 1| + LL| 1| #[rustfmt::skip] + LL| 1| let _async = + LL| | async + LL| 0| { + LL| 0| 7 + 4 + LL| 0| } + LL| | ; + LL| | + LL| 1| black_box(()); + LL| 1|} + diff --git a/tests/coverage/holes.rs b/tests/coverage/holes.rs new file mode 100644 index 00000000000..b3a71e759c8 --- /dev/null +++ b/tests/coverage/holes.rs @@ -0,0 +1,67 @@ +//@ edition: 2021 + +// Nested items/closures should be treated as "holes", so that their spans are +// not displayed as executable code in the enclosing function. + +use core::hint::black_box; + +fn main() { + black_box(()); + + // Splitting this across multiple lines makes it easier to see where the + // coverage mapping regions begin and end. + #[rustfmt::skip] + let _closure = + | + _arg: (), + | + { + black_box(()); + } + ; + + black_box(()); + + fn _unused_fn() {} + + black_box(()); + + struct MyStruct { + _x: u32, + _y: u32, + } + + black_box(()); + + impl MyStruct { + fn _method(&self) {} + } + + black_box(()); + + macro_rules! _my_macro { + () => {}; + } + + black_box(()); + + #[rustfmt::skip] + let _const = + const + { + 7 + 4 + } + ; + + black_box(()); + + #[rustfmt::skip] + let _async = + async + { + 7 + 4 + } + ; + + black_box(()); +} diff --git a/tests/coverage/no_cov_crate.cov-map b/tests/coverage/no_cov_crate.cov-map index 281efb6d00d..75234f6c3b7 100644 --- a/tests/coverage/no_cov_crate.cov-map +++ b/tests/coverage/no_cov_crate.cov-map @@ -31,20 +31,22 @@ Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 77, 1) to (start + 11, 2) Function name: no_cov_crate::nested_fns::outer -Raw bytes (9): 0x[01, 01, 00, 01, 01, 31, 05, 0c, 06] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 31, 05, 02, 23, 01, 0c, 05, 00, 06] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 49, 5) to (start + 12, 6) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 49, 5) to (start + 2, 35) +- Code(Counter(0)) at (prev + 12, 5) to (start + 0, 6) Function name: no_cov_crate::nested_fns::outer_both_covered -Raw bytes (9): 0x[01, 01, 00, 01, 01, 3f, 05, 0b, 06] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 3f, 05, 02, 17, 01, 0b, 05, 00, 06] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 63, 5) to (start + 11, 6) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 63, 5) to (start + 2, 23) +- Code(Counter(0)) at (prev + 11, 5) to (start + 0, 6) Function name: no_cov_crate::nested_fns::outer_both_covered::inner Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 43, 09, 01, 17, 05, 01, 18, 02, 0e, 02, 02, 14, 02, 0e, 01, 03, 09, 00, 0a] diff --git a/tests/coverage/no_cov_crate.coverage b/tests/coverage/no_cov_crate.coverage index 29ad1f979cf..6a43e52652e 100644 --- a/tests/coverage/no_cov_crate.coverage +++ b/tests/coverage/no_cov_crate.coverage @@ -49,21 +49,21 @@ LL| 1| pub fn outer(is_true: bool) { LL| 1| println!("called and covered"); LL| 1| inner_not_covered(is_true); - LL| 1| - LL| 1| #[coverage(off)] - LL| 1| fn inner_not_covered(is_true: bool) { - LL| 1| if is_true { - LL| 1| println!("called but not covered"); - LL| 1| } else { - LL| 1| println!("absolutely not covered"); - LL| 1| } - LL| 1| } + LL| | + LL| | #[coverage(off)] + LL| | fn inner_not_covered(is_true: bool) { + LL| | if is_true { + LL| | println!("called but not covered"); + LL| | } else { + LL| | println!("absolutely not covered"); + LL| | } + LL| | } LL| 1| } LL| | LL| 1| pub fn outer_both_covered(is_true: bool) { LL| 1| println!("called and covered"); LL| 1| inner(is_true); - LL| 1| + LL| | LL| 1| fn inner(is_true: bool) { LL| 1| if is_true { LL| 1| println!("called and covered"); diff --git a/tests/crashes/125099.rs b/tests/crashes/125099.rs deleted file mode 100644 index bfc8c8fdcf6..00000000000 --- a/tests/crashes/125099.rs +++ /dev/null @@ -1,24 +0,0 @@ -//@ known-bug: rust-lang/rust#125099 - -pub trait ContFn<T>: Fn(T) -> Self::Future { - type Future; -} -impl<T, F> ContFn<T> for F -where - F: Fn(T), -{ - type Future = (); -} - -pub trait SeqHandler { - type Requires; - fn process<F: ContFn<Self::Requires>>() -> impl Sized; -} - -pub struct ConvertToU64; -impl SeqHandler for ConvertToU64 { - type Requires = u64; - fn process<F: ContFn<Self::Requires>>() -> impl Sized {} -} - -fn main() {} diff --git a/tests/crashes/125249.rs b/tests/crashes/125249.rs index 18196d7b34f..1cf6338a0d6 100644 --- a/tests/crashes/125249.rs +++ b/tests/crashes/125249.rs @@ -2,7 +2,7 @@ #![feature(return_position_impl_trait_in_trait, return_type_notation)] trait IntFactory { - fn stream(&self) -> impl IntFactory<stream(): IntFactory<stream(): Send> + Send>; + fn stream(&self) -> impl IntFactory<stream(..): IntFactory<stream(..): Send> + Send>; } pub fn main() {} diff --git a/tests/crashes/126896.rs b/tests/crashes/126896.rs new file mode 100644 index 00000000000..35bf9d5207a --- /dev/null +++ b/tests/crashes/126896.rs @@ -0,0 +1,17 @@ +//@ known-bug: rust-lang/rust#126896 +//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes + +#![feature(type_alias_impl_trait)] +type Two<'a, 'b> = impl std::fmt::Debug; + +fn set(x: &mut isize) -> isize { + *x +} + +fn d(x: Two) { + let c1 = || set(x); + c1; +} + +fn main() { +} diff --git a/tests/crashes/126939.rs b/tests/crashes/126939.rs new file mode 100644 index 00000000000..1edf7484606 --- /dev/null +++ b/tests/crashes/126939.rs @@ -0,0 +1,21 @@ +//@ known-bug: rust-lang/rust#126939 + +struct MySlice<T: Copy>(bool, T); +type MySliceBool = MySlice<[bool]>; + +use std::mem; + +struct P2<T> { + a: T, + b: MySliceBool, +} + +macro_rules! check { + ($t:ty, $align:expr) => ({ + assert_eq!(mem::align_of::<$t>(), $align); + }); +} + +pub fn main() { + check!(P2<u8>, 1); +} diff --git a/tests/crashes/126942.rs b/tests/crashes/126942.rs new file mode 100644 index 00000000000..e4adc8fab28 --- /dev/null +++ b/tests/crashes/126942.rs @@ -0,0 +1,11 @@ +//@ known-bug: rust-lang/rust#126942 +struct Thing; + +pub trait Every { + type Assoc; +} +impl<T: ?Sized> Every for Thing { + type Assoc = T; +} + +static I: <Thing as Every>::Assoc = 3; diff --git a/tests/crashes/126944.rs b/tests/crashes/126944.rs new file mode 100644 index 00000000000..c0c5622e260 --- /dev/null +++ b/tests/crashes/126944.rs @@ -0,0 +1,38 @@ +//@ known-bug: rust-lang/rust#126944 +// Step 1: Create two names for a single type: `Thing` and `AlsoThing` + +struct Thing; +struct Dummy; +pub trait DummyTrait { + type DummyType; +} +impl DummyTrait for Dummy { + type DummyType = Thing; +} +type AlsoThing = <Dummy as DummyTrait>::DummyType; + +// Step 2: Create names for a single trait object type: `TraitObject` and `AlsoTraitObject` + +pub trait SomeTrait { + type Item; +} +type TraitObject = dyn SomeTrait<Item = AlsoThing>; +type AlsoTraitObject = dyn SomeTrait<Item = Thing>; + +// Step 3: Force the compiler to check whether the two names are the same type + +pub trait Supertrait { + type Foo; +} +pub trait Subtrait: Supertrait<Foo = TraitObject> {} + +pub trait HasOutput<A: ?Sized> { + type Output; +} + +fn foo<F>() -> F::Output +where + F: HasOutput<dyn Subtrait<Foo = AlsoTraitObject>>, +{ + todo!() +} diff --git a/tests/crashes/126966.rs b/tests/crashes/126966.rs new file mode 100644 index 00000000000..edeedc68c40 --- /dev/null +++ b/tests/crashes/126966.rs @@ -0,0 +1,29 @@ +//@ known-bug: rust-lang/rust#126966 +mod assert { + use std::mem::{Assume, BikeshedIntrinsicFrom}; + + pub fn is_transmutable<Src, Dst>() + where + Dst: BikeshedIntrinsicFrom<Src>, + { + } +} + +#[repr(u32)] +enum Ox00 { + V = 0x00, +} + +#[repr(C, packed(2))] +enum OxFF { + V = 0xFF, +} + +fn test() { + union Superset { + a: Ox00, + b: OxFF, + } + + assert::is_transmutable::<Superset, Subset>(); +} diff --git a/tests/crashes/126969.rs b/tests/crashes/126969.rs new file mode 100644 index 00000000000..676563d059c --- /dev/null +++ b/tests/crashes/126969.rs @@ -0,0 +1,9 @@ +//@ known-bug: rust-lang/rust#126969 + +struct S<T> { + _: union { t: T }, +} + +fn f(S::<&i8> { .. }: S<&i8>) {} + +fn main() {} diff --git a/tests/crashes/126982.rs b/tests/crashes/126982.rs new file mode 100644 index 00000000000..8522d9415eb --- /dev/null +++ b/tests/crashes/126982.rs @@ -0,0 +1,18 @@ +//@ known-bug: rust-lang/rust#126982 + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo<T: ?Sized> { + a: T, +} + +impl<T, U> CoerceUnsized<U> for Foo<T> {} + +union U { + a: usize, +} + +const C: U = Foo { a: 10 }; + +fn main() {} diff --git a/tests/crashes/127222.rs b/tests/crashes/127222.rs new file mode 100644 index 00000000000..eda0ea3d9b7 --- /dev/null +++ b/tests/crashes/127222.rs @@ -0,0 +1,3 @@ +//@ known-bug: rust-lang/rust#127222 +#[marker] +trait Foo = PartialEq<i32> + Send; diff --git a/tests/crashes/127266.rs b/tests/crashes/127266.rs new file mode 100644 index 00000000000..2bdbe03e373 --- /dev/null +++ b/tests/crashes/127266.rs @@ -0,0 +1,17 @@ +//@ known-bug: rust-lang/rust#127266 +#![feature(const_mut_refs)] +#![feature(const_refs_to_static)] + +struct Meh { + x: &'static dyn UnsafeCell, +} + +const MUH: Meh = Meh { + x: &mut *(READONLY as *mut _), +}; + +static READONLY: i32 = 0; + +trait UnsafeCell<'a> {} + +pub fn main() {} diff --git a/tests/crashes/127299.rs b/tests/crashes/127299.rs new file mode 100644 index 00000000000..7eb78387997 --- /dev/null +++ b/tests/crashes/127299.rs @@ -0,0 +1,12 @@ +//@ known-bug: rust-lang/rust#127299 +trait Qux { + fn bar() -> i32; +} + +pub struct Lint { + pub desc: &'static Qux, +} + +static FOO: &Lint = &Lint { desc: "desc" }; + +fn main() {} diff --git a/tests/crashes/127304.rs b/tests/crashes/127304.rs new file mode 100644 index 00000000000..2975fc27f67 --- /dev/null +++ b/tests/crashes/127304.rs @@ -0,0 +1,20 @@ +//@ known-bug: rust-lang/rust #127304 +#![feature(adt_const_params)] + +trait Trait<T> {} +impl Trait<u16> for () {} + +struct MyStr(str); +impl std::marker::ConstParamTy for MyStr {} + +fn function_with_my_str<const S: &'static MyStr>() -> &'static MyStr { + S +} + +impl MyStr { + const fn new(s: &Trait str) -> &'static MyStr {} +} + +pub fn main() { + let f = function_with_my_str::<{ MyStr::new("hello") }>(); +} diff --git a/tests/mir-opt/tail_call_drops.f.ElaborateDrops.panic-abort.diff b/tests/mir-opt/tail_call_drops.f.ElaborateDrops.panic-abort.diff new file mode 100644 index 00000000000..44673ea00a9 --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f.ElaborateDrops.panic-abort.diff @@ -0,0 +1,108 @@ +- // MIR for `f` before ElaborateDrops ++ // MIR for `f` after ElaborateDrops + + fn f() -> () { + let mut _0: (); + let mut _1: !; + let _2: std::string::String; + let _6: (); + let mut _7: std::string::String; ++ let mut _8: bool; + scope 1 { + debug _a => _2; + let _3: i32; + scope 2 { + debug _b => _3; + let _4: std::string::String; + scope 3 { + debug _c => _4; + let _5: std::string::String; + scope 4 { + debug _d => _5; + } + } + } + } + + bb0: { ++ _8 = const false; + StorageLive(_2); + _2 = String::new() -> [return: bb1, unwind: bb12]; + } + + bb1: { + StorageLive(_3); + _3 = const 12_i32; + StorageLive(_4); + _4 = String::new() -> [return: bb2, unwind: bb11]; + } + + bb2: { ++ _8 = const true; + StorageLive(_5); + _5 = String::new() -> [return: bb3, unwind: bb10]; + } + + bb3: { + StorageLive(_6); + StorageLive(_7); ++ _8 = const false; + _7 = move _4; + _6 = std::mem::drop::<String>(move _7) -> [return: bb4, unwind: bb8]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + drop(_5) -> [return: bb5, unwind: bb10]; + } + + bb5: { + StorageDead(_5); +- drop(_4) -> [return: bb6, unwind: bb11]; ++ goto -> bb6; + } + + bb6: { ++ _8 = const false; + StorageDead(_4); + StorageDead(_3); + drop(_2) -> [return: bb7, unwind: bb12]; + } + + bb7: { + StorageDead(_2); + tailcall g(); + } + + bb8 (cleanup): { +- drop(_7) -> [return: bb9, unwind terminate(cleanup)]; ++ goto -> bb9; + } + + bb9 (cleanup): { + drop(_5) -> [return: bb10, unwind terminate(cleanup)]; + } + + bb10 (cleanup): { +- drop(_4) -> [return: bb11, unwind terminate(cleanup)]; ++ goto -> bb14; + } + + bb11 (cleanup): { + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { + resume; ++ } ++ ++ bb13 (cleanup): { ++ drop(_4) -> [return: bb11, unwind terminate(cleanup)]; ++ } ++ ++ bb14 (cleanup): { ++ switchInt(_8) -> [0: bb11, otherwise: bb13]; + } + } + diff --git a/tests/mir-opt/tail_call_drops.f.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/tail_call_drops.f.ElaborateDrops.panic-unwind.diff new file mode 100644 index 00000000000..a6d33a24595 --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f.ElaborateDrops.panic-unwind.diff @@ -0,0 +1,109 @@ +- // MIR for `f` before ElaborateDrops ++ // MIR for `f` after ElaborateDrops + + fn f() -> () { + let mut _0: (); + let mut _1: !; + let _2: std::string::String; + let _6: (); + let mut _7: std::string::String; ++ let mut _8: bool; + scope 1 { + debug _a => _2; + let _3: i32; + scope 2 { + debug _b => _3; + let _4: std::string::String; + scope 3 { + debug _c => _4; + let _5: std::string::String; + scope 4 { + debug _d => _5; + } + } + } + } + + bb0: { ++ _8 = const false; + StorageLive(_2); + _2 = String::new() -> [return: bb1, unwind continue]; + } + + bb1: { + StorageLive(_3); + _3 = const 12_i32; + StorageLive(_4); + _4 = String::new() -> [return: bb2, unwind: bb11]; + } + + bb2: { ++ _8 = const true; + StorageLive(_5); + _5 = String::new() -> [return: bb3, unwind: bb10]; + } + + bb3: { + StorageLive(_6); + StorageLive(_7); ++ _8 = const false; + _7 = move _4; + _6 = std::mem::drop::<String>(move _7) -> [return: bb4, unwind: bb8]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + drop(_5) -> [return: bb5, unwind: bb10]; + } + + bb5: { + StorageDead(_5); +- drop(_4) -> [return: bb6, unwind: bb11]; ++ goto -> bb6; + } + + bb6: { ++ _8 = const false; + StorageDead(_4); + StorageDead(_3); +- drop(_2) -> [return: bb7, unwind continue]; ++ drop(_2) -> [return: bb7, unwind: bb12]; + } + + bb7: { + StorageDead(_2); + tailcall g(); + } + + bb8 (cleanup): { +- drop(_7) -> [return: bb9, unwind terminate(cleanup)]; ++ goto -> bb9; + } + + bb9 (cleanup): { + drop(_5) -> [return: bb10, unwind terminate(cleanup)]; + } + + bb10 (cleanup): { +- drop(_4) -> [return: bb11, unwind terminate(cleanup)]; ++ goto -> bb14; + } + + bb11 (cleanup): { + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { + resume; ++ } ++ ++ bb13 (cleanup): { ++ drop(_4) -> [return: bb11, unwind terminate(cleanup)]; ++ } ++ ++ bb14 (cleanup): { ++ switchInt(_8) -> [0: bb11, otherwise: bb13]; + } + } + diff --git a/tests/mir-opt/tail_call_drops.f.built.after.panic-abort.mir b/tests/mir-opt/tail_call_drops.f.built.after.panic-abort.mir new file mode 100644 index 00000000000..2c3d62491d7 --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f.built.after.panic-abort.mir @@ -0,0 +1,118 @@ +// MIR for `f` after built + +fn f() -> () { + let mut _0: (); + let mut _1: !; + let _2: std::string::String; + let _6: (); + let mut _7: std::string::String; + scope 1 { + debug _a => _2; + let _3: i32; + scope 2 { + debug _b => _3; + let _4: std::string::String; + scope 3 { + debug _c => _4; + let _5: std::string::String; + scope 4 { + debug _d => _5; + } + } + } + } + + bb0: { + StorageLive(_2); + _2 = String::new() -> [return: bb1, unwind: bb17]; + } + + bb1: { + FakeRead(ForLet(None), _2); + StorageLive(_3); + _3 = const 12_i32; + FakeRead(ForLet(None), _3); + StorageLive(_4); + _4 = String::new() -> [return: bb2, unwind: bb16]; + } + + bb2: { + FakeRead(ForLet(None), _4); + StorageLive(_5); + _5 = String::new() -> [return: bb3, unwind: bb15]; + } + + bb3: { + FakeRead(ForLet(None), _5); + StorageLive(_6); + StorageLive(_7); + _7 = move _4; + _6 = std::mem::drop::<String>(move _7) -> [return: bb4, unwind: bb13]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + drop(_5) -> [return: bb5, unwind: bb15]; + } + + bb5: { + StorageDead(_5); + drop(_4) -> [return: bb6, unwind: bb16]; + } + + bb6: { + StorageDead(_4); + StorageDead(_3); + drop(_2) -> [return: bb7, unwind: bb17]; + } + + bb7: { + StorageDead(_2); + tailcall g(); + } + + bb8: { + drop(_5) -> [return: bb9, unwind: bb15]; + } + + bb9: { + StorageDead(_5); + drop(_4) -> [return: bb10, unwind: bb16]; + } + + bb10: { + StorageDead(_4); + StorageDead(_3); + drop(_2) -> [return: bb11, unwind: bb17]; + } + + bb11: { + StorageDead(_2); + unreachable; + } + + bb12: { + return; + } + + bb13 (cleanup): { + drop(_7) -> [return: bb14, unwind terminate(cleanup)]; + } + + bb14 (cleanup): { + drop(_5) -> [return: bb15, unwind terminate(cleanup)]; + } + + bb15 (cleanup): { + drop(_4) -> [return: bb16, unwind terminate(cleanup)]; + } + + bb16 (cleanup): { + drop(_2) -> [return: bb17, unwind terminate(cleanup)]; + } + + bb17 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/tail_call_drops.f.built.after.panic-unwind.mir b/tests/mir-opt/tail_call_drops.f.built.after.panic-unwind.mir new file mode 100644 index 00000000000..2c3d62491d7 --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f.built.after.panic-unwind.mir @@ -0,0 +1,118 @@ +// MIR for `f` after built + +fn f() -> () { + let mut _0: (); + let mut _1: !; + let _2: std::string::String; + let _6: (); + let mut _7: std::string::String; + scope 1 { + debug _a => _2; + let _3: i32; + scope 2 { + debug _b => _3; + let _4: std::string::String; + scope 3 { + debug _c => _4; + let _5: std::string::String; + scope 4 { + debug _d => _5; + } + } + } + } + + bb0: { + StorageLive(_2); + _2 = String::new() -> [return: bb1, unwind: bb17]; + } + + bb1: { + FakeRead(ForLet(None), _2); + StorageLive(_3); + _3 = const 12_i32; + FakeRead(ForLet(None), _3); + StorageLive(_4); + _4 = String::new() -> [return: bb2, unwind: bb16]; + } + + bb2: { + FakeRead(ForLet(None), _4); + StorageLive(_5); + _5 = String::new() -> [return: bb3, unwind: bb15]; + } + + bb3: { + FakeRead(ForLet(None), _5); + StorageLive(_6); + StorageLive(_7); + _7 = move _4; + _6 = std::mem::drop::<String>(move _7) -> [return: bb4, unwind: bb13]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + drop(_5) -> [return: bb5, unwind: bb15]; + } + + bb5: { + StorageDead(_5); + drop(_4) -> [return: bb6, unwind: bb16]; + } + + bb6: { + StorageDead(_4); + StorageDead(_3); + drop(_2) -> [return: bb7, unwind: bb17]; + } + + bb7: { + StorageDead(_2); + tailcall g(); + } + + bb8: { + drop(_5) -> [return: bb9, unwind: bb15]; + } + + bb9: { + StorageDead(_5); + drop(_4) -> [return: bb10, unwind: bb16]; + } + + bb10: { + StorageDead(_4); + StorageDead(_3); + drop(_2) -> [return: bb11, unwind: bb17]; + } + + bb11: { + StorageDead(_2); + unreachable; + } + + bb12: { + return; + } + + bb13 (cleanup): { + drop(_7) -> [return: bb14, unwind terminate(cleanup)]; + } + + bb14 (cleanup): { + drop(_5) -> [return: bb15, unwind terminate(cleanup)]; + } + + bb15 (cleanup): { + drop(_4) -> [return: bb16, unwind terminate(cleanup)]; + } + + bb16 (cleanup): { + drop(_2) -> [return: bb17, unwind terminate(cleanup)]; + } + + bb17 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/tail_call_drops.f_with_arg.ElaborateDrops.panic-abort.diff b/tests/mir-opt/tail_call_drops.f_with_arg.ElaborateDrops.panic-abort.diff new file mode 100644 index 00000000000..c7df2bb2207 --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f_with_arg.ElaborateDrops.panic-abort.diff @@ -0,0 +1,184 @@ +- // MIR for `f_with_arg` before ElaborateDrops ++ // MIR for `f_with_arg` after ElaborateDrops + + fn f_with_arg(_1: String, _2: String) -> () { + debug _arg1 => _1; + debug _arg2 => _2; + let mut _0: (); + let mut _3: !; + let _4: std::string::String; + let _8: (); + let mut _9: std::string::String; + let mut _10: std::string::String; + let mut _11: std::string::String; ++ let mut _12: bool; + scope 1 { + debug _a => _4; + let _5: i32; + scope 2 { + debug _b => _5; + let _6: std::string::String; + scope 3 { + debug _c => _6; + let _7: std::string::String; + scope 4 { + debug _d => _7; + } + } + } + } + + bb0: { ++ _12 = const false; + StorageLive(_4); + _4 = String::new() -> [return: bb1, unwind: bb27]; + } + + bb1: { + StorageLive(_5); + _5 = const 12_i32; + StorageLive(_6); + _6 = String::new() -> [return: bb2, unwind: bb26]; + } + + bb2: { ++ _12 = const true; + StorageLive(_7); + _7 = String::new() -> [return: bb3, unwind: bb25]; + } + + bb3: { + StorageLive(_8); + StorageLive(_9); ++ _12 = const false; + _9 = move _6; + _8 = std::mem::drop::<String>(move _9) -> [return: bb4, unwind: bb23]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = String::new() -> [return: bb5, unwind: bb24]; + } + + bb5: { + StorageLive(_11); + _11 = String::new() -> [return: bb6, unwind: bb22]; + } + + bb6: { + drop(_7) -> [return: bb7, unwind: bb20]; + } + + bb7: { + StorageDead(_7); +- drop(_6) -> [return: bb8, unwind: bb18]; ++ goto -> bb8; + } + + bb8: { ++ _12 = const false; + StorageDead(_6); + StorageDead(_5); + drop(_4) -> [return: bb9, unwind: bb16]; + } + + bb9: { + StorageDead(_4); + drop(_2) -> [return: bb10, unwind: bb14]; + } + + bb10: { + drop(_1) -> [return: bb11, unwind: bb12]; + } + + bb11: { + tailcall g_with_arg(Spanned { node: move _10, span: $DIR/tail_call_drops.rs:36:23: 36:36 (#0) }, Spanned { node: move _11, span: $DIR/tail_call_drops.rs:36:38: 36:51 (#0) }); + } + + bb12 (cleanup): { + drop(_10) -> [return: bb13, unwind terminate(cleanup)]; + } + + bb13 (cleanup): { + drop(_11) -> [return: bb29, unwind terminate(cleanup)]; + } + + bb14 (cleanup): { + drop(_10) -> [return: bb15, unwind terminate(cleanup)]; + } + + bb15 (cleanup): { + drop(_11) -> [return: bb28, unwind terminate(cleanup)]; + } + + bb16 (cleanup): { + drop(_10) -> [return: bb17, unwind terminate(cleanup)]; + } + + bb17 (cleanup): { + drop(_11) -> [return: bb27, unwind terminate(cleanup)]; + } + + bb18 (cleanup): { +- drop(_10) -> [return: bb19, unwind terminate(cleanup)]; ++ goto -> bb19; + } + + bb19 (cleanup): { +- drop(_11) -> [return: bb26, unwind terminate(cleanup)]; ++ goto -> bb26; + } + + bb20 (cleanup): { + drop(_10) -> [return: bb21, unwind terminate(cleanup)]; + } + + bb21 (cleanup): { + drop(_11) -> [return: bb25, unwind terminate(cleanup)]; + } + + bb22 (cleanup): { + drop(_10) -> [return: bb24, unwind terminate(cleanup)]; + } + + bb23 (cleanup): { +- drop(_9) -> [return: bb24, unwind terminate(cleanup)]; ++ goto -> bb24; + } + + bb24 (cleanup): { + drop(_7) -> [return: bb25, unwind terminate(cleanup)]; + } + + bb25 (cleanup): { +- drop(_6) -> [return: bb26, unwind terminate(cleanup)]; ++ goto -> bb31; + } + + bb26 (cleanup): { + drop(_4) -> [return: bb27, unwind terminate(cleanup)]; + } + + bb27 (cleanup): { + drop(_2) -> [return: bb28, unwind terminate(cleanup)]; + } + + bb28 (cleanup): { + drop(_1) -> [return: bb29, unwind terminate(cleanup)]; + } + + bb29 (cleanup): { + resume; ++ } ++ ++ bb30 (cleanup): { ++ drop(_6) -> [return: bb26, unwind terminate(cleanup)]; ++ } ++ ++ bb31 (cleanup): { ++ switchInt(_12) -> [0: bb26, otherwise: bb30]; + } + } + diff --git a/tests/mir-opt/tail_call_drops.f_with_arg.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/tail_call_drops.f_with_arg.ElaborateDrops.panic-unwind.diff new file mode 100644 index 00000000000..c7df2bb2207 --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f_with_arg.ElaborateDrops.panic-unwind.diff @@ -0,0 +1,184 @@ +- // MIR for `f_with_arg` before ElaborateDrops ++ // MIR for `f_with_arg` after ElaborateDrops + + fn f_with_arg(_1: String, _2: String) -> () { + debug _arg1 => _1; + debug _arg2 => _2; + let mut _0: (); + let mut _3: !; + let _4: std::string::String; + let _8: (); + let mut _9: std::string::String; + let mut _10: std::string::String; + let mut _11: std::string::String; ++ let mut _12: bool; + scope 1 { + debug _a => _4; + let _5: i32; + scope 2 { + debug _b => _5; + let _6: std::string::String; + scope 3 { + debug _c => _6; + let _7: std::string::String; + scope 4 { + debug _d => _7; + } + } + } + } + + bb0: { ++ _12 = const false; + StorageLive(_4); + _4 = String::new() -> [return: bb1, unwind: bb27]; + } + + bb1: { + StorageLive(_5); + _5 = const 12_i32; + StorageLive(_6); + _6 = String::new() -> [return: bb2, unwind: bb26]; + } + + bb2: { ++ _12 = const true; + StorageLive(_7); + _7 = String::new() -> [return: bb3, unwind: bb25]; + } + + bb3: { + StorageLive(_8); + StorageLive(_9); ++ _12 = const false; + _9 = move _6; + _8 = std::mem::drop::<String>(move _9) -> [return: bb4, unwind: bb23]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = String::new() -> [return: bb5, unwind: bb24]; + } + + bb5: { + StorageLive(_11); + _11 = String::new() -> [return: bb6, unwind: bb22]; + } + + bb6: { + drop(_7) -> [return: bb7, unwind: bb20]; + } + + bb7: { + StorageDead(_7); +- drop(_6) -> [return: bb8, unwind: bb18]; ++ goto -> bb8; + } + + bb8: { ++ _12 = const false; + StorageDead(_6); + StorageDead(_5); + drop(_4) -> [return: bb9, unwind: bb16]; + } + + bb9: { + StorageDead(_4); + drop(_2) -> [return: bb10, unwind: bb14]; + } + + bb10: { + drop(_1) -> [return: bb11, unwind: bb12]; + } + + bb11: { + tailcall g_with_arg(Spanned { node: move _10, span: $DIR/tail_call_drops.rs:36:23: 36:36 (#0) }, Spanned { node: move _11, span: $DIR/tail_call_drops.rs:36:38: 36:51 (#0) }); + } + + bb12 (cleanup): { + drop(_10) -> [return: bb13, unwind terminate(cleanup)]; + } + + bb13 (cleanup): { + drop(_11) -> [return: bb29, unwind terminate(cleanup)]; + } + + bb14 (cleanup): { + drop(_10) -> [return: bb15, unwind terminate(cleanup)]; + } + + bb15 (cleanup): { + drop(_11) -> [return: bb28, unwind terminate(cleanup)]; + } + + bb16 (cleanup): { + drop(_10) -> [return: bb17, unwind terminate(cleanup)]; + } + + bb17 (cleanup): { + drop(_11) -> [return: bb27, unwind terminate(cleanup)]; + } + + bb18 (cleanup): { +- drop(_10) -> [return: bb19, unwind terminate(cleanup)]; ++ goto -> bb19; + } + + bb19 (cleanup): { +- drop(_11) -> [return: bb26, unwind terminate(cleanup)]; ++ goto -> bb26; + } + + bb20 (cleanup): { + drop(_10) -> [return: bb21, unwind terminate(cleanup)]; + } + + bb21 (cleanup): { + drop(_11) -> [return: bb25, unwind terminate(cleanup)]; + } + + bb22 (cleanup): { + drop(_10) -> [return: bb24, unwind terminate(cleanup)]; + } + + bb23 (cleanup): { +- drop(_9) -> [return: bb24, unwind terminate(cleanup)]; ++ goto -> bb24; + } + + bb24 (cleanup): { + drop(_7) -> [return: bb25, unwind terminate(cleanup)]; + } + + bb25 (cleanup): { +- drop(_6) -> [return: bb26, unwind terminate(cleanup)]; ++ goto -> bb31; + } + + bb26 (cleanup): { + drop(_4) -> [return: bb27, unwind terminate(cleanup)]; + } + + bb27 (cleanup): { + drop(_2) -> [return: bb28, unwind terminate(cleanup)]; + } + + bb28 (cleanup): { + drop(_1) -> [return: bb29, unwind terminate(cleanup)]; + } + + bb29 (cleanup): { + resume; ++ } ++ ++ bb30 (cleanup): { ++ drop(_6) -> [return: bb26, unwind terminate(cleanup)]; ++ } ++ ++ bb31 (cleanup): { ++ switchInt(_12) -> [0: bb26, otherwise: bb30]; + } + } + diff --git a/tests/mir-opt/tail_call_drops.f_with_arg.built.after.panic-abort.mir b/tests/mir-opt/tail_call_drops.f_with_arg.built.after.panic-abort.mir new file mode 100644 index 00000000000..744f1989acc --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f_with_arg.built.after.panic-abort.mir @@ -0,0 +1,202 @@ +// MIR for `f_with_arg` after built + +fn f_with_arg(_1: String, _2: String) -> () { + debug _arg1 => _1; + debug _arg2 => _2; + let mut _0: (); + let mut _3: !; + let _4: std::string::String; + let _8: (); + let mut _9: std::string::String; + let mut _10: std::string::String; + let mut _11: std::string::String; + scope 1 { + debug _a => _4; + let _5: i32; + scope 2 { + debug _b => _5; + let _6: std::string::String; + scope 3 { + debug _c => _6; + let _7: std::string::String; + scope 4 { + debug _d => _7; + } + } + } + } + + bb0: { + StorageLive(_4); + _4 = String::new() -> [return: bb1, unwind: bb34]; + } + + bb1: { + FakeRead(ForLet(None), _4); + StorageLive(_5); + _5 = const 12_i32; + FakeRead(ForLet(None), _5); + StorageLive(_6); + _6 = String::new() -> [return: bb2, unwind: bb33]; + } + + bb2: { + FakeRead(ForLet(None), _6); + StorageLive(_7); + _7 = String::new() -> [return: bb3, unwind: bb32]; + } + + bb3: { + FakeRead(ForLet(None), _7); + StorageLive(_8); + StorageLive(_9); + _9 = move _6; + _8 = std::mem::drop::<String>(move _9) -> [return: bb4, unwind: bb30]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = String::new() -> [return: bb5, unwind: bb31]; + } + + bb5: { + StorageLive(_11); + _11 = String::new() -> [return: bb6, unwind: bb29]; + } + + bb6: { + drop(_7) -> [return: bb7, unwind: bb27]; + } + + bb7: { + StorageDead(_7); + drop(_6) -> [return: bb8, unwind: bb25]; + } + + bb8: { + StorageDead(_6); + StorageDead(_5); + drop(_4) -> [return: bb9, unwind: bb23]; + } + + bb9: { + StorageDead(_4); + drop(_2) -> [return: bb10, unwind: bb21]; + } + + bb10: { + drop(_1) -> [return: bb11, unwind: bb19]; + } + + bb11: { + tailcall g_with_arg(Spanned { node: move _10, span: $DIR/tail_call_drops.rs:36:23: 36:36 (#0) }, Spanned { node: move _11, span: $DIR/tail_call_drops.rs:36:38: 36:51 (#0) }); + } + + bb12: { + StorageDead(_11); + StorageDead(_10); + drop(_7) -> [return: bb13, unwind: bb32]; + } + + bb13: { + StorageDead(_7); + drop(_6) -> [return: bb14, unwind: bb33]; + } + + bb14: { + StorageDead(_6); + StorageDead(_5); + drop(_4) -> [return: bb15, unwind: bb34]; + } + + bb15: { + StorageDead(_4); + unreachable; + } + + bb16: { + drop(_2) -> [return: bb17, unwind: bb35]; + } + + bb17: { + drop(_1) -> [return: bb18, unwind: bb36]; + } + + bb18: { + return; + } + + bb19 (cleanup): { + drop(_10) -> [return: bb20, unwind terminate(cleanup)]; + } + + bb20 (cleanup): { + drop(_11) -> [return: bb36, unwind terminate(cleanup)]; + } + + bb21 (cleanup): { + drop(_10) -> [return: bb22, unwind terminate(cleanup)]; + } + + bb22 (cleanup): { + drop(_11) -> [return: bb35, unwind terminate(cleanup)]; + } + + bb23 (cleanup): { + drop(_10) -> [return: bb24, unwind terminate(cleanup)]; + } + + bb24 (cleanup): { + drop(_11) -> [return: bb34, unwind terminate(cleanup)]; + } + + bb25 (cleanup): { + drop(_10) -> [return: bb26, unwind terminate(cleanup)]; + } + + bb26 (cleanup): { + drop(_11) -> [return: bb33, unwind terminate(cleanup)]; + } + + bb27 (cleanup): { + drop(_10) -> [return: bb28, unwind terminate(cleanup)]; + } + + bb28 (cleanup): { + drop(_11) -> [return: bb32, unwind terminate(cleanup)]; + } + + bb29 (cleanup): { + drop(_10) -> [return: bb31, unwind terminate(cleanup)]; + } + + bb30 (cleanup): { + drop(_9) -> [return: bb31, unwind terminate(cleanup)]; + } + + bb31 (cleanup): { + drop(_7) -> [return: bb32, unwind terminate(cleanup)]; + } + + bb32 (cleanup): { + drop(_6) -> [return: bb33, unwind terminate(cleanup)]; + } + + bb33 (cleanup): { + drop(_4) -> [return: bb34, unwind terminate(cleanup)]; + } + + bb34 (cleanup): { + drop(_2) -> [return: bb35, unwind terminate(cleanup)]; + } + + bb35 (cleanup): { + drop(_1) -> [return: bb36, unwind terminate(cleanup)]; + } + + bb36 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/tail_call_drops.f_with_arg.built.after.panic-unwind.mir b/tests/mir-opt/tail_call_drops.f_with_arg.built.after.panic-unwind.mir new file mode 100644 index 00000000000..744f1989acc --- /dev/null +++ b/tests/mir-opt/tail_call_drops.f_with_arg.built.after.panic-unwind.mir @@ -0,0 +1,202 @@ +// MIR for `f_with_arg` after built + +fn f_with_arg(_1: String, _2: String) -> () { + debug _arg1 => _1; + debug _arg2 => _2; + let mut _0: (); + let mut _3: !; + let _4: std::string::String; + let _8: (); + let mut _9: std::string::String; + let mut _10: std::string::String; + let mut _11: std::string::String; + scope 1 { + debug _a => _4; + let _5: i32; + scope 2 { + debug _b => _5; + let _6: std::string::String; + scope 3 { + debug _c => _6; + let _7: std::string::String; + scope 4 { + debug _d => _7; + } + } + } + } + + bb0: { + StorageLive(_4); + _4 = String::new() -> [return: bb1, unwind: bb34]; + } + + bb1: { + FakeRead(ForLet(None), _4); + StorageLive(_5); + _5 = const 12_i32; + FakeRead(ForLet(None), _5); + StorageLive(_6); + _6 = String::new() -> [return: bb2, unwind: bb33]; + } + + bb2: { + FakeRead(ForLet(None), _6); + StorageLive(_7); + _7 = String::new() -> [return: bb3, unwind: bb32]; + } + + bb3: { + FakeRead(ForLet(None), _7); + StorageLive(_8); + StorageLive(_9); + _9 = move _6; + _8 = std::mem::drop::<String>(move _9) -> [return: bb4, unwind: bb30]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = String::new() -> [return: bb5, unwind: bb31]; + } + + bb5: { + StorageLive(_11); + _11 = String::new() -> [return: bb6, unwind: bb29]; + } + + bb6: { + drop(_7) -> [return: bb7, unwind: bb27]; + } + + bb7: { + StorageDead(_7); + drop(_6) -> [return: bb8, unwind: bb25]; + } + + bb8: { + StorageDead(_6); + StorageDead(_5); + drop(_4) -> [return: bb9, unwind: bb23]; + } + + bb9: { + StorageDead(_4); + drop(_2) -> [return: bb10, unwind: bb21]; + } + + bb10: { + drop(_1) -> [return: bb11, unwind: bb19]; + } + + bb11: { + tailcall g_with_arg(Spanned { node: move _10, span: $DIR/tail_call_drops.rs:36:23: 36:36 (#0) }, Spanned { node: move _11, span: $DIR/tail_call_drops.rs:36:38: 36:51 (#0) }); + } + + bb12: { + StorageDead(_11); + StorageDead(_10); + drop(_7) -> [return: bb13, unwind: bb32]; + } + + bb13: { + StorageDead(_7); + drop(_6) -> [return: bb14, unwind: bb33]; + } + + bb14: { + StorageDead(_6); + StorageDead(_5); + drop(_4) -> [return: bb15, unwind: bb34]; + } + + bb15: { + StorageDead(_4); + unreachable; + } + + bb16: { + drop(_2) -> [return: bb17, unwind: bb35]; + } + + bb17: { + drop(_1) -> [return: bb18, unwind: bb36]; + } + + bb18: { + return; + } + + bb19 (cleanup): { + drop(_10) -> [return: bb20, unwind terminate(cleanup)]; + } + + bb20 (cleanup): { + drop(_11) -> [return: bb36, unwind terminate(cleanup)]; + } + + bb21 (cleanup): { + drop(_10) -> [return: bb22, unwind terminate(cleanup)]; + } + + bb22 (cleanup): { + drop(_11) -> [return: bb35, unwind terminate(cleanup)]; + } + + bb23 (cleanup): { + drop(_10) -> [return: bb24, unwind terminate(cleanup)]; + } + + bb24 (cleanup): { + drop(_11) -> [return: bb34, unwind terminate(cleanup)]; + } + + bb25 (cleanup): { + drop(_10) -> [return: bb26, unwind terminate(cleanup)]; + } + + bb26 (cleanup): { + drop(_11) -> [return: bb33, unwind terminate(cleanup)]; + } + + bb27 (cleanup): { + drop(_10) -> [return: bb28, unwind terminate(cleanup)]; + } + + bb28 (cleanup): { + drop(_11) -> [return: bb32, unwind terminate(cleanup)]; + } + + bb29 (cleanup): { + drop(_10) -> [return: bb31, unwind terminate(cleanup)]; + } + + bb30 (cleanup): { + drop(_9) -> [return: bb31, unwind terminate(cleanup)]; + } + + bb31 (cleanup): { + drop(_7) -> [return: bb32, unwind terminate(cleanup)]; + } + + bb32 (cleanup): { + drop(_6) -> [return: bb33, unwind terminate(cleanup)]; + } + + bb33 (cleanup): { + drop(_4) -> [return: bb34, unwind terminate(cleanup)]; + } + + bb34 (cleanup): { + drop(_2) -> [return: bb35, unwind terminate(cleanup)]; + } + + bb35 (cleanup): { + drop(_1) -> [return: bb36, unwind terminate(cleanup)]; + } + + bb36 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/tail_call_drops.rs b/tests/mir-opt/tail_call_drops.rs new file mode 100644 index 00000000000..56f4852a95f --- /dev/null +++ b/tests/mir-opt/tail_call_drops.rs @@ -0,0 +1,41 @@ +// skip-filecheck +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +// EMIT_MIR tail_call_drops.f.built.after.mir +// Expected result: +// drop(_d) -> drop(_c) -> drop(_a) -> tailcall g() +// +// EMIT_MIR tail_call_drops.f.ElaborateDrops.diff +// Expected result: +// drop(_d) -> drop(_a) -> tailcall g() +fn f() { + let _a = String::new(); + let _b = 12; + let _c = String::new(); + let _d = String::new(); + + drop(_c); + + become g(); +} + +fn g() {} + +// EMIT_MIR tail_call_drops.f_with_arg.built.after.mir +// EMIT_MIR tail_call_drops.f_with_arg.ElaborateDrops.diff +fn f_with_arg(_arg1: String, _arg2: String) { + let _a = String::new(); + let _b = 12; + let _c = String::new(); + let _d = String::new(); + + drop(_c); + + become g_with_arg(String::new(), String::new()); +} + +fn g_with_arg(_arg1: String, _arg2: String) {} + +fn main() {} diff --git a/tests/pretty/issue-4264.pp b/tests/pretty/issue-4264.pp index 018ccf82dae..fa958d9f1e8 100644 --- a/tests/pretty/issue-4264.pp +++ b/tests/pretty/issue-4264.pp @@ -29,16 +29,17 @@ fn bar() ({ - ({ - let res = - ((::alloc::fmt::format as - for<'a> fn(Arguments<'a>) -> String {format})(((format_arguments::new_const - as - fn(&[&'static str; 1]) -> Arguments<'_> {Arguments::<'_>::new_const::<1>})((&([("test" - as &str)] as [&str; 1]) as &[&str; 1])) as Arguments<'_>)) - as String); - (res as String) - } as String); + ((::alloc::__export::must_use as + fn(String) -> String {must_use::<String>})(({ + let res = + ((::alloc::fmt::format as + for<'a> fn(Arguments<'a>) -> String {format})(((format_arguments::new_const + as + fn(&[&'static str; 1]) -> Arguments<'_> {Arguments::<'_>::new_const::<1>})((&([("test" + as &str)] as [&str; 1]) as &[&str; 1])) as Arguments<'_>)) + as String); + (res as String) + } as String)) as String); } as ()) type Foo = [i32; (3 as usize)]; struct Bar { diff --git a/tests/run-make/dylib-chain/Makefile b/tests/run-make/dylib-chain/Makefile deleted file mode 100644 index f1fea99c5ee..00000000000 --- a/tests/run-make/dylib-chain/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) m1.rs -C prefer-dynamic - $(RUSTC) m2.rs -C prefer-dynamic - $(RUSTC) m3.rs -C prefer-dynamic - $(RUSTC) m4.rs - $(call RUN,m4) - $(call REMOVE_DYLIBS,m1) - $(call REMOVE_DYLIBS,m2) - $(call REMOVE_DYLIBS,m3) - $(call FAIL,m4) diff --git a/tests/run-make/dylib-chain/rmake.rs b/tests/run-make/dylib-chain/rmake.rs new file mode 100644 index 00000000000..a96cc350875 --- /dev/null +++ b/tests/run-make/dylib-chain/rmake.rs @@ -0,0 +1,23 @@ +// In this test, m4 depends on m3, which depends on m2, which depends on m1. +// Even though dependencies are chained like this and there is no direct mention +// of m1 or m2 in m4.rs, compilation and execution should still succeed. Unlike the +// rlib-chain test, dynamic libraries contain upstream dependencies, and breaking +// the chain by removing the dylibs causes execution to fail. +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rustc}; + +fn main() { + rustc().input("m1.rs").arg("-Cprefer-dynamic").run(); + rustc().input("m2.rs").arg("-Cprefer-dynamic").run(); + rustc().input("m3.rs").arg("-Cprefer-dynamic").run(); + rustc().input("m4.rs").run(); + run("m4"); + fs_wrapper::remove_file(dynamic_lib_name("m1")); + fs_wrapper::remove_file(dynamic_lib_name("m2")); + fs_wrapper::remove_file(dynamic_lib_name("m3")); + run_fail("m4"); +} diff --git a/tests/run-make/emit-named-files/rmake.rs b/tests/run-make/emit-named-files/rmake.rs index 79c3ee90c98..a02c97fec4c 100644 --- a/tests/run-make/emit-named-files/rmake.rs +++ b/tests/run-make/emit-named-files/rmake.rs @@ -4,7 +4,7 @@ use run_make_support::{fs_wrapper, rustc}; fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) { let out_file = out_dir.join(out_file); - rustc().input("foo.rs").emit(&format!("{format}={}", out_file.display())).run(); + rustc().input("foo.rs").emit(format!("{format}={}", out_file.display())).run(); assert!(out_file.is_file()); } diff --git a/tests/run-make/emit-path-unhashed/Makefile b/tests/run-make/emit-path-unhashed/Makefile deleted file mode 100644 index 611f8578140..00000000000 --- a/tests/run-make/emit-path-unhashed/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -include ../tools.mk - -OUT=$(TMPDIR)/emit - -# --emit KIND=PATH should not affect crate hash vs --emit KIND -all: $(OUT)/a/libfoo.rlib $(OUT)/b/libfoo.rlib $(OUT)/c/libfoo.rlib \ - $(TMPDIR)/libfoo.rlib - $(RUSTC) -Zls=root $(TMPDIR)/libfoo.rlib > $(TMPDIR)/base.txt - $(RUSTC) -Zls=root $(OUT)/a/libfoo.rlib > $(TMPDIR)/a.txt - $(RUSTC) -Zls=root $(OUT)/b/libfoo.rlib > $(TMPDIR)/b.txt - $(RUSTC) -Zls=root $(OUT)/c/libfoo.rlib > $(TMPDIR)/c.txt - - diff $(TMPDIR)/base.txt $(TMPDIR)/a.txt - diff $(TMPDIR)/base.txt $(TMPDIR)/b.txt - - # Different KIND parameters do affect hash. - # diff exits 1 on difference, 2 on trouble - diff $(TMPDIR)/base.txt $(TMPDIR)/c.txt ; test "$$?" -eq 1 - -# Default output name -$(TMPDIR)/libfoo.rlib: foo.rs - $(RUSTC) --emit link foo.rs - -# Output named with -o -$(OUT)/a/libfoo.rlib: foo.rs - mkdir -p $(OUT)/a - $(RUSTC) --emit link -o $@ foo.rs - -# Output named with KIND=PATH -$(OUT)/b/libfoo.rlib: foo.rs - mkdir -p $(OUT)/b - $(RUSTC) --emit link=$@ foo.rs - -# Output multiple kinds -$(OUT)/c/libfoo.rlib: foo.rs - mkdir -p $(OUT)/c - $(RUSTC) --emit link=$@,metadata foo.rs diff --git a/tests/run-make/emit-path-unhashed/rmake.rs b/tests/run-make/emit-path-unhashed/rmake.rs new file mode 100644 index 00000000000..ce56c197588 --- /dev/null +++ b/tests/run-make/emit-path-unhashed/rmake.rs @@ -0,0 +1,34 @@ +// Specifying how rustc outputs a file can be done in different ways, such as +// the output flag or the KIND=NAME syntax. However, some of these methods used +// to result in different hashes on output files even though they yielded the +// exact same result otherwise. This was fixed in #86045, and this test checks +// that the hash is only modified when the output is made different, such as by +// adding a new output type (in this test, metadata). +// See https://github.com/rust-lang/rust/issues/86044 + +use run_make_support::{diff, fs_wrapper, rustc}; + +fn main() { + fs_wrapper::create_dir("emit"); + fs_wrapper::create_dir("emit/a"); + fs_wrapper::create_dir("emit/b"); + fs_wrapper::create_dir("emit/c"); + // The default output name. + rustc().emit("link").input("foo.rs").run(); + // The output is named with the output flag. + rustc().emit("link").output("emit/a/libfoo.rlib").input("foo.rs").run(); + // The output is named with link=NAME. + rustc().emit("link=emit/b/libfoo.rlib").input("foo.rs").run(); + // The output is named with link=NAME, with an additional kind tacked on. + rustc().emit("link=emit/c/libfoo.rlib,metadata").input("foo.rs").run(); + + let base = rustc().arg("-Zls=root").input("libfoo.rlib").run().stdout_utf8(); + let a = rustc().arg("-Zls=root").input("emit/a/libfoo.rlib").run().stdout_utf8(); + let b = rustc().arg("-Zls=root").input("emit/b/libfoo.rlib").run().stdout_utf8(); + let c = rustc().arg("-Zls=root").input("emit/c/libfoo.rlib").run().stdout_utf8(); + // Both the output flag and link=NAME methods do not modify the hash of the output file. + diff().expected_text("base", &base).actual_text("a", a).run(); + diff().expected_text("base", &base).actual_text("b", b).run(); + // However, having multiple types of outputs does modify the hash. + diff().expected_text("base", &base).actual_text("c", c).run_fail(); +} diff --git a/tests/run-make/emit-shared-files/Makefile b/tests/run-make/emit-shared-files/Makefile deleted file mode 100644 index 27c72b00368..00000000000 --- a/tests/run-make/emit-shared-files/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -include ../tools.mk - -INVOCATION_ONLY = $(TMPDIR)/invocation-only -TOOLCHAIN_ONLY = $(TMPDIR)/toolchain-only -ALL_SHARED = $(TMPDIR)/all-shared - -all: invocation-only toolchain-only all-shared - -invocation-only: - $(RUSTDOC) -Z unstable-options --emit=invocation-specific --output $(INVOCATION_ONLY) --resource-suffix=-xxx --theme y.css --extend-css z.css x.rs - [ -e $(INVOCATION_ONLY)/search-index-xxx.js ] - [ -e $(INVOCATION_ONLY)/settings.html ] - [ -e $(INVOCATION_ONLY)/x/all.html ] - [ -e $(INVOCATION_ONLY)/x/index.html ] - [ -e $(INVOCATION_ONLY)/theme-xxx.css ] # generated from z.css - ! [ -e $(INVOCATION_ONLY)/storage-xxx.js ] - ! [ -e $(INVOCATION_ONLY)/SourceSerif4-It.ttf.woff2 ] - - # FIXME: this probably shouldn't have a suffix - [ -e $(INVOCATION_ONLY)/y-xxx.css ] - # FIXME: this is technically incorrect (see `write_shared`) - ! [ -e $(INVOCATION_ONLY)/main-xxx.js ] - -toolchain-only: - $(RUSTDOC) -Z unstable-options --emit=toolchain-shared-resources --output $(TOOLCHAIN_ONLY) --resource-suffix=-xxx --extend-css z.css x.rs - [ -e $(TOOLCHAIN_ONLY)/static.files/storage-*.js ] - [ -e $(TOOLCHAIN_ONLY)/static.files/SourceSerif4-It-*.ttf.woff2 ] - ! [ -e $(TOOLCHAIN_ONLY)/search-index-xxx.js ] - ! [ -e $(TOOLCHAIN_ONLY)/x/index.html ] - ! [ -e $(TOOLCHAIN_ONLY)/theme.css ] - - [ -e $(TOOLCHAIN_ONLY)/static.files/main-*.js ] - ! [ -e $(TOOLCHAIN_ONLY)/y-xxx.css ] - -all-shared: - $(RUSTDOC) -Z unstable-options --emit=toolchain-shared-resources,unversioned-shared-resources --output $(ALL_SHARED) --resource-suffix=-xxx --extend-css z.css x.rs - [ -e $(ALL_SHARED)/static.files/storage-*.js ] - [ -e $(ALL_SHARED)/static.files/SourceSerif4-It-*.ttf.woff2 ] - ! [ -e $(ALL_SHARED)/search-index-xxx.js ] - ! [ -e $(ALL_SHARED)/settings.html ] - ! [ -e $(ALL_SHARED)/x ] - ! [ -e $(ALL_SHARED)/src ] - ! [ -e $(ALL_SHARED)/theme.css ] - - [ -e $(ALL_SHARED)/static.files/main-*.js ] - ! [ -e $(ALL_SHARED)/y-xxx.css ] diff --git a/tests/run-make/emit-shared-files/rmake.rs b/tests/run-make/emit-shared-files/rmake.rs new file mode 100644 index 00000000000..33c12310246 --- /dev/null +++ b/tests/run-make/emit-shared-files/rmake.rs @@ -0,0 +1,102 @@ +// This test checks the functionality of one of rustdoc's unstable options, +// the ability to specify emit restrictions with `--emit`. +// `invocation-only` should only emit crate-specific files. +// `toolchain-only` should only emit toolchain-specific files. +// `all-shared` should only emit files that can be shared between crates. +// See https://github.com/rust-lang/rust/pull/83478 + +use run_make_support::{has_extension, has_prefix, rustdoc, shallow_find_files}; +use std::path::Path; + +fn main() { + rustdoc() + .arg("-Zunstable-options") + .arg("--emit=invocation-specific") + .output("invocation-only") + .arg("--resource-suffix=-xxx") + .args(&["--theme", "y.css"]) + .args(&["--extend-css", "z.css"]) + .input("x.rs") + .run(); + assert!(Path::new("invocation-only/search-index-xxx.js").exists()); + assert!(Path::new("invocation-only/settings.html").exists()); + assert!(Path::new("invocation-only/x/all.html").exists()); + assert!(Path::new("invocation-only/x/index.html").exists()); + assert!(Path::new("invocation-only/theme-xxx.css").exists()); // generated from z.css + assert!(!Path::new("invocation-only/storage-xxx.js").exists()); + assert!(!Path::new("invocation-only/SourceSerif4-It.ttf.woff2").exists()); + // FIXME: this probably shouldn't have a suffix + assert!(Path::new("invocation-only/y-xxx.css").exists()); + // FIXME: this is technically incorrect (see `write_shared`) + assert!(!Path::new("invocation-only/main-xxx.js").exists()); + + rustdoc() + .arg("-Zunstable-options") + .arg("--emit=toolchain-shared-resources") + .output("toolchain-only") + .arg("--resource-suffix=-xxx") + .args(&["--extend-css", "z.css"]) + .input("x.rs") + .run(); + assert_eq!( + shallow_find_files("toolchain-only/static.files", |path| { + has_prefix(path, "storage-") && has_extension(path, "js") + }) + .len(), + 1 + ); + assert_eq!( + shallow_find_files("toolchain-only/static.files", |path| { + has_prefix(path, "SourceSerif4-It-") && has_extension(path, "woff2") + }) + .len(), + 1 + ); + assert_eq!( + shallow_find_files("toolchain-only/static.files", |path| { + has_prefix(path, "main-") && has_extension(path, "js") + }) + .len(), + 1 + ); + assert!(!Path::new("toolchain-only/search-index-xxx.js").exists()); + assert!(!Path::new("toolchain-only/x/index.html").exists()); + assert!(!Path::new("toolchain-only/theme.css").exists()); + assert!(!Path::new("toolchain-only/y-xxx.css").exists()); + + rustdoc() + .arg("-Zunstable-options") + .arg("--emit=toolchain-shared-resources,unversioned-shared-resources") + .output("all-shared") + .arg("--resource-suffix=-xxx") + .args(&["--extend-css", "z.css"]) + .input("x.rs") + .run(); + assert_eq!( + shallow_find_files("all-shared/static.files", |path| { + has_prefix(path, "storage-") && has_extension(path, "js") + }) + .len(), + 1 + ); + assert_eq!( + shallow_find_files("all-shared/static.files", |path| { + has_prefix(path, "SourceSerif4-It-") && has_extension(path, "woff2") + }) + .len(), + 1 + ); + assert!(!Path::new("all-shared/search-index-xxx.js").exists()); + assert!(!Path::new("all-shared/settings.html").exists()); + assert!(!Path::new("all-shared/x").exists()); + assert!(!Path::new("all-shared/src").exists()); + assert!(!Path::new("all-shared/theme.css").exists()); + assert_eq!( + shallow_find_files("all-shared/static.files", |path| { + has_prefix(path, "main-") && has_extension(path, "js") + }) + .len(), + 1 + ); + assert!(!Path::new("all-shared/y-xxx.css").exists()); +} diff --git a/tests/run-make/inaccessible-temp-dir/rmake.rs b/tests/run-make/inaccessible-temp-dir/rmake.rs index b98e151e906..62b8479c328 100644 --- a/tests/run-make/inaccessible-temp-dir/rmake.rs +++ b/tests/run-make/inaccessible-temp-dir/rmake.rs @@ -14,7 +14,7 @@ // See https://github.com/rust-lang/rust/issues/66530 //@ ignore-riscv64 -// FIXME: The riscv build container runs as root, and can always write +// FIXME: The riscv64gc-gnu build container runs as root, and can always write // into `inaccessible/tmp`. Ideally, the riscv64-gnu docker container // would use a non-root user, but this leads to issues with // `mkfs.ext4 -d`, as well as mounting a loop device for the rootfs. diff --git a/tests/run-make/issue-47384/lib.rs b/tests/run-make/include-all-symbols-linking/lib.rs index 99508bcdaf3..99508bcdaf3 100644 --- a/tests/run-make/issue-47384/lib.rs +++ b/tests/run-make/include-all-symbols-linking/lib.rs diff --git a/tests/run-make/issue-47384/linker.ld b/tests/run-make/include-all-symbols-linking/linker.ld index 2e70acab3f4..2e70acab3f4 100644 --- a/tests/run-make/issue-47384/linker.ld +++ b/tests/run-make/include-all-symbols-linking/linker.ld diff --git a/tests/run-make/issue-47384/main.rs b/tests/run-make/include-all-symbols-linking/main.rs index 02572632517..02572632517 100644 --- a/tests/run-make/issue-47384/main.rs +++ b/tests/run-make/include-all-symbols-linking/main.rs diff --git a/tests/run-make/include-all-symbols-linking/rmake.rs b/tests/run-make/include-all-symbols-linking/rmake.rs new file mode 100644 index 00000000000..77fd71ab20d --- /dev/null +++ b/tests/run-make/include-all-symbols-linking/rmake.rs @@ -0,0 +1,31 @@ +// Linkers treat archives differently from object files: all object files participate in linking, +// while archives will only participate in linking if they can satisfy at least one undefined +// reference (version scripts doesn't count). This causes `#[no_mangle]` or `#[used]` items to +// be ignored by the linker, and since they never participate in the linking, using `KEEP` in the +// linker scripts can't keep them either. This causes #47384. After the fix in #95604, this test +// checks that these symbols and sections successfully appear in the output dynamic library. +// See https://github.com/rust-lang/rust/pull/95604 +// See https://github.com/rust-lang/rust/issues/47384 + +//@ only-linux +// Reason: differences in object file formats on OSX and Windows +// causes errors in the llvm_objdump step + +use run_make_support::{dynamic_lib_name, llvm_objdump, llvm_readobj, rustc}; + +fn main() { + rustc().crate_type("lib").input("lib.rs").run(); + rustc().crate_type("cdylib").link_args("-Tlinker.ld").input("main.rs").run(); + // Ensure `#[used]` and `KEEP`-ed section is there + llvm_objdump() + .arg("--full-contents") + .arg("--section=.static") + .input(dynamic_lib_name("main")) + .run(); + // Ensure `#[no_mangle]` symbol is there + llvm_readobj() + .arg("--symbols") + .input(dynamic_lib_name("main")) + .run() + .assert_stdout_contains("bar"); +} diff --git a/tests/run-make/include_bytes_deps/input.bin b/tests/run-make/include-bytes-deps/input.bin index cd0875583aa..cd0875583aa 100644 --- a/tests/run-make/include_bytes_deps/input.bin +++ b/tests/run-make/include-bytes-deps/input.bin diff --git a/tests/run-make/include_bytes_deps/input.md b/tests/run-make/include-bytes-deps/input.md index 2a19b7405f7..2a19b7405f7 100644 --- a/tests/run-make/include_bytes_deps/input.md +++ b/tests/run-make/include-bytes-deps/input.md diff --git a/tests/run-make/include_bytes_deps/input.txt b/tests/run-make/include-bytes-deps/input.txt index cd0875583aa..cd0875583aa 100644 --- a/tests/run-make/include_bytes_deps/input.txt +++ b/tests/run-make/include-bytes-deps/input.txt diff --git a/tests/run-make/include_bytes_deps/main.rs b/tests/run-make/include-bytes-deps/main.rs index 2fd55699d44..2fd55699d44 100644 --- a/tests/run-make/include_bytes_deps/main.rs +++ b/tests/run-make/include-bytes-deps/main.rs diff --git a/tests/run-make/include-bytes-deps/rmake.rs b/tests/run-make/include-bytes-deps/rmake.rs new file mode 100644 index 00000000000..ea371ddae56 --- /dev/null +++ b/tests/run-make/include-bytes-deps/rmake.rs @@ -0,0 +1,13 @@ +// include_bytes! and include_str! in `main.rs` +// should register the included file as of #24423, +// and this test checks that this is still the case. +// See https://github.com/rust-lang/rust/pull/24423 + +use run_make_support::{invalid_utf8_contains, rustc}; + +fn main() { + rustc().emit("dep-info").input("main.rs").run(); + invalid_utf8_contains("main.d", "input.txt"); + invalid_utf8_contains("main.d", "input.bin"); + invalid_utf8_contains("main.d", "input.md"); +} diff --git a/tests/run-make/include_bytes_deps/Makefile b/tests/run-make/include_bytes_deps/Makefile deleted file mode 100644 index 696dfd207bb..00000000000 --- a/tests/run-make/include_bytes_deps/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -# ignore-freebsd - -all: - $(RUSTC) --emit dep-info main.rs - $(CGREP) "input.txt" "input.bin" "input.md" < $(TMPDIR)/main.d diff --git a/tests/run-make/intrinsic-unreachable/Makefile b/tests/run-make/intrinsic-unreachable/Makefile deleted file mode 100644 index ff9cc57098c..00000000000 --- a/tests/run-make/intrinsic-unreachable/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# needs-asm-support -# ignore-windows-msvc -# -# Because of Windows exception handling, the code is not necessarily any shorter. -# https://github.com/llvm-mirror/llvm/commit/64b2297786f7fd6f5fa24cdd4db0298fbf211466 - -all: - $(RUSTC) -O --emit asm exit-ret.rs - $(RUSTC) -O --emit asm exit-unreachable.rs - test `wc -l < $(TMPDIR)/exit-unreachable.s` -lt `wc -l < $(TMPDIR)/exit-ret.s` diff --git a/tests/run-make/intrinsic-unreachable/rmake.rs b/tests/run-make/intrinsic-unreachable/rmake.rs new file mode 100644 index 00000000000..7e78c8288b8 --- /dev/null +++ b/tests/run-make/intrinsic-unreachable/rmake.rs @@ -0,0 +1,20 @@ +// intrinsics::unreachable tells the compiler that a certain point in the code +// is not reachable by any means, which enables some useful optimizations. +// In this test, exit-unreachable contains this instruction and exit-ret does not, +// which means the emitted artifacts should be shorter in length. +// See https://github.com/rust-lang/rust/pull/16970 + +//@ needs-asm-support +//@ ignore-windows +// Reason: Because of Windows exception handling, the code is not necessarily any shorter. + +use run_make_support::{fs_wrapper, rustc}; + +fn main() { + rustc().opt().emit("asm").input("exit-ret.rs").run(); + rustc().opt().emit("asm").input("exit-unreachable.rs").run(); + assert!( + fs_wrapper::read_to_string("exit-unreachable.s").lines().count() + < fs_wrapper::read_to_string("exit-ret.s").lines().count() + ); +} diff --git a/tests/run-make/issue-40535/Makefile b/tests/run-make/issue-40535/Makefile deleted file mode 100644 index 155c8825214..00000000000 --- a/tests/run-make/issue-40535/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -include ../tools.mk - -# The ICE occurred in the following situation: -# * `foo` declares `extern crate bar, baz`, depends only on `bar` (forgetting `baz` in `Cargo.toml`) -# * `bar` declares and depends on `extern crate baz` -# * All crates built in metadata-only mode (`cargo check`) -all: - # cc https://github.com/rust-lang/rust/issues/40623 - $(RUSTC) baz.rs --emit=metadata - $(RUSTC) bar.rs --emit=metadata --extern baz=$(TMPDIR)/libbaz.rmeta - $(RUSTC) foo.rs --emit=metadata --extern bar=$(TMPDIR)/libbar.rmeta 2>&1 | \ - $(CGREP) -v "unexpectedly panicked" - # ^ Succeeds if it doesn't find the ICE message diff --git a/tests/run-make/issue-47384/Makefile b/tests/run-make/issue-47384/Makefile deleted file mode 100644 index afc77cb275a..00000000000 --- a/tests/run-make/issue-47384/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# only-linux -# ignore-cross-compile - -all: main.rs - $(RUSTC) --crate-type lib lib.rs - $(RUSTC) --crate-type cdylib -Clink-args="-Tlinker.ld" main.rs - # Ensure `#[used]` and `KEEP`-ed section is there - objdump -s -j".static" $(TMPDIR)/libmain.so - # Ensure `#[no_mangle]` symbol is there - nm $(TMPDIR)/libmain.so | $(CGREP) bar diff --git a/tests/run-make/llvm-ident/rmake.rs b/tests/run-make/llvm-ident/rmake.rs index f460829288e..9699d0579f6 100644 --- a/tests/run-make/llvm-ident/rmake.rs +++ b/tests/run-make/llvm-ident/rmake.rs @@ -2,9 +2,9 @@ //@ ignore-cross-compile use run_make_support::llvm::llvm_bin_dir; -use run_make_support::{cmd, env_var, llvm_filecheck, read_dir, rustc, source_root}; - -use std::ffi::OsStr; +use run_make_support::{ + cmd, env_var, has_extension, llvm_filecheck, rustc, shallow_find_files, source_root, +}; fn main() { // `-Ccodegen-units=16 -Copt-level=2` is used here to trigger thin LTO @@ -22,20 +22,14 @@ fn main() { // `llvm-dis` is used here since `--emit=llvm-ir` does not emit LLVM IR // for temporary outputs. - let mut files = Vec::new(); - read_dir(".", |path| { - if path.is_file() && path.extension().is_some_and(|ext| ext == OsStr::new("bc")) { - files.push(path.to_path_buf()); - } - }); - cmd(llvm_bin_dir().join("llvm-dis")).args(&files).run(); + let files = shallow_find_files(".", |path| has_extension(path, "bc")); + cmd(llvm_bin_dir().join("llvm-dis")).args(files).run(); // Check LLVM IR files (including temporary outputs) have `!llvm.ident` // named metadata, reusing the related codegen test. let llvm_ident_path = source_root().join("tests/codegen/llvm-ident.rs"); - read_dir(".", |path| { - if path.is_file() && path.extension().is_some_and(|ext| ext == OsStr::new("ll")) { - llvm_filecheck().input_file(path).arg(&llvm_ident_path).run(); - } - }); + let files = shallow_find_files(".", |path| has_extension(path, "ll")); + for file in files { + llvm_filecheck().input_file(file).arg(&llvm_ident_path).run(); + } } diff --git a/tests/run-make/issue-40535/bar.rs b/tests/run-make/metadata-only-crate-no-ice/bar.rs index b02b28f59d9..b02b28f59d9 100644 --- a/tests/run-make/issue-40535/bar.rs +++ b/tests/run-make/metadata-only-crate-no-ice/bar.rs diff --git a/tests/run-make/issue-40535/baz.rs b/tests/run-make/metadata-only-crate-no-ice/baz.rs index 83be6e807e0..83be6e807e0 100644 --- a/tests/run-make/issue-40535/baz.rs +++ b/tests/run-make/metadata-only-crate-no-ice/baz.rs diff --git a/tests/run-make/issue-40535/foo.rs b/tests/run-make/metadata-only-crate-no-ice/foo.rs index 27020266425..27020266425 100644 --- a/tests/run-make/issue-40535/foo.rs +++ b/tests/run-make/metadata-only-crate-no-ice/foo.rs diff --git a/tests/run-make/metadata-only-crate-no-ice/rmake.rs b/tests/run-make/metadata-only-crate-no-ice/rmake.rs new file mode 100644 index 00000000000..e6f852fca41 --- /dev/null +++ b/tests/run-make/metadata-only-crate-no-ice/rmake.rs @@ -0,0 +1,14 @@ +// In a dependency hierarchy, metadata-only crates could cause an Internal +// Compiler Error (ICE) due to a compiler bug - not correctly fetching sources for +// metadata-only crates. This test is a minimal reproduction of a program that triggered +// this bug, and checks that no ICE occurs. +// See https://github.com/rust-lang/rust/issues/40535 + +use run_make_support::rustc; + +fn main() { + rustc().input("baz.rs").emit("metadata").run(); + rustc().input("bar.rs").emit("metadata").extern_("baz", "libbaz.rmeta").run(); + // There should be no internal compiler error. + rustc().input("foo.rs").emit("metadata").extern_("bar", "libbaz.rmeta").run(); +} diff --git a/tests/run-make/msvc-opt-minsize/Makefile b/tests/run-make/msvc-opt-minsize/Makefile deleted file mode 100644 index 32e6e28018f..00000000000 --- a/tests/run-make/msvc-opt-minsize/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs -Copt-level=z 2>&1 - $(call RUN,foo) diff --git a/tests/run-make/msvc-opt-minsize/foo.rs b/tests/run-make/msvc-opt-minsize/foo.rs deleted file mode 100644 index 3f5496c08ee..00000000000 --- a/tests/run-make/msvc-opt-minsize/foo.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(test)] -extern crate test; - -fn foo(x: i32, y: i32) -> i64 { - (x + y) as i64 -} - -#[inline(never)] -fn bar() { - let _f = Box::new(0); - // This call used to trigger an LLVM bug in opt-level z where the base - // pointer gets corrupted, see issue #45034 - let y: fn(i32, i32) -> i64 = test::black_box(foo); - test::black_box(y(1, 2)); -} - -fn main() { - bar(); -} diff --git a/tests/run-make/optimization-remarks-dir-pgo/Makefile b/tests/run-make/optimization-remarks-dir-pgo/Makefile deleted file mode 100644 index 57ffd6e70f0..00000000000 --- a/tests/run-make/optimization-remarks-dir-pgo/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# needs-profiler-support -# ignore-cross-compile - -include ../tools.mk - -PROFILE_DIR=$(TMPDIR)/profiles - -check_hotness: - $(RUSTC) -Cprofile-generate="$(TMPDIR)"/profdata -O foo.rs -o$(TMPDIR)/foo - $(TMPDIR)/foo - "$(LLVM_BIN_DIR)"/llvm-profdata merge \ - -o "$(TMPDIR)"/merged.profdata \ - "$(TMPDIR)"/profdata/*.profraw - $(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata -O foo.rs -Cremark=all -Zremark-dir=$(PROFILE_DIR) - - # Check that PGO hotness is included in the remark files - cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "Hotness" diff --git a/tests/run-make/optimization-remarks-dir-pgo/rmake.rs b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs new file mode 100644 index 00000000000..228c43cc5f1 --- /dev/null +++ b/tests/run-make/optimization-remarks-dir-pgo/rmake.rs @@ -0,0 +1,41 @@ +// This test checks the -Zremark-dir flag, which writes LLVM +// optimization remarks to the YAML format. When using PGO (Profile +// Guided Optimization), the Hotness attribute should be included in +// the output remark files. +// See https://github.com/rust-lang/rust/pull/114439 + +//@ needs-profiler-support +//@ ignore-cross-compile + +use run_make_support::{ + has_extension, has_prefix, invalid_utf8_contains, llvm_profdata, run, rustc, shallow_find_files, +}; + +fn main() { + rustc().profile_generate("profdata").opt().input("foo.rs").output("foo").run(); + run("foo"); + // The profdata filename is a long sequence of numbers, fetch it by prefix and extension + // to keep the test working even if the filename changes. + let profdata_files = shallow_find_files("profdata", |path| { + has_prefix(path, "default") && has_extension(path, "profraw") + }); + let profdata_file = profdata_files.get(0).unwrap(); + llvm_profdata().merge().output("merged.profdata").input(profdata_file).run(); + rustc() + .profile_use("merged.profdata") + .opt() + .input("foo.rs") + .arg("-Cremark=all") + .arg("-Zremark-dir=profiles") + .run(); + // Check that PGO hotness is included in the remark files + let remark_files = shallow_find_files("profiles", |path| { + has_prefix(path, "foo") && has_extension(path, "yaml") + }); + assert!(!remark_files.is_empty()); + for file in remark_files { + if !file.to_str().unwrap().contains("codegen") { + invalid_utf8_contains(file, "Hotness") + }; + } +} diff --git a/tests/run-make/optimization-remarks-dir/Makefile b/tests/run-make/optimization-remarks-dir/Makefile deleted file mode 100644 index a8342c8ad14..00000000000 --- a/tests/run-make/optimization-remarks-dir/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -PROFILE_DIR=$(TMPDIR)/profiles - -all: check_inline check_filter - -check_inline: - $(RUSTC) -O foo.rs --crate-type=lib -Cremark=all -Zremark-dir=$(PROFILE_DIR) - cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "inline" -check_filter: - $(RUSTC) -O foo.rs --crate-type=lib -Cremark=foo -Zremark-dir=$(PROFILE_DIR) - cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e -v "inline" diff --git a/tests/run-make/optimization-remarks-dir/rmake.rs b/tests/run-make/optimization-remarks-dir/rmake.rs new file mode 100644 index 00000000000..afcb8c3e3eb --- /dev/null +++ b/tests/run-make/optimization-remarks-dir/rmake.rs @@ -0,0 +1,39 @@ +// In this test, the function `bar` has #[inline(never)] and the function `foo` +// does not. This test outputs LLVM optimization remarks twice - first for all +// functions (including `bar`, and the `inline` mention), and then for only `foo` +// (should not have the `inline` mention). +// See https://github.com/rust-lang/rust/pull/113040 + +use run_make_support::{ + has_extension, has_prefix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains, + rustc, shallow_find_files, +}; + +fn main() { + rustc() + .opt() + .input("foo.rs") + .crate_type("lib") + .arg("-Cremark=all") + .arg("-Zremark-dir=profiles_all") + .run(); + let all_remark_files = shallow_find_files("profiles_all", |path| { + has_prefix(path, "foo") && has_extension(path, "yaml") && not_contains(path, "codegen") + }); + for file in all_remark_files { + invalid_utf8_contains(file, "inline") + } + rustc() + .opt() + .input("foo.rs") + .crate_type("lib") + .arg("-Cremark=foo") + .arg("-Zremark-dir=profiles_foo") + .run(); + let foo_remark_files = shallow_find_files("profiles_foo", |path| { + has_prefix(path, "foo") && has_extension(path, "yaml") + }); + for file in foo_remark_files { + invalid_utf8_not_contains(file, "inline") + } +} diff --git a/tests/run-make/output-type-permutations/Makefile b/tests/run-make/output-type-permutations/Makefile deleted file mode 100644 index 035033b9fdd..00000000000 --- a/tests/run-make/output-type-permutations/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib - $(call REMOVE_RLIBS,bar) - $(call REMOVE_DYLIBS,bar) - rm $(call STATICLIB,bar) - rm -f $(TMPDIR)/{lib,}bar.{dll.exp,dll.lib,pdb,dll.a} - # Check that $(TMPDIR) is empty. - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=bin - rm $(TMPDIR)/$(call BIN,bar) - rm -f $(TMPDIR)/bar.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link - rm $(TMPDIR)/bar.ll - rm $(TMPDIR)/bar.bc - rm $(TMPDIR)/bar.s - rm $(TMPDIR)/bar.o - rm $(TMPDIR)/$(call BIN,bar) - rm -f $(TMPDIR)/bar.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit asm -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit asm=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=asm=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit llvm-bc -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit llvm-bc=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=llvm-bc=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit llvm-ir -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit llvm-ir=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=llvm-ir=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit obj -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit obj=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --emit=obj=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit link -o $(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --emit link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --emit=link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - rm -f $(TMPDIR)/foo.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=rlib --emit link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=rlib --emit=link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=dylib --emit link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=dylib --emit=link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - rm -f $(TMPDIR)/{lib,}foo.{dll.exp,dll.lib,pdb,dll.a,exe.a} - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] || (ls -1 $(TMPDIR) && exit 1) - - $(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=staticlib --emit link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - $(RUSTC) foo.rs --crate-type=staticlib --emit=link=$(TMPDIR)/foo - rm $(TMPDIR)/foo - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=bin --emit link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - $(RUSTC) foo.rs --crate-type=bin --emit=link=$(TMPDIR)/$(call BIN,foo) - rm $(TMPDIR)/$(call BIN,foo) - rm -f $(TMPDIR)/foo.pdb - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit llvm-ir=$(TMPDIR)/ir \ - --emit link \ - --crate-type=rlib - rm $(TMPDIR)/ir - rm $(TMPDIR)/libbar.rlib - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit asm=$(TMPDIR)/asm \ - --emit llvm-ir=$(TMPDIR)/ir \ - --emit llvm-bc=$(TMPDIR)/bc \ - --emit obj=$(TMPDIR)/obj \ - --emit link=$(TMPDIR)/link \ - --crate-type=staticlib - rm $(TMPDIR)/asm - rm $(TMPDIR)/ir - rm $(TMPDIR)/bc - rm $(TMPDIR)/obj - rm $(TMPDIR)/link - $(RUSTC) foo.rs --emit=asm=$(TMPDIR)/asm \ - --emit llvm-ir=$(TMPDIR)/ir \ - --emit=llvm-bc=$(TMPDIR)/bc \ - --emit obj=$(TMPDIR)/obj \ - --emit=link=$(TMPDIR)/link \ - --crate-type=staticlib - rm $(TMPDIR)/asm - rm $(TMPDIR)/ir - rm $(TMPDIR)/bc - rm $(TMPDIR)/obj - rm $(TMPDIR)/link - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] - - $(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link --crate-type=staticlib - rm $(TMPDIR)/bar.ll - rm $(TMPDIR)/bar.s - rm $(TMPDIR)/bar.o - rm $(call STATICLIB,bar) - mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc - # Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later - # comparison. - - $(RUSTC) foo.rs --emit=llvm-bc,link --crate-type=rlib - cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc - rm $(TMPDIR)/bar.bc - rm $(TMPDIR)/foo.bc - $(call REMOVE_RLIBS,bar) - [ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ] diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs new file mode 100644 index 00000000000..1d1637a744e --- /dev/null +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -0,0 +1,542 @@ +// In 2014, rustc's output flags were reworked to be a lot more modular. +// This test uses these output flags in an expansive variety of combinations +// and syntax styles, checking that compilation is successful and that output +// files are exactly what is expected, no more, no less. +// See https://github.com/rust-lang/rust/pull/12020 + +use run_make_support::{ + bin_name, dynamic_lib_name, filename_not_in_denylist, fs_wrapper, rust_lib_name, rustc, + shallow_find_files, static_lib_name, +}; +use std::path::PathBuf; + +// Each test takes 4 arguments: +// `must_exist`: output files which must be found - if any are absent, the test fails +// `can_exist`: optional output files which will not trigger a failure +// `dir`: the name of the directory where the test happens +// `rustc_invocation`: the rustc command being tested +// Any unexpected output files not listed in `must_exist` or `can_exist` will cause a failure. +fn assert_expected_output_files(expectations: Expectations, rustc_invocation: impl Fn()) { + let Expectations { expected_files: must_exist, allowed_files: can_exist, test_dir: dir } = + expectations; + + fs_wrapper::create_dir(&dir); + rustc_invocation(); + for file in must_exist { + fs_wrapper::remove_file(PathBuf::from(&dir).join(&file)); + } + let actual_output_files = + shallow_find_files(dir, |path| filename_not_in_denylist(path, &can_exist)); + if !&actual_output_files.is_empty() { + dbg!(&actual_output_files); + panic!("unexpected output artifacts detected"); + } +} + +struct Expectations { + /// Output files which must be found. The test fails if any are absent. + expected_files: Vec<String>, + /// Allowed output files which will not trigger a failure. + allowed_files: Vec<String>, + /// Name of the directory where the test happens. + test_dir: String, +} + +macro_rules! s { + ( $( $x:expr ),* ) => { + { + let mut temp_vec = Vec::new(); + $( + temp_vec.push($x.to_string()); + )* + temp_vec + } + }; +} + +fn main() { + let bin_foo = bin_name("foo"); + + assert_expected_output_files( + Expectations { + expected_files: s![ + static_lib_name("bar"), + dynamic_lib_name("bar"), + rust_lib_name("bar") + ], + allowed_files: s![ + "libbar.dll.exp", + "libbar.dll.lib", + "libbar.pdb", + "libbar.dll.a", + "libbar.exe.a", + "bar.dll.exp", + "bar.dll.lib", + "bar.pdb", + "bar.dll.a", + "bar.exe.a" + ], + test_dir: "three-crates".to_string(), + }, + || { + rustc() + .input("foo.rs") + .out_dir("three-crates") + .crate_type("rlib,dylib,staticlib") + .run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s![bin_name("bar")], + allowed_files: s!["bar.pdb"], + test_dir: "bin-crate".to_string(), + }, + || { + rustc().input("foo.rs").crate_type("bin").out_dir("bin-crate").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["bar.ll", "bar.bc", "bar.s", "bar.o", bin_name("bar")], + allowed_files: s!["bar.pdb"], + test_dir: "all-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").out_dir("all-emit").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "asm-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("asm").output("asm-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "asm-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("asm=asm-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "asm-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=asm=asm-emit3/foo").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-ir-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-ir").output("llvm-ir-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-ir-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-ir=llvm-ir-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-ir-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=llvm-ir=llvm-ir-emit3/foo").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-bc-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-bc").output("llvm-bc-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-bc-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("llvm-bc=llvm-bc-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "llvm-bc-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=llvm-bc=llvm-bc-emit3/foo").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "obj-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("obj").output("obj-emit/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "obj-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit("obj=obj-emit2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "obj-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg("--emit=obj=obj-emit3/foo").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s![&bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "link-emit".to_string(), + }, + || { + rustc().input("foo.rs").emit("link").output("link-emit/".to_owned() + &bin_foo).run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![&bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "link-emit2".to_string(), + }, + || { + rustc().input("foo.rs").emit(&format!("link=link-emit2/{bin_foo}")).run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![&bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "link-emit3".to_string(), + }, + || { + rustc().input("foo.rs").arg(&format!("--emit=link=link-emit3/{bin_foo}")).run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "rlib".to_string(), + }, + || { + rustc().crate_type("rlib").input("foo.rs").output("rlib/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "rlib2".to_string(), + }, + || { + rustc().crate_type("rlib").input("foo.rs").emit("link=rlib2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "rlib3".to_string(), + }, + || { + rustc().crate_type("rlib").input("foo.rs").arg("--emit=link=rlib3/foo").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s![ + "libfoo.dll.exp", + "libfoo.dll.lib", + "libfoo.pdb", + "libfoo.dll.a", + "libfoo.exe.a", + "foo.dll.exp", + "foo.dll.lib", + "foo.pdb", + "foo.dll.a", + "foo.exe.a" + ], + test_dir: "dylib".to_string(), + }, + || { + rustc() + .crate_type("dylib") + .input("foo.rs") + .output("dylib/".to_owned() + &bin_foo) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s![ + "libfoo.dll.exp", + "libfoo.dll.lib", + "libfoo.pdb", + "libfoo.dll.a", + "libfoo.exe.a", + "foo.dll.exp", + "foo.dll.lib", + "foo.pdb", + "foo.dll.a", + "foo.exe.a" + ], + test_dir: "dylib2".to_string(), + }, + || { + rustc() + .crate_type("dylib") + .input("foo.rs") + .emit(&format!("link=dylib2/{bin_foo}")) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s![ + "libfoo.dll.exp", + "libfoo.dll.lib", + "libfoo.pdb", + "libfoo.dll.a", + "libfoo.exe.a", + "foo.dll.exp", + "foo.dll.lib", + "foo.pdb", + "foo.dll.a", + "foo.exe.a" + ], + test_dir: "dylib3".to_string(), + }, + || { + rustc() + .crate_type("dylib") + .input("foo.rs") + .arg(&format!("--emit=link=dylib3/{bin_foo}")) + .run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "staticlib".to_string(), + }, + || { + rustc().crate_type("staticlib").input("foo.rs").output("staticlib/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "staticlib2".to_string(), + }, + || { + rustc().crate_type("staticlib").input("foo.rs").emit("link=staticlib2/foo").run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["foo"], + allowed_files: s![], + test_dir: "staticlib3".to_string(), + }, + || { + rustc().crate_type("staticlib").input("foo.rs").arg("--emit=link=staticlib3/foo").run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "bincrate".to_string(), + }, + || { + rustc() + .crate_type("bin") + .input("foo.rs") + .output("bincrate/".to_owned() + &bin_foo) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "bincrate2".to_string(), + }, + || { + rustc() + .crate_type("bin") + .input("foo.rs") + .emit(&format!("link=bincrate2/{bin_foo}")) + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s![bin_foo], + allowed_files: s!["foo.pdb"], + test_dir: "bincrate3".to_string(), + }, + || { + rustc() + .crate_type("bin") + .input("foo.rs") + .arg(&format!("--emit=link=bincrate3/{bin_foo}")) + .run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["ir", rust_lib_name("bar")], + allowed_files: s![], + test_dir: "rlib-ir".to_string(), + }, + || { + rustc() + .input("foo.rs") + .emit("llvm-ir=rlib-ir/ir") + .emit("link") + .crate_type("rlib") + .out_dir("rlib-ir") + .run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["ir", "asm", "bc", "obj", "link"], + allowed_files: s![], + test_dir: "staticlib-all".to_string(), + }, + || { + rustc() + .input("foo.rs") + .emit("asm=staticlib-all/asm") + .emit("llvm-ir=staticlib-all/ir") + .emit("llvm-bc=staticlib-all/bc") + .emit("obj=staticlib-all/obj") + .emit("link=staticlib-all/link") + .crate_type("staticlib") + .run(); + }, + ); + assert_expected_output_files( + Expectations { + expected_files: s!["ir", "asm", "bc", "obj", "link"], + allowed_files: s![], + test_dir: "staticlib-all2".to_string(), + }, + || { + rustc() + .input("foo.rs") + .arg("--emit=asm=staticlib-all2/asm") + .arg("--emit") + .arg("llvm-ir=staticlib-all2/ir") + .arg("--emit=llvm-bc=staticlib-all2/bc") + .arg("--emit") + .arg("obj=staticlib-all2/obj") + .arg("--emit=link=staticlib-all2/link") + .crate_type("staticlib") + .run(); + }, + ); + + assert_expected_output_files( + Expectations { + expected_files: s!["bar.ll", "bar.s", "bar.o", static_lib_name("bar")], + allowed_files: s!["bar.bc"], // keep this one for the next test + test_dir: "staticlib-all3".to_string(), + }, + || { + rustc() + .input("foo.rs") + .emit("asm,llvm-ir,llvm-bc,obj,link") + .crate_type("staticlib") + .out_dir("staticlib-all3") + .run(); + }, + ); + + // the .bc file from the previous test should be equivalent to this one, despite the difference + // in crate type + assert_expected_output_files( + Expectations { + expected_files: s!["bar.bc", rust_lib_name("bar"), "foo.bc"], + allowed_files: s![], + test_dir: "rlib-emits".to_string(), + }, + || { + fs_wrapper::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); + rustc() + .input("foo.rs") + .emit("llvm-bc,link") + .crate_type("rlib") + .out_dir("rlib-emits") + .run(); + assert_eq!( + fs_wrapper::read("rlib-emits/foo.bc"), + fs_wrapper::read("rlib-emits/bar.bc") + ); + }, + ); +} diff --git a/tests/run-make/pgo-gen/Makefile b/tests/run-make/pgo-gen/Makefile deleted file mode 100644 index c1d456986fb..00000000000 --- a/tests/run-make/pgo-gen/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# needs-profiler-support -# ignore-cross-compile - -include ../tools.mk - -COMPILE_FLAGS=-g -Cprofile-generate="$(TMPDIR)" - -all: - $(RUSTC) $(COMPILE_FLAGS) test.rs - $(call RUN,test) || exit 1 - [ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1) diff --git a/tests/run-make/pgo-gen/rmake.rs b/tests/run-make/pgo-gen/rmake.rs new file mode 100644 index 00000000000..ad2f6388e8f --- /dev/null +++ b/tests/run-make/pgo-gen/rmake.rs @@ -0,0 +1,18 @@ +// -C profile-generate, when used with rustc, is supposed to output +// profile files (.profraw) after running a binary to analyze how the compiler +// optimizes code. This test checks that these files are generated. +// See https://github.com/rust-lang/rust/pull/48346 + +//@ needs-profiler-support +//@ ignore-cross-compile + +use run_make_support::{cwd, has_extension, has_prefix, run, rustc, shallow_find_files}; + +fn main() { + rustc().arg("-g").profile_generate(cwd()).input("test.rs").run(); + run("test"); + let profraw_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "default") && has_extension(path, "profraw") + }); + assert!(!profraw_files.is_empty(), "no .profraw file generated"); +} diff --git a/tests/run-make/pgo-use/Makefile b/tests/run-make/pgo-use/Makefile deleted file mode 100644 index 92098a4019c..00000000000 --- a/tests/run-make/pgo-use/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# needs-profiler-support -# ignore-cross-compile - -include ../tools.mk - -# This test makes sure that PGO profiling data leads to cold functions being -# marked as `cold` and hot functions with `inlinehint`. -# The test program contains an `if` were actual execution only ever takes the -# `else` branch. Accordingly, we expect the function that is never called to -# be marked as cold. -# -# Disable the pre-inlining pass (i.e. a pass that does some inlining before -# it adds the profiling instrumentation). Disabling this pass leads to -# rather predictable IR which we need for this test to be stable. - -COMMON_FLAGS=-Copt-level=2 -Ccodegen-units=1 -Cllvm-args=-disable-preinline - -ifeq ($(UNAME),Darwin) -# macOS does not have the `tac` command, but `tail -r` does the same thing -TAC := tail -r -else -# some other platforms don't support the `-r` flag for `tail`, so use `tac` -TAC := tac -endif - -all: - # Compile the test program with instrumentation - $(RUSTC) $(COMMON_FLAGS) -Cprofile-generate="$(TMPDIR)" main.rs - # Run it in order to generate some profiling data - $(call RUN,main some-argument) || exit 1 - # Postprocess the profiling data so it can be used by the compiler - "$(LLVM_BIN_DIR)"/llvm-profdata merge \ - -o "$(TMPDIR)"/merged.profdata \ - "$(TMPDIR)"/default_*.profraw - # Compile the test program again, making use of the profiling data - $(RUSTC) $(COMMON_FLAGS) -Cprofile-use="$(TMPDIR)"/merged.profdata --emit=llvm-ir main.rs - # Check that the generate IR contains some things that we expect - # - # We feed the file into LLVM FileCheck tool *in reverse* so that we see the - # line with the function name before the line with the function attributes. - # FileCheck only supports checking that something matches on the next line, - # but not if something matches on the previous line. - $(TAC) "$(TMPDIR)"/main.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt diff --git a/tests/run-make/pgo-use/rmake.rs b/tests/run-make/pgo-use/rmake.rs new file mode 100644 index 00000000000..0f76aff80d0 --- /dev/null +++ b/tests/run-make/pgo-use/rmake.rs @@ -0,0 +1,55 @@ +// This test makes sure that PGO profiling data leads to cold functions being +// marked as `cold` and hot functions with `inlinehint`. +// The test program contains an `if` where actual execution only ever takes the +// `else` branch. Accordingly, we expect the function that is never called to +// be marked as cold. +// See https://github.com/rust-lang/rust/pull/60262 + +//@ needs-profiler-support +//@ ignore-cross-compile + +use run_make_support::{ + cwd, fs_wrapper, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args, + rustc, shallow_find_files, +}; + +fn main() { + // Compile the test program with instrumentation + // Disable the pre-inlining pass (i.e. a pass that does some inlining before + // it adds the profiling instrumentation). Disabling this pass leads to + // rather predictable IR which we need for this test to be stable. + rustc() + .opt_level("2") + .codegen_units(1) + .arg("-Cllvm-args=-disable-preinline") + .profile_generate(cwd()) + .input("main.rs") + .run(); + // Run it in order to generate some profiling data + run_with_args("main", &["some-argument"]); + // Postprocess the profiling data so it can be used by the compiler + let profraw_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "default") && has_extension(path, "profraw") + }); + let profraw_file = profraw_files.get(0).unwrap(); + llvm_profdata().merge().output("merged.profdata").input(profraw_file).run(); + // Compile the test program again, making use of the profiling data + rustc() + .opt_level("2") + .codegen_units(1) + .arg("-Cllvm-args=-disable-preinline") + .profile_use("merged.profdata") + .emit("llvm-ir") + .input("main.rs") + .run(); + // Check that the generate IR contains some things that we expect. + // We feed the file into LLVM FileCheck tool *with its lines reversed* so that we see the + // line with the function name before the line with the function attributes. + // FileCheck only supports checking that something matches on the next line, + // but not if something matches on the previous line. + let ir = fs_wrapper::read_to_string("main.ll"); + let lines: Vec<_> = ir.lines().rev().collect(); + let mut reversed_ir = lines.join("\n"); + reversed_ir.push('\n'); + llvm_filecheck().patterns("filecheck-patterns.txt").stdin(reversed_ir.as_bytes()).run(); +} diff --git a/tests/run-make/profile/Makefile b/tests/run-make/profile/Makefile deleted file mode 100644 index 7919b18ba74..00000000000 --- a/tests/run-make/profile/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# needs-profiler-support -# ignore-cross-compile - -include ../tools.mk - -all: - $(RUSTC) -g -Z profile test.rs - $(call RUN,test) || exit 1 - [ -e "$(TMPDIR)/test.gcno" ] || (echo "No .gcno file"; exit 1) - [ -e "$(TMPDIR)/test.gcda" ] || (echo "No .gcda file"; exit 1) - $(RUSTC) -g -Z profile -Z profile-emit=$(TMPDIR)/abc/abc.gcda test.rs - $(call RUN,test) || exit 1 - [ -e "$(TMPDIR)/abc/abc.gcda" ] || (echo "gcda file not emitted to defined path"; exit 1) diff --git a/tests/run-make/profile/rmake.rs b/tests/run-make/profile/rmake.rs new file mode 100644 index 00000000000..8d41978baec --- /dev/null +++ b/tests/run-make/profile/rmake.rs @@ -0,0 +1,22 @@ +// This test revolves around the rustc flag -Z profile, which should +// generate a .gcno file (initial profiling information) as well +// as a .gcda file (branch counters). The path where these are emitted +// should also be configurable with -Z profile-emit. This test checks +// that the files are produced, and then that the latter flag is respected. +// See https://github.com/rust-lang/rust/pull/42433 + +//@ ignore-cross-compile +//@ needs-profiler-support + +use run_make_support::{run, rustc}; +use std::path::Path; + +fn main() { + rustc().arg("-g").arg("-Zprofile").input("test.rs").run(); + run("test"); + assert!(Path::new("test.gcno").exists(), "no .gcno file"); + assert!(Path::new("test.gcda").exists(), "no .gcda file"); + rustc().arg("-g").arg("-Zprofile").arg("-Zprofile-emit=abc/abc.gcda").input("test.rs").run(); + run("test"); + assert!(Path::new("abc/abc.gcda").exists(), "gcda file not emitted to defined path"); +} diff --git a/tests/run-make/rlib-chain/Makefile b/tests/run-make/rlib-chain/Makefile deleted file mode 100644 index 7a1f887fa52..00000000000 --- a/tests/run-make/rlib-chain/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) m1.rs - $(RUSTC) m2.rs - $(RUSTC) m3.rs - $(RUSTC) m4.rs - $(call RUN,m4) - rm $(TMPDIR)/*lib - $(call RUN,m4) diff --git a/tests/run-make/rlib-chain/rmake.rs b/tests/run-make/rlib-chain/rmake.rs new file mode 100644 index 00000000000..0947262bf62 --- /dev/null +++ b/tests/run-make/rlib-chain/rmake.rs @@ -0,0 +1,23 @@ +// In this test, m4 depends on m3, which depends on m2, which depends on m1. +// Even though dependencies are chained like this and there is no direct mention +// of m1 or m2 in m4.rs, compilation and execution should still succeed. Unlike +// the dylib-chain test, rlibs do not contain upstream dependencies, and removing +// the libraries still allows m4 to successfully execute. +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{fs_wrapper, run, rust_lib_name, rustc}; + +fn main() { + rustc().input("m1.rs").run(); + rustc().input("m2.rs").run(); + rustc().input("m3.rs").run(); + rustc().input("m4.rs").run(); + run("m4"); + fs_wrapper::remove_file(rust_lib_name("m1")); + fs_wrapper::remove_file(rust_lib_name("m2")); + fs_wrapper::remove_file(rust_lib_name("m3")); + run("m4"); +} diff --git a/tests/run-make/rmeta-preferred/Makefile b/tests/run-make/rmeta-preferred/Makefile deleted file mode 100644 index 3bf12cced29..00000000000 --- a/tests/run-make/rmeta-preferred/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Test that using rlibs and rmeta dep crates work together. Specifically, that -# there can be both an rmeta and an rlib file and rustc will prefer the rmeta -# file. -# -# This behavior is simply making sure this doesn't accidentally change; in this -# case we want to make sure that the rlib isn't being used as that would cause -# bugs in -Zbinary-dep-depinfo (see #68298). - -all: - $(RUSTC) rmeta_aux.rs --crate-type=rlib --emit link,metadata - $(RUSTC) lib.rs --crate-type=rlib --emit dep-info -Zbinary-dep-depinfo - $(CGREP) "librmeta_aux.rmeta" < $(TMPDIR)/lib.d - $(CGREP) -v "librmeta_aux.rlib" < $(TMPDIR)/lib.d diff --git a/tests/run-make/rmeta-preferred/rmake.rs b/tests/run-make/rmeta-preferred/rmake.rs new file mode 100644 index 00000000000..09cba06e2f5 --- /dev/null +++ b/tests/run-make/rmeta-preferred/rmake.rs @@ -0,0 +1,18 @@ +// This test compiles `lib.rs`'s dependency, `rmeta_aux.rs`, as both an rlib +// and an rmeta crate. By default, rustc should give the metadata crate (rmeta) +// precedence over the rust-lib (rlib). This test inspects the contents of the binary +// and that the correct (rmeta) crate was used. +// rlibs being preferred could indicate a resurgence of the -Zbinary-dep-depinfo bug +// seen in #68298. +// See https://github.com/rust-lang/rust/pull/37681 + +//@ ignore-cross-compile + +use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, rustc}; + +fn main() { + rustc().input("rmeta_aux.rs").crate_type("rlib").emit("link,metadata").run(); + rustc().input("lib.rs").crate_type("rlib").emit("dep-info").arg("-Zbinary-dep-depinfo").run(); + invalid_utf8_contains("lib.d", "librmeta_aux.rmeta"); + invalid_utf8_not_contains("lib.d", "librmeta_aux.rlib"); +} diff --git a/tests/run-make/rustdoc-io-error/rmake.rs b/tests/run-make/rustdoc-io-error/rmake.rs index d60e4438e6f..69afea40162 100644 --- a/tests/run-make/rustdoc-io-error/rmake.rs +++ b/tests/run-make/rustdoc-io-error/rmake.rs @@ -6,8 +6,13 @@ // permissions so that it is not writable. We have to take special care to set // the permissions back to normal so that it's able to be deleted later. +//@ ignore-riscv64 +//@ ignore-arm +// FIXME: The riscv64gc-gnu and armhf-gnu build containers run as root, +// and can always write into `inaccessible/tmp`. Ideally, these docker +// containers would use a non-root user, but this leads to issues with +// `mkfs.ext4 -d`, as well as mounting a loop device for the rootfs. //@ ignore-windows - the `set_readonly` functions doesn't work on folders. -//@ ignore-arm - weird file perms on armhf-gnu use run_make_support::{path, rustdoc}; use std::fs; diff --git a/tests/run-make/sepcomp-cci-copies/Makefile b/tests/run-make/sepcomp-cci-copies/Makefile deleted file mode 100644 index df289d0b0b1..00000000000 --- a/tests/run-make/sepcomp-cci-copies/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# Check that cross-crate inlined items are inlined in all compilation units -# that refer to them, and not in any other compilation units. -# Note that we have to pass `-C codegen-units=6` because up to two CGUs may be -# created for each source module (see `rustc_const_eval::monomorphize::partitioning`). - -all: - $(RUSTC) cci_lib.rs - $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=6 \ - -Z inline-in-all-cgus - [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*cci_fn)" -eq "2" ] diff --git a/tests/run-make/sepcomp-cci-copies/rmake.rs b/tests/run-make/sepcomp-cci-copies/rmake.rs new file mode 100644 index 00000000000..612a73977fe --- /dev/null +++ b/tests/run-make/sepcomp-cci-copies/rmake.rs @@ -0,0 +1,17 @@ +// Check that cross-crate inlined items are inlined in all compilation units +// that refer to them, and not in any other compilation units. +// Note that we have to pass `-C codegen-units=6` because up to two CGUs may be +// created for each source module (see `rustc_const_eval::monomorphize::partitioning`). +// See https://github.com/rust-lang/rust/pull/16367 + +use run_make_support::{ + count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc, + shallow_find_files, +}; + +fn main() { + rustc().input("cci_lib.rs").run(); + rustc().input("foo.rs").emit("llvm-ir").codegen_units(6).arg("-Zinline-in-all-cgus").run(); + let re = regex::Regex::new(r#"define\ .*cci_fn"#).unwrap(); + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2); +} diff --git a/tests/run-make/sepcomp-inlining/Makefile b/tests/run-make/sepcomp-inlining/Makefile deleted file mode 100644 index 327aeb75e5e..00000000000 --- a/tests/run-make/sepcomp-inlining/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include ../tools.mk - -# Test that #[inline] functions still get inlined across compilation unit -# boundaries. Compilation should produce three IR files, but only the two -# compilation units that have a usage of the #[inline] function should -# contain a definition. Also, the non-#[inline] function should be defined -# in only one compilation unit. - -all: - $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \ - -Z inline-in-all-cgus - [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ i32\ .*inlined)" -eq "0" ] - [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ internal\ i32\ .*inlined)" -eq "2" ] - [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ hidden\ i32\ .*normal)" -eq "1" ] - [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c declare\ hidden\ i32\ .*normal)" -eq "2" ] diff --git a/tests/run-make/sepcomp-inlining/rmake.rs b/tests/run-make/sepcomp-inlining/rmake.rs new file mode 100644 index 00000000000..de7551b9a51 --- /dev/null +++ b/tests/run-make/sepcomp-inlining/rmake.rs @@ -0,0 +1,23 @@ +// Test that #[inline] functions still get inlined across compilation unit +// boundaries. Compilation should produce three IR files, but only the two +// compilation units that have a usage of the #[inline] function should +// contain a definition. Also, the non-#[inline] function should be defined +// in only one compilation unit. +// See https://github.com/rust-lang/rust/pull/16367 + +use run_make_support::{ + count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc, + shallow_find_files, +}; + +fn main() { + rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run(); + let re = regex::Regex::new(r#"define\ i32\ .*inlined"#).unwrap(); + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 0); + let re = regex::Regex::new(r#"define\ internal\ .*inlined"#).unwrap(); + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2); + let re = regex::Regex::new(r#"define\ hidden\ i32\ .*normal"#).unwrap(); + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 1); + let re = regex::Regex::new(r#"declare\ hidden\ i32\ .*normal"#).unwrap(); + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2); +} diff --git a/tests/run-make/sepcomp-separate/Makefile b/tests/run-make/sepcomp-separate/Makefile deleted file mode 100644 index 62cf54a88fb..00000000000 --- a/tests/run-make/sepcomp-separate/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# Test that separate compilation actually puts code into separate compilation -# units. `foo.rs` defines `magic_fn` in three different modules, which should -# wind up in three different compilation units. - -all: - $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 - [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*magic_fn)" -eq "3" ] diff --git a/tests/run-make/sepcomp-separate/rmake.rs b/tests/run-make/sepcomp-separate/rmake.rs new file mode 100644 index 00000000000..6f1d22424b5 --- /dev/null +++ b/tests/run-make/sepcomp-separate/rmake.rs @@ -0,0 +1,15 @@ +// Test that separate compilation actually puts code into separate compilation +// units. `foo.rs` defines `magic_fn` in three different modules, which should +// wind up in three different compilation units. +// See https://github.com/rust-lang/rust/pull/16367 + +use run_make_support::{ + count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc, + shallow_find_files, +}; + +fn main() { + rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run(); + let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap(); + assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3); +} diff --git a/tests/run-make/test-harness/Makefile b/tests/run-make/test-harness/Makefile deleted file mode 100644 index ee8c9294f91..00000000000 --- a/tests/run-make/test-harness/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - # check that #[cfg_attr(..., ignore)] does the right thing. - $(RUSTC) --test test-ignore-cfg.rs --cfg ignorecfg - $(call RUN,test-ignore-cfg) | $(CGREP) 'shouldnotignore ... ok' 'shouldignore ... ignored' - $(call RUN,test-ignore-cfg --quiet) | $(CGREP) -e "^i\.$$" - $(call RUN,test-ignore-cfg --quiet) | $(CGREP) -v 'should' diff --git a/tests/run-make/test-harness/rmake.rs b/tests/run-make/test-harness/rmake.rs new file mode 100644 index 00000000000..30b3d00f4d1 --- /dev/null +++ b/tests/run-make/test-harness/rmake.rs @@ -0,0 +1,25 @@ +// The way test suites run can be modified using configuration flags, +// ignoring certain tests while running others. This test contains two +// functions, one which must run and the other which must not. The standard +// output is checked to verify that the ignore configuration is doing its job, +// and that output is successfully minimized with the --quiet flag. +// See https://github.com/rust-lang/rust/commit/f7ebe23ae185991b0fee05b32fbb3e29b89a41bf + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{run, run_with_args, rustc}; + +fn main() { + rustc().arg("--test").input("test-ignore-cfg.rs").cfg("ignorecfg").run(); + // check that #[cfg_attr(..., ignore)] does the right thing. + run("test-ignore-cfg") + .assert_stdout_contains("shouldnotignore ... ok") + .assert_stdout_contains("shouldignore ... ignored"); + assert_eq!( + // One of the lines is exactly "i." + run_with_args("test-ignore-cfg", &["--quiet"]).stdout_utf8().lines().find(|&x| x == "i."), + Some("i.") + ); + run_with_args("test-ignore-cfg", &["--quiet"]).assert_stdout_not_contains("should"); +} diff --git a/tests/rustdoc-json/lifetime/outlives_in_param.rs b/tests/rustdoc-json/lifetime/outlives_in_param.rs new file mode 100644 index 00000000000..f6db93c9183 --- /dev/null +++ b/tests/rustdoc-json/lifetime/outlives_in_param.rs @@ -0,0 +1,8 @@ +// ignore-tidy-linelength + +// @count '$.index[*][?(@.name=="outlives")].inner.function.generics.params[*]' 2 +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].name' \"\'a\" +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].kind.lifetime.outlives' [] +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[1].name' '"T"' +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[1].kind.type.bounds' '[{"outlives": "'\''a"}]' +pub fn outlives<'a, T: 'a>() {} diff --git a/tests/rustdoc-json/lifetime/outlives_in_where.rs b/tests/rustdoc-json/lifetime/outlives_in_where.rs new file mode 100644 index 00000000000..ca3e1a150ce --- /dev/null +++ b/tests/rustdoc-json/lifetime/outlives_in_where.rs @@ -0,0 +1,24 @@ +// ignore-tidy-linelength + +// @is '$.index[*][?(@.name=="on_lifetimes")].inner.function.generics.where_predicates' '[{"lifetime_predicate": {"lifetime": "'\''all", "outlives": ["'\''a", "'\''b", "'\''c"]}}]' +pub fn on_lifetimes<'a, 'b, 'c, 'all>() +where + 'all: 'a + 'b + 'c, +{ +} + +// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[*]' 2 +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[0].name' \"\'a\" +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[0].kind.lifetime.outlives' [] +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].name' '"T"' +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' [] +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' [] +// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[*]' 1 +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.type.generic' '"T"' +// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[*]' 1 +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[0].outlives' \"\'a\" +pub fn on_trait<'a, T>() +where + T: 'a, +{ +} diff --git a/tests/rustdoc-json/trait_alias.rs b/tests/rustdoc-json/trait_alias.rs new file mode 100644 index 00000000000..dc930550ef1 --- /dev/null +++ b/tests/rustdoc-json/trait_alias.rs @@ -0,0 +1,18 @@ +// ignore-tidy-linelength +#![feature(trait_alias)] + +// @set StrLike = "$.index[*][?(@.name=='StrLike')].id" +// @is "$.index[*][?(@.name=='StrLike')].visibility" \"public\" +// @has "$.index[*][?(@.name=='StrLike')].inner.trait_alias" +// @is "$.index[*][?(@.name=='StrLike')].span.filename" $FILE +pub trait StrLike = AsRef<str>; + +// @is "$.index[*][?(@.name=='f')].inner.function.decl.output.impl_trait[0].trait_bound.trait.id" $StrLike +pub fn f() -> impl StrLike { + "heya" +} + +// @!is "$.index[*][?(@.name=='g')].inner.function.decl.output.impl_trait[0].trait_bound.trait.id" $StrLike +pub fn g() -> impl AsRef<str> { + "heya" +} diff --git a/tests/rustdoc-json/type_alias.rs b/tests/rustdoc-json/type_alias.rs new file mode 100644 index 00000000000..7a938c50ba0 --- /dev/null +++ b/tests/rustdoc-json/type_alias.rs @@ -0,0 +1,15 @@ +// @set IntVec = "$.index[*][?(@.name=='IntVec')].id" +// @is "$.index[*][?(@.name=='IntVec')].visibility" \"public\" +// @has "$.index[*][?(@.name=='IntVec')].inner.type_alias" +// @is "$.index[*][?(@.name=='IntVec')].span.filename" $FILE +pub type IntVec = Vec<u32>; + +// @is "$.index[*][?(@.name=='f')].inner.function.decl.output.resolved_path.id" $IntVec +pub fn f() -> IntVec { + vec![0; 32] +} + +// @!is "$.index[*][?(@.name=='g')].inner.function.decl.output.resolved_path.id" $IntVec +pub fn g() -> Vec<u32> { + vec![0; 32] +} diff --git a/tests/rustdoc-ui/diagnostic-width.stderr b/tests/rustdoc-ui/diagnostic-width.stderr index c1cc4898ac5..d8c4934a576 100644 --- a/tests/rustdoc-ui/diagnostic-width.stderr +++ b/tests/rustdoc-ui/diagnostic-width.stderr @@ -2,7 +2,7 @@ error: this URL is not a hyperlink --> $DIR/diagnostic-width.rs:4:41 | LL | ... a http://link.com - | ^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://link.com>` + | ^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links note: the lint level is defined here @@ -10,6 +10,10 @@ note: the lint level is defined here | LL | ...ny(rustdoc::bare_url... | ^^^^^^^^^^^^^^^^^^ +help: use an automatic link instead + | +LL | /// This is a long line that contains a <http://link.com> + | + + error: aborting due to 1 previous error diff --git a/tests/rustdoc-ui/include-str-bare-urls.stderr b/tests/rustdoc-ui/include-str-bare-urls.stderr index a4234196b23..53da2411874 100644 --- a/tests/rustdoc-ui/include-str-bare-urls.stderr +++ b/tests/rustdoc-ui/include-str-bare-urls.stderr @@ -2,7 +2,7 @@ error: this URL is not a hyperlink --> $DIR/auxiliary/include-str-bare-urls.md:1:11 | LL | HEADS UP! https://example.com MUST SHOW UP IN THE STDERR FILE! - | ^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com>` + | ^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links note: the lint level is defined here @@ -10,6 +10,10 @@ note: the lint level is defined here | LL | #![deny(rustdoc::bare_urls)] | ^^^^^^^^^^^^^^^^^^ +help: use an automatic link instead + | +LL | HEADS UP! <https://example.com> MUST SHOW UP IN THE STDERR FILE! + | + + error: aborting due to 1 previous error diff --git a/tests/rustdoc-ui/lints/bare-urls.stderr b/tests/rustdoc-ui/lints/bare-urls.stderr index ccf52cd0b93..ddfc387eaf6 100644 --- a/tests/rustdoc-ui/lints/bare-urls.stderr +++ b/tests/rustdoc-ui/lints/bare-urls.stderr @@ -2,7 +2,7 @@ error: this URL is not a hyperlink --> $DIR/bare-urls.rs:5:5 | LL | /// https://somewhere.com - | ^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com>` + | ^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links note: the lint level is defined here @@ -10,134 +10,202 @@ note: the lint level is defined here | LL | #![deny(rustdoc::bare_urls)] | ^^^^^^^^^^^^^^^^^^ +help: use an automatic link instead + | +LL | /// <https://somewhere.com> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:7:5 | LL | /// https://somewhere.com/a - | ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a>` + | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com/a> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:9:5 | LL | /// https://www.somewhere.com - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://www.somewhere.com> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:11:5 | LL | /// https://www.somewhere.com/a - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com/a>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://www.somewhere.com/a> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:13:5 | LL | /// https://subdomain.example.com - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://subdomain.example.com>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://subdomain.example.com> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:15:5 | LL | /// https://somewhere.com? - | ^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?>` + | ^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com?> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:17:5 | LL | /// https://somewhere.com/a? - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?>` + | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com/a?> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:19:5 | LL | /// https://somewhere.com?hello=12 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com?hello=12> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:21:5 | LL | /// https://somewhere.com/a?hello=12 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com/a?hello=12> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:23:5 | LL | /// https://example.com?hello=12#xyz - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com?hello=12#xyz>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://example.com?hello=12#xyz> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:25:5 | LL | /// https://example.com/a?hello=12#xyz - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a?hello=12#xyz>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://example.com/a?hello=12#xyz> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:27:5 | LL | /// https://example.com#xyz - | ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com#xyz>` + | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://example.com#xyz> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:29:5 | LL | /// https://example.com/a#xyz - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a#xyz>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://example.com/a#xyz> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:31:5 | LL | /// https://somewhere.com?hello=12&bye=11 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com?hello=12&bye=11> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:33:5 | LL | /// https://somewhere.com/a?hello=12&bye=11 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com/a?hello=12&bye=11> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:35:5 | LL | /// https://somewhere.com?hello=12&bye=11#xyz - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11#xyz>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// <https://somewhere.com?hello=12&bye=11#xyz> + | + + error: this URL is not a hyperlink --> $DIR/bare-urls.rs:37:10 | LL | /// hey! https://somewhere.com/a?hello=12&bye=11#xyz - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11#xyz>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links +help: use an automatic link instead + | +LL | /// hey! <https://somewhere.com/a?hello=12&bye=11#xyz> + | + + error: aborting due to 17 previous errors diff --git a/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr b/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr index ee9b67cb91b..88807dfb495 100644 --- a/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr +++ b/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr @@ -29,7 +29,7 @@ error: this URL is not a hyperlink --> $DIR/renamed-lint-still-applies.rs:9:5 | LL | //! http://example.com - | ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.com>` + | ^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links note: the lint level is defined here @@ -37,6 +37,10 @@ note: the lint level is defined here | LL | #![deny(rustdoc::non_autolinks)] | ^^^^^^^^^^^^^^^^^^^^^^ +help: use an automatic link instead + | +LL | //! <http://example.com> + | + + error: aborting due to 2 previous errors; 2 warnings emitted diff --git a/tests/rustdoc-ui/unportable-markdown.rs b/tests/rustdoc-ui/unportable-markdown.rs new file mode 100644 index 00000000000..8035e680f3c --- /dev/null +++ b/tests/rustdoc-ui/unportable-markdown.rs @@ -0,0 +1,63 @@ +// https://internals.rust-lang.org/t/proposal-migrate-the-syntax-of-rustdoc-markdown-footnotes-to-be-compatible-with-the-syntax-used-in-github/18929 +// +// A series of test cases for CommonMark corner cases that pulldown-cmark 0.11 fixes. +// +// This version of the lint is targeted at two especially-common cases where docs got broken. +// Other differences in parsing should not warn. +#![allow(rustdoc::broken_intra_doc_links)] +#![deny(rustdoc::unportable_markdown)] + +/// <https://github.com/pulldown-cmark/pulldown-cmark/pull/654> +/// +/// Test footnote [^foot]. +/// +/// [^foot]: This is nested within the footnote now, but didn't used to be. +/// +/// This is a multi-paragraph footnote. +pub struct GfmFootnotes; + +/// <https://github.com/pulldown-cmark/pulldown-cmark/pull/773> +/// +/// test [^foo][^bar] +//~^ ERROR unportable markdown +/// +/// [^foo]: test +/// [^bar]: test2 +pub struct FootnoteSmashedName; + +/// <https://github.com/pulldown-cmark/pulldown-cmark/pull/829> +/// +/// - _t +/// # test +/// t_ +pub struct NestingCornerCase; + +/// <https://github.com/pulldown-cmark/pulldown-cmark/pull/650> +/// +/// *~~__emphasis strike strong__~~* ~~*__strike emphasis strong__*~~ +pub struct Emphasis1; + +/// <https://github.com/pulldown-cmark/pulldown-cmark/pull/732> +/// +/// | +/// | +pub struct NotEnoughTable; + +/// <https://github.com/pulldown-cmark/pulldown-cmark/pull/675> +/// +/// foo +/// >bar +//~^ ERROR unportable markdown +pub struct BlockQuoteNoSpace; + +/// Negative test. +/// +/// foo +/// > bar +pub struct BlockQuoteSpace; + +/// Negative test. +/// +/// >bar +/// baz +pub struct BlockQuoteNoSpaceStart; diff --git a/tests/rustdoc-ui/unportable-markdown.stderr b/tests/rustdoc-ui/unportable-markdown.stderr new file mode 100644 index 00000000000..b524aca25ae --- /dev/null +++ b/tests/rustdoc-ui/unportable-markdown.stderr @@ -0,0 +1,39 @@ +error: unportable markdown + --> $DIR/unportable-markdown.rs:21:10 + | +LL | /// test [^foo][^bar] + | ^^^^^^ + | + = help: confusing footnote reference and link +note: the lint level is defined here + --> $DIR/unportable-markdown.rs:8:9 + | +LL | #![deny(rustdoc::unportable_markdown)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: if it should not be a footnote, escape it + | +LL | /// test \[^foo][^bar] + | + +help: if the footnote is intended, add a space + | +LL | /// test [^foo] [^bar] + | + + +error: unportable markdown + --> $DIR/unportable-markdown.rs:49:5 + | +LL | /// >bar + | ^ + | + = help: confusing block quote with no space after the `>` marker +help: if the quote is intended, add a space + | +LL | /// > bar + | + +help: if it should not be a quote, escape it + | +LL | /// \>bar + | + + +error: aborting due to 2 previous errors + diff --git a/tests/ui-fulldeps/deriving-global.rs b/tests/ui-fulldeps/deriving-global.rs index 7783010be44..0ba149c9ad6 100644 --- a/tests/ui-fulldeps/deriving-global.rs +++ b/tests/ui-fulldeps/deriving-global.rs @@ -17,18 +17,21 @@ mod submod { // if any of these are implemented without global calls for any // function calls, then being in a submodule will (correctly) // cause errors about unrecognised module `std` (or `extra`) + #[allow(dead_code)] #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)] enum A { A1(usize), A2(isize), } + #[allow(dead_code)] #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)] struct B { x: usize, y: isize, } + #[allow(dead_code)] #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)] struct C(usize, isize); } diff --git a/tests/ui-fulldeps/deriving-hygiene.rs b/tests/ui-fulldeps/deriving-hygiene.rs index a3a6f9e022e..f948d6ac544 100644 --- a/tests/ui-fulldeps/deriving-hygiene.rs +++ b/tests/ui-fulldeps/deriving-hygiene.rs @@ -20,6 +20,7 @@ pub const s: u8 = 1; pub const state: u8 = 1; pub const cmp: u8 = 1; +#[allow(dead_code)] #[derive(Ord, Eq, PartialOrd, PartialEq, Debug, Decodable, Encodable, Hash)] struct Foo {} diff --git a/tests/ui-fulldeps/run-compiler-twice.rs b/tests/ui-fulldeps/run-compiler-twice.rs index 02748626723..720fc42cc57 100644 --- a/tests/ui-fulldeps/run-compiler-twice.rs +++ b/tests/ui-fulldeps/run-compiler-twice.rs @@ -17,6 +17,7 @@ extern crate rustc_span; use std::path::{Path, PathBuf}; +use rustc_interface::Linker; use rustc_interface::interface; use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes}; use rustc_span::FileName; @@ -78,8 +79,10 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path interface::run_compiler(config, |compiler| { let linker = compiler.enter(|queries| { - queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?; - queries.codegen_and_build_linker() + queries.global_ctxt()?.enter(|tcx| { + tcx.analysis(())?; + Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend) + }) }); linker.unwrap().link(&compiler.sess, &*compiler.codegen_backend).unwrap(); }); diff --git a/tests/ui/abi/compatibility.rs b/tests/ui/abi/compatibility.rs index 1be9ada2822..ca78604edd8 100644 --- a/tests/ui/abi/compatibility.rs +++ b/tests/ui/abi/compatibility.rs @@ -271,6 +271,11 @@ test_abi_compatible!(zst_unit, Zst, ()); test_abi_compatible!(zst_array, Zst, [u8; 0]); test_abi_compatible!(nonzero_int, NonZero<i32>, i32); +// `#[repr(C)]` enums should not change ABI based on individual variant inhabitedness. +// (However, this is *not* a guarantee. We only guarantee same layout, not same ABI.) +enum Void {} +test_abi_compatible!(repr_c_enum_void, ReprCEnum<Void>, ReprCEnum<ReprCUnion<Void>>); + // `DispatchFromDyn` relies on ABI compatibility. // This is interesting since these types are not `repr(transparent)`. So this is not part of our // public ABI guarantees, but is relied on by the compiler. diff --git a/tests/ui/argument-suggestions/basic.stderr b/tests/ui/argument-suggestions/basic.stderr index c74186285f9..ea58ca97cfa 100644 --- a/tests/ui/argument-suggestions/basic.stderr +++ b/tests/ui/argument-suggestions/basic.stderr @@ -16,16 +16,18 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/basic.rs:21:5 | LL | extra(""); - | ^^^^^ -- - | | - | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^^^ -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/basic.rs:14:4 | LL | fn extra() {} | ^^^^^ +help: remove the extra argument + | +LL - extra(""); +LL + extra(); + | error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/basic.rs:22:5 diff --git a/tests/ui/argument-suggestions/exotic-calls.stderr b/tests/ui/argument-suggestions/exotic-calls.stderr index ff795b507f2..aca3b8a3433 100644 --- a/tests/ui/argument-suggestions/exotic-calls.stderr +++ b/tests/ui/argument-suggestions/exotic-calls.stderr @@ -2,61 +2,69 @@ error[E0057]: this function takes 0 arguments but 1 argument was supplied --> $DIR/exotic-calls.rs:2:5 | LL | t(1i32); - | ^ ---- - | | - | unexpected argument of type `i32` - | help: remove the extra argument + | ^ ---- unexpected argument of type `i32` | note: callable defined here --> $DIR/exotic-calls.rs:1:11 | LL | fn foo<T: Fn()>(t: T) { | ^^^^ +help: remove the extra argument + | +LL - t(1i32); +LL + t(); + | error[E0057]: this function takes 0 arguments but 1 argument was supplied --> $DIR/exotic-calls.rs:7:5 | LL | t(1i32); - | ^ ---- - | | - | unexpected argument of type `i32` - | help: remove the extra argument + | ^ ---- unexpected argument of type `i32` | note: type parameter defined here --> $DIR/exotic-calls.rs:6:11 | LL | fn bar(t: impl Fn()) { | ^^^^^^^^^ +help: remove the extra argument + | +LL - t(1i32); +LL + t(); + | error[E0057]: this function takes 0 arguments but 1 argument was supplied --> $DIR/exotic-calls.rs:16:5 | LL | baz()(1i32) - | ^^^^^ ---- - | | - | unexpected argument of type `i32` - | help: remove the extra argument + | ^^^^^ ---- unexpected argument of type `i32` | note: opaque type defined here --> $DIR/exotic-calls.rs:11:13 | LL | fn baz() -> impl Fn() { | ^^^^^^^^^ +help: remove the extra argument + | +LL - baz()(1i32) +LL + baz()() + | error[E0057]: this function takes 0 arguments but 1 argument was supplied --> $DIR/exotic-calls.rs:22:5 | LL | x(1i32); - | ^ ---- - | | - | unexpected argument of type `i32` - | help: remove the extra argument + | ^ ---- unexpected argument of type `i32` | note: closure defined here --> $DIR/exotic-calls.rs:21:13 | LL | let x = || {}; | ^^ +help: remove the extra argument + | +LL - x(1i32); +LL + x(); + | error: aborting due to 4 previous errors diff --git a/tests/ui/argument-suggestions/extra_arguments.stderr b/tests/ui/argument-suggestions/extra_arguments.stderr index 5ad8e35920a..dec3da75186 100644 --- a/tests/ui/argument-suggestions/extra_arguments.stderr +++ b/tests/ui/argument-suggestions/extra_arguments.stderr @@ -2,16 +2,18 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/extra_arguments.rs:19:3 | LL | empty(""); - | ^^^^^ -- - | | - | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^^^ -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/extra_arguments.rs:1:4 | LL | fn empty() {} | ^^^^^ +help: remove the extra argument + | +LL - empty(""); +LL + empty(); + | error[E0061]: this function takes 0 arguments but 2 arguments were supplied --> $DIR/extra_arguments.rs:20:3 @@ -36,31 +38,35 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:22:3 | LL | one_arg(1, 1); - | ^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:2:4 | LL | fn one_arg<T>(_a: T) {} | ^^^^^^^ ----- +help: remove the extra argument + | +LL - one_arg(1, 1); +LL + one_arg(1); + | error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:23:3 | LL | one_arg(1, ""); - | ^^^^^^^ ---- - | | | - | | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^^^^^ -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/extra_arguments.rs:2:4 | LL | fn one_arg<T>(_a: T) {} | ^^^^^^^ ----- +help: remove the extra argument + | +LL - one_arg(1, ""); +LL + one_arg(1); + | error[E0061]: this function takes 1 argument but 3 arguments were supplied --> $DIR/extra_arguments.rs:24:3 @@ -85,61 +91,69 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:26:3 | LL | two_arg_same(1, 1, 1); - | ^^^^^^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:3:4 | LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL - two_arg_same(1, 1, 1); +LL + two_arg_same(1, 1); + | error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:27:3 | LL | two_arg_same(1, 1, 1.0); - | ^^^^^^^^^^^^ ----- - | | | - | | unexpected argument of type `{float}` - | help: remove the extra argument + | ^^^^^^^^^^^^ --- unexpected argument of type `{float}` | note: function defined here --> $DIR/extra_arguments.rs:3:4 | LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL - two_arg_same(1, 1, 1.0); +LL + two_arg_same(1, 1); + | error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:29:3 | LL | two_arg_diff(1, 1, ""); - | ^^^^^^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:4:4 | LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL - two_arg_diff(1, 1, ""); +LL + two_arg_diff(1, ""); + | error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:30:3 | LL | two_arg_diff(1, "", ""); - | ^^^^^^^^^^^^ ---- - | | | - | | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^^^^^^^^^^ -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/extra_arguments.rs:4:4 | LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL - two_arg_diff(1, "", ""); +LL + two_arg_diff(1, ""); + | error[E0061]: this function takes 2 arguments but 4 arguments were supplied --> $DIR/extra_arguments.rs:31:3 @@ -183,70 +197,75 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:35:3 | LL | two_arg_same(1, 1, ""); - | ^^^^^^^^^^^^ -------- - | | | - | | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^^^^^^^^^^ -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/extra_arguments.rs:3:4 | LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL - two_arg_same(1, 1, ""); +LL + two_arg_same(1, 1); + | error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:36:3 | LL | two_arg_diff(1, 1, ""); - | ^^^^^^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:4:4 | LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL - two_arg_diff(1, 1, ""); +LL + two_arg_diff(1, ""); + | error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:37:3 | -LL | two_arg_same( - | ^^^^^^^^^^^^ -LL | 1, -LL | 1, - | ______- -LL | | "" - | | -- - | |_____|| - | |help: remove the extra argument - | unexpected argument of type `&'static str` +LL | two_arg_same( + | ^^^^^^^^^^^^ +... +LL | "" + | -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/extra_arguments.rs:3:4 | LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL - 1, +LL - "" +LL + 1 + | error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/extra_arguments.rs:43:3 | -LL | two_arg_diff( - | ^^^^^^^^^^^^ -LL | 1, - | ______- -LL | | 1, - | | - - | | | - | |_____unexpected argument of type `{integer}` - | help: remove the extra argument +LL | two_arg_diff( + | ^^^^^^^^^^^^ +LL | 1, +LL | 1, + | - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:4:4 | LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL - 1, + | error[E0061]: this function takes 0 arguments but 2 arguments were supplied --> $DIR/extra_arguments.rs:8:9 @@ -310,61 +329,69 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:53:3 | LL | one_arg(1, panic!()); - | ^^^^^^^ ---------- - | | | - | | unexpected argument - | help: remove the extra argument + | ^^^^^^^ -------- unexpected argument | note: function defined here --> $DIR/extra_arguments.rs:2:4 | LL | fn one_arg<T>(_a: T) {} | ^^^^^^^ ----- +help: remove the extra argument + | +LL - one_arg(1, panic!()); +LL + one_arg(1); + | error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:54:3 | LL | one_arg(panic!(), 1); - | ^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:2:4 | LL | fn one_arg<T>(_a: T) {} | ^^^^^^^ ----- +help: remove the extra argument + | +LL - one_arg(panic!(), 1); +LL + one_arg(panic!()); + | error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:55:3 | LL | one_arg(stringify!($e), 1); - | ^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:2:4 | LL | fn one_arg<T>(_a: T) {} | ^^^^^^^ ----- +help: remove the extra argument + | +LL - one_arg(stringify!($e), 1); +LL + one_arg(stringify!($e)); + | error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:60:3 | LL | one_arg(for _ in 1.. {}, 1); - | ^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/extra_arguments.rs:2:4 | LL | fn one_arg<T>(_a: T) {} | ^^^^^^^ ----- +help: remove the extra argument + | +LL - one_arg(for _ in 1.. {}, 1); +LL + one_arg(for _ in 1.. {}); + | error: aborting due to 22 previous errors diff --git a/tests/ui/argument-suggestions/suggest-better-removing-issue-126246.rs b/tests/ui/argument-suggestions/suggest-better-removing-issue-126246.rs new file mode 100644 index 00000000000..fa1802283c3 --- /dev/null +++ b/tests/ui/argument-suggestions/suggest-better-removing-issue-126246.rs @@ -0,0 +1,21 @@ +fn add_one(x: i32) -> i32 { + x + 1 +} + +fn add_two(x: i32, y: i32) -> i32 { + x + y +} + +fn main() { + add_one(2, 2); //~ ERROR this function takes 1 argument but 2 arguments were supplied + add_one(no_such_local, 10); //~ ERROR cannot find value `no_such_local` in this scope + //~| ERROR this function takes 1 argument but 2 arguments were supplied + add_one(10, no_such_local); //~ ERROR cannot find value `no_such_local` in this scope + //~| ERROR this function takes 1 argument but 2 arguments were supplied + add_two(10, no_such_local, 10); //~ ERROR cannot find value `no_such_local` in this scope + //~| ERROR this function takes 2 arguments but 3 arguments were supplied + add_two(no_such_local, 10, 10); //~ ERROR cannot find value `no_such_local` in this scope + //~| ERROR this function takes 2 arguments but 3 arguments were supplied + add_two(10, 10, no_such_local); //~ ERROR cannot find value `no_such_local` in this scope + //~| ERROR this function takes 2 arguments but 3 arguments were supplied +} diff --git a/tests/ui/argument-suggestions/suggest-better-removing-issue-126246.stderr b/tests/ui/argument-suggestions/suggest-better-removing-issue-126246.stderr new file mode 100644 index 00000000000..dc293945eb6 --- /dev/null +++ b/tests/ui/argument-suggestions/suggest-better-removing-issue-126246.stderr @@ -0,0 +1,136 @@ +error[E0425]: cannot find value `no_such_local` in this scope + --> $DIR/suggest-better-removing-issue-126246.rs:11:13 + | +LL | add_one(no_such_local, 10); + | ^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `no_such_local` in this scope + --> $DIR/suggest-better-removing-issue-126246.rs:13:17 + | +LL | add_one(10, no_such_local); + | ^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `no_such_local` in this scope + --> $DIR/suggest-better-removing-issue-126246.rs:15:17 + | +LL | add_two(10, no_such_local, 10); + | ^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `no_such_local` in this scope + --> $DIR/suggest-better-removing-issue-126246.rs:17:13 + | +LL | add_two(no_such_local, 10, 10); + | ^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `no_such_local` in this scope + --> $DIR/suggest-better-removing-issue-126246.rs:19:21 + | +LL | add_two(10, 10, no_such_local); + | ^^^^^^^^^^^^^ not found in this scope + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/suggest-better-removing-issue-126246.rs:10:5 + | +LL | add_one(2, 2); + | ^^^^^^^ - unexpected argument of type `{integer}` + | +note: function defined here + --> $DIR/suggest-better-removing-issue-126246.rs:1:4 + | +LL | fn add_one(x: i32) -> i32 { + | ^^^^^^^ ------ +help: remove the extra argument + | +LL - add_one(2, 2); +LL + add_one(2); + | + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/suggest-better-removing-issue-126246.rs:11:5 + | +LL | add_one(no_such_local, 10); + | ^^^^^^^ ------------- unexpected argument + | +note: function defined here + --> $DIR/suggest-better-removing-issue-126246.rs:1:4 + | +LL | fn add_one(x: i32) -> i32 { + | ^^^^^^^ ------ +help: remove the extra argument + | +LL - add_one(no_such_local, 10); +LL + add_one(10); + | + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/suggest-better-removing-issue-126246.rs:13:5 + | +LL | add_one(10, no_such_local); + | ^^^^^^^ ------------- unexpected argument + | +note: function defined here + --> $DIR/suggest-better-removing-issue-126246.rs:1:4 + | +LL | fn add_one(x: i32) -> i32 { + | ^^^^^^^ ------ +help: remove the extra argument + | +LL - add_one(10, no_such_local); +LL + add_one(10); + | + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/suggest-better-removing-issue-126246.rs:15:5 + | +LL | add_two(10, no_such_local, 10); + | ^^^^^^^ ------------- unexpected argument + | +note: function defined here + --> $DIR/suggest-better-removing-issue-126246.rs:5:4 + | +LL | fn add_two(x: i32, y: i32) -> i32 { + | ^^^^^^^ ------ ------ +help: remove the extra argument + | +LL - add_two(10, no_such_local, 10); +LL + add_two(10, 10); + | + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/suggest-better-removing-issue-126246.rs:17:5 + | +LL | add_two(no_such_local, 10, 10); + | ^^^^^^^ ------------- unexpected argument + | +note: function defined here + --> $DIR/suggest-better-removing-issue-126246.rs:5:4 + | +LL | fn add_two(x: i32, y: i32) -> i32 { + | ^^^^^^^ ------ ------ +help: remove the extra argument + | +LL - add_two(no_such_local, 10, 10); +LL + add_two(10, 10); + | + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/suggest-better-removing-issue-126246.rs:19:5 + | +LL | add_two(10, 10, no_such_local); + | ^^^^^^^ ------------- unexpected argument + | +note: function defined here + --> $DIR/suggest-better-removing-issue-126246.rs:5:4 + | +LL | fn add_two(x: i32, y: i32) -> i32 { + | ^^^^^^^ ------ ------ +help: remove the extra argument + | +LL - add_two(10, 10, no_such_local); +LL + add_two(10, 10); + | + +error: aborting due to 11 previous errors + +Some errors have detailed explanations: E0061, E0425. +For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/assign-imm-local-twice.rs b/tests/ui/assign-imm-local-twice.rs index b50f6ab5deb..b2dfeb564d9 100644 --- a/tests/ui/assign-imm-local-twice.rs +++ b/tests/ui/assign-imm-local-twice.rs @@ -1,7 +1,7 @@ fn test() { let v: isize; //~^ HELP consider making this binding mutable - //~| SUGGESTION mut v + //~| SUGGESTION mut v = 1; //~ NOTE first assignment println!("v={}", v); v = 2; //~ ERROR cannot assign twice to immutable variable diff --git a/tests/ui/assign-imm-local-twice.stderr b/tests/ui/assign-imm-local-twice.stderr index d92485de68f..fda3aa3de1b 100644 --- a/tests/ui/assign-imm-local-twice.stderr +++ b/tests/ui/assign-imm-local-twice.stderr @@ -1,14 +1,16 @@ error[E0384]: cannot assign twice to immutable variable `v` --> $DIR/assign-imm-local-twice.rs:7:5 | -LL | let v: isize; - | - help: consider making this binding mutable: `mut v` -... LL | v = 1; | ----- first assignment to `v` LL | println!("v={}", v); LL | v = 2; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut v: isize; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs index c23eff79ce2..a8c8a85c5aa 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs @@ -13,7 +13,7 @@ fn foo<T: Trait<method(i32): Send>>() {} fn bar<T: Trait<method() -> (): Send>>() {} //~^ ERROR return type not allowed with return type notation -fn baz<T: Trait<method(..): Send>>() {} -//~^ ERROR return type notation uses `()` instead of `(..)` for elided arguments +fn baz<T: Trait<method(): Send>>() {} +//~^ ERROR return type notation arguments must be elided with `..` fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr index d95249efe40..7e1695984f1 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr @@ -1,9 +1,3 @@ -error: return type notation uses `()` instead of `(..)` for elided arguments - --> $DIR/bad-inputs-and-output.rs:16:24 - | -LL | fn baz<T: Trait<method(..): Send>>() {} - | ^^ help: remove the `..` - warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/bad-inputs-and-output.rs:3:12 | @@ -25,5 +19,11 @@ error: return type not allowed with return type notation LL | fn bar<T: Trait<method() -> (): Send>>() {} | ^^^^^^ help: remove the return type +error: return type notation arguments must be elided with `..` + --> $DIR/bad-inputs-and-output.rs:16:23 + | +LL | fn baz<T: Trait<method(): Send>>() {} + | ^^ help: add `..`: `(..)` + error: aborting due to 3 previous errors; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs b/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs new file mode 100644 index 00000000000..f507d82afec --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs @@ -0,0 +1,26 @@ +#![feature(return_type_notation)] +//~^ WARN the feature `return_type_notation` is incomplete + +trait Tr { + const CONST: usize; + + fn method() -> impl Sized; +} + +fn foo<T: Tr>() +where + T::method(..): Send, + //~^ ERROR return type notation not allowed in this position yet + //~| ERROR expected type, found function + <T as Tr>::method(..): Send, + //~^ ERROR return type notation not allowed in this position yet + //~| ERROR expected associated type, found associated function `Tr::method` +{ + let _ = T::CONST::(..); + //~^ ERROR return type notation not allowed in this position yet + let _: T::method(..); + //~^ ERROR return type notation not allowed in this position yet + //~| ERROR expected type, found function +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr b/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr new file mode 100644 index 00000000000..cb45de59c7e --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr @@ -0,0 +1,66 @@ +error[E0575]: expected associated type, found associated function `Tr::method` + --> $DIR/bare-path.rs:15:5 + | +LL | <T as Tr>::method(..): Send, + | ^^^^^^^^^^^^^^^^^^^^^ not a associated type + +warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/bare-path.rs:1:12 + | +LL | #![feature(return_type_notation)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:19:23 + | +LL | let _ = T::CONST::(..); + | ^^^^ + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:21:21 + | +LL | let _: T::method(..); + | ^^^^ + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:12:14 + | +LL | T::method(..): Send, + | ^^^^ + +error: return type notation not allowed in this position yet + --> $DIR/bare-path.rs:15:22 + | +LL | <T as Tr>::method(..): Send, + | ^^^^ + +error: expected type, found function + --> $DIR/bare-path.rs:12:8 + | +LL | T::method(..): Send, + | ^^^^^^ unexpected function + | +note: the associated function is defined here + --> $DIR/bare-path.rs:7:5 + | +LL | fn method() -> impl Sized; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected type, found function + --> $DIR/bare-path.rs:21:15 + | +LL | let _: T::method(..); + | ^^^^^^ unexpected function + | +note: the associated function is defined here + --> $DIR/bare-path.rs:7:5 + | +LL | fn method() -> impl Sized; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0575`. diff --git a/tests/ui/associated-type-bounds/return-type-notation/basic.rs b/tests/ui/associated-type-bounds/return-type-notation/basic.rs index 9755fd01c97..be489a19a7a 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/basic.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/basic.rs @@ -17,7 +17,7 @@ async fn foo<T: Foo>() -> Result<(), ()> { fn is_send(_: impl Send) {} fn test< - #[cfg(with)] T: Foo<method(): Send>, + #[cfg(with)] T: Foo<method(..): Send>, #[cfg(without)] T: Foo, >() { is_send(foo::<T>()); diff --git a/tests/ui/associated-type-bounds/return-type-notation/equality.rs b/tests/ui/associated-type-bounds/return-type-notation/equality.rs index ae38dce1818..95c16fa1e3f 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/equality.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/equality.rs @@ -9,7 +9,7 @@ trait Trait { async fn method() {} } -fn test<T: Trait<method() = Box<dyn Future<Output = ()>>>>() {} +fn test<T: Trait<method(..) = Box<dyn Future<Output = ()>>>>() {} //~^ ERROR return type notation is not allowed to use type equality fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/equality.stderr b/tests/ui/associated-type-bounds/return-type-notation/equality.stderr index d432e957735..d76b1bd1c05 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/equality.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/equality.stderr @@ -10,8 +10,8 @@ LL | #![feature(return_type_notation)] error: return type notation is not allowed to use type equality --> $DIR/equality.rs:12:18 | -LL | fn test<T: Trait<method() = Box<dyn Future<Output = ()>>>>() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn test<T: Trait<method(..) = Box<dyn Future<Output = ()>>>>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs index 11728b87990..4d026b7d1d8 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.rs @@ -9,7 +9,7 @@ trait HealthCheck { async fn do_health_check_par<HC>(hc: HC) where - HC: HealthCheck<check(): Send> + Send + 'static, + HC: HealthCheck<check(..): Send> + Send + 'static, //~^ ERROR return type notation is not allowed for functions that have const parameters { } diff --git a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr index 8a3f037d003..12f32a75eda 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/issue-120208-higher-ranked-const.stderr @@ -13,8 +13,8 @@ error: return type notation is not allowed for functions that have const paramet LL | async fn check<const N: usize>() -> bool; | -------------- const parameter declared here ... -LL | HC: HealthCheck<check(): Send> + Send + 'static, - | ^^^^^^^^^^^^^ +LL | HC: HealthCheck<check(..): Send> + Send + 'static, + | ^^^^^^^^^^^^^^^ error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/missing.rs b/tests/ui/associated-type-bounds/return-type-notation/missing.rs index 9a8b77d00b7..3a04a56339b 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/missing.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/missing.rs @@ -7,7 +7,7 @@ trait Trait { async fn method() {} } -fn bar<T: Trait<methid(): Send>>() {} +fn bar<T: Trait<methid(..): Send>>() {} //~^ ERROR associated function `methid` not found for `Trait` fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/missing.stderr b/tests/ui/associated-type-bounds/return-type-notation/missing.stderr index db9cb9f49a3..5cb8e2642f5 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/missing.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/missing.stderr @@ -10,7 +10,7 @@ LL | #![feature(return_type_notation)] error[E0220]: associated function `methid` not found for `Trait` --> $DIR/missing.rs:10:17 | -LL | fn bar<T: Trait<methid(): Send>>() {} +LL | fn bar<T: Trait<methid(..): Send>>() {} | ^^^^^^ help: there is an associated function with a similar name: `method` error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs index db5f6fe389e..d283c6eab37 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.rs @@ -5,7 +5,7 @@ trait Trait { fn method() {} } -fn test<T: Trait<method(): Send>>() {} +fn test<T: Trait<method(..): Send>>() {} //~^ ERROR return type notation used on function that is not `async` and does not return `impl Trait` fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr index 3e307c5f42c..79ced3c96ed 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/non-rpitit.stderr @@ -13,8 +13,8 @@ error: return type notation used on function that is not `async` and does not re LL | fn method() {} | ----------- this function must be `async` or return `impl Trait` ... -LL | fn test<T: Trait<method(): Send>>() {} - | ^^^^^^^^^^^^^^ +LL | fn test<T: Trait<method(..): Send>>() {} + | ^^^^^^^^^^^^^^^^ | = note: function returns `()`, which is not compatible with associated type return bounds diff --git a/tests/ui/associated-types/defaults-specialization.stderr b/tests/ui/associated-types/defaults-specialization.stderr index 7ef433d859f..b4ed99f36f4 100644 --- a/tests/ui/associated-types/defaults-specialization.stderr +++ b/tests/ui/associated-types/defaults-specialization.stderr @@ -12,10 +12,7 @@ error[E0053]: method `make` has an incompatible type for trait --> $DIR/defaults-specialization.rs:19:18 | LL | fn make() -> u8 { 0 } - | ^^ - | | - | expected associated type, found `u8` - | help: change the output type to match the trait: `<A<T> as Tr>::Ty` + | ^^ expected associated type, found `u8` | note: type in trait --> $DIR/defaults-specialization.rs:9:18 @@ -24,6 +21,10 @@ LL | fn make() -> Self::Ty { | ^^^^^^^^ = note: expected signature `fn() -> <A<T> as Tr>::Ty` found signature `fn() -> u8` +help: change the output type to match the trait + | +LL | fn make() -> <A<T> as Tr>::Ty { 0 } + | ~~~~~~~~~~~~~~~~ error[E0053]: method `make` has an incompatible type for trait --> $DIR/defaults-specialization.rs:35:18 @@ -32,10 +33,7 @@ LL | default type Ty = bool; | ----------------------- associated type is `default` and may be overridden LL | LL | fn make() -> bool { true } - | ^^^^ - | | - | expected associated type, found `bool` - | help: change the output type to match the trait: `<B<T> as Tr>::Ty` + | ^^^^ expected associated type, found `bool` | note: type in trait --> $DIR/defaults-specialization.rs:9:18 @@ -44,6 +42,10 @@ LL | fn make() -> Self::Ty { | ^^^^^^^^ = note: expected signature `fn() -> <B<T> as Tr>::Ty` found signature `fn() -> bool` +help: change the output type to match the trait + | +LL | fn make() -> <B<T> as Tr>::Ty { true } + | ~~~~~~~~~~~~~~~~ error[E0308]: mismatched types --> $DIR/defaults-specialization.rs:10:9 diff --git a/tests/ui/associated-types/issue-22560.stderr b/tests/ui/associated-types/issue-22560.stderr index 46e6e3951a5..834040490f9 100644 --- a/tests/ui/associated-types/issue-22560.stderr +++ b/tests/ui/associated-types/issue-22560.stderr @@ -35,9 +35,13 @@ LL | trait Add<Rhs=Self> { | ------------------- type parameter `Rhs` must be specified for this ... LL | type Test = dyn Add + Sub; - | ^^^ help: set the type parameter to the desired type: `Add<Rhs>` + | ^^^ | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | type Test = dyn Add<Rhs> + Sub; + | +++++ error[E0393]: the type parameter `Rhs` must be explicitly specified --> $DIR/issue-22560.rs:9:23 @@ -46,9 +50,13 @@ LL | trait Sub<Rhs=Self> { | ------------------- type parameter `Rhs` must be specified for this ... LL | type Test = dyn Add + Sub; - | ^^^ help: set the type parameter to the desired type: `Sub<Rhs>` + | ^^^ | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | type Test = dyn Add + Sub<Rhs>; + | +++++ error: aborting due to 4 previous errors diff --git a/tests/ui/async-await/in-trait/async-generics-and-bounds.stderr b/tests/ui/async-await/in-trait/async-generics-and-bounds.stderr index 3cc35b21409..b547da7126a 100644 --- a/tests/ui/async-await/in-trait/async-generics-and-bounds.stderr +++ b/tests/ui/async-await/in-trait/async-generics-and-bounds.stderr @@ -1,29 +1,29 @@ -error[E0311]: the parameter type `U` may not live long enough +error[E0311]: the parameter type `T` may not live long enough --> $DIR/async-generics-and-bounds.rs:9:5 | LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash; | ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | - | | the parameter type `U` must be valid for the anonymous lifetime as defined here... + | | the parameter type `T` must be valid for the anonymous lifetime as defined here... | ...so that the reference type `&(T, U)` does not outlive the data it points at | help: consider adding an explicit lifetime bound | -LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: Debug + Sized, U: Hash, U: 'a; +LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: Debug + Sized, U: Hash, T: 'a; | ++++ ++ ++ +++++++ -error[E0311]: the parameter type `T` may not live long enough +error[E0311]: the parameter type `U` may not live long enough --> $DIR/async-generics-and-bounds.rs:9:5 | LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash; | ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | - | | the parameter type `T` must be valid for the anonymous lifetime as defined here... + | | the parameter type `U` must be valid for the anonymous lifetime as defined here... | ...so that the reference type `&(T, U)` does not outlive the data it points at | help: consider adding an explicit lifetime bound | -LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: Debug + Sized, U: Hash, T: 'a; +LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: Debug + Sized, U: Hash, U: 'a; | ++++ ++ ++ +++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/async-await/in-trait/async-generics.stderr b/tests/ui/async-await/in-trait/async-generics.stderr index 3b27f8fe2f0..2e29a9bcc77 100644 --- a/tests/ui/async-await/in-trait/async-generics.stderr +++ b/tests/ui/async-await/in-trait/async-generics.stderr @@ -1,29 +1,29 @@ -error[E0311]: the parameter type `U` may not live long enough +error[E0311]: the parameter type `T` may not live long enough --> $DIR/async-generics.rs:6:5 | LL | async fn foo(&self) -> &(T, U); | ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^ | | | - | | the parameter type `U` must be valid for the anonymous lifetime as defined here... + | | the parameter type `T` must be valid for the anonymous lifetime as defined here... | ...so that the reference type `&(T, U)` does not outlive the data it points at | help: consider adding an explicit lifetime bound | -LL | async fn foo<'a>(&'a self) -> &'a (T, U) where U: 'a; +LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: 'a; | ++++ ++ ++ +++++++++++ -error[E0311]: the parameter type `T` may not live long enough +error[E0311]: the parameter type `U` may not live long enough --> $DIR/async-generics.rs:6:5 | LL | async fn foo(&self) -> &(T, U); | ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^ | | | - | | the parameter type `T` must be valid for the anonymous lifetime as defined here... + | | the parameter type `U` must be valid for the anonymous lifetime as defined here... | ...so that the reference type `&(T, U)` does not outlive the data it points at | help: consider adding an explicit lifetime bound | -LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: 'a; +LL | async fn foo<'a>(&'a self) -> &'a (T, U) where U: 'a; | ++++ ++ ++ +++++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/async-await/issue-61452.stderr b/tests/ui/async-await/issue-61452.stderr index 3f623ba8ad2..b7b1e380c9e 100644 --- a/tests/ui/async-await/issue-61452.stderr +++ b/tests/ui/async-await/issue-61452.stderr @@ -13,12 +13,14 @@ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/issue-61452.rs:9:5 | LL | pub async fn g(x: usize) { - | - - | | - | first assignment to `x` - | help: consider making this binding mutable: `mut x` + | - first assignment to `x` LL | x += 1; | ^^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | pub async fn g(mut x: usize) { + | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/async-await/return-type-notation/issue-110963-early.rs b/tests/ui/async-await/return-type-notation/issue-110963-early.rs index 4090912f528..46b8fbf6f86 100644 --- a/tests/ui/async-await/return-type-notation/issue-110963-early.rs +++ b/tests/ui/async-await/return-type-notation/issue-110963-early.rs @@ -9,7 +9,7 @@ trait HealthCheck { async fn do_health_check_par<HC>(hc: HC) where - HC: HealthCheck<check(): Send> + Send + 'static, + HC: HealthCheck<check(..): Send> + Send + 'static, { spawn(async move { let mut hc = hc; diff --git a/tests/ui/async-await/return-type-notation/issue-110963-late.rs b/tests/ui/async-await/return-type-notation/issue-110963-late.rs index e0e59b6c6ad..cb9c0b97f1e 100644 --- a/tests/ui/async-await/return-type-notation/issue-110963-late.rs +++ b/tests/ui/async-await/return-type-notation/issue-110963-late.rs @@ -10,7 +10,7 @@ trait HealthCheck { async fn do_health_check_par<HC>(hc: HC) where - HC: HealthCheck<check(): Send> + Send + 'static, + HC: HealthCheck<check(..): Send> + Send + 'static, { spawn(async move { let mut hc = hc; diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs index bee9ad2516e..24041ed0807 100644 --- a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs @@ -16,7 +16,7 @@ impl Foo for Bar { async fn bar(&self) {} } -fn build<T>(_: T) where T: Foo<bar(): Send> {} +fn build<T>(_: T) where T: Foo<bar(..): Send> {} fn main() { build(Bar); diff --git a/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs b/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs index 365ca574006..2f6e04c3853 100644 --- a/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs +++ b/tests/ui/async-await/return-type-notation/rtn-implied-in-supertrait.rs @@ -16,7 +16,7 @@ trait Foo { async fn bar(&self) -> i32; } -trait SendFoo: Foo<bar(): Send> + Send {} +trait SendFoo: Foo<bar(..): Send> + Send {} fn foobar(foo: impl SendFoo) -> JoinHandle<i32> { spawn(async move { diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs index 637678692bd..1e971d0aea7 100644 --- a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs +++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs @@ -7,7 +7,7 @@ trait Super1<'a> { fn bar<'b>() -> bool; } -impl Super1<'_, bar(): Send> for () {} +impl Super1<'_, bar(..): Send> for () {} //~^ ERROR associated item constraints are not allowed here //~| ERROR not all trait items implemented diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr index 54960ae60bc..b23dbc37a55 100644 --- a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr +++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr @@ -10,13 +10,13 @@ LL | #![feature(return_type_notation)] error[E0229]: associated item constraints are not allowed here --> $DIR/rtn-in-impl-signature.rs:10:17 | -LL | impl Super1<'_, bar(): Send> for () {} - | ^^^^^^^^^^^ associated item constraint not allowed here +LL | impl Super1<'_, bar(..): Send> for () {} + | ^^^^^^^^^^^^^ associated item constraint not allowed here | help: consider removing this associated item constraint | -LL | impl Super1<'_, bar(): Send> for () {} - | ~~~~~~~~~~~~~ +LL | impl Super1<'_, bar(..): Send> for () {} + | ~~~~~~~~~~~~~~~ error[E0046]: not all trait items implemented, missing: `bar` --> $DIR/rtn-in-impl-signature.rs:10:1 @@ -24,8 +24,8 @@ error[E0046]: not all trait items implemented, missing: `bar` LL | fn bar<'b>() -> bool; | --------------------- `bar` from trait ... -LL | impl Super1<'_, bar(): Send> for () {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation +LL | impl Super1<'_, bar(..): Send> for () {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs index fa647ea0bc7..452568f3e46 100644 --- a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs +++ b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.rs @@ -22,7 +22,7 @@ impl Foo for () {} fn test<T>() where - T: Foo<test(): Send>, + T: Foo<test(..): Send>, //~^ ERROR ambiguous associated function `test` in bounds of `Foo` { } diff --git a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr index 4003aad6d03..9a6fdd7f2ac 100644 --- a/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr +++ b/tests/ui/async-await/return-type-notation/super-method-bound-ambig.stderr @@ -16,8 +16,8 @@ LL | async fn test(); LL | async fn test(); | ---------------- ambiguous `test` from `Super2` ... -LL | T: Foo<test(): Send>, - | ^^^^^^^^^^^^ ambiguous associated function `test` +LL | T: Foo<test(..): Send>, + | ^^^^^^^^^^^^^^ ambiguous associated function `test` error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/async-await/return-type-notation/super-method-bound.rs b/tests/ui/async-await/return-type-notation/super-method-bound.rs index ad7ed5b283c..1aa8258a09b 100644 --- a/tests/ui/async-await/return-type-notation/super-method-bound.rs +++ b/tests/ui/async-await/return-type-notation/super-method-bound.rs @@ -16,7 +16,7 @@ impl Foo for () {} fn test<T>() where - T: Foo<test(): Send>, + T: Foo<test(..): Send>, { } diff --git a/tests/ui/async-await/return-type-notation/supertrait-bound.rs b/tests/ui/async-await/return-type-notation/supertrait-bound.rs index adb286a21d2..9c74c10b333 100644 --- a/tests/ui/async-await/return-type-notation/supertrait-bound.rs +++ b/tests/ui/async-await/return-type-notation/supertrait-bound.rs @@ -6,6 +6,6 @@ trait IntFactory { fn stream(&self) -> impl Iterator<Item = i32>; } -trait SendIntFactory: IntFactory<stream(): Send> + Send {} +trait SendIntFactory: IntFactory<stream(..): Send> + Send {} fn main() {} diff --git a/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs b/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs index 328cd8d2ad0..06a966df445 100644 --- a/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs +++ b/tests/ui/async-await/return-type-notation/ty-or-ct-params.rs @@ -11,7 +11,7 @@ trait Foo { fn test<T>() where - T: Foo<bar(): Send, baz(): Send>, + T: Foo<bar(..): Send, baz(..): Send>, //~^ ERROR return type notation is not allowed for functions that have const parameters //~| ERROR return type notation is not allowed for functions that have type parameters { diff --git a/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr b/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr index da94d9d1e6d..1c000bc6c33 100644 --- a/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr +++ b/tests/ui/async-await/return-type-notation/ty-or-ct-params.stderr @@ -13,17 +13,17 @@ error: return type notation is not allowed for functions that have type paramete LL | async fn bar<T>() {} | - type parameter declared here ... -LL | T: Foo<bar(): Send, baz(): Send>, - | ^^^^^^^^^^^ +LL | T: Foo<bar(..): Send, baz(..): Send>, + | ^^^^^^^^^^^^^ error: return type notation is not allowed for functions that have const parameters - --> $DIR/ty-or-ct-params.rs:14:25 + --> $DIR/ty-or-ct-params.rs:14:27 | LL | async fn baz<const N: usize>() {} | -------------- const parameter declared here ... -LL | T: Foo<bar(): Send, baz(): Send>, - | ^^^^^^^^^^^ +LL | T: Foo<bar(..): Send, baz(..): Send>, + | ^^^^^^^^^^^^^ error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/borrowck/alias-liveness/rtn-static.rs b/tests/ui/borrowck/alias-liveness/rtn-static.rs index 37f634a8e23..6aa5d8fc7a1 100644 --- a/tests/ui/borrowck/alias-liveness/rtn-static.rs +++ b/tests/ui/borrowck/alias-liveness/rtn-static.rs @@ -7,7 +7,7 @@ trait Foo { fn borrow(&mut self) -> impl Sized + '_; } -fn live_past_borrow<T: Foo<borrow(): 'static>>(mut t: T) { +fn live_past_borrow<T: Foo<borrow(..): 'static>>(mut t: T) { let x = t.borrow(); drop(t); drop(x); @@ -15,7 +15,7 @@ fn live_past_borrow<T: Foo<borrow(): 'static>>(mut t: T) { // Test that the `'_` item bound in `borrow` does not cause us to // overlook the `'static` RTN bound. -fn overlapping_mut<T: Foo<borrow(): 'static>>(mut t: T) { +fn overlapping_mut<T: Foo<borrow(..): 'static>>(mut t: T) { let x = t.borrow(); let x = t.borrow(); } diff --git a/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr b/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr index a7748209187..4b5b368287e 100644 --- a/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr +++ b/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr @@ -12,11 +12,13 @@ LL | let mut x = 0; error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/borrow-raw-address-of-mutability.rs:11:17 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -LL | let mut f = || { LL | let y = &raw mut x; | ^^^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable --> $DIR/borrow-raw-address-of-mutability.rs:21:5 diff --git a/tests/ui/borrowck/borrowck-closures-unique.stderr b/tests/ui/borrowck/borrowck-closures-unique.stderr index 23d3cc0e76f..613df9f2100 100644 --- a/tests/ui/borrowck/borrowck-closures-unique.stderr +++ b/tests/ui/borrowck/borrowck-closures-unique.stderr @@ -43,10 +43,13 @@ LL | c1; error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/borrowck-closures-unique.rs:43:38 | -LL | fn e(x: &'static mut isize) { - | - help: consider changing this to be mutable: `mut x` LL | let c1 = |y: &'static mut isize| x = y; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn e(mut x: &'static mut isize) { + | +++ error: aborting due to 4 previous errors diff --git a/tests/ui/borrowck/borrowck-match-binding-is-assignment.stderr b/tests/ui/borrowck/borrowck-match-binding-is-assignment.stderr index 98ffa7f6ffa..e164ea44aa4 100644 --- a/tests/ui/borrowck/borrowck-match-binding-is-assignment.stderr +++ b/tests/ui/borrowck/borrowck-match-binding-is-assignment.stderr @@ -9,11 +9,11 @@ LL | x += 1; help: consider making this binding mutable | LL | mut x => { - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | ref mut x => { - | ~~~~~~~~~ + | +++++++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/borrowck-match-binding-is-assignment.rs:20:13 @@ -26,11 +26,11 @@ LL | x += 1; help: consider making this binding mutable | LL | E::Foo(mut x) => { - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | E::Foo(ref mut x) => { - | ~~~~~~~~~ + | +++++++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/borrowck-match-binding-is-assignment.rs:26:13 @@ -43,11 +43,11 @@ LL | x += 1; help: consider making this binding mutable | LL | S { bar: mut x } => { - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | S { bar: ref mut x } => { - | ~~~~~~~~~ + | +++++++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/borrowck-match-binding-is-assignment.rs:32:13 @@ -60,11 +60,11 @@ LL | x += 1; help: consider making this binding mutable | LL | (mut x,) => { - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | (ref mut x,) => { - | ~~~~~~~~~ + | +++++++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/borrowck-match-binding-is-assignment.rs:38:13 @@ -77,11 +77,11 @@ LL | x += 1; help: consider making this binding mutable | LL | [mut x,_,_] => { - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | [ref mut x,_,_] => { - | ~~~~~~~~~ + | +++++++ error: aborting due to 5 previous errors diff --git a/tests/ui/borrowck/immutable-arg.stderr b/tests/ui/borrowck/immutable-arg.stderr index 84a480f6410..fb75172532f 100644 --- a/tests/ui/borrowck/immutable-arg.stderr +++ b/tests/ui/borrowck/immutable-arg.stderr @@ -1,10 +1,13 @@ error[E0384]: cannot assign to immutable argument `_x` --> $DIR/immutable-arg.rs:2:5 | -LL | fn foo(_x: u32) { - | -- help: consider making this binding mutable: `mut _x` LL | _x = 4; | ^^^^^^ cannot assign to immutable argument + | +help: consider making this binding mutable + | +LL | fn foo(mut _x: u32) { + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/issue-111554.stderr b/tests/ui/borrowck/issue-111554.stderr index 6b7a42e4959..b3e8caae343 100644 --- a/tests/ui/borrowck/issue-111554.stderr +++ b/tests/ui/borrowck/issue-111554.stderr @@ -19,10 +19,13 @@ LL | || bar(&mut self); error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-111554.rs:21:16 | -LL | pub fn quux(self) { - | ---- help: consider changing this to be mutable: `mut self` LL | || bar(&mut self); | ^^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | pub fn quux(mut self) { + | +++ error: aborting due to 4 previous errors diff --git a/tests/ui/borrowck/issue-33819.stderr b/tests/ui/borrowck/issue-33819.stderr index 41c9d6aac76..e5f6df26bc1 100644 --- a/tests/ui/borrowck/issue-33819.stderr +++ b/tests/ui/borrowck/issue-33819.stderr @@ -2,10 +2,13 @@ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable --> $DIR/issue-33819.rs:4:34 | LL | Some(ref v) => { let a = &mut v; }, - | ^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here + | ^^^^^^ cannot borrow as mutable + | +help: try removing `&mut` here + | +LL - Some(ref v) => { let a = &mut v; }, +LL + Some(ref v) => { let a = v; }, + | error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/issue-45199.rs b/tests/ui/borrowck/issue-45199.rs index ded46e56e34..b38967524fa 100644 --- a/tests/ui/borrowck/issue-45199.rs +++ b/tests/ui/borrowck/issue-45199.rs @@ -1,7 +1,7 @@ fn test_drop_replace() { let b: Box<isize>; //~^ HELP consider making this binding mutable - //~| SUGGESTION mut b + //~| SUGGESTION mut b = Box::new(1); //~ NOTE first assignment b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` //~| NOTE cannot assign twice to immutable @@ -10,13 +10,13 @@ fn test_drop_replace() { fn test_call() { let b = Box::new(1); //~ NOTE first assignment //~| HELP consider making this binding mutable - //~| SUGGESTION mut b + //~| SUGGESTION mut b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` //~| NOTE cannot assign twice to immutable } fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable - //~| SUGGESTION mut b + //~| SUGGESTION mut b = Box::new(2); //~ ERROR cannot assign to immutable argument `b` //~| NOTE cannot assign to immutable argument } diff --git a/tests/ui/borrowck/issue-45199.stderr b/tests/ui/borrowck/issue-45199.stderr index 47aa3090827..8886e618e18 100644 --- a/tests/ui/borrowck/issue-45199.stderr +++ b/tests/ui/borrowck/issue-45199.stderr @@ -1,34 +1,40 @@ error[E0384]: cannot assign twice to immutable variable `b` --> $DIR/issue-45199.rs:6:5 | -LL | let b: Box<isize>; - | - help: consider making this binding mutable: `mut b` -... LL | b = Box::new(1); | - first assignment to `b` LL | b = Box::new(2); | ^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut b: Box<isize>; + | +++ error[E0384]: cannot assign twice to immutable variable `b` --> $DIR/issue-45199.rs:14:5 | LL | let b = Box::new(1); - | - - | | - | first assignment to `b` - | help: consider making this binding mutable: `mut b` + | - first assignment to `b` ... LL | b = Box::new(2); | ^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut b = Box::new(1); + | +++ error[E0384]: cannot assign to immutable argument `b` --> $DIR/issue-45199.rs:20:5 | -LL | fn test_args(b: Box<i32>) { - | - help: consider making this binding mutable: `mut b` -LL | LL | b = Box::new(2); | ^ cannot assign to immutable argument + | +help: consider making this binding mutable + | +LL | fn test_args(mut b: Box<i32>) { + | +++ error: aborting due to 3 previous errors diff --git a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr index 098a2964e9f..ff5ec1db346 100644 --- a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr +++ b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr @@ -44,56 +44,68 @@ LL | borrowck_closures_unique::e(addr_of_mut!(X)); error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46 | -LL | pub fn e(x: &'static mut isize) { - | - help: consider changing this to be mutable: `mut x` -LL | static mut Y: isize = 3; LL | let mut c1 = |y: &'static mut isize| x = y; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | pub fn e(mut x: &'static mut isize) { + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:22:50 | -LL | pub fn ee(x: &'static mut isize) { - | - help: consider changing this to be mutable: `mut x` -... LL | let mut c2 = |y: &'static mut isize| x = y; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | pub fn ee(mut x: &'static mut isize) { + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:37:13 | -LL | pub fn capture_assign_whole(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -LL | || { LL | x = (1,); | ^^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | pub fn capture_assign_whole(mut x: (i32,)) { + | +++ error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:13 | -LL | pub fn capture_assign_part(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -LL | || { LL | x.0 = 1; | ^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | pub fn capture_assign_part(mut x: (i32,)) { + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:13 | -LL | pub fn capture_reborrow_whole(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -LL | || { LL | &mut x; | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | pub fn capture_reborrow_whole(mut x: (i32,)) { + | +++ error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:55:13 | -LL | pub fn capture_reborrow_part(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -LL | || { LL | &mut x.0; | ^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | pub fn capture_reborrow_part(mut x: (i32,)) { + | +++ error: aborting due to 6 previous errors; 3 warnings emitted diff --git a/tests/ui/borrowck/mutability-errors.stderr b/tests/ui/borrowck/mutability-errors.stderr index b39e57d70ec..3cab3ccb993 100644 --- a/tests/ui/borrowck/mutability-errors.stderr +++ b/tests/ui/borrowck/mutability-errors.stderr @@ -262,74 +262,90 @@ LL | fn imm_local(mut x: (i32,)) { error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/mutability-errors.rs:60:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -LL | || { LL | x = (1,); | ^^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable --> $DIR/mutability-errors.rs:61:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | x.0 = 1; | ^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/mutability-errors.rs:62:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | &mut x; | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable --> $DIR/mutability-errors.rs:63:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | &mut x.0; | ^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/mutability-errors.rs:66:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | x = (1,); | ^^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable --> $DIR/mutability-errors.rs:67:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | x.0 = 1; | ^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/mutability-errors.rs:68:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | &mut x; | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable --> $DIR/mutability-errors.rs:69:9 | -LL | fn imm_capture(x: (i32,)) { - | - help: consider changing this to be mutable: `mut x` -... LL | &mut x.0; | ^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | fn imm_capture(mut x: (i32,)) { + | +++ error[E0594]: cannot assign to immutable static item `X` --> $DIR/mutability-errors.rs:76:5 diff --git a/tests/ui/borrowck/suggest-ref-mut-issue-118596.stderr b/tests/ui/borrowck/suggest-ref-mut-issue-118596.stderr index fd2a775a099..aec3d663160 100644 --- a/tests/ui/borrowck/suggest-ref-mut-issue-118596.stderr +++ b/tests/ui/borrowck/suggest-ref-mut-issue-118596.stderr @@ -9,11 +9,11 @@ LL | x = 2; help: consider making this binding mutable | LL | if let Some(mut x) = y { - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | if let Some(ref mut x) = y { - | ~~~~~~~~~ + | +++++++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/suggest-ref-mut-issue-118596.rs:9:5 @@ -26,11 +26,11 @@ LL | x = 0; help: consider making this binding mutable | LL | let [mut x, ref xs_hold @ ..] = arr; - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | let [ref mut x, ref xs_hold @ ..] = arr; - | ~~~~~~~~~ + | +++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/borrowck/tainted-promoteds.stderr b/tests/ui/borrowck/tainted-promoteds.stderr index a5c448fdcdb..04669a29097 100644 --- a/tests/ui/borrowck/tainted-promoteds.stderr +++ b/tests/ui/borrowck/tainted-promoteds.stderr @@ -2,12 +2,14 @@ error[E0384]: cannot assign twice to immutable variable `a` --> $DIR/tainted-promoteds.rs:7:5 | LL | let a = 0; - | - - | | - | first assignment to `a` - | help: consider making this binding mutable: `mut a` + | - first assignment to `a` LL | a = &0 * &1 * &2 * &3; | ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut a = 0; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/cannot-mutate-captured-non-mut-var.stderr b/tests/ui/cannot-mutate-captured-non-mut-var.stderr index 2d6e83c9e82..8d794f8251f 100644 --- a/tests/ui/cannot-mutate-captured-non-mut-var.stderr +++ b/tests/ui/cannot-mutate-captured-non-mut-var.stderr @@ -1,18 +1,24 @@ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25 | -LL | let x = 1; - | - help: consider changing this to be mutable: `mut x` LL | to_fn_once(move|| { x = 2; }); | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 1; + | +++ error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable --> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25 | -LL | let s = std::io::stdin(); - | - help: consider changing this to be mutable: `mut s` LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); }); | ^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut s = std::io::stdin(); + | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/cast/cast-rfc0401-vtable-kinds.rs b/tests/ui/cast/cast-rfc0401-vtable-kinds.rs index 0d8f92f013f..5704a33cc87 100644 --- a/tests/ui/cast/cast-rfc0401-vtable-kinds.rs +++ b/tests/ui/cast/cast-rfc0401-vtable-kinds.rs @@ -4,25 +4,12 @@ #![feature(unsized_tuple_coercion)] -trait Foo<T> { - fn foo(&self, _: T) -> u32 { 42 } -} - trait Bar { //~ WARN trait `Bar` is never used fn bar(&self) { println!("Bar!"); } } -impl<T> Foo<T> for () {} -impl Foo<u32> for u32 { fn foo(&self, _: u32) -> u32 { self+43 } } impl Bar for () {} -unsafe fn round_trip_and_call<'a>(t: *const (dyn Foo<u32>+'a)) -> u32 { - let foo_e : *const dyn Foo<u32> = t as *const _; - let r_1 = foo_e as *mut dyn Foo<u32>; - - (&*r_1).foo(0) -} - #[repr(C)] struct FooS<T:?Sized>(T); #[repr(C)] @@ -38,11 +25,6 @@ fn tuple_i32_to_u32<T:?Sized>(u: *const (i32, T)) -> *const (u32, T) { fn main() { - let x = 4u32; - let y : &dyn Foo<u32> = &x; - let fl = unsafe { round_trip_and_call(y as *const dyn Foo<u32>) }; - assert_eq!(fl, (43+4)); - let s = FooS([0,1,2]); let u: &FooS<[u32]> = &s; let u: *const FooS<[u32]> = u; diff --git a/tests/ui/cast/cast-rfc0401-vtable-kinds.stderr b/tests/ui/cast/cast-rfc0401-vtable-kinds.stderr index 952687e98d0..4f57e2e7df7 100644 --- a/tests/ui/cast/cast-rfc0401-vtable-kinds.stderr +++ b/tests/ui/cast/cast-rfc0401-vtable-kinds.stderr @@ -1,5 +1,5 @@ warning: trait `Bar` is never used - --> $DIR/cast-rfc0401-vtable-kinds.rs:11:7 + --> $DIR/cast-rfc0401-vtable-kinds.rs:7:7 | LL | trait Bar { | ^^^ diff --git a/tests/ui/cast/ptr-to-trait-obj-add-auto.rs b/tests/ui/cast/ptr-to-trait-obj-add-auto.rs new file mode 100644 index 00000000000..46e72ea0877 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-add-auto.rs @@ -0,0 +1,18 @@ +//@ check-pass + +trait Trait<'a> {} + +fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) { + x as _ + //~^ warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on + //~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +} + +// (to test diagnostic list formatting) +fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) { + x as _ + //~^ warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on + //~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr b/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr new file mode 100644 index 00000000000..e5ef8bf76b4 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr @@ -0,0 +1,43 @@ +warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on + --> $DIR/ptr-to-trait-obj-add-auto.rs:6:5 + | +LL | x as _ + | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323> + = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default + +warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on + --> $DIR/ptr-to-trait-obj-add-auto.rs:13:5 + | +LL | x as _ + | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323> + +warning: 2 warnings emitted + +Future incompatibility report: Future breakage diagnostic: +warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on + --> $DIR/ptr-to-trait-obj-add-auto.rs:6:5 + | +LL | x as _ + | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323> + = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default + +Future breakage diagnostic: +warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on + --> $DIR/ptr-to-trait-obj-add-auto.rs:13:5 + | +LL | x as _ + | ^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323> + = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default + diff --git a/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs b/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs new file mode 100644 index 00000000000..ac8108d8ec4 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs @@ -0,0 +1,9 @@ +//@ check-pass + +trait Trait: Send {} +impl Trait for () {} + +fn main() { + // This is OK: `Trait` has `Send` super trait. + &() as *const dyn Trait as *const (dyn Trait + Send); +} diff --git a/tests/ui/cast/ptr-to-trait-obj-different-args.rs b/tests/ui/cast/ptr-to-trait-obj-different-args.rs new file mode 100644 index 00000000000..c6038cfe864 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-args.rs @@ -0,0 +1,37 @@ +//@ check-fail +// +// issue: <https://github.com/rust-lang/rust/issues/120222> + +trait A {} +impl<T> A for T {} +trait B {} +impl<T> B for T {} + +trait Trait<G> {} +struct X; +impl<T> Trait<X> for T {} +struct Y; +impl<T> Trait<Y> for T {} + +fn main() { + let a: *const dyn A = &(); + let b: *const dyn B = a as _; //~ error: casting `*const dyn A` as `*const dyn B` is invalid + + let x: *const dyn Trait<X> = &(); + let y: *const dyn Trait<Y> = x as _; //~ error: mismatched types + + _ = (b, y); +} + +fn generic<T>(x: *const dyn Trait<X>, t: *const dyn Trait<T>) { + let _: *const dyn Trait<T> = x as _; //~ error: mismatched types + let _: *const dyn Trait<X> = t as _; //~ error: mismatched types +} + +trait Assocked { + type Assoc: ?Sized; +} + +fn change_assoc(x: *mut dyn Assocked<Assoc = u8>) -> *mut dyn Assocked<Assoc = u32> { + x as _ //~ error: mismatched types +} diff --git a/tests/ui/cast/ptr-to-trait-obj-different-args.stderr b/tests/ui/cast/ptr-to-trait-obj-different-args.stderr new file mode 100644 index 00000000000..b04289ae747 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-args.stderr @@ -0,0 +1,53 @@ +error[E0606]: casting `*const dyn A` as `*const dyn B` is invalid + --> $DIR/ptr-to-trait-obj-different-args.rs:18:27 + | +LL | let b: *const dyn B = a as _; + | ^^^^^^ + | + = note: vtable kinds may not match + +error[E0308]: mismatched types + --> $DIR/ptr-to-trait-obj-different-args.rs:21:34 + | +LL | let y: *const dyn Trait<Y> = x as _; + | ^^^^^^ expected `X`, found `Y` + | + = note: expected trait object `dyn Trait<X>` + found trait object `dyn Trait<Y>` + +error[E0308]: mismatched types + --> $DIR/ptr-to-trait-obj-different-args.rs:27:34 + | +LL | fn generic<T>(x: *const dyn Trait<X>, t: *const dyn Trait<T>) { + | - found this type parameter +LL | let _: *const dyn Trait<T> = x as _; + | ^^^^^^ expected `X`, found type parameter `T` + | + = note: expected trait object `dyn Trait<X>` + found trait object `dyn Trait<T>` + +error[E0308]: mismatched types + --> $DIR/ptr-to-trait-obj-different-args.rs:28:34 + | +LL | fn generic<T>(x: *const dyn Trait<X>, t: *const dyn Trait<T>) { + | - expected this type parameter +LL | let _: *const dyn Trait<T> = x as _; +LL | let _: *const dyn Trait<X> = t as _; + | ^^^^^^ expected type parameter `T`, found `X` + | + = note: expected trait object `dyn Trait<T>` + found trait object `dyn Trait<X>` + +error[E0308]: mismatched types + --> $DIR/ptr-to-trait-obj-different-args.rs:36:5 + | +LL | x as _ + | ^^^^^^ expected `u8`, found `u32` + | + = note: expected trait object `dyn Assocked<Assoc = u8>` + found trait object `dyn Assocked<Assoc = u32>` + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0308, E0606. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/cast/ptr-to-trait-obj-different-regions-id-trait.rs b/tests/ui/cast/ptr-to-trait-obj-different-regions-id-trait.rs new file mode 100644 index 00000000000..cdd55e24392 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-regions-id-trait.rs @@ -0,0 +1,27 @@ +//@ check-fail +// +// Make sure we can't trick the compiler by using a projection. + +trait Cat<'a> {} +impl Cat<'_> for () {} + +trait Id { + type Id: ?Sized; +} +impl<T: ?Sized> Id for T { + type Id = T; +} + +struct S<T: ?Sized> { + tail: <T as Id>::Id, +} + +fn m<'a>() { + let unsend: *const dyn Cat<'a> = &(); + let _send = unsend as *const S<dyn Cat<'static>>; + //~^ error: lifetime may not live long enough +} + +fn main() { + m(); +} diff --git a/tests/ui/cast/ptr-to-trait-obj-different-regions-id-trait.stderr b/tests/ui/cast/ptr-to-trait-obj-different-regions-id-trait.stderr new file mode 100644 index 00000000000..d1d598e603f --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-regions-id-trait.stderr @@ -0,0 +1,15 @@ +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-id-trait.rs:21:17 + | +LL | fn m<'a>() { + | -- lifetime `'a` defined here +LL | let unsend: *const dyn Cat<'a> = &(); +LL | let _send = unsend as *const S<dyn Cat<'static>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` + | + = note: requirement occurs because of the type `S<dyn Cat<'_>>`, which makes the generic argument `dyn Cat<'_>` invariant + = note: the struct `S<T>` is invariant over the parameter `T` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: aborting due to 1 previous error + diff --git a/tests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.rs b/tests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.rs new file mode 100644 index 00000000000..96345de01c9 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.rs @@ -0,0 +1,31 @@ +//@ check-fail +// +// issue: <https://github.com/rust-lang/rust/issues/120217> + +#![feature(arbitrary_self_types)] + +trait Static<'a> { + fn proof(self: *const Self, s: &'a str) -> &'static str; +} + +fn bad_cast<'a>(x: *const dyn Static<'static>) -> *const dyn Static<'a> { + x as _ //~ error: lifetime may not live long enough +} + +impl Static<'static> for () { + fn proof(self: *const Self, s: &'static str) -> &'static str { + s + } +} + +fn extend_lifetime(s: &str) -> &'static str { + bad_cast(&()).proof(s) +} + +fn main() { + let s = String::from("Hello World"); + let slice = extend_lifetime(&s); + println!("Now it exists: {slice}"); + drop(s); + println!("Now it’s gone: {slice}"); +} diff --git a/tests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.stderr b/tests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.stderr new file mode 100644 index 00000000000..b7319e3356b --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-regions-lt-ext.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-lt-ext.rs:12:5 + | +LL | fn bad_cast<'a>(x: *const dyn Static<'static>) -> *const dyn Static<'a> { + | -- lifetime `'a` defined here +LL | x as _ + | ^^^^^^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to 1 previous error + diff --git a/tests/ui/cast/ptr-to-trait-obj-different-regions-misc.rs b/tests/ui/cast/ptr-to-trait-obj-different-regions-misc.rs new file mode 100644 index 00000000000..01c347bfae5 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-regions-misc.rs @@ -0,0 +1,37 @@ +//@ check-fail + +trait Trait<'a> {} + +fn change_lt<'a, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + x as _ //~ error: lifetime may not live long enough + //~| error: lifetime may not live long enough +} + +fn change_lt_ab<'a: 'b, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + x as _ //~ error: lifetime may not live long enough +} + +fn change_lt_ba<'a, 'b: 'a>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + x as _ //~ error: lifetime may not live long enough +} + +trait Assocked { + type Assoc: ?Sized; +} + +fn change_assoc_0<'a, 'b>( + x: *mut dyn Assocked<Assoc = dyn Send + 'a>, +) -> *mut dyn Assocked<Assoc = dyn Send + 'b> { + x as _ //~ error: lifetime may not live long enough + //~| error: lifetime may not live long enough +} + +fn change_assoc_1<'a, 'b>( + x: *mut dyn Assocked<Assoc = dyn Trait<'a>>, +) -> *mut dyn Assocked<Assoc = dyn Trait<'b>> { + x as _ //~ error: lifetime may not live long enough + //~| error: lifetime may not live long enough +} + + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-different-regions-misc.stderr b/tests/ui/cast/ptr-to-trait-obj-different-regions-misc.stderr new file mode 100644 index 00000000000..7044e4dec1f --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-different-regions-misc.stderr @@ -0,0 +1,136 @@ +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:6:5 + | +LL | fn change_lt<'a, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of a mutable pointer to `dyn Trait<'_>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:6:5 + | +LL | fn change_lt<'a, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of a mutable pointer to `dyn Trait<'_>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'b` and `'a` must be the same: replace one with the other + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:11:5 + | +LL | fn change_lt_ab<'a: 'b, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of a mutable pointer to `dyn Trait<'_>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:15:5 + | +LL | fn change_lt_ba<'a, 'b: 'a>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of a mutable pointer to `dyn Trait<'_>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:25:5 + | +LL | fn change_assoc_0<'a, 'b>( + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of a mutable pointer to `dyn Assocked<Assoc = dyn Send>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:25:5 + | +LL | fn change_assoc_0<'a, 'b>( + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of a mutable pointer to `dyn Assocked<Assoc = dyn Send>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'b` and `'a` must be the same: replace one with the other + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:32:5 + | +LL | fn change_assoc_1<'a, 'b>( + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of a mutable pointer to `dyn Assocked<Assoc = dyn Trait<'_>>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/ptr-to-trait-obj-different-regions-misc.rs:32:5 + | +LL | fn change_assoc_1<'a, 'b>( + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | x as _ + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of a mutable pointer to `dyn Assocked<Assoc = dyn Trait<'_>>` + = note: mutable pointers are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'b` and `'a` must be the same: replace one with the other + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 8 previous errors + diff --git a/tests/ui/cast/ptr-to-trait-obj-ok.rs b/tests/ui/cast/ptr-to-trait-obj-ok.rs new file mode 100644 index 00000000000..656c99c58dc --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-ok.rs @@ -0,0 +1,17 @@ +//@ check-pass + +trait Trait<'a> {} + +fn remove_auto<'a>(x: *mut (dyn Trait<'a> + Send)) -> *mut dyn Trait<'a> { + x as _ +} + +fn cast_inherent_lt<'a, 'b>(x: *mut (dyn Trait<'static> + 'a)) -> *mut (dyn Trait<'static> + 'b) { + x as _ +} + +fn unprincipled<'a, 'b>(x: *mut (dyn Send + 'a)) -> *mut (dyn Sync + 'b) { + x as _ +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.rs b/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.rs new file mode 100644 index 00000000000..ff2c4cacfb1 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.rs @@ -0,0 +1,14 @@ +trait Super {} +trait Sub: Super {} + +struct Wrapper<T: ?Sized>(T); + +// This cast should not compile. +// Upcasting can't work here, because we are also changing the type (`Wrapper`), +// and reinterpreting would be confusing/surprising. +// See <https://github.com/rust-lang/rust/pull/120248#discussion_r1487739518> +fn cast(ptr: *const dyn Sub) -> *const Wrapper<dyn Super> { + ptr as _ //~ error: casting `*const (dyn Sub + 'static)` as `*const Wrapper<dyn Super>` is invalid +} + +fn main() {} diff --git a/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.stderr b/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.stderr new file mode 100644 index 00000000000..38c8ba96bc5 --- /dev/null +++ b/tests/ui/cast/ptr-to-trait-obj-wrap-upcast.stderr @@ -0,0 +1,11 @@ +error[E0606]: casting `*const (dyn Sub + 'static)` as `*const Wrapper<dyn Super>` is invalid + --> $DIR/ptr-to-trait-obj-wrap-upcast.rs:11:5 + | +LL | ptr as _ + | ^^^^^^^^ + | + = note: vtable kinds may not match + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0606`. diff --git a/tests/ui/closures/2229_closure_analysis/array_subslice.stderr b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr index 888c60d5e91..ee941caa773 100644 --- a/tests/ui/closures/2229_closure_analysis/array_subslice.stderr +++ b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr @@ -1,11 +1,13 @@ error[E0596]: cannot borrow `x[..]` as mutable, as `x` is not declared as mutable --> $DIR/array_subslice.rs:7:21 | -LL | pub fn subslice_array(x: [u8; 3]) { - | - help: consider changing this to be mutable: `mut x` -... LL | let [ref y, ref mut z @ ..] = x; | ^^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | pub fn subslice_array(mut x: [u8; 3]) { + | +++ error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable --> $DIR/array_subslice.rs:10:5 diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr b/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr index 98414fa8a3d..6f5043ef08d 100644 --- a/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr +++ b/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr @@ -1,20 +1,24 @@ error[E0594]: cannot assign to `z.0.0.0`, as it is not declared as mutable --> $DIR/cant-mutate-imm.rs:12:9 | -LL | let z = (y, 10); - | - help: consider changing this to be mutable: `mut z` -... LL | z.0.0.0 = 20; | ^^^^^^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut z = (y, 10); + | +++ error[E0594]: cannot assign to `*bx.0`, as it is not declared as mutable --> $DIR/cant-mutate-imm.rs:24:9 | -LL | let bx = Box::new(x); - | -- help: consider changing this to be mutable: `mut bx` -... LL | bx.0 = 20; | ^^^^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut bx = Box::new(x); + | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/closures/closure-immutable-outer-variable.stderr b/tests/ui/closures/closure-immutable-outer-variable.stderr index 23bd0020db6..c4b0e544957 100644 --- a/tests/ui/closures/closure-immutable-outer-variable.stderr +++ b/tests/ui/closures/closure-immutable-outer-variable.stderr @@ -1,10 +1,13 @@ error[E0594]: cannot assign to `y`, as it is not declared as mutable --> $DIR/closure-immutable-outer-variable.rs:11:26 | -LL | let y = true; - | - help: consider changing this to be mutable: `mut y` LL | foo(Box::new(move || y = !y) as Box<_>); | ^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut y = true; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/command-line-diagnostics.stderr b/tests/ui/command-line-diagnostics.stderr index b719a00ad5d..6d33fb4172f 100644 --- a/tests/ui/command-line-diagnostics.stderr +++ b/tests/ui/command-line-diagnostics.stderr @@ -2,12 +2,14 @@ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/command-line-diagnostics.rs:6:5 | LL | let x = 42; - | - - | | - | first assignment to `x` - | help: consider making this binding mutable: `mut x` + | - first assignment to `x` LL | x = 43; | ^^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut x = 42; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/compare-method/bad-self-type.stderr b/tests/ui/compare-method/bad-self-type.stderr index a87b713c2b4..a3a31f43447 100644 --- a/tests/ui/compare-method/bad-self-type.stderr +++ b/tests/ui/compare-method/bad-self-type.stderr @@ -2,22 +2,20 @@ error[E0053]: method `poll` has an incompatible type for trait --> $DIR/bad-self-type.rs:10:13 | LL | fn poll(self, _: &mut Context<'_>) -> Poll<()> { - | ^^^^ - | | - | expected `Pin<&mut MyFuture>`, found `MyFuture` - | help: change the self-receiver type to match the trait: `self: Pin<&mut MyFuture>` + | ^^^^ expected `Pin<&mut MyFuture>`, found `MyFuture` | = note: expected signature `fn(Pin<&mut MyFuture>, &mut Context<'_>) -> Poll<_>` found signature `fn(MyFuture, &mut Context<'_>) -> Poll<_>` +help: change the self-receiver type to match the trait + | +LL | fn poll(self: Pin<&mut MyFuture>, _: &mut Context<'_>) -> Poll<()> { + | ~~~~~~~~~~~~~~~~~~~~~~~~ error[E0053]: method `foo` has an incompatible type for trait --> $DIR/bad-self-type.rs:22:18 | LL | fn foo(self: Box<Self>) {} - | ------^^^^^^^^^ - | | | - | | expected `MyFuture`, found `Box<MyFuture>` - | help: change the self-receiver type to match the trait: `self` + | ^^^^^^^^^ expected `MyFuture`, found `Box<MyFuture>` | note: type in trait --> $DIR/bad-self-type.rs:17:12 @@ -26,6 +24,10 @@ LL | fn foo(self); | ^^^^ = note: expected signature `fn(MyFuture)` found signature `fn(Box<MyFuture>)` +help: change the self-receiver type to match the trait + | +LL | fn foo(self) {} + | ~~~~ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/bad-self-type.rs:24:17 @@ -39,7 +41,7 @@ note: type in trait LL | fn bar(self) -> Option<()>; | ^^^^^^^^^^ = note: expected signature `fn(MyFuture) -> Option<()>` - found signature `fn(MyFuture)` + found signature `fn(MyFuture) -> ()` help: change the output type to match the trait | LL | fn bar(self) -> Option<()> {} diff --git a/tests/ui/compare-method/issue-90444.stderr b/tests/ui/compare-method/issue-90444.stderr index 52e23d03b14..f05c9939c00 100644 --- a/tests/ui/compare-method/issue-90444.stderr +++ b/tests/ui/compare-method/issue-90444.stderr @@ -2,25 +2,27 @@ error[E0053]: method `from` has an incompatible type for trait --> $DIR/issue-90444.rs:3:16 | LL | fn from(_: fn((), (), &mut ())) -> Self { - | ^^^^^^^^^^^^^^^^^^^ - | | - | types differ in mutability - | help: change the parameter type to match the trait: `for<'a> fn((), (), &'a ())` + | ^^^^^^^^^^^^^^^^^^^ types differ in mutability | = note: expected signature `fn(for<'a> fn((), (), &'a ())) -> A` found signature `fn(for<'a> fn((), (), &'a mut ())) -> A` +help: change the parameter type to match the trait + | +LL | fn from(_: for<'a> fn((), (), &'a ())) -> Self { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0053]: method `from` has an incompatible type for trait --> $DIR/issue-90444.rs:11:16 | LL | fn from(_: fn((), (), u64)) -> Self { - | ^^^^^^^^^^^^^^^ - | | - | expected `u32`, found `u64` - | help: change the parameter type to match the trait: `fn((), (), u32)` + | ^^^^^^^^^^^^^^^ expected `u32`, found `u64` | = note: expected signature `fn(fn((), (), u32)) -> B` found signature `fn(fn((), (), u64)) -> B` +help: change the parameter type to match the trait + | +LL | fn from(_: fn((), (), u32)) -> Self { + | ~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/compare-method/reordered-type-param.stderr b/tests/ui/compare-method/reordered-type-param.stderr index 8a439acee13..1e8266e213d 100644 --- a/tests/ui/compare-method/reordered-type-param.stderr +++ b/tests/ui/compare-method/reordered-type-param.stderr @@ -2,10 +2,8 @@ error[E0053]: method `b` has an incompatible type for trait --> $DIR/reordered-type-param.rs:16:30 | LL | fn b<F:Clone,G>(&self, _x: G) -> G { panic!() } - | - - ^ - | | | | - | | | expected type parameter `F`, found type parameter `G` - | | | help: change the parameter type to match the trait: `F` + | - - ^ expected type parameter `F`, found type parameter `G` + | | | | | found type parameter | expected type parameter | @@ -18,6 +16,10 @@ LL | fn b<C:Clone,D>(&self, x: C) -> C; found signature `fn(&E, G) -> G` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters +help: change the parameter type to match the trait + | +LL | fn b<F:Clone,G>(&self, _x: F) -> G { panic!() } + | ~ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr b/tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr index be79450a3ce..416a9381124 100644 --- a/tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr +++ b/tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr @@ -20,24 +20,32 @@ error[E0393]: the type parameter `Rhs` must be explicitly specified --> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27 | LL | ) -> impl Iterator<Item = SubAssign> { - | ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>` + | ^^^^^^^^^ --> $SRC_DIR/core/src/ops/arith.rs:LL:COL | = note: type parameter `Rhs` must be specified for this | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | ) -> impl Iterator<Item = SubAssign<Rhs>> { + | +++++ error[E0393]: the type parameter `Rhs` must be explicitly specified --> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27 | LL | ) -> impl Iterator<Item = SubAssign> { - | ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>` + | ^^^^^^^^^ --> $SRC_DIR/core/src/ops/arith.rs:LL:COL | = note: type parameter `Rhs` must be specified for this | = note: because of the default `Self` reference, type parameters must be specified on object types = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: set the type parameter to the desired type + | +LL | ) -> impl Iterator<Item = SubAssign<Rhs>> { + | +++++ error[E0277]: `()` is not an iterator --> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6 diff --git a/tests/ui/const-generics/issues/issue-86535-2.rs b/tests/ui/const-generics/issues/issue-86535-2.rs index 1ba3b6d5347..bd9431dbc85 100644 --- a/tests/ui/const-generics/issues/issue-86535-2.rs +++ b/tests/ui/const-generics/issues/issue-86535-2.rs @@ -7,6 +7,7 @@ pub trait Foo { fn foo() where [(); Self::ASSOC_C]:; } +#[allow(dead_code)] struct Bar<const N: &'static ()>; impl<const N: &'static ()> Foo for Bar<N> { const ASSOC_C: usize = 3; diff --git a/tests/ui/const-generics/issues/issue-86535.rs b/tests/ui/const-generics/issues/issue-86535.rs index dd6bc88ad19..cd9934a4a99 100644 --- a/tests/ui/const-generics/issues/issue-86535.rs +++ b/tests/ui/const-generics/issues/issue-86535.rs @@ -2,6 +2,7 @@ #![feature(adt_const_params, generic_const_exprs)] #![allow(incomplete_features, unused_variables)] +#[allow(dead_code)] struct F<const S: &'static str>; impl<const S: &'static str> X for F<{ S }> { const W: usize = 3; diff --git a/tests/ui/consts/issue-39974.stderr b/tests/ui/consts/issue-39974.stderr index 114c4cfeaf7..a371ea5709e 100644 --- a/tests/ui/consts/issue-39974.stderr +++ b/tests/ui/consts/issue-39974.stderr @@ -2,10 +2,12 @@ error[E0308]: mismatched types --> $DIR/issue-39974.rs:1:21 | LL | const LENGTH: f64 = 2; - | ^ - | | - | expected `f64`, found integer - | help: use a float literal: `2.0` + | ^ expected `f64`, found integer + | +help: use a float literal + | +LL | const LENGTH: f64 = 2.0; + | ++ error[E0308]: mismatched types --> $DIR/issue-39974.rs:5:19 diff --git a/tests/ui/consts/offset_from_ub.rs b/tests/ui/consts/offset_from_ub.rs index 57767e96596..e71f88b8d5f 100644 --- a/tests/ui/consts/offset_from_ub.rs +++ b/tests/ui/consts/offset_from_ub.rs @@ -92,6 +92,14 @@ pub const TOO_FAR_APART2: isize = { unsafe { ptr_offset_from(ptr1, ptr2) } //~ERROR evaluation of constant value failed //~| too far before }; +pub const TOO_FAR_APART3: isize = { + let ptr1 = &0u8 as *const u8; + let ptr2 = ptr1.wrapping_offset(isize::MIN); + // The result of this would be `isize::MIN`, which *does* fit in an `isize`, but its + // absolute value does not. (Also anyway there cannot be an allocation of that size.) + unsafe { ptr_offset_from(ptr1, ptr2) } //~ERROR evaluation of constant value failed + //~| too far before +}; const WRONG_ORDER_UNSIGNED: usize = { let a = ['a', 'b', 'c']; diff --git a/tests/ui/consts/offset_from_ub.stderr b/tests/ui/consts/offset_from_ub.stderr index 65f75a6e058..7caf6247b9e 100644 --- a/tests/ui/consts/offset_from_ub.stderr +++ b/tests/ui/consts/offset_from_ub.stderr @@ -60,13 +60,19 @@ LL | unsafe { ptr_offset_from(ptr1, ptr2) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called when first pointer is too far before second error[E0080]: evaluation of constant value failed - --> $DIR/offset_from_ub.rs:99:14 + --> $DIR/offset_from_ub.rs:100:14 + | +LL | unsafe { ptr_offset_from(ptr1, ptr2) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called when first pointer is too far before second + +error[E0080]: evaluation of constant value failed + --> $DIR/offset_from_ub.rs:107:14 | LL | unsafe { ptr_offset_from_unsigned(p, p.add(2) ) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer has smaller offset than second: 0 < 8 error[E0080]: evaluation of constant value failed - --> $DIR/offset_from_ub.rs:106:14 + --> $DIR/offset_from_ub.rs:114:14 | LL | unsafe { ptr_offset_from_unsigned(ptr2, ptr1) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer is too far ahead of second @@ -79,7 +85,7 @@ error[E0080]: evaluation of constant value failed note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `OFFSET_VERY_FAR1` - --> $DIR/offset_from_ub.rs:115:14 + --> $DIR/offset_from_ub.rs:123:14 | LL | unsafe { ptr2.offset_from(ptr1) } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -92,11 +98,11 @@ error[E0080]: evaluation of constant value failed note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL note: inside `OFFSET_VERY_FAR2` - --> $DIR/offset_from_ub.rs:121:14 + --> $DIR/offset_from_ub.rs:129:14 | LL | unsafe { ptr1.offset_from(ptr2.wrapping_offset(1)) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: aborting due to 14 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/slice_elem_ty_mismatch_in_unsizing_cast.rs b/tests/ui/consts/slice_elem_ty_mismatch_in_unsizing_cast.rs new file mode 100644 index 00000000000..d821b6a0117 --- /dev/null +++ b/tests/ui/consts/slice_elem_ty_mismatch_in_unsizing_cast.rs @@ -0,0 +1,4 @@ +const FOO: &str = unsafe { &*(1_usize as *const [i64; 0] as *const [u8] as *const str) }; +//~^ ERROR: cannot cast + +fn main() {} diff --git a/tests/ui/consts/slice_elem_ty_mismatch_in_unsizing_cast.stderr b/tests/ui/consts/slice_elem_ty_mismatch_in_unsizing_cast.stderr new file mode 100644 index 00000000000..3b861d784d8 --- /dev/null +++ b/tests/ui/consts/slice_elem_ty_mismatch_in_unsizing_cast.stderr @@ -0,0 +1,9 @@ +error[E0607]: cannot cast thin pointer `*const [i64; 0]` to fat pointer `*const [u8]` + --> $DIR/slice_elem_ty_mismatch_in_unsizing_cast.rs:1:31 + | +LL | const FOO: &str = unsafe { &*(1_usize as *const [i64; 0] as *const [u8] as *const str) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0607`. diff --git a/tests/ui/deriving/deriving-in-fn.rs b/tests/ui/deriving/deriving-in-fn.rs index 72da2148350..13f3d39597c 100644 --- a/tests/ui/deriving/deriving-in-fn.rs +++ b/tests/ui/deriving/deriving-in-fn.rs @@ -9,5 +9,5 @@ pub fn main() { } let f = Foo { foo: 10 }; - format!("{:?}", f); + let _ = format!("{:?}", f); } diff --git a/tests/ui/deriving/deriving-smart-pointer-neg.rs b/tests/ui/deriving/deriving-smart-pointer-neg.rs new file mode 100644 index 00000000000..bfb4e86b396 --- /dev/null +++ b/tests/ui/deriving/deriving-smart-pointer-neg.rs @@ -0,0 +1,45 @@ +#![feature(derive_smart_pointer, arbitrary_self_types)] + +use std::marker::SmartPointer; + +#[derive(SmartPointer)] +//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` +enum NotStruct<'a, T: ?Sized> { + Variant(&'a T), +} + +#[derive(SmartPointer)] +//~^ ERROR: At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits +#[repr(transparent)] +struct NoPointee<'a, T: ?Sized> { + ptr: &'a T, +} + +#[derive(SmartPointer)] +//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field +#[repr(transparent)] +struct NoField<'a, #[pointee] T: ?Sized> {} +//~^ ERROR: lifetime parameter `'a` is never used +//~| ERROR: type parameter `T` is never used + +#[derive(SmartPointer)] +//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field +#[repr(transparent)] +struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); +//~^ ERROR: lifetime parameter `'a` is never used +//~| ERROR: type parameter `T` is never used + +#[derive(SmartPointer)] +//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` +struct NotTransparent<'a, #[pointee] T: ?Sized> { + ptr: &'a T, +} + +// However, reordering attributes should work nevertheless. +#[repr(transparent)] +#[derive(SmartPointer)] +struct ThisIsAPossibleSmartPointer<'a, #[pointee] T: ?Sized> { + ptr: &'a T, +} + +fn main() {} diff --git a/tests/ui/deriving/deriving-smart-pointer-neg.stderr b/tests/ui/deriving/deriving-smart-pointer-neg.stderr new file mode 100644 index 00000000000..d994a6ee376 --- /dev/null +++ b/tests/ui/deriving/deriving-smart-pointer-neg.stderr @@ -0,0 +1,75 @@ +error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` + --> $DIR/deriving-smart-pointer-neg.rs:5:10 + | +LL | #[derive(SmartPointer)] + | ^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits + --> $DIR/deriving-smart-pointer-neg.rs:11:10 + | +LL | #[derive(SmartPointer)] + | ^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `SmartPointer` can only be derived on `struct`s with at least one field + --> $DIR/deriving-smart-pointer-neg.rs:18:10 + | +LL | #[derive(SmartPointer)] + | ^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `SmartPointer` can only be derived on `struct`s with at least one field + --> $DIR/deriving-smart-pointer-neg.rs:25:10 + | +LL | #[derive(SmartPointer)] + | ^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` + --> $DIR/deriving-smart-pointer-neg.rs:32:10 + | +LL | #[derive(SmartPointer)] + | ^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/deriving-smart-pointer-neg.rs:21:16 + | +LL | struct NoField<'a, #[pointee] T: ?Sized> {} + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: type parameter `T` is never used + --> $DIR/deriving-smart-pointer-neg.rs:21:31 + | +LL | struct NoField<'a, #[pointee] T: ?Sized> {} + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/deriving-smart-pointer-neg.rs:28:20 + | +LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: type parameter `T` is never used + --> $DIR/deriving-smart-pointer-neg.rs:28:35 + | +LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 9 previous errors + +For more information about this error, try `rustc --explain E0392`. diff --git a/tests/ui/deriving/deriving-smart-pointer.rs b/tests/ui/deriving/deriving-smart-pointer.rs index cfc3369850b..d34a502da68 100644 --- a/tests/ui/deriving/deriving-smart-pointer.rs +++ b/tests/ui/deriving/deriving-smart-pointer.rs @@ -4,6 +4,7 @@ use std::marker::SmartPointer; #[derive(SmartPointer)] +#[repr(transparent)] struct MyPointer<'a, #[pointee] T: ?Sized> { ptr: &'a T, } diff --git a/tests/ui/did_you_mean/issue-34337.stderr b/tests/ui/did_you_mean/issue-34337.stderr index c727a565dbe..7bb651c47d0 100644 --- a/tests/ui/did_you_mean/issue-34337.stderr +++ b/tests/ui/did_you_mean/issue-34337.stderr @@ -2,10 +2,13 @@ error[E0596]: cannot borrow `key` as mutable, as it is not declared as mutable --> $DIR/issue-34337.rs:6:9 | LL | get(&mut key); - | ^^^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here + | ^^^^^^^^ cannot borrow as mutable + | +help: try removing `&mut` here + | +LL - get(&mut key); +LL + get(key); + | error: aborting due to 1 previous error diff --git a/tests/ui/did_you_mean/issue-37139.stderr b/tests/ui/did_you_mean/issue-37139.stderr index a07d83b31db..dbaab70d8bc 100644 --- a/tests/ui/did_you_mean/issue-37139.stderr +++ b/tests/ui/did_you_mean/issue-37139.stderr @@ -2,10 +2,13 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/issue-37139.rs:12:18 | LL | test(&mut x); - | ^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here + | ^^^^^^ cannot borrow as mutable + | +help: try removing `&mut` here + | +LL - test(&mut x); +LL + test(x); + | error: aborting due to 1 previous error diff --git a/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr b/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr index 6f853ccab37..6e32483aee4 100644 --- a/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr +++ b/tests/ui/did_you_mean/issue-53280-expected-float-found-integer-literal.stderr @@ -2,31 +2,40 @@ error[E0308]: mismatched types --> $DIR/issue-53280-expected-float-found-integer-literal.rs:2:24 | LL | let sixteen: f32 = 16; - | --- ^^ - | | | - | | expected `f32`, found integer - | | help: use a float literal: `16.0` + | --- ^^ expected `f32`, found integer + | | | expected due to this + | +help: use a float literal + | +LL | let sixteen: f32 = 16.0; + | ++ error[E0308]: mismatched types --> $DIR/issue-53280-expected-float-found-integer-literal.rs:5:38 | LL | let a_million_and_seventy: f64 = 1_000_070; - | --- ^^^^^^^^^ - | | | - | | expected `f64`, found integer - | | help: use a float literal: `1_000_070.0` + | --- ^^^^^^^^^ expected `f64`, found integer + | | | expected due to this + | +help: use a float literal + | +LL | let a_million_and_seventy: f64 = 1_000_070.0; + | ++ error[E0308]: mismatched types --> $DIR/issue-53280-expected-float-found-integer-literal.rs:8:30 | LL | let negative_nine: f32 = -9; - | --- ^^ - | | | - | | expected `f32`, found integer - | | help: use a float literal: `-9.0` + | --- ^^ expected `f32`, found integer + | | | expected due to this + | +help: use a float literal + | +LL | let negative_nine: f32 = -9.0; + | ++ error[E0308]: mismatched types --> $DIR/issue-53280-expected-float-found-integer-literal.rs:15:30 diff --git a/tests/ui/error-codes/E0057.stderr b/tests/ui/error-codes/E0057.stderr index 9b0cf069824..efd2af6d609 100644 --- a/tests/ui/error-codes/E0057.stderr +++ b/tests/ui/error-codes/E0057.stderr @@ -18,16 +18,18 @@ error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/E0057.rs:5:13 | LL | let c = f(2, 3); - | ^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^ - unexpected argument of type `{integer}` | note: closure defined here --> $DIR/E0057.rs:2:13 | LL | let f = |x| x * 3; | ^^^ +help: remove the extra argument + | +LL - let c = f(2, 3); +LL + let c = f(2); + | error: aborting due to 2 previous errors diff --git a/tests/ui/error-codes/E0308.stderr b/tests/ui/error-codes/E0308.stderr index bc6c5a632a1..709b3119276 100644 --- a/tests/ui/error-codes/E0308.stderr +++ b/tests/ui/error-codes/E0308.stderr @@ -5,7 +5,7 @@ LL | fn size_of<T>(); | ^ expected `usize`, found `()` | = note: expected signature `extern "rust-intrinsic" fn() -> usize` - found signature `extern "rust-intrinsic" fn()` + found signature `extern "rust-intrinsic" fn() -> ()` error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/E0393.stderr b/tests/ui/error-codes/E0393.stderr index 4083fa23e87..489398b7be5 100644 --- a/tests/ui/error-codes/E0393.stderr +++ b/tests/ui/error-codes/E0393.stderr @@ -5,9 +5,13 @@ LL | trait A<T=Self> {} | --------------- type parameter `T` must be specified for this LL | LL | fn together_we_will_rule_the_galaxy(son: &dyn A) {} - | ^ help: set the type parameter to the desired type: `A<T>` + | ^ | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | fn together_we_will_rule_the_galaxy(son: &dyn A<T>) {} + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/explicit-tail-calls/constck.rs b/tests/ui/explicit-tail-calls/constck.rs new file mode 100644 index 00000000000..938f15f12c0 --- /dev/null +++ b/tests/ui/explicit-tail-calls/constck.rs @@ -0,0 +1,22 @@ +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +const fn f() { + if false { + become not_const(); + //~^ error: cannot call non-const fn `not_const` in constant functions + } +} + +const fn g((): ()) { + if false { + become yes_const(not_const()); + //~^ error: cannot call non-const fn `not_const` in constant functions + } +} + +fn not_const() {} + +const fn yes_const((): ()) {} + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/constck.stderr b/tests/ui/explicit-tail-calls/constck.stderr new file mode 100644 index 00000000000..d9967c45fa0 --- /dev/null +++ b/tests/ui/explicit-tail-calls/constck.stderr @@ -0,0 +1,19 @@ +error[E0015]: cannot call non-const fn `not_const` in constant functions + --> $DIR/constck.rs:6:16 + | +LL | become not_const(); + | ^^^^^^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error[E0015]: cannot call non-const fn `not_const` in constant functions + --> $DIR/constck.rs:13:26 + | +LL | become yes_const(not_const()); + | ^^^^^^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/explicit-tail-calls/ctfe-arg-bad-borrow.rs b/tests/ui/explicit-tail-calls/ctfe-arg-bad-borrow.rs new file mode 100644 index 00000000000..5a105ee4eb5 --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-arg-bad-borrow.rs @@ -0,0 +1,14 @@ +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +pub const fn test(_: &Type) { + const fn takes_borrow(_: &Type) {} + + let local = Type; + become takes_borrow(&local); + //~^ error: `local` does not live long enough +} + +struct Type; + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/ctfe-arg-bad-borrow.stderr b/tests/ui/explicit-tail-calls/ctfe-arg-bad-borrow.stderr new file mode 100644 index 00000000000..75fb13c378c --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-arg-bad-borrow.stderr @@ -0,0 +1,14 @@ +error[E0597]: `local` does not live long enough + --> $DIR/ctfe-arg-bad-borrow.rs:8:25 + | +LL | let local = Type; + | ----- binding `local` declared here +LL | become takes_borrow(&local); + | ^^^^^^ borrowed value does not live long enough +LL | +LL | } + | - `local` dropped here while still borrowed + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/tests/ui/explicit-tail-calls/ctfe-arg-good-borrow.rs b/tests/ui/explicit-tail-calls/ctfe-arg-good-borrow.rs new file mode 100644 index 00000000000..50bf6c946ca --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-arg-good-borrow.rs @@ -0,0 +1,13 @@ +//@ check-pass +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +pub const fn test(x: &Type) { + const fn takes_borrow(_: &Type) {} + + become takes_borrow(x); +} + +pub struct Type; + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/ctfe-arg-move.rs b/tests/ui/explicit-tail-calls/ctfe-arg-move.rs new file mode 100644 index 00000000000..88ff3a4a5ad --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-arg-move.rs @@ -0,0 +1,15 @@ +//@ check-pass +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +pub const fn test(s: String) -> String { + const fn takes_string(s: String) -> String { + s + } + + become takes_string(s); +} + +struct Type; + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/ctfe-collatz-multi-rec.rs b/tests/ui/explicit-tail-calls/ctfe-collatz-multi-rec.rs new file mode 100644 index 00000000000..86041b66960 --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-collatz-multi-rec.rs @@ -0,0 +1,43 @@ +//@ run-pass +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +/// A very unnecessarily complicated "implementation" of the Collatz conjecture. +/// Returns the number of steps to reach `1`. +/// +/// This is just a test for tail calls, which involves multiple functions calling each other. +/// +/// Panics if `x == 0`. +const fn collatz(x: u32) -> u32 { + assert!(x > 0); + + const fn switch(x: u32, steps: u32) -> u32 { + match x { + 1 => steps, + _ if x & 1 == 0 => become div2(x, steps + 1), + _ => become mul3plus1(x, steps + 1), + } + } + + const fn div2(x: u32, steps: u32) -> u32 { + become switch(x >> 1, steps) + } + + const fn mul3plus1(x: u32, steps: u32) -> u32 { + become switch(3 * x + 1, steps) + } + + switch(x, 0) +} + +const ASSERTS: () = { + assert!(collatz(1) == 0); + assert!(collatz(2) == 1); + assert!(collatz(3) == 7); + assert!(collatz(4) == 2); + assert!(collatz(6171) == 261); +}; + +fn main() { + let _ = ASSERTS; +} diff --git a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr new file mode 100644 index 00000000000..4a1e50b4111 --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr @@ -0,0 +1,36 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/ctfe-id-unlimited.rs:17:42 + | +LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), + | ^^^^^^^^^^^^^^^^^^^^^ reached the configured maximum number of stack frames + | +note: inside `inner` + --> $DIR/ctfe-id-unlimited.rs:17:42 + | +LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), + | ^^^^^^^^^^^^^^^^^^^^^ +note: [... 125 additional calls inside `inner` ...] + --> $DIR/ctfe-id-unlimited.rs:17:42 + | +LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), + | ^^^^^^^^^^^^^^^^^^^^^ +note: inside `rec_id` + --> $DIR/ctfe-id-unlimited.rs:22:5 + | +LL | inner(0, n) + | ^^^^^^^^^^^ +note: inside `ID_ED` + --> $DIR/ctfe-id-unlimited.rs:29:20 + | +LL | const ID_ED: u32 = rec_id(ORIGINAL); + | ^^^^^^^^^^^^^^^^ + +note: erroneous constant encountered + --> $DIR/ctfe-id-unlimited.rs:31:40 + | +LL | const ASSERT: () = assert!(ORIGINAL == ID_ED); + | ^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs new file mode 100644 index 00000000000..54e68b2b7f7 --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs @@ -0,0 +1,35 @@ +//@ revisions: become return +//@ [become] run-pass +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +// This is an identity function (`|x| x`), but implemented using recursion. +// Each step we increment accumulator and decrement the number. +// +// With normal calls this fails compilation because of the recursion limit, +// but with tail calls/`become` we don't grow the stack/spend recursion limit +// so this should compile. +const fn rec_id(n: u32) -> u32 { + const fn inner(acc: u32, n: u32) -> u32 { + match n { + 0 => acc, + #[cfg(r#become)] _ => become inner(acc + 1, n - 1), + #[cfg(r#return)] _ => return inner(acc + 1, n - 1), + //[return]~^ error: evaluation of constant value failed + } + } + + inner(0, n) +} + +// Some relatively big number that is higher than recursion limit +const ORIGINAL: u32 = 12345; +// Original number, but with identity function applied +// (this is the same, but requires execution of the recursion) +const ID_ED: u32 = rec_id(ORIGINAL); +// Assert to make absolutely sure the computation actually happens +const ASSERT: () = assert!(ORIGINAL == ID_ED); + +fn main() { + let _ = ASSERT; +} diff --git a/tests/ui/explicit-tail-calls/ctfe-tail-call-panic.rs b/tests/ui/explicit-tail-calls/ctfe-tail-call-panic.rs new file mode 100644 index 00000000000..3d69cde2989 --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-tail-call-panic.rs @@ -0,0 +1,19 @@ +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +pub const fn f() { + become g(); +} + +const fn g() { + panic!() + //~^ error: evaluation of constant value failed + //~| note: in this expansion of panic! + //~| note: inside `g` + //~| note: in this expansion of panic! +} + +const _: () = f(); +//~^ note: inside `_` + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/ctfe-tail-call-panic.stderr b/tests/ui/explicit-tail-calls/ctfe-tail-call-panic.stderr new file mode 100644 index 00000000000..8c070512105 --- /dev/null +++ b/tests/ui/explicit-tail-calls/ctfe-tail-call-panic.stderr @@ -0,0 +1,21 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/ctfe-tail-call-panic.rs:9:5 + | +LL | panic!() + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/ctfe-tail-call-panic.rs:9:5 + | +note: inside `g` + --> $DIR/ctfe-tail-call-panic.rs:9:5 + | +LL | panic!() + | ^^^^^^^^ +note: inside `_` + --> $DIR/ctfe-tail-call-panic.rs:16:15 + | +LL | const _: () = f(); + | ^^^ + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/explicit-tail-calls/drop-order.rs b/tests/ui/explicit-tail-calls/drop-order.rs new file mode 100644 index 00000000000..e20730446ec --- /dev/null +++ b/tests/ui/explicit-tail-calls/drop-order.rs @@ -0,0 +1,70 @@ +// FIXME(explicit_tail_calls): enable this test once rustc_codegen_ssa supports tail calls +//@ ignore-test: tail calls are not implemented in rustc_codegen_ssa yet, so this causes 🧊 +//@ run-pass +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] +use std::cell::RefCell; + +fn main() { + let tail_counter = Default::default(); + tail_recursive(0, &tail_counter); + assert_eq!(tail_counter.into_inner(), (0..128).collect::<Vec<u8>>()); + + let simply_counter = Default::default(); + simply_recursive(0, &simply_counter); + assert_eq!(simply_counter.into_inner(), (0..128).rev().collect::<Vec<u8>>()); + + let scope_counter = Default::default(); + out_of_inner_scope(&scope_counter); + assert_eq!(scope_counter.into_inner(), (0..8).collect::<Vec<u8>>()); +} + +fn tail_recursive(n: u8, order: &RefCell<Vec<u8>>) { + if n >= 128 { + return; + } + + let _local = DropCounter(n, order); + + become tail_recursive(n + 1, order) +} + +fn simply_recursive(n: u8, order: &RefCell<Vec<u8>>) { + if n >= 128 { + return; + } + + let _local = DropCounter(n, order); + + return simply_recursive(n + 1, order); +} + +fn out_of_inner_scope(order: &RefCell<Vec<u8>>) { + fn inner(order: &RefCell<Vec<u8>>) { + let _7 = DropCounter(7, order); + let _6 = DropCounter(6, order); + } + + let _5 = DropCounter(5, order); + let _4 = DropCounter(4, order); + + if true { + let _3 = DropCounter(3, order); + let _2 = DropCounter(2, order); + loop { + let _1 = DropCounter(1, order); + let _0 = DropCounter(0, order); + + become inner(order); + } + } +} + +struct DropCounter<'a>(u8, &'a RefCell<Vec<u8>>); + +impl Drop for DropCounter<'_> { + #[track_caller] + fn drop(&mut self) { + self.1.borrow_mut().push(self.0); + } +} diff --git a/tests/ui/explicit-tail-calls/return-mismatches.rs b/tests/ui/explicit-tail-calls/return-mismatches.rs index 8094a192913..935a1a1d28b 100644 --- a/tests/ui/explicit-tail-calls/return-mismatches.rs +++ b/tests/ui/explicit-tail-calls/return-mismatches.rs @@ -13,7 +13,7 @@ fn _f1() { become _g1(); //~ error: mismatched types } -fn _g1() -> ! { //~ WARN: cannot return without recursing +fn _g1() -> ! { become _g1(); } diff --git a/tests/ui/explicit-tail-calls/return-mismatches.stderr b/tests/ui/explicit-tail-calls/return-mismatches.stderr index 31c7a46ded9..1dcc35797c1 100644 --- a/tests/ui/explicit-tail-calls/return-mismatches.stderr +++ b/tests/ui/explicit-tail-calls/return-mismatches.stderr @@ -22,17 +22,6 @@ error[E0308]: mismatched types LL | become _g2(); | ^^^^^^^^^^^^ expected `u32`, found `u16` -warning: function cannot return without recursing - --> $DIR/return-mismatches.rs:16:1 - | -LL | fn _g1() -> ! { - | ^^^^^^^^^^^^^ cannot return without recursing -LL | become _g1(); - | ----- recursive call site - | - = help: a `loop` may express intention better if this is on purpose - = note: `#[warn(unconditional_recursion)]` on by default - -error: aborting due to 3 previous errors; 1 warning emitted +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/explicit-tail-calls/unsafeck.rs b/tests/ui/explicit-tail-calls/unsafeck.rs new file mode 100644 index 00000000000..872a70ca3a0 --- /dev/null +++ b/tests/ui/explicit-tail-calls/unsafeck.rs @@ -0,0 +1,11 @@ +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +const fn f() { + become dangerous(); + //~^ error: call to unsafe function `dangerous` is unsafe and requires unsafe function or block +} + +const unsafe fn dangerous() {} + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/unsafeck.stderr b/tests/ui/explicit-tail-calls/unsafeck.stderr new file mode 100644 index 00000000000..25b8967e17b --- /dev/null +++ b/tests/ui/explicit-tail-calls/unsafeck.stderr @@ -0,0 +1,11 @@ +error[E0133]: call to unsafe function `dangerous` is unsafe and requires unsafe function or block + --> $DIR/unsafeck.rs:5:12 + | +LL | become dangerous(); + | ^^^^^^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on how to avoid undefined behavior + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs b/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs index ae8005592cd..3257a9ca624 100644 --- a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs +++ b/tests/ui/feature-gates/feature-gate-derive-smart-pointer.rs @@ -1,6 +1,7 @@ use std::marker::SmartPointer; //~ ERROR use of unstable library feature 'derive_smart_pointer' #[derive(SmartPointer)] //~ ERROR use of unstable library feature 'derive_smart_pointer' +#[repr(transparent)] struct MyPointer<'a, #[pointee] T: ?Sized> { //~^ ERROR the `#[pointee]` attribute is an experimental feature ptr: &'a T, diff --git a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr b/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr index 0ffd82fb9e1..19501939dc5 100644 --- a/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr +++ b/tests/ui/feature-gates/feature-gate-derive-smart-pointer.stderr @@ -9,7 +9,7 @@ LL | #[derive(SmartPointer)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: the `#[pointee]` attribute is an experimental feature - --> $DIR/feature-gate-derive-smart-pointer.rs:4:22 + --> $DIR/feature-gate-derive-smart-pointer.rs:5:22 | LL | struct MyPointer<'a, #[pointee] T: ?Sized> { | ^^^^^^^^^^ diff --git a/tests/ui/feature-gates/feature-gate-negate-unsigned.stderr b/tests/ui/feature-gates/feature-gate-negate-unsigned.stderr index d1f4ed5cb04..696326157ce 100644 --- a/tests/ui/feature-gates/feature-gate-negate-unsigned.stderr +++ b/tests/ui/feature-gates/feature-gate-negate-unsigned.stderr @@ -2,12 +2,13 @@ error[E0600]: cannot apply unary operator `-` to type `usize` --> $DIR/feature-gate-negate-unsigned.rs:10:23 | LL | let _max: usize = -1; - | ^^ - | | - | cannot apply unary operator `-` - | help: you may have meant the maximum value of `usize`: `usize::MAX` + | ^^ cannot apply unary operator `-` | = note: unsigned values cannot be negated +help: you may have meant the maximum value of `usize` + | +LL | let _max: usize = usize::MAX; + | ~~~~~~~~~~ error[E0600]: cannot apply unary operator `-` to type `u8` --> $DIR/feature-gate-negate-unsigned.rs:14:14 diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr index 41bd66b13e7..18f46928fab 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr @@ -1,33 +1,13 @@ error[E0658]: return type notation is experimental - --> $DIR/feature-gate-return_type_notation.rs:14:17 + --> $DIR/feature-gate-return_type_notation.rs:10:18 | -LL | fn foo<T: Trait<m(): Send>>() {} - | ^^^^^^^^^ +LL | fn foo<T: Trait<m(..): Send>>() {} + | ^^^^ | = note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information = help: add `#![feature(return_type_notation)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: parenthesized generic arguments cannot be used in associated type constraints - --> $DIR/feature-gate-return_type_notation.rs:14:17 - | -LL | fn foo<T: Trait<m(): Send>>() {} - | ^-- - | | - | help: remove these parentheses - -error: expected type, found function - --> $DIR/feature-gate-return_type_notation.rs:14:17 - | -LL | fn foo<T: Trait<m(): Send>>() {} - | ^ unexpected function - | -note: the associated function is defined here - --> $DIR/feature-gate-return_type_notation.rs:10:5 - | -LL | async fn m(); - | ^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr index 79c626cef35..18f46928fab 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.no.stderr @@ -1,14 +1,13 @@ -warning: return type notation is experimental - --> $DIR/feature-gate-return_type_notation.rs:14:17 +error[E0658]: return type notation is experimental + --> $DIR/feature-gate-return_type_notation.rs:10:18 | -LL | fn foo<T: Trait<m(): Send>>() {} - | ^^^^^^^^^ +LL | fn foo<T: Trait<m(..): Send>>() {} + | ^^^^ | = note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information = help: add `#![feature(return_type_notation)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> -warning: 1 warning emitted +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.rs b/tests/ui/feature-gates/feature-gate-return_type_notation.rs index 7ae6cd0234b..254b794e431 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.rs +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.rs @@ -1,21 +1,13 @@ //@ edition: 2021 //@ revisions: cfg no -//@ [no] check-pass -// Since we're not adding new syntax, `cfg`'d out RTN must pass. - - trait Trait { #[allow(async_fn_in_trait)] async fn m(); } #[cfg(cfg)] -fn foo<T: Trait<m(): Send>>() {} -//[cfg]~^ ERROR return type notation is experimental -//[cfg]~| ERROR parenthesized generic arguments cannot be used in associated type constraints -//[cfg]~| ERROR expected type, found function -//[no]~^^^^ WARN return type notation is experimental -//[no]~| WARN unstable syntax can change at any point in the future, causing a hard error! +fn foo<T: Trait<m(..): Send>>() {} +//~^ ERROR return type notation is experimental fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr b/tests/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr index 1b9febd431d..584724dfe59 100644 --- a/tests/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr +++ b/tests/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr @@ -89,13 +89,14 @@ error[E0053]: method `call` has an incompatible type for trait --> $DIR/feature-gate-unboxed-closures-manual-impls.rs:13:32 | LL | extern "rust-call" fn call(self, args: ()) -> () {} - | ^^^^ - | | - | expected `&Foo`, found `Foo` - | help: change the self-receiver type to match the trait: `&self` + | ^^^^ expected `&Foo`, found `Foo` | = note: expected signature `extern "rust-call" fn(&Foo, ()) -> _` - found signature `extern "rust-call" fn(Foo, ())` + found signature `extern "rust-call" fn(Foo, ()) -> ()` +help: change the self-receiver type to match the trait + | +LL | extern "rust-call" fn call(&self, args: ()) -> () {} + | ~~~~~ error[E0183]: manual implementations of `FnOnce` are experimental --> $DIR/feature-gate-unboxed-closures-manual-impls.rs:18:6 @@ -158,13 +159,14 @@ error[E0053]: method `call_mut` has an incompatible type for trait --> $DIR/feature-gate-unboxed-closures-manual-impls.rs:30:36 | LL | extern "rust-call" fn call_mut(&self, args: ()) -> () {} - | ^^^^^ - | | - | types differ in mutability - | help: change the self-receiver type to match the trait: `&mut self` + | ^^^^^ types differ in mutability | = note: expected signature `extern "rust-call" fn(&mut Bar, ()) -> _` - found signature `extern "rust-call" fn(&Bar, ())` + found signature `extern "rust-call" fn(&Bar, ()) -> ()` +help: change the self-receiver type to match the trait + | +LL | extern "rust-call" fn call_mut(&mut self, args: ()) -> () {} + | ~~~~~~~~~ error[E0046]: not all trait items implemented, missing: `Output` --> $DIR/feature-gate-unboxed-closures-manual-impls.rs:35:1 diff --git a/tests/ui/fmt/struct-field-as-captured-argument.fixed b/tests/ui/fmt/struct-field-as-captured-argument.fixed index e13af744ec8..0da40737354 100644 --- a/tests/ui/fmt/struct-field-as-captured-argument.fixed +++ b/tests/ui/fmt/struct-field-as-captured-argument.fixed @@ -8,11 +8,11 @@ struct Foo { fn main() { let foo = Foo { field: 0 }; let bar = 3; - format!("{0}", foo.field); //~ ERROR invalid format string: field access isn't supported - format!("{1} {} {bar}", "aa", foo.field); //~ ERROR invalid format string: field access isn't supported - format!("{2} {} {1} {bar}", "aa", "bb", foo.field); //~ ERROR invalid format string: field access isn't supported - format!("{1} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported - format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported - format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported - format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{0}", foo.field); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{1} {} {bar}", "aa", foo.field); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{2} {} {1} {bar}", "aa", "bb", foo.field); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{1} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported } diff --git a/tests/ui/fmt/struct-field-as-captured-argument.rs b/tests/ui/fmt/struct-field-as-captured-argument.rs index 6a875a85848..325b4e3a218 100644 --- a/tests/ui/fmt/struct-field-as-captured-argument.rs +++ b/tests/ui/fmt/struct-field-as-captured-argument.rs @@ -8,11 +8,11 @@ struct Foo { fn main() { let foo = Foo { field: 0 }; let bar = 3; - format!("{foo.field}"); //~ ERROR invalid format string: field access isn't supported - format!("{foo.field} {} {bar}", "aa"); //~ ERROR invalid format string: field access isn't supported - format!("{foo.field} {} {1} {bar}", "aa", "bb"); //~ ERROR invalid format string: field access isn't supported - format!("{foo.field} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported - format!("{foo.field:?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported - format!("{foo.field:#?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported - format!("{foo.field:.3} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field}"); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field} {} {bar}", "aa"); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field} {} {1} {bar}", "aa", "bb"); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field:?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field:#?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + let _ = format!("{foo.field:.3} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported } diff --git a/tests/ui/fmt/struct-field-as-captured-argument.stderr b/tests/ui/fmt/struct-field-as-captured-argument.stderr index 7ea8b4068f2..4ef022cecb0 100644 --- a/tests/ui/fmt/struct-field-as-captured-argument.stderr +++ b/tests/ui/fmt/struct-field-as-captured-argument.stderr @@ -1,79 +1,79 @@ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:11:15 + --> $DIR/struct-field-as-captured-argument.rs:11:23 | -LL | format!("{foo.field}"); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field}"); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{0}", foo.field); - | ~ +++++++++++ +LL | let _ = format!("{0}", foo.field); + | ~ +++++++++++ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:12:15 + --> $DIR/struct-field-as-captured-argument.rs:12:23 | -LL | format!("{foo.field} {} {bar}", "aa"); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field} {} {bar}", "aa"); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{1} {} {bar}", "aa", foo.field); - | ~ +++++++++++ +LL | let _ = format!("{1} {} {bar}", "aa", foo.field); + | ~ +++++++++++ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:13:15 + --> $DIR/struct-field-as-captured-argument.rs:13:23 | -LL | format!("{foo.field} {} {1} {bar}", "aa", "bb"); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field} {} {1} {bar}", "aa", "bb"); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{2} {} {1} {bar}", "aa", "bb", foo.field); - | ~ +++++++++++ +LL | let _ = format!("{2} {} {1} {bar}", "aa", "bb", foo.field); + | ~ +++++++++++ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:14:15 + --> $DIR/struct-field-as-captured-argument.rs:14:23 | -LL | format!("{foo.field} {} {baz}", "aa", baz = 3); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{1} {} {baz}", "aa", foo.field, baz = 3); - | ~ +++++++++++ +LL | let _ = format!("{1} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:15:15 + --> $DIR/struct-field-as-captured-argument.rs:15:23 | -LL | format!("{foo.field:?} {} {baz}", "aa", baz = 3); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field:?} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); - | ~ +++++++++++ +LL | let _ = format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:16:15 + --> $DIR/struct-field-as-captured-argument.rs:16:23 | -LL | format!("{foo.field:#?} {} {baz}", "aa", baz = 3); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field:#?} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); - | ~ +++++++++++ +LL | let _ = format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ error: invalid format string: field access isn't supported - --> $DIR/struct-field-as-captured-argument.rs:17:15 + --> $DIR/struct-field-as-captured-argument.rs:17:23 | -LL | format!("{foo.field:.3} {} {baz}", "aa", baz = 3); - | ^^^^^^^^^ not supported in format string +LL | let _ = format!("{foo.field:.3} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string | help: consider using a positional formatting argument instead | -LL | format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); - | ~ +++++++++++ +LL | let _ = format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ error: aborting due to 7 previous errors diff --git a/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr b/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr index 0b3331b040d..5000601e90f 100644 --- a/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr +++ b/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr @@ -10,7 +10,7 @@ LL | x = foo::<()>; | ^^^^^^^^^ expected fn item, found a different fn item | = note: expected fn item `fn(F) -> F {bar::<F>}` - found fn item `fn(()) {foo::<()>}` + found fn item `fn(()) -> () {foo::<()>}` error[E0308]: mismatched types --> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:27:9 @@ -26,7 +26,7 @@ LL | let mut x = bar::<()>; LL | x = foo::<I>; | ^^^^^^^^ expected fn item, found a different fn item | - = note: expected fn item `fn(()) {bar::<()>}` + = note: expected fn item `fn(()) -> () {bar::<()>}` found fn item `fn(I) -> I {foo::<I>}` help: use parentheses to call this function | diff --git a/tests/ui/fn/suggest-return-closure.stderr b/tests/ui/fn/suggest-return-closure.stderr index d276ce8be2b..45c12b548e6 100644 --- a/tests/ui/fn/suggest-return-closure.stderr +++ b/tests/ui/fn/suggest-return-closure.stderr @@ -34,11 +34,13 @@ LL | fn fun() -> _ { error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/suggest-return-closure.rs:23:9 | -LL | let x = String::new(); - | - help: consider changing this to be mutable: `mut x` -... LL | x.push(c); | ^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut x = String::new(); + | +++ error[E0597]: `x` does not live long enough --> $DIR/suggest-return-closure.rs:23:9 diff --git a/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.next.stderr b/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.next.stderr index 9b5d84b5b09..c5c4f2c4d23 100644 --- a/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.next.stderr +++ b/tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.next.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `i32: Baz<Self>` is not satisfied +error[E0277]: the trait bound `<Self as Foo>::Bar<()>: Eq<i32>` is not satisfied --> $DIR/assume-gat-normalization-for-nested-goals.rs:9:30 | LL | type Bar<T>: Baz<Self> = i32; diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed b/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed index 886fc1d0058..3c4499f0173 100644 --- a/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed +++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed @@ -1,6 +1,8 @@ //@ run-rustfix +#[allow(dead_code)] struct S<T>(T); +#[allow(dead_code)] struct S2; impl<T: Default> Default for S<T> { diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.rs b/tests/ui/impl-trait/extra-impl-in-trait-impl.rs index f3271993867..ac078329524 100644 --- a/tests/ui/impl-trait/extra-impl-in-trait-impl.rs +++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.rs @@ -1,6 +1,8 @@ //@ run-rustfix +#[allow(dead_code)] struct S<T>(T); +#[allow(dead_code)] struct S2; impl<T: Default> impl Default for S<T> { diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr index 5aafc8b64d4..91c7da5a04f 100644 --- a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr +++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr @@ -1,23 +1,23 @@ error: unexpected `impl` keyword - --> $DIR/extra-impl-in-trait-impl.rs:6:18 + --> $DIR/extra-impl-in-trait-impl.rs:8:18 | LL | impl<T: Default> impl Default for S<T> { | ^^^^^ help: remove the extra `impl` | note: this is parsed as an `impl Trait` type, but a trait is expected at this position - --> $DIR/extra-impl-in-trait-impl.rs:6:18 + --> $DIR/extra-impl-in-trait-impl.rs:8:18 | LL | impl<T: Default> impl Default for S<T> { | ^^^^^^^^^^^^ error: unexpected `impl` keyword - --> $DIR/extra-impl-in-trait-impl.rs:12:6 + --> $DIR/extra-impl-in-trait-impl.rs:14:6 | LL | impl impl Default for S2 { | ^^^^^ help: remove the extra `impl` | note: this is parsed as an `impl Trait` type, but a trait is expected at this position - --> $DIR/extra-impl-in-trait-impl.rs:12:6 + --> $DIR/extra-impl-in-trait-impl.rs:14:6 | LL | impl impl Default for S2 { | ^^^^^^^^^^^^ diff --git a/tests/ui/impl-trait/impl-generic-mismatch-ab.stderr b/tests/ui/impl-trait/impl-generic-mismatch-ab.stderr index 7046e729e18..90c31c9e3fc 100644 --- a/tests/ui/impl-trait/impl-generic-mismatch-ab.stderr +++ b/tests/ui/impl-trait/impl-generic-mismatch-ab.stderr @@ -2,10 +2,8 @@ error[E0053]: method `foo` has an incompatible type for trait --> $DIR/impl-generic-mismatch-ab.rs:8:32 | LL | fn foo<B: Debug>(&self, a: &impl Debug, b: &B) { } - | - ^^^^^^^^^^^ - | | | - | | expected type parameter `B`, found type parameter `impl Debug` - | | help: change the parameter type to match the trait: `&B` + | - ^^^^^^^^^^^ expected type parameter `B`, found type parameter `impl Debug` + | | | expected type parameter | note: type in trait @@ -17,6 +15,10 @@ LL | fn foo<A: Debug>(&self, a: &A, b: &impl Debug); found signature `fn(&(), &impl Debug, &B)` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters +help: change the parameter type to match the trait + | +LL | fn foo<B: Debug>(&self, a: &B, b: &B) { } + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr index 8e61a65abe4..75cbe43eeb4 100644 --- a/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr +++ b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr @@ -27,10 +27,7 @@ LL | type Ty = impl Sized; | ---------- the expected opaque type LL | LL | fn method() -> () {} - | ^^ - | | - | expected opaque type, found `()` - | help: change the output type to match the trait: `<() as compare_method::Trait>::Ty` + | ^^ expected opaque type, found `()` | note: type in trait --> $DIR/in-assoc-type-unconstrained.rs:17:24 @@ -38,12 +35,16 @@ note: type in trait LL | fn method() -> Self::Ty; | ^^^^^^^^ = note: expected signature `fn() -> <() as compare_method::Trait>::Ty` - found signature `fn()` + found signature `fn() -> ()` note: this item must have the opaque type in its signature in order to be able to register hidden types --> $DIR/in-assoc-type-unconstrained.rs:22:12 | LL | fn method() -> () {} | ^^^^^^ +help: change the output type to match the trait + | +LL | fn method() -> <() as compare_method::Trait>::Ty {} + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unconstrained opaque type --> $DIR/in-assoc-type-unconstrained.rs:20:19 diff --git a/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr new file mode 100644 index 00000000000..d71c1768a6a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr @@ -0,0 +1,173 @@ +error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:5 + | +LL | / fn autobatch<F>(self) -> impl Trait +LL | | +LL | | +LL | | +... | +LL | | where +LL | | F: Callback<Self::CallbackArg>, + | |_______________________________________^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +help: consider further restricting this bound + | +LL | F: Callback<Self::CallbackArg> + MyFn<i32>, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:30 + | +LL | fn autobatch<F>(self) -> impl Trait + | ^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: required by a bound in `<Sender as ChannelSender>::autobatch` + --> $DIR/false-positive-predicate-entailment-error.rs:43:12 + | +LL | fn autobatch<F>(self) -> impl Trait + | --------- required by a bound in this associated function +... +LL | F: Callback<Self::CallbackArg>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `<Sender as ChannelSender>::autobatch` +help: consider further restricting this bound + | +LL | F: Callback<Self::CallbackArg> + MyFn<i32>, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:5 + | +LL | / fn autobatch<F>(self) -> impl Trait +LL | | +LL | | +LL | | +... | +LL | | where +LL | | F: Callback<Self::CallbackArg>, + | |_______________________________________^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting this bound + | +LL | F: Callback<Self::CallbackArg> + MyFn<i32>, + | +++++++++++ + +error[E0277]: the trait bound `F: Callback<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:43:12 + | +LL | F: Callback<Self::CallbackArg>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: the requirement `F: Callback<i32>` appears on the `impl`'s method `autobatch` but not on the corresponding trait's method + --> $DIR/false-positive-predicate-entailment-error.rs:25:8 + | +LL | trait ChannelSender { + | ------------- in this trait +... +LL | fn autobatch<F>(self) -> impl Trait + | ^^^^^^^^^ this trait's method doesn't have the requirement `F: Callback<i32>` +help: consider further restricting this bound + | +LL | F: Callback<Self::CallbackArg> + MyFn<i32>, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:30 + | +LL | fn autobatch<F>(self) -> impl Trait + | ^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0277]: the trait bound `F: Callback<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:27:12 + | +LL | F: Callback<Self::CallbackArg>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:5 + | +LL | / fn autobatch<F>(self) -> impl Trait +LL | | +LL | | +LL | | +... | +LL | | where +LL | | F: Callback<Self::CallbackArg>, + | |_______________________________________^ the trait `MyFn<i32>` is not implemented for `F`, which is required by `F: Callback<i32>` + | +note: required for `F` to implement `Callback<i32>` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl<A, F: MyFn<A>> Callback<A> for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting this bound + | +LL | F: Callback<Self::CallbackArg> + MyFn<i32>, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn<i32>` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:43:12 + | +LL | F: Callback<Self::CallbackArg>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn<i32>` is not implemented for `F` + | +note: required by a bound in `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:10:20 + | +LL | trait Callback<A>: MyFn<A, Output = Self::Ret> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Callback` +help: consider further restricting this bound + | +LL | F: Callback<Self::CallbackArg> + MyFn<i32>, + | +++++++++++ + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs new file mode 100644 index 00000000000..59fdeab9e0a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs @@ -0,0 +1,51 @@ +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver +//@[next] check-pass + +trait MyFn<T> { + type Output; +} + +trait Callback<A>: MyFn<A, Output = Self::Ret> { + type Ret; +} + +impl<A, F: MyFn<A>> Callback<A> for F { + type Ret = F::Output; +} + +struct Thing; +trait Trait {} +impl Trait for Thing {} + +trait ChannelSender { + type CallbackArg; + + fn autobatch<F>(self) -> impl Trait + where + F: Callback<Self::CallbackArg>; + //[current]~^ ERROR the trait bound `F: Callback<i32>` is not satisfied +} + +struct Sender; + +impl ChannelSender for Sender { + type CallbackArg = i32; + + fn autobatch<F>(self) -> impl Trait + //[current]~^ ERROR the trait bound `F: MyFn<i32>` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied + where + F: Callback<Self::CallbackArg>, + //[current]~^ ERROR the trait bound `F: Callback<i32>` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn<i32>` is not satisfied + { + Thing + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr index 2231205327c..6f6b787b6fe 100644 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr @@ -2,10 +2,8 @@ error[E0053]: method `early` has an incompatible type for trait --> $DIR/method-signature-matches.rs:55:27 | LL | fn early<'late, T>(_: &'late ()) {} - | - ^^^^^^^^^ - | | | - | | expected type parameter `T`, found `()` - | | help: change the parameter type to match the trait: `&T` + | - ^^^^^^^^^ expected type parameter `T`, found `()` + | | | expected this type parameter | note: type in trait @@ -15,6 +13,10 @@ LL | fn early<'early, T>(x: &'early T) -> impl Sized; | ^^^^^^^^^ = note: expected signature `fn(&T)` found signature `fn(&'late ())` +help: change the parameter type to match the trait + | +LL | fn early<'late, T>(_: &T) {} + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr index ec2a126865d..9e18517e48c 100644 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr @@ -2,10 +2,7 @@ error[E0053]: method `owo` has an incompatible type for trait --> $DIR/method-signature-matches.rs:11:15 | LL | fn owo(_: u8) {} - | ^^ - | | - | expected `()`, found `u8` - | help: change the parameter type to match the trait: `()` + | ^^ expected `()`, found `u8` | note: type in trait --> $DIR/method-signature-matches.rs:6:15 @@ -14,6 +11,10 @@ LL | fn owo(x: ()) -> impl Sized; | ^^ = note: expected signature `fn(())` found signature `fn(u8)` +help: change the parameter type to match the trait + | +LL | fn owo(_: ()) {} + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr index 4d3e64e8050..c01d7322d11 100644 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr @@ -2,10 +2,7 @@ error[E0053]: method `owo` has an incompatible type for trait --> $DIR/method-signature-matches.rs:22:21 | LL | async fn owo(_: u8) {} - | ^^ - | | - | expected `()`, found `u8` - | help: change the parameter type to match the trait: `()` + | ^^ expected `()`, found `u8` | note: type in trait --> $DIR/method-signature-matches.rs:17:21 @@ -14,6 +11,10 @@ LL | async fn owo(x: ()) {} | ^^ = note: expected signature `fn(()) -> _` found signature `fn(u8) -> _` +help: change the parameter type to match the trait + | +LL | async fn owo(_: ()) {} + | ~~ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr index d7fc40fa342..1f8a0d5edd7 100644 --- a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr +++ b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr @@ -75,10 +75,7 @@ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/opaque-and-lifetime-mismatch.rs:10:17 | LL | fn bar() -> i32 { - | ^^^ - | | - | expected `Wrapper<'static>`, found `i32` - | help: change the output type to match the trait: `Wrapper<'static>` + | ^^^ expected `Wrapper<'static>`, found `i32` | note: type in trait --> $DIR/opaque-and-lifetime-mismatch.rs:4:17 @@ -87,6 +84,10 @@ LL | fn bar() -> Wrapper<impl Sized>; | ^^^^^^^^^^^^^^^^^^^ = note: expected signature `fn() -> Wrapper<'static>` found signature `fn() -> i32` +help: change the output type to match the trait + | +LL | fn bar() -> Wrapper<'static> { + | ~~~~~~~~~~~~~~~~ error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/opaque-and-lifetime-mismatch.rs:24:17 diff --git a/tests/ui/impl-trait/in-trait/specialization-broken.stderr b/tests/ui/impl-trait/in-trait/specialization-broken.stderr index b8a8e2401b2..8c9f2656015 100644 --- a/tests/ui/impl-trait/in-trait/specialization-broken.stderr +++ b/tests/ui/impl-trait/in-trait/specialization-broken.stderr @@ -5,10 +5,7 @@ LL | default impl<U> Foo for U | - found this type parameter ... LL | fn bar(&self) -> U { - | ^ - | | - | expected associated type, found type parameter `U` - | help: change the output type to match the trait: `impl Sized` + | ^ expected associated type, found type parameter `U` | note: type in trait --> $DIR/specialization-broken.rs:8:22 @@ -17,6 +14,10 @@ LL | fn bar(&self) -> impl Sized; | ^^^^^^^^^^ = note: expected signature `fn(&_) -> impl Sized` found signature `fn(&_) -> U` +help: change the output type to match the trait + | +LL | fn bar(&self) -> impl Sized { + | ~~~~~~~~~~ error: method with return-position `impl Trait` in trait cannot be specialized --> $DIR/specialization-broken.rs:15:5 diff --git a/tests/ui/impl-trait/nested_impl_trait.rs b/tests/ui/impl-trait/nested_impl_trait.rs index 502b2af2bc6..760102794c3 100644 --- a/tests/ui/impl-trait/nested_impl_trait.rs +++ b/tests/ui/impl-trait/nested_impl_trait.rs @@ -5,7 +5,7 @@ fn fine(x: impl Into<u32>) -> impl Into<u32> { x } fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x } //~^ ERROR nested `impl Trait` is not allowed -//~| ERROR the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied +//~| ERROR the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {} //~^ ERROR nested `impl Trait` is not allowed @@ -18,7 +18,7 @@ struct X; impl X { fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x } //~^ ERROR nested `impl Trait` is not allowed - //~| ERROR the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied + //~| ERROR the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied } fn allowed_in_assoc_type() -> impl Iterator<Item=impl Fn()> { diff --git a/tests/ui/impl-trait/nested_impl_trait.stderr b/tests/ui/impl-trait/nested_impl_trait.stderr index a53312e5c0b..83d1347aff4 100644 --- a/tests/ui/impl-trait/nested_impl_trait.stderr +++ b/tests/ui/impl-trait/nested_impl_trait.stderr @@ -42,7 +42,7 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {} | = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied +error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied --> $DIR/nested_impl_trait.rs:6:46 | LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x } @@ -51,7 +51,7 @@ LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x } = help: the trait `Into<U>` is implemented for `T` = note: required for `impl Into<u32>` to implement `Into<impl Debug>` -error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied +error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied --> $DIR/nested_impl_trait.rs:19:34 | LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x } diff --git a/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr b/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr index 6d417488533..caaac5434c5 100644 --- a/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr +++ b/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr @@ -57,31 +57,35 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/opaque-used-in-extraneous-argument.rs:17:20 | LL | let old_path = frob("hello"); - | ^^^^ ------- - | | - | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^^ ------- unexpected argument of type `&'static str` | note: function defined here --> $DIR/opaque-used-in-extraneous-argument.rs:5:4 | LL | fn frob() -> impl Fn<P, Output = T> + '_ {} | ^^^^ +help: remove the extra argument + | +LL - let old_path = frob("hello"); +LL + let old_path = frob(); + | error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/opaque-used-in-extraneous-argument.rs:20:5 | LL | open_parent(&old_path) - | ^^^^^^^^^^^ --------- - | | - | unexpected argument of type `&impl FnOnce<{type error}, Output = {type error}> + Fn<{type error}> + 'static` - | help: remove the extra argument + | ^^^^^^^^^^^ --------- unexpected argument of type `&impl FnOnce<{type error}, Output = {type error}> + Fn<{type error}> + 'static` | note: function defined here --> $DIR/opaque-used-in-extraneous-argument.rs:12:4 | LL | fn open_parent<'path>() { | ^^^^^^^^^^^ +help: remove the extra argument + | +LL - open_parent(&old_path) +LL + open_parent() + | error: aborting due to 7 previous errors diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr index 4352af1c0df..3692cc77b0f 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr @@ -26,13 +26,14 @@ LL | type Foo = impl PartialEq<(Foo, i32)>; | -------------------------- the found opaque type ... LL | fn eq(&self, _other: &(Foo, i32)) -> bool { - | ^^^^^^^^^^^ - | | - | expected `a::Bar`, found opaque type - | help: change the parameter type to match the trait: `&(a::Bar, i32)` + | ^^^^^^^^^^^ expected `a::Bar`, found opaque type | = note: expected signature `fn(&a::Bar, &(a::Bar, _)) -> _` found signature `fn(&a::Bar, &(a::Foo, _)) -> _` +help: change the parameter type to match the trait + | +LL | fn eq(&self, _other: &(a::Bar, i32)) -> bool { + | ~~~~~~~~~~~~~~ error: unconstrained opaque type --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:19:16 @@ -49,10 +50,7 @@ LL | type Foo = impl PartialEq<(Foo, i32)>; | -------------------------- the expected opaque type ... LL | fn eq(&self, _other: &(Bar, i32)) -> bool { - | ^^^^^^^^^^^ - | | - | expected opaque type, found `b::Bar` - | help: change the parameter type to match the trait: `&(b::Foo, i32)` + | ^^^^^^^^^^^ expected opaque type, found `b::Bar` | = note: expected signature `fn(&b::Bar, &(b::Foo, _)) -> _` found signature `fn(&b::Bar, &(b::Bar, _)) -> _` @@ -61,6 +59,10 @@ note: this item must have the opaque type in its signature in order to be able t | LL | fn eq(&self, _other: &(Bar, i32)) -> bool { | ^^ +help: change the parameter type to match the trait + | +LL | fn eq(&self, _other: &(b::Foo, i32)) -> bool { + | ~~~~~~~~~~~~~~ error: aborting due to 5 previous errors diff --git a/tests/ui/impl-trait/trait_type.stderr b/tests/ui/impl-trait/trait_type.stderr index 81e4c933e53..989779a6178 100644 --- a/tests/ui/impl-trait/trait_type.stderr +++ b/tests/ui/impl-trait/trait_type.stderr @@ -2,13 +2,14 @@ error[E0053]: method `fmt` has an incompatible type for trait --> $DIR/trait_type.rs:7:21 | LL | fn fmt(&self, x: &str) -> () { } - | ^^^^ - | | - | types differ in mutability - | help: change the parameter type to match the trait: `&mut Formatter<'_>` + | ^^^^ types differ in mutability | = note: expected signature `fn(&MyType, &mut Formatter<'_>) -> Result<(), std::fmt::Error>` - found signature `fn(&MyType, &str)` + found signature `fn(&MyType, &str) -> ()` +help: change the parameter type to match the trait + | +LL | fn fmt(&self, x: &mut Formatter<'_>) -> () { } + | ~~~~~~~~~~~~~~~~~~ error[E0050]: method `fmt` has 1 parameter but the declaration in trait `std::fmt::Display::fmt` has 2 --> $DIR/trait_type.rs:12:11 diff --git a/tests/ui/impl-trait/where-allowed.stderr b/tests/ui/impl-trait/where-allowed.stderr index bffe0447f8b..f0d259d01de 100644 --- a/tests/ui/impl-trait/where-allowed.stderr +++ b/tests/ui/impl-trait/where-allowed.stderr @@ -397,10 +397,7 @@ LL | type Out = impl Debug; | ---------- the expected opaque type ... LL | fn in_trait_impl_return() -> impl Debug { () } - | ^^^^^^^^^^ - | | - | expected opaque type, found a different opaque type - | help: change the output type to match the trait: `<() as DummyTrait>::Out` + | ^^^^^^^^^^ expected opaque type, found a different opaque type | note: type in trait --> $DIR/where-allowed.rs:119:34 @@ -410,6 +407,10 @@ LL | fn in_trait_impl_return() -> Self::Out; = note: expected signature `fn() -> <() as DummyTrait>::Out` found signature `fn() -> impl Debug` = note: distinct uses of `impl Trait` result in different opaque types +help: change the output type to match the trait + | +LL | fn in_trait_impl_return() -> <() as DummyTrait>::Out { () } + | ~~~~~~~~~~~~~~~~~~~~~~~ error: unconstrained opaque type --> $DIR/where-allowed.rs:122:16 diff --git a/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr index e2ddf474c4a..a5cd057e284 100644 --- a/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr +++ b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr @@ -55,16 +55,18 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:21:31 | LL | LendingIterator::for_each(Query::new(&data), Box::new); - | ^^^^^^^^^^ ----- - | | - | unexpected argument of type `&fn() {data}` - | help: remove the extra argument + | ^^^^^^^^^^ ----- unexpected argument of type `&fn() {data}` | note: associated function defined here --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:17:12 | LL | pub fn new() -> Self {} | ^^^ +help: remove the extra argument + | +LL - LendingIterator::for_each(Query::new(&data), Box::new); +LL + LendingIterator::for_each(Query::new(), Box::new); + | error: aborting due to 6 previous errors diff --git a/tests/ui/intrinsics/not-overridden.rs b/tests/ui/intrinsics/not-overridden.rs index a53071e304d..93b408331b8 100644 --- a/tests/ui/intrinsics/not-overridden.rs +++ b/tests/ui/intrinsics/not-overridden.rs @@ -1,6 +1,6 @@ //! Check that intrinsics that do not get overridden, but are marked as such, //! cause an error instead of silently invoking the body. -#![feature(rustc_attrs/* , effects*/)] // FIXME(effects) +#![feature(rustc_attrs)] //@ build-fail //@ failure-status:101 //@ normalize-stderr-test ".*note: .*\n\n" -> "" diff --git a/tests/ui/intrinsics/safe-intrinsic-mismatch.effects.stderr b/tests/ui/intrinsics/safe-intrinsic-mismatch.effects.stderr new file mode 100644 index 00000000000..d9a4960feec --- /dev/null +++ b/tests/ui/intrinsics/safe-intrinsic-mismatch.effects.stderr @@ -0,0 +1,52 @@ +error: using `#![feature(effects)]` without enabling next trait solver globally + | + = note: the next trait solver must be enabled globally for the effects feature to work correctly + = help: use `-Znext-solver` to enable + +error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of` + --> $DIR/safe-intrinsic-mismatch.rs:11:5 + | +LL | fn size_of<T>() -> usize; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of` + --> $DIR/safe-intrinsic-mismatch.rs:11:5 + | +LL | fn size_of<T>() -> usize; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume` + --> $DIR/safe-intrinsic-mismatch.rs:16:1 + | +LL | const fn assume(_b: bool) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: intrinsic has wrong type + --> $DIR/safe-intrinsic-mismatch.rs:16:16 + | +LL | const fn assume(_b: bool) {} + | ^ expected unsafe fn, found safe fn + | + = note: expected signature `unsafe fn(_)` + found signature `fn(_)` + +error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate` + --> $DIR/safe-intrinsic-mismatch.rs:20:1 + | +LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: intrinsic has wrong type + --> $DIR/safe-intrinsic-mismatch.rs:20:26 + | +LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {} + | ^ expected unsafe fn, found safe fn + | + = note: expected signature `unsafe fn(_, _, _)` + found signature `fn(_, _, _)` + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/intrinsics/safe-intrinsic-mismatch.rs b/tests/ui/intrinsics/safe-intrinsic-mismatch.rs index c116ba7a62e..af563e996c1 100644 --- a/tests/ui/intrinsics/safe-intrinsic-mismatch.rs +++ b/tests/ui/intrinsics/safe-intrinsic-mismatch.rs @@ -1,6 +1,11 @@ +//@ revisions: stock effects #![feature(intrinsics)] #![feature(rustc_attrs)] -// FIXME(effects) do this with revisions #![feature(effects)] +// as effects insert a const generic param to const intrinsics, +// check here that it doesn't report a const param mismatch either +// enabling or disabling effects. +#![cfg_attr(effects, feature(effects))] +#![allow(incomplete_features)] extern "rust-intrinsic" { fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch diff --git a/tests/ui/intrinsics/safe-intrinsic-mismatch.stderr b/tests/ui/intrinsics/safe-intrinsic-mismatch.stock.stderr index 7f37e0f8211..6864c0f36de 100644 --- a/tests/ui/intrinsics/safe-intrinsic-mismatch.stderr +++ b/tests/ui/intrinsics/safe-intrinsic-mismatch.stock.stderr @@ -1,11 +1,11 @@ error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of` - --> $DIR/safe-intrinsic-mismatch.rs:6:5 + --> $DIR/safe-intrinsic-mismatch.rs:11:5 | LL | fn size_of<T>() -> usize; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of` - --> $DIR/safe-intrinsic-mismatch.rs:6:5 + --> $DIR/safe-intrinsic-mismatch.rs:11:5 | LL | fn size_of<T>() -> usize; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | fn size_of<T>() -> usize; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume` - --> $DIR/safe-intrinsic-mismatch.rs:11:1 + --> $DIR/safe-intrinsic-mismatch.rs:16:1 | LL | const fn assume(_b: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: intrinsic has wrong type - --> $DIR/safe-intrinsic-mismatch.rs:11:16 + --> $DIR/safe-intrinsic-mismatch.rs:16:16 | LL | const fn assume(_b: bool) {} | ^ expected unsafe fn, found safe fn @@ -28,13 +28,13 @@ LL | const fn assume(_b: bool) {} found signature `fn(_)` error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate` - --> $DIR/safe-intrinsic-mismatch.rs:15:1 + --> $DIR/safe-intrinsic-mismatch.rs:20:1 | LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: intrinsic has wrong type - --> $DIR/safe-intrinsic-mismatch.rs:15:26 + --> $DIR/safe-intrinsic-mismatch.rs:20:26 | LL | const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {} | ^ expected unsafe fn, found safe fn diff --git a/tests/ui/issues/issue-11004.stderr b/tests/ui/issues/issue-11004.stderr index ea141e61df8..6d157c91130 100644 --- a/tests/ui/issues/issue-11004.stderr +++ b/tests/ui/issues/issue-11004.stderr @@ -2,19 +2,23 @@ error[E0609]: no field `x` on type `*mut A` --> $DIR/issue-11004.rs:7:21 | LL | let x : i32 = n.x; - | --^ - | | | - | | unknown field - | help: `n` is a raw pointer; try dereferencing it: `(*n).x` + | ^ unknown field + | +help: `n` is a raw pointer; try dereferencing it + | +LL | let x : i32 = (*n).x; + | ++ + error[E0609]: no field `y` on type `*mut A` --> $DIR/issue-11004.rs:8:21 | LL | let y : f64 = n.y; - | --^ - | | | - | | unknown field - | help: `n` is a raw pointer; try dereferencing it: `(*n).y` + | ^ unknown field + | +help: `n` is a raw pointer; try dereferencing it + | +LL | let y : f64 = (*n).y; + | ++ + error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-16939.stderr b/tests/ui/issues/issue-16939.stderr index 229ff9f1817..6e0889b8963 100644 --- a/tests/ui/issues/issue-16939.stderr +++ b/tests/ui/issues/issue-16939.stderr @@ -2,16 +2,18 @@ error[E0057]: this function takes 0 arguments but 1 argument was supplied --> $DIR/issue-16939.rs:5:9 | LL | |t| f(t); - | ^ - - | | - | unexpected argument - | help: remove the extra argument + | ^ - unexpected argument | note: callable defined here --> $DIR/issue-16939.rs:4:12 | LL | fn _foo<F: Fn()> (f: F) { | ^^^^ +help: remove the extra argument + | +LL - |t| f(t); +LL + |t| f(); + | error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-20225.stderr b/tests/ui/issues/issue-20225.stderr index 2d24a5bbd50..7d6b09cf7f8 100644 --- a/tests/ui/issues/issue-20225.stderr +++ b/tests/ui/issues/issue-20225.stderr @@ -4,13 +4,14 @@ error[E0053]: method `call` has an incompatible type for trait LL | impl<'a, T> Fn<(&'a T,)> for Foo { | - found this type parameter LL | extern "rust-call" fn call(&self, (_,): (T,)) {} - | ^^^^ - | | - | expected `&'a T`, found type parameter `T` - | help: change the parameter type to match the trait: `(&'a T,)` + | ^^^^ expected `&'a T`, found type parameter `T` | = note: expected signature `extern "rust-call" fn(&Foo, (&'a _,))` found signature `extern "rust-call" fn(&Foo, (_,))` +help: change the parameter type to match the trait + | +LL | extern "rust-call" fn call(&self, (_,): (&'a T,)) {} + | ~~~~~~~~ error[E0053]: method `call_mut` has an incompatible type for trait --> $DIR/issue-20225.rs:11:51 @@ -18,13 +19,14 @@ error[E0053]: method `call_mut` has an incompatible type for trait LL | impl<'a, T> FnMut<(&'a T,)> for Foo { | - found this type parameter LL | extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {} - | ^^^^ - | | - | expected `&'a T`, found type parameter `T` - | help: change the parameter type to match the trait: `(&'a T,)` + | ^^^^ expected `&'a T`, found type parameter `T` | = note: expected signature `extern "rust-call" fn(&mut Foo, (&'a _,))` found signature `extern "rust-call" fn(&mut Foo, (_,))` +help: change the parameter type to match the trait + | +LL | extern "rust-call" fn call_mut(&mut self, (_,): (&'a T,)) {} + | ~~~~~~~~ error[E0053]: method `call_once` has an incompatible type for trait --> $DIR/issue-20225.rs:18:47 @@ -33,13 +35,14 @@ LL | impl<'a, T> FnOnce<(&'a T,)> for Foo { | - found this type parameter ... LL | extern "rust-call" fn call_once(self, (_,): (T,)) {} - | ^^^^ - | | - | expected `&'a T`, found type parameter `T` - | help: change the parameter type to match the trait: `(&'a T,)` + | ^^^^ expected `&'a T`, found type parameter `T` | = note: expected signature `extern "rust-call" fn(Foo, (&'a _,))` found signature `extern "rust-call" fn(Foo, (_,))` +help: change the parameter type to match the trait + | +LL | extern "rust-call" fn call_once(self, (_,): (&'a T,)) {} + | ~~~~~~~~ error: aborting due to 3 previous errors diff --git a/tests/ui/issues/issue-20676.rs b/tests/ui/issues/issue-20676.rs index b3319950b42..2059365c7d6 100644 --- a/tests/ui/issues/issue-20676.rs +++ b/tests/ui/issues/issue-20676.rs @@ -8,5 +8,5 @@ use std::fmt; fn main() { let a: &dyn fmt::Debug = &1; - format!("{:?}", a); + let _ = format!("{:?}", a); } diff --git a/tests/ui/issues/issue-21332.stderr b/tests/ui/issues/issue-21332.stderr index 96e0f5fdb31..7c960f7646d 100644 --- a/tests/ui/issues/issue-21332.stderr +++ b/tests/ui/issues/issue-21332.stderr @@ -2,13 +2,14 @@ error[E0053]: method `next` has an incompatible type for trait --> $DIR/issue-21332.rs:5:27 | LL | fn next(&mut self) -> Result<i32, i32> { Ok(7) } - | ^^^^^^^^^^^^^^^^ - | | - | expected `Option<i32>`, found `Result<i32, i32>` - | help: change the output type to match the trait: `Option<i32>` + | ^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Result<i32, i32>` | = note: expected signature `fn(&mut S) -> Option<i32>` found signature `fn(&mut S) -> Result<i32, i32>` +help: change the output type to match the trait + | +LL | fn next(&mut self) -> Option<i32> { Ok(7) } + | ~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-21950.stderr b/tests/ui/issues/issue-21950.stderr index e498565d4e6..584370c7178 100644 --- a/tests/ui/issues/issue-21950.stderr +++ b/tests/ui/issues/issue-21950.stderr @@ -14,9 +14,13 @@ LL | trait Add<Rhs=Self> { | ------------------- type parameter `Rhs` must be specified for this ... LL | let x = &10 as &dyn Add; - | ^^^ help: set the type parameter to the desired type: `Add<Rhs>` + | ^^^ | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | let x = &10 as &dyn Add<Rhs>; + | +++++ error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-22370.stderr b/tests/ui/issues/issue-22370.stderr index 977cfe06bb8..3dc060963f9 100644 --- a/tests/ui/issues/issue-22370.stderr +++ b/tests/ui/issues/issue-22370.stderr @@ -5,9 +5,13 @@ LL | trait A<T=Self> {} | --------------- type parameter `T` must be specified for this LL | LL | fn f(a: &dyn A) {} - | ^ help: set the type parameter to the desired type: `A<T>` + | ^ | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | fn f(a: &dyn A<T>) {} + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-4935.stderr b/tests/ui/issues/issue-4935.stderr index 25f299ae5f3..f18cf66f14d 100644 --- a/tests/ui/issues/issue-4935.stderr +++ b/tests/ui/issues/issue-4935.stderr @@ -2,16 +2,18 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/issue-4935.rs:5:13 | LL | fn main() { foo(5, 6) } - | ^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/issue-4935.rs:3:4 | LL | fn foo(a: usize) {} | ^^^ -------- +help: remove the extra argument + | +LL - fn main() { foo(5, 6) } +LL + fn main() { foo(5) } + | error: aborting due to 1 previous error diff --git a/tests/ui/lang-items/start_lang_item_args.missing_ret.stderr b/tests/ui/lang-items/start_lang_item_args.missing_ret.stderr index aa1b1b73bae..2672efe51c9 100644 --- a/tests/ui/lang-items/start_lang_item_args.missing_ret.stderr +++ b/tests/ui/lang-items/start_lang_item_args.missing_ret.stderr @@ -5,7 +5,7 @@ LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpi | ^ expected `isize`, found `()` | = note: expected signature `fn(fn() -> _, _, _, _) -> isize` - found signature `fn(fn() -> _, _, _, _)` + found signature `fn(fn() -> _, _, _, _) -> ()` error: aborting due to 1 previous error diff --git a/tests/ui/let-else/let-else-slicing-error.stderr b/tests/ui/let-else/let-else-slicing-error.stderr index 73c357dd5d4..4daae861965 100644 --- a/tests/ui/let-else/let-else-slicing-error.stderr +++ b/tests/ui/let-else/let-else-slicing-error.stderr @@ -2,9 +2,12 @@ error[E0529]: expected an array or slice, found `Vec<{integer}>` --> $DIR/let-else-slicing-error.rs:6:9 | LL | let [x, y] = nums else { - | ^^^^^^ ---- help: consider slicing here: `nums[..]` - | | - | pattern cannot match with input type `Vec<{integer}>` + | ^^^^^^ pattern cannot match with input type `Vec<{integer}>` + | +help: consider slicing here + | +LL | let [x, y] = nums[..] else { + | ++++ error: aborting due to 1 previous error diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-2.stderr b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-2.stderr index 0980de92d35..29bf7e62985 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-2.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-2.stderr @@ -16,10 +16,13 @@ LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: &'a u32) { error[E0384]: cannot assign to immutable argument `y` --> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5 | -LL | fn foo(mut x: Ref, y: &u32) { - | - help: consider making this binding mutable: `mut y` LL | y = x.b; | ^^^^^^^ cannot assign to immutable argument + | +help: consider making this binding mutable + | +LL | fn foo(mut x: Ref, mut y: &u32) { + | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/lifetimes/lifetime-errors/liveness-assign-imm-local-notes.stderr b/tests/ui/lifetimes/lifetime-errors/liveness-assign-imm-local-notes.stderr index b47a47d631e..3fbd863467d 100644 --- a/tests/ui/lifetimes/lifetime-errors/liveness-assign-imm-local-notes.stderr +++ b/tests/ui/lifetimes/lifetime-errors/liveness-assign-imm-local-notes.stderr @@ -1,45 +1,53 @@ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/liveness-assign-imm-local-notes.rs:10:9 | -LL | let x; - | - help: consider making this binding mutable: `mut x` -... LL | x = 2; | ----- first assignment to `x` LL | x = 3; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut x; + | +++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/liveness-assign-imm-local-notes.rs:21:13 | -LL | let x; - | - help: consider making this binding mutable: `mut x` -... LL | x = 2; | ----- first assignment to `x` LL | x = 3; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut x; + | +++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/liveness-assign-imm-local-notes.rs:30:13 | -LL | let x; - | - help: consider making this binding mutable: `mut x` -... LL | x = 1; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut x; + | +++ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/liveness-assign-imm-local-notes.rs:32:13 | -LL | let x; - | - help: consider making this binding mutable: `mut x` -... LL | x = 1; | ----- first assignment to `x` LL | } else { LL | x = 2; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut x; + | +++ error: aborting due to 4 previous errors diff --git a/tests/ui/lint/dead-code/issue-59003.rs b/tests/ui/lint/dead-code/issue-59003.rs index e3dcaca5778..319cf2db149 100644 --- a/tests/ui/lint/dead-code/issue-59003.rs +++ b/tests/ui/lint/dead-code/issue-59003.rs @@ -4,8 +4,8 @@ #![deny(dead_code)] +#[allow(dead_code)] struct Foo { - #[allow(dead_code)] inner: u32, } diff --git a/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs b/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs new file mode 100644 index 00000000000..25777438456 --- /dev/null +++ b/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs @@ -0,0 +1,37 @@ +#![deny(dead_code)] + +struct Foo(u8); //~ ERROR struct `Foo` is never constructed + +enum Bar { //~ ERROR enum `Bar` is never used + Var1(u8), + Var2(u8), +} + +pub trait Tr1 { + fn f1() -> Self; +} + +impl Tr1 for Foo { + fn f1() -> Foo { + let f = Foo(0); + let Foo(tag) = f; + Foo(tag) + } +} + +impl Tr1 for Bar { + fn f1() -> Bar { + let b = Bar::Var1(0); + let b = if let Bar::Var1(_) = b { + Bar::Var1(0) + } else { + Bar::Var2(0) + }; + match b { + Bar::Var1(_) => Bar::Var2(0), + Bar::Var2(_) => Bar::Var1(0), + } + } +} + +fn main() {} diff --git a/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr b/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr new file mode 100644 index 00000000000..7c1a4b45977 --- /dev/null +++ b/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr @@ -0,0 +1,20 @@ +error: struct `Foo` is never constructed + --> $DIR/lint-unused-adt-appeared-in-pattern.rs:3:8 + | +LL | struct Foo(u8); + | ^^^ + | +note: the lint level is defined here + --> $DIR/lint-unused-adt-appeared-in-pattern.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: enum `Bar` is never used + --> $DIR/lint-unused-adt-appeared-in-pattern.rs:5:6 + | +LL | enum Bar { + | ^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs b/tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs new file mode 100644 index 00000000000..43a2e431904 --- /dev/null +++ b/tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs @@ -0,0 +1,32 @@ +//@ check-pass + +#![deny(dead_code)] + +#[repr(u8)] +#[derive(Copy, Clone, Debug)] +pub enum RecordField { + Target = 1, + Level, + Module, + File, + Line, + NumArgs, +} + +unsafe trait Pod {} + +#[repr(transparent)] +struct RecordFieldWrapper(RecordField); + +unsafe impl Pod for RecordFieldWrapper {} + +fn try_read<T: Pod>(buf: &[u8]) -> T { + unsafe { std::ptr::read_unaligned(buf.as_ptr() as *const T) } +} + +pub fn foo(buf: &[u8]) -> RecordField { + let RecordFieldWrapper(tag) = try_read(buf); + tag +} + +fn main() {} diff --git a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs index bf2fc243e81..658cc3d6c61 100644 --- a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs +++ b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs @@ -1,8 +1,9 @@ #![deny(dead_code)] struct T1; //~ ERROR struct `T1` is never constructed -pub struct T2(i32); //~ ERROR struct `T2` is never constructed -struct T3; +struct T2; //~ ERROR struct `T2` is never constructed +pub struct T3(i32); //~ ERROR struct `T3` is never constructed +pub struct T4(i32); //~ ERROR field `0` is never read trait Trait1 { //~ ERROR trait `Trait1` is never used const UNUSED: i32; @@ -11,13 +12,13 @@ trait Trait1 { //~ ERROR trait `Trait1` is never used } pub trait Trait2 { - const USED: i32; - fn used(&self) {} + const MAY_USED: i32; + fn may_used(&self) {} } pub trait Trait3 { - const USED: i32; - fn construct_self() -> Self; + const MAY_USED: i32; + fn may_used() -> Self; } impl Trait1 for T1 { @@ -30,23 +31,34 @@ impl Trait1 for T1 { impl Trait1 for T2 { const UNUSED: i32 = 0; fn construct_self() -> Self { - T2(0) + Self } } impl Trait2 for T1 { - const USED: i32 = 0; + const MAY_USED: i32 = 0; } impl Trait2 for T2 { - const USED: i32 = 0; + const MAY_USED: i32 = 0; } -impl Trait3 for T3 { - const USED: i32 = 0; - fn construct_self() -> Self { +impl Trait2 for T3 { + const MAY_USED: i32 = 0; +} + +impl Trait3 for T2 { + const MAY_USED: i32 = 0; + fn may_used() -> Self { Self } } +impl Trait3 for T4 { + const MAY_USED: i32 = 0; + fn may_used() -> Self { + T4(0) + } +} + fn main() {} diff --git a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr index 174096d9398..08c7a5cb4b0 100644 --- a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr +++ b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr @@ -11,16 +11,32 @@ LL | #![deny(dead_code)] | ^^^^^^^^^ error: struct `T2` is never constructed - --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:4:12 + --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:4:8 | -LL | pub struct T2(i32); +LL | struct T2; + | ^^ + +error: struct `T3` is never constructed + --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:5:12 + | +LL | pub struct T3(i32); | ^^ +error: field `0` is never read + --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:6:15 + | +LL | pub struct T4(i32); + | -- ^^^ + | | + | field in this struct + | + = help: consider removing this field + error: trait `Trait1` is never used - --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:7:7 + --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:8:7 | LL | trait Trait1 { | ^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors diff --git a/tests/ui/lint/dead-code/unused-struct-derive-default.rs b/tests/ui/lint/dead-code/unused-struct-derive-default.rs index 330ad32dd57..f20b7cb66ee 100644 --- a/tests/ui/lint/dead-code/unused-struct-derive-default.rs +++ b/tests/ui/lint/dead-code/unused-struct-derive-default.rs @@ -22,4 +22,5 @@ pub struct T2 { fn main() { let _x: Used = Default::default(); + let _e: E = Default::default(); } diff --git a/tests/ui/lint/dead-code/unused-struct-derive-default.stderr b/tests/ui/lint/dead-code/unused-struct-derive-default.stderr index bbb0bd7be70..7422f9a39f3 100644 --- a/tests/ui/lint/dead-code/unused-struct-derive-default.stderr +++ b/tests/ui/lint/dead-code/unused-struct-derive-default.stderr @@ -4,7 +4,6 @@ error: struct `T` is never constructed LL | struct T; | ^ | - = note: `T` has a derived impl for the trait `Default`, but this is intentionally ignored during dead code analysis note: the lint level is defined here --> $DIR/unused-struct-derive-default.rs:1:9 | diff --git a/tests/ui/lint/lint-unconditional-recursion-tail-calls.rs b/tests/ui/lint/lint-unconditional-recursion-tail-calls.rs new file mode 100644 index 00000000000..c94bf032579 --- /dev/null +++ b/tests/ui/lint/lint-unconditional-recursion-tail-calls.rs @@ -0,0 +1,24 @@ +#![allow(incomplete_features, dead_code)] +#![deny(unconditional_recursion)] //~ note: the lint level is defined here +#![feature(explicit_tail_calls)] + +fn f(x: bool) { + //~^ error: function cannot return without recursing + //~| note: cannot return without recursing + if x { + become f(!x) + } else { + f(!x) //~ note: recursive call site + } +} + +// This should *not* lint, tail-recursive functions which never return is a reasonable thing +fn g(x: bool) { + if x { + become g(!x) + } else { + become g(!x) + } +} + +fn main() {} diff --git a/tests/ui/lint/lint-unconditional-recursion-tail-calls.stderr b/tests/ui/lint/lint-unconditional-recursion-tail-calls.stderr new file mode 100644 index 00000000000..52f9740d027 --- /dev/null +++ b/tests/ui/lint/lint-unconditional-recursion-tail-calls.stderr @@ -0,0 +1,18 @@ +error: function cannot return without recursing + --> $DIR/lint-unconditional-recursion-tail-calls.rs:5:1 + | +LL | fn f(x: bool) { + | ^^^^^^^^^^^^^ cannot return without recursing +... +LL | f(!x) + | ----- recursive call site + | + = help: a `loop` may express intention better if this is on purpose +note: the lint level is defined here + --> $DIR/lint-unconditional-recursion-tail-calls.rs:2:9 + | +LL | #![deny(unconditional_recursion)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs index 08911c5bde7..d2f32a47122 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs @@ -1,7 +1,7 @@ fn test() { let v: isize; //~^ HELP consider making this binding mutable - //~| SUGGESTION mut v + //~| SUGGESTION mut loop { v = 1; //~ ERROR cannot assign twice to immutable variable `v` //~| NOTE cannot assign twice to immutable variable diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr index f0174560fd5..e8c0721b903 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr @@ -1,11 +1,13 @@ error[E0384]: cannot assign twice to immutable variable `v` --> $DIR/liveness-assign-imm-local-in-loop.rs:6:9 | -LL | let v: isize; - | - help: consider making this binding mutable: `mut v` -... LL | v = 1; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut v: isize; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs index 1752d969086..fd6b4bcdf84 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs @@ -1,7 +1,7 @@ fn test() { let v: isize; //~^ HELP consider making this binding mutable - //~| SUGGESTION mut v + //~| SUGGESTION mut v = 2; //~ NOTE first assignment v += 1; //~ ERROR cannot assign twice to immutable variable `v` //~| NOTE cannot assign twice to immutable diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr index 578a40e4070..b7373d7cf1d 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr @@ -1,13 +1,15 @@ error[E0384]: cannot assign twice to immutable variable `v` --> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5 | -LL | let v: isize; - | - help: consider making this binding mutable: `mut v` -... LL | v = 2; | ----- first assignment to `v` LL | v += 1; | ^^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut v: isize; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs index c9b16e43910..b7050d69306 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs @@ -1,7 +1,7 @@ fn test() { let b = Box::new(1); //~ NOTE first assignment //~| HELP consider making this binding mutable - //~| SUGGESTION mut b + //~| SUGGESTION mut drop(b); b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` //~| NOTE cannot assign twice to immutable diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr index 2f55b50f0ba..35b47bd6d91 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr @@ -2,13 +2,15 @@ error[E0384]: cannot assign twice to immutable variable `b` --> $DIR/liveness-assign-imm-local-with-drop.rs:6:5 | LL | let b = Box::new(1); - | - - | | - | first assignment to `b` - | help: consider making this binding mutable: `mut b` + | - first assignment to `b` ... LL | b = Box::new(2); | ^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut b = Box::new(1); + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs index 4bb2db27a16..67c97e38546 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs @@ -1,7 +1,7 @@ fn test() { let v: isize = 1; //~ NOTE first assignment //~| HELP consider making this binding mutable - //~| SUGGESTION mut v + //~| SUGGESTION mut v.clone(); v = 2; //~ ERROR cannot assign twice to immutable variable `v` //~| NOTE cannot assign twice to immutable diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr index 8eb71cd99bf..d1f9e1573e4 100644 --- a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr @@ -2,13 +2,15 @@ error[E0384]: cannot assign twice to immutable variable `v` --> $DIR/liveness-assign-imm-local-with-init.rs:6:5 | LL | let v: isize = 1; - | - - | | - | first assignment to `v` - | help: consider making this binding mutable: `mut v` + | - first assignment to `v` ... LL | v = 2; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +LL | let mut v: isize = 1; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs b/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs index e44eeffb01b..1acefa314aa 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs +++ b/tests/ui/macros/macro-metavar-expr-concat/allowed-operations.rs @@ -37,6 +37,16 @@ macro_rules! without_dollar_sign_is_an_ident { }; } +macro_rules! literals { + ($ident:ident) => {{ + let ${concat(_a, "_b")}: () = (); + let ${concat("_b", _a)}: () = (); + + let ${concat($ident, "_b")}: () = (); + let ${concat("_b", $ident)}: () = (); + }}; +} + fn main() { create_things!(behold); behold_separated_idents_in_a_fn(); @@ -55,4 +65,6 @@ fn main() { without_dollar_sign_is_an_ident!(_123); assert_eq!(VARident, 1); assert_eq!(VAR_123, 2); + + literals!(_hello); } diff --git a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs b/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs index f72b9baca89..b1cb2141cc4 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs +++ b/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.rs @@ -26,14 +26,14 @@ macro_rules! idents_11 { macro_rules! no_params { () => { let ${concat(r#abc, abc)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers + //~^ ERROR expected identifier or string literal //~| ERROR expected pattern, found `$` let ${concat(abc, r#abc)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers + //~^ ERROR expected identifier or string literal let ${concat(r#abc, r#abc)}: () = (); - //~^ ERROR `${concat(..)}` currently does not support raw identifiers + //~^ ERROR expected identifier or string literal }; } diff --git a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr b/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr index dd525cf0801..4e11e20acc5 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr +++ b/tests/ui/macros/macro-metavar-expr-concat/raw-identifiers.stderr @@ -1,16 +1,16 @@ -error: `${concat(..)}` currently does not support raw identifiers +error: expected identifier or string literal --> $DIR/raw-identifiers.rs:28:22 | LL | let ${concat(r#abc, abc)}: () = (); | ^^^^^ -error: `${concat(..)}` currently does not support raw identifiers +error: expected identifier or string literal --> $DIR/raw-identifiers.rs:32:27 | LL | let ${concat(abc, r#abc)}: () = (); | ^^^^^ -error: `${concat(..)}` currently does not support raw identifiers +error: expected identifier or string literal --> $DIR/raw-identifiers.rs:35:22 | LL | let ${concat(r#abc, r#abc)}: () = (); diff --git a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs b/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs index bf47442ea76..b2845c8d1c1 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs +++ b/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.rs @@ -11,9 +11,6 @@ macro_rules! wrong_concat_declarations { ${concat(aaaa,)} //~^ ERROR expected identifier - ${concat(aaaa, 1)} - //~^ ERROR expected identifier - ${concat(_, aaaa)} ${concat(aaaa aaaa)} @@ -30,9 +27,6 @@ macro_rules! wrong_concat_declarations { ${concat($ex, aaaa,)} //~^ ERROR expected identifier - - ${concat($ex, aaaa, 123)} - //~^ ERROR expected identifier }; } @@ -43,8 +37,80 @@ macro_rules! dollar_sign_without_referenced_ident { }; } +macro_rules! starting_number { + ($ident:ident) => {{ + let ${concat("1", $ident)}: () = (); + //~^ ERROR `${concat(..)}` is not generating a valid identifier + }}; +} + +macro_rules! starting_valid_unicode { + ($ident:ident) => {{ + let ${concat("Ý", $ident)}: () = (); + }}; +} + +macro_rules! starting_invalid_unicode { + ($ident:ident) => {{ + let ${concat("\u{00BD}", $ident)}: () = (); + //~^ ERROR `${concat(..)}` is not generating a valid identifier + }}; +} + +macro_rules! ending_number { + ($ident:ident) => {{ + let ${concat($ident, "1")}: () = (); + }}; +} + +macro_rules! ending_valid_unicode { + ($ident:ident) => {{ + let ${concat($ident, "Ý")}: () = (); + }}; +} + +macro_rules! ending_invalid_unicode { + ($ident:ident) => {{ + let ${concat($ident, "\u{00BD}")}: () = (); + //~^ ERROR `${concat(..)}` is not generating a valid identifier + }}; +} + +macro_rules! empty { + () => {{ + let ${concat("", "")}: () = (); + //~^ ERROR `${concat(..)}` is not generating a valid identifier + }}; +} + +macro_rules! unsupported_literals { + ($ident:ident) => {{ + let ${concat(_a, 'b')}: () = (); + //~^ ERROR expected identifier or string literal + //~| ERROR expected pattern + let ${concat(_a, 1)}: () = (); + //~^ ERROR expected identifier or string literal + + let ${concat($ident, 'b')}: () = (); + //~^ ERROR expected identifier or string literal + let ${concat($ident, 1)}: () = (); + //~^ ERROR expected identifier or string literal + }}; +} + fn main() { wrong_concat_declarations!(1); dollar_sign_without_referenced_ident!(VAR); + + starting_number!(_abc); + starting_valid_unicode!(_abc); + starting_invalid_unicode!(_abc); + + ending_number!(_abc); + ending_valid_unicode!(_abc); + ending_invalid_unicode!(_abc); + unsupported_literals!(_abc); + + empty!(); } diff --git a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr b/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr index b216a86d59a..2fe5842b39e 100644 --- a/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr +++ b/tests/ui/macros/macro-metavar-expr-concat/syntax-errors.stderr @@ -1,4 +1,4 @@ -error: expected identifier +error: expected identifier or string literal --> $DIR/syntax-errors.rs:5:10 | LL | ${concat()} @@ -10,59 +10,126 @@ error: `concat` must have at least two elements LL | ${concat(aaaa)} | ^^^^^^ -error: expected identifier +error: expected identifier or string literal --> $DIR/syntax-errors.rs:11:10 | LL | ${concat(aaaa,)} | ^^^^^^^^^^^^^^^ -error: expected identifier, found `1` - --> $DIR/syntax-errors.rs:14:24 - | -LL | ${concat(aaaa, 1)} - | ^ help: try removing `1` - error: expected comma - --> $DIR/syntax-errors.rs:19:10 + --> $DIR/syntax-errors.rs:16:10 | LL | ${concat(aaaa aaaa)} | ^^^^^^^^^^^^^^^^^^^ error: `concat` must have at least two elements - --> $DIR/syntax-errors.rs:22:11 + --> $DIR/syntax-errors.rs:19:11 | LL | ${concat($ex)} | ^^^^^^ error: expected comma - --> $DIR/syntax-errors.rs:28:10 + --> $DIR/syntax-errors.rs:25:10 | LL | ${concat($ex, aaaa 123)} | ^^^^^^^^^^^^^^^^^^^^^^^ -error: expected identifier - --> $DIR/syntax-errors.rs:31:10 +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:28:10 | LL | ${concat($ex, aaaa,)} | ^^^^^^^^^^^^^^^^^^^^ -error: expected identifier, found `123` - --> $DIR/syntax-errors.rs:34:29 +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:88:26 | -LL | ${concat($ex, aaaa, 123)} - | ^^^ help: try removing `123` +LL | let ${concat(_a, 'b')}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:91:26 + | +LL | let ${concat(_a, 1)}: () = (); + | ^ + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:94:30 + | +LL | let ${concat($ident, 'b')}: () = (); + | ^^^ + +error: expected identifier or string literal + --> $DIR/syntax-errors.rs:96:30 + | +LL | let ${concat($ident, 1)}: () = (); + | ^ error: `${concat(..)}` currently only accepts identifiers or meta-variables as parameters - --> $DIR/syntax-errors.rs:25:19 + --> $DIR/syntax-errors.rs:22:19 | LL | ${concat($ex, aaaa)} | ^^ error: variable `foo` is not recognized in meta-variable expression - --> $DIR/syntax-errors.rs:41:30 + --> $DIR/syntax-errors.rs:35:30 | LL | const ${concat(FOO, $foo)}: i32 = 2; | ^^^ -error: aborting due to 11 previous errors +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/syntax-errors.rs:42:14 + | +LL | let ${concat("1", $ident)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | starting_number!(_abc); + | ---------------------- in this macro invocation + | + = note: this error originates in the macro `starting_number` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/syntax-errors.rs:55:14 + | +LL | let ${concat("\u{00BD}", $ident)}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | starting_invalid_unicode!(_abc); + | ------------------------------- in this macro invocation + | + = note: this error originates in the macro `starting_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/syntax-errors.rs:74:14 + | +LL | let ${concat($ident, "\u{00BD}")}: () = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | ending_invalid_unicode!(_abc); + | ----------------------------- in this macro invocation + | + = note: this error originates in the macro `ending_invalid_unicode` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected pattern, found `$` + --> $DIR/syntax-errors.rs:88:13 + | +LL | let ${concat(_a, 'b')}: () = (); + | ^ expected pattern +... +LL | unsupported_literals!(_abc); + | --------------------------- in this macro invocation + | + = note: this error originates in the macro `unsupported_literals` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `${concat(..)}` is not generating a valid identifier + --> $DIR/syntax-errors.rs:81:14 + | +LL | let ${concat("", "")}: () = (); + | ^^^^^^^^^^^^^^^^ +... +LL | empty!(); + | -------- in this macro invocation + | + = note: this error originates in the macro `empty` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 18 previous errors diff --git a/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs b/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs new file mode 100644 index 00000000000..b2cfb211e2d --- /dev/null +++ b/tests/ui/macros/macro-metavar-expr-concat/unicode-expansion.rs @@ -0,0 +1,14 @@ +//@ run-pass + +#![feature(macro_metavar_expr_concat)] + +macro_rules! turn_to_page { + ($ident:ident) => { + const ${concat("Ḧ", $ident)}: i32 = 394; + }; +} + +fn main() { + turn_to_page!(P); + assert_eq!(ḦP, 394); +} diff --git a/tests/ui/macros/out-of-scope-calls-false-positives.rs b/tests/ui/macros/out-of-scope-calls-false-positives.rs new file mode 100644 index 00000000000..8d696c177e4 --- /dev/null +++ b/tests/ui/macros/out-of-scope-calls-false-positives.rs @@ -0,0 +1,10 @@ +//@ check-pass +//@ needs-asm-support + +macro_rules! mac { () => { "" } } +macro_rules! mac2 { () => { "auxiliary/issue-40469.rs" } } + +std::arch::global_asm!(mac!()); // OK +include!(mac2!()); // OK + +fn main() {} diff --git a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr b/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr index 8e4ba192d79..2c44ad2e0a4 100644 --- a/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr +++ b/tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr @@ -190,7 +190,7 @@ error: unrecognized meta-variable expression LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and len -error: expected identifier +error: expected identifier or string literal --> $DIR/syntax-errors.rs:118:33 | LL | ( $( $i:ident ),* ) => { ${ {} } }; diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.rs index 83f1ee6a77e..7cbe8e0943a 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.rs @@ -1,5 +1,6 @@ //@ edition: 2024 //@ compile-flags: -Zunstable-options +// gate-test-ref_pat_eat_one_layer_2024_structural pub fn main() { if let Some(Some(&x)) = &Some(&Some(0)) { diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.stderr index 132fe421a18..b3ea60252ac 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.stderr +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_2024.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:5:22 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:6:22 | LL | if let Some(Some(&x)) = &Some(&Some(0)) { | ^^ --------------- this expression has type `&Option<&Option<{integer}>>` @@ -14,7 +14,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:10:23 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:11:23 | LL | let _: &u32 = x; | ---- ^ expected `&u32`, found integer @@ -27,7 +27,7 @@ LL | let _: &u32 = &x; | + error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:13:23 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:14:23 | LL | if let Some(Some(&&x)) = &Some(Some(&0)) { | ^^ --------------- this expression has type `&Option<Option<&{integer}>>` @@ -43,7 +43,7 @@ LL + if let Some(Some(&x)) = &Some(Some(&0)) { | error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:17:17 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:18:17 | LL | if let Some(&Some(x)) = &Some(Some(0)) { | ^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` @@ -54,7 +54,7 @@ LL | if let Some(&Some(x)) = &Some(Some(0)) { found reference `&_` error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:21:22 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:22:22 | LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ^^^^^^ ----------------------- this expression has type `&mut Option<&mut Option<{integer}>>` @@ -64,7 +64,7 @@ LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { = note: expected type `{integer}` found mutable reference `&mut _` note: to declare a mutable binding use: `mut x` - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:21:22 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:22:22 | LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ^^^^^^ @@ -74,7 +74,7 @@ LL | if let Some(Some(x)) = &mut Some(&mut Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:25:22 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:26:22 | LL | if let Some(Some(&x)) = &Some(&Some(0)) { | ^^ --------------- this expression has type `&Option<&Option<{integer}>>` @@ -89,7 +89,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:29:27 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:30:27 | LL | if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { | ^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>` @@ -104,7 +104,7 @@ LL | if let Some(&mut Some(x)) = &Some(&mut Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:33:23 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:34:23 | LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>` @@ -114,7 +114,7 @@ LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { = note: expected type `{integer}` found mutable reference `&mut _` note: to declare a mutable binding use: `mut x` - --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:33:23 + --> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:34:23 | LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ^^^^^^ diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs index d28567f2859..afea249ffef 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs @@ -1,37 +1,15 @@ +//@ run-pass //@ edition: 2021 +//@ revisions: classic structural both #![allow(incomplete_features)] -#![feature(ref_pat_eat_one_layer_2024)] +#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))] +#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))] + pub fn main() { - if let Some(Some(&x)) = &Some(&Some(0)) { - //~^ ERROR: mismatched types - let _: u32 = x; - } - if let Some(Some(&x)) = &Some(Some(&0)) { + if let &Some(Some(x)) = &Some(&mut Some(0)) { let _: &u32 = x; - //~^ ERROR: mismatched types - } - if let Some(Some(&&x)) = &Some(Some(&0)) { - //~^ ERROR: mismatched types - let _: u32 = x; - } - if let Some(&Some(x)) = &Some(Some(0)) { - //~^ ERROR: mismatched types - let _: u32 = x; - } - if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { - //~^ ERROR: mismatched types - let _: u32 = x; - } - if let Some(Some(&x)) = &Some(&Some(0)) { - //~^ ERROR: mismatched types - let _: u32 = x; - } - if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { - //~^ ERROR: mismatched types - let _: u32 = x; } - if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { - //~^ ERROR: mismatched types + if let Some(&x) = Some(&mut 0) { let _: u32 = x; } } diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.rs new file mode 100644 index 00000000000..d28567f2859 --- /dev/null +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.rs @@ -0,0 +1,37 @@ +//@ edition: 2021 +#![allow(incomplete_features)] +#![feature(ref_pat_eat_one_layer_2024)] +pub fn main() { + if let Some(Some(&x)) = &Some(&Some(0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } + if let Some(Some(&x)) = &Some(Some(&0)) { + let _: &u32 = x; + //~^ ERROR: mismatched types + } + if let Some(Some(&&x)) = &Some(Some(&0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } + if let Some(&Some(x)) = &Some(Some(0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } + if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } + if let Some(Some(&x)) = &Some(&Some(0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } + if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } + if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { + //~^ ERROR: mismatched types + let _: u32 = x; + } +} diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.stderr index 28706f89c06..1a921234ea0 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.stderr +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:5:22 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:5:22 | LL | if let Some(Some(&x)) = &Some(&Some(0)) { | ^^ --------------- this expression has type `&Option<&Option<{integer}>>` @@ -14,7 +14,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:10:23 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:10:23 | LL | let _: &u32 = x; | ---- ^ expected `&u32`, found integer @@ -27,7 +27,7 @@ LL | let _: &u32 = &x; | + error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:13:23 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:13:23 | LL | if let Some(Some(&&x)) = &Some(Some(&0)) { | ^^ --------------- this expression has type `&Option<Option<&{integer}>>` @@ -43,7 +43,7 @@ LL + if let Some(Some(&x)) = &Some(Some(&0)) { | error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:17:17 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:17:17 | LL | if let Some(&Some(x)) = &Some(Some(0)) { | ^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` @@ -54,7 +54,7 @@ LL | if let Some(&Some(x)) = &Some(Some(0)) { found reference `&_` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:21:22 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:21:22 | LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ^^^^^^ ----------------------- this expression has type `&mut Option<&mut Option<{integer}>>` @@ -64,7 +64,7 @@ LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { = note: expected type `{integer}` found mutable reference `&mut _` note: to declare a mutable binding use: `mut x` - --> $DIR/ref_pat_eat_one_layer_2021.rs:21:22 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:21:22 | LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ^^^^^^ @@ -74,7 +74,7 @@ LL | if let Some(Some(x)) = &mut Some(&mut Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:25:22 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:25:22 | LL | if let Some(Some(&x)) = &Some(&Some(0)) { | ^^ --------------- this expression has type `&Option<&Option<{integer}>>` @@ -89,7 +89,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:29:27 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:29:27 | LL | if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { | ^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>` @@ -104,7 +104,7 @@ LL | if let Some(&mut Some(x)) = &Some(&mut Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2021.rs:33:23 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:33:23 | LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>` @@ -114,7 +114,7 @@ LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { = note: expected type `{integer}` found mutable reference `&mut _` note: to declare a mutable binding use: `mut x` - --> $DIR/ref_pat_eat_one_layer_2021.rs:33:23 + --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:33:23 | LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ^^^^^^ diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs index 829b7f86e26..c6a699d2ff8 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs @@ -1,8 +1,10 @@ //@ run-pass //@ edition: 2024 //@ compile-flags: -Zunstable-options +//@ revisions: classic structural both #![allow(incomplete_features)] -#![feature(ref_pat_eat_one_layer_2024)] +#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))] +#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))] pub fn main() { if let Some(Some(&x)) = &Some(&Some(0)) { @@ -53,4 +55,35 @@ pub fn main() { if let Some(&Some(x)) = &mut Some(Some(0)) { let _: u32 = x; } + #[cfg(any(classic, both))] + if let Some(&mut x) = &mut Some(&0) { + let _: &u32 = x; + } + #[cfg(any(structural, both))] + if let Some(&mut x) = &Some(&mut 0) { + let _: &u32 = x; + } + + fn generic<R: Ref>() -> (R, bool) { + R::meow() + } + + trait Ref: Sized { + fn meow() -> (Self, bool); + } + + impl Ref for &'static [(); 0] { + fn meow() -> (Self, bool) { + (&[], false) + } + } + + impl Ref for &'static mut [(); 0] { + fn meow() -> (Self, bool) { + (&mut [], true) + } + } + + let (&_, b) = generic(); + assert!(!b); } diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.both.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.both.stderr new file mode 100644 index 00000000000..0215df98ea1 --- /dev/null +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.both.stderr @@ -0,0 +1,169 @@ +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:9:17 + | +LL | if let Some(&mut Some(&_)) = &Some(&Some(0)) { + | ^^^^^^^^^^^^^ --------------- this expression has type `&Option<&Option<{integer}>>` + | | + | types differ in mutability + | + = note: expected reference `&Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:12:23 + | +LL | if let Some(&Some(&mut _)) = &Some(&mut Some(0)) { + | ^^^^^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:16:27 + | +LL | let _: &mut u32 = x; + | -------- ^ types differ in mutability + | | + | expected due to this + | + = note: expected mutable reference `&mut u32` + found reference `&{integer}` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:19:23 + | +LL | if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { + | ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:22:29 + | +LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { + | ^^^^^^ ------------------------- this expression has type `&Option<Option<&mut Option<{integer}>>>` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:25:17 + | +LL | if let Some(&mut Some(x)) = &Some(Some(0)) { + | ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` + | | + | expected `Option<{integer}>`, found `&mut _` + | + = note: expected enum `Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:28:17 + | +LL | if let Some(&mut Some(x)) = &Some(Some(0)) { + | ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` + | | + | expected `Option<{integer}>`, found `&mut _` + | + = note: expected enum `Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:32:9 + | +LL | let &mut _ = &&0; + | ^^^^^^ --- this expression has type `&&{integer}` + | | + | types differ in mutability + | + = note: expected reference `&&{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:35:9 + | +LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; + | ^^^^^^ ----------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` + | | + | types differ in mutability + | + = note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:46:9 + | +LL | let &mut _ = &&mut 0; + | ^^^^^^ ------- this expression has type `&&mut {integer}` + | | + | types differ in mutability + | + = note: expected reference `&&mut {integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:49:9 + | +LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&mut 0; + | ^^^^^^ --------------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}` + | | + | types differ in mutability + | + = note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:52:14 + | +LL | let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0; + | ^^^^^^^^^^^^^^^^ -------------------------- this expression has type `&mut &&&&mut &&&mut &mut {integer}` + | | + | types differ in mutability + | + = note: expected reference `&&&&mut &&&mut &mut {integer}` + found mutable reference `&mut _` + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:61:13 + | +LL | let Foo(mut a) = &Foo(0); + | ^^^^ + | + = note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:65:13 + | +LL | let Foo(mut a) = &mut Foo(0); + | ^^^^ + | + = note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0277]: the trait bound `&_: main::Ref` is not satisfied + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14 + | +LL | let &_ = generic(); + | ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_` + | + = help: the trait `main::Ref` is implemented for `&'static mut [(); 0]` +note: required by a bound in `generic` + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19 + | +LL | fn generic<R: Ref>() -> R { + | ^^^ required by this bound in `generic` + +error: aborting due to 15 previous errors + +Some errors have detailed explanations: E0277, E0308, E0658. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.classic.stderr index 26317e43d02..9428b32c4af 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.stderr +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.classic.stderr @@ -1,27 +1,29 @@ -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:7:17 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:9:17 | LL | if let Some(&mut Some(&_)) = &Some(&Some(0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(&_)) = &Some(&Some(0)) { | ~ -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:10:23 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:12:23 | LL | if let Some(&Some(&mut _)) = &Some(&mut Some(0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(&_)) = &Some(&mut Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:14:27 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:16:27 | LL | let _: &mut u32 = x; | -------- ^ types differ in mutability @@ -31,52 +33,56 @@ LL | let _: &mut u32 = x; = note: expected mutable reference `&mut u32` found reference `&{integer}` -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:17:23 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:19:23 | LL | if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(&_)) = &mut Some(&Some(0)) { | ~ -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:20:29 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:22:29 | LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(Some((&_)))) = &Some(Some(&mut Some(0))) { | ~ -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:23:17 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:25:17 | LL | if let Some(&mut Some(x)) = &Some(Some(0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(x)) = &Some(Some(0)) { | ~ -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:26:17 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:28:17 | LL | if let Some(&mut Some(x)) = &Some(Some(0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(x)) = &Some(Some(0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:30:9 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:32:9 | LL | let &mut _ = &&0; | ^^^^^^ --- this expression has type `&&{integer}` @@ -87,7 +93,7 @@ LL | let &mut _ = &&0; found mutable reference `&mut _` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:33:9 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:35:9 | LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; | ^^^^^^ ----------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` @@ -97,30 +103,32 @@ LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; = note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` found mutable reference `&mut _` -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:36:17 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:38:17 | LL | if let Some(&mut Some(&_)) = &Some(&mut Some(0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(&Some(&_)) = &Some(&mut Some(0)) { | ~ -error: cannot match inherited `&` with `&mut` pattern - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:40:22 +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:42:22 | LL | if let Some(Some(&mut x)) = &Some(Some(&mut 0)) { | ^^^^^ | + = note: cannot match inherited `&` with `&mut` pattern help: replace this `&mut` pattern with `&` | LL | if let Some(Some(&x)) = &Some(Some(&mut 0)) { | ~ error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:44:9 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:46:9 | LL | let &mut _ = &&mut 0; | ^^^^^^ ------- this expression has type `&&mut {integer}` @@ -131,7 +139,7 @@ LL | let &mut _ = &&mut 0; found mutable reference `&mut _` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:47:9 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:49:9 | LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&mut 0; | ^^^^^^ --------------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}` @@ -142,7 +150,7 @@ LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&mut 0; found mutable reference `&mut _` error[E0308]: mismatched types - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:50:14 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:52:14 | LL | let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0; | ^^^^^^^^^^^^^^^^ -------------------------- this expression has type `&mut &&&&mut &&&mut &mut {integer}` @@ -153,7 +161,7 @@ LL | let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0; found mutable reference `&mut _` error[E0658]: binding cannot be both mutable and by-reference - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:55:13 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:61:13 | LL | let Foo(mut a) = &Foo(0); | ^^^^ @@ -163,7 +171,7 @@ LL | let Foo(mut a) = &Foo(0); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: binding cannot be both mutable and by-reference - --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:59:13 + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:65:13 | LL | let Foo(mut a) = &mut Foo(0); | ^^^^ @@ -172,7 +180,20 @@ LL | let Foo(mut a) = &mut Foo(0); = help: add `#![feature(mut_ref)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 16 previous errors +error[E0277]: the trait bound `&_: main::Ref` is not satisfied + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14 + | +LL | let &_ = generic(); + | ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_` + | + = help: the trait `main::Ref` is implemented for `&'static mut [(); 0]` +note: required by a bound in `generic` + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19 + | +LL | fn generic<R: Ref>() -> R { + | ^^^ required by this bound in `generic` + +error: aborting due to 17 previous errors -Some errors have detailed explanations: E0308, E0658. -For more information about an error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0277, E0308, E0658. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs index 40e8293e241..d23e9c8083d 100644 --- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs @@ -1,30 +1,32 @@ //@ edition: 2024 //@ compile-flags: -Zunstable-options +//@ revisions: classic structural both #![allow(incomplete_features)] -#![feature(ref_pat_eat_one_layer_2024)] +#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))] +#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))] pub fn main() { if let Some(&mut Some(&_)) = &Some(&Some(0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //~^ ERROR: mismatched types } if let Some(&Some(&mut _)) = &Some(&mut Some(0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //~^ ERROR: mismatched types } if let Some(&Some(x)) = &mut Some(&Some(0)) { let _: &mut u32 = x; //~^ ERROR: mismatched types } if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //~^ ERROR: mismatched types } if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //~^ ERROR: mismatched types } if let Some(&mut Some(x)) = &Some(Some(0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //~^ ERROR: mismatched types } if let Some(&mut Some(x)) = &Some(Some(0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //~^ ERROR: mismatched types } let &mut _ = &&0; @@ -34,11 +36,11 @@ pub fn main() { //~^ ERROR: mismatched types if let Some(&mut Some(&_)) = &Some(&mut Some(0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //[classic]~^ ERROR: mismatched types } if let Some(Some(&mut x)) = &Some(Some(&mut 0)) { - //~^ ERROR: cannot match inherited `&` with `&mut` pattern + //[classic]~^ ERROR: mismatched types } let &mut _ = &&mut 0; @@ -50,6 +52,10 @@ pub fn main() { let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0; //~^ ERROR: mismatched types + if let Some(&mut _) = &mut Some(&0) { + //[structural]~^ ERROR + } + struct Foo(u8); let Foo(mut a) = &Foo(0); @@ -59,4 +65,20 @@ pub fn main() { let Foo(mut a) = &mut Foo(0); //~^ ERROR: binding cannot be both mutable and by-reference a = &mut 42; + + fn generic<R: Ref>() -> R { + R::meow() + } + + trait Ref: Sized { + fn meow() -> Self; + } + + impl Ref for &'static mut [(); 0] { + fn meow() -> Self { + &mut [] + } + } + + let &_ = generic(); //~ERROR: the trait bound `&_: main::Ref` is not satisfied [E0277] } diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.structural.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.structural.stderr new file mode 100644 index 00000000000..56dad605030 --- /dev/null +++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.structural.stderr @@ -0,0 +1,180 @@ +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:9:17 + | +LL | if let Some(&mut Some(&_)) = &Some(&Some(0)) { + | ^^^^^^^^^^^^^ --------------- this expression has type `&Option<&Option<{integer}>>` + | | + | types differ in mutability + | + = note: expected reference `&Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:12:23 + | +LL | if let Some(&Some(&mut _)) = &Some(&mut Some(0)) { + | ^^^^^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:16:27 + | +LL | let _: &mut u32 = x; + | -------- ^ types differ in mutability + | | + | expected due to this + | + = note: expected mutable reference `&mut u32` + found reference `&{integer}` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:19:23 + | +LL | if let Some(&Some(&mut _)) = &mut Some(&Some(0)) { + | ^^^^^^ ------------------- this expression has type `&mut Option<&Option<{integer}>>` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:22:29 + | +LL | if let Some(&Some(Some((&mut _)))) = &Some(Some(&mut Some(0))) { + | ^^^^^^ ------------------------- this expression has type `&Option<Option<&mut Option<{integer}>>>` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:25:17 + | +LL | if let Some(&mut Some(x)) = &Some(Some(0)) { + | ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` + | | + | expected `Option<{integer}>`, found `&mut _` + | + = note: expected enum `Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:28:17 + | +LL | if let Some(&mut Some(x)) = &Some(Some(0)) { + | ^^^^^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` + | | + | expected `Option<{integer}>`, found `&mut _` + | + = note: expected enum `Option<{integer}>` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:32:9 + | +LL | let &mut _ = &&0; + | ^^^^^^ --- this expression has type `&&{integer}` + | | + | types differ in mutability + | + = note: expected reference `&&{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:35:9 + | +LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&0; + | ^^^^^^ ----------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` + | | + | types differ in mutability + | + = note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&{integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:46:9 + | +LL | let &mut _ = &&mut 0; + | ^^^^^^ ------- this expression has type `&&mut {integer}` + | | + | types differ in mutability + | + = note: expected reference `&&mut {integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:49:9 + | +LL | let &mut _ = &&&&&&&&&&&&&&&&&&&&&&&&&&&&mut 0; + | ^^^^^^ --------------------------------- this expression has type `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}` + | | + | types differ in mutability + | + = note: expected reference `&&&&&&&&&&&&&&&&&&&&&&&&&&&&mut {integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:52:14 + | +LL | let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0; + | ^^^^^^^^^^^^^^^^ -------------------------- this expression has type `&mut &&&&mut &&&mut &mut {integer}` + | | + | types differ in mutability + | + = note: expected reference `&&&&mut &&&mut &mut {integer}` + found mutable reference `&mut _` + +error[E0308]: mismatched types + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:55:17 + | +LL | if let Some(&mut _) = &mut Some(&0) { + | ^^^^^^ ------------- this expression has type `&mut Option<&{integer}>` + | | + | types differ in mutability + | + = note: expected reference `&{integer}` + found mutable reference `&mut _` + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:61:13 + | +LL | let Foo(mut a) = &Foo(0); + | ^^^^ + | + = note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:65:13 + | +LL | let Foo(mut a) = &mut Foo(0); + | ^^^^ + | + = note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0277]: the trait bound `&_: main::Ref` is not satisfied + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14 + | +LL | let &_ = generic(); + | ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_` + | + = help: the trait `main::Ref` is implemented for `&'static mut [(); 0]` +note: required by a bound in `generic` + --> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19 + | +LL | fn generic<R: Ref>() -> R { + | ^^^ required by this bound in `generic` + +error: aborting due to 16 previous errors + +Some errors have detailed explanations: E0277, E0308, E0658. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/method-output-diff-issue-127263.rs b/tests/ui/method-output-diff-issue-127263.rs new file mode 100644 index 00000000000..85a903e2453 --- /dev/null +++ b/tests/ui/method-output-diff-issue-127263.rs @@ -0,0 +1,8 @@ +fn bar() {} +fn foo(x: i32) -> u32 { + 0 +} +fn main() { + let b: fn() -> u32 = bar; //~ ERROR mismatched types [E0308] + let f: fn(i32) = foo; //~ ERROR mismatched types [E0308] +} diff --git a/tests/ui/method-output-diff-issue-127263.stderr b/tests/ui/method-output-diff-issue-127263.stderr new file mode 100644 index 00000000000..35b86114f16 --- /dev/null +++ b/tests/ui/method-output-diff-issue-127263.stderr @@ -0,0 +1,25 @@ +error[E0308]: mismatched types + --> $DIR/method-output-diff-issue-127263.rs:6:26 + | +LL | let b: fn() -> u32 = bar; + | ----------- ^^^ expected fn pointer, found fn item + | | + | expected due to this + | + = note: expected fn pointer `fn() -> u32` + found fn item `fn() -> () {bar}` + +error[E0308]: mismatched types + --> $DIR/method-output-diff-issue-127263.rs:7:22 + | +LL | let f: fn(i32) = foo; + | ------- ^^^ expected fn pointer, found fn item + | | + | expected due to this + | + = note: expected fn pointer `fn(_) -> ()` + found fn item `fn(_) -> u32 {foo}` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/methods/method-call-err-msg.stderr b/tests/ui/methods/method-call-err-msg.stderr index 5a76449e9f9..0855a17b333 100644 --- a/tests/ui/methods/method-call-err-msg.stderr +++ b/tests/ui/methods/method-call-err-msg.stderr @@ -2,16 +2,18 @@ error[E0061]: this method takes 0 arguments but 1 argument was supplied --> $DIR/method-call-err-msg.rs:13:7 | LL | x.zero(0) - | ^^^^ - - | | - | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^ - unexpected argument of type `{integer}` | note: method defined here --> $DIR/method-call-err-msg.rs:5:8 | LL | fn zero(self) -> Foo { self } | ^^^^ +help: remove the extra argument + | +LL - x.zero(0) +LL + x.zero() + | error[E0061]: this method takes 1 argument but 0 arguments were supplied --> $DIR/method-call-err-msg.rs:14:7 diff --git a/tests/ui/mir/alignment/misaligned-constant-gvn.rs b/tests/ui/mir/alignment/misaligned-constant-gvn.rs new file mode 100644 index 00000000000..363d5c0ed34 --- /dev/null +++ b/tests/ui/mir/alignment/misaligned-constant-gvn.rs @@ -0,0 +1,8 @@ +//@ build-pass +//@ compile-flags: -Zmir-opt-level=0 -Zmir-enable-passes=+GVN + +fn main() { + let variant: Option<u32> = None; + let transmuted: u64 = unsafe { std::mem::transmute(variant) }; + println!("{transmuted}"); +} diff --git a/tests/ui/mismatched_types/E0053.stderr b/tests/ui/mismatched_types/E0053.stderr index d0bd5b46cf5..2559d448749 100644 --- a/tests/ui/mismatched_types/E0053.stderr +++ b/tests/ui/mismatched_types/E0053.stderr @@ -2,10 +2,7 @@ error[E0053]: method `foo` has an incompatible type for trait --> $DIR/E0053.rs:9:15 | LL | fn foo(x: i16) { } - | ^^^ - | | - | expected `u16`, found `i16` - | help: change the parameter type to match the trait: `u16` + | ^^^ expected `u16`, found `i16` | note: type in trait --> $DIR/E0053.rs:2:15 @@ -14,15 +11,16 @@ LL | fn foo(x: u16); | ^^^ = note: expected signature `fn(u16)` found signature `fn(i16)` +help: change the parameter type to match the trait + | +LL | fn foo(x: u16) { } + | ~~~ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/E0053.rs:11:12 | LL | fn bar(&mut self) { } - | ^^^^^^^^^ - | | - | types differ in mutability - | help: change the self-receiver type to match the trait: `&self` + | ^^^^^^^^^ types differ in mutability | note: type in trait --> $DIR/E0053.rs:3:12 @@ -31,6 +29,10 @@ LL | fn bar(&self); | ^^^^^ = note: expected signature `fn(&Bar)` found signature `fn(&mut Bar)` +help: change the self-receiver type to match the trait + | +LL | fn bar(&self) { } + | ~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/mismatched_types/cast-rfc0401.rs b/tests/ui/mismatched_types/cast-rfc0401.rs index 57222f45947..b2ff5b4a0c0 100644 --- a/tests/ui/mismatched_types/cast-rfc0401.rs +++ b/tests/ui/mismatched_types/cast-rfc0401.rs @@ -66,7 +66,7 @@ fn main() let cf: *const dyn Foo = &0; let _ = cf as *const [u16]; //~ ERROR is invalid - let _ = cf as *const dyn Bar; //~ ERROR is invalid + let _ = cf as *const dyn Bar; //~ ERROR casting `*const dyn Foo` as `*const dyn Bar` is invalid vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); //~ ERROR is invalid } diff --git a/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr b/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr index 454373c322e..6b3e0cb505f 100644 --- a/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr +++ b/tests/ui/mismatched_types/float-literal-inference-restrictions.stderr @@ -2,11 +2,14 @@ error[E0308]: mismatched types --> $DIR/float-literal-inference-restrictions.rs:2:18 | LL | let x: f32 = 1; - | --- ^ - | | | - | | expected `f32`, found integer - | | help: use a float literal: `1.0` + | --- ^ expected `f32`, found integer + | | | expected due to this + | +help: use a float literal + | +LL | let x: f32 = 1.0; + | ++ error[E0308]: mismatched types --> $DIR/float-literal-inference-restrictions.rs:3:18 diff --git a/tests/ui/mismatched_types/issue-112036.stderr b/tests/ui/mismatched_types/issue-112036.stderr index b93ce4a8674..bd446b3d78c 100644 --- a/tests/ui/mismatched_types/issue-112036.stderr +++ b/tests/ui/mismatched_types/issue-112036.stderr @@ -2,13 +2,14 @@ error[E0053]: method `drop` has an incompatible type for trait --> $DIR/issue-112036.rs:4:13 | LL | fn drop(self) {} - | ^^^^ - | | - | expected `&mut Foo`, found `Foo` - | help: change the self-receiver type to match the trait: `&mut self` + | ^^^^ expected `&mut Foo`, found `Foo` | = note: expected signature `fn(&mut Foo)` found signature `fn(Foo)` +help: change the self-receiver type to match the trait + | +LL | fn drop(&mut self) {} + | ~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/mismatched_types/issue-13033.stderr b/tests/ui/mismatched_types/issue-13033.stderr index 4886fa30e89..2a266d40e77 100644 --- a/tests/ui/mismatched_types/issue-13033.stderr +++ b/tests/ui/mismatched_types/issue-13033.stderr @@ -2,10 +2,7 @@ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/issue-13033.rs:8:30 | LL | fn bar(&mut self, other: &dyn Foo) {} - | ^^^^^^^^ - | | - | types differ in mutability - | help: change the parameter type to match the trait: `&mut dyn Foo` + | ^^^^^^^^ types differ in mutability | note: type in trait --> $DIR/issue-13033.rs:2:30 @@ -14,6 +11,10 @@ LL | fn bar(&mut self, other: &mut dyn Foo); | ^^^^^^^^^^^^ = note: expected signature `fn(&mut Baz, &mut dyn Foo)` found signature `fn(&mut Baz, &dyn Foo)` +help: change the parameter type to match the trait + | +LL | fn bar(&mut self, other: &mut dyn Foo) {} + | ~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/mismatched_types/trait-impl-fn-incompatibility.stderr b/tests/ui/mismatched_types/trait-impl-fn-incompatibility.stderr index 6e7bf5eb46d..2e544a62223 100644 --- a/tests/ui/mismatched_types/trait-impl-fn-incompatibility.stderr +++ b/tests/ui/mismatched_types/trait-impl-fn-incompatibility.stderr @@ -2,10 +2,7 @@ error[E0053]: method `foo` has an incompatible type for trait --> $DIR/trait-impl-fn-incompatibility.rs:9:15 | LL | fn foo(x: i16) { } - | ^^^ - | | - | expected `u16`, found `i16` - | help: change the parameter type to match the trait: `u16` + | ^^^ expected `u16`, found `i16` | note: type in trait --> $DIR/trait-impl-fn-incompatibility.rs:2:15 @@ -14,15 +11,16 @@ LL | fn foo(x: u16); | ^^^ = note: expected signature `fn(u16)` found signature `fn(i16)` +help: change the parameter type to match the trait + | +LL | fn foo(x: u16) { } + | ~~~ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/trait-impl-fn-incompatibility.rs:10:28 | LL | fn bar(&mut self, bar: &Bar) { } - | ^^^^ - | | - | types differ in mutability - | help: change the parameter type to match the trait: `&mut Bar` + | ^^^^ types differ in mutability | note: type in trait --> $DIR/trait-impl-fn-incompatibility.rs:3:28 @@ -31,6 +29,10 @@ LL | fn bar(&mut self, bar: &mut Bar); | ^^^^^^^^ = note: expected signature `fn(&mut Bar, &mut Bar)` found signature `fn(&mut Bar, &Bar)` +help: change the parameter type to match the trait + | +LL | fn bar(&mut self, bar: &mut Bar) { } + | ~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/msvc-opt-minsize.rs b/tests/ui/msvc-opt-minsize.rs new file mode 100644 index 00000000000..c1be168a05d --- /dev/null +++ b/tests/ui/msvc-opt-minsize.rs @@ -0,0 +1,31 @@ +// A previously outdated version of LLVM caused compilation failures on Windows +// specifically with optimization level `z`. After the update to a more recent LLVM +// version, this test checks that compilation and execution both succeed. +// See https://github.com/rust-lang/rust/issues/45034 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ only-windows +// Reason: the observed bug only occurs on Windows +//@ run-pass +//@ compile-flags: -C opt-level=z + +#![feature(test)] +extern crate test; + +fn foo(x: i32, y: i32) -> i64 { + (x + y) as i64 +} + +#[inline(never)] +fn bar() { + let _f = Box::new(0); + // This call used to trigger an LLVM bug in opt-level z where the base + // pointer gets corrupted, see issue #45034 + let y: fn(i32, i32) -> i64 = test::black_box(foo); + test::black_box(y(1, 2)); +} + +fn main() { + bar(); +} diff --git a/tests/ui/mut/mut-pattern-internal-mutability.stderr b/tests/ui/mut/mut-pattern-internal-mutability.stderr index ab80af17a08..f3a8aa0126c 100644 --- a/tests/ui/mut/mut-pattern-internal-mutability.stderr +++ b/tests/ui/mut/mut-pattern-internal-mutability.stderr @@ -9,11 +9,11 @@ LL | x += 1; help: consider making this binding mutable | LL | let &mut mut x = foo; - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | let &mut ref mut x = foo; - | ~~~~~~~~~ + | +++++++ error[E0506]: cannot assign to `*foo` because it is borrowed --> $DIR/mut-pattern-internal-mutability.rs:13:5 diff --git a/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.stderr b/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr index fbd92f8f662..a75039b8237 100644 --- a/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.stderr +++ b/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr @@ -1,5 +1,5 @@ warning: never type fallback affects this call to an `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:8:18 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:13:18 | LL | unsafe { mem::zeroed() } | ^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | unsafe { mem::zeroed() } = note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default warning: never type fallback affects this call to an `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:23:13 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:30:13 | LL | core::mem::transmute(Zst) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | core::mem::transmute(Zst) = help: specify the type explicitly warning: never type fallback affects this union access - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:39:18 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:47:18 | LL | unsafe { Union { a: () }.b } | ^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | unsafe { Union { a: () }.b } = help: specify the type explicitly warning: never type fallback affects this raw pointer dereference - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:49:18 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:58:18 | LL | unsafe { *ptr::from_ref(&()).cast() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | unsafe { *ptr::from_ref(&()).cast() } = help: specify the type explicitly warning: never type fallback affects this call to an `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:67:18 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:79:18 | LL | unsafe { internally_create(x) } | ^^^^^^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | unsafe { internally_create(x) } = help: specify the type explicitly warning: never type fallback affects this call to an `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:83:18 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:97:18 | LL | unsafe { zeroed() } | ^^^^^^^^ @@ -60,7 +60,7 @@ LL | unsafe { zeroed() } = help: specify the type explicitly warning: never type fallback affects this `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:79:22 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:92:22 | LL | let zeroed = mem::zeroed; | ^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let zeroed = mem::zeroed; = help: specify the type explicitly warning: never type fallback affects this `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:98:17 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:115:17 | LL | let f = internally_create; | ^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | let f = internally_create; = help: specify the type explicitly warning: never type fallback affects this call to an `unsafe` method - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:122:13 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:140:13 | LL | S(marker::PhantomData).create_out_of_thin_air() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | S(marker::PhantomData).create_out_of_thin_air() = help: specify the type explicitly warning: never type fallback affects this call to an `unsafe` function - --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:139:19 + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:158:19 | LL | match send_message::<_ /* ?0 */>() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2024.stderr b/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2024.stderr new file mode 100644 index 00000000000..4138e9f8c86 --- /dev/null +++ b/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2024.stderr @@ -0,0 +1,116 @@ +error: never type fallback affects this call to an `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:13:18 + | +LL | unsafe { mem::zeroed() } + | ^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` on by default + +error: never type fallback affects this call to an `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:30:13 + | +LL | core::mem::transmute(Zst) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this union access + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:47:18 + | +LL | unsafe { Union { a: () }.b } + | ^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this raw pointer dereference + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:58:18 + | +LL | unsafe { *ptr::from_ref(&()).cast() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this call to an `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:79:18 + | +LL | unsafe { internally_create(x) } + | ^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this call to an `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:97:18 + | +LL | unsafe { zeroed() } + | ^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:92:22 + | +LL | let zeroed = mem::zeroed; + | ^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:115:17 + | +LL | let f = internally_create; + | ^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this call to an `unsafe` method + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:140:13 + | +LL | S(marker::PhantomData).create_out_of_thin_air() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + +error: never type fallback affects this call to an `unsafe` function + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:158:19 + | +LL | match send_message::<_ /* ?0 */>() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | msg_send!(); + | ----------- in this macro invocation + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> + = help: specify the type explicitly + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +warning: the type `!` does not permit zero-initialization + --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:13:18 + | +LL | unsafe { mem::zeroed() } + | ^^^^^^^^^^^^^ this code causes undefined behavior when executed + | + = note: the `!` type has no valid value + = note: `#[warn(invalid_value)]` on by default + +error: aborting due to 10 previous errors; 1 warning emitted + diff --git a/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs b/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs index d65bfee843e..c96f4dda3f8 100644 --- a/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs +++ b/tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs @@ -1,4 +1,9 @@ -//@ check-pass +//@ revisions: e2015 e2024 +//@[e2015] check-pass +//@[e2024] check-fail +//@[e2024] edition:2024 +//@[e2024] compile-flags: -Zunstable-options + use std::{marker, mem, ptr}; fn main() {} @@ -6,8 +11,10 @@ fn main() {} fn _zero() { if false { unsafe { mem::zeroed() } - //~^ warn: never type fallback affects this call to an `unsafe` function + //[e2015]~^ warn: never type fallback affects this call to an `unsafe` function + //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function //~| warn: this will change its meaning in a future release! + //[e2024]~| warning: the type `!` does not permit zero-initialization } else { return; }; @@ -21,7 +28,8 @@ fn _trans() { unsafe { struct Zst; core::mem::transmute(Zst) - //~^ warn: never type fallback affects this call to an `unsafe` function + //[e2015]~^ warn: never type fallback affects this call to an `unsafe` function + //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function //~| warn: this will change its meaning in a future release! } } else { @@ -37,7 +45,8 @@ fn _union() { } unsafe { Union { a: () }.b } - //~^ warn: never type fallback affects this union access + //[e2015]~^ warn: never type fallback affects this union access + //[e2024]~^^ error: never type fallback affects this union access //~| warn: this will change its meaning in a future release! } else { return; @@ -47,7 +56,8 @@ fn _union() { fn _deref() { if false { unsafe { *ptr::from_ref(&()).cast() } - //~^ warn: never type fallback affects this raw pointer dereference + //[e2015]~^ warn: never type fallback affects this raw pointer dereference + //[e2024]~^^ error: never type fallback affects this raw pointer dereference //~| warn: this will change its meaning in a future release! } else { return; @@ -57,7 +67,9 @@ fn _deref() { fn _only_generics() { if false { unsafe fn internally_create<T>(_: Option<T>) { - let _ = mem::zeroed::<T>(); + unsafe { + let _ = mem::zeroed::<T>(); + } } // We need the option (and unwrap later) to call a function in a way, @@ -65,7 +77,8 @@ fn _only_generics() { let x = None; unsafe { internally_create(x) } - //~^ warn: never type fallback affects this call to an `unsafe` function + //[e2015]~^ warn: never type fallback affects this call to an `unsafe` function + //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function //~| warn: this will change its meaning in a future release! x.unwrap() @@ -77,11 +90,13 @@ fn _only_generics() { fn _stored_function() { if false { let zeroed = mem::zeroed; - //~^ warn: never type fallback affects this `unsafe` function + //[e2015]~^ warn: never type fallback affects this `unsafe` function + //[e2024]~^^ error: never type fallback affects this `unsafe` function //~| warn: this will change its meaning in a future release! unsafe { zeroed() } - //~^ warn: never type fallback affects this call to an `unsafe` function + //[e2015]~^ warn: never type fallback affects this call to an `unsafe` function + //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function //~| warn: this will change its meaning in a future release! } else { return; @@ -91,12 +106,15 @@ fn _stored_function() { fn _only_generics_stored_function() { if false { unsafe fn internally_create<T>(_: Option<T>) { - let _ = mem::zeroed::<T>(); + unsafe { + let _ = mem::zeroed::<T>(); + } } let x = None; let f = internally_create; - //~^ warn: never type fallback affects this `unsafe` function + //[e2015]~^ warn: never type fallback affects this `unsafe` function + //[e2024]~^^ error: never type fallback affects this `unsafe` function //~| warn: this will change its meaning in a future release! unsafe { f(x) } @@ -120,7 +138,8 @@ fn _method() { if false { unsafe { S(marker::PhantomData).create_out_of_thin_air() - //~^ warn: never type fallback affects this call to an `unsafe` method + //[e2015]~^ warn: never type fallback affects this call to an `unsafe` method + //[e2024]~^^ error: never type fallback affects this call to an `unsafe` method //~| warn: this will change its meaning in a future release! } } else { @@ -137,7 +156,8 @@ fn _objc() { macro_rules! msg_send { () => { match send_message::<_ /* ?0 */>() { - //~^ warn: never type fallback affects this call to an `unsafe` function + //[e2015]~^ warn: never type fallback affects this call to an `unsafe` function + //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function //~| warn: this will change its meaning in a future release! Ok(x) => x, Err(_) => loop {}, diff --git a/tests/ui/nll/closure-captures.stderr b/tests/ui/nll/closure-captures.stderr index 5233f0b2462..828974c517e 100644 --- a/tests/ui/nll/closure-captures.stderr +++ b/tests/ui/nll/closure-captures.stderr @@ -1,38 +1,46 @@ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/closure-captures.rs:7:5 | -LL | fn one_closure(x: i32) { - | - help: consider changing this to be mutable: `mut x` -LL | || LL | x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn one_closure(mut x: i32) { + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/closure-captures.rs:9:5 | -LL | fn one_closure(x: i32) { - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn one_closure(mut x: i32) { + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/closure-captures.rs:15:9 | -LL | fn two_closures(x: i32) { - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn two_closures(mut x: i32) { + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/closure-captures.rs:19:9 | -LL | fn two_closures(x: i32) { - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn two_closures(mut x: i32) { + | +++ error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure --> $DIR/closure-captures.rs:27:9 @@ -67,11 +75,13 @@ LL | x = 1;}); error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/closure-captures.rs:39:10 | -LL | fn two_closures_ref(x: i32) { - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1;} | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn two_closures_ref(mut x: i32) { + | +++ error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure --> $DIR/closure-captures.rs:38:9 @@ -91,11 +101,13 @@ LL | x = 1;} error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/closure-captures.rs:43:5 | -LL | fn two_closures_ref(x: i32) { - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1;}); | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | fn two_closures_ref(mut x: i32) { + | +++ error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure --> $DIR/closure-captures.rs:42:9 diff --git a/tests/ui/nll/coroutine-upvar-mutability.stderr b/tests/ui/nll/coroutine-upvar-mutability.stderr index 8b9be877c8f..02c01130176 100644 --- a/tests/ui/nll/coroutine-upvar-mutability.stderr +++ b/tests/ui/nll/coroutine-upvar-mutability.stderr @@ -1,11 +1,13 @@ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/coroutine-upvar-mutability.rs:10:9 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/nll/issue-46023.stderr b/tests/ui/nll/issue-46023.stderr index 062e07407ce..d071c29271c 100644 --- a/tests/ui/nll/issue-46023.stderr +++ b/tests/ui/nll/issue-46023.stderr @@ -1,11 +1,13 @@ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/issue-46023.rs:5:9 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr index 812f7a0692f..4fea52fec6e 100644 --- a/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr +++ b/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr @@ -5,7 +5,7 @@ LL | fn panic(info: PanicInfo) -> () {} | ^^^^^^^^^ expected `&PanicInfo<'_>`, found `PanicInfo<'_>` | = note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !` - found signature `for<'a> fn(PanicInfo<'a>)` + found signature `for<'a> fn(PanicInfo<'a>) -> ()` error: aborting due to 1 previous error diff --git a/tests/ui/parser/bad-let-else-statement.rs b/tests/ui/parser/bad-let-else-statement.rs index ff6619cbc98..3ede26dbcd0 100644 --- a/tests/ui/parser/bad-let-else-statement.rs +++ b/tests/ui/parser/bad-let-else-statement.rs @@ -147,14 +147,14 @@ fn o() -> Result<(), ()> { }; } -fn p() { - let 0 = become { - () - } else { - //~^ ERROR right curly brace `}` before `else` in a `let...else` statement not allowed - return; - }; -} +// fn p() { // FIXME(explicit_tail_calls): this currently trips an assertion... +// let 0 = become { +// () +// } else { +// // ~^ ERROR right curly brace `}` before `else` in a `let...else` statement not allowed +// return; +// }; +// } fn q() { let foo = |x: i32| { diff --git a/tests/ui/parser/bad-let-else-statement.stderr b/tests/ui/parser/bad-let-else-statement.stderr index 0bf6a346dfb..79d722bb7ac 100644 --- a/tests/ui/parser/bad-let-else-statement.stderr +++ b/tests/ui/parser/bad-let-else-statement.stderr @@ -204,19 +204,6 @@ LL ~ }) else { | error: right curly brace `}` before `else` in a `let...else` statement not allowed - --> $DIR/bad-let-else-statement.rs:153:5 - | -LL | } else { - | ^ - | -help: wrap the expression in parentheses - | -LL ~ let 0 = become ({ -LL | () -LL ~ }) else { - | - -error: right curly brace `}` before `else` in a `let...else` statement not allowed --> $DIR/bad-let-else-statement.rs:163:5 | LL | } else { @@ -325,5 +312,5 @@ LL | | } else { = note: this pattern will always match, so the `else` clause is useless = help: consider removing the `else` clause -error: aborting due to 20 previous errors; 5 warnings emitted +error: aborting due to 19 previous errors; 5 warnings emitted diff --git a/tests/ui/parser/issues/issue-105366.fixed b/tests/ui/parser/issues/issue-105366.fixed index 7157b647524..95419dc07f2 100644 --- a/tests/ui/parser/issues/issue-105366.fixed +++ b/tests/ui/parser/issues/issue-105366.fixed @@ -1,5 +1,6 @@ //@ run-rustfix +#[allow(dead_code)] struct Foo; impl From<i32> for Foo { diff --git a/tests/ui/parser/issues/issue-105366.rs b/tests/ui/parser/issues/issue-105366.rs index dc3cb8b343d..3278b737991 100644 --- a/tests/ui/parser/issues/issue-105366.rs +++ b/tests/ui/parser/issues/issue-105366.rs @@ -1,5 +1,6 @@ //@ run-rustfix +#[allow(dead_code)] struct Foo; fn From<i32> for Foo { diff --git a/tests/ui/parser/issues/issue-105366.stderr b/tests/ui/parser/issues/issue-105366.stderr index 18c04dfaf20..195305a2ec8 100644 --- a/tests/ui/parser/issues/issue-105366.stderr +++ b/tests/ui/parser/issues/issue-105366.stderr @@ -1,5 +1,5 @@ error: you might have meant to write `impl` instead of `fn` - --> $DIR/issue-105366.rs:5:1 + --> $DIR/issue-105366.rs:6:1 | LL | fn From<i32> for Foo { | ^^ diff --git a/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr b/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr index 41d1b79d97d..ed71a39ff7e 100644 --- a/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr +++ b/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr @@ -78,11 +78,11 @@ LL | | Err(a @ b @ a) help: consider making this binding mutable | LL | Ok(a @ b @ mut a) - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | Ok(a @ b @ ref mut a) - | ~~~~~~~~~ + | +++++++ error: aborting due to 12 previous errors diff --git a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr index 1e7b990b67c..a1049701dc3 100644 --- a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr +++ b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr @@ -22,11 +22,11 @@ LL | _x1 = U; help: consider making this binding mutable | LL | let [ref _x0_hold, mut _x1, ref xs_hold @ ..] = arr; - | ~~~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | let [ref _x0_hold, ref mut _x1, ref xs_hold @ ..] = arr; - | ~~~~~~~~~~~ + | +++++++ error[E0505]: cannot move out of `arr[..]` because it is borrowed --> $DIR/borrowck-move-ref-pattern.rs:11:10 @@ -86,11 +86,11 @@ LL | _x1 = U; help: consider making this binding mutable | LL | let (ref _x0, mut _x1, ref _x2, ..) = tup; - | ~~~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | let (ref _x0, ref mut _x1, ref _x2, ..) = tup; - | ~~~~~~~~~~~ + | +++++++ error[E0502]: cannot borrow `tup.0` as mutable because it is also borrowed as immutable --> $DIR/borrowck-move-ref-pattern.rs:24:20 diff --git a/tests/ui/pattern/mut-ref-mut-2021.stderr b/tests/ui/pattern/mut-ref-mut-2021.stderr index ebf7979edb6..228afed2026 100644 --- a/tests/ui/pattern/mut-ref-mut-2021.stderr +++ b/tests/ui/pattern/mut-ref-mut-2021.stderr @@ -9,11 +9,11 @@ LL | a = 42; help: consider making this binding mutable | LL | let Foo(mut a) = Foo(0); - | ~~~~~ + | +++ help: to modify the original value, take a borrow instead | LL | let Foo(ref mut a) = Foo(0); - | ~~~~~~~~~ + | +++++++ error[E0384]: cannot assign twice to immutable variable `a` --> $DIR/mut-ref-mut-2021.rs:15:5 diff --git a/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr index 68538255edd..e9c2fccaba2 100644 --- a/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable --> $DIR/patkind-ref-binding-issue-114896.rs:7:9 | -LL | let &b = a; - | -- help: consider changing this to be mutable: `&(mut b)` LL | b.make_ascii_uppercase(); | ^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let &(mut b) = a; + | ~~~~~ + error: aborting due to 1 previous error diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr index 39283133ac7..e93b8bbaccc 100644 --- a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/patkind-ref-binding-issue-122415.rs:7:12 | -LL | fn foo(&x: &i32) { - | -- help: consider changing this to be mutable: `&(mut x)` LL | mutate(&mut x); | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | fn foo(&(mut x): &i32) { + | ~~~~~ + error: aborting due to 1 previous error diff --git a/tests/ui/range/issue-54505-no-std.stderr b/tests/ui/range/issue-54505-no-std.stderr index 1694d514f42..f15a0ae6138 100644 --- a/tests/ui/range/issue-54505-no-std.stderr +++ b/tests/ui/range/issue-54505-no-std.stderr @@ -7,7 +7,7 @@ LL | take_range(0..1); | arguments to this function are incorrect | = note: expected reference `&_` - found struct `Range<{integer}>` + found struct `core::ops::Range<{integer}>` note: function defined here --> $DIR/issue-54505-no-std.rs:25:4 | @@ -27,7 +27,7 @@ LL | take_range(1..); | arguments to this function are incorrect | = note: expected reference `&_` - found struct `RangeFrom<{integer}>` + found struct `core::ops::RangeFrom<{integer}>` note: function defined here --> $DIR/issue-54505-no-std.rs:25:4 | @@ -67,7 +67,7 @@ LL | take_range(0..=1); | arguments to this function are incorrect | = note: expected reference `&_` - found struct `RangeInclusive<{integer}>` + found struct `core::ops::RangeInclusive<{integer}>` note: function defined here --> $DIR/issue-54505-no-std.rs:25:4 | diff --git a/tests/ui/repr/repr-c-dead-variants.aarch64-unknown-linux-gnu.stderr b/tests/ui/repr/repr-c-dead-variants.aarch64-unknown-linux-gnu.stderr new file mode 100644 index 00000000000..e2e57fe0e73 --- /dev/null +++ b/tests/ui/repr/repr-c-dead-variants.aarch64-unknown-linux-gnu.stderr @@ -0,0 +1,288 @@ +error: layout_of(Univariant) = Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=0, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=0, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + } + --> $DIR/repr-c-dead-variants.rs:38:1 + | +LL | enum Univariant { + | ^^^^^^^^^^^^^^^ + +error: layout_of(TwoVariants) = Layout { + size: Size(8 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + Layout { + size: Size(8 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + } + --> $DIR/repr-c-dead-variants.rs:45:1 + | +LL | enum TwoVariants { + | ^^^^^^^^^^^^^^^^ + +error: layout_of(DeadBranchHasOtherField) = Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + Size(8 bytes), + ], + memory_index: [ + 0, + 1, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + }, + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(8 bytes), + }, + ], + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + } + --> $DIR/repr-c-dead-variants.rs:57:1 + | +LL | enum DeadBranchHasOtherField { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/repr/repr-c-dead-variants.armebv7r-none-eabi.stderr b/tests/ui/repr/repr-c-dead-variants.armebv7r-none-eabi.stderr new file mode 100644 index 00000000000..6ecdab1cc14 --- /dev/null +++ b/tests/ui/repr/repr-c-dead-variants.armebv7r-none-eabi.stderr @@ -0,0 +1,288 @@ +error: layout_of(Univariant) = Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=0, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=0, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(1 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + } + --> $DIR/repr-c-dead-variants.rs:38:1 + | +LL | enum Univariant { + | ^^^^^^^^^^^^^^^ + +error: layout_of(TwoVariants) = Layout { + size: Size(2 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(1 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + }, + Layout { + size: Size(2 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(1 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + } + --> $DIR/repr-c-dead-variants.rs:45:1 + | +LL | enum TwoVariants { + | ^^^^^^^^^^^^^^^^ + +error: layout_of(DeadBranchHasOtherField) = Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + Size(8 bytes), + ], + memory_index: [ + 0, + 1, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + }, + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(8 bytes), + }, + ], + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + } + --> $DIR/repr-c-dead-variants.rs:57:1 + | +LL | enum DeadBranchHasOtherField { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/repr/repr-c-dead-variants.i686-pc-windows-msvc.stderr b/tests/ui/repr/repr-c-dead-variants.i686-pc-windows-msvc.stderr new file mode 100644 index 00000000000..e2e57fe0e73 --- /dev/null +++ b/tests/ui/repr/repr-c-dead-variants.i686-pc-windows-msvc.stderr @@ -0,0 +1,288 @@ +error: layout_of(Univariant) = Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=0, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=0, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + } + --> $DIR/repr-c-dead-variants.rs:38:1 + | +LL | enum Univariant { + | ^^^^^^^^^^^^^^^ + +error: layout_of(TwoVariants) = Layout { + size: Size(8 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + Layout { + size: Size(8 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + } + --> $DIR/repr-c-dead-variants.rs:45:1 + | +LL | enum TwoVariants { + | ^^^^^^^^^^^^^^^^ + +error: layout_of(DeadBranchHasOtherField) = Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + Size(8 bytes), + ], + memory_index: [ + 0, + 1, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + }, + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(8 bytes), + }, + ], + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + } + --> $DIR/repr-c-dead-variants.rs:57:1 + | +LL | enum DeadBranchHasOtherField { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/repr/repr-c-dead-variants.rs b/tests/ui/repr/repr-c-dead-variants.rs new file mode 100644 index 00000000000..f113588e83f --- /dev/null +++ b/tests/ui/repr/repr-c-dead-variants.rs @@ -0,0 +1,63 @@ +#![feature(no_core, rustc_attrs, lang_items)] +#![allow(dead_code)] +#![crate_type = "lib"] +#![no_std] +#![no_core] + +// See also: repr-c-int-dead-variants.rs + +//@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN" + +// This test depends on the value of the `c_enum_min_bits` target option. +// As there's no way to actually check it from UI test, we only run this test on a subset of archs. +// Four archs specifically are chosen: one for major architectures (x86_64, i686, aarch64) +// and `armebv7r-none-eabi` that has `c_enum_min_bits` set to 8. + +//@ revisions: aarch64-unknown-linux-gnu +//@[aarch64-unknown-linux-gnu] compile-flags: --target aarch64-unknown-linux-gnu +//@[aarch64-unknown-linux-gnu] needs-llvm-components: aarch64 + +//@ revisions: i686-pc-windows-msvc +//@[i686-pc-windows-msvc] compile-flags: --target i686-pc-windows-gnu +//@[i686-pc-windows-msvc] needs-llvm-components: x86 + +//@ revisions: x86_64-unknown-linux-gnu +//@[x86_64-unknown-linux-gnu] compile-flags: --target x86_64-unknown-linux-gnu +//@[x86_64-unknown-linux-gnu] needs-llvm-components: x86 +// +//@ revisions: armebv7r-none-eabi +//@[armebv7r-none-eabi] compile-flags: --target armebv7r-none-eabi +//@[armebv7r-none-eabi] needs-llvm-components: arm + +// A simple uninhabited type. +enum Void {} + +// Compiler must not remove dead variants of `#[repr(C, int)]` ADTs. +#[repr(C)] +#[rustc_layout(debug)] +enum Univariant { //~ ERROR layout_of + Variant(Void), +} + +// ADTs with variants that have fields must have space allocated for those fields. +#[repr(C)] +#[rustc_layout(debug)] +enum TwoVariants { //~ ERROR layout_of + Variant1(Void), + Variant2(u8), +} + +// Some targets have 4-byte-aligned u64, make it always 8-byte-aligned. +#[repr(C, align(8))] +struct Align8U64(u64); + +// This one is 2 x u64: we reserve space for fields in a dead branch. +#[repr(C)] +#[rustc_layout(debug)] +enum DeadBranchHasOtherField { //~ ERROR layout_of + Variant1(Void, Align8U64), + Variant2(u8), +} + +#[lang = "sized"] +trait Sized {} diff --git a/tests/ui/repr/repr-c-dead-variants.x86_64-unknown-linux-gnu.stderr b/tests/ui/repr/repr-c-dead-variants.x86_64-unknown-linux-gnu.stderr new file mode 100644 index 00000000000..e2e57fe0e73 --- /dev/null +++ b/tests/ui/repr/repr-c-dead-variants.x86_64-unknown-linux-gnu.stderr @@ -0,0 +1,288 @@ +error: layout_of(Univariant) = Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=0, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=0, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + } + --> $DIR/repr-c-dead-variants.rs:38:1 + | +LL | enum Univariant { + | ^^^^^^^^^^^^^^^ + +error: layout_of(TwoVariants) = Layout { + size: Size(8 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(4 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + Layout { + size: Size(8 bytes), + align: AbiAndPrefAlign { + abi: Align(4 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(4 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + } + --> $DIR/repr-c-dead-variants.rs:45:1 + | +LL | enum TwoVariants { + | ^^^^^^^^^^^^^^^^ + +error: layout_of(DeadBranchHasOtherField) = Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I32, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + Size(8 bytes), + ], + memory_index: [ + 0, + 1, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + }, + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(8 bytes), + }, + ], + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + } + --> $DIR/repr-c-dead-variants.rs:57:1 + | +LL | enum DeadBranchHasOtherField { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/repr/repr-c-int-dead-variants.rs b/tests/ui/repr/repr-c-int-dead-variants.rs new file mode 100644 index 00000000000..8d2b39bd648 --- /dev/null +++ b/tests/ui/repr/repr-c-int-dead-variants.rs @@ -0,0 +1,38 @@ +#![feature(rustc_attrs)] +#![allow(dead_code)] + +// See also: repr-c-dead-variants.rs + +//@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN" + +// A simple uninhabited type. +enum Void {} + +// Compiler must not remove dead variants of `#[repr(C, int)]` ADTs. +#[repr(C, u8)] +#[rustc_layout(debug)] +enum UnivariantU8 { //~ ERROR layout_of + Variant(Void), +} + +// ADTs with variants that have fields must have space allocated for those fields. +#[repr(C, u8)] +#[rustc_layout(debug)] +enum TwoVariantsU8 { //~ ERROR layout_of + Variant1(Void), + Variant2(u8), +} + +// Some targets have 4-byte-aligned u64, make it always 8-byte-aligned. +#[repr(C, align(8))] +struct Align8U64(u64); + +// This one is 2 x u64: we reserve space for fields in a dead branch. +#[repr(C, u8)] +#[rustc_layout(debug)] +enum DeadBranchHasOtherFieldU8 { //~ ERROR layout_of + Variant1(Void, Align8U64), + Variant2(u8), +} + +fn main() {} diff --git a/tests/ui/repr/repr-c-int-dead-variants.stderr b/tests/ui/repr/repr-c-int-dead-variants.stderr new file mode 100644 index 00000000000..f7df576df24 --- /dev/null +++ b/tests/ui/repr/repr-c-int-dead-variants.stderr @@ -0,0 +1,288 @@ +error: layout_of(UnivariantU8) = Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=0, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=0, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(1 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + } + --> $DIR/repr-c-int-dead-variants.rs:14:1 + | +LL | enum UnivariantU8 { + | ^^^^^^^^^^^^^^^^^ + +error: layout_of(TwoVariantsU8) = Layout { + size: Size(2 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(1 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + }, + Layout { + size: Size(2 bytes), + align: AbiAndPrefAlign { + abi: Align(1 bytes), + pref: $SOME_ALIGN, + }, + abi: ScalarPair( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + Union { + value: Int( + I8, + false, + ), + }, + ), + fields: Arbitrary { + offsets: [ + Size(1 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + }, + ], + }, + max_repr_align: None, + unadjusted_abi_align: Align(1 bytes), + } + --> $DIR/repr-c-int-dead-variants.rs:21:1 + | +LL | enum TwoVariantsU8 { + | ^^^^^^^^^^^^^^^^^^ + +error: layout_of(DeadBranchHasOtherFieldU8) = Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(0 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Multiple { + tag: Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + tag_encoding: Direct, + tag_field: 0, + variants: [ + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Uninhabited, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + Size(8 bytes), + ], + memory_index: [ + 0, + 1, + ], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + }, + Layout { + size: Size(16 bytes), + align: AbiAndPrefAlign { + abi: Align(8 bytes), + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [ + Size(8 bytes), + ], + memory_index: [ + 0, + ], + }, + largest_niche: None, + variants: Single { + index: 1, + }, + max_repr_align: None, + unadjusted_abi_align: Align(8 bytes), + }, + ], + }, + max_repr_align: Some( + Align(8 bytes), + ), + unadjusted_abi_align: Align(8 bytes), + } + --> $DIR/repr-c-int-dead-variants.rs:33:1 + | +LL | enum DeadBranchHasOtherFieldU8 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/resolve/field-and-method-in-self-not-available-in-assoc-fn.stderr b/tests/ui/resolve/field-and-method-in-self-not-available-in-assoc-fn.stderr index 3c44c1c249c..2f624f24804 100644 --- a/tests/ui/resolve/field-and-method-in-self-not-available-in-assoc-fn.stderr +++ b/tests/ui/resolve/field-and-method-in-self-not-available-in-assoc-fn.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find value `field` in this scope --> $DIR/field-and-method-in-self-not-available-in-assoc-fn.rs:11:9 | LL | field: u32, - | ---------- a field by that name exists in `Self` + | ----- a field by that name exists in `Self` ... LL | fn field(&self) -> u32 { | ----- a method by that name is available on `Self` here @@ -14,7 +14,7 @@ error[E0425]: cannot find value `field` in this scope --> $DIR/field-and-method-in-self-not-available-in-assoc-fn.rs:12:15 | LL | field: u32, - | ---------- a field by that name exists in `Self` + | ----- a field by that name exists in `Self` ... LL | fn field(&self) -> u32 { | ----- a method by that name is available on `Self` here diff --git a/tests/ui/resolve/issue-2356.stderr b/tests/ui/resolve/issue-2356.stderr index 5f75ae98870..74a2c9268a2 100644 --- a/tests/ui/resolve/issue-2356.stderr +++ b/tests/ui/resolve/issue-2356.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find value `whiskers` in this scope --> $DIR/issue-2356.rs:39:5 | LL | whiskers: isize, - | --------------- a field by that name exists in `Self` + | -------- a field by that name exists in `Self` ... LL | whiskers -= other; | ^^^^^^^^ @@ -35,7 +35,7 @@ error[E0425]: cannot find value `whiskers` in this scope --> $DIR/issue-2356.rs:84:5 | LL | whiskers: isize, - | --------------- a field by that name exists in `Self` + | -------- a field by that name exists in `Self` ... LL | whiskers = 4; | ^^^^^^^^ diff --git a/tests/ui/resolve/issue-60057.stderr b/tests/ui/resolve/issue-60057.stderr index a2ab8644353..8737cf77001 100644 --- a/tests/ui/resolve/issue-60057.stderr +++ b/tests/ui/resolve/issue-60057.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find value `banana` in this scope --> $DIR/issue-60057.rs:8:21 | LL | banana: u8, - | ---------- a field by that name exists in `Self` + | ------ a field by that name exists in `Self` ... LL | banana: banana | ^^^^^^ diff --git a/tests/ui/resolve/resolve-primitive-fallback.stderr b/tests/ui/resolve/resolve-primitive-fallback.stderr index e3a5d4edcf1..d0583966459 100644 --- a/tests/ui/resolve/resolve-primitive-fallback.stderr +++ b/tests/ui/resolve/resolve-primitive-fallback.stderr @@ -24,13 +24,15 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/resolve-primitive-fallback.rs:3:5 | LL | std::mem::size_of(u16); - | ^^^^^^^^^^^^^^^^^ --- - | | - | unexpected argument - | help: remove the extra argument + | ^^^^^^^^^^^^^^^^^ --- unexpected argument | note: function defined here --> $SRC_DIR/core/src/mem/mod.rs:LL:COL +help: remove the extra argument + | +LL - std::mem::size_of(u16); +LL + std::mem::size_of(); + | error: aborting due to 3 previous errors diff --git a/tests/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr b/tests/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr index 0306c8af87d..5662021a2d5 100644 --- a/tests/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr +++ b/tests/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find value `config` in this scope --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:7:16 | LL | config: String, - | -------------- a field by that name exists in `Self` + | ------ a field by that name exists in `Self` ... LL | Self { config } | ^^^^^^ help: a local variable with a similar name exists: `cofig` @@ -11,7 +11,7 @@ error[E0425]: cannot find value `config` in this scope --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:11:20 | LL | config: String, - | -------------- a field by that name exists in `Self` + | ------ a field by that name exists in `Self` ... LL | println!("{config}"); | ^^^^^^ help: a local variable with a similar name exists: `cofig` diff --git a/tests/ui/resolve/unresolved_static_type_field.stderr b/tests/ui/resolve/unresolved_static_type_field.stderr index e3de0a3fb74..f039eef2e06 100644 --- a/tests/ui/resolve/unresolved_static_type_field.stderr +++ b/tests/ui/resolve/unresolved_static_type_field.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find value `cx` in this scope --> $DIR/unresolved_static_type_field.rs:9:11 | LL | cx: bool, - | -------- a field by that name exists in `Self` + | -- a field by that name exists in `Self` ... LL | f(cx); | ^^ diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs index af88a73b4d6..63c353c7d66 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs @@ -1,12 +1,16 @@ //@ known-bug: #110395 +//@ failure-status: 101 +//@ normalize-stderr-test ".*note: .*\n\n" -> "" +//@ normalize-stderr-test "thread 'rustc' panicked.*:\n.*\n" -> "" +//@ rustc-env:RUST_BACKTRACE=0 // FIXME(effects) check-pass -// FIXME(effects) fix intrinsics const parameter counting +//@ compile-flags: -Znext-solver #![crate_type = "lib"] #![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs, staged_api)] -#![feature(fundamental)] +#![feature(fundamental, marker_trait_attr)] #![feature(const_trait_impl, effects, const_mut_refs)] -#![allow(internal_features)] +#![allow(internal_features, incomplete_features)] #![no_std] #![no_core] #![stable(feature = "minicore", since = "1.0.0")] @@ -532,3 +536,35 @@ fn test_const_eval_select() { const_eval_select((), const_fn, rt_fn); } + +mod effects { + use super::Sized; + + #[lang = "EffectsNoRuntime"] + pub struct NoRuntime; + #[lang = "EffectsMaybe"] + pub struct Maybe; + #[lang = "EffectsRuntime"] + pub struct Runtime; + + #[lang = "EffectsCompat"] + pub trait Compat<#[rustc_runtime] const RUNTIME: bool> {} + + impl Compat<false> for NoRuntime {} + impl Compat<true> for Runtime {} + impl<#[rustc_runtime] const RUNTIME: bool> Compat<RUNTIME> for Maybe {} + + #[lang = "EffectsTyCompat"] + #[marker] + pub trait TyCompat<T: ?Sized> {} + + impl<T: ?Sized> TyCompat<T> for T {} + impl<T: ?Sized> TyCompat<T> for Maybe {} + impl<T: ?Sized> TyCompat<Maybe> for T {} + + #[lang = "EffectsIntersection"] + pub trait Intersection { + #[lang = "EffectsIntersectionOutput"] + type Output: ?Sized; + } +} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr index 1963332b856..823ab69df9c 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr @@ -1,17 +1,13 @@ -warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/minicore.rs:8:30 - | -LL | #![feature(const_trait_impl, effects, const_mut_refs)] - | ^^^^^^^ - | - = note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information - = note: `#[warn(incomplete_features)]` on by default +error: the compiler unexpectedly panicked. this is a bug. -error: requires `EffectsCompat` lang_item - --> $DIR/minicore.rs:455:9 - | -LL | impl<T: Clone> Clone for RefCell<T> { - | ^^^^^ +query stack during panic: +#0 [check_well_formed] checking that `<impl at $DIR/minicore.rs:459:1: 459:36>` is well-formed +#1 [check_mod_type_wf] checking that types are well-formed in top-level module +end of query stack -error: aborting due to 1 previous error; 1 warning emitted +error: the compiler unexpectedly panicked. this is a bug. +query stack during panic: +#0 [check_well_formed] checking that `drop` is well-formed +#1 [check_mod_type_wf] checking that types are well-formed in top-level module +end of query stack diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.nn.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.nn.stderr deleted file mode 100644 index 03536dca1e8..00000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.nn.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0271]: type mismatch resolving `<() as Index>::Output == &mut <() as Index>::Output` - --> $DIR/issue-100222.rs:34:12 - | -LL | fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output - | ^^^^^^^^^ expected `()`, found `&mut <() as Index>::Output` - | - = note: expected unit type `()` - found mutable reference `&mut <() as Index>::Output` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.ny.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.ny.stderr deleted file mode 100644 index 6a70a503606..00000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.ny.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0271]: type mismatch resolving `<() as Index>::Output == &mut <() as Index>::Output` - --> $DIR/issue-100222.rs:25:12 - | -LL | fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output - | ^^^^^^^^^ expected `()`, found `&mut <() as Index>::Output` - | - = note: expected unit type `()` - found mutable reference `&mut <() as Index>::Output` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.rs index 7949772a2b4..47f9fc664ce 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.rs @@ -1,6 +1,7 @@ //@ revisions: nn ny yn yy -//@ known-bug: #110395 //@ compile-flags: -Znext-solver +//@ check-pass + #![allow(incomplete_features)] #![feature(const_trait_impl, effects, associated_type_defaults, const_mut_refs)] diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yn.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yn.stderr deleted file mode 100644 index 03536dca1e8..00000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yn.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0271]: type mismatch resolving `<() as Index>::Output == &mut <() as Index>::Output` - --> $DIR/issue-100222.rs:34:12 - | -LL | fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output - | ^^^^^^^^^ expected `()`, found `&mut <() as Index>::Output` - | - = note: expected unit type `()` - found mutable reference `&mut <() as Index>::Output` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yy.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yy.stderr deleted file mode 100644 index 6a70a503606..00000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yy.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0271]: type mismatch resolving `<() as Index>::Output == &mut <() as Index>::Output` - --> $DIR/issue-100222.rs:25:12 - | -LL | fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output - | ^^^^^^^^^ expected `()`, found `&mut <() as Index>::Output` - | - = note: expected unit type `()` - found mutable reference `&mut <() as Index>::Output` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.gated.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.gated.stderr new file mode 100644 index 00000000000..80e7a45f57e --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.gated.stderr @@ -0,0 +1,8 @@ +error: expected one of `!` or `::`, found keyword `impl` + --> $DIR/safe-impl-trait.rs:5:6 + | +LL | safe impl Bar for () { } + | ^^^^ expected one of `!` or `::` + +error: aborting due to 1 previous error + diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.rs b/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.rs new file mode 100644 index 00000000000..57c03e4d896 --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.rs @@ -0,0 +1,8 @@ +//@ revisions: gated ungated +#![cfg_attr(gated, feature(unsafe_extern_blocks))] + +trait Bar {} +safe impl Bar for () { } +//~^ ERROR expected one of `!` or `::`, found keyword `impl` + +fn main() {} diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.ungated.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.ungated.stderr new file mode 100644 index 00000000000..80e7a45f57e --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/safe-impl-trait.ungated.stderr @@ -0,0 +1,8 @@ +error: expected one of `!` or `::`, found keyword `impl` + --> $DIR/safe-impl-trait.rs:5:6 + | +LL | safe impl Bar for () { } + | ^^^^ expected one of `!` or `::` + +error: aborting due to 1 previous error + diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.gated.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.gated.stderr new file mode 100644 index 00000000000..de84037f28c --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.gated.stderr @@ -0,0 +1,8 @@ +error: expected one of `!` or `::`, found keyword `trait` + --> $DIR/safe-trait.rs:4:6 + | +LL | safe trait Foo {} + | ^^^^^ expected one of `!` or `::` + +error: aborting due to 1 previous error + diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.rs b/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.rs new file mode 100644 index 00000000000..e73cb45b188 --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.rs @@ -0,0 +1,7 @@ +//@ revisions: gated ungated +#![cfg_attr(gated, feature(unsafe_extern_blocks))] + +safe trait Foo {} +//~^ ERROR expected one of `!` or `::`, found keyword `trait` + +fn main() {} diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.ungated.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.ungated.stderr new file mode 100644 index 00000000000..de84037f28c --- /dev/null +++ b/tests/ui/rust-2024/unsafe-extern-blocks/safe-trait.ungated.stderr @@ -0,0 +1,8 @@ +error: expected one of `!` or `::`, found keyword `trait` + --> $DIR/safe-trait.rs:4:6 + | +LL | safe trait Foo {} + | ^^^^^ expected one of `!` or `::` + +error: aborting due to 1 previous error + diff --git a/tests/ui/self/arbitrary-self-from-method-substs-ice.rs b/tests/ui/self/arbitrary-self-from-method-substs-ice.rs new file mode 100644 index 00000000000..8bf9f97e0b9 --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-ice.rs @@ -0,0 +1,29 @@ +//! The same as the non-ICE test, but const eval will run typeck of +//! `get` before running wfcheck (as that may in itself trigger const +//! eval again, and thus cause bogus cycles). This used to ICE because +//! we asserted that an error had already been emitted. + +use std::ops::Deref; + +struct Foo(u32); +impl Foo { + const fn get<R: Deref<Target = Self>>(self: R) -> u32 { + //~^ ERROR: `R` cannot be used as the type of `self` + //~| ERROR destructor of `R` cannot be evaluated at compile-time + self.0 + //~^ ERROR cannot borrow here, since the borrowed element may contain interior mutability + //~| ERROR cannot call non-const fn `<R as Deref>::deref` in constant function + } +} + +const FOO: () = { + let foo = Foo(1); + foo.get::<&Foo>(); +}; + +const BAR: [(); { + FOO; + 0 +}] = []; + +fn main() {} diff --git a/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr b/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr new file mode 100644 index 00000000000..9e3851f9a6e --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr @@ -0,0 +1,46 @@ +error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability + --> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9 + | +LL | self.0 + | ^^^^ + | + = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information + = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0015]: cannot call non-const fn `<R as Deref>::deref` in constant functions + --> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9 + | +LL | self.0 + | ^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | + +error[E0493]: destructor of `R` cannot be evaluated at compile-time + --> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43 + | +LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 { + | ^^^^ the destructor for this type cannot be evaluated in constant functions +... +LL | } + | - value is dropped here + +error[E0658]: `R` cannot be used as the type of `self` without the `arbitrary_self_types` feature + --> $DIR/arbitrary-self-from-method-substs-ice.rs:10:49 + | +LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 { + | ^ + | + = note: see issue #44874 <https://github.com/rust-lang/rust/issues/44874> for more information + = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0015, E0493, E0658. +For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/self/arbitrary-self-from-method-substs.default.stderr b/tests/ui/self/arbitrary-self-from-method-substs.default.stderr index 6fff086a89c..4cc69666b88 100644 --- a/tests/ui/self/arbitrary-self-from-method-substs.default.stderr +++ b/tests/ui/self/arbitrary-self-from-method-substs.default.stderr @@ -9,7 +9,6 @@ LL | fn get<R: Deref<Target = Self>>(self: R) -> u32 { = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) - ERROR rustc_hir_typeck::method::confirm Foo was a subtype of &Foo but now is not? error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/simd/simd-bitmask-notpow2.rs b/tests/ui/simd/simd-bitmask-notpow2.rs new file mode 100644 index 00000000000..ff43206a3fd --- /dev/null +++ b/tests/ui/simd/simd-bitmask-notpow2.rs @@ -0,0 +1,90 @@ +//@run-pass +// SEGFAULTS on LLVM 17. This should be merged into `simd-bitmask` once we require LLVM 18. +//@ min-llvm-version: 18 +// FIXME: broken codegen on big-endian (https://github.com/rust-lang/rust/issues/127205) +//@ ignore-endian-big +#![feature(repr_simd, intrinsics)] + +extern "rust-intrinsic" { + fn simd_bitmask<T, U>(v: T) -> U; + fn simd_select_bitmask<T, U>(m: T, a: U, b: U) -> U; +} + +fn main() { + // Non-power-of-2 multi-byte mask. + #[repr(simd, packed)] + #[allow(non_camel_case_types)] + #[derive(Copy, Clone, Debug, PartialEq)] + struct i32x10([i32; 10]); + impl i32x10 { + fn splat(x: i32) -> Self { + Self([x; 10]) + } + } + unsafe { + let mask = i32x10([!0, !0, 0, !0, 0, 0, !0, 0, !0, 0]); + let mask_bits = if cfg!(target_endian = "little") { 0b0101001011 } else { 0b1101001010 }; + let mask_bytes = + if cfg!(target_endian = "little") { [0b01001011, 0b01] } else { [0b11, 0b01001010] }; + + let bitmask1: u16 = simd_bitmask(mask); + let bitmask2: [u8; 2] = simd_bitmask(mask); + assert_eq!(bitmask1, mask_bits); + assert_eq!(bitmask2, mask_bytes); + + let selected1 = simd_select_bitmask::<u16, _>( + mask_bits, + i32x10::splat(!0), // yes + i32x10::splat(0), // no + ); + let selected2 = simd_select_bitmask::<[u8; 2], _>( + mask_bytes, + i32x10::splat(!0), // yes + i32x10::splat(0), // no + ); + assert_eq!(selected1, mask); + assert_eq!(selected2, mask); + } + + // Test for a mask where the next multiple of 8 is not a power of two. + #[repr(simd, packed)] + #[allow(non_camel_case_types)] + #[derive(Copy, Clone, Debug, PartialEq)] + struct i32x20([i32; 20]); + impl i32x20 { + fn splat(x: i32) -> Self { + Self([x; 20]) + } + } + unsafe { + let mask = i32x20([!0, !0, 0, !0, 0, 0, !0, 0, !0, 0, 0, 0, 0, !0, !0, !0, !0, !0, !0, !0]); + let mask_bits = if cfg!(target_endian = "little") { + 0b11111110000101001011 + } else { + 0b11010010100001111111 + }; + let mask_bytes = if cfg!(target_endian = "little") { + [0b01001011, 0b11100001, 0b1111] + } else { + [0b1101, 0b00101000, 0b01111111] + }; + + let bitmask1: u32 = simd_bitmask(mask); + let bitmask2: [u8; 3] = simd_bitmask(mask); + assert_eq!(bitmask1, mask_bits); + assert_eq!(bitmask2, mask_bytes); + + let selected1 = simd_select_bitmask::<u32, _>( + mask_bits, + i32x20::splat(!0), // yes + i32x20::splat(0), // no + ); + let selected2 = simd_select_bitmask::<[u8; 3], _>( + mask_bytes, + i32x20::splat(!0), // yes + i32x20::splat(0), // no + ); + assert_eq!(selected1, mask); + assert_eq!(selected2, mask); + } +} diff --git a/tests/ui/simd/simd-bitmask.rs b/tests/ui/simd/simd-bitmask.rs index 4a7c3bc7750..82f73fca951 100644 --- a/tests/ui/simd/simd-bitmask.rs +++ b/tests/ui/simd/simd-bitmask.rs @@ -1,5 +1,4 @@ //@run-pass -//@ignore-endian-big behavior of simd_select_bitmask is endian-specific #![feature(repr_simd, intrinsics)] extern "rust-intrinsic" { @@ -17,36 +16,58 @@ fn main() { let i: u8 = simd_bitmask(v); let a: [u8; 1] = simd_bitmask(v); - assert_eq!(i, 0b0101); - assert_eq!(a, [0b0101]); + if cfg!(target_endian = "little") { + assert_eq!(i, 0b0101); + assert_eq!(a, [0b0101]); + } else { + assert_eq!(i, 0b1010); + assert_eq!(a, [0b1010]); + } let v = Simd::<i8, 16>([0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0]); let i: u16 = simd_bitmask(v); let a: [u8; 2] = simd_bitmask(v); - assert_eq!(i, 0b0101000000001100); - assert_eq!(a, [0b1100, 0b01010000]); + if cfg!(target_endian = "little") { + assert_eq!(i, 0b0101000000001100); + assert_eq!(a, [0b00001100, 0b01010000]); + } else { + assert_eq!(i, 0b0011000000001010); + assert_eq!(a, [0b00110000, 0b00001010]); + } } unsafe { - let a = Simd::<i32, 8>([0, 1, 2, 3, 4, 5, 6, 7]); - let b = Simd::<i32, 8>([8, 9, 10, 11, 12, 13, 14, 15]); - let e = [0, 9, 2, 11, 12, 13, 14, 15]; + let a = Simd::<i32, 4>([0, 1, 2, 3]); + let b = Simd::<i32, 4>([8, 9, 10, 11]); + let e = [0, 9, 2, 11]; - let r = simd_select_bitmask(0b0101u8, a, b); + let mask = if cfg!(target_endian = "little") { 0b0101u8 } else { 0b1010u8 }; + let r = simd_select_bitmask(mask, a, b); assert_eq!(r.0, e); - let r = simd_select_bitmask([0b0101u8], a, b); + let mask = if cfg!(target_endian = "little") { [0b0101u8] } else { [0b1010u8] }; + let r = simd_select_bitmask(mask, a, b); assert_eq!(r.0, e); let a = Simd::<i32, 16>([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); let b = Simd::<i32, 16>([16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]); let e = [16, 17, 2, 3, 20, 21, 22, 23, 24, 25, 26, 27, 12, 29, 14, 31]; - let r = simd_select_bitmask(0b0101000000001100u16, a, b); + let mask = if cfg!(target_endian = "little") { + 0b0101000000001100u16 + } else { + 0b0011000000001010u16 + }; + let r = simd_select_bitmask(mask, a, b); assert_eq!(r.0, e); - let r = simd_select_bitmask([0b1100u8, 0b01010000u8], a, b); + let mask = if cfg!(target_endian = "little") { + [0b00001100u8, 0b01010000u8] + } else { + [0b00110000u8, 0b00001010u8] + }; + let r = simd_select_bitmask(mask, a, b); assert_eq!(r.0, e); } } diff --git a/tests/ui/span/issue-34264.stderr b/tests/ui/span/issue-34264.stderr index f0dea66f612..89c67719b5a 100644 --- a/tests/ui/span/issue-34264.stderr +++ b/tests/ui/span/issue-34264.stderr @@ -54,16 +54,18 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/issue-34264.rs:7:5 | LL | foo(Some(42), 2, ""); - | ^^^ ---- - | | | - | | unexpected argument of type `&'static str` - | help: remove the extra argument + | ^^^ -- unexpected argument of type `&'static str` | note: function defined here --> $DIR/issue-34264.rs:1:4 | LL | fn foo(Option<i32>, String) {} | ^^^ ----------- ------ +help: remove the extra argument + | +LL - foo(Some(42), 2, ""); +LL + foo(Some(42), 2); + | error[E0308]: mismatched types --> $DIR/issue-34264.rs:8:13 @@ -83,16 +85,18 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/issue-34264.rs:10:5 | LL | bar(1, 2, 3); - | ^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^ - unexpected argument of type `{integer}` | note: function defined here --> $DIR/issue-34264.rs:3:4 | LL | fn bar(x, y: usize) {} | ^^^ - -------- +help: remove the extra argument + | +LL - bar(1, 2, 3); +LL + bar(1, 2); + | error: aborting due to 6 previous errors diff --git a/tests/ui/structs/structure-constructor-type-mismatch.stderr b/tests/ui/structs/structure-constructor-type-mismatch.stderr index 63dda459396..cb957487347 100644 --- a/tests/ui/structs/structure-constructor-type-mismatch.stderr +++ b/tests/ui/structs/structure-constructor-type-mismatch.stderr @@ -2,55 +2,67 @@ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:17:12 | LL | x: 1, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `1.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | x: 1.0, + | ++ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:20:12 | LL | y: 2, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `2.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | y: 2.0, + | ++ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:26:12 | LL | x: 3, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `3.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | x: 3.0, + | ++ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:29:12 | LL | y: 4, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `4.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | y: 4.0, + | ++ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:35:12 | LL | x: 5, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `5.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | x: 5.0, + | ++ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:42:12 | LL | x: 7, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `7.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | x: 7.0, + | ++ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/structure-constructor-type-mismatch.rs:48:15 @@ -70,19 +82,23 @@ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:49:12 | LL | x: 9, - | ^ - | | - | expected `f32`, found integer - | help: use a float literal: `9.0` + | ^ expected `f32`, found integer + | +help: use a float literal + | +LL | x: 9.0, + | ++ error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:50:12 | LL | y: 10, - | ^^ - | | - | expected `f32`, found integer - | help: use a float literal: `10.0` + | ^^ expected `f32`, found integer + | +help: use a float literal + | +LL | y: 10.0, + | ++ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/structure-constructor-type-mismatch.rs:54:9 diff --git a/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.fixed b/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.fixed index e072c476c6b..4e562193f0d 100644 --- a/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.fixed +++ b/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.fixed @@ -3,9 +3,9 @@ trait Trait {} -fn assert_send(ptr: *mut dyn Trait) -> *mut (dyn Trait + Send) { +fn assert_send() -> *mut (dyn Trait + Send) { //~^ ERROR incorrect parentheses around trait bounds - ptr as _ + loop {} } fn foo2(_: &(dyn Trait + Send)) {} diff --git a/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.rs b/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.rs index 88995141426..4a00059400c 100644 --- a/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.rs +++ b/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.rs @@ -3,9 +3,9 @@ trait Trait {} -fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) { +fn assert_send() -> *mut dyn (Trait + Send) { //~^ ERROR incorrect parentheses around trait bounds - ptr as _ + loop {} } fn foo2(_: &dyn (Trait + Send)) {} diff --git a/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.stderr b/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.stderr index 2d1abe91a1e..c67557fa14f 100644 --- a/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.stderr +++ b/tests/ui/suggestions/issue-114797-bad-parentheses-dyn-trait.stderr @@ -1,13 +1,13 @@ error: incorrect parentheses around trait bounds - --> $DIR/issue-114797-bad-parentheses-dyn-trait.rs:6:49 + --> $DIR/issue-114797-bad-parentheses-dyn-trait.rs:6:30 | -LL | fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) { - | ^ ^ +LL | fn assert_send() -> *mut dyn (Trait + Send) { + | ^ ^ | help: fix the parentheses | -LL - fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) { -LL + fn assert_send(ptr: *mut dyn Trait) -> *mut (dyn Trait + Send) { +LL - fn assert_send() -> *mut dyn (Trait + Send) { +LL + fn assert_send() -> *mut (dyn Trait + Send) { | error: incorrect parentheses around trait bounds diff --git a/tests/ui/suggestions/match-ergonomics.stderr b/tests/ui/suggestions/match-ergonomics.stderr index a3e059e8ac6..2cd43c26ca3 100644 --- a/tests/ui/suggestions/match-ergonomics.stderr +++ b/tests/ui/suggestions/match-ergonomics.stderr @@ -17,18 +17,24 @@ LL + [v] => {}, error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/match-ergonomics.rs:8:9 | -LL | match x { - | - help: consider slicing here: `x[..]` LL | [&v] => {}, | ^^^^ pattern cannot match with input type `Vec<i32>` + | +help: consider slicing here + | +LL | match x[..] { + | ++++ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/match-ergonomics.rs:20:9 | -LL | match x { - | - help: consider slicing here: `x[..]` LL | [v] => {}, | ^^^ pattern cannot match with input type `Vec<i32>` + | +help: consider slicing here + | +LL | match x[..] { + | ++++ error[E0308]: mismatched types --> $DIR/match-ergonomics.rs:29:9 diff --git a/tests/ui/suggestions/parenthesized-deref-suggestion.stderr b/tests/ui/suggestions/parenthesized-deref-suggestion.stderr index 9f185f5dd52..29e973b3a17 100644 --- a/tests/ui/suggestions/parenthesized-deref-suggestion.stderr +++ b/tests/ui/suggestions/parenthesized-deref-suggestion.stderr @@ -4,19 +4,21 @@ error[E0609]: no field `opts` on type `*const Session` LL | (sess as *const Session).opts; | ^^^^ unknown field | -help: `(sess as *const Session)` is a raw pointer; try dereferencing it +help: the value is a raw pointer; try dereferencing it | LL | (*(sess as *const Session)).opts; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ++ + error[E0609]: no field `0` on type `[u32; 1]` --> $DIR/parenthesized-deref-suggestion.rs:10:21 | LL | (x as [u32; 1]).0; - | ----------------^ - | | | - | | unknown field - | help: instead of using tuple indexing, use array indexing: `(x as [u32; 1])[0]` + | ^ unknown field + | +help: instead of using tuple indexing, use array indexing + | +LL | (x as [u32; 1])[0]; + | ~ + error: aborting due to 2 previous errors diff --git a/tests/ui/suggestions/pattern-slice-vec.stderr b/tests/ui/suggestions/pattern-slice-vec.stderr index f69e7de971a..36a9df3f750 100644 --- a/tests/ui/suggestions/pattern-slice-vec.stderr +++ b/tests/ui/suggestions/pattern-slice-vec.stderr @@ -2,42 +2,56 @@ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/pattern-slice-vec.rs:8:12 | LL | if let [_, _, _] = foo() {} - | ^^^^^^^^^ ----- help: consider slicing here: `foo()[..]` - | | - | pattern cannot match with input type `Vec<i32>` + | ^^^^^^^^^ pattern cannot match with input type `Vec<i32>` + | +help: consider slicing here + | +LL | if let [_, _, _] = foo()[..] {} + | ++++ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/pattern-slice-vec.rs:12:12 | LL | if let [] = &foo() {} - | ^^ ------ help: consider slicing here: `&foo()[..]` - | | - | pattern cannot match with input type `Vec<i32>` + | ^^ pattern cannot match with input type `Vec<i32>` + | +help: consider slicing here + | +LL | if let [] = &foo()[..] {} + | ++++ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/pattern-slice-vec.rs:16:12 | LL | if let [] = foo() {} - | ^^ ----- help: consider slicing here: `foo()[..]` - | | - | pattern cannot match with input type `Vec<i32>` + | ^^ pattern cannot match with input type `Vec<i32>` + | +help: consider slicing here + | +LL | if let [] = foo()[..] {} + | ++++ error[E0529]: expected an array or slice, found `Vec<_>` --> $DIR/pattern-slice-vec.rs:23:9 | -LL | match &v { - | -- help: consider slicing here: `&v[..]` -LL | LL | [5] => {} | ^^^ pattern cannot match with input type `Vec<_>` + | +help: consider slicing here + | +LL | match &v[..] { + | ++++ error[E0529]: expected an array or slice, found `Vec<{integer}>` --> $DIR/pattern-slice-vec.rs:28:9 | LL | let [..] = vec![1, 2, 3]; - | ^^^^ ------------- help: consider slicing here: `vec![1, 2, 3][..]` - | | - | pattern cannot match with input type `Vec<{integer}>` + | ^^^^ pattern cannot match with input type `Vec<{integer}>` + | +help: consider slicing here + | +LL | let [..] = vec![1, 2, 3][..]; + | ++++ error: aborting due to 5 previous errors diff --git a/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr b/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr index c28d67604da..cab9bbb72df 100644 --- a/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr +++ b/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr @@ -2,9 +2,12 @@ error[E0529]: expected an array or slice, found `Vec<Struct>` --> $DIR/suppress-consider-slicing-issue-120605.rs:7:16 | LL | if let [Struct { a: [] }] = &self.a { - | ^^^^^^^^^^^^^^^^^^ ------- help: consider slicing here: `&self.a[..]` - | | - | pattern cannot match with input type `Vec<Struct>` + | ^^^^^^^^^^^^^^^^^^ pattern cannot match with input type `Vec<Struct>` + | +help: consider slicing here + | +LL | if let [Struct { a: [] }] = &self.a[..] { + | ++++ error[E0529]: expected an array or slice, found `Vec<Struct>` --> $DIR/suppress-consider-slicing-issue-120605.rs:7:29 diff --git a/tests/ui/traits/impl-method-mismatch.stderr b/tests/ui/traits/impl-method-mismatch.stderr index 77d542c729a..db457b77a23 100644 --- a/tests/ui/traits/impl-method-mismatch.stderr +++ b/tests/ui/traits/impl-method-mismatch.stderr @@ -10,7 +10,7 @@ note: type in trait LL | fn jumbo(&self, x: &usize) -> usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature `fn(&_, &_) -> usize` - found signature `unsafe fn(&_, &_)` + found signature `unsafe fn(&_, &_) -> ()` error: aborting due to 1 previous error diff --git a/tests/ui/traits/issue-35869.stderr b/tests/ui/traits/issue-35869.stderr index 6d985bdeaf8..503f9cee246 100644 --- a/tests/ui/traits/issue-35869.stderr +++ b/tests/ui/traits/issue-35869.stderr @@ -2,10 +2,7 @@ error[E0053]: method `foo` has an incompatible type for trait --> $DIR/issue-35869.rs:11:15 | LL | fn foo(_: fn(u16) -> ()) {} - | ^^^^^^^^^^^^^ - | | - | expected `u8`, found `u16` - | help: change the parameter type to match the trait: `fn(u8)` + | ^^^^^^^^^^^^^ expected `u8`, found `u16` | note: type in trait --> $DIR/issue-35869.rs:2:15 @@ -14,15 +11,16 @@ LL | fn foo(_: fn(u8) -> ()); | ^^^^^^^^^^^^ = note: expected signature `fn(fn(u8))` found signature `fn(fn(u16))` +help: change the parameter type to match the trait + | +LL | fn foo(_: fn(u8)) {} + | ~~~~~~ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/issue-35869.rs:13:15 | LL | fn bar(_: Option<u16>) {} - | ^^^^^^^^^^^ - | | - | expected `u8`, found `u16` - | help: change the parameter type to match the trait: `Option<u8>` + | ^^^^^^^^^^^ expected `u8`, found `u16` | note: type in trait --> $DIR/issue-35869.rs:3:15 @@ -31,15 +29,16 @@ LL | fn bar(_: Option<u8>); | ^^^^^^^^^^ = note: expected signature `fn(Option<u8>)` found signature `fn(Option<u16>)` +help: change the parameter type to match the trait + | +LL | fn bar(_: Option<u8>) {} + | ~~~~~~~~~~ error[E0053]: method `baz` has an incompatible type for trait --> $DIR/issue-35869.rs:15:15 | LL | fn baz(_: (u16, u16)) {} - | ^^^^^^^^^^ - | | - | expected `u8`, found `u16` - | help: change the parameter type to match the trait: `(u8, u16)` + | ^^^^^^^^^^ expected `u8`, found `u16` | note: type in trait --> $DIR/issue-35869.rs:4:15 @@ -48,15 +47,16 @@ LL | fn baz(_: (u8, u16)); | ^^^^^^^^^ = note: expected signature `fn((u8, _))` found signature `fn((u16, _))` +help: change the parameter type to match the trait + | +LL | fn baz(_: (u8, u16)) {} + | ~~~~~~~~~ error[E0053]: method `qux` has an incompatible type for trait --> $DIR/issue-35869.rs:17:17 | LL | fn qux() -> u16 { 5u16 } - | ^^^ - | | - | expected `u8`, found `u16` - | help: change the output type to match the trait: `u8` + | ^^^ expected `u8`, found `u16` | note: type in trait --> $DIR/issue-35869.rs:5:17 @@ -65,6 +65,10 @@ LL | fn qux() -> u8; | ^^ = note: expected signature `fn() -> u8` found signature `fn() -> u16` +help: change the output type to match the trait + | +LL | fn qux() -> u8 { 5u16 } + | ~~ error: aborting due to 4 previous errors diff --git a/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr b/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr index e0b23bd8110..c2029a5a1c8 100644 --- a/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr +++ b/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr @@ -17,10 +17,6 @@ note: required by a bound in `is_send` | LL | fn is_send(_: impl Send) {} | ^^^^ required by this bound in `is_send` -help: consider dereferencing here - | -LL | is_send(*foo()); - | + error: aborting due to 1 previous error diff --git a/tests/ui/traits/next-solver/typeck/receiver-self-ty-check-eq.rs b/tests/ui/traits/next-solver/typeck/receiver-self-ty-check-eq.rs new file mode 100644 index 00000000000..f8c8a17b7e5 --- /dev/null +++ b/tests/ui/traits/next-solver/typeck/receiver-self-ty-check-eq.rs @@ -0,0 +1,23 @@ +//@ compile-flags: -Znext-solver +//@ check-pass + +// Fixes a regression in `receiver_is_valid` in wfcheck where we were using +// `InferCtxt::can_eq` instead of processing alias-relate goals, leading to false +// positives, not deref'ing enough steps to check the receiver is valid. + +trait Mirror { + type Mirror: ?Sized; +} +impl<T: ?Sized> Mirror for T { + type Mirror = T; +} + +trait Foo { + fn foo(&self) {} +} + +impl Foo for <() as Mirror>::Mirror { + fn foo(&self) {} +} + +fn main() {} diff --git a/tests/ui/traits/upcast_soundness_bug.rs b/tests/ui/traits/upcast_soundness_bug.rs index 95b48cdf379..5eaa58f7efe 100644 --- a/tests/ui/traits/upcast_soundness_bug.rs +++ b/tests/ui/traits/upcast_soundness_bug.rs @@ -1,7 +1,8 @@ #![feature(trait_upcasting)] -//@ known-bug: #120222 -//@ check-pass -//! This will segfault at runtime. +//@ check-fail +// +// issue: <https://github.com/rust-lang/rust/pull/120222> +//! This would segfault at runtime. pub trait SupSupA { fn method(&self) {} @@ -56,6 +57,7 @@ pub fn user2() -> &'static dyn Trait<u8, u16> { fn main() { let p: *const dyn Trait<u8, u8> = &(); let p = p as *const dyn Trait<u8, u16>; // <- this is bad! + //~^ error: mismatched types let p = p as *const dyn Super<u16>; // <- this upcast accesses improper vtable entry // accessing from L__unnamed_2 the position for the 'Super<u16> vtable (pointer)', // thus reading 'null pointer for missing_method' diff --git a/tests/ui/traits/upcast_soundness_bug.stderr b/tests/ui/traits/upcast_soundness_bug.stderr new file mode 100644 index 00000000000..5864abcdb41 --- /dev/null +++ b/tests/ui/traits/upcast_soundness_bug.stderr @@ -0,0 +1,13 @@ +error[E0308]: mismatched types + --> $DIR/upcast_soundness_bug.rs:59:13 + | +LL | let p = p as *const dyn Trait<u8, u16>; // <- this is bad! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `u16` + | + = note: expected trait object `dyn Trait<u8, u8>` + found trait object `dyn Trait<u8, u16>` + = help: `dyn Trait<u8, u16>` implements `Trait` so you could box the found value and coerce it to the trait object `Box<dyn Trait>`, you will have to change the expected type as well + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/wrong-mul-method-signature.stderr b/tests/ui/traits/wrong-mul-method-signature.stderr index 91162cbc123..e30b61622ae 100644 --- a/tests/ui/traits/wrong-mul-method-signature.stderr +++ b/tests/ui/traits/wrong-mul-method-signature.stderr @@ -2,37 +2,40 @@ error[E0053]: method `mul` has an incompatible type for trait --> $DIR/wrong-mul-method-signature.rs:16:21 | LL | fn mul(self, s: &f64) -> Vec1 { - | ^^^^ - | | - | expected `f64`, found `&f64` - | help: change the parameter type to match the trait: `f64` + | ^^^^ expected `f64`, found `&f64` | = note: expected signature `fn(Vec1, _) -> Vec1` found signature `fn(Vec1, &_) -> Vec1` +help: change the parameter type to match the trait + | +LL | fn mul(self, s: f64) -> Vec1 { + | ~~~ error[E0053]: method `mul` has an incompatible type for trait --> $DIR/wrong-mul-method-signature.rs:33:21 | LL | fn mul(self, s: f64) -> Vec2 { - | ^^^ - | | - | expected `Vec2`, found `f64` - | help: change the parameter type to match the trait: `Vec2` + | ^^^ expected `Vec2`, found `f64` | = note: expected signature `fn(Vec2, Vec2) -> f64` found signature `fn(Vec2, f64) -> Vec2` +help: change the parameter type to match the trait + | +LL | fn mul(self, s: Vec2) -> Vec2 { + | ~~~~ error[E0053]: method `mul` has an incompatible type for trait --> $DIR/wrong-mul-method-signature.rs:52:29 | LL | fn mul(self, s: f64) -> f64 { - | ^^^ - | | - | expected `i32`, found `f64` - | help: change the output type to match the trait: `i32` + | ^^^ expected `i32`, found `f64` | = note: expected signature `fn(Vec3, _) -> i32` found signature `fn(Vec3, _) -> f64` +help: change the output type to match the trait + | +LL | fn mul(self, s: f64) -> i32 { + | ~~~ error[E0308]: mismatched types --> $DIR/wrong-mul-method-signature.rs:63:45 diff --git a/tests/ui/try-block/try-block-type-error.stderr b/tests/ui/try-block/try-block-type-error.stderr index 3e9a584a551..2cdb5fdee79 100644 --- a/tests/ui/try-block/try-block-type-error.stderr +++ b/tests/ui/try-block/try-block-type-error.stderr @@ -2,10 +2,12 @@ error[E0271]: type mismatch resolving `<Option<f32> as Try>::Output == {integer} --> $DIR/try-block-type-error.rs:10:9 | LL | 42 - | ^^ - | | - | expected `f32`, found integer - | help: use a float literal: `42.0` + | ^^ expected `f32`, found integer + | +help: use a float literal + | +LL | 42.0 + | ++ error[E0271]: type mismatch resolving `<Option<i32> as Try>::Output == ()` --> $DIR/try-block-type-error.rs:16:5 diff --git a/tests/ui/tuple/wrong_argument_ice-4.stderr b/tests/ui/tuple/wrong_argument_ice-4.stderr index 3c7d6699be2..10191faf7bf 100644 --- a/tests/ui/tuple/wrong_argument_ice-4.stderr +++ b/tests/ui/tuple/wrong_argument_ice-4.stderr @@ -6,16 +6,21 @@ LL | (|| {})(|| { LL | | LL | | let b = 1; LL | | }); - | | - - | | | - | |_____unexpected argument of type `{closure@$DIR/wrong_argument_ice-4.rs:2:13: 2:15}` - | help: remove the extra argument + | |_____- unexpected argument of type `{closure@$DIR/wrong_argument_ice-4.rs:2:13: 2:15}` | note: closure defined here --> $DIR/wrong_argument_ice-4.rs:2:6 | LL | (|| {})(|| { | ^^ +help: remove the extra argument + | +LL - (|| {})(|| { +LL - +LL - let b = 1; +LL - }); +LL + (|| {})(); + | error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/method_resolution3.current.stderr b/tests/ui/type-alias-impl-trait/method_resolution3.current.stderr index e992d059daf..09efd7a9e7e 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution3.current.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution3.current.stderr @@ -8,7 +8,7 @@ LL | fn bar(self: Bar<u32>) { = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) error[E0307]: invalid `self` parameter type: `&Bar<u32>` - --> $DIR/method_resolution3.rs:21:18 + --> $DIR/method_resolution3.rs:20:18 | LL | fn baz(self: &Bar<u32>) { | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/method_resolution3.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution3.next.stderr index 9272017cdf5..09efd7a9e7e 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution3.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution3.next.stderr @@ -1,15 +1,21 @@ -error[E0271]: type mismatch resolving `Foo == u32` +error[E0307]: invalid `self` parameter type: `Bar<u32>` --> $DIR/method_resolution3.rs:16:18 | LL | fn bar(self: Bar<u32>) { - | ^^^^^^^^ types differ + | ^^^^^^^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) -error[E0271]: type mismatch resolving `Foo == u32` - --> $DIR/method_resolution3.rs:21:18 +error[E0307]: invalid `self` parameter type: `&Bar<u32>` + --> $DIR/method_resolution3.rs:20:18 | LL | fn baz(self: &Bar<u32>) { - | ^^^^^^^^^ types differ + | ^^^^^^^^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +For more information about this error, try `rustc --explain E0307`. diff --git a/tests/ui/type-alias-impl-trait/method_resolution3.rs b/tests/ui/type-alias-impl-trait/method_resolution3.rs index 447f3144b82..0e6176bfe03 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution3.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution3.rs @@ -14,13 +14,11 @@ struct Bar<T>(T); impl Bar<Foo> { fn bar(self: Bar<u32>) { - //[current]~^ ERROR: invalid `self` parameter - //[next]~^^ ERROR: type mismatch resolving `Foo == u32` + //~^ ERROR: invalid `self` parameter self.foo() } fn baz(self: &Bar<u32>) { - //[current]~^ ERROR: invalid `self` parameter - //[next]~^^ ERROR: type mismatch resolving `Foo == u32` + //~^ ERROR: invalid `self` parameter self.foo() } } diff --git a/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr b/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr index 3a2ca18f890..8ffdb21f251 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr @@ -8,7 +8,7 @@ LL | fn foo(self: Bar<Foo>) { = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) error[E0307]: invalid `self` parameter type: `&Bar<Foo>` - --> $DIR/method_resolution4.rs:32:20 + --> $DIR/method_resolution4.rs:31:20 | LL | fn foomp(self: &Bar<Foo>) { | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr index 33ed2800ebe..8ffdb21f251 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr @@ -1,15 +1,21 @@ -error[E0271]: type mismatch resolving `u32 == Foo` +error[E0307]: invalid `self` parameter type: `Bar<Foo>` --> $DIR/method_resolution4.rs:27:18 | LL | fn foo(self: Bar<Foo>) { - | ^^^^^^^^ types differ + | ^^^^^^^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) -error[E0271]: type mismatch resolving `u32 == Foo` - --> $DIR/method_resolution4.rs:32:20 +error[E0307]: invalid `self` parameter type: `&Bar<Foo>` + --> $DIR/method_resolution4.rs:31:20 | LL | fn foomp(self: &Bar<Foo>) { - | ^^^^^^^^^ types differ + | ^^^^^^^^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +For more information about this error, try `rustc --explain E0307`. diff --git a/tests/ui/type-alias-impl-trait/method_resolution4.rs b/tests/ui/type-alias-impl-trait/method_resolution4.rs index 42ed04b3c30..f33b4e473ae 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution4.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution4.rs @@ -25,13 +25,11 @@ impl Bar<Foo> { impl Bar<u32> { fn foo(self: Bar<Foo>) { - //[current]~^ ERROR: invalid `self` parameter - //[next]~^^ ERROR: type mismatch resolving `u32 == Foo` + //~^ ERROR: invalid `self` parameter self.bar() } fn foomp(self: &Bar<Foo>) { - //[current]~^ ERROR: invalid `self` parameter - //[next]~^^ ERROR: type mismatch resolving `u32 == Foo` + //~^ ERROR: invalid `self` parameter self.bar() } } diff --git a/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903.rs b/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903.rs deleted file mode 100644 index 4f9d54737dc..00000000000 --- a/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903.rs +++ /dev/null @@ -1,29 +0,0 @@ -//@ check-pass - -// See https://doc.rust-lang.org/1.77.0/nightly-rustc/rustc_lint/opaque_hidden_inferred_bound/static.OPAQUE_HIDDEN_INFERRED_BOUND.html#example - -#![feature(type_alias_impl_trait)] -#![allow(dead_code)] - -trait Duh {} - -impl Duh for i32 {} - -trait Trait { - type Assoc: Duh; -} - -impl<R: Duh, F: FnMut() -> R> Trait for F { - type Assoc = R; -} - -type Sendable = impl Send; - -type Foo = impl Trait<Assoc = Sendable>; - //~^ WARNING opaque type `Foo` does not satisfy its associated type bounds - -fn foo() -> Foo { - || 42 -} - -fn main() {} diff --git a/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903.stderr b/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903.stderr deleted file mode 100644 index 68def454c7f..00000000000 --- a/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903.stderr +++ /dev/null @@ -1,13 +0,0 @@ -warning: opaque type `Foo` does not satisfy its associated type bounds - --> $DIR/tait-in-function-return-type-issue-101903.rs:22:23 - | -LL | type Assoc: Duh; - | --- this associated type bound is unsatisfied for `Sendable` -... -LL | type Foo = impl Trait<Assoc = Sendable>; - | ^^^^^^^^^^^^^^^^ - | - = note: `#[warn(opaque_hidden_inferred_bound)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.stderr b/tests/ui/type-alias-impl-trait/unnameable_type.stderr index f567b01d29a..5b331c5660d 100644 --- a/tests/ui/type-alias-impl-trait/unnameable_type.stderr +++ b/tests/ui/type-alias-impl-trait/unnameable_type.stderr @@ -5,10 +5,7 @@ LL | type MyPrivate = impl Sized; | ---------- the found opaque type LL | impl Trait for u32 { LL | fn dont_define_this(private: MyPrivate) { - | ^^^^^^^^^ - | | - | expected `Private`, found opaque type - | help: change the parameter type to match the trait: `Private` + | ^^^^^^^^^ expected `Private`, found opaque type | note: type in trait --> $DIR/unnameable_type.rs:10:39 @@ -17,6 +14,10 @@ LL | fn dont_define_this(_private: Private) {} | ^^^^^^^ = note: expected signature `fn(Private)` found signature `fn(MyPrivate)` +help: change the parameter type to match the trait + | +LL | fn dont_define_this(private: Private) { + | ~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/type/subtyping-opaque-type.rs b/tests/ui/type/subtyping-opaque-type.rs deleted file mode 100644 index e17114a3647..00000000000 --- a/tests/ui/type/subtyping-opaque-type.rs +++ /dev/null @@ -1,19 +0,0 @@ -//@ check-pass -//@ compile-flags: -Zvalidate-mir -trait Duh {} - -impl Duh for i32 {} - -trait Trait { - type Assoc: Duh; -} - -impl<R: Duh, F: FnMut() -> R> Trait for F { - type Assoc = R; -} - -fn foo() -> impl Trait<Assoc = impl Send> { - || 42 -} - -fn main() {} diff --git a/tests/ui/type/type-ascription-instead-of-initializer.stderr b/tests/ui/type/type-ascription-instead-of-initializer.stderr index efa917334bf..224ff6e7404 100644 --- a/tests/ui/type/type-ascription-instead-of-initializer.stderr +++ b/tests/ui/type/type-ascription-instead-of-initializer.stderr @@ -11,13 +11,15 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/type-ascription-instead-of-initializer.rs:2:12 | LL | let x: Vec::with_capacity(10, 20); - | ^^^^^^^^^^^^^^^^^^ ---- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^^^^^^^^^^^^ -- unexpected argument of type `{integer}` | note: associated function defined here --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL +help: remove the extra argument + | +LL - let x: Vec::with_capacity(10, 20); +LL + let x: Vec::with_capacity(10); + | error: aborting due to 2 previous errors diff --git a/tests/ui/type/type-parameter-defaults-referencing-Self.stderr b/tests/ui/type/type-parameter-defaults-referencing-Self.stderr index 16d08b26722..c81405f03f8 100644 --- a/tests/ui/type/type-parameter-defaults-referencing-Self.stderr +++ b/tests/ui/type/type-parameter-defaults-referencing-Self.stderr @@ -5,9 +5,13 @@ LL | trait Foo<T=Self> { | ----------------- type parameter `T` must be specified for this ... LL | fn foo(x: &dyn Foo) { } - | ^^^ help: set the type parameter to the desired type: `Foo<T>` + | ^^^ | = note: because of the default `Self` reference, type parameters must be specified on object types +help: set the type parameter to the desired type + | +LL | fn foo(x: &dyn Foo<T>) { } + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/typeck/ice-with-expr-not-struct-127332.rs b/tests/ui/typeck/ice-with-expr-not-struct-127332.rs new file mode 100644 index 00000000000..f3ea360e7e9 --- /dev/null +++ b/tests/ui/typeck/ice-with-expr-not-struct-127332.rs @@ -0,0 +1,15 @@ +// Regression test for ICE #127332 + +// Tests that we do not ICE when a with expr is +// not a struct but something else like an enum + +fn main() { + let x = || { + enum Foo { + A { x: u32 }, + } + let orig = Foo::A { x: 5 }; + Foo::A { x: 6, ..orig }; + //~^ ERROR functional record update syntax requires a struct + }; +} diff --git a/tests/ui/typeck/ice-with-expr-not-struct-127332.stderr b/tests/ui/typeck/ice-with-expr-not-struct-127332.stderr new file mode 100644 index 00000000000..446f49e8639 --- /dev/null +++ b/tests/ui/typeck/ice-with-expr-not-struct-127332.stderr @@ -0,0 +1,9 @@ +error[E0436]: functional record update syntax requires a struct + --> $DIR/ice-with-expr-not-struct-127332.rs:12:26 + | +LL | Foo::A { x: 6, ..orig }; + | ^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0436`. diff --git a/tests/ui/typeck/issue-53712.rs b/tests/ui/typeck/issue-53712.rs index 2353904d79d..49db4fa306a 100644 --- a/tests/ui/typeck/issue-53712.rs +++ b/tests/ui/typeck/issue-53712.rs @@ -5,5 +5,5 @@ fn main() { arr.0; //~^ ERROR no field `0` on type `[{integer}; 5]` [E0609] //~| HELP instead of using tuple indexing, use array indexing - //~| SUGGESTION arr[0] + //~| SUGGESTION [ } diff --git a/tests/ui/typeck/issue-53712.stderr b/tests/ui/typeck/issue-53712.stderr index ec31766324b..ffaf5cde1d7 100644 --- a/tests/ui/typeck/issue-53712.stderr +++ b/tests/ui/typeck/issue-53712.stderr @@ -2,10 +2,12 @@ error[E0609]: no field `0` on type `[{integer}; 5]` --> $DIR/issue-53712.rs:5:9 | LL | arr.0; - | ----^ - | | | - | | unknown field - | help: instead of using tuple indexing, use array indexing: `arr[0]` + | ^ unknown field + | +help: instead of using tuple indexing, use array indexing + | +LL | arr[0]; + | ~ + error: aborting due to 1 previous error diff --git a/tests/ui/typeck/issue-91328.stderr b/tests/ui/typeck/issue-91328.stderr index f2f407bcaff..f9016400fd7 100644 --- a/tests/ui/typeck/issue-91328.stderr +++ b/tests/ui/typeck/issue-91328.stderr @@ -1,38 +1,46 @@ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/issue-91328.rs:10:12 | -LL | match r { - | - help: consider using `as_deref` here: `r.as_deref()` -LL | LL | Ok([a, b]) => a + b, | ^^^^^^ pattern cannot match with input type `Vec<i32>` + | +help: consider using `as_deref` here + | +LL | match r.as_deref() { + | +++++++++++ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/issue-91328.rs:20:14 | -LL | match o { - | - help: consider using `as_deref` here: `o.as_deref()` -LL | LL | Some([a, b]) => a + b, | ^^^^^^ pattern cannot match with input type `Vec<i32>` + | +help: consider using `as_deref` here + | +LL | match o.as_deref() { + | +++++++++++ error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/issue-91328.rs:30:9 | -LL | match v { - | - help: consider slicing here: `v[..]` -LL | LL | [a, b] => a + b, | ^^^^^^ pattern cannot match with input type `Vec<i32>` + | +help: consider slicing here + | +LL | match v[..] { + | ++++ error[E0529]: expected an array or slice, found `Box<[i32; 2]>` --> $DIR/issue-91328.rs:40:14 | -LL | match a { - | - help: consider using `as_deref` here: `a.as_deref()` -LL | LL | Some([a, b]) => a + b, | ^^^^^^ pattern cannot match with input type `Box<[i32; 2]>` + | +help: consider using `as_deref` here + | +LL | match a.as_deref() { + | +++++++++++ error: aborting due to 4 previous errors diff --git a/tests/ui/typeck/mismatched-map-under-self.stderr b/tests/ui/typeck/mismatched-map-under-self.stderr index 322bf349f92..59de00a58bb 100644 --- a/tests/ui/typeck/mismatched-map-under-self.stderr +++ b/tests/ui/typeck/mismatched-map-under-self.stderr @@ -2,10 +2,7 @@ error[E0053]: method `values` has an incompatible type for trait --> $DIR/mismatched-map-under-self.rs:10:15 | LL | fn values(self) -> Self::Values { - | ^^^^ - | | - | expected `&Option<T>`, found `Option<T>` - | help: change the self-receiver type to match the trait: `&self` + | ^^^^ expected `&Option<T>`, found `Option<T>` | note: type in trait --> $DIR/mismatched-map-under-self.rs:4:15 @@ -14,6 +11,10 @@ LL | fn values(&self) -> Self::Values; | ^^^^^ = note: expected signature `fn(&Option<_>)` found signature `fn(Option<_>)` +help: change the self-receiver type to match the trait + | +LL | fn values(&self) -> Self::Values { + | ~~~~~ error[E0631]: type mismatch in function arguments --> $DIR/mismatched-map-under-self.rs:12:18 diff --git a/tests/ui/typeck/ptr-null-mutability-suggestions.stderr b/tests/ui/typeck/ptr-null-mutability-suggestions.stderr index b615d9fb45c..2912977a461 100644 --- a/tests/ui/typeck/ptr-null-mutability-suggestions.stderr +++ b/tests/ui/typeck/ptr-null-mutability-suggestions.stderr @@ -2,10 +2,8 @@ error[E0308]: mismatched types --> $DIR/ptr-null-mutability-suggestions.rs:9:24 | LL | expecting_null_mut(ptr::null()); - | ------------------ ^^^^^^^^^^^ - | | | - | | types differ in mutability - | | help: consider using `core::ptr::null_mut` instead: `core::ptr::null_mut()` + | ------------------ ^^^^^^^^^^^ types differ in mutability + | | | arguments to this function are incorrect | = note: expected raw pointer `*mut u8` @@ -15,6 +13,10 @@ note: function defined here | LL | fn expecting_null_mut(_: *mut u8) {} | ^^^^^^^^^^^^^^^^^^ ---------- +help: consider using `core::ptr::null_mut` instead + | +LL | expecting_null_mut(core::ptr::null_mut()); + | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/typeck/remove-extra-argument.stderr b/tests/ui/typeck/remove-extra-argument.stderr index 9557c41457d..4bab2959651 100644 --- a/tests/ui/typeck/remove-extra-argument.stderr +++ b/tests/ui/typeck/remove-extra-argument.stderr @@ -2,16 +2,18 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/remove-extra-argument.rs:6:5 | LL | l(vec![], vec![]) - | ^ -------- - | | | - | | unexpected argument of type `Vec<_>` - | help: remove the extra argument + | ^ ------ unexpected argument of type `Vec<_>` | note: function defined here --> $DIR/remove-extra-argument.rs:3:4 | LL | fn l(_a: Vec<u8>) {} | ^ ----------- +help: remove the extra argument + | +LL - l(vec![], vec![]) +LL + l(vec![]) + | error: aborting due to 1 previous error diff --git a/tests/ui/typeck/struct-enum-wrong-args.stderr b/tests/ui/typeck/struct-enum-wrong-args.stderr index 57cbd1d2005..d005eca841e 100644 --- a/tests/ui/typeck/struct-enum-wrong-args.stderr +++ b/tests/ui/typeck/struct-enum-wrong-args.stderr @@ -2,13 +2,15 @@ error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:6:13 | LL | let _ = Some(3, 2); - | ^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^ - unexpected argument of type `{integer}` | note: tuple variant defined here --> $SRC_DIR/core/src/option.rs:LL:COL +help: remove the extra argument + | +LL - let _ = Some(3, 2); +LL + let _ = Some(3); + | error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:7:13 @@ -59,16 +61,18 @@ error[E0061]: this struct takes 1 argument but 2 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:10:13 | LL | let _ = Wrapper(5, 2); - | ^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^ - unexpected argument of type `{integer}` | note: tuple struct defined here --> $DIR/struct-enum-wrong-args.rs:2:8 | LL | struct Wrapper(i32); | ^^^^^^^ +help: remove the extra argument + | +LL - let _ = Wrapper(5, 2); +LL + let _ = Wrapper(5); + | error[E0061]: this struct takes 2 arguments but 0 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:11:13 @@ -106,16 +110,18 @@ error[E0061]: this struct takes 2 arguments but 3 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:13:13 | LL | let _ = DoubleWrapper(5, 2, 7); - | ^^^^^^^^^^^^^ --- - | | | - | | unexpected argument of type `{integer}` - | help: remove the extra argument + | ^^^^^^^^^^^^^ - unexpected argument of type `{integer}` | note: tuple struct defined here --> $DIR/struct-enum-wrong-args.rs:3:8 | LL | struct DoubleWrapper(i32, i32); | ^^^^^^^^^^^^^ +help: remove the extra argument + | +LL - let _ = DoubleWrapper(5, 2, 7); +LL + let _ = DoubleWrapper(5, 2); + | error: aborting due to 8 previous errors diff --git a/tests/ui/ufcs/ufcs-explicit-self-bad.stderr b/tests/ui/ufcs/ufcs-explicit-self-bad.stderr index c48d094daea..2a8c4edbdb5 100644 --- a/tests/ui/ufcs/ufcs-explicit-self-bad.stderr +++ b/tests/ui/ufcs/ufcs-explicit-self-bad.stderr @@ -2,10 +2,7 @@ error[E0053]: method `dummy2` has an incompatible type for trait --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar<T>) {} - | ------^^^^^^^ - | | | - | | expected `&'a Bar<T>`, found `Bar<T>` - | help: change the self-receiver type to match the trait: `&self` + | ^^^^^^^ expected `&'a Bar<T>`, found `Bar<T>` | note: type in trait --> $DIR/ufcs-explicit-self-bad.rs:31:15 @@ -14,6 +11,10 @@ LL | fn dummy2(&self); | ^^^^^ = note: expected signature `fn(&&'a Bar<_>)` found signature `fn(&Bar<_>)` +help: change the self-receiver type to match the trait + | +LL | fn dummy2(&self) {} + | ~~~~~ error[E0307]: invalid `self` parameter type: `isize` --> $DIR/ufcs-explicit-self-bad.rs:8:18 diff --git a/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr b/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr index ad5451ced55..04f9ab246b3 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr @@ -1,73 +1,90 @@ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:9:13 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` LL | move || x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:10:17 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -LL | move || x = 1; LL | move || set(&mut x); | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:11:13 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | move || x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:12:17 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | move || set(&mut x); | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:13:8 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | || x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:14:12 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | || set(&mut x); | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0594]: cannot assign to `x`, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:15:8 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | || x = 1; | ^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/unboxed-closure-immutable-capture.rs:16:12 | -LL | let x = 0; - | - help: consider changing this to be mutable: `mut x` -... LL | || set(&mut x); | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut x = 0; + | +++ error: aborting due to 8 previous errors diff --git a/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr b/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr index 5c93ed6d7f7..07c66276eaf 100644 --- a/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr +++ b/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr @@ -1,13 +1,16 @@ error[E0596]: cannot borrow `tick1` as mutable, as it is not declared as mutable --> $DIR/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs:16:9 | -LL | let tick1 = || { - | ----- help: consider changing this to be mutable: `mut tick1` LL | counter += 1; | ------- calling `tick1` requires mutable binding due to mutable borrow of `counter` ... LL | tick1(); | ^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut tick1 = || { + | +++ error[E0596]: cannot borrow `tick2` as mutable, as it is not declared as mutable --> $DIR/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs:19:5 diff --git a/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr b/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr index 26f97b51913..80caddb2a11 100644 --- a/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr +++ b/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr @@ -1,29 +1,35 @@ error[E0594]: cannot assign to `n`, as it is not declared as mutable --> $DIR/unboxed-closures-mutate-upvar.rs:15:9 | -LL | let n = 0; - | - help: consider changing this to be mutable: `mut n` -LL | let mut f = to_fn_mut(|| { LL | n += 1; | ^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut n = 0; + | +++ error[E0594]: cannot assign to `n`, as it is not declared as mutable --> $DIR/unboxed-closures-mutate-upvar.rs:32:9 | -LL | let n = 0; - | - help: consider changing this to be mutable: `mut n` -... LL | n += 1; | ^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut n = 0; + | +++ error[E0594]: cannot assign to `n`, as it is not declared as mutable --> $DIR/unboxed-closures-mutate-upvar.rs:46:9 | -LL | let n = 0; - | - help: consider changing this to be mutable: `mut n` -LL | let mut f = to_fn(move || { LL | n += 1; | ^^^^^^ cannot assign + | +help: consider changing this to be mutable + | +LL | let mut n = 0; + | +++ error[E0594]: cannot assign to `n`, as it is a captured variable in a `Fn` closure --> $DIR/unboxed-closures-mutate-upvar.rs:53:9 diff --git a/tests/ui/unsafe/unsafe-fn-autoderef.stderr b/tests/ui/unsafe/unsafe-fn-autoderef.stderr index c3ab8020222..c19028ac866 100644 --- a/tests/ui/unsafe/unsafe-fn-autoderef.stderr +++ b/tests/ui/unsafe/unsafe-fn-autoderef.stderr @@ -2,10 +2,12 @@ error[E0609]: no field `f` on type `*const Rec` --> $DIR/unsafe-fn-autoderef.rs:19:14 | LL | return p.f; - | --^ - | | | - | | unknown field - | help: `p` is a raw pointer; try dereferencing it: `(*p).f` + | ^ unknown field + | +help: `p` is a raw pointer; try dereferencing it + | +LL | return (*p).f; + | ++ + error: aborting due to 1 previous error diff --git a/tests/ui/unsigned-literal-negation.stderr b/tests/ui/unsigned-literal-negation.stderr index 0aaa8c3b72f..b0a730477a1 100644 --- a/tests/ui/unsigned-literal-negation.stderr +++ b/tests/ui/unsigned-literal-negation.stderr @@ -2,34 +2,37 @@ error[E0600]: cannot apply unary operator `-` to type `usize` --> $DIR/unsigned-literal-negation.rs:2:13 | LL | let x = -1 as usize; - | ^^ - | | - | cannot apply unary operator `-` - | help: you may have meant the maximum value of `usize`: `usize::MAX` + | ^^ cannot apply unary operator `-` | = note: unsigned values cannot be negated +help: you may have meant the maximum value of `usize` + | +LL | let x = usize::MAX; + | ~~~~~~~~~~ error[E0600]: cannot apply unary operator `-` to type `usize` --> $DIR/unsigned-literal-negation.rs:3:13 | LL | let x = (-1) as usize; - | ^^^^ - | | - | cannot apply unary operator `-` - | help: you may have meant the maximum value of `usize`: `usize::MAX` + | ^^^^ cannot apply unary operator `-` | = note: unsigned values cannot be negated +help: you may have meant the maximum value of `usize` + | +LL | let x = usize::MAX; + | ~~~~~~~~~~ error[E0600]: cannot apply unary operator `-` to type `u32` --> $DIR/unsigned-literal-negation.rs:4:18 | LL | let x: u32 = -1; - | ^^ - | | - | cannot apply unary operator `-` - | help: you may have meant the maximum value of `u32`: `u32::MAX` + | ^^ cannot apply unary operator `-` | = note: unsigned values cannot be negated +help: you may have meant the maximum value of `u32` + | +LL | let x: u32 = u32::MAX; + | ~~~~~~~~ error: aborting due to 3 previous errors |
