diff options
Diffstat (limited to 'tests')
868 files changed, 19572 insertions, 4515 deletions
diff --git a/tests/codegen/debuginfo-inline-callsite-location.rs b/tests/codegen/debuginfo-inline-callsite-location.rs new file mode 100644 index 00000000000..b1475ee7931 --- /dev/null +++ b/tests/codegen/debuginfo-inline-callsite-location.rs @@ -0,0 +1,28 @@ +// compile-flags: -g -O + +// Check that each inline call site for the same function uses the same "sub-program" so that LLVM +// can correctly merge the debug info if it merges the inlined code (e.g., for merging of tail +// calls to panic. + +// CHECK: tail call void @_ZN4core9panicking5panic17h{{([0-9a-z]{16})}}E +// CHECK-SAME: !dbg ![[#first_dbg:]] +// CHECK: tail call void @_ZN4core9panicking5panic17h{{([0-9a-z]{16})}}E +// CHECK-SAME: !dbg ![[#second_dbg:]] + +// CHECK-DAG: ![[#func_dbg:]] = distinct !DISubprogram(name: "unwrap<i32>" +// CHECK-DAG: ![[#first_scope:]] = distinct !DILexicalBlock(scope: ![[#func_dbg]], +// CHECK: ![[#second_scope:]] = distinct !DILexicalBlock(scope: ![[#func_dbg]], +// CHECK: ![[#first_dbg]] = !DILocation(line: [[#]] +// CHECK-SAME: scope: ![[#first_scope]], inlinedAt: ![[#]]) +// CHECK: ![[#second_dbg]] = !DILocation(line: [[#]] +// CHECK-SAME: scope: ![[#second_scope]], inlinedAt: ![[#]]) + +#![crate_type = "lib"] + +#[no_mangle] +extern "C" fn add_numbers(x: &Option<i32>, y: &Option<i32>) -> i32 { + let x1 = x.unwrap(); + let y1 = y.unwrap(); + + x1 + y1 +} diff --git a/tests/codegen/issues/issue-115385-llvm-jump-threading.rs b/tests/codegen/issues/issue-115385-llvm-jump-threading.rs new file mode 100644 index 00000000000..142e3596d96 --- /dev/null +++ b/tests/codegen/issues/issue-115385-llvm-jump-threading.rs @@ -0,0 +1,46 @@ +// compile-flags: -O -Ccodegen-units=1 + +#![crate_type = "lib"] + +#[repr(i64)] +pub enum Boolean { + False = 0, + True = 1, +} + +impl Clone for Boolean { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for Boolean {} + +extern "C" { + fn set_value(foo: *mut i64); + fn bar(); +} + +pub fn foo(x: bool) { + let mut foo = core::mem::MaybeUninit::<i64>::uninit(); + unsafe { + set_value(foo.as_mut_ptr()); + } + + if x { + let l1 = unsafe { *foo.as_mut_ptr().cast::<Boolean>() }; + if matches!(l1, Boolean::False) { + unsafe { + *foo.as_mut_ptr() = 0; + } + } + } + + let l2 = unsafe { *foo.as_mut_ptr() }; + if l2 == 2 { + // CHECK: call void @bar + unsafe { + bar(); + } + } +} diff --git a/tests/codegen/lib-optimizations/iter-sum.rs b/tests/codegen/lib-optimizations/iter-sum.rs new file mode 100644 index 00000000000..ff7ca6ef6c1 --- /dev/null +++ b/tests/codegen/lib-optimizations/iter-sum.rs @@ -0,0 +1,15 @@ +// ignore-debug: the debug assertions get in the way +// compile-flags: -O +// only-x86_64 (vectorization varies between architectures) +#![crate_type = "lib"] + + +// Ensure that slice + take + sum gets vectorized. +// Currently this relies on the slice::Iter::try_fold implementation +// CHECK-LABEL: @slice_take_sum +#[no_mangle] +pub fn slice_take_sum(s: &[u64], l: usize) -> u64 { + // CHECK: vector.body: + // CHECK: ret + s.iter().take(l).sum() +} diff --git a/tests/codegen/repr/transparent.rs b/tests/codegen/repr/transparent.rs index b140fc719da..c5974248bb3 100644 --- a/tests/codegen/repr/transparent.rs +++ b/tests/codegen/repr/transparent.rs @@ -43,7 +43,6 @@ pub extern "C" fn test_WithZst(_: WithZst) -> WithZst { loop {} } #[repr(transparent)] pub struct WithZeroSizedArray(*const f32, [i8; 0]); -// Apparently we use i32* when newtype-unwrapping f32 pointers. Whatever. // CHECK: define{{.*}}ptr @test_WithZeroSizedArray(ptr noundef %_1) #[no_mangle] pub extern "C" fn test_WithZeroSizedArray(_: WithZeroSizedArray) -> WithZeroSizedArray { loop {} } diff --git a/tests/codegen/sanitizer/address-sanitizer-globals-tracking.rs b/tests/codegen/sanitizer/address-sanitizer-globals-tracking.rs new file mode 100644 index 00000000000..a70ef7751b6 --- /dev/null +++ b/tests/codegen/sanitizer/address-sanitizer-globals-tracking.rs @@ -0,0 +1,43 @@ +// Verifies that AddressSanitizer symbols show up as expected in LLVM IR with `-Zsanitizer`. +// This is a regression test for https://github.com/rust-lang/rust/issues/113404 +// +// Notes about the `compile-flags` below: +// +// * The original issue only reproed with LTO - this is why this angle has +// extra test coverage via different `revisions` +// * To observe the failure/repro at LLVM-IR level we need to use `staticlib` +// which necessitates `-C prefer-dynamic=false` - without the latter flag, +// we would have run into "cannot prefer dynamic linking when performing LTO". +// +// The test is restricted to `only-linux`, because the sanitizer-related instrumentation is target +// specific. In particular, `___asan_globals_registered` is only used in the +// `InstrumentGlobalsELF` and `InstrumentGlobalsMachO` code paths. The `only-linux` filter is +// narrower than really needed (i.e. narrower than ELF-or-MachO), but this seems ok - having a +// linux-only regression test should be sufficient here. +// +// needs-sanitizer-address +// only-linux +// +// revisions:ASAN ASAN-FAT-LTO +//[ASAN] compile-flags: -Zsanitizer=address +//[ASAN-FAT-LTO] compile-flags: -Zsanitizer=address -Cprefer-dynamic=false -Clto=fat + +#![crate_type="staticlib"] + +// The test below mimics `CACHED_POW10` from `library/core/src/num/flt2dec/strategy/grisu.rs` which +// (because of incorrect handling of `___asan_globals_registered` during LTO) was incorrectly +// reported as an ODR violation in https://crbug.com/1459233#c1. Before this bug was fixed, +// `___asan_globals_registered` would show up as `internal global i64` rather than `common hidden +// global i64`. (The test expectations ignore the exact type because on `arm-android` the type +// is `i32` rather than `i64`.) +// +// CHECK: @___asan_globals_registered = common hidden global +// CHECK: @__start_asan_globals = extern_weak hidden global +// CHECK: @__stop_asan_globals = extern_weak hidden global +#[no_mangle] +pub static CACHED_POW10: [(u64, i16, i16); 4] = [ + (0xe61acf033d1a45df, -1087, -308), + (0xab70fe17c79ac6ca, -1060, -300), + (0xff77b1fcbebcdc4f, -1034, -292), + (0xbe5691ef416bd60c, -1007, -284), +]; diff --git a/tests/codegen/slice-as_chunks.rs b/tests/codegen/slice-as_chunks.rs index 48e3f73fc86..efac9f3d68d 100644 --- a/tests/codegen/slice-as_chunks.rs +++ b/tests/codegen/slice-as_chunks.rs @@ -22,9 +22,9 @@ pub fn chunks4(x: &[u8]) -> &[[u8; 4]] { // CHECK-LABEL: @chunks4_with_remainder #[no_mangle] pub fn chunks4_with_remainder(x: &[u8]) -> (&[[u8; 4]], &[u8]) { - // CHECK: and i64 %x.1, -4 - // CHECK: and i64 %x.1, 3 - // CHECK: lshr exact + // CHECK-DAG: and i64 %x.1, -4 + // CHECK-DAG: and i64 %x.1, 3 + // CHECK-DAG: lshr // CHECK-NOT: mul // CHECK-NOT: udiv // CHECK-NOT: urem diff --git a/tests/codegen/slice-iter-nonnull.rs b/tests/codegen/slice-iter-nonnull.rs index f7d164bc856..8749226d401 100644 --- a/tests/codegen/slice-iter-nonnull.rs +++ b/tests/codegen/slice-iter-nonnull.rs @@ -100,13 +100,13 @@ pub fn slice_iter_is_empty(it: &std::slice::Iter<'_, u32>) -> bool { // CHECK-LABEL: @slice_iter_len #[no_mangle] pub fn slice_iter_len(it: &std::slice::Iter<'_, u32>) -> usize { - // CHECK: %[[START:.+]] = load ptr, ptr %it, - // CHECK-SAME: !nonnull - // CHECK-SAME: !noundef // CHECK: %[[ENDP:.+]] = getelementptr{{.+}}ptr %it,{{.+}} 1 // CHECK: %[[END:.+]] = load ptr, ptr %[[ENDP]] // CHECK-SAME: !nonnull // CHECK-SAME: !noundef + // CHECK: %[[START:.+]] = load ptr, ptr %it, + // CHECK-SAME: !nonnull + // CHECK-SAME: !noundef // CHECK: ptrtoint // CHECK: ptrtoint diff --git a/tests/coverage-map/README.md b/tests/coverage-map/README.md new file mode 100644 index 00000000000..60d1352cd64 --- /dev/null +++ b/tests/coverage-map/README.md @@ -0,0 +1,13 @@ +The tests in `./status-quo` were copied from `tests/run-coverage` in order to +capture the current behavior of the instrumentor on non-trivial programs. +The actual mappings have not been closely inspected. + +## Maintenance note + +These tests can be sensitive to small changes in MIR spans or MIR control flow, +especially in HIR-to-MIR lowering or MIR optimizations. + +If you haven't touched the coverage code directly, and the `run-coverage` test +suite still works, then it should usually be OK to just `--bless` these +coverage mapping tests as necessary, without worrying too much about the exact +changes. diff --git a/tests/coverage-map/if.cov-map b/tests/coverage-map/if.cov-map new file mode 100644 index 00000000000..3cedb5ffbec --- /dev/null +++ b/tests/coverage-map/if.cov-map @@ -0,0 +1,15 @@ +Function name: if::main +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 03, 01, 02, 0c, 05, 02, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 3, 1) to (start + 2, 12) +- Code(Counter(1)) at (prev + 2, 13) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 1, 2) + = (c1 + (c0 - c1)) + diff --git a/tests/coverage-map/if.rs b/tests/coverage-map/if.rs new file mode 100644 index 00000000000..ed3f69bdc98 --- /dev/null +++ b/tests/coverage-map/if.rs @@ -0,0 +1,9 @@ +// compile-flags: --edition=2021 + +fn main() { + let cond = std::env::args().len() == 1; + if cond { + println!("true"); + } + println!("done"); +} diff --git a/tests/coverage-map/long_and_wide.cov-map b/tests/coverage-map/long_and_wide.cov-map new file mode 100644 index 00000000000..97aebf9b18a --- /dev/null +++ b/tests/coverage-map/long_and_wide.cov-map @@ -0,0 +1,32 @@ +Function name: long_and_wide::far_function +Raw bytes (10): 0x[01, 01, 00, 01, 01, 96, 01, 01, 00, 15] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 150, 1) to (start + 0, 21) + +Function name: long_and_wide::long_function +Raw bytes (10): 0x[01, 01, 00, 01, 01, 10, 01, 84, 01, 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 + 16, 1) to (start + 132, 2) + +Function name: long_and_wide::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 01, 04, 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 + 7, 1) to (start + 4, 2) + +Function name: long_and_wide::wide_function +Raw bytes (10): 0x[01, 01, 00, 01, 01, 0e, 01, 00, 8b, 01] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 14, 1) to (start + 0, 139) + diff --git a/tests/coverage-map/long_and_wide.rs b/tests/coverage-map/long_and_wide.rs new file mode 100644 index 00000000000..a7cbcd48027 --- /dev/null +++ b/tests/coverage-map/long_and_wide.rs @@ -0,0 +1,150 @@ +// compile-flags: --edition=2021 +// ignore-tidy-linelength + +// This file deliberately contains line and column numbers larger than 127, +// to verify that `coverage-dump`'s ULEB128 parser can handle them. + +fn main() { + wide_function(); + long_function(); + far_function(); +} + +#[rustfmt::skip] +fn wide_function() { /* */ (); } + +fn long_function() { + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // +} + +fn far_function() {} diff --git a/tests/coverage-map/status-quo/abort.cov-map b/tests/coverage-map/status-quo/abort.cov-map new file mode 100644 index 00000000000..45d3795eff8 --- /dev/null +++ b/tests/coverage-map/status-quo/abort.cov-map @@ -0,0 +1,57 @@ +Function name: abort::main +Raw bytes (105): 0x[01, 01, 12, 01, 47, 05, 09, 03, 0d, 42, 11, 03, 0d, 11, 3e, 42, 11, 03, 0d, 3b, 15, 11, 3e, 42, 11, 03, 0d, 15, 36, 3b, 15, 11, 3e, 42, 11, 03, 0d, 05, 09, 0d, 01, 0d, 01, 01, 1b, 03, 02, 0b, 00, 18, 42, 01, 0c, 00, 19, 11, 00, 1a, 02, 0a, 3e, 02, 0a, 00, 0b, 3b, 02, 0c, 00, 19, 15, 00, 1a, 00, 31, 36, 00, 31, 00, 32, 33, 04, 0c, 00, 19, 05, 00, 1a, 00, 31, 09, 00, 31, 00, 32, 47, 01, 09, 00, 17, 0d, 02, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 18 +- expression 0 operands: lhs = Counter(0), rhs = Expression(17, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Expression(16, Sub), rhs = Counter(4) +- expression 4 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 5 operands: lhs = Counter(4), rhs = Expression(15, Sub) +- expression 6 operands: lhs = Expression(16, Sub), rhs = Counter(4) +- expression 7 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 8 operands: lhs = Expression(14, Add), rhs = Counter(5) +- expression 9 operands: lhs = Counter(4), rhs = Expression(15, Sub) +- expression 10 operands: lhs = Expression(16, Sub), rhs = Counter(4) +- expression 11 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 12 operands: lhs = Counter(5), rhs = Expression(13, Sub) +- expression 13 operands: lhs = Expression(14, Add), rhs = Counter(5) +- expression 14 operands: lhs = Counter(4), rhs = Expression(15, Sub) +- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(4) +- expression 16 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 17 operands: lhs = Counter(1), rhs = Counter(2) +Number of file 0 mappings: 13 +- Code(Counter(0)) at (prev + 13, 1) to (start + 1, 27) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24) + = (c0 + (c1 + c2)) +- Code(Expression(16, Sub)) at (prev + 1, 12) to (start + 0, 25) + = ((c0 + (c1 + c2)) - c3) +- Code(Counter(4)) at (prev + 0, 26) to (start + 2, 10) +- Code(Expression(15, Sub)) at (prev + 2, 10) to (start + 0, 11) + = (((c0 + (c1 + c2)) - c3) - c4) +- Code(Expression(14, Add)) at (prev + 2, 12) to (start + 0, 25) + = (c4 + (((c0 + (c1 + c2)) - c3) - c4)) +- Code(Counter(5)) at (prev + 0, 26) to (start + 0, 49) +- Code(Expression(13, Sub)) at (prev + 0, 49) to (start + 0, 50) + = ((c4 + (((c0 + (c1 + c2)) - c3) - c4)) - c5) +- Code(Expression(12, Add)) at (prev + 4, 12) to (start + 0, 25) + = (c5 + ((c4 + (((c0 + (c1 + c2)) - c3) - c4)) - c5)) +- Code(Counter(1)) at (prev + 0, 26) to (start + 0, 49) +- Code(Counter(2)) at (prev + 0, 49) to (start + 0, 50) +- Code(Expression(17, Add)) at (prev + 1, 9) to (start + 0, 23) + = (c1 + c2) +- Code(Counter(3)) at (prev + 2, 5) to (start + 1, 2) + +Function name: abort::might_abort +Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 01, 14, 05, 02, 09, 01, 24, 02, 02, 0c, 03, 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: 3 +- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 20) +- Code(Counter(1)) at (prev + 2, 9) to (start + 1, 36) +- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 3, 2) + = (c0 - c1) + diff --git a/tests/coverage-map/status-quo/abort.rs b/tests/coverage-map/status-quo/abort.rs new file mode 100644 index 00000000000..98264bdc1af --- /dev/null +++ b/tests/coverage-map/status-quo/abort.rs @@ -0,0 +1,66 @@ +#![feature(c_unwind)] +#![allow(unused_assignments)] + +extern "C" fn might_abort(should_abort: bool) { + if should_abort { + println!("aborting..."); + panic!("panics and aborts"); + } else { + println!("Don't Panic"); + } +} + +fn main() -> Result<(), u8> { + let mut countdown = 10; + while countdown > 0 { + if countdown < 5 { + might_abort(false); + } + // See discussion (below the `Notes` section) on coverage results for the closing brace. + if countdown < 5 { might_abort(false); } // Counts for different regions on one line. + // For the following example, the closing brace is the last character on the line. + // This shows the character after the closing brace is highlighted, even if that next + // character is a newline. + if countdown < 5 { might_abort(false); } + countdown -= 1; + } + Ok(()) +} + +// Notes: +// 1. Compare this program and its coverage results to those of the similar tests +// `panic_unwind.rs` and `try_error_result.rs`. +// 2. This test confirms the coverage generated when a program includes `UnwindAction::Terminate`. +// 3. The test does not invoke the abort. By executing to a successful completion, the coverage +// results show where the program did and did not execute. +// 4. If the program actually aborted, the coverage counters would not be saved (which "works as +// intended"). Coverage results would show no executed coverage regions. +// 6. If `should_abort` is `true` and the program aborts, the program exits with a `132` status +// (on Linux at least). + +/* + +Expect the following coverage results: + +```text + 16| 11| while countdown > 0 { + 17| 10| if countdown < 5 { + 18| 4| might_abort(false); + 19| 6| } +``` + +This is actually correct. + +The condition `countdown < 5` executed 10 times (10 loop iterations). + +It evaluated to `true` 4 times, and executed the `might_abort()` call. + +It skipped the body of the `might_abort()` call 6 times. If an `if` does not include an explicit +`else`, the coverage implementation injects a counter, at the character immediately after the `if`s +closing brace, to count the "implicit" `else`. This is the only way to capture the coverage of the +non-true condition. + +As another example of why this is important, say the condition was `countdown < 50`, which is always +`true`. In that case, we wouldn't have a test for what happens if `might_abort()` is not called. +The closing brace would have a count of `0`, highlighting the missed coverage. +*/ diff --git a/tests/coverage-map/status-quo/assert.cov-map b/tests/coverage-map/status-quo/assert.cov-map new file mode 100644 index 00000000000..dd413123de7 --- /dev/null +++ b/tests/coverage-map/status-quo/assert.cov-map @@ -0,0 +1,40 @@ +Function name: assert::main +Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 09, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 02, 0a, 12, 02, 13, 00, 20, 09, 00, 21, 02, 0a, 0d, 02, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 8 +- expression 0 operands: lhs = Counter(0), rhs = Expression(6, Add) +- expression 1 operands: lhs = Counter(1), rhs = Expression(7, Add) +- expression 2 operands: lhs = Counter(2), rhs = Counter(3) +- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(4) +- expression 4 operands: lhs = Expression(5, Sub), rhs = Counter(1) +- expression 5 operands: lhs = Expression(0, Add), rhs = Counter(4) +- expression 6 operands: lhs = Counter(1), rhs = Expression(7, Add) +- expression 7 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 9, 1) to (start + 1, 27) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24) + = (c0 + (c1 + (c2 + c3))) +- Code(Expression(5, Sub)) at (prev + 1, 12) to (start + 0, 26) + = ((c0 + (c1 + (c2 + c3))) - c4) +- Code(Counter(1)) at (prev + 0, 27) to (start + 2, 10) +- Code(Expression(4, Sub)) at (prev + 2, 19) to (start + 0, 32) + = (((c0 + (c1 + (c2 + c3))) - c4) - c1) +- Code(Counter(2)) at (prev + 0, 33) to (start + 2, 10) +- Code(Counter(3)) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23) + = (c1 + (c2 + c3)) +- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2) + +Function name: assert::might_fail_assert +Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 02, 0f, 02, 02, 25, 00, 3d, 05, 01, 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: 3 +- Code(Counter(0)) at (prev + 4, 1) to (start + 2, 15) +- Code(Expression(0, Sub)) at (prev + 2, 37) to (start + 0, 61) + = (c0 - c1) +- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2) + diff --git a/tests/coverage-map/status-quo/assert.rs b/tests/coverage-map/status-quo/assert.rs new file mode 100644 index 00000000000..85e6662a6ad --- /dev/null +++ b/tests/coverage-map/status-quo/assert.rs @@ -0,0 +1,32 @@ +#![allow(unused_assignments)] +// failure-status: 101 + +fn might_fail_assert(one_plus_one: u32) { + println!("does 1 + 1 = {}?", one_plus_one); + assert_eq!(1 + 1, one_plus_one, "the argument was wrong"); +} + +fn main() -> Result<(), u8> { + let mut countdown = 10; + while countdown > 0 { + if countdown == 1 { + might_fail_assert(3); + } else if countdown < 5 { + might_fail_assert(2); + } + countdown -= 1; + } + Ok(()) +} + +// Notes: +// 1. Compare this program and its coverage results to those of the very similar test +// `panic_unwind.rs`, and similar tests `abort.rs` and `try_error_result.rs`. +// 2. This test confirms the coverage generated when a program passes or fails an `assert!()` or +// related `assert_*!()` macro. +// 3. Notably, the `assert` macros *do not* generate `TerminatorKind::Assert`. The macros produce +// conditional expressions, `TerminatorKind::SwitchInt` branches, and a possible call to +// `begin_panic_fmt()` (that begins a panic unwind, if the assertion test fails). +// 4. `TerminatoKind::Assert` is, however, also present in the MIR generated for this test +// (and in many other coverage tests). The `Assert` terminator is typically generated by the +// Rust compiler to check for runtime failures, such as numeric overflows. diff --git a/tests/coverage-map/status-quo/async.cov-map b/tests/coverage-map/status-quo/async.cov-map new file mode 100644 index 00000000000..5f28252ef80 --- /dev/null +++ b/tests/coverage-map/status-quo/async.cov-map @@ -0,0 +1,340 @@ +Function name: async::c +Raw bytes (9): 0x[01, 01, 00, 01, 01, 05, 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 + 5, 1) to (start + 0, 25) + +Function name: async::c::{closure#0} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 05, 19, 01, 0e, 05, 02, 09, 00, 0a, 02, 02, 09, 00, 0a, 07, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 5, 25) to (start + 1, 14) +- Code(Counter(1)) at (prev + 2, 9) to (start + 0, 10) +- Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 10) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: async::d +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0d, 01, 00, 14] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 20) + +Function name: async::d::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0d, 14, 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 + 13, 20) to (start + 0, 25) + +Function name: async::e (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 01, 00, 14] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 15, 1) to (start + 0, 20) + +Function name: async::e::{closure#0} (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 14, 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 + 15, 20) to (start + 0, 25) + +Function name: async::executor::block_on::<core::pin::Pin<&mut async::i::{closure#0}>> +Raw bytes (44): 0x[01, 01, 05, 0b, 05, 01, 05, 01, 05, 02, 00, 02, 00, 06, 01, 6e, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 0f, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 13, 02, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Counter(1) +- expression 3 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 4 operands: lhs = Expression(0, Sub), rhs = Zero +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 110, 5) to (start + 10, 54) +- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35) + = ((c0 + c1) - c1) +- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73) + = (c0 + c1) +- Code(Expression(3, Add)) at (prev + 1, 23) to (start + 0, 26) + = (((c0 + c1) - c1) + Zero) +- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15) +- Code(Expression(4, Add)) at (prev + 2, 5) to (start + 0, 6) + = (((c0 + c1) - c1) + Zero) + +Function name: async::executor::block_on::VTABLE::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 72, 11, 00, 33] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 114, 17) to (start + 0, 51) + +Function name: async::executor::block_on::VTABLE::{closure#1} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 73, 11, 00, 33] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 115, 17) to (start + 0, 51) + +Function name: async::executor::block_on::VTABLE::{closure#2} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 74, 11, 00, 33] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 116, 17) to (start + 0, 51) + +Function name: async::executor::block_on::VTABLE::{closure#3} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 75, 11, 00, 13] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 117, 17) to (start + 0, 19) + +Function name: async::f +Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 01, 00, 14] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 20) + +Function name: async::f::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 14, 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 + 17, 20) to (start + 0, 25) + +Function name: async::foo (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 00, 1e] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 19, 1) to (start + 0, 30) + +Function name: async::foo::{closure#0} (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 1e, 00, 2d] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 19, 30) to (start + 0, 45) + +Function name: async::g +Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 01, 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 + 21, 1) to (start + 0, 23) + +Function name: async::g::{closure#0} (unused) +Raw bytes (69): 0x[01, 01, 00, 0d, 00, 15, 17, 01, 0c, 00, 02, 09, 00, 0a, 01, 00, 0e, 00, 11, 00, 00, 12, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 09, 00, 0a, 00, 00, 0e, 00, 11, 00, 00, 12, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 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: 13 +- Code(Zero) at (prev + 21, 23) to (start + 1, 12) +- Code(Zero) at (prev + 2, 9) to (start + 0, 10) +- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) +- Code(Zero) at (prev + 0, 18) to (start + 0, 23) +- Code(Zero) at (prev + 0, 27) to (start + 0, 28) +- Code(Zero) at (prev + 0, 32) to (start + 0, 34) +- Code(Zero) at (prev + 1, 9) to (start + 0, 10) +- Code(Zero) at (prev + 0, 14) to (start + 0, 17) +- Code(Zero) at (prev + 0, 18) to (start + 0, 23) +- Code(Zero) at (prev + 0, 27) to (start + 0, 28) +- Code(Zero) at (prev + 0, 32) to (start + 0, 34) +- Code(Zero) at (prev + 1, 14) to (start + 0, 16) +- Code(Zero) at (prev + 2, 1) to (start + 0, 2) + +Function name: async::h +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1d, 01, 00, 16] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 29, 1) to (start + 0, 22) + +Function name: async::h::{closure#0} (unused) +Raw bytes (44): 0x[01, 01, 00, 08, 00, 1d, 16, 03, 0c, 00, 04, 09, 00, 0a, 01, 00, 0e, 00, 13, 00, 00, 14, 00, 19, 00, 00, 1a, 00, 1b, 00, 00, 20, 00, 22, 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: 8 +- Code(Zero) at (prev + 29, 22) to (start + 3, 12) +- Code(Zero) at (prev + 4, 9) to (start + 0, 10) +- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 19) +- Code(Zero) at (prev + 0, 20) to (start + 0, 25) +- Code(Zero) at (prev + 0, 26) to (start + 0, 27) +- Code(Zero) at (prev + 0, 32) to (start + 0, 34) +- Code(Zero) at (prev + 1, 14) to (start + 0, 16) +- Code(Zero) at (prev + 2, 1) to (start + 0, 2) + +Function name: async::i +Raw bytes (9): 0x[01, 01, 00, 01, 01, 26, 01, 00, 13] +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, 1) to (start + 0, 19) + +Function name: async::i::{closure#0} +Raw bytes (84): 0x[01, 01, 05, 01, 00, 0d, 00, 1d, 00, 19, 13, 1d, 21, 0e, 01, 26, 13, 04, 0c, 0d, 05, 09, 00, 0a, 03, 00, 0e, 00, 12, 05, 00, 13, 00, 18, 09, 00, 1c, 00, 21, 07, 00, 27, 00, 2a, 15, 00, 2b, 00, 30, 1d, 01, 09, 00, 0a, 11, 00, 0e, 00, 11, 25, 00, 12, 00, 17, 29, 00, 1b, 00, 20, 0b, 00, 24, 00, 26, 21, 01, 0e, 00, 10, 0f, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(0), rhs = Zero +- expression 1 operands: lhs = Counter(3), rhs = Zero +- expression 2 operands: lhs = Counter(7), rhs = Zero +- expression 3 operands: lhs = Counter(6), rhs = Expression(4, Add) +- expression 4 operands: lhs = Counter(7), rhs = Counter(8) +Number of file 0 mappings: 14 +- Code(Counter(0)) at (prev + 38, 19) to (start + 4, 12) +- Code(Counter(3)) at (prev + 5, 9) to (start + 0, 10) +- Code(Expression(0, Add)) at (prev + 0, 14) to (start + 0, 18) + = (c0 + Zero) +- Code(Counter(1)) at (prev + 0, 19) to (start + 0, 24) +- Code(Counter(2)) at (prev + 0, 28) to (start + 0, 33) +- Code(Expression(1, Add)) at (prev + 0, 39) to (start + 0, 42) + = (c3 + Zero) +- Code(Counter(5)) at (prev + 0, 43) to (start + 0, 48) +- Code(Counter(7)) at (prev + 1, 9) to (start + 0, 10) +- Code(Counter(4)) at (prev + 0, 14) to (start + 0, 17) +- Code(Counter(9)) at (prev + 0, 18) to (start + 0, 23) +- Code(Counter(10)) at (prev + 0, 27) to (start + 0, 32) +- Code(Expression(2, Add)) at (prev + 0, 36) to (start + 0, 38) + = (c7 + Zero) +- Code(Counter(8)) at (prev + 1, 14) to (start + 0, 16) +- Code(Expression(3, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c6 + (c7 + c8)) + +Function name: async::j +Raw bytes (59): 0x[01, 01, 05, 01, 00, 05, 00, 09, 00, 05, 13, 09, 0d, 09, 01, 31, 01, 13, 0c, 05, 14, 09, 00, 0a, 03, 00, 0e, 00, 1b, 07, 00, 1f, 00, 27, 09, 01, 09, 00, 0a, 11, 00, 0e, 00, 1a, 0b, 00, 1e, 00, 20, 0d, 01, 0e, 00, 10, 0f, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(0), rhs = Zero +- expression 1 operands: lhs = Counter(1), rhs = Zero +- expression 2 operands: lhs = Counter(2), rhs = Zero +- expression 3 operands: lhs = Counter(1), rhs = Expression(4, Add) +- expression 4 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 49, 1) to (start + 19, 12) +- Code(Counter(1)) at (prev + 20, 9) to (start + 0, 10) +- Code(Expression(0, Add)) at (prev + 0, 14) to (start + 0, 27) + = (c0 + Zero) +- Code(Expression(1, Add)) at (prev + 0, 31) to (start + 0, 39) + = (c1 + Zero) +- Code(Counter(2)) at (prev + 1, 9) to (start + 0, 10) +- Code(Counter(4)) at (prev + 0, 14) to (start + 0, 26) +- Code(Expression(2, Add)) at (prev + 0, 30) to (start + 0, 32) + = (c2 + Zero) +- Code(Counter(3)) at (prev + 1, 14) to (start + 0, 16) +- Code(Expression(3, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c1 + (c2 + c3)) + +Function name: async::j::c +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 33, 05, 01, 12, 05, 02, 0d, 00, 0e, 02, 0a, 0d, 00, 0e, 07, 02, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 51, 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) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 2, 5) to (start + 0, 6) + = (c1 + (c0 - c1)) + +Function name: async::j::d +Raw bytes (9): 0x[01, 01, 00, 01, 01, 42, 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 + 66, 5) to (start + 0, 23) + +Function name: async::j::f +Raw bytes (9): 0x[01, 01, 00, 01, 01, 43, 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 + 67, 5) to (start + 0, 23) + +Function name: async::k (unused) +Raw bytes (29): 0x[01, 01, 00, 05, 01, 4b, 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(Counter(0)) at (prev + 75, 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, 09, 05, 09, 0f, 05, 02, 05, 01, 53, 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 +- expression 0 operands: lhs = Counter(0), rhs = Expression(1, Add) +- expression 1 operands: lhs = Counter(2), rhs = Counter(1) +- expression 2 operands: lhs = Counter(2), rhs = Expression(3, Add) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 5 +- Code(Counter(0)) at (prev + 83, 1) to (start + 1, 12) +- Code(Expression(0, Sub)) at (prev + 2, 14) to (start + 0, 16) + = (c0 - (c2 + c1)) +- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 16) +- Code(Counter(2)) at (prev + 1, 14) to (start + 0, 16) +- Code(Expression(2, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c2 + (c1 + (c0 - (c2 + c1)))) + +Function name: async::m +Raw bytes (9): 0x[01, 01, 00, 01, 01, 5b, 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 + 91, 1) to (start + 0, 25) + +Function name: async::m::{closure#0} (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 5b, 19, 00, 22] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 91, 25) to (start + 0, 34) + +Function name: async::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 5d, 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 + 93, 1) to (start + 8, 2) + diff --git a/tests/coverage-map/status-quo/async.rs b/tests/coverage-map/status-quo/async.rs new file mode 100644 index 00000000000..efd9e62d64e --- /dev/null +++ b/tests/coverage-map/status-quo/async.rs @@ -0,0 +1,128 @@ +#![allow(unused_assignments, dead_code)] + +// compile-flags: --edition=2018 -C opt-level=1 + +async fn c(x: u8) -> u8 { + if x == 8 { + 1 + } else { + 0 + } +} + +async fn d() -> u8 { 1 } + +async fn e() -> u8 { 1 } // unused function; executor does not block on `g()` + +async fn f() -> u8 { 1 } + +async fn foo() -> [bool; 10] { [false; 10] } // unused function; executor does not block on `h()` + +pub async fn g(x: u8) { + match x { + y if e().await == y => (), + y if f().await == y => (), + _ => (), + } +} + +async fn h(x: usize) { // The function signature is counted when called, but the body is not + // executed (not awaited) so the open brace has a `0` count (at least when + // displayed with `llvm-cov show` in color-mode). + match x { + y if foo().await[y] => (), + _ => (), + } +} + +async fn i(x: u8) { // line coverage is 1, but there are 2 regions: + // (a) the function signature, counted when the function is called; and + // (b) the open brace for the function body, counted once when the body is + // executed asynchronously. + match x { + y if c(x).await == y + 1 => { d().await; } + y if f().await == y + 1 => (), + _ => (), + } +} + +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`). + } else { + 0 + } + } + fn d() -> u8 { 1 } // inner function is defined in-line, but the function is not executed + fn f() -> u8 { 1 } + match x { + y if c(x) == y + 1 => { d(); } + y if f() == y + 1 => (), + _ => (), + } +} + +fn k(x: u8) { // unused function + match x { + 1 => (), + 2 => (), + _ => (), + } +} + +fn l(x: u8) { + match x { + 1 => (), + 2 => (), + _ => (), + } +} + +async fn m(x: u8) -> u8 { x - 1 } + +fn main() { + let _ = g(10); + let _ = h(9); + let mut future = Box::pin(i(8)); + j(7); + l(6); + let _ = m(5); + executor::block_on(future.as_mut()); +} + +mod executor { + use core::{ + future::Future, + pin::Pin, + task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, + }; + + pub fn block_on<F: Future>(mut future: F) -> F::Output { + let mut future = unsafe { Pin::new_unchecked(&mut future) }; + use std::hint::unreachable_unchecked; + static VTABLE: RawWakerVTable = RawWakerVTable::new( + |_| unsafe { unreachable_unchecked() }, // clone + |_| unsafe { unreachable_unchecked() }, // wake + |_| unsafe { unreachable_unchecked() }, // wake_by_ref + |_| (), + ); + let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; + let mut context = Context::from_waker(&waker); + + loop { + if let Poll::Ready(val) = future.as_mut().poll(&mut context) { + break val; + } + } + } +} diff --git a/tests/coverage-map/status-quo/async2.cov-map b/tests/coverage-map/status-quo/async2.cov-map new file mode 100644 index 00000000000..fe74dcd8840 --- /dev/null +++ b/tests/coverage-map/status-quo/async2.cov-map @@ -0,0 +1,136 @@ +Function name: async2::async_func +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 01, 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 + 11, 1) to (start + 0, 23) + +Function name: async2::async_func::{closure#0} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0b, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 11, 23) to (start + 3, 9) +- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: async2::async_func_just_println +Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 00, 24] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 19, 1) to (start + 0, 36) + +Function name: async2::async_func_just_println::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 24, 02, 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 + 19, 36) to (start + 2, 2) + +Function name: async2::executor::block_on::<async2::async_func::{closure#0}> +Raw bytes (44): 0x[01, 01, 05, 0b, 05, 01, 05, 01, 05, 02, 00, 02, 00, 06, 01, 27, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 0f, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 13, 02, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Counter(1) +- expression 3 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 4 operands: lhs = Expression(0, Sub), rhs = Zero +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 39, 5) to (start + 10, 54) +- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35) + = ((c0 + c1) - c1) +- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73) + = (c0 + c1) +- Code(Expression(3, Add)) at (prev + 1, 23) to (start + 0, 26) + = (((c0 + c1) - c1) + Zero) +- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15) +- Code(Expression(4, Add)) at (prev + 2, 5) to (start + 0, 6) + = (((c0 + c1) - c1) + Zero) + +Function name: async2::executor::block_on::<async2::async_func_just_println::{closure#0}> +Raw bytes (44): 0x[01, 01, 05, 0b, 05, 01, 05, 01, 05, 02, 00, 02, 00, 06, 01, 27, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 0f, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 13, 02, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Counter(1) +- expression 3 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 4 operands: lhs = Expression(0, Sub), rhs = Zero +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 39, 5) to (start + 10, 54) +- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35) + = ((c0 + c1) - c1) +- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73) + = (c0 + c1) +- Code(Expression(3, Add)) at (prev + 1, 23) to (start + 0, 26) + = (((c0 + c1) - c1) + Zero) +- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15) +- Code(Expression(4, Add)) at (prev + 2, 5) to (start + 0, 6) + = (((c0 + c1) - c1) + Zero) + +Function name: async2::executor::block_on::VTABLE::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 2b, 11, 00, 33] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 43, 17) to (start + 0, 51) + +Function name: async2::executor::block_on::VTABLE::{closure#1} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 2c, 11, 00, 33] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 44, 17) to (start + 0, 51) + +Function name: async2::executor::block_on::VTABLE::{closure#2} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 2d, 11, 00, 33] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 45, 17) to (start + 0, 51) + +Function name: async2::executor::block_on::VTABLE::{closure#3} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 2e, 11, 00, 13] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 46, 17) to (start + 0, 19) + +Function name: async2::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 17, 01, 07, 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 + 23, 1) to (start + 7, 2) + +Function name: async2::non_async_func +Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 03, 01, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 1 +- expression 0 operands: lhs = Counter(1), rhs = Zero +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 3, 1) to (start + 3, 9) +- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(0, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + Zero) + diff --git a/tests/coverage-map/status-quo/async2.rs b/tests/coverage-map/status-quo/async2.rs new file mode 100644 index 00000000000..2884ff297af --- /dev/null +++ b/tests/coverage-map/status-quo/async2.rs @@ -0,0 +1,57 @@ +// compile-flags: --edition=2018 + +fn non_async_func() { + println!("non_async_func was covered"); + let b = true; + if b { + println!("non_async_func println in block"); + } +} + +async fn async_func() { + println!("async_func was covered"); + let b = true; + if b { + println!("async_func println in block"); + } +} + +async fn async_func_just_println() { + println!("async_func_just_println was covered"); +} + +fn main() { + println!("codecovsample::main"); + + non_async_func(); + + executor::block_on(async_func()); + executor::block_on(async_func_just_println()); +} + +mod executor { + use core::{ + future::Future, + pin::Pin, + task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, + }; + + pub fn block_on<F: Future>(mut future: F) -> F::Output { + let mut future = unsafe { Pin::new_unchecked(&mut future) }; + use std::hint::unreachable_unchecked; + static VTABLE: RawWakerVTable = RawWakerVTable::new( + |_| unsafe { unreachable_unchecked() }, // clone + |_| unsafe { unreachable_unchecked() }, // wake + |_| unsafe { unreachable_unchecked() }, // wake_by_ref + |_| (), + ); + let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; + let mut context = Context::from_waker(&waker); + + loop { + if let Poll::Ready(val) = future.as_mut().poll(&mut context) { + break val; + } + } + } +} diff --git a/tests/coverage-map/status-quo/closure.cov-map b/tests/coverage-map/status-quo/closure.cov-map new file mode 100644 index 00000000000..f3a32f091a9 --- /dev/null +++ b/tests/coverage-map/status-quo/closure.cov-map @@ -0,0 +1,324 @@ +Function name: closure::main +Raw bytes (170): 0x[01, 01, 17, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 00, 01, 05, 05, 5a, 01, 05, 18, 01, 08, 01, 0f, 0d, 03, 16, 0e, 06, 0a, 07, 10, 05, 13, 0d, 0b, 1a, 0e, 08, 09, 0f, 10, 05, 0e, 09, 13, 16, 05, 0d, 18, 17, 19, 09, 01, 21, 1b, 04, 09, 00, 29, 1f, 01, 09, 00, 2d, 23, 01, 09, 00, 24, 27, 05, 09, 00, 24, 2b, 02, 09, 00, 21, 2f, 04, 09, 00, 21, 33, 04, 09, 00, 28, 37, 09, 09, 00, 32, 3b, 04, 09, 00, 33, 3f, 07, 09, 00, 4b, 43, 08, 09, 01, 09, 47, 0a, 09, 01, 09, 4b, 08, 09, 01, 09, 4f, 0a, 08, 00, 10, 05, 00, 11, 04, 06, 5a, 04, 06, 00, 07, 57, 01, 05, 03, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 23 +- expression 0 operands: lhs = Counter(0), rhs = Zero +- expression 1 operands: lhs = Counter(0), rhs = Zero +- expression 2 operands: lhs = Counter(0), rhs = Zero +- expression 3 operands: lhs = Counter(0), rhs = Zero +- expression 4 operands: lhs = Counter(0), rhs = Zero +- expression 5 operands: lhs = Counter(0), rhs = Zero +- expression 6 operands: lhs = Counter(0), rhs = Zero +- expression 7 operands: lhs = Counter(0), rhs = Zero +- expression 8 operands: lhs = Counter(0), rhs = Zero +- expression 9 operands: lhs = Counter(0), rhs = Zero +- expression 10 operands: lhs = Counter(0), rhs = Zero +- expression 11 operands: lhs = Counter(0), rhs = Zero +- expression 12 operands: lhs = Counter(0), rhs = Zero +- expression 13 operands: lhs = Counter(0), rhs = Zero +- expression 14 operands: lhs = Counter(0), rhs = Zero +- expression 15 operands: lhs = Counter(0), rhs = Zero +- expression 16 operands: lhs = Counter(0), rhs = Zero +- expression 17 operands: lhs = Counter(0), rhs = Zero +- expression 18 operands: lhs = Counter(0), rhs = Zero +- expression 19 operands: lhs = Counter(0), rhs = Zero +- expression 20 operands: lhs = Counter(0), rhs = Counter(1) +- expression 21 operands: lhs = Counter(1), rhs = Expression(22, Sub) +- expression 22 operands: lhs = Counter(0), rhs = Counter(1) +Number of file 0 mappings: 24 +- Code(Counter(0)) at (prev + 8, 1) to (start + 15, 13) +- Code(Expression(0, Add)) at (prev + 22, 14) to (start + 6, 10) + = (c0 + Zero) +- Code(Expression(1, Add)) at (prev + 16, 5) to (start + 19, 13) + = (c0 + Zero) +- Code(Expression(2, Add)) at (prev + 26, 14) to (start + 8, 9) + = (c0 + Zero) +- Code(Expression(3, Add)) at (prev + 16, 5) to (start + 14, 9) + = (c0 + Zero) +- Code(Expression(4, Add)) at (prev + 22, 5) to (start + 13, 24) + = (c0 + Zero) +- Code(Expression(5, Add)) at (prev + 25, 9) to (start + 1, 33) + = (c0 + Zero) +- Code(Expression(6, Add)) at (prev + 4, 9) to (start + 0, 41) + = (c0 + Zero) +- Code(Expression(7, Add)) at (prev + 1, 9) to (start + 0, 45) + = (c0 + Zero) +- Code(Expression(8, Add)) at (prev + 1, 9) to (start + 0, 36) + = (c0 + Zero) +- Code(Expression(9, Add)) at (prev + 5, 9) to (start + 0, 36) + = (c0 + Zero) +- Code(Expression(10, Add)) at (prev + 2, 9) to (start + 0, 33) + = (c0 + Zero) +- Code(Expression(11, Add)) at (prev + 4, 9) to (start + 0, 33) + = (c0 + Zero) +- Code(Expression(12, Add)) at (prev + 4, 9) to (start + 0, 40) + = (c0 + Zero) +- Code(Expression(13, Add)) at (prev + 9, 9) to (start + 0, 50) + = (c0 + Zero) +- Code(Expression(14, Add)) at (prev + 4, 9) to (start + 0, 51) + = (c0 + Zero) +- Code(Expression(15, Add)) at (prev + 7, 9) to (start + 0, 75) + = (c0 + Zero) +- Code(Expression(16, Add)) at (prev + 8, 9) to (start + 1, 9) + = (c0 + Zero) +- Code(Expression(17, Add)) at (prev + 10, 9) to (start + 1, 9) + = (c0 + Zero) +- Code(Expression(18, Add)) at (prev + 8, 9) to (start + 1, 9) + = (c0 + Zero) +- Code(Expression(19, Add)) at (prev + 10, 8) to (start + 0, 16) + = (c0 + Zero) +- Code(Counter(1)) at (prev + 0, 17) to (start + 4, 6) +- Code(Expression(22, Sub)) at (prev + 4, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(21, Add)) at (prev + 1, 5) to (start + 3, 2) + = (c1 + (c0 - c1)) + +Function name: closure::main::{closure#0} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 27, 05, 02, 14, 05, 02, 15, 02, 0a, 02, 02, 0a, 00, 0b, 07, 01, 09, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 39, 5) to (start + 2, 20) +- Code(Counter(1)) at (prev + 2, 21) to (start + 2, 10) +- Code(Expression(0, Sub)) at (prev + 2, 10) to (start + 0, 11) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 9) to (start + 1, 6) + = (c1 + (c0 - c1)) + +Function name: closure::main::{closure#10} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, 9a, 01, 07, 00, 21] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 154, 7) to (start + 0, 33) + +Function name: closure::main::{closure#11} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, 9e, 01, 07, 00, 21] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 158, 7) to (start + 0, 33) + +Function name: closure::main::{closure#12} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, a6, 01, 01, 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 + 166, 1) to (start + 0, 23) + +Function name: closure::main::{closure#13} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, ab, 01, 0d, 02, 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 + 171, 13) to (start + 2, 14) + +Function name: closure::main::{closure#14} +Raw bytes (38): 0x[01, 01, 04, 05, 0a, 01, 05, 01, 05, 03, 00, 05, 03, b2, 01, 0d, 00, 15, 01, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0a, 00, 2f, 00, 33, 0f, 01, 0d, 00, 0e] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 4 +- expression 0 operands: lhs = Counter(1), rhs = Expression(2, Sub) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Counter(1) +- expression 3 operands: lhs = Expression(0, Add), rhs = Zero +Number of file 0 mappings: 5 +- Code(Expression(0, Add)) at (prev + 178, 13) to (start + 0, 21) + = (c1 + (c0 - c1)) +- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 27) +- Code(Counter(1)) at (prev + 1, 30) to (start + 0, 37) +- Code(Expression(2, Sub)) at (prev + 0, 47) to (start + 0, 51) + = (c0 - c1) +- Code(Expression(3, Add)) at (prev + 1, 13) to (start + 0, 14) + = ((c1 + (c0 - c1)) + Zero) + +Function name: closure::main::{closure#15} +Raw bytes (45): 0x[01, 01, 05, 05, 0e, 01, 05, 01, 00, 01, 05, 03, 00, 06, 01, ba, 01, 09, 00, 0a, 03, 01, 0d, 00, 15, 0b, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0e, 00, 2f, 00, 33, 13, 02, 09, 00, 0a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(1), rhs = Expression(3, Sub) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Zero +- expression 3 operands: lhs = Counter(0), rhs = Counter(1) +- expression 4 operands: lhs = Expression(0, Add), rhs = Zero +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 186, 9) to (start + 0, 10) +- Code(Expression(0, Add)) at (prev + 1, 13) to (start + 0, 21) + = (c1 + (c0 - c1)) +- Code(Expression(2, Add)) at (prev + 1, 17) to (start + 1, 27) + = (c0 + Zero) +- Code(Counter(1)) at (prev + 1, 30) to (start + 0, 37) +- Code(Expression(3, Sub)) at (prev + 0, 47) to (start + 0, 51) + = (c0 - c1) +- Code(Expression(4, Add)) at (prev + 2, 9) to (start + 0, 10) + = ((c1 + (c0 - c1)) + Zero) + +Function name: closure::main::{closure#16} +Raw bytes (38): 0x[01, 01, 04, 05, 0a, 01, 05, 01, 05, 03, 00, 05, 03, c4, 01, 0d, 00, 15, 01, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0a, 00, 2f, 00, 33, 0f, 01, 0d, 00, 0e] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 4 +- expression 0 operands: lhs = Counter(1), rhs = Expression(2, Sub) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Counter(1) +- expression 3 operands: lhs = Expression(0, Add), rhs = Zero +Number of file 0 mappings: 5 +- Code(Expression(0, Add)) at (prev + 196, 13) to (start + 0, 21) + = (c1 + (c0 - c1)) +- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 27) +- Code(Counter(1)) at (prev + 1, 30) to (start + 0, 37) +- Code(Expression(2, Sub)) at (prev + 0, 47) to (start + 0, 51) + = (c0 - c1) +- Code(Expression(3, Add)) at (prev + 1, 13) to (start + 0, 14) + = ((c1 + (c0 - c1)) + Zero) + +Function name: closure::main::{closure#17} +Raw bytes (45): 0x[01, 01, 05, 05, 0e, 01, 05, 01, 00, 01, 05, 03, 00, 06, 01, cc, 01, 09, 00, 0a, 03, 01, 0d, 00, 15, 0b, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0e, 00, 2f, 00, 33, 13, 02, 09, 00, 0a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(1), rhs = Expression(3, Sub) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(0), rhs = Zero +- expression 3 operands: lhs = Counter(0), rhs = Counter(1) +- expression 4 operands: lhs = Expression(0, Add), rhs = Zero +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 204, 9) to (start + 0, 10) +- Code(Expression(0, Add)) at (prev + 1, 13) to (start + 0, 21) + = (c1 + (c0 - c1)) +- Code(Expression(2, Add)) at (prev + 1, 17) to (start + 1, 27) + = (c0 + Zero) +- Code(Counter(1)) at (prev + 1, 30) to (start + 0, 37) +- Code(Expression(3, Sub)) at (prev + 0, 47) to (start + 0, 51) + = (c0 - c1) +- Code(Expression(4, Add)) at (prev + 2, 9) to (start + 0, 10) + = ((c1 + (c0 - c1)) + Zero) + +Function name: closure::main::{closure#18} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 18, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 12, 00, 13, 07, 01, 11, 01, 0e] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 24, 13) to (start + 2, 28) +- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18) +- Code(Expression(0, Sub)) at (prev + 2, 18) to (start + 0, 19) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 17) to (start + 1, 14) + = (c1 + (c0 - c1)) + +Function name: closure::main::{closure#19} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 42, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 12, 00, 13, 07, 01, 11, 01, 0e] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 66, 13) to (start + 2, 28) +- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18) +- Code(Expression(0, Sub)) at (prev + 2, 18) to (start + 0, 19) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 17) to (start + 1, 14) + = (c1 + (c0 - c1)) + +Function name: closure::main::{closure#1} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 51, 05, 02, 14, 05, 02, 15, 02, 0a, 02, 02, 0a, 00, 0b, 07, 01, 09, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 81, 5) to (start + 2, 20) +- Code(Counter(1)) at (prev + 2, 21) to (start + 2, 10) +- Code(Expression(0, Sub)) at (prev + 2, 10) to (start + 0, 11) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 9) to (start + 1, 6) + = (c1 + (c0 - c1)) + +Function name: closure::main::{closure#2} +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 67, 05, 02, 14, 05, 02, 15, 02, 0a, 02, 02, 0a, 00, 0b, 07, 01, 09, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 103, 5) to (start + 2, 20) +- Code(Counter(1)) at (prev + 2, 21) to (start + 2, 10) +- Code(Expression(0, Sub)) at (prev + 2, 10) to (start + 0, 11) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 9) to (start + 1, 6) + = (c1 + (c0 - c1)) + +Function name: closure::main::{closure#3} (unused) +Raw bytes (25): 0x[01, 01, 00, 04, 01, 80, 01, 05, 01, 14, 00, 01, 15, 02, 0a, 00, 02, 0a, 00, 0b, 00, 01, 09, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 128, 5) to (start + 1, 20) +- Code(Zero) at (prev + 1, 21) to (start + 2, 10) +- Code(Zero) at (prev + 2, 10) to (start + 0, 11) +- Code(Zero) at (prev + 1, 9) to (start + 1, 6) + +Function name: closure::main::{closure#4} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, 88, 01, 35, 00, 43] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 136, 53) to (start + 0, 67) + +Function name: closure::main::{closure#5} +Raw bytes (10): 0x[01, 01, 00, 01, 01, 8b, 01, 3d, 00, 4f] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 139, 61) to (start + 0, 79) + +Function name: closure::main::{closure#6} +Raw bytes (10): 0x[01, 01, 00, 01, 01, 8c, 01, 41, 00, 57] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 140, 65) to (start + 0, 87) + +Function name: closure::main::{closure#7} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, 8d, 01, 3b, 00, 51] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 141, 59) to (start + 0, 81) + +Function name: closure::main::{closure#8} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, 92, 01, 3b, 00, 55] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 146, 59) to (start + 0, 85) + +Function name: closure::main::{closure#9} (unused) +Raw bytes (10): 0x[01, 01, 00, 01, 01, 94, 01, 38, 02, 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 + 148, 56) to (start + 2, 6) + diff --git a/tests/coverage-map/status-quo/closure.rs b/tests/coverage-map/status-quo/closure.rs new file mode 100644 index 00000000000..16a2c4e33bd --- /dev/null +++ b/tests/coverage-map/status-quo/closure.rs @@ -0,0 +1,220 @@ +#![allow(unused_assignments, unused_variables)] +// compile-flags: -C opt-level=2 + +// This test used to be sensitive to certain coverage-specific hacks in +// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by +// <https://github.com/rust-lang/rust/pull/83666>. + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + let is_false = !is_true; + + let mut some_string = Some(String::from("the string content")); + println!( + "The string or alt: {}" + , + some_string + . + unwrap_or_else + ( + || + { + let mut countdown = 0; + if is_false { + countdown = 10; + } + "alt string 1".to_owned() + } + ) + ); + + some_string = Some(String::from("the string content")); + let + a + = + || + { + let mut countdown = 0; + if is_false { + countdown = 10; + } + "alt string 2".to_owned() + }; + println!( + "The string or alt: {}" + , + some_string + . + unwrap_or_else + ( + a + ) + ); + + some_string = None; + println!( + "The string or alt: {}" + , + some_string + . + unwrap_or_else + ( + || + { + let mut countdown = 0; + if is_false { + countdown = 10; + } + "alt string 3".to_owned() + } + ) + ); + + some_string = None; + let + a + = + || + { + let mut countdown = 0; + if is_false { + countdown = 10; + } + "alt string 4".to_owned() + }; + println!( + "The string or alt: {}" + , + some_string + . + unwrap_or_else + ( + a + ) + ); + + let + quote_closure + = + |val| + { + let mut countdown = 0; + if is_false { + countdown = 10; + } + format!("'{}'", val) + }; + println!( + "Repeated, quoted string: {:?}" + , + std::iter::repeat("repeat me") + .take(5) + .map + ( + quote_closure + ) + .collect::<Vec<_>>() + ); + + let + _unused_closure + = + | + mut countdown + | + { + if is_false { + countdown = 10; + } + "closure should be unused".to_owned() + }; + + let mut countdown = 10; + let _short_unused_closure = | _unused_arg: u8 | countdown += 1; + + + let short_used_covered_closure_macro = | used_arg: u8 | println!("called"); + let short_used_not_covered_closure_macro = | used_arg: u8 | println!("not called"); + let _short_unused_closure_macro = | _unused_arg: u8 | println!("not called"); + + + + + let _short_unused_closure_block = | _unused_arg: u8 | { println!("not called") }; + + let _shortish_unused_closure = | _unused_arg: u8 | { + println!("not called") + }; + + let _as_short_unused_closure = | + _unused_arg: u8 + | { println!("not called") }; + + let _almost_as_short_unused_closure = | + _unused_arg: u8 + | { println!("not called") } + ; + + + + + + let _short_unused_closure_line_break_no_block = | _unused_arg: u8 | +println!("not called") + ; + + let _short_unused_closure_line_break_no_block2 = + | _unused_arg: u8 | + println!( + "not called" + ) + ; + + let short_used_not_covered_closure_line_break_no_block_embedded_branch = + | _unused_arg: u8 | + println!( + "not called: {}", + if is_true { "check" } else { "me" } + ) + ; + + let short_used_not_covered_closure_line_break_block_embedded_branch = + | _unused_arg: u8 | + { + println!( + "not called: {}", + if is_true { "check" } else { "me" } + ) + } + ; + + let short_used_covered_closure_line_break_no_block_embedded_branch = + | _unused_arg: u8 | + println!( + "not called: {}", + if is_true { "check" } else { "me" } + ) + ; + + let short_used_covered_closure_line_break_block_embedded_branch = + | _unused_arg: u8 | + { + println!( + "not called: {}", + if is_true { "check" } else { "me" } + ) + } + ; + + if is_false { + short_used_not_covered_closure_macro(0); + short_used_not_covered_closure_line_break_no_block_embedded_branch(0); + short_used_not_covered_closure_line_break_block_embedded_branch(0); + } + short_used_covered_closure_macro(0); + short_used_covered_closure_line_break_no_block_embedded_branch(0); + short_used_covered_closure_line_break_block_embedded_branch(0); +} diff --git a/tests/coverage-map/status-quo/closure_macro.cov-map b/tests/coverage-map/status-quo/closure_macro.cov-map new file mode 100644 index 00000000000..ac017eb4468 --- /dev/null +++ b/tests/coverage-map/status-quo/closure_macro.cov-map @@ -0,0 +1,40 @@ +Function name: closure_macro::load_configuration_files +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1d, 01, 02, 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 + 29, 1) to (start + 2, 2) + +Function name: closure_macro::main +Raw bytes (49): 0x[01, 01, 05, 01, 05, 02, 00, 05, 00, 02, 00, 05, 02, 07, 01, 21, 01, 01, 21, 02, 02, 09, 00, 0f, 05, 00, 12, 00, 13, 07, 00, 12, 00, 13, 0b, 00, 54, 00, 55, 0f, 02, 09, 02, 0b, 13, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 2 operands: lhs = Counter(1), rhs = Zero +- expression 3 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 4 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 7 +- 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(1)) at (prev + 0, 18) to (start + 0, 19) +- Code(Expression(1, Add)) at (prev + 0, 18) to (start + 0, 19) + = ((c0 - c1) + Zero) +- Code(Expression(2, Add)) at (prev + 0, 84) to (start + 0, 85) + = (c1 + Zero) +- Code(Expression(3, Add)) at (prev + 2, 9) to (start + 2, 11) + = ((c0 - c1) + Zero) +- Code(Expression(4, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: closure_macro::main::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 23, 12, 00, 54] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 35, 18) to (start + 0, 84) + diff --git a/tests/coverage-map/status-quo/closure_macro.rs b/tests/coverage-map/status-quo/closure_macro.rs new file mode 100644 index 00000000000..9b289141c2e --- /dev/null +++ b/tests/coverage-map/status-quo/closure_macro.rs @@ -0,0 +1,40 @@ +// compile-flags: --edition=2018 +#![feature(coverage_attribute)] + +macro_rules! bail { + ($msg:literal $(,)?) => { + if $msg.len() > 0 { + println!("no msg"); + } else { + println!($msg); + } + return Err(String::from($msg)); + }; +} + +macro_rules! on_error { + ($value:expr, $error_message:expr) => { + $value.or_else(|e| { // FIXME(85000): no coverage in closure macros + let message = format!($error_message, e); + if message.len() > 0 { + println!("{}", message); + Ok(String::from("ok")) + } else { + bail!("error"); + } + }) + }; +} + +fn load_configuration_files() -> Result<String, String> { + Ok(String::from("config")) +} + +pub fn main() -> Result<(), String> { + println!("Starting service"); + let config = on_error!(load_configuration_files(), "Error loading configs: {}")?; + + let startup_delay_duration = String::from("arg"); + let _ = (config, startup_delay_duration); + Ok(()) +} diff --git a/tests/coverage-map/status-quo/closure_macro_async.cov-map b/tests/coverage-map/status-quo/closure_macro_async.cov-map new file mode 100644 index 00000000000..c9a142e5aeb --- /dev/null +++ b/tests/coverage-map/status-quo/closure_macro_async.cov-map @@ -0,0 +1,48 @@ +Function name: closure_macro_async::load_configuration_files +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1d, 01, 02, 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 + 29, 1) to (start + 2, 2) + +Function name: closure_macro_async::test +Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 01, 00, 2b] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 33, 1) to (start + 0, 43) + +Function name: closure_macro_async::test::{closure#0} +Raw bytes (49): 0x[01, 01, 05, 01, 05, 02, 00, 05, 00, 02, 00, 05, 02, 07, 01, 21, 2b, 01, 21, 02, 02, 09, 00, 0f, 05, 00, 12, 00, 13, 07, 00, 12, 00, 13, 0b, 00, 54, 00, 55, 0f, 02, 09, 02, 0b, 13, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 2 operands: lhs = Counter(1), rhs = Zero +- expression 3 operands: lhs = Expression(0, Sub), rhs = Zero +- expression 4 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 7 +- Code(Counter(0)) at (prev + 33, 43) to (start + 1, 33) +- Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 15) + = (c0 - c1) +- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 19) +- Code(Expression(1, Add)) at (prev + 0, 18) to (start + 0, 19) + = ((c0 - c1) + Zero) +- Code(Expression(2, Add)) at (prev + 0, 84) to (start + 0, 85) + = (c1 + Zero) +- Code(Expression(3, Add)) at (prev + 2, 9) to (start + 2, 11) + = ((c0 - c1) + Zero) +- Code(Expression(4, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: closure_macro_async::test::{closure#0}::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 23, 12, 00, 54] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 35, 18) to (start + 0, 84) + diff --git a/tests/coverage-map/status-quo/closure_macro_async.rs b/tests/coverage-map/status-quo/closure_macro_async.rs new file mode 100644 index 00000000000..b4275599e59 --- /dev/null +++ b/tests/coverage-map/status-quo/closure_macro_async.rs @@ -0,0 +1,77 @@ +// compile-flags: --edition=2018 +#![feature(coverage_attribute)] + +macro_rules! bail { + ($msg:literal $(,)?) => { + if $msg.len() > 0 { + println!("no msg"); + } else { + println!($msg); + } + return Err(String::from($msg)); + }; +} + +macro_rules! on_error { + ($value:expr, $error_message:expr) => { + $value.or_else(|e| { // FIXME(85000): no coverage in closure macros + let message = format!($error_message, e); + if message.len() > 0 { + println!("{}", message); + Ok(String::from("ok")) + } else { + bail!("error"); + } + }) + }; +} + +fn load_configuration_files() -> Result<String, String> { + Ok(String::from("config")) +} + +pub async fn test() -> Result<(), String> { + println!("Starting service"); + let config = on_error!(load_configuration_files(), "Error loading configs: {}")?; + + let startup_delay_duration = String::from("arg"); + let _ = (config, startup_delay_duration); + Ok(()) +} + +#[coverage(off)] +fn main() { + executor::block_on(test()).unwrap(); +} + +mod executor { + use core::{ + future::Future, + pin::Pin, + task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, + }; + + #[coverage(off)] + pub fn block_on<F: Future>(mut future: F) -> F::Output { + let mut future = unsafe { Pin::new_unchecked(&mut future) }; + use std::hint::unreachable_unchecked; + static VTABLE: RawWakerVTable = RawWakerVTable::new( + #[coverage(off)] + |_| unsafe { unreachable_unchecked() }, // clone + #[coverage(off)] + |_| unsafe { unreachable_unchecked() }, // wake + #[coverage(off)] + |_| unsafe { unreachable_unchecked() }, // wake_by_ref + #[coverage(off)] + |_| (), + ); + let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; + let mut context = Context::from_waker(&waker); + + loop { + if let Poll::Ready(val) = future.as_mut().poll(&mut context) { + break val; + } + } + } +} diff --git a/tests/coverage-map/status-quo/conditions.cov-map b/tests/coverage-map/status-quo/conditions.cov-map new file mode 100644 index 00000000000..d82b8389b4d --- /dev/null +++ b/tests/coverage-map/status-quo/conditions.cov-map @@ -0,0 +1,261 @@ +Function name: conditions::main +Raw bytes (793): 0x[01, 01, 90, 01, 09, 33, 37, 41, 3b, 3d, 35, 39, 05, 00, bf, 04, 09, 05, 00, 0d, 35, 26, 39, 0d, 35, 3b, 3d, 35, 39, 37, 41, 3b, 3d, 35, 39, ba, 04, 0d, bf, 04, 09, 05, 00, 03, 00, 45, 00, 87, 01, 49, 45, 00, 82, 01, 31, 87, 01, 49, 45, 00, 7e, 4d, 82, 01, 31, 87, 01, 49, 45, 00, 7a, 51, 7e, 4d, 82, 01, 31, 87, 01, 49, 45, 00, ab, 01, 55, 4d, 51, a7, 01, 59, ab, 01, 55, 4d, 51, 49, a3, 01, a7, 01, 59, ab, 01, 55, 4d, 51, 61, 00, e7, 01, 65, 61, 00, e2, 01, 2d, e7, 01, 65, 61, 00, de, 01, 69, e2, 01, 2d, e7, 01, 65, 61, 00, da, 01, 6d, de, 01, 69, e2, 01, 2d, e7, 01, 65, 61, 00, 8f, 02, 71, 69, 6d, 8b, 02, 75, 8f, 02, 71, 69, 6d, 83, 02, 00, 65, 87, 02, 8b, 02, 75, 8f, 02, 71, 69, 6d, 7d, f3, 03, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, 79, 00, db, 02, 7d, 79, 00, d6, 02, 29, db, 02, 7d, 79, 00, d2, 02, 81, 01, d6, 02, 29, db, 02, 7d, 79, 00, ce, 02, 85, 01, d2, 02, 81, 01, d6, 02, 29, db, 02, 7d, 79, 00, fb, 03, 89, 01, 81, 01, 85, 01, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, 11, 9b, 04, 9f, 04, 21, a3, 04, 1d, 15, 19, ef, 03, 00, 7d, f3, 03, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, ef, 03, 11, 7d, f3, 03, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, ea, 03, 25, ef, 03, 11, 7d, f3, 03, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, e6, 03, 15, ea, 03, 25, ef, 03, 11, 7d, f3, 03, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, e2, 03, 19, e6, 03, 15, ea, 03, 25, ef, 03, 11, 7d, f3, 03, f7, 03, 8d, 01, fb, 03, 89, 01, 81, 01, 85, 01, a3, 04, 1d, 15, 19, 9f, 04, 21, a3, 04, 1d, 15, 19, 97, 04, a7, 04, 11, 9b, 04, 9f, 04, 21, a3, 04, 1d, 15, 19, ab, 04, b6, 04, af, 04, b3, 04, 25, 29, 2d, 31, ba, 04, 0d, bf, 04, 09, 05, 00, 44, 01, 03, 01, 02, 0c, 05, 02, 0d, 02, 06, 00, 02, 06, 00, 07, 03, 03, 09, 00, 0a, bf, 04, 00, 10, 00, 1d, 09, 01, 09, 01, 0a, ba, 04, 02, 0f, 00, 1c, 0d, 01, 0c, 00, 19, 26, 00, 1d, 00, 2a, 22, 00, 2e, 00, 3c, 37, 00, 3d, 02, 0a, 41, 02, 0a, 00, 0b, 33, 01, 09, 01, 12, b6, 04, 03, 09, 00, 0f, 4b, 03, 09, 01, 0c, 45, 01, 0d, 02, 06, 00, 02, 06, 00, 07, 87, 01, 02, 08, 00, 15, 49, 00, 16, 02, 06, 82, 01, 02, 0f, 00, 1c, 7e, 01, 0c, 00, 19, 7a, 00, 1d, 00, 2a, 76, 00, 2e, 00, 3c, a7, 01, 00, 3d, 02, 0a, 59, 02, 0a, 00, 0b, a3, 01, 01, 09, 00, 17, 31, 02, 09, 00, 0f, 9f, 01, 03, 08, 00, 0c, 5d, 01, 0d, 01, 10, 61, 01, 11, 02, 0a, 00, 02, 0a, 00, 0b, e7, 01, 02, 0c, 00, 19, 65, 00, 1a, 02, 0a, e2, 01, 03, 11, 00, 1e, de, 01, 01, 10, 00, 1d, da, 01, 00, 21, 00, 2e, d6, 01, 00, 32, 00, 40, 8b, 02, 00, 41, 02, 0e, 75, 02, 0e, 00, 0f, 87, 02, 01, 0d, 00, 1b, 2d, 02, 0d, 00, 13, 00, 02, 06, 00, 07, ff, 01, 02, 09, 01, 0c, 79, 01, 0d, 02, 06, 00, 02, 06, 00, 07, ef, 03, 02, 09, 00, 0a, db, 02, 00, 10, 00, 1d, 7d, 00, 1e, 02, 06, d6, 02, 02, 0f, 00, 1c, d2, 02, 01, 0c, 00, 19, ce, 02, 00, 1d, 00, 2a, ca, 02, 00, 2e, 00, 3c, f7, 03, 00, 3d, 02, 0a, 8d, 01, 02, 0a, 00, 0b, f3, 03, 01, 09, 00, 17, 29, 02, 0d, 02, 0f, 97, 04, 05, 09, 00, 0a, 83, 03, 00, 10, 00, 1d, 11, 00, 1e, 02, 06, ea, 03, 02, 0f, 00, 1c, e6, 03, 01, 0c, 00, 19, e2, 03, 00, 1d, 00, 2a, de, 03, 00, 2e, 00, 3c, 9f, 04, 00, 3d, 02, 0a, 21, 02, 0a, 00, 0b, 9b, 04, 01, 09, 00, 17, 25, 02, 09, 00, 0f, 93, 04, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 144 +- expression 0 operands: lhs = Counter(2), rhs = Expression(12, Add) +- expression 1 operands: lhs = Expression(13, Add), rhs = Counter(16) +- expression 2 operands: lhs = Expression(14, Add), rhs = Counter(15) +- expression 3 operands: lhs = Counter(13), rhs = Counter(14) +- expression 4 operands: lhs = Counter(1), rhs = Zero +- expression 5 operands: lhs = Expression(143, Add), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Zero +- expression 7 operands: lhs = Counter(3), rhs = Counter(13) +- expression 8 operands: lhs = Expression(9, Sub), rhs = Counter(14) +- expression 9 operands: lhs = Counter(3), rhs = Counter(13) +- expression 10 operands: lhs = Expression(14, Add), rhs = Counter(15) +- expression 11 operands: lhs = Counter(13), rhs = Counter(14) +- expression 12 operands: lhs = Expression(13, Add), rhs = Counter(16) +- expression 13 operands: lhs = Expression(14, Add), rhs = Counter(15) +- expression 14 operands: lhs = Counter(13), rhs = Counter(14) +- expression 15 operands: lhs = Expression(142, Sub), rhs = Counter(3) +- expression 16 operands: lhs = Expression(143, Add), rhs = Counter(2) +- expression 17 operands: lhs = Counter(1), rhs = Zero +- expression 18 operands: lhs = Expression(0, Add), rhs = Zero +- expression 19 operands: lhs = Counter(17), rhs = Zero +- expression 20 operands: lhs = Expression(33, Add), rhs = Counter(18) +- expression 21 operands: lhs = Counter(17), rhs = Zero +- expression 22 operands: lhs = Expression(32, Sub), rhs = Counter(12) +- expression 23 operands: lhs = Expression(33, Add), rhs = Counter(18) +- expression 24 operands: lhs = Counter(17), rhs = Zero +- expression 25 operands: lhs = Expression(31, Sub), rhs = Counter(19) +- expression 26 operands: lhs = Expression(32, Sub), rhs = Counter(12) +- expression 27 operands: lhs = Expression(33, Add), rhs = Counter(18) +- expression 28 operands: lhs = Counter(17), rhs = Zero +- expression 29 operands: lhs = Expression(30, Sub), rhs = Counter(20) +- expression 30 operands: lhs = Expression(31, Sub), rhs = Counter(19) +- expression 31 operands: lhs = Expression(32, Sub), rhs = Counter(12) +- expression 32 operands: lhs = Expression(33, Add), rhs = Counter(18) +- expression 33 operands: lhs = Counter(17), rhs = Zero +- expression 34 operands: lhs = Expression(42, Add), rhs = Counter(21) +- expression 35 operands: lhs = Counter(19), rhs = Counter(20) +- expression 36 operands: lhs = Expression(41, Add), rhs = Counter(22) +- expression 37 operands: lhs = Expression(42, Add), rhs = Counter(21) +- expression 38 operands: lhs = Counter(19), rhs = Counter(20) +- expression 39 operands: lhs = Counter(18), rhs = Expression(40, Add) +- expression 40 operands: lhs = Expression(41, Add), rhs = Counter(22) +- expression 41 operands: lhs = Expression(42, Add), rhs = Counter(21) +- expression 42 operands: lhs = Counter(19), rhs = Counter(20) +- expression 43 operands: lhs = Counter(24), rhs = Zero +- expression 44 operands: lhs = Expression(57, Add), rhs = Counter(25) +- expression 45 operands: lhs = Counter(24), rhs = Zero +- expression 46 operands: lhs = Expression(56, Sub), rhs = Counter(11) +- expression 47 operands: lhs = Expression(57, Add), rhs = Counter(25) +- expression 48 operands: lhs = Counter(24), rhs = Zero +- expression 49 operands: lhs = Expression(55, Sub), rhs = Counter(26) +- expression 50 operands: lhs = Expression(56, Sub), rhs = Counter(11) +- expression 51 operands: lhs = Expression(57, Add), rhs = Counter(25) +- expression 52 operands: lhs = Counter(24), rhs = Zero +- expression 53 operands: lhs = Expression(54, Sub), rhs = Counter(27) +- expression 54 operands: lhs = Expression(55, Sub), rhs = Counter(26) +- expression 55 operands: lhs = Expression(56, Sub), rhs = Counter(11) +- expression 56 operands: lhs = Expression(57, Add), rhs = Counter(25) +- expression 57 operands: lhs = Counter(24), rhs = Zero +- expression 58 operands: lhs = Expression(67, Add), rhs = Counter(28) +- expression 59 operands: lhs = Counter(26), rhs = Counter(27) +- expression 60 operands: lhs = Expression(66, Add), rhs = Counter(29) +- expression 61 operands: lhs = Expression(67, Add), rhs = Counter(28) +- expression 62 operands: lhs = Counter(26), rhs = Counter(27) +- expression 63 operands: lhs = Expression(64, Add), rhs = Zero +- expression 64 operands: lhs = Counter(25), rhs = Expression(65, Add) +- expression 65 operands: lhs = Expression(66, Add), rhs = Counter(29) +- expression 66 operands: lhs = Expression(67, Add), rhs = Counter(28) +- expression 67 operands: lhs = Counter(26), rhs = Counter(27) +- expression 68 operands: lhs = Counter(31), rhs = Expression(124, Add) +- expression 69 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 70 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 71 operands: lhs = Counter(32), rhs = Counter(33) +- expression 72 operands: lhs = Counter(30), rhs = Zero +- expression 73 operands: lhs = Expression(86, Add), rhs = Counter(31) +- expression 74 operands: lhs = Counter(30), rhs = Zero +- expression 75 operands: lhs = Expression(85, Sub), rhs = Counter(10) +- expression 76 operands: lhs = Expression(86, Add), rhs = Counter(31) +- expression 77 operands: lhs = Counter(30), rhs = Zero +- expression 78 operands: lhs = Expression(84, Sub), rhs = Counter(32) +- expression 79 operands: lhs = Expression(85, Sub), rhs = Counter(10) +- expression 80 operands: lhs = Expression(86, Add), rhs = Counter(31) +- expression 81 operands: lhs = Counter(30), rhs = Zero +- expression 82 operands: lhs = Expression(83, Sub), rhs = Counter(33) +- expression 83 operands: lhs = Expression(84, Sub), rhs = Counter(32) +- expression 84 operands: lhs = Expression(85, Sub), rhs = Counter(10) +- expression 85 operands: lhs = Expression(86, Add), rhs = Counter(31) +- expression 86 operands: lhs = Counter(30), rhs = Zero +- expression 87 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 88 operands: lhs = Counter(32), rhs = Counter(33) +- expression 89 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 90 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 91 operands: lhs = Counter(32), rhs = Counter(33) +- expression 92 operands: lhs = Counter(4), rhs = Expression(134, Add) +- expression 93 operands: lhs = Expression(135, Add), rhs = Counter(8) +- expression 94 operands: lhs = Expression(136, Add), rhs = Counter(7) +- expression 95 operands: lhs = Counter(5), rhs = Counter(6) +- expression 96 operands: lhs = Expression(123, Add), rhs = Zero +- expression 97 operands: lhs = Counter(31), rhs = Expression(124, Add) +- expression 98 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 99 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 100 operands: lhs = Counter(32), rhs = Counter(33) +- expression 101 operands: lhs = Expression(123, Add), rhs = Counter(4) +- expression 102 operands: lhs = Counter(31), rhs = Expression(124, Add) +- expression 103 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 104 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 105 operands: lhs = Counter(32), rhs = Counter(33) +- expression 106 operands: lhs = Expression(122, Sub), rhs = Counter(9) +- expression 107 operands: lhs = Expression(123, Add), rhs = Counter(4) +- expression 108 operands: lhs = Counter(31), rhs = Expression(124, Add) +- expression 109 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 110 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 111 operands: lhs = Counter(32), rhs = Counter(33) +- expression 112 operands: lhs = Expression(121, Sub), rhs = Counter(5) +- expression 113 operands: lhs = Expression(122, Sub), rhs = Counter(9) +- expression 114 operands: lhs = Expression(123, Add), rhs = Counter(4) +- expression 115 operands: lhs = Counter(31), rhs = Expression(124, Add) +- expression 116 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 117 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 118 operands: lhs = Counter(32), rhs = Counter(33) +- expression 119 operands: lhs = Expression(120, Sub), rhs = Counter(6) +- expression 120 operands: lhs = Expression(121, Sub), rhs = Counter(5) +- expression 121 operands: lhs = Expression(122, Sub), rhs = Counter(9) +- expression 122 operands: lhs = Expression(123, Add), rhs = Counter(4) +- expression 123 operands: lhs = Counter(31), rhs = Expression(124, Add) +- expression 124 operands: lhs = Expression(125, Add), rhs = Counter(35) +- expression 125 operands: lhs = Expression(126, Add), rhs = Counter(34) +- expression 126 operands: lhs = Counter(32), rhs = Counter(33) +- expression 127 operands: lhs = Expression(136, Add), rhs = Counter(7) +- expression 128 operands: lhs = Counter(5), rhs = Counter(6) +- expression 129 operands: lhs = Expression(135, Add), rhs = Counter(8) +- expression 130 operands: lhs = Expression(136, Add), rhs = Counter(7) +- expression 131 operands: lhs = Counter(5), rhs = Counter(6) +- expression 132 operands: lhs = Expression(133, Add), rhs = Expression(137, Add) +- expression 133 operands: lhs = Counter(4), rhs = Expression(134, Add) +- expression 134 operands: lhs = Expression(135, Add), rhs = Counter(8) +- expression 135 operands: lhs = Expression(136, Add), rhs = Counter(7) +- expression 136 operands: lhs = Counter(5), rhs = Counter(6) +- expression 137 operands: lhs = Expression(138, Add), rhs = Expression(141, Sub) +- expression 138 operands: lhs = Expression(139, Add), rhs = Expression(140, Add) +- expression 139 operands: lhs = Counter(9), rhs = Counter(10) +- expression 140 operands: lhs = Counter(11), rhs = Counter(12) +- expression 141 operands: lhs = Expression(142, Sub), rhs = Counter(3) +- expression 142 operands: lhs = Expression(143, Add), rhs = Counter(2) +- expression 143 operands: lhs = Counter(1), rhs = Zero +Number of file 0 mappings: 68 +- Code(Counter(0)) at (prev + 3, 1) to (start + 2, 12) +- Code(Counter(1)) at (prev + 2, 13) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(0, Add)) at (prev + 3, 9) to (start + 0, 10) + = (c2 + (((c13 + c14) + c15) + c16)) +- Code(Expression(143, Add)) at (prev + 0, 16) to (start + 0, 29) + = (c1 + Zero) +- Code(Counter(2)) at (prev + 1, 9) to (start + 1, 10) +- Code(Expression(142, Sub)) at (prev + 2, 15) to (start + 0, 28) + = ((c1 + Zero) - c2) +- Code(Counter(3)) at (prev + 1, 12) to (start + 0, 25) +- Code(Expression(9, Sub)) at (prev + 0, 29) to (start + 0, 42) + = (c3 - c13) +- Code(Expression(8, Sub)) at (prev + 0, 46) to (start + 0, 60) + = ((c3 - c13) - c14) +- Code(Expression(13, Add)) at (prev + 0, 61) to (start + 2, 10) + = ((c13 + c14) + c15) +- Code(Counter(16)) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(12, Add)) at (prev + 1, 9) to (start + 1, 18) + = (((c13 + c14) + c15) + c16) +- Code(Expression(141, Sub)) at (prev + 3, 9) to (start + 0, 15) + = (((c1 + Zero) - c2) - c3) +- Code(Expression(18, Add)) at (prev + 3, 9) to (start + 1, 12) + = ((c2 + (((c13 + c14) + c15) + c16)) + Zero) +- Code(Counter(17)) at (prev + 1, 13) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(33, Add)) at (prev + 2, 8) to (start + 0, 21) + = (c17 + Zero) +- Code(Counter(18)) at (prev + 0, 22) to (start + 2, 6) +- Code(Expression(32, Sub)) at (prev + 2, 15) to (start + 0, 28) + = ((c17 + Zero) - c18) +- Code(Expression(31, Sub)) at (prev + 1, 12) to (start + 0, 25) + = (((c17 + Zero) - c18) - c12) +- Code(Expression(30, Sub)) at (prev + 0, 29) to (start + 0, 42) + = ((((c17 + Zero) - c18) - c12) - c19) +- Code(Expression(29, Sub)) at (prev + 0, 46) to (start + 0, 60) + = (((((c17 + Zero) - c18) - c12) - c19) - c20) +- Code(Expression(41, Add)) at (prev + 0, 61) to (start + 2, 10) + = ((c19 + c20) + c21) +- Code(Counter(22)) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(40, Add)) at (prev + 1, 9) to (start + 0, 23) + = (((c19 + c20) + c21) + c22) +- Code(Counter(12)) at (prev + 2, 9) to (start + 0, 15) +- Code(Expression(39, Add)) at (prev + 3, 8) to (start + 0, 12) + = (c18 + (((c19 + c20) + c21) + c22)) +- Code(Counter(23)) at (prev + 1, 13) to (start + 1, 16) +- Code(Counter(24)) at (prev + 1, 17) to (start + 2, 10) +- Code(Zero) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(57, Add)) at (prev + 2, 12) to (start + 0, 25) + = (c24 + Zero) +- Code(Counter(25)) at (prev + 0, 26) to (start + 2, 10) +- Code(Expression(56, Sub)) at (prev + 3, 17) to (start + 0, 30) + = ((c24 + Zero) - c25) +- Code(Expression(55, Sub)) at (prev + 1, 16) to (start + 0, 29) + = (((c24 + Zero) - c25) - c11) +- Code(Expression(54, Sub)) at (prev + 0, 33) to (start + 0, 46) + = ((((c24 + Zero) - c25) - c11) - c26) +- Code(Expression(53, Sub)) at (prev + 0, 50) to (start + 0, 64) + = (((((c24 + Zero) - c25) - c11) - c26) - c27) +- Code(Expression(66, Add)) at (prev + 0, 65) to (start + 2, 14) + = ((c26 + c27) + c28) +- Code(Counter(29)) at (prev + 2, 14) to (start + 0, 15) +- Code(Expression(65, Add)) at (prev + 1, 13) to (start + 0, 27) + = (((c26 + c27) + c28) + c29) +- Code(Counter(11)) at (prev + 2, 13) to (start + 0, 19) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(63, Add)) at (prev + 2, 9) to (start + 1, 12) + = ((c25 + (((c26 + c27) + c28) + c29)) + Zero) +- Code(Counter(30)) at (prev + 1, 13) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(123, Add)) at (prev + 2, 9) to (start + 0, 10) + = (c31 + (((c32 + c33) + c34) + c35)) +- Code(Expression(86, Add)) at (prev + 0, 16) to (start + 0, 29) + = (c30 + Zero) +- Code(Counter(31)) at (prev + 0, 30) to (start + 2, 6) +- Code(Expression(85, Sub)) at (prev + 2, 15) to (start + 0, 28) + = ((c30 + Zero) - c31) +- Code(Expression(84, Sub)) at (prev + 1, 12) to (start + 0, 25) + = (((c30 + Zero) - c31) - c10) +- Code(Expression(83, Sub)) at (prev + 0, 29) to (start + 0, 42) + = ((((c30 + Zero) - c31) - c10) - c32) +- Code(Expression(82, Sub)) at (prev + 0, 46) to (start + 0, 60) + = (((((c30 + Zero) - c31) - c10) - c32) - c33) +- Code(Expression(125, Add)) at (prev + 0, 61) to (start + 2, 10) + = ((c32 + c33) + c34) +- Code(Counter(35)) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(124, Add)) at (prev + 1, 9) to (start + 0, 23) + = (((c32 + c33) + c34) + c35) +- Code(Counter(10)) at (prev + 2, 13) to (start + 2, 15) +- Code(Expression(133, Add)) at (prev + 5, 9) to (start + 0, 10) + = (c4 + (((c5 + c6) + c7) + c8)) +- Code(Expression(96, Add)) at (prev + 0, 16) to (start + 0, 29) + = ((c31 + (((c32 + c33) + c34) + c35)) + Zero) +- Code(Counter(4)) at (prev + 0, 30) to (start + 2, 6) +- Code(Expression(122, Sub)) at (prev + 2, 15) to (start + 0, 28) + = ((c31 + (((c32 + c33) + c34) + c35)) - c4) +- Code(Expression(121, Sub)) at (prev + 1, 12) to (start + 0, 25) + = (((c31 + (((c32 + c33) + c34) + c35)) - c4) - c9) +- Code(Expression(120, Sub)) at (prev + 0, 29) to (start + 0, 42) + = ((((c31 + (((c32 + c33) + c34) + c35)) - c4) - c9) - c5) +- Code(Expression(119, Sub)) at (prev + 0, 46) to (start + 0, 60) + = (((((c31 + (((c32 + c33) + c34) + c35)) - c4) - c9) - c5) - c6) +- Code(Expression(135, Add)) at (prev + 0, 61) to (start + 2, 10) + = ((c5 + c6) + c7) +- Code(Counter(8)) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(134, Add)) at (prev + 1, 9) to (start + 0, 23) + = (((c5 + c6) + c7) + c8) +- Code(Counter(9)) at (prev + 2, 9) to (start + 0, 15) +- Code(Expression(132, Add)) at (prev + 2, 1) to (start + 0, 2) + = ((c4 + (((c5 + c6) + c7) + c8)) + (((c9 + c10) + (c11 + c12)) + (((c1 + Zero) - c2) - c3))) + diff --git a/tests/coverage-map/status-quo/conditions.rs b/tests/coverage-map/status-quo/conditions.rs new file mode 100644 index 00000000000..fa7f2a116c2 --- /dev/null +++ b/tests/coverage-map/status-quo/conditions.rs @@ -0,0 +1,86 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + let mut countdown = 0; + if true { + countdown = 10; + } + + const B: u32 = 100; + let x = if countdown > 7 { + countdown -= 4; + B + } else if countdown > 2 { + if countdown < 1 || countdown > 5 || countdown != 9 { + countdown = 0; + } + countdown -= 5; + countdown + } else { + return; + }; + + let mut countdown = 0; + if true { + countdown = 10; + } + + if countdown > 7 { + countdown -= 4; + } else if countdown > 2 { + if countdown < 1 || countdown > 5 || countdown != 9 { + countdown = 0; + } + countdown -= 5; + } else { + return; + } + + if true { + let mut countdown = 0; + if true { + countdown = 10; + } + + if countdown > 7 { + countdown -= 4; + } + else if countdown > 2 { + if countdown < 1 || countdown > 5 || countdown != 9 { + countdown = 0; + } + countdown -= 5; + } else { + return; + } + } + + let mut countdown = 0; + if true { + countdown = 1; + } + + let z = if countdown > 7 { + countdown -= 4; + } else if countdown > 2 { + if countdown < 1 || countdown > 5 || countdown != 9 { + countdown = 0; + } + countdown -= 5; + } else { + let should_be_reachable = countdown; + println!("reached"); + return; + }; + + let w = if countdown > 7 { + countdown -= 4; + } else if countdown > 2 { + if countdown < 1 || countdown > 5 || countdown != 9 { + countdown = 0; + } + countdown -= 5; + } else { + return; + }; +} diff --git a/tests/coverage-map/status-quo/continue.cov-map b/tests/coverage-map/status-quo/continue.cov-map new file mode 100644 index 00000000000..c78cf293079 --- /dev/null +++ b/tests/coverage-map/status-quo/continue.cov-map @@ -0,0 +1,85 @@ +Function name: continue::main +Raw bytes (216): 0x[01, 01, 1f, 01, 07, 05, 09, 03, 0d, 0d, 1f, 11, 15, 1b, 19, 0d, 1f, 11, 15, 15, 00, 19, 37, 1d, 21, 33, 25, 19, 37, 1d, 21, 1d, 00, 25, 4f, 29, 2d, 4b, 31, 25, 4f, 29, 2d, 31, 67, 35, 39, 5f, 3d, 31, 67, 35, 39, 35, 39, 3d, 41, 73, 45, 3d, 41, 41, 00, 49, 45, 1e, 01, 03, 01, 03, 12, 03, 04, 0e, 00, 13, 0a, 01, 0f, 00, 16, 05, 02, 11, 00, 19, 09, 02, 12, 04, 0e, 1b, 06, 0e, 00, 13, 16, 01, 0f, 00, 16, 15, 01, 16, 02, 0e, 11, 04, 11, 00, 19, 23, 03, 09, 00, 0e, 33, 02, 0e, 00, 13, 2e, 01, 0f, 00, 16, 1d, 01, 15, 02, 0e, 21, 04, 11, 00, 19, 3b, 03, 09, 00, 0e, 4b, 02, 0e, 00, 13, 46, 01, 0c, 00, 13, 29, 01, 0d, 00, 15, 2d, 01, 0a, 01, 0e, 5f, 03, 0e, 00, 13, 5a, 01, 0f, 00, 16, 39, 01, 16, 02, 0e, 35, 03, 12, 02, 0e, 67, 04, 09, 00, 0e, 73, 02, 0e, 00, 13, 6e, 01, 0f, 00, 16, 41, 01, 16, 02, 0e, 49, 04, 11, 00, 16, 77, 03, 09, 00, 0e, 7b, 02, 0d, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 31 +- expression 0 operands: lhs = Counter(0), rhs = Expression(1, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Counter(3), rhs = Expression(7, Add) +- expression 4 operands: lhs = Counter(4), rhs = Counter(5) +- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(6) +- expression 6 operands: lhs = Counter(3), rhs = Expression(7, Add) +- expression 7 operands: lhs = Counter(4), rhs = Counter(5) +- expression 8 operands: lhs = Counter(5), rhs = Zero +- expression 9 operands: lhs = Counter(6), rhs = Expression(13, Add) +- expression 10 operands: lhs = Counter(7), rhs = Counter(8) +- expression 11 operands: lhs = Expression(12, Add), rhs = Counter(9) +- expression 12 operands: lhs = Counter(6), rhs = Expression(13, Add) +- expression 13 operands: lhs = Counter(7), rhs = Counter(8) +- expression 14 operands: lhs = Counter(7), rhs = Zero +- expression 15 operands: lhs = Counter(9), rhs = Expression(19, Add) +- expression 16 operands: lhs = Counter(10), rhs = Counter(11) +- expression 17 operands: lhs = Expression(18, Add), rhs = Counter(12) +- expression 18 operands: lhs = Counter(9), rhs = Expression(19, Add) +- expression 19 operands: lhs = Counter(10), rhs = Counter(11) +- expression 20 operands: lhs = Counter(12), rhs = Expression(25, Add) +- expression 21 operands: lhs = Counter(13), rhs = Counter(14) +- expression 22 operands: lhs = Expression(23, Add), rhs = Counter(15) +- expression 23 operands: lhs = Counter(12), rhs = Expression(25, Add) +- expression 24 operands: lhs = Counter(13), rhs = Counter(14) +- expression 25 operands: lhs = Counter(13), rhs = Counter(14) +- expression 26 operands: lhs = Counter(15), rhs = Counter(16) +- expression 27 operands: lhs = Expression(28, Add), rhs = Counter(17) +- expression 28 operands: lhs = Counter(15), rhs = Counter(16) +- expression 29 operands: lhs = Counter(16), rhs = Zero +- expression 30 operands: lhs = Counter(18), rhs = Counter(17) +Number of file 0 mappings: 30 +- Code(Counter(0)) at (prev + 3, 1) to (start + 3, 18) +- Code(Expression(0, Add)) at (prev + 4, 14) to (start + 0, 19) + = (c0 + (c1 + c2)) +- Code(Expression(2, Sub)) at (prev + 1, 15) to (start + 0, 22) + = ((c0 + (c1 + c2)) - c3) +- Code(Counter(1)) at (prev + 2, 17) to (start + 0, 25) +- Code(Counter(2)) at (prev + 2, 18) to (start + 4, 14) +- Code(Expression(6, Add)) at (prev + 6, 14) to (start + 0, 19) + = (c3 + (c4 + c5)) +- Code(Expression(5, Sub)) at (prev + 1, 15) to (start + 0, 22) + = ((c3 + (c4 + c5)) - c6) +- Code(Counter(5)) at (prev + 1, 22) to (start + 2, 14) +- Code(Counter(4)) at (prev + 4, 17) to (start + 0, 25) +- Code(Expression(8, Add)) at (prev + 3, 9) to (start + 0, 14) + = (c5 + Zero) +- Code(Expression(12, Add)) at (prev + 2, 14) to (start + 0, 19) + = (c6 + (c7 + c8)) +- Code(Expression(11, Sub)) at (prev + 1, 15) to (start + 0, 22) + = ((c6 + (c7 + c8)) - c9) +- Code(Counter(7)) at (prev + 1, 21) to (start + 2, 14) +- Code(Counter(8)) at (prev + 4, 17) to (start + 0, 25) +- Code(Expression(14, Add)) at (prev + 3, 9) to (start + 0, 14) + = (c7 + Zero) +- Code(Expression(18, Add)) at (prev + 2, 14) to (start + 0, 19) + = (c9 + (c10 + c11)) +- Code(Expression(17, Sub)) at (prev + 1, 12) to (start + 0, 19) + = ((c9 + (c10 + c11)) - c12) +- Code(Counter(10)) at (prev + 1, 13) to (start + 0, 21) +- Code(Counter(11)) at (prev + 1, 10) to (start + 1, 14) +- Code(Expression(23, Add)) at (prev + 3, 14) to (start + 0, 19) + = (c12 + (c13 + c14)) +- Code(Expression(22, Sub)) at (prev + 1, 15) to (start + 0, 22) + = ((c12 + (c13 + c14)) - c15) +- Code(Counter(14)) at (prev + 1, 22) to (start + 2, 14) +- Code(Counter(13)) at (prev + 3, 18) to (start + 2, 14) +- Code(Expression(25, Add)) at (prev + 4, 9) to (start + 0, 14) + = (c13 + c14) +- Code(Expression(28, Add)) at (prev + 2, 14) to (start + 0, 19) + = (c15 + c16) +- Code(Expression(27, Sub)) at (prev + 1, 15) to (start + 0, 22) + = ((c15 + c16) - c17) +- Code(Counter(16)) at (prev + 1, 22) to (start + 2, 14) +- Code(Counter(18)) at (prev + 4, 17) to (start + 0, 22) +- Code(Expression(29, Add)) at (prev + 3, 9) to (start + 0, 14) + = (c16 + Zero) +- Code(Expression(30, Add)) at (prev + 2, 13) to (start + 1, 2) + = (c18 + c17) + diff --git a/tests/coverage-map/status-quo/continue.rs b/tests/coverage-map/status-quo/continue.rs new file mode 100644 index 00000000000..624aa98341b --- /dev/null +++ b/tests/coverage-map/status-quo/continue.rs @@ -0,0 +1,69 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + let is_true = std::env::args().len() == 1; + + let mut x = 0; + for _ in 0..10 { + match is_true { + true => { + continue; + } + _ => { + x = 1; + } + } + x = 3; + } + for _ in 0..10 { + match is_true { + false => { + x = 1; + } + _ => { + continue; + } + } + x = 3; + } + for _ in 0..10 { + match is_true { + true => { + x = 1; + } + _ => { + continue; + } + } + x = 3; + } + for _ in 0..10 { + if is_true { + continue; + } + x = 3; + } + for _ in 0..10 { + match is_true { + false => { + x = 1; + } + _ => { + let _ = x; + } + } + x = 3; + } + for _ in 0..10 { + match is_true { + false => { + x = 1; + } + _ => { + break; + } + } + x = 3; + } + let _ = x; +} diff --git a/tests/coverage-map/status-quo/dead_code.cov-map b/tests/coverage-map/status-quo/dead_code.cov-map new file mode 100644 index 00000000000..8d5f88e63ef --- /dev/null +++ b/tests/coverage-map/status-quo/dead_code.cov-map @@ -0,0 +1,37 @@ +Function name: dead_code::main +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 1b, 01, 07, 0f, 05, 07, 10, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 27, 1) to (start + 7, 15) +- Code(Counter(1)) at (prev + 7, 16) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: dead_code::unused_fn (unused) +Raw bytes (24): 0x[01, 01, 00, 04, 01, 0f, 01, 07, 0f, 00, 07, 10, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 15, 1) to (start + 7, 15) +- Code(Zero) at (prev + 7, 16) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Zero) at (prev + 1, 1) to (start + 0, 2) + +Function name: dead_code::unused_pub_fn_not_in_library (unused) +Raw bytes (24): 0x[01, 01, 00, 04, 01, 03, 01, 07, 0f, 00, 07, 10, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 3, 1) to (start + 7, 15) +- Code(Zero) at (prev + 7, 16) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Zero) at (prev + 1, 1) to (start + 0, 2) + diff --git a/tests/coverage-map/status-quo/dead_code.rs b/tests/coverage-map/status-quo/dead_code.rs new file mode 100644 index 00000000000..3492712a6f9 --- /dev/null +++ b/tests/coverage-map/status-quo/dead_code.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused_assignments, unused_variables)] + +pub fn unused_pub_fn_not_in_library() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 0; + if is_true { + countdown = 10; + } +} + +fn unused_fn() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 0; + if is_true { + countdown = 10; + } +} + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 0; + if is_true { + countdown = 10; + } +} diff --git a/tests/coverage-map/status-quo/drop_trait.cov-map b/tests/coverage-map/status-quo/drop_trait.cov-map new file mode 100644 index 00000000000..203d1048b05 --- /dev/null +++ b/tests/coverage-map/status-quo/drop_trait.cov-map @@ -0,0 +1,21 @@ +Function name: <drop_trait::Firework as core::ops::drop::Drop>::drop +Raw bytes (9): 0x[01, 01, 00, 01, 01, 09, 05, 02, 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 + 9, 5) to (start + 2, 6) + +Function name: drop_trait::main +Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 0e, 01, 05, 0c, 05, 06, 09, 01, 16, 00, 02, 06, 04, 0b, 03, 05, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 1 +- expression 0 operands: lhs = Counter(1), rhs = Zero +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 14, 1) to (start + 5, 12) +- Code(Counter(1)) at (prev + 6, 9) to (start + 1, 22) +- Code(Zero) at (prev + 2, 6) to (start + 4, 11) +- Code(Expression(0, Add)) at (prev + 5, 1) to (start + 0, 2) + = (c1 + Zero) + diff --git a/tests/coverage-map/status-quo/drop_trait.rs b/tests/coverage-map/status-quo/drop_trait.rs new file mode 100644 index 00000000000..7b062719c6b --- /dev/null +++ b/tests/coverage-map/status-quo/drop_trait.rs @@ -0,0 +1,33 @@ +#![allow(unused_assignments)] +// failure-status: 1 + +struct Firework { + strength: i32, +} + +impl Drop for Firework { + fn drop(&mut self) { + println!("BOOM times {}!!!", self.strength); + } +} + +fn main() -> Result<(), u8> { + let _firecracker = Firework { strength: 1 }; + + let _tnt = Firework { strength: 100 }; + + if true { + println!("Exiting with error..."); + return Err(1); + } + + let _ = Firework { strength: 1000 }; + + Ok(()) +} + +// Expected program output: +// Exiting with error... +// BOOM times 100!!! +// BOOM times 1!!! +// Error: 1 diff --git a/tests/coverage-map/status-quo/generator.cov-map b/tests/coverage-map/status-quo/generator.cov-map new file mode 100644 index 00000000000..6e10b58a941 --- /dev/null +++ b/tests/coverage-map/status-quo/generator.cov-map @@ -0,0 +1,58 @@ +Function name: generator::get_u32 +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0b, 01, 01, 0b, 05, 01, 0e, 00, 13, 02, 00, 1d, 00, 3c, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 11, 1) to (start + 1, 11) +- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 19) +- Code(Expression(0, Sub)) at (prev + 0, 29) to (start + 0, 60) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: generator::main +Raw bytes (71): 0x[01, 01, 0b, 01, 00, 05, 0b, 09, 0d, 11, 00, 11, 15, 2a, 19, 11, 15, 15, 19, 26, 00, 2a, 19, 11, 15, 09, 01, 0f, 01, 02, 19, 03, 07, 0b, 00, 2e, 11, 01, 2b, 00, 2d, 07, 01, 0e, 00, 35, 0f, 02, 0b, 00, 2e, 2a, 01, 22, 00, 27, 26, 00, 2c, 00, 2e, 1f, 01, 0e, 00, 35, 23, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 11 +- expression 0 operands: lhs = Counter(0), rhs = Zero +- expression 1 operands: lhs = Counter(1), rhs = Expression(2, Add) +- expression 2 operands: lhs = Counter(2), rhs = Counter(3) +- expression 3 operands: lhs = Counter(4), rhs = Zero +- expression 4 operands: lhs = Counter(4), rhs = Counter(5) +- expression 5 operands: lhs = Expression(10, Sub), rhs = Counter(6) +- expression 6 operands: lhs = Counter(4), rhs = Counter(5) +- expression 7 operands: lhs = Counter(5), rhs = Counter(6) +- expression 8 operands: lhs = Expression(9, Sub), rhs = Zero +- expression 9 operands: lhs = Expression(10, Sub), rhs = Counter(6) +- expression 10 operands: lhs = Counter(4), rhs = Counter(5) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 15, 1) to (start + 2, 25) +- Code(Expression(0, Add)) at (prev + 7, 11) to (start + 0, 46) + = (c0 + Zero) +- Code(Counter(4)) at (prev + 1, 43) to (start + 0, 45) +- Code(Expression(1, Add)) at (prev + 1, 14) to (start + 0, 53) + = (c1 + (c2 + c3)) +- Code(Expression(3, Add)) at (prev + 2, 11) to (start + 0, 46) + = (c4 + Zero) +- Code(Expression(10, Sub)) at (prev + 1, 34) to (start + 0, 39) + = (c4 - c5) +- Code(Expression(9, Sub)) at (prev + 0, 44) to (start + 0, 46) + = ((c4 - c5) - c6) +- Code(Expression(7, Add)) at (prev + 1, 14) to (start + 0, 53) + = (c5 + c6) +- Code(Expression(8, Add)) at (prev + 2, 1) to (start + 0, 2) + = (((c4 - c5) - c6) + Zero) + +Function name: generator::main::{closure#0} +Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 1c, 01, 1f, 05, 02, 10, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 17, 28) to (start + 1, 31) +- Code(Counter(1)) at (prev + 2, 16) to (start + 1, 6) + diff --git a/tests/coverage-map/status-quo/generator.rs b/tests/coverage-map/status-quo/generator.rs new file mode 100644 index 00000000000..4319991021e --- /dev/null +++ b/tests/coverage-map/status-quo/generator.rs @@ -0,0 +1,30 @@ +#![feature(generators, generator_trait)] + +use std::ops::{Generator, GeneratorState}; +use std::pin::Pin; + +// The following implementation of a function called from a `yield` statement +// (apparently requiring the Result and the `String` type or constructor) +// creates conditions where the `generator::StateTransform` MIR transform will +// drop all `Counter` `Coverage` statements from a MIR. `simplify.rs` has logic +// to handle this condition, and still report dead block coverage. +fn get_u32(val: bool) -> Result<u32, String> { + if val { Ok(1) } else { Err(String::from("some error")) } +} + +fn main() { + let is_true = std::env::args().len() == 1; + let mut generator = || { + yield get_u32(is_true); + return "foo"; + }; + + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(Ok(1)) => {} + _ => panic!("unexpected return from resume"), + } + match Pin::new(&mut generator).resume(()) { + GeneratorState::Complete("foo") => {} + _ => panic!("unexpected return from resume"), + } +} diff --git a/tests/coverage-map/status-quo/generics.cov-map b/tests/coverage-map/status-quo/generics.cov-map new file mode 100644 index 00000000000..6079a433cd0 --- /dev/null +++ b/tests/coverage-map/status-quo/generics.cov-map @@ -0,0 +1,45 @@ +Function name: <generics::Firework<f64> as core::ops::drop::Drop>::drop +Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 05, 02, 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 + 17, 5) to (start + 2, 6) + +Function name: <generics::Firework<f64>>::set_strength +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 05, 02, 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 + 10, 5) to (start + 2, 6) + +Function name: <generics::Firework<i32> as core::ops::drop::Drop>::drop +Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 05, 02, 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 + 17, 5) to (start + 2, 6) + +Function name: <generics::Firework<i32>>::set_strength +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 05, 02, 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 + 10, 5) to (start + 2, 6) + +Function name: generics::main +Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 16, 01, 08, 0c, 05, 09, 09, 01, 16, 00, 02, 06, 04, 0b, 03, 05, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 1 +- expression 0 operands: lhs = Counter(1), rhs = Zero +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 22, 1) to (start + 8, 12) +- Code(Counter(1)) at (prev + 9, 9) to (start + 1, 22) +- Code(Zero) at (prev + 2, 6) to (start + 4, 11) +- Code(Expression(0, Add)) at (prev + 5, 1) to (start + 0, 2) + = (c1 + Zero) + diff --git a/tests/coverage-map/status-quo/generics.rs b/tests/coverage-map/status-quo/generics.rs new file mode 100644 index 00000000000..bf4c2d8d685 --- /dev/null +++ b/tests/coverage-map/status-quo/generics.rs @@ -0,0 +1,44 @@ +#![allow(unused_assignments)] +// failure-status: 1 + +struct Firework<T> where T: Copy + std::fmt::Display { + strength: T, +} + +impl<T> Firework<T> where T: Copy + std::fmt::Display { + #[inline(always)] + fn set_strength(&mut self, new_strength: T) { + self.strength = new_strength; + } +} + +impl<T> Drop for Firework<T> where T: Copy + std::fmt::Display { + #[inline(always)] + fn drop(&mut self) { + println!("BOOM times {}!!!", self.strength); + } +} + +fn main() -> Result<(), u8> { + let mut firecracker = Firework { strength: 1 }; + firecracker.set_strength(2); + + let mut tnt = Firework { strength: 100.1 }; + tnt.set_strength(200.1); + tnt.set_strength(300.3); + + if true { + println!("Exiting with error..."); + return Err(1); + } + + let _ = Firework { strength: 1000 }; + + Ok(()) +} + +// Expected program output: +// Exiting with error... +// BOOM times 100!!! +// BOOM times 1!!! +// Error: 1 diff --git a/tests/coverage-map/status-quo/if.cov-map b/tests/coverage-map/status-quo/if.cov-map new file mode 100644 index 00000000000..391a69e0e82 --- /dev/null +++ b/tests/coverage-map/status-quo/if.cov-map @@ -0,0 +1,15 @@ +Function name: if::main +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 03, 01, 12, 10, 05, 13, 05, 05, 06, 02, 05, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 3, 1) to (start + 18, 16) +- Code(Counter(1)) at (prev + 19, 5) to (start + 5, 6) +- Code(Expression(0, Sub)) at (prev + 5, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + diff --git a/tests/coverage-map/status-quo/if.rs b/tests/coverage-map/status-quo/if.rs new file mode 100644 index 00000000000..8ad5042ff7b --- /dev/null +++ b/tests/coverage-map/status-quo/if.rs @@ -0,0 +1,28 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let + is_true + = + std::env::args().len() + == + 1 + ; + let + mut + countdown + = + 0 + ; + if + is_true + { + countdown + = + 10 + ; + } +} diff --git a/tests/coverage-map/status-quo/if_else.cov-map b/tests/coverage-map/status-quo/if_else.cov-map new file mode 100644 index 00000000000..da692ca3aa2 --- /dev/null +++ b/tests/coverage-map/status-quo/if_else.cov-map @@ -0,0 +1,25 @@ +Function name: if_else::main +Raw bytes (53): 0x[01, 01, 07, 01, 05, 05, 02, 1b, 09, 05, 02, 09, 16, 1b, 09, 05, 02, 07, 01, 03, 01, 08, 10, 05, 09, 05, 05, 06, 02, 08, 09, 02, 10, 1b, 06, 09, 00, 10, 09, 01, 05, 05, 06, 16, 07, 05, 05, 06, 13, 06, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 7 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Expression(6, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Sub) +- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 7 +- Code(Counter(0)) at (prev + 3, 1) to (start + 8, 16) +- Code(Counter(1)) at (prev + 9, 5) to (start + 5, 6) +- Code(Expression(0, Sub)) at (prev + 8, 9) to (start + 2, 16) + = (c0 - c1) +- Code(Expression(6, Add)) at (prev + 6, 9) to (start + 0, 16) + = (c1 + (c0 - c1)) +- Code(Counter(2)) at (prev + 1, 5) to (start + 5, 6) +- Code(Expression(5, Sub)) at (prev + 7, 5) to (start + 5, 6) + = ((c1 + (c0 - c1)) - c2) +- Code(Expression(4, Add)) at (prev + 6, 1) to (start + 0, 2) + = (c2 + ((c1 + (c0 - c1)) - c2)) + diff --git a/tests/coverage-map/status-quo/if_else.rs b/tests/coverage-map/status-quo/if_else.rs new file mode 100644 index 00000000000..3244e1e3afd --- /dev/null +++ b/tests/coverage-map/status-quo/if_else.rs @@ -0,0 +1,40 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 0; + if + is_true + { + countdown + = + 10 + ; + } + else // Note coverage region difference without semicolon + { + countdown + = + 100 + } + + if + is_true + { + countdown + = + 10 + ; + } + else + { + countdown + = + 100 + ; + } +} diff --git a/tests/coverage-map/status-quo/inline-dead.cov-map b/tests/coverage-map/status-quo/inline-dead.cov-map new file mode 100644 index 00000000000..dec43d3e8bb --- /dev/null +++ b/tests/coverage-map/status-quo/inline-dead.cov-map @@ -0,0 +1,45 @@ +Function name: inline_dead::dead (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 19, 01, 02, 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 + 25, 1) to (start + 2, 2) + +Function name: inline_dead::live::<false> +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 10, 01, 01, 09, 00, 02, 09, 00, 0f, 02, 02, 09, 00, 0a, 07, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 9) +- Code(Zero) at (prev + 2, 9) to (start + 0, 15) +- Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 10) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: inline_dead::main +Raw bytes (16): 0x[01, 01, 01, 01, 00, 02, 01, 04, 01, 03, 0d, 03, 07, 06, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 1 +- expression 0 operands: lhs = Counter(0), rhs = Zero +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 4, 1) to (start + 3, 13) +- Code(Expression(0, Add)) at (prev + 7, 6) to (start + 2, 2) + = (c0 + Zero) + +Function name: inline_dead::main::{closure#0} +Raw bytes (16): 0x[01, 01, 01, 01, 05, 02, 00, 09, 0d, 00, 0e, 03, 02, 05, 00, 06] +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: 2 +- Code(Zero) at (prev + 9, 13) to (start + 0, 14) +- Code(Expression(0, Add)) at (prev + 2, 5) to (start + 0, 6) + = (c0 + c1) + diff --git a/tests/coverage-map/status-quo/inline-dead.rs b/tests/coverage-map/status-quo/inline-dead.rs new file mode 100644 index 00000000000..854fa062967 --- /dev/null +++ b/tests/coverage-map/status-quo/inline-dead.rs @@ -0,0 +1,27 @@ +// Regression test for issue #98833. +// compile-flags: -Zinline-mir -Cdebug-assertions=off + +fn main() { + println!("{}", live::<false>()); + + let f = |x: bool| { + debug_assert!( + x + ); + }; + f(false); +} + +#[inline] +fn live<const B: bool>() -> u32 { + if B { + dead() + } else { + 0 + } +} + +#[inline] +fn dead() -> u32 { + 42 +} diff --git a/tests/coverage-map/status-quo/inline.cov-map b/tests/coverage-map/status-quo/inline.cov-map new file mode 100644 index 00000000000..57ae85623fb --- /dev/null +++ b/tests/coverage-map/status-quo/inline.cov-map @@ -0,0 +1,82 @@ +Function name: inline::display::<char> +Raw bytes (35): 0x[01, 01, 03, 01, 05, 05, 00, 03, 05, 05, 01, 29, 01, 00, 22, 05, 01, 09, 00, 0a, 03, 00, 0e, 00, 10, 07, 00, 11, 02, 06, 0a, 03, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 3 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Zero +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(1) +Number of file 0 mappings: 5 +- Code(Counter(0)) at (prev + 41, 1) to (start + 0, 34) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 10) +- Code(Expression(0, Add)) at (prev + 0, 14) to (start + 0, 16) + = (c0 + c1) +- Code(Expression(1, Add)) at (prev + 0, 17) to (start + 2, 6) + = (c1 + Zero) +- Code(Expression(2, Sub)) at (prev + 3, 5) to (start + 1, 2) + = ((c0 + c1) - c1) + +Function name: inline::error +Raw bytes (9): 0x[01, 01, 00, 01, 01, 31, 01, 02, 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 + 49, 1) to (start + 2, 2) + +Function name: inline::length::<char> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1e, 01, 02, 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 + 30, 1) to (start + 2, 2) + +Function name: inline::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 05, 01, 02, 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 + 5, 1) to (start + 2, 2) + +Function name: inline::permutate::<char> +Raw bytes (54): 0x[01, 01, 05, 01, 05, 02, 0d, 11, 00, 05, 13, 09, 0d, 08, 01, 0f, 01, 02, 0e, 05, 02, 0f, 02, 06, 02, 02, 0f, 00, 14, 11, 01, 0d, 00, 0e, 06, 00, 12, 00, 16, 0b, 00, 17, 04, 0a, 0d, 05, 0c, 02, 06, 0f, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 5 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(0, Sub), rhs = Counter(3) +- expression 2 operands: lhs = Counter(4), rhs = Zero +- expression 3 operands: lhs = Counter(1), rhs = Expression(4, Add) +- expression 4 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 8 +- Code(Counter(0)) at (prev + 15, 1) to (start + 2, 14) +- Code(Counter(1)) at (prev + 2, 15) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 15) to (start + 0, 20) + = (c0 - c1) +- Code(Counter(4)) at (prev + 1, 13) to (start + 0, 14) +- Code(Expression(1, Sub)) at (prev + 0, 18) to (start + 0, 22) + = ((c0 - c1) - c3) +- Code(Expression(2, Add)) at (prev + 0, 23) to (start + 4, 10) + = (c4 + Zero) +- Code(Counter(3)) at (prev + 5, 12) to (start + 2, 6) +- Code(Expression(3, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c1 + (c2 + c3)) + +Function name: inline::permutations::<char> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 01, 03, 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 + 10, 1) to (start + 3, 2) + +Function name: inline::swap::<char> +Raw bytes (9): 0x[01, 01, 00, 01, 01, 23, 01, 04, 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 + 35, 1) to (start + 4, 2) + diff --git a/tests/coverage-map/status-quo/inline.rs b/tests/coverage-map/status-quo/inline.rs new file mode 100644 index 00000000000..9cfab9ddbad --- /dev/null +++ b/tests/coverage-map/status-quo/inline.rs @@ -0,0 +1,51 @@ +// compile-flags: -Zinline-mir + +use std::fmt::Display; + +fn main() { + permutations(&['a', 'b', 'c']); +} + +#[inline(always)] +fn permutations<T: Copy + Display>(xs: &[T]) { + let mut ys = xs.to_owned(); + permutate(&mut ys, 0); +} + +fn permutate<T: Copy + Display>(xs: &mut [T], k: usize) { + let n = length(xs); + if k == n { + display(xs); + } else if k < n { + for i in k..n { + swap(xs, i, k); + permutate(xs, k + 1); + swap(xs, i, k); + } + } else { + error(); + } +} + +fn length<T>(xs: &[T]) -> usize { + xs.len() +} + +#[inline] +fn swap<T: Copy>(xs: &mut [T], i: usize, j: usize) { + let t = xs[i]; + xs[i] = xs[j]; + xs[j] = t; +} + +fn display<T: Display>(xs: &[T]) { + for x in xs { + print!("{}", x); + } + println!(); +} + +#[inline(always)] +fn error() { + panic!("error"); +} diff --git a/tests/coverage-map/status-quo/inner_items.cov-map b/tests/coverage-map/status-quo/inner_items.cov-map new file mode 100644 index 00000000000..3f39d74efba --- /dev/null +++ b/tests/coverage-map/status-quo/inner_items.cov-map @@ -0,0 +1,49 @@ +Function name: <inner_items::main::InStruct as inner_items::main::InTrait>::default_trait_func +Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 09, 03, 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 + 33, 9) to (start + 3, 10) + +Function name: <inner_items::main::InStruct as inner_items::main::InTrait>::trait_func +Raw bytes (9): 0x[01, 01, 00, 01, 01, 28, 09, 03, 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 + 40, 9) to (start + 3, 10) + +Function name: inner_items::main +Raw bytes (53): 0x[01, 01, 07, 01, 05, 05, 02, 1b, 09, 05, 02, 09, 16, 1b, 09, 05, 02, 07, 01, 03, 01, 07, 0f, 05, 07, 10, 02, 06, 02, 02, 06, 00, 07, 1b, 24, 08, 00, 0f, 09, 00, 10, 02, 06, 16, 02, 06, 00, 07, 13, 02, 09, 05, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 7 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Expression(6, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Sub) +- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 7 +- Code(Counter(0)) at (prev + 3, 1) to (start + 7, 15) +- Code(Counter(1)) at (prev + 7, 16) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(6, Add)) at (prev + 36, 8) to (start + 0, 15) + = (c1 + (c0 - c1)) +- Code(Counter(2)) at (prev + 0, 16) to (start + 2, 6) +- Code(Expression(5, Sub)) at (prev + 2, 6) to (start + 0, 7) + = ((c1 + (c0 - c1)) - c2) +- Code(Expression(4, Add)) at (prev + 2, 9) to (start + 5, 2) + = (c2 + ((c1 + (c0 - c1)) - c2)) + +Function name: inner_items::main::in_func +Raw bytes (9): 0x[01, 01, 00, 01, 01, 12, 05, 04, 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 + 18, 5) to (start + 4, 6) + diff --git a/tests/coverage-map/status-quo/inner_items.rs b/tests/coverage-map/status-quo/inner_items.rs new file mode 100644 index 00000000000..bcb62b3031c --- /dev/null +++ b/tests/coverage-map/status-quo/inner_items.rs @@ -0,0 +1,57 @@ +#![allow(unused_assignments, unused_variables, dead_code)] + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 0; + if is_true { + countdown = 10; + } + + mod in_mod { + const IN_MOD_CONST: u32 = 1000; + } + + fn in_func(a: u32) { + let b = 1; + let c = a + b; + println!("c = {}", c) + } + + struct InStruct { + in_struct_field: u32, + } + + const IN_CONST: u32 = 1234; + + trait InTrait { + fn trait_func(&mut self, incr: u32); + + fn default_trait_func(&mut self) { + in_func(IN_CONST); + self.trait_func(IN_CONST); + } + } + + impl InTrait for InStruct { + fn trait_func(&mut self, incr: u32) { + self.in_struct_field += incr; + in_func(self.in_struct_field); + } + } + + type InType = String; + + if is_true { + in_func(countdown); + } + + let mut val = InStruct { + in_struct_field: 101, + }; + + val.default_trait_func(); +} diff --git a/tests/coverage-map/status-quo/issue-83601.cov-map b/tests/coverage-map/status-quo/issue-83601.cov-map new file mode 100644 index 00000000000..f5db3a89750 --- /dev/null +++ b/tests/coverage-map/status-quo/issue-83601.cov-map @@ -0,0 +1,28 @@ +Function name: <issue_83601::Foo as core::cmp::PartialEq>::eq +Raw bytes (9): 0x[01, 01, 00, 01, 01, 03, 11, 00, 1a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 3, 17) to (start + 0, 26) + +Function name: <issue_83601::Foo as core::fmt::Debug>::fmt +Raw bytes (9): 0x[01, 01, 00, 01, 01, 03, 0a, 00, 0f] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 3, 10) to (start + 0, 15) + +Function name: issue_83601::main +Raw bytes (21): 0x[01, 01, 01, 05, 09, 03, 01, 06, 01, 02, 1c, 05, 03, 09, 01, 1c, 02, 02, 05, 03, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 1 +- expression 0 operands: lhs = Counter(1), rhs = Counter(2) +Number of file 0 mappings: 3 +- Code(Counter(0)) at (prev + 6, 1) to (start + 2, 28) +- Code(Counter(1)) at (prev + 3, 9) to (start + 1, 28) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 3, 2) + = (c1 - c2) + diff --git a/tests/coverage-map/status-quo/issue-83601.rs b/tests/coverage-map/status-quo/issue-83601.rs new file mode 100644 index 00000000000..0b72a81947c --- /dev/null +++ b/tests/coverage-map/status-quo/issue-83601.rs @@ -0,0 +1,14 @@ +// Shows that rust-lang/rust/83601 is resolved + +#[derive(Debug, PartialEq, Eq)] +struct Foo(u32); + +fn main() { + let bar = Foo(1); + assert_eq!(bar, Foo(1)); + let baz = Foo(0); + assert_ne!(baz, Foo(1)); + println!("{:?}", Foo(1)); + println!("{:?}", bar); + println!("{:?}", baz); +} diff --git a/tests/coverage-map/status-quo/issue-84561.cov-map b/tests/coverage-map/status-quo/issue-84561.cov-map new file mode 100644 index 00000000000..fe098fd396c --- /dev/null +++ b/tests/coverage-map/status-quo/issue-84561.cov-map @@ -0,0 +1,233 @@ +Function name: <issue_84561::Foo as core::cmp::PartialEq>::eq +Raw bytes (14): 0x[01, 01, 00, 02, 01, 04, 0a, 00, 13, 00, 00, 0a, 00, 13] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 4, 10) to (start + 0, 19) +- Code(Zero) at (prev + 0, 10) to (start + 0, 19) + +Function name: <issue_84561::Foo as core::fmt::Debug>::fmt +Raw bytes (29): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 89, 01, 09, 00, 25, 05, 00, 25, 00, 26, 02, 01, 09, 00, 0f, 07, 01, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 137, 9) to (start + 0, 37) +- Code(Counter(1)) at (prev + 0, 37) to (start + 0, 38) +- Code(Expression(0, Sub)) at (prev + 1, 9) to (start + 0, 15) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 0, 6) + = (c1 + (c0 - c1)) + +Function name: issue_84561::main +Raw bytes (10): 0x[01, 01, 00, 01, 01, b2, 01, 01, 04, 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 + 178, 1) to (start + 4, 2) + +Function name: issue_84561::test1 +Raw bytes (78): 0x[01, 01, 0e, 05, 06, 01, 05, 09, 36, 03, 09, 0d, 2e, 33, 0d, 09, 36, 03, 09, 11, 26, 2b, 11, 0d, 2e, 33, 0d, 09, 36, 03, 09, 09, 01, 98, 01, 01, 01, 0b, 05, 01, 0c, 00, 1e, 03, 01, 05, 00, 0b, 09, 00, 0c, 00, 1e, 33, 01, 0d, 01, 0b, 0d, 01, 0c, 00, 1e, 2b, 01, 05, 03, 0b, 11, 03, 0c, 00, 1e, 23, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 14 +- expression 0 operands: lhs = Counter(1), rhs = Expression(1, Sub) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +- expression 2 operands: lhs = Counter(2), rhs = Expression(13, Sub) +- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(2) +- expression 4 operands: lhs = Counter(3), rhs = Expression(11, Sub) +- expression 5 operands: lhs = Expression(12, Add), rhs = Counter(3) +- expression 6 operands: lhs = Counter(2), rhs = Expression(13, Sub) +- expression 7 operands: lhs = Expression(0, Add), rhs = Counter(2) +- expression 8 operands: lhs = Counter(4), rhs = Expression(9, Sub) +- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(4) +- expression 10 operands: lhs = Counter(3), rhs = Expression(11, Sub) +- expression 11 operands: lhs = Expression(12, Add), rhs = Counter(3) +- expression 12 operands: lhs = Counter(2), rhs = Expression(13, Sub) +- expression 13 operands: lhs = Expression(0, Add), rhs = Counter(2) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 152, 1) to (start + 1, 11) +- Code(Counter(1)) at (prev + 1, 12) to (start + 0, 30) +- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 0, 11) + = (c1 + (c0 - c1)) +- Code(Counter(2)) at (prev + 0, 12) to (start + 0, 30) +- Code(Expression(12, Add)) at (prev + 1, 13) to (start + 1, 11) + = (c2 + ((c1 + (c0 - c1)) - c2)) +- Code(Counter(3)) at (prev + 1, 12) to (start + 0, 30) +- Code(Expression(10, Add)) at (prev + 1, 5) to (start + 3, 11) + = (c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) +- Code(Counter(4)) at (prev + 3, 12) to (start + 0, 30) +- Code(Expression(8, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) + +Function name: issue_84561::test2 +Raw bytes (24): 0x[01, 01, 02, 05, 06, 01, 05, 03, 01, ae, 01, 01, 01, 10, 05, 01, 11, 00, 23, 03, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(1), rhs = Expression(1, Sub) +- expression 1 operands: lhs = Counter(0), rhs = Counter(1) +Number of file 0 mappings: 3 +- Code(Counter(0)) at (prev + 174, 1) to (start + 1, 16) +- Code(Counter(1)) at (prev + 1, 17) to (start + 0, 35) +- Code(Expression(0, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: issue_84561::test2::call_print +Raw bytes (10): 0x[01, 01, 00, 01, 01, a5, 01, 09, 02, 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 + 165, 9) to (start + 2, 10) + +Function name: issue_84561::test3 +Raw bytes (437): 0x[01, 01, 41, 05, 09, 0d, 11, 15, 19, 12, 1d, 15, 19, 21, 25, 1e, 29, 21, 25, 31, 39, 3d, 41, 2e, 45, 3d, 41, 42, 49, 45, 4d, 3f, 51, 42, 49, 45, 4d, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 59, 92, 01, 55, 51, 59, 8f, 01, 5d, 92, 01, 55, 51, 59, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 59, 82, 01, 65, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 59, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, 71, fe, 01, 82, 02, 71, 69, 6d, 69, 6d, 82, 02, 71, 69, 6d, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, ee, 01, 81, 01, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, 33, 01, 06, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 12, 02, 05, 00, 1f, 0e, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 1e, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 1a, 04, 09, 05, 06, 31, 06, 05, 03, 06, 22, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 2e, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 2a, 05, 09, 03, 0a, 3f, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 3a, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 87, 01, 03, 05, 00, 0f, 8f, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 8a, 01, 02, 0d, 00, 13, 82, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 7e, 02, 0d, 00, 13, f3, 01, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, fb, 01, 02, 0d, 00, 17, 82, 02, 01, 14, 00, 1b, 71, 01, 15, 00, 1b, fe, 01, 02, 15, 00, 1b, f6, 01, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, ee, 01, 02, 05, 00, 0f, ea, 01, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 65 +- expression 0 operands: lhs = Counter(1), rhs = Counter(2) +- expression 1 operands: lhs = Counter(3), rhs = Counter(4) +- expression 2 operands: lhs = Counter(5), rhs = Counter(6) +- expression 3 operands: lhs = Expression(4, Sub), rhs = Counter(7) +- expression 4 operands: lhs = Counter(5), rhs = Counter(6) +- expression 5 operands: lhs = Counter(8), rhs = Counter(9) +- expression 6 operands: lhs = Expression(7, Sub), rhs = Counter(10) +- expression 7 operands: lhs = Counter(8), rhs = Counter(9) +- expression 8 operands: lhs = Counter(12), rhs = Counter(14) +- expression 9 operands: lhs = Counter(15), rhs = Counter(16) +- expression 10 operands: lhs = Expression(11, Sub), rhs = Counter(17) +- expression 11 operands: lhs = Counter(15), rhs = Counter(16) +- expression 12 operands: lhs = Expression(16, Sub), rhs = Counter(18) +- expression 13 operands: lhs = Counter(17), rhs = Counter(19) +- expression 14 operands: lhs = Expression(15, Add), rhs = Counter(20) +- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(18) +- expression 16 operands: lhs = Counter(17), rhs = Counter(19) +- expression 17 operands: lhs = Counter(23), rhs = Expression(34, Sub) +- expression 18 operands: lhs = Expression(35, Add), rhs = Counter(23) +- expression 19 operands: lhs = Expression(36, Sub), rhs = Counter(21) +- expression 20 operands: lhs = Counter(20), rhs = Counter(22) +- expression 21 operands: lhs = Expression(36, Sub), rhs = Counter(21) +- expression 22 operands: lhs = Counter(20), rhs = Counter(22) +- expression 23 operands: lhs = Expression(35, Add), rhs = Counter(23) +- expression 24 operands: lhs = Expression(36, Sub), rhs = Counter(21) +- expression 25 operands: lhs = Counter(20), rhs = Counter(22) +- expression 26 operands: lhs = Expression(33, Add), rhs = Counter(24) +- expression 27 operands: lhs = Counter(23), rhs = Expression(34, Sub) +- expression 28 operands: lhs = Expression(35, Add), rhs = Counter(23) +- expression 29 operands: lhs = Expression(36, Sub), rhs = Counter(21) +- expression 30 operands: lhs = Counter(20), rhs = Counter(22) +- expression 31 operands: lhs = Expression(32, Sub), rhs = Counter(25) +- expression 32 operands: lhs = Expression(33, Add), rhs = Counter(24) +- expression 33 operands: lhs = Counter(23), rhs = Expression(34, Sub) +- expression 34 operands: lhs = Expression(35, Add), rhs = Counter(23) +- expression 35 operands: lhs = Expression(36, Sub), rhs = Counter(21) +- expression 36 operands: lhs = Counter(20), rhs = Counter(22) +- expression 37 operands: lhs = Counter(29), rhs = Expression(61, Sub) +- expression 38 operands: lhs = Expression(62, Add), rhs = Counter(30) +- expression 39 operands: lhs = Counter(28), rhs = Expression(63, Sub) +- expression 40 operands: lhs = Expression(64, Sub), rhs = Counter(28) +- expression 41 operands: lhs = Counter(26), rhs = Counter(27) +- expression 42 operands: lhs = Counter(28), rhs = Expression(63, Sub) +- expression 43 operands: lhs = Expression(64, Sub), rhs = Counter(28) +- expression 44 operands: lhs = Counter(26), rhs = Counter(27) +- expression 45 operands: lhs = Counter(26), rhs = Counter(27) +- expression 46 operands: lhs = Expression(64, Sub), rhs = Counter(28) +- expression 47 operands: lhs = Counter(26), rhs = Counter(27) +- expression 48 operands: lhs = Expression(62, Add), rhs = Counter(30) +- expression 49 operands: lhs = Counter(28), rhs = Expression(63, Sub) +- expression 50 operands: lhs = Expression(64, Sub), rhs = Counter(28) +- expression 51 operands: lhs = Counter(26), rhs = Counter(27) +- expression 52 operands: lhs = Expression(60, Add), rhs = Counter(31) +- expression 53 operands: lhs = Counter(29), rhs = Expression(61, Sub) +- expression 54 operands: lhs = Expression(62, Add), rhs = Counter(30) +- expression 55 operands: lhs = Counter(28), rhs = Expression(63, Sub) +- expression 56 operands: lhs = Expression(64, Sub), rhs = Counter(28) +- expression 57 operands: lhs = Counter(26), rhs = Counter(27) +- expression 58 operands: lhs = Expression(59, Sub), rhs = Counter(32) +- expression 59 operands: lhs = Expression(60, Add), rhs = Counter(31) +- expression 60 operands: lhs = Counter(29), rhs = Expression(61, Sub) +- expression 61 operands: lhs = Expression(62, Add), rhs = Counter(30) +- expression 62 operands: lhs = Counter(28), rhs = Expression(63, Sub) +- expression 63 operands: lhs = Expression(64, Sub), rhs = Counter(28) +- expression 64 operands: lhs = Counter(26), rhs = Counter(27) +Number of file 0 mappings: 51 +- Code(Counter(0)) at (prev + 6, 1) to (start + 3, 28) +- Code(Counter(1)) at (prev + 4, 9) to (start + 1, 28) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 4, 31) + = (c1 - c2) +- Code(Counter(3)) at (prev + 5, 5) to (start + 0, 31) +- Code(Expression(1, Sub)) at (prev + 1, 5) to (start + 0, 31) + = (c3 - c4) +- Code(Counter(5)) at (prev + 1, 9) to (start + 1, 28) +- Code(Expression(4, Sub)) at (prev + 2, 5) to (start + 0, 31) + = (c5 - c6) +- Code(Expression(3, Sub)) at (prev + 1, 5) to (start + 0, 15) + = ((c5 - c6) - c7) +- Code(Zero) at (prev + 0, 32) to (start + 0, 48) +- Code(Counter(8)) at (prev + 1, 5) to (start + 3, 15) +- Code(Zero) at (prev + 3, 32) to (start + 0, 48) +- Code(Zero) at (prev + 0, 51) to (start + 0, 65) +- Code(Zero) at (prev + 0, 75) to (start + 0, 90) +- Code(Expression(7, Sub)) at (prev + 1, 5) to (start + 0, 15) + = (c8 - c9) +- Code(Zero) at (prev + 5, 9) to (start + 3, 16) +- Code(Zero) at (prev + 5, 13) to (start + 0, 27) +- Code(Zero) at (prev + 2, 13) to (start + 0, 28) +- Code(Expression(6, Sub)) at (prev + 4, 9) to (start + 5, 6) + = ((c8 - c9) - c10) +- Code(Counter(12)) at (prev + 6, 5) to (start + 3, 6) +- Code(Expression(8, Sub)) at (prev + 4, 5) to (start + 3, 6) + = (c12 - c14) +- Code(Counter(15)) at (prev + 4, 9) to (start + 4, 6) +- Code(Expression(11, Sub)) at (prev + 5, 8) to (start + 0, 15) + = (c15 - c16) +- Code(Counter(17)) at (prev + 1, 9) to (start + 3, 10) +- Code(Expression(10, Sub)) at (prev + 5, 9) to (start + 3, 10) + = ((c15 - c16) - c17) +- Code(Expression(15, Add)) at (prev + 5, 8) to (start + 0, 15) + = ((c17 - c19) + c18) +- Code(Counter(20)) at (prev + 1, 9) to (start + 0, 19) +- Code(Zero) at (prev + 3, 13) to (start + 0, 29) +- Code(Expression(14, Sub)) at (prev + 3, 9) to (start + 0, 19) + = (((c17 - c19) + c18) - c20) +- Code(Zero) at (prev + 3, 13) to (start + 0, 29) +- Code(Expression(33, Add)) at (prev + 3, 5) to (start + 0, 15) + = (c23 + (((c20 - c22) + c21) - c23)) +- Code(Expression(35, Add)) at (prev + 1, 12) to (start + 0, 19) + = ((c20 - c22) + c21) +- Code(Counter(23)) at (prev + 1, 13) to (start + 0, 19) +- Code(Expression(34, Sub)) at (prev + 2, 13) to (start + 0, 19) + = (((c20 - c22) + c21) - c23) +- Code(Expression(32, Sub)) at (prev + 4, 5) to (start + 2, 19) + = ((c23 + (((c20 - c22) + c21) - c23)) - c24) +- Code(Counter(25)) at (prev + 3, 13) to (start + 0, 19) +- Code(Expression(31, Sub)) at (prev + 2, 13) to (start + 0, 19) + = (((c23 + (((c20 - c22) + c21) - c23)) - c24) - c25) +- Code(Expression(60, Add)) at (prev + 3, 5) to (start + 0, 15) + = (c29 + ((c28 + ((c26 - c27) - c28)) - c30)) +- Code(Counter(26)) at (prev + 1, 12) to (start + 0, 19) +- Code(Counter(27)) at (prev + 1, 13) to (start + 3, 14) +- Code(Counter(29)) at (prev + 4, 13) to (start + 0, 19) +- Code(Expression(62, Add)) at (prev + 2, 13) to (start + 0, 23) + = (c28 + ((c26 - c27) - c28)) +- Code(Expression(64, Sub)) at (prev + 1, 20) to (start + 0, 27) + = (c26 - c27) +- Code(Counter(28)) at (prev + 1, 21) to (start + 0, 27) +- Code(Expression(63, Sub)) at (prev + 2, 21) to (start + 0, 27) + = ((c26 - c27) - c28) +- Code(Expression(61, Sub)) at (prev + 4, 13) to (start + 0, 19) + = ((c28 + ((c26 - c27) - c28)) - c30) +- Code(Counter(31)) at (prev + 3, 9) to (start + 0, 25) +- Code(Expression(59, Sub)) at (prev + 2, 5) to (start + 0, 15) + = ((c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - c31) +- Code(Expression(58, Sub)) at (prev + 3, 9) to (start + 0, 34) + = (((c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - c31) - c32) +- Code(Zero) at (prev + 2, 5) to (start + 0, 15) +- Code(Zero) at (prev + 3, 9) to (start + 0, 44) +- Code(Zero) at (prev + 2, 1) to (start + 0, 2) + diff --git a/tests/coverage-map/status-quo/issue-84561.rs b/tests/coverage-map/status-quo/issue-84561.rs new file mode 100644 index 00000000000..facf5b5b4cf --- /dev/null +++ b/tests/coverage-map/status-quo/issue-84561.rs @@ -0,0 +1,182 @@ +// This demonstrated Issue #84561: function-like macros produce unintuitive coverage results. + +// failure-status: 101 +#[derive(PartialEq, Eq)] +struct Foo(u32); +fn test3() { + let is_true = std::env::args().len() == 1; + let bar = Foo(1); + assert_eq!(bar, Foo(1)); + let baz = Foo(0); + assert_ne!(baz, Foo(1)); + println!("{:?}", Foo(1)); + println!("{:?}", bar); + println!("{:?}", baz); + + assert_eq!(Foo(1), Foo(1)); + assert_ne!(Foo(0), Foo(1)); + assert_eq!(Foo(2), Foo(2)); + let bar = Foo(0); + assert_ne!(bar, Foo(3)); + assert_ne!(Foo(0), Foo(4)); + assert_eq!(Foo(3), Foo(3), "with a message"); + println!("{:?}", bar); + println!("{:?}", Foo(1)); + + assert_ne!(Foo(0), Foo(5), "{}", if is_true { "true message" } else { "false message" }); + assert_ne!( + Foo(0) + , + Foo(5) + , + "{}" + , + if + is_true + { + "true message" + } else { + "false message" + } + ); + + let is_true = std::env::args().len() == 1; + + assert_eq!( + Foo(1), + Foo(1) + ); + assert_ne!( + Foo(0), + Foo(1) + ); + assert_eq!( + Foo(2), + Foo(2) + ); + let bar = Foo(1); + assert_ne!( + bar, + Foo(3) + ); + if is_true { + assert_ne!( + Foo(0), + Foo(4) + ); + } else { + assert_eq!( + Foo(3), + Foo(3) + ); + } + if is_true { + assert_ne!( + Foo(0), + Foo(4), + "with a message" + ); + } else { + assert_eq!( + Foo(3), + Foo(3), + "with a message" + ); + } + assert_ne!( + if is_true { + Foo(0) + } else { + Foo(1) + }, + Foo(5) + ); + assert_ne!( + Foo(5), + if is_true { + Foo(0) + } else { + Foo(1) + } + ); + assert_ne!( + if is_true { + assert_eq!( + Foo(3), + Foo(3) + ); + Foo(0) + } else { + assert_ne!( + if is_true { + Foo(0) + } else { + Foo(1) + }, + Foo(5) + ); + Foo(1) + }, + Foo(5), + "with a message" + ); + assert_eq!( + Foo(1), + Foo(3), + "this assert should fail" + ); + assert_eq!( + Foo(3), + Foo(3), + "this assert should not be reached" + ); +} + +impl std::fmt::Debug for Foo { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "try and succeed")?; + Ok(()) + } +} + +static mut DEBUG_LEVEL_ENABLED: bool = false; + +macro_rules! debug { + ($($arg:tt)+) => ( + if unsafe { DEBUG_LEVEL_ENABLED } { + println!($($arg)+); + } + ); +} + +fn test1() { + debug!("debug is enabled"); + debug!("debug is enabled"); + let _ = 0; + debug!("debug is enabled"); + unsafe { + DEBUG_LEVEL_ENABLED = true; + } + debug!("debug is enabled"); +} + +macro_rules! call_debug { + ($($arg:tt)+) => ( + fn call_print(s: &str) { + print!("{}", s); + } + + call_print("called from call_debug: "); + debug!($($arg)+); + ); +} + +fn test2() { + call_debug!("debug is enabled"); +} + +fn main() { + test1(); + test2(); + test3(); +} diff --git a/tests/coverage-map/status-quo/issue-93054.cov-map b/tests/coverage-map/status-quo/issue-93054.cov-map new file mode 100644 index 00000000000..52fe7f58d15 --- /dev/null +++ b/tests/coverage-map/status-quo/issue-93054.cov-map @@ -0,0 +1,24 @@ +Function name: issue_93054::foo2 (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 16, 01, 00, 1d] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 22, 1) to (start + 0, 29) + +Function name: issue_93054::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1e, 01, 00, 0d] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 30, 1) to (start + 0, 13) + +Function name: issue_93054::make (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1a, 01, 02, 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 + 26, 1) to (start + 2, 2) + diff --git a/tests/coverage-map/status-quo/issue-93054.rs b/tests/coverage-map/status-quo/issue-93054.rs new file mode 100644 index 00000000000..da546cfeef8 --- /dev/null +++ b/tests/coverage-map/status-quo/issue-93054.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unreachable_code)] + +// Regression test for #93054: Functions using uninhabited types often only have a single, +// unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail. +// Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them. + +// compile-flags: --edition=2021 + +enum Never {} + +impl Never { + fn foo(self) { + match self {} + make().map(|never| match never {}); + } + + fn bar(&self) { + match *self {} + } +} + +async fn foo2(never: Never) { + match never {} +} + +fn make() -> Option<Never> { + None +} + +fn main() {} diff --git a/tests/coverage-map/status-quo/lazy_boolean.cov-map b/tests/coverage-map/status-quo/lazy_boolean.cov-map new file mode 100644 index 00000000000..b18a9640433 --- /dev/null +++ b/tests/coverage-map/status-quo/lazy_boolean.cov-map @@ -0,0 +1,223 @@ +Function name: lazy_boolean::main +Raw bytes (646): 0x[01, 01, a8, 01, 01, 05, 09, 9a, 05, 9f, 05, 09, 05, 02, 05, 02, 9f, 05, 09, 05, 02, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 97, 05, 00, 09, 9a, 05, 9f, 05, 09, 05, 02, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 8f, 05, 00, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 87, 05, 00, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, ff, 04, 00, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, f7, 04, 1d, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 1d, f2, 04, f7, 04, 1d, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, ef, 04, 21, 1d, f2, 04, f7, 04, 1d, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 21, ea, 04, ef, 04, 21, 1d, f2, 04, f7, 04, 1d, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, e7, 04, 25, 21, ea, 04, ef, 04, 21, 1d, f2, 04, f7, 04, 1d, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 25, e2, 04, e7, 04, 25, 21, ea, 04, ef, 04, 21, 1d, f2, 04, f7, 04, 1d, 19, fa, 04, ff, 04, 19, 15, 82, 05, 87, 05, 15, 11, 8a, 05, 8f, 05, 11, 0d, 92, 05, 97, 05, 0d, 09, 9a, 05, 9f, 05, 09, 05, 02, 1c, 01, 03, 01, 07, 0f, 05, 07, 10, 04, 06, 02, 04, 06, 00, 07, 97, 05, 02, 09, 00, 11, 9f, 05, 02, 0d, 00, 12, 9a, 05, 02, 0d, 00, 12, 8f, 05, 03, 09, 00, 11, 33, 02, 0d, 00, 12, 92, 05, 02, 0d, 00, 12, 87, 05, 02, 09, 00, 11, 6f, 00, 14, 00, 19, 11, 00, 1d, 00, 22, ff, 04, 01, 09, 00, 11, ab, 01, 00, 14, 00, 19, 15, 00, 1d, 00, 22, cb, 01, 04, 09, 00, 10, fa, 04, 01, 05, 03, 06, 19, 03, 06, 00, 07, f7, 04, 03, 09, 00, 10, 1d, 01, 05, 03, 06, f2, 04, 05, 05, 03, 06, ef, 04, 05, 09, 00, 10, ea, 04, 00, 11, 02, 06, 21, 02, 06, 00, 07, e7, 04, 02, 08, 00, 0f, 25, 00, 10, 02, 06, e2, 04, 02, 0c, 02, 06, df, 04, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 168 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 2 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 5 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 7 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 8 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 9 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 10 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 11 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 12 operands: lhs = Expression(165, Add), rhs = Zero +- expression 13 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 14 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 15 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 16 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 17 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 18 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 19 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 20 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 21 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 22 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 23 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 24 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 25 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 26 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 27 operands: lhs = Expression(163, Add), rhs = Zero +- expression 28 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 29 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 30 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 31 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 32 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 33 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 34 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 35 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 36 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 37 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 38 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 39 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 40 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 41 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 42 operands: lhs = Expression(161, Add), rhs = Zero +- expression 43 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 44 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 45 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 46 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 47 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 48 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 49 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 50 operands: lhs = Expression(159, Add), rhs = Zero +- expression 51 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 52 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 53 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 54 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 55 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 56 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 57 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 58 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 59 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 60 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 61 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 62 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 63 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 64 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 65 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 66 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 67 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 68 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 69 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 70 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 71 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 72 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 73 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 74 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 75 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 76 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 77 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 78 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 79 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 80 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 81 operands: lhs = Expression(157, Add), rhs = Counter(7) +- expression 82 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 83 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 84 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 85 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 86 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 87 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 88 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 89 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 90 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 91 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 92 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 93 operands: lhs = Counter(7), rhs = Expression(156, Sub) +- expression 94 operands: lhs = Expression(157, Add), rhs = Counter(7) +- expression 95 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 96 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 97 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 98 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 99 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 100 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 101 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 102 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 103 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 104 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 105 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 106 operands: lhs = Expression(155, Add), rhs = Counter(8) +- expression 107 operands: lhs = Counter(7), rhs = Expression(156, Sub) +- expression 108 operands: lhs = Expression(157, Add), rhs = Counter(7) +- expression 109 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 110 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 111 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 112 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 113 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 114 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 115 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 116 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 117 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 118 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 119 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 120 operands: lhs = Counter(8), rhs = Expression(154, Sub) +- expression 121 operands: lhs = Expression(155, Add), rhs = Counter(8) +- expression 122 operands: lhs = Counter(7), rhs = Expression(156, Sub) +- expression 123 operands: lhs = Expression(157, Add), rhs = Counter(7) +- expression 124 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 125 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 126 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 127 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 128 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 129 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 130 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 131 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 132 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 133 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 134 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 135 operands: lhs = Expression(153, Add), rhs = Counter(9) +- expression 136 operands: lhs = Counter(8), rhs = Expression(154, Sub) +- expression 137 operands: lhs = Expression(155, Add), rhs = Counter(8) +- expression 138 operands: lhs = Counter(7), rhs = Expression(156, Sub) +- expression 139 operands: lhs = Expression(157, Add), rhs = Counter(7) +- expression 140 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 141 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 142 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 143 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 144 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 145 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 146 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 147 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 148 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 149 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 150 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 151 operands: lhs = Counter(9), rhs = Expression(152, Sub) +- expression 152 operands: lhs = Expression(153, Add), rhs = Counter(9) +- expression 153 operands: lhs = Counter(8), rhs = Expression(154, Sub) +- expression 154 operands: lhs = Expression(155, Add), rhs = Counter(8) +- expression 155 operands: lhs = Counter(7), rhs = Expression(156, Sub) +- expression 156 operands: lhs = Expression(157, Add), rhs = Counter(7) +- expression 157 operands: lhs = Counter(6), rhs = Expression(158, Sub) +- expression 158 operands: lhs = Expression(159, Add), rhs = Counter(6) +- expression 159 operands: lhs = Counter(5), rhs = Expression(160, Sub) +- expression 160 operands: lhs = Expression(161, Add), rhs = Counter(5) +- expression 161 operands: lhs = Counter(4), rhs = Expression(162, Sub) +- expression 162 operands: lhs = Expression(163, Add), rhs = Counter(4) +- expression 163 operands: lhs = Counter(3), rhs = Expression(164, Sub) +- expression 164 operands: lhs = Expression(165, Add), rhs = Counter(3) +- expression 165 operands: lhs = Counter(2), rhs = Expression(166, Sub) +- expression 166 operands: lhs = Expression(167, Add), rhs = Counter(2) +- expression 167 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 28 +- Code(Counter(0)) at (prev + 3, 1) to (start + 7, 15) +- Code(Counter(1)) at (prev + 7, 16) to (start + 4, 6) +- Code(Expression(0, Sub)) at (prev + 4, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(165, Add)) at (prev + 2, 9) to (start + 0, 17) + = (c2 + ((c1 + (c0 - c1)) - c2)) +- Code(Expression(167, Add)) at (prev + 2, 13) to (start + 0, 18) + = (c1 + (c0 - c1)) +- Code(Expression(166, Sub)) at (prev + 2, 13) to (start + 0, 18) + = ((c1 + (c0 - c1)) - c2) +- Code(Expression(163, Add)) at (prev + 3, 9) to (start + 0, 17) + = (c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) +- Code(Expression(12, Add)) at (prev + 2, 13) to (start + 0, 18) + = ((c2 + ((c1 + (c0 - c1)) - c2)) + Zero) +- Code(Expression(164, Sub)) at (prev + 2, 13) to (start + 0, 18) + = ((c2 + ((c1 + (c0 - c1)) - c2)) - c3) +- Code(Expression(161, Add)) at (prev + 2, 9) to (start + 0, 17) + = (c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) +- Code(Expression(27, Add)) at (prev + 0, 20) to (start + 0, 25) + = ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) + Zero) +- Code(Counter(4)) at (prev + 0, 29) to (start + 0, 34) +- Code(Expression(159, Add)) at (prev + 1, 9) to (start + 0, 17) + = (c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) +- Code(Expression(42, Add)) at (prev + 0, 20) to (start + 0, 25) + = ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) + Zero) +- Code(Counter(5)) at (prev + 0, 29) to (start + 0, 34) +- Code(Expression(50, Add)) at (prev + 4, 9) to (start + 0, 16) + = ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) + Zero) +- Code(Expression(158, Sub)) at (prev + 1, 5) to (start + 3, 6) + = ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6) +- Code(Counter(6)) at (prev + 3, 6) to (start + 0, 7) +- Code(Expression(157, Add)) at (prev + 3, 9) to (start + 0, 16) + = (c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) +- Code(Counter(7)) at (prev + 1, 5) to (start + 3, 6) +- Code(Expression(156, Sub)) at (prev + 5, 5) to (start + 3, 6) + = ((c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) - c7) +- Code(Expression(155, Add)) at (prev + 5, 9) to (start + 0, 16) + = (c7 + ((c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) - c7)) +- Code(Expression(154, Sub)) at (prev + 0, 17) to (start + 2, 6) + = ((c7 + ((c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) - c7)) - c8) +- Code(Counter(8)) at (prev + 2, 6) to (start + 0, 7) +- Code(Expression(153, Add)) at (prev + 2, 8) to (start + 0, 15) + = (c8 + ((c7 + ((c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) - c7)) - c8)) +- Code(Counter(9)) at (prev + 0, 16) to (start + 2, 6) +- Code(Expression(152, Sub)) at (prev + 2, 12) to (start + 2, 6) + = ((c8 + ((c7 + ((c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) - c7)) - c8)) - c9) +- Code(Expression(151, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c9 + ((c8 + ((c7 + ((c6 + ((c5 + ((c4 + ((c3 + ((c2 + ((c1 + (c0 - c1)) - c2)) - c3)) - c4)) - c5)) - c6)) - c7)) - c8)) - c9)) + diff --git a/tests/coverage-map/status-quo/lazy_boolean.rs b/tests/coverage-map/status-quo/lazy_boolean.rs new file mode 100644 index 00000000000..bb6219e851c --- /dev/null +++ b/tests/coverage-map/status-quo/lazy_boolean.rs @@ -0,0 +1,61 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let (mut a, mut b, mut c) = (0, 0, 0); + if is_true { + a = 1; + b = 10; + c = 100; + } + let + somebool + = + a < b + || + b < c + ; + let + somebool + = + b < a + || + b < c + ; + let somebool = a < b && b < c; + let somebool = b < a && b < c; + + if + ! + is_true + { + a = 2 + ; + } + + if + is_true + { + b = 30 + ; + } + else + { + c = 400 + ; + } + + if !is_true { + a = 2; + } + + if is_true { + b = 30; + } else { + c = 400; + } +} diff --git a/tests/coverage-map/status-quo/loop_break_value.cov-map b/tests/coverage-map/status-quo/loop_break_value.cov-map new file mode 100644 index 00000000000..75018442d07 --- /dev/null +++ b/tests/coverage-map/status-quo/loop_break_value.cov-map @@ -0,0 +1,8 @@ +Function name: loop_break_value::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 03, 01, 0a, 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 + 3, 1) to (start + 10, 2) + diff --git a/tests/coverage-map/status-quo/loop_break_value.rs b/tests/coverage-map/status-quo/loop_break_value.rs new file mode 100644 index 00000000000..dbc4fad7a23 --- /dev/null +++ b/tests/coverage-map/status-quo/loop_break_value.rs @@ -0,0 +1,13 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + let result + = + loop + { + break + 10 + ; + } + ; +} diff --git a/tests/coverage-map/status-quo/loops_branches.cov-map b/tests/coverage-map/status-quo/loops_branches.cov-map new file mode 100644 index 00000000000..56fafc0a67b --- /dev/null +++ b/tests/coverage-map/status-quo/loops_branches.cov-map @@ -0,0 +1,193 @@ +Function name: <loops_branches::DebugTest as core::fmt::Debug>::fmt +Raw bytes (262): 0x[01, 01, 36, 05, 09, 0a, 02, 00, 00, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, d3, 01, d7, 01, 0d, 00, 11, 15, ca, 01, 00, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, ca, 01, 15, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, c6, 01, 1d, ca, 01, 15, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, be, 01, c2, 01, 00, 00, c6, 01, 1d, ca, 01, 15, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, bb, 01, 11, be, 01, c2, 01, 00, 00, c6, 01, 1d, ca, 01, 15, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, 25, b3, 01, b6, 01, 19, bb, 01, 11, be, 01, c2, 01, 00, 00, c6, 01, 1d, ca, 01, 15, cf, 01, 19, d3, 01, d7, 01, 0d, 00, 11, 15, 14, 01, 09, 05, 01, 10, 05, 02, 10, 00, 15, 00, 01, 17, 00, 1b, 00, 00, 1c, 00, 1e, 02, 01, 0e, 00, 0f, 07, 01, 0d, 00, 1e, 25, 00, 1e, 00, 1f, 00, 01, 10, 01, 0a, ca, 01, 03, 0d, 00, 0e, cf, 01, 00, 12, 00, 17, 2b, 01, 10, 00, 14, c6, 01, 01, 14, 00, 19, 00, 01, 1b, 00, 1f, 00, 00, 20, 00, 22, c2, 01, 01, 12, 00, 13, bb, 01, 01, 11, 00, 22, b6, 01, 00, 22, 00, 23, 00, 01, 14, 01, 0e, 19, 03, 09, 00, 0f, af, 01, 01, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 54 +- expression 0 operands: lhs = Counter(1), rhs = Counter(2) +- expression 1 operands: lhs = Expression(2, Sub), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Zero, rhs = Zero +- expression 3 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 4 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 5 operands: lhs = Counter(3), rhs = Zero +- expression 6 operands: lhs = Counter(4), rhs = Counter(5) +- expression 7 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 8 operands: lhs = Counter(3), rhs = Zero +- expression 9 operands: lhs = Counter(4), rhs = Counter(5) +- expression 10 operands: lhs = Expression(50, Sub), rhs = Zero +- expression 11 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 12 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 13 operands: lhs = Counter(3), rhs = Zero +- expression 14 operands: lhs = Counter(4), rhs = Counter(5) +- expression 15 operands: lhs = Expression(50, Sub), rhs = Counter(5) +- expression 16 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 17 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 18 operands: lhs = Counter(3), rhs = Zero +- expression 19 operands: lhs = Counter(4), rhs = Counter(5) +- expression 20 operands: lhs = Expression(49, Sub), rhs = Counter(7) +- expression 21 operands: lhs = Expression(50, Sub), rhs = Counter(5) +- expression 22 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 23 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 24 operands: lhs = Counter(3), rhs = Zero +- expression 25 operands: lhs = Counter(4), rhs = Counter(5) +- expression 26 operands: lhs = Expression(47, Sub), rhs = Expression(48, Sub) +- expression 27 operands: lhs = Zero, rhs = Zero +- expression 28 operands: lhs = Expression(49, Sub), rhs = Counter(7) +- expression 29 operands: lhs = Expression(50, Sub), rhs = Counter(5) +- expression 30 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 31 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 32 operands: lhs = Counter(3), rhs = Zero +- expression 33 operands: lhs = Counter(4), rhs = Counter(5) +- expression 34 operands: lhs = Expression(46, Add), rhs = Counter(4) +- expression 35 operands: lhs = Expression(47, Sub), rhs = Expression(48, Sub) +- expression 36 operands: lhs = Zero, rhs = Zero +- expression 37 operands: lhs = Expression(49, Sub), rhs = Counter(7) +- expression 38 operands: lhs = Expression(50, Sub), rhs = Counter(5) +- expression 39 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 40 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 41 operands: lhs = Counter(3), rhs = Zero +- expression 42 operands: lhs = Counter(4), rhs = Counter(5) +- expression 43 operands: lhs = Counter(9), rhs = Expression(44, Add) +- expression 44 operands: lhs = Expression(45, Sub), rhs = Counter(6) +- expression 45 operands: lhs = Expression(46, Add), rhs = Counter(4) +- expression 46 operands: lhs = Expression(47, Sub), rhs = Expression(48, Sub) +- expression 47 operands: lhs = Zero, rhs = Zero +- expression 48 operands: lhs = Expression(49, Sub), rhs = Counter(7) +- expression 49 operands: lhs = Expression(50, Sub), rhs = Counter(5) +- expression 50 operands: lhs = Expression(51, Add), rhs = Counter(6) +- expression 51 operands: lhs = Expression(52, Add), rhs = Expression(53, Add) +- expression 52 operands: lhs = Counter(3), rhs = Zero +- expression 53 operands: lhs = Counter(4), rhs = Counter(5) +Number of file 0 mappings: 20 +- Code(Counter(0)) at (prev + 9, 5) to (start + 1, 16) +- Code(Counter(1)) at (prev + 2, 16) to (start + 0, 21) +- Code(Zero) at (prev + 1, 23) to (start + 0, 27) +- Code(Zero) at (prev + 0, 28) to (start + 0, 30) +- Code(Expression(0, Sub)) at (prev + 1, 14) to (start + 0, 15) + = (c1 - c2) +- Code(Expression(1, Add)) at (prev + 1, 13) to (start + 0, 30) + = ((Zero - Zero) + (c1 - c2)) +- Code(Counter(9)) at (prev + 0, 30) to (start + 0, 31) +- Code(Zero) at (prev + 1, 16) to (start + 1, 10) +- Code(Expression(50, Sub)) at (prev + 3, 13) to (start + 0, 14) + = (((c3 + Zero) + (c4 + c5)) - c6) +- Code(Expression(51, Add)) at (prev + 0, 18) to (start + 0, 23) + = ((c3 + Zero) + (c4 + c5)) +- Code(Expression(10, Add)) at (prev + 1, 16) to (start + 0, 20) + = ((((c3 + Zero) + (c4 + c5)) - c6) + Zero) +- Code(Expression(49, Sub)) at (prev + 1, 20) to (start + 0, 25) + = ((((c3 + Zero) + (c4 + c5)) - c6) - c5) +- Code(Zero) at (prev + 1, 27) to (start + 0, 31) +- Code(Zero) at (prev + 0, 32) to (start + 0, 34) +- Code(Expression(48, Sub)) at (prev + 1, 18) to (start + 0, 19) + = (((((c3 + Zero) + (c4 + c5)) - c6) - c5) - c7) +- Code(Expression(46, Add)) at (prev + 1, 17) to (start + 0, 34) + = ((Zero - Zero) + (((((c3 + Zero) + (c4 + c5)) - c6) - c5) - c7)) +- Code(Expression(45, Sub)) at (prev + 0, 34) to (start + 0, 35) + = (((Zero - Zero) + (((((c3 + Zero) + (c4 + c5)) - c6) - c5) - c7)) - c4) +- Code(Zero) at (prev + 1, 20) to (start + 1, 14) +- Code(Counter(6)) at (prev + 3, 9) to (start + 0, 15) +- Code(Expression(43, Add)) at (prev + 1, 5) to (start + 0, 6) + = (c9 + ((((Zero - Zero) + (((((c3 + Zero) + (c4 + c5)) - c6) - c5) - c7)) - c4) + c6)) + +Function name: <loops_branches::DisplayTest as core::fmt::Display>::fmt +Raw bytes (266): 0x[01, 01, 38, 01, 05, 02, 09, 0e, 12, 00, 00, 02, 09, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, d7, 01, db, 01, 05, 0d, 11, 15, ce, 01, 00, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, ce, 01, 11, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, ca, 01, 1d, ce, 01, 11, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, c2, 01, c6, 01, 00, 00, ca, 01, 1d, ce, 01, 11, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, bf, 01, 15, c2, 01, c6, 01, 00, 00, ca, 01, 1d, ce, 01, 11, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, ba, 01, df, 01, bf, 01, 15, c2, 01, c6, 01, 00, 00, ca, 01, 1d, ce, 01, 11, d3, 01, 19, d7, 01, db, 01, 05, 0d, 11, 15, 19, 25, 14, 01, 22, 05, 01, 11, 00, 01, 12, 01, 0a, 02, 02, 10, 00, 15, 00, 01, 17, 00, 1b, 00, 00, 1c, 00, 1e, 12, 01, 0e, 00, 0f, 0b, 01, 0d, 00, 1e, 25, 00, 1e, 00, 1f, ce, 01, 02, 0d, 00, 0e, d3, 01, 00, 12, 00, 17, 33, 01, 10, 00, 15, 00, 00, 16, 01, 0e, ca, 01, 02, 14, 00, 19, 00, 01, 1b, 00, 1f, 00, 00, 20, 00, 22, c6, 01, 01, 12, 00, 13, bf, 01, 01, 11, 00, 22, ba, 01, 00, 22, 00, 23, 19, 03, 09, 00, 0f, b7, 01, 01, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 56 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(0, Sub), rhs = Counter(2) +- expression 2 operands: lhs = Expression(3, Sub), rhs = Expression(4, Sub) +- expression 3 operands: lhs = Zero, rhs = Zero +- expression 4 operands: lhs = Expression(0, Sub), rhs = Counter(2) +- expression 5 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 6 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 7 operands: lhs = Counter(1), rhs = Counter(3) +- expression 8 operands: lhs = Counter(4), rhs = Counter(5) +- expression 9 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 10 operands: lhs = Counter(1), rhs = Counter(3) +- expression 11 operands: lhs = Counter(4), rhs = Counter(5) +- expression 12 operands: lhs = Expression(51, Sub), rhs = Zero +- expression 13 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 14 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 15 operands: lhs = Counter(1), rhs = Counter(3) +- expression 16 operands: lhs = Counter(4), rhs = Counter(5) +- expression 17 operands: lhs = Expression(51, Sub), rhs = Counter(4) +- expression 18 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 19 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 20 operands: lhs = Counter(1), rhs = Counter(3) +- expression 21 operands: lhs = Counter(4), rhs = Counter(5) +- expression 22 operands: lhs = Expression(50, Sub), rhs = Counter(7) +- expression 23 operands: lhs = Expression(51, Sub), rhs = Counter(4) +- expression 24 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 25 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 26 operands: lhs = Counter(1), rhs = Counter(3) +- expression 27 operands: lhs = Counter(4), rhs = Counter(5) +- expression 28 operands: lhs = Expression(48, Sub), rhs = Expression(49, Sub) +- expression 29 operands: lhs = Zero, rhs = Zero +- expression 30 operands: lhs = Expression(50, Sub), rhs = Counter(7) +- expression 31 operands: lhs = Expression(51, Sub), rhs = Counter(4) +- expression 32 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 33 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 34 operands: lhs = Counter(1), rhs = Counter(3) +- expression 35 operands: lhs = Counter(4), rhs = Counter(5) +- expression 36 operands: lhs = Expression(47, Add), rhs = Counter(5) +- expression 37 operands: lhs = Expression(48, Sub), rhs = Expression(49, Sub) +- expression 38 operands: lhs = Zero, rhs = Zero +- expression 39 operands: lhs = Expression(50, Sub), rhs = Counter(7) +- expression 40 operands: lhs = Expression(51, Sub), rhs = Counter(4) +- expression 41 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 42 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 43 operands: lhs = Counter(1), rhs = Counter(3) +- expression 44 operands: lhs = Counter(4), rhs = Counter(5) +- expression 45 operands: lhs = Expression(46, Sub), rhs = Expression(55, Add) +- expression 46 operands: lhs = Expression(47, Add), rhs = Counter(5) +- expression 47 operands: lhs = Expression(48, Sub), rhs = Expression(49, Sub) +- expression 48 operands: lhs = Zero, rhs = Zero +- expression 49 operands: lhs = Expression(50, Sub), rhs = Counter(7) +- expression 50 operands: lhs = Expression(51, Sub), rhs = Counter(4) +- expression 51 operands: lhs = Expression(52, Add), rhs = Counter(6) +- expression 52 operands: lhs = Expression(53, Add), rhs = Expression(54, Add) +- expression 53 operands: lhs = Counter(1), rhs = Counter(3) +- expression 54 operands: lhs = Counter(4), rhs = Counter(5) +- expression 55 operands: lhs = Counter(6), rhs = Counter(9) +Number of file 0 mappings: 20 +- Code(Counter(0)) at (prev + 34, 5) to (start + 1, 17) +- Code(Zero) at (prev + 1, 18) to (start + 1, 10) +- Code(Expression(0, Sub)) at (prev + 2, 16) to (start + 0, 21) + = (c0 - c1) +- Code(Zero) at (prev + 1, 23) to (start + 0, 27) +- Code(Zero) at (prev + 0, 28) to (start + 0, 30) +- Code(Expression(4, Sub)) at (prev + 1, 14) to (start + 0, 15) + = ((c0 - c1) - c2) +- Code(Expression(2, Add)) at (prev + 1, 13) to (start + 0, 30) + = ((Zero - Zero) + ((c0 - c1) - c2)) +- Code(Counter(9)) at (prev + 0, 30) to (start + 0, 31) +- Code(Expression(51, Sub)) at (prev + 2, 13) to (start + 0, 14) + = (((c1 + c3) + (c4 + c5)) - c6) +- Code(Expression(52, Add)) at (prev + 0, 18) to (start + 0, 23) + = ((c1 + c3) + (c4 + c5)) +- Code(Expression(12, Add)) at (prev + 1, 16) to (start + 0, 21) + = ((((c1 + c3) + (c4 + c5)) - c6) + Zero) +- Code(Zero) at (prev + 0, 22) to (start + 1, 14) +- Code(Expression(50, Sub)) at (prev + 2, 20) to (start + 0, 25) + = ((((c1 + c3) + (c4 + c5)) - c6) - c4) +- Code(Zero) at (prev + 1, 27) to (start + 0, 31) +- Code(Zero) at (prev + 0, 32) to (start + 0, 34) +- Code(Expression(49, Sub)) at (prev + 1, 18) to (start + 0, 19) + = (((((c1 + c3) + (c4 + c5)) - c6) - c4) - c7) +- Code(Expression(47, Add)) at (prev + 1, 17) to (start + 0, 34) + = ((Zero - Zero) + (((((c1 + c3) + (c4 + c5)) - c6) - c4) - c7)) +- Code(Expression(46, Sub)) at (prev + 0, 34) to (start + 0, 35) + = (((Zero - Zero) + (((((c1 + c3) + (c4 + c5)) - c6) - c4) - c7)) - c5) +- Code(Counter(6)) at (prev + 3, 9) to (start + 0, 15) +- Code(Expression(45, Add)) at (prev + 1, 5) to (start + 0, 6) + = ((((Zero - Zero) + (((((c1 + c3) + (c4 + c5)) - c6) - c4) - c7)) - c5) + (c6 + c9)) + +Function name: loops_branches::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 37, 01, 05, 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 + 55, 1) to (start + 5, 2) + diff --git a/tests/coverage-map/status-quo/loops_branches.rs b/tests/coverage-map/status-quo/loops_branches.rs new file mode 100644 index 00000000000..f3a343bcc1f --- /dev/null +++ b/tests/coverage-map/status-quo/loops_branches.rs @@ -0,0 +1,60 @@ +#![allow(unused_assignments, unused_variables, while_true)] + +// This test confirms that (1) unexecuted infinite loops are handled correctly by the +// InstrumentCoverage MIR pass; and (2) Counter Expressions that subtract from zero can be dropped. + +struct DebugTest; + +impl std::fmt::Debug for DebugTest { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + if true { + if false { + while true {} + } + write!(f, "cool")?; + } else { + } + + for i in 0..10 { + if true { + if false { + while true {} + } + write!(f, "cool")?; + } else { + } + } + Ok(()) + } +} + +struct DisplayTest; + +impl std::fmt::Display for DisplayTest { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + if false { + } else { + if false { + while true {} + } + write!(f, "cool")?; + } + for i in 0..10 { + if false { + } else { + if false { + while true {} + } + write!(f, "cool")?; + } + } + Ok(()) + } +} + +fn main() { + let debug_test = DebugTest; + println!("{:?}", debug_test); + let display_test = DisplayTest; + println!("{}", display_test); +} diff --git a/tests/coverage-map/status-quo/match_or_pattern.cov-map b/tests/coverage-map/status-quo/match_or_pattern.cov-map new file mode 100644 index 00000000000..d63407a99c3 --- /dev/null +++ b/tests/coverage-map/status-quo/match_or_pattern.cov-map @@ -0,0 +1,83 @@ +Function name: match_or_pattern::main +Raw bytes (202): 0x[01, 01, 23, 01, 05, 05, 02, 09, 0d, 2f, 11, 09, 0d, 2b, 15, 2f, 11, 09, 0d, 15, 26, 2b, 15, 2f, 11, 09, 0d, 19, 1d, 57, 21, 19, 1d, 53, 25, 57, 21, 19, 1d, 25, 4e, 53, 25, 57, 21, 19, 1d, 29, 2d, 7f, 31, 29, 2d, 7b, 35, 7f, 31, 29, 2d, 35, 76, 7b, 35, 7f, 31, 29, 2d, 39, 3d, 8b, 01, 41, 39, 3d, 19, 01, 01, 01, 08, 0f, 05, 08, 10, 03, 06, 02, 03, 06, 00, 07, 07, 01, 0b, 00, 11, 11, 03, 1b, 00, 1d, 2f, 01, 0e, 00, 10, 2b, 02, 08, 00, 0f, 15, 00, 10, 03, 06, 26, 03, 06, 00, 07, 23, 01, 0b, 00, 11, 21, 01, 1b, 00, 1d, 57, 01, 0e, 00, 10, 53, 02, 08, 00, 0f, 25, 00, 10, 03, 06, 4e, 03, 06, 00, 07, 4b, 01, 0b, 00, 11, 31, 01, 1b, 00, 1d, 7f, 01, 0e, 00, 10, 7b, 02, 08, 00, 0f, 35, 00, 10, 03, 06, 76, 03, 06, 00, 07, 73, 01, 0b, 00, 11, 41, 01, 1b, 00, 1d, 8b, 01, 01, 0e, 00, 10, 87, 01, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 35 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Counter(2), rhs = Counter(3) +- expression 3 operands: lhs = Expression(11, Add), rhs = Counter(4) +- expression 4 operands: lhs = Counter(2), rhs = Counter(3) +- expression 5 operands: lhs = Expression(10, Add), rhs = Counter(5) +- expression 6 operands: lhs = Expression(11, Add), rhs = Counter(4) +- expression 7 operands: lhs = Counter(2), rhs = Counter(3) +- expression 8 operands: lhs = Counter(5), rhs = Expression(9, Sub) +- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(5) +- expression 10 operands: lhs = Expression(11, Add), rhs = Counter(4) +- expression 11 operands: lhs = Counter(2), rhs = Counter(3) +- expression 12 operands: lhs = Counter(6), rhs = Counter(7) +- expression 13 operands: lhs = Expression(21, Add), rhs = Counter(8) +- expression 14 operands: lhs = Counter(6), rhs = Counter(7) +- expression 15 operands: lhs = Expression(20, Add), rhs = Counter(9) +- expression 16 operands: lhs = Expression(21, Add), rhs = Counter(8) +- expression 17 operands: lhs = Counter(6), rhs = Counter(7) +- expression 18 operands: lhs = Counter(9), rhs = Expression(19, Sub) +- expression 19 operands: lhs = Expression(20, Add), rhs = Counter(9) +- expression 20 operands: lhs = Expression(21, Add), rhs = Counter(8) +- expression 21 operands: lhs = Counter(6), rhs = Counter(7) +- expression 22 operands: lhs = Counter(10), rhs = Counter(11) +- expression 23 operands: lhs = Expression(31, Add), rhs = Counter(12) +- expression 24 operands: lhs = Counter(10), rhs = Counter(11) +- expression 25 operands: lhs = Expression(30, Add), rhs = Counter(13) +- expression 26 operands: lhs = Expression(31, Add), rhs = Counter(12) +- expression 27 operands: lhs = Counter(10), rhs = Counter(11) +- expression 28 operands: lhs = Counter(13), rhs = Expression(29, Sub) +- expression 29 operands: lhs = Expression(30, Add), rhs = Counter(13) +- expression 30 operands: lhs = Expression(31, Add), rhs = Counter(12) +- expression 31 operands: lhs = Counter(10), rhs = Counter(11) +- expression 32 operands: lhs = Counter(14), rhs = Counter(15) +- expression 33 operands: lhs = Expression(34, Add), rhs = Counter(16) +- expression 34 operands: lhs = Counter(14), rhs = Counter(15) +Number of file 0 mappings: 25 +- Code(Counter(0)) at (prev + 1, 1) to (start + 8, 15) +- Code(Counter(1)) at (prev + 8, 16) to (start + 3, 6) +- Code(Expression(0, Sub)) at (prev + 3, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 11) to (start + 0, 17) + = (c1 + (c0 - c1)) +- Code(Counter(4)) at (prev + 3, 27) to (start + 0, 29) +- Code(Expression(11, Add)) at (prev + 1, 14) to (start + 0, 16) + = (c2 + c3) +- Code(Expression(10, Add)) at (prev + 2, 8) to (start + 0, 15) + = ((c2 + c3) + c4) +- Code(Counter(5)) at (prev + 0, 16) to (start + 3, 6) +- Code(Expression(9, Sub)) at (prev + 3, 6) to (start + 0, 7) + = (((c2 + c3) + c4) - c5) +- Code(Expression(8, Add)) at (prev + 1, 11) to (start + 0, 17) + = (c5 + (((c2 + c3) + c4) - c5)) +- Code(Counter(8)) at (prev + 1, 27) to (start + 0, 29) +- Code(Expression(21, Add)) at (prev + 1, 14) to (start + 0, 16) + = (c6 + c7) +- Code(Expression(20, Add)) at (prev + 2, 8) to (start + 0, 15) + = ((c6 + c7) + c8) +- Code(Counter(9)) at (prev + 0, 16) to (start + 3, 6) +- Code(Expression(19, Sub)) at (prev + 3, 6) to (start + 0, 7) + = (((c6 + c7) + c8) - c9) +- Code(Expression(18, Add)) at (prev + 1, 11) to (start + 0, 17) + = (c9 + (((c6 + c7) + c8) - c9)) +- Code(Counter(12)) at (prev + 1, 27) to (start + 0, 29) +- Code(Expression(31, Add)) at (prev + 1, 14) to (start + 0, 16) + = (c10 + c11) +- Code(Expression(30, Add)) at (prev + 2, 8) to (start + 0, 15) + = ((c10 + c11) + c12) +- Code(Counter(13)) at (prev + 0, 16) to (start + 3, 6) +- Code(Expression(29, Sub)) at (prev + 3, 6) to (start + 0, 7) + = (((c10 + c11) + c12) - c13) +- Code(Expression(28, Add)) at (prev + 1, 11) to (start + 0, 17) + = (c13 + (((c10 + c11) + c12) - c13)) +- Code(Counter(16)) at (prev + 1, 27) to (start + 0, 29) +- Code(Expression(34, Add)) at (prev + 1, 14) to (start + 0, 16) + = (c14 + c15) +- Code(Expression(33, Add)) at (prev + 2, 1) to (start + 0, 2) + = ((c14 + c15) + c16) + diff --git a/tests/coverage-map/status-quo/match_or_pattern.rs b/tests/coverage-map/status-quo/match_or_pattern.rs new file mode 100644 index 00000000000..ab7aee51d1b --- /dev/null +++ b/tests/coverage-map/status-quo/match_or_pattern.rs @@ -0,0 +1,43 @@ +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut a: u8 = 0; + let mut b: u8 = 0; + if is_true { + a = 2; + b = 0; + } + match (a, b) { + // Or patterns generate MIR `SwitchInt` with multiple targets to the same `BasicBlock`. + // This test confirms a fix for Issue #79569. + (0 | 1, 2 | 3) => {} + _ => {} + } + if is_true { + a = 0; + b = 0; + } + match (a, b) { + (0 | 1, 2 | 3) => {} + _ => {} + } + if is_true { + a = 2; + b = 2; + } + match (a, b) { + (0 | 1, 2 | 3) => {} + _ => {} + } + if is_true { + a = 0; + b = 2; + } + match (a, b) { + (0 | 1, 2 | 3) => {} + _ => {} + } +} diff --git a/tests/coverage-map/status-quo/nested_loops.cov-map b/tests/coverage-map/status-quo/nested_loops.cov-map new file mode 100644 index 00000000000..35d92594e75 --- /dev/null +++ b/tests/coverage-map/status-quo/nested_loops.cov-map @@ -0,0 +1,51 @@ +Function name: nested_loops::main +Raw bytes (115): 0x[01, 01, 17, 01, 57, 05, 09, 03, 0d, 4e, 53, 03, 0d, 15, 19, 4b, 09, 4e, 53, 03, 0d, 15, 19, 46, 05, 4b, 09, 4e, 53, 03, 0d, 15, 19, 42, 19, 46, 05, 4b, 09, 4e, 53, 03, 0d, 15, 19, 05, 09, 11, 0d, 0d, 01, 01, 01, 02, 1b, 03, 04, 13, 00, 20, 4e, 01, 0d, 01, 18, 4b, 02, 12, 00, 17, 46, 01, 10, 00, 16, 05, 01, 11, 00, 16, 42, 01, 0e, 03, 16, 3e, 04, 11, 01, 1b, 11, 02, 15, 00, 21, 15, 01, 18, 02, 12, 19, 03, 0e, 00, 0f, 57, 02, 09, 00, 17, 5b, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 23 +- expression 0 operands: lhs = Counter(0), rhs = Expression(21, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Expression(19, Sub), rhs = Expression(20, Add) +- expression 4 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 5 operands: lhs = Counter(5), rhs = Counter(6) +- expression 6 operands: lhs = Expression(18, Add), rhs = Counter(2) +- expression 7 operands: lhs = Expression(19, Sub), rhs = Expression(20, Add) +- expression 8 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 9 operands: lhs = Counter(5), rhs = Counter(6) +- expression 10 operands: lhs = Expression(17, Sub), rhs = Counter(1) +- expression 11 operands: lhs = Expression(18, Add), rhs = Counter(2) +- expression 12 operands: lhs = Expression(19, Sub), rhs = Expression(20, Add) +- expression 13 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 14 operands: lhs = Counter(5), rhs = Counter(6) +- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(6) +- expression 16 operands: lhs = Expression(17, Sub), rhs = Counter(1) +- expression 17 operands: lhs = Expression(18, Add), rhs = Counter(2) +- expression 18 operands: lhs = Expression(19, Sub), rhs = Expression(20, Add) +- expression 19 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 20 operands: lhs = Counter(5), rhs = Counter(6) +- expression 21 operands: lhs = Counter(1), rhs = Counter(2) +- expression 22 operands: lhs = Counter(4), rhs = Counter(3) +Number of file 0 mappings: 13 +- Code(Counter(0)) at (prev + 1, 1) to (start + 2, 27) +- Code(Expression(0, Add)) at (prev + 4, 19) to (start + 0, 32) + = (c0 + (c1 + c2)) +- Code(Expression(19, Sub)) at (prev + 1, 13) to (start + 1, 24) + = ((c0 + (c1 + c2)) - c3) +- Code(Expression(18, Add)) at (prev + 2, 18) to (start + 0, 23) + = (((c0 + (c1 + c2)) - c3) + (c5 + c6)) +- Code(Expression(17, Sub)) at (prev + 1, 16) to (start + 0, 22) + = ((((c0 + (c1 + c2)) - c3) + (c5 + c6)) - c2) +- Code(Counter(1)) at (prev + 1, 17) to (start + 0, 22) +- Code(Expression(16, Sub)) at (prev + 1, 14) to (start + 3, 22) + = (((((c0 + (c1 + c2)) - c3) + (c5 + c6)) - c2) - c1) +- Code(Expression(15, Sub)) at (prev + 4, 17) to (start + 1, 27) + = ((((((c0 + (c1 + c2)) - c3) + (c5 + c6)) - c2) - c1) - c6) +- Code(Counter(4)) at (prev + 2, 21) to (start + 0, 33) +- Code(Counter(5)) at (prev + 1, 24) to (start + 2, 18) +- Code(Counter(6)) at (prev + 3, 14) to (start + 0, 15) +- Code(Expression(21, Add)) at (prev + 2, 9) to (start + 0, 23) + = (c1 + c2) +- Code(Expression(22, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c4 + c3) + diff --git a/tests/coverage-map/status-quo/nested_loops.rs b/tests/coverage-map/status-quo/nested_loops.rs new file mode 100644 index 00000000000..4c7c7842796 --- /dev/null +++ b/tests/coverage-map/status-quo/nested_loops.rs @@ -0,0 +1,25 @@ +fn main() { + let is_true = std::env::args().len() == 1; + let mut countdown = 10; + + 'outer: while countdown > 0 { + let mut a = 100; + let mut b = 100; + for _ in 0..50 { + if a < 30 { + break; + } + a -= 5; + b -= 5; + if b < 90 { + a -= 10; + if is_true { + break 'outer; + } else { + a -= 2; + } + } + } + countdown -= 1; + } +} diff --git a/tests/coverage-map/status-quo/no_cov_crate.cov-map b/tests/coverage-map/status-quo/no_cov_crate.cov-map new file mode 100644 index 00000000000..7ab5995dc28 --- /dev/null +++ b/tests/coverage-map/status-quo/no_cov_crate.cov-map @@ -0,0 +1,78 @@ +Function name: no_cov_crate::add_coverage_1 +Raw bytes (9): 0x[01, 01, 00, 01, 01, 14, 01, 02, 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 + 20, 1) to (start + 2, 2) + +Function name: no_cov_crate::add_coverage_2 +Raw bytes (9): 0x[01, 01, 00, 01, 01, 18, 01, 02, 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 + 24, 1) to (start + 2, 2) + +Function name: no_cov_crate::add_coverage_not_called (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 1d, 01, 02, 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 + 29, 1) to (start + 2, 2) + +Function name: no_cov_crate::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 4d, 01, 0b, 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 + 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] +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) + +Function name: no_cov_crate::nested_fns::outer_both_covered +Raw bytes (9): 0x[01, 01, 00, 01, 01, 3f, 05, 0b, 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) + +Function name: no_cov_crate::nested_fns::outer_both_covered::inner +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 43, 09, 01, 17, 05, 01, 18, 02, 0e, 02, 02, 14, 02, 0e, 07, 03, 09, 00, 0a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 67, 9) to (start + 1, 23) +- Code(Counter(1)) at (prev + 1, 24) to (start + 2, 14) +- Code(Expression(0, Sub)) at (prev + 2, 20) to (start + 2, 14) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 3, 9) to (start + 0, 10) + = (c1 + (c0 - c1)) + +Function name: no_cov_crate::nested_fns::outer_not_covered::inner +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 26, 09, 01, 17, 05, 01, 18, 02, 0e, 02, 02, 14, 02, 0e, 07, 03, 09, 00, 0a] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 38, 9) to (start + 1, 23) +- Code(Counter(1)) at (prev + 1, 24) to (start + 2, 14) +- Code(Expression(0, Sub)) at (prev + 2, 20) to (start + 2, 14) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 3, 9) to (start + 0, 10) + = (c1 + (c0 - c1)) + diff --git a/tests/coverage-map/status-quo/no_cov_crate.rs b/tests/coverage-map/status-quo/no_cov_crate.rs new file mode 100644 index 00000000000..e12e4bc55e3 --- /dev/null +++ b/tests/coverage-map/status-quo/no_cov_crate.rs @@ -0,0 +1,88 @@ +// Enables `coverage(off)` on the entire crate +#![feature(coverage_attribute)] + +#[coverage(off)] +fn do_not_add_coverage_1() { + println!("called but not covered"); +} + +fn do_not_add_coverage_2() { + #![coverage(off)] + println!("called but not covered"); +} + +#[coverage(off)] +#[allow(dead_code)] +fn do_not_add_coverage_not_called() { + println!("not called and not covered"); +} + +fn add_coverage_1() { + println!("called and covered"); +} + +fn add_coverage_2() { + println!("called and covered"); +} + +#[allow(dead_code)] +fn add_coverage_not_called() { + println!("not called but covered"); +} + +// FIXME: These test-cases illustrate confusing results of nested functions. +// See https://github.com/rust-lang/rust/issues/93319 +mod nested_fns { + #[coverage(off)] + pub fn outer_not_covered(is_true: bool) { + fn inner(is_true: bool) { + if is_true { + println!("called and covered"); + } else { + println!("absolutely not covered"); + } + } + println!("called but not covered"); + inner(is_true); + } + + pub fn outer(is_true: bool) { + println!("called and covered"); + inner_not_covered(is_true); + + #[coverage(off)] + fn inner_not_covered(is_true: bool) { + if is_true { + println!("called but not covered"); + } else { + println!("absolutely not covered"); + } + } + } + + pub fn outer_both_covered(is_true: bool) { + println!("called and covered"); + inner(is_true); + + fn inner(is_true: bool) { + if is_true { + println!("called and covered"); + } else { + println!("absolutely not covered"); + } + } + } +} + +fn main() { + let is_true = std::env::args().len() == 1; + + do_not_add_coverage_1(); + do_not_add_coverage_2(); + add_coverage_1(); + add_coverage_2(); + + nested_fns::outer_not_covered(is_true); + nested_fns::outer(is_true); + nested_fns::outer_both_covered(is_true); +} diff --git a/tests/coverage-map/status-quo/overflow.cov-map b/tests/coverage-map/status-quo/overflow.cov-map new file mode 100644 index 00000000000..bfffd9b2ab5 --- /dev/null +++ b/tests/coverage-map/status-quo/overflow.cov-map @@ -0,0 +1,43 @@ +Function name: overflow::main +Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 0f, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 03, 0a, 12, 03, 13, 00, 20, 09, 00, 21, 03, 0a, 0d, 03, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 8 +- expression 0 operands: lhs = Counter(0), rhs = Expression(6, Add) +- expression 1 operands: lhs = Counter(1), rhs = Expression(7, Add) +- expression 2 operands: lhs = Counter(2), rhs = Counter(3) +- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(4) +- expression 4 operands: lhs = Expression(5, Sub), rhs = Counter(1) +- expression 5 operands: lhs = Expression(0, Add), rhs = Counter(4) +- expression 6 operands: lhs = Counter(1), rhs = Expression(7, Add) +- expression 7 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 15, 1) to (start + 1, 27) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24) + = (c0 + (c1 + (c2 + c3))) +- Code(Expression(5, Sub)) at (prev + 1, 12) to (start + 0, 26) + = ((c0 + (c1 + (c2 + c3))) - c4) +- Code(Counter(1)) at (prev + 0, 27) to (start + 3, 10) +- Code(Expression(4, Sub)) at (prev + 3, 19) to (start + 0, 32) + = (((c0 + (c1 + (c2 + c3))) - c4) - c1) +- Code(Counter(2)) at (prev + 0, 33) to (start + 3, 10) +- Code(Counter(3)) at (prev + 3, 10) to (start + 0, 11) +- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23) + = (c1 + (c2 + c3)) +- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2) + +Function name: overflow::might_overflow +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 04, 01, 01, 12, 05, 01, 13, 02, 06, 02, 02, 06, 00, 07, 07, 01, 09, 05, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 18) +- Code(Counter(1)) at (prev + 1, 19) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 9) to (start + 5, 2) + = (c1 + (c0 - c1)) + diff --git a/tests/coverage-map/status-quo/overflow.rs b/tests/coverage-map/status-quo/overflow.rs new file mode 100644 index 00000000000..bbb65c1b35d --- /dev/null +++ b/tests/coverage-map/status-quo/overflow.rs @@ -0,0 +1,63 @@ +#![allow(unused_assignments)] +// failure-status: 101 + +fn might_overflow(to_add: u32) -> u32 { + if to_add > 5 { + println!("this will probably overflow"); + } + let add_to = u32::MAX - 5; + println!("does {} + {} overflow?", add_to, to_add); + let result = to_add + add_to; + println!("continuing after overflow check"); + result +} + +fn main() -> Result<(), u8> { + let mut countdown = 10; + while countdown > 0 { + if countdown == 1 { + let result = might_overflow(10); + println!("Result: {}", result); + } else if countdown < 5 { + let result = might_overflow(1); + println!("Result: {}", result); + } + countdown -= 1; + } + Ok(()) +} + +// Notes: +// 1. Compare this program and its coverage results to those of the very similar test `assert.rs`, +// and similar tests `panic_unwind.rs`, abort.rs` and `try_error_result.rs`. +// 2. This test confirms the coverage generated when a program passes or fails a +// compiler-generated `TerminatorKind::Assert` (based on an overflow check, in this case). +// 3. Similar to how the coverage instrumentation handles `TerminatorKind::Call`, +// compiler-generated assertion failures are assumed to be a symptom of a program bug, not +// expected behavior. To simplify the coverage graphs and keep instrumented programs as +// small and fast as possible, `Assert` terminators are assumed to always succeed, and +// therefore are considered "non-branching" terminators. So, an `Assert` terminator does not +// get its own coverage counter. +// 4. After an unhandled panic or failed Assert, coverage results may not always be intuitive. +// In this test, the final count for the statements after the `if` block in `might_overflow()` +// is 4, even though the lines after `to_add + add_to` were executed only 3 times. Depending +// on the MIR graph and the structure of the code, this count could have been 3 (which might +// have been valid for the overflowed add `+`, but should have been 4 for the lines before +// the overflow. The reason for this potential uncertainty is, a `CounterKind` is incremented +// via StatementKind::Counter at the end of the block, but (as in the case in this test), +// a CounterKind::Expression is always evaluated. In this case, the expression was based on +// a `Counter` incremented as part of the evaluation of the `if` expression, which was +// executed, and counted, 4 times, before reaching the overflow add. + +// If the program did not overflow, the coverage for `might_overflow()` would look like this: +// +// 4| |fn might_overflow(to_add: u32) -> u32 { +// 5| 4| if to_add > 5 { +// 6| 0| println!("this will probably overflow"); +// 7| 4| } +// 8| 4| let add_to = u32::MAX - 5; +// 9| 4| println!("does {} + {} overflow?", add_to, to_add); +// 10| 4| let result = to_add + add_to; +// 11| 4| println!("continuing after overflow check"); +// 12| 4| result +// 13| 4|} diff --git a/tests/coverage-map/status-quo/panic_unwind.cov-map b/tests/coverage-map/status-quo/panic_unwind.cov-map new file mode 100644 index 00000000000..f6089ce55ae --- /dev/null +++ b/tests/coverage-map/status-quo/panic_unwind.cov-map @@ -0,0 +1,40 @@ +Function name: panic_unwind::main +Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 0d, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 02, 0a, 12, 02, 13, 00, 20, 09, 00, 21, 02, 0a, 0d, 02, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 8 +- expression 0 operands: lhs = Counter(0), rhs = Expression(6, Add) +- expression 1 operands: lhs = Counter(1), rhs = Expression(7, Add) +- expression 2 operands: lhs = Counter(2), rhs = Counter(3) +- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(4) +- expression 4 operands: lhs = Expression(5, Sub), rhs = Counter(1) +- expression 5 operands: lhs = Expression(0, Add), rhs = Counter(4) +- expression 6 operands: lhs = Counter(1), rhs = Expression(7, Add) +- expression 7 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 13, 1) to (start + 1, 27) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24) + = (c0 + (c1 + (c2 + c3))) +- Code(Expression(5, Sub)) at (prev + 1, 12) to (start + 0, 26) + = ((c0 + (c1 + (c2 + c3))) - c4) +- Code(Counter(1)) at (prev + 0, 27) to (start + 2, 10) +- Code(Expression(4, Sub)) at (prev + 2, 19) to (start + 0, 32) + = (((c0 + (c1 + (c2 + c3))) - c4) - c1) +- Code(Counter(2)) at (prev + 0, 33) to (start + 2, 10) +- Code(Counter(3)) at (prev + 2, 10) to (start + 0, 11) +- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23) + = (c1 + (c2 + c3)) +- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2) + +Function name: panic_unwind::might_panic +Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 01, 14, 05, 02, 09, 01, 19, 02, 02, 0c, 03, 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: 3 +- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 20) +- Code(Counter(1)) at (prev + 2, 9) to (start + 1, 25) +- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 3, 2) + = (c0 - c1) + diff --git a/tests/coverage-map/status-quo/panic_unwind.rs b/tests/coverage-map/status-quo/panic_unwind.rs new file mode 100644 index 00000000000..638d2eb6aaa --- /dev/null +++ b/tests/coverage-map/status-quo/panic_unwind.rs @@ -0,0 +1,31 @@ +#![allow(unused_assignments)] +// failure-status: 101 + +fn might_panic(should_panic: bool) { + if should_panic { + println!("panicking..."); + panic!("panics"); + } else { + println!("Don't Panic"); + } +} + +fn main() -> Result<(), u8> { + let mut countdown = 10; + while countdown > 0 { + if countdown == 1 { + might_panic(true); + } else if countdown < 5 { + might_panic(false); + } + countdown -= 1; + } + Ok(()) +} + +// Notes: +// 1. Compare this program and its coverage results to those of the similar tests `abort.rs` and +// `try_error_result.rs`. +// 2. Since the `panic_unwind.rs` test is allowed to unwind, it is also allowed to execute the +// normal program exit cleanup, including writing out the current values of the coverage +// counters. diff --git a/tests/coverage-map/status-quo/partial_eq.cov-map b/tests/coverage-map/status-quo/partial_eq.cov-map new file mode 100644 index 00000000000..dd61cd77ab6 --- /dev/null +++ b/tests/coverage-map/status-quo/partial_eq.cov-map @@ -0,0 +1,64 @@ +Function name: <partial_eq::Version as core::clone::Clone>::clone (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 04, 0a, 00, 0f] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 4, 10) to (start + 0, 15) + +Function name: <partial_eq::Version as core::cmp::Ord>::cmp (unused) +Raw bytes (14): 0x[01, 01, 00, 02, 01, 04, 33, 00, 34, 00, 00, 35, 00, 36] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 4, 51) to (start + 0, 52) +- Code(Zero) at (prev + 0, 53) to (start + 0, 54) + +Function name: <partial_eq::Version as core::cmp::PartialEq>::eq (unused) +Raw bytes (14): 0x[01, 01, 00, 02, 01, 04, 18, 00, 19, 00, 00, 20, 00, 21] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 4, 24) to (start + 0, 25) +- Code(Zero) at (prev + 0, 32) to (start + 0, 33) + +Function name: <partial_eq::Version as core::cmp::PartialOrd>::partial_cmp +Raw bytes (22): 0x[01, 01, 04, 07, 0b, 05, 09, 0f, 15, 0d, 11, 02, 01, 04, 27, 00, 28, 03, 00, 30, 00, 31] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 4 +- expression 0 operands: lhs = Expression(1, Add), rhs = Expression(2, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(5) +- expression 3 operands: lhs = Counter(3), rhs = Counter(4) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 4, 39) to (start + 0, 40) +- Code(Expression(0, Add)) at (prev + 0, 48) to (start + 0, 49) + = ((c1 + c2) + ((c3 + c4) + c5)) + +Function name: <partial_eq::Version as core::fmt::Debug>::fmt +Raw bytes (9): 0x[01, 01, 00, 01, 01, 04, 11, 00, 16] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 4, 17) to (start + 0, 22) + +Function name: <partial_eq::Version>::new +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0c, 05, 06, 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 + 12, 5) to (start + 6, 6) + +Function name: partial_eq::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 01, 05, 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 + 21, 1) to (start + 5, 2) + diff --git a/tests/coverage-map/status-quo/partial_eq.rs b/tests/coverage-map/status-quo/partial_eq.rs new file mode 100644 index 00000000000..dd8b42c18ce --- /dev/null +++ b/tests/coverage-map/status-quo/partial_eq.rs @@ -0,0 +1,46 @@ +// This test confirms an earlier problem was resolved, supporting the MIR graph generated by the +// structure of this test. + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Version { + major: usize, + minor: usize, + patch: usize, +} + +impl Version { + pub fn new(major: usize, minor: usize, patch: usize) -> Self { + Self { + major, + minor, + patch, + } + } +} + +fn main() { + let version_3_2_1 = Version::new(3, 2, 1); + let version_3_3_0 = Version::new(3, 3, 0); + + println!("{:?} < {:?} = {}", version_3_2_1, version_3_3_0, version_3_2_1 < version_3_3_0); +} + +/* + +This test verifies a bug was fixed that otherwise generated this error: + +thread 'rustc' panicked at 'No counters provided the source_hash for function: + Instance { + def: Item(WithOptConstParam { + did: DefId(0:101 ~ autocfg[c44a]::version::{impl#2}::partial_cmp), + const_param_did: None + }), + args: [] + }' +The `PartialOrd` derived by `Version` happened to generate a MIR that generated coverage +without a code region associated with any `Counter`. Code regions were associated with at least +one expression, which is allowed, but the `function_source_hash` was only passed to the codegen +(coverage mapgen) phase from a `Counter`s code region. A new method was added to pass the +`function_source_hash` without a code region, if necessary. + +*/ diff --git a/tests/coverage-map/status-quo/simple_loop.cov-map b/tests/coverage-map/status-quo/simple_loop.cov-map new file mode 100644 index 00000000000..eb49c2324cc --- /dev/null +++ b/tests/coverage-map/status-quo/simple_loop.cov-map @@ -0,0 +1,28 @@ +Function name: simple_loop::main +Raw bytes (59): 0x[01, 01, 0a, 01, 05, 27, 09, 05, 02, 23, 09, 27, 09, 05, 02, 1e, 00, 23, 09, 27, 09, 05, 02, 07, 01, 03, 01, 09, 10, 05, 0a, 05, 05, 06, 02, 05, 06, 00, 07, 23, 05, 0d, 02, 0e, 1e, 04, 0d, 00, 12, 09, 02, 0a, 03, 0a, 1b, 06, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 10 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(9, Add), rhs = Counter(2) +- expression 2 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 3 operands: lhs = Expression(8, Add), rhs = Counter(2) +- expression 4 operands: lhs = Expression(9, Add), rhs = Counter(2) +- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 6 operands: lhs = Expression(7, Sub), rhs = Zero +- expression 7 operands: lhs = Expression(8, Add), rhs = Counter(2) +- expression 8 operands: lhs = Expression(9, Add), rhs = Counter(2) +- expression 9 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 7 +- Code(Counter(0)) at (prev + 3, 1) to (start + 9, 16) +- Code(Counter(1)) at (prev + 10, 5) to (start + 5, 6) +- Code(Expression(0, Sub)) at (prev + 5, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(8, Add)) at (prev + 5, 13) to (start + 2, 14) + = ((c1 + (c0 - c1)) + c2) +- Code(Expression(7, Sub)) at (prev + 4, 13) to (start + 0, 18) + = (((c1 + (c0 - c1)) + c2) - c2) +- Code(Counter(2)) at (prev + 2, 10) to (start + 3, 10) +- Code(Expression(6, Add)) at (prev + 6, 1) to (start + 0, 2) + = ((((c1 + (c0 - c1)) + c2) - c2) + Zero) + diff --git a/tests/coverage-map/status-quo/simple_loop.rs b/tests/coverage-map/status-quo/simple_loop.rs new file mode 100644 index 00000000000..6f7f23475b8 --- /dev/null +++ b/tests/coverage-map/status-quo/simple_loop.rs @@ -0,0 +1,35 @@ +#![allow(unused_assignments)] + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 0; + + if + is_true + { + countdown + = + 10 + ; + } + + loop + { + if + countdown + == + 0 + { + break + ; + } + countdown + -= + 1 + ; + } +} diff --git a/tests/coverage-map/status-quo/simple_match.cov-map b/tests/coverage-map/status-quo/simple_match.cov-map new file mode 100644 index 00000000000..d5389f04b26 --- /dev/null +++ b/tests/coverage-map/status-quo/simple_match.cov-map @@ -0,0 +1,36 @@ +Function name: simple_match::main +Raw bytes (82): 0x[01, 01, 0e, 01, 05, 2f, 33, 05, 02, 09, 0d, 2b, 11, 2f, 33, 05, 02, 09, 0d, 26, 00, 2b, 11, 2f, 33, 05, 02, 09, 0d, 09, 00, 0a, 01, 03, 01, 07, 0f, 05, 07, 10, 02, 06, 02, 02, 06, 00, 07, 2b, 05, 09, 00, 0d, 26, 05, 0d, 00, 16, 09, 02, 0d, 00, 0e, 23, 02, 11, 02, 12, 37, 04, 0d, 07, 0e, 0d, 0a, 0d, 00, 0f, 11, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 14 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(11, Add), rhs = Expression(12, Add) +- expression 2 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 3 operands: lhs = Counter(2), rhs = Counter(3) +- expression 4 operands: lhs = Expression(10, Add), rhs = Counter(4) +- expression 5 operands: lhs = Expression(11, Add), rhs = Expression(12, Add) +- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 7 operands: lhs = Counter(2), rhs = Counter(3) +- expression 8 operands: lhs = Expression(9, Sub), rhs = Zero +- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(4) +- expression 10 operands: lhs = Expression(11, Add), rhs = Expression(12, Add) +- expression 11 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 12 operands: lhs = Counter(2), rhs = Counter(3) +- expression 13 operands: lhs = Counter(2), rhs = Zero +Number of file 0 mappings: 10 +- Code(Counter(0)) at (prev + 3, 1) to (start + 7, 15) +- Code(Counter(1)) at (prev + 7, 16) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(10, Add)) at (prev + 5, 9) to (start + 0, 13) + = ((c1 + (c0 - c1)) + (c2 + c3)) +- Code(Expression(9, Sub)) at (prev + 5, 13) to (start + 0, 22) + = (((c1 + (c0 - c1)) + (c2 + c3)) - c4) +- Code(Counter(2)) at (prev + 2, 13) to (start + 0, 14) +- Code(Expression(8, Add)) at (prev + 2, 17) to (start + 2, 18) + = ((((c1 + (c0 - c1)) + (c2 + c3)) - c4) + Zero) +- Code(Expression(13, Add)) at (prev + 4, 13) to (start + 7, 14) + = (c2 + Zero) +- Code(Counter(3)) at (prev + 10, 13) to (start + 0, 15) +- Code(Counter(4)) at (prev + 3, 1) to (start + 0, 2) + diff --git a/tests/coverage-map/status-quo/simple_match.rs b/tests/coverage-map/status-quo/simple_match.rs new file mode 100644 index 00000000000..be99e59a826 --- /dev/null +++ b/tests/coverage-map/status-quo/simple_match.rs @@ -0,0 +1,43 @@ +#![allow(unused_assignments, unused_variables)] + +fn main() { + // Initialize test constants in a way that cannot be determined at compile time, to ensure + // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from + // dependent conditions. + let is_true = std::env::args().len() == 1; + + let mut countdown = 1; + if is_true { + countdown = 0; + } + + for + _ + in + 0..2 + { + let z + ; + match + countdown + { + x + if + x + < + 1 + => + { + z = countdown + ; + let y = countdown + ; + countdown = 10 + ; + } + _ + => + {} + } + } +} diff --git a/tests/coverage-map/status-quo/sort_groups.cov-map b/tests/coverage-map/status-quo/sort_groups.cov-map new file mode 100644 index 00000000000..7156a66cf89 --- /dev/null +++ b/tests/coverage-map/status-quo/sort_groups.cov-map @@ -0,0 +1,68 @@ +Function name: sort_groups::generic_fn::<&str> +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 12) +- Code(Counter(1)) at (prev + 1, 13) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: sort_groups::generic_fn::<()> +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 12) +- Code(Counter(1)) at (prev + 1, 13) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: sort_groups::generic_fn::<i32> +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 12) +- Code(Counter(1)) at (prev + 1, 13) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: sort_groups::main +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 06, 01, 04, 0d, 00, 04, 0e, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 6, 1) to (start + 4, 13) +- Code(Zero) at (prev + 4, 14) to (start + 2, 6) +- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 2, 2) + = (c1 + (c0 - c1)) + +Function name: sort_groups::other_fn +Raw bytes (9): 0x[01, 01, 00, 01, 01, 17, 01, 00, 11] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 23, 1) to (start + 0, 17) + diff --git a/tests/coverage-map/status-quo/sort_groups.rs b/tests/coverage-map/status-quo/sort_groups.rs new file mode 100644 index 00000000000..f89f9f3ec61 --- /dev/null +++ b/tests/coverage-map/status-quo/sort_groups.rs @@ -0,0 +1,23 @@ +// compile-flags: --edition=2021 + +// Demonstrate that `sort_subviews.py` can sort instantiation groups into a +// predictable order, while preserving their heterogeneous contents. + +fn main() { + let cond = std::env::args().len() > 1; + generic_fn::<()>(cond); + generic_fn::<&'static str>(!cond); + if false { + generic_fn::<char>(cond); + } + generic_fn::<i32>(cond); + other_fn(); +} + +fn generic_fn<T>(cond: bool) { + if cond { + println!("{}", std::any::type_name::<T>()); + } +} + +fn other_fn() {} diff --git a/tests/coverage-map/status-quo/test_harness.cov-map b/tests/coverage-map/status-quo/test_harness.cov-map new file mode 100644 index 00000000000..b0e955dd142 --- /dev/null +++ b/tests/coverage-map/status-quo/test_harness.cov-map @@ -0,0 +1,24 @@ +Function name: test_harness::my_test +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 01, 00, 10] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 10, 1) to (start + 0, 16) + +Function name: test_harness::my_test::{closure#0} +Raw bytes (9): 0x[01, 01, 00, 01, 01, 09, 01, 00, 08] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 9, 1) to (start + 0, 8) + +Function name: test_harness::unused (unused) +Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 01, 00, 0f] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 7, 1) to (start + 0, 15) + diff --git a/tests/coverage-map/status-quo/test_harness.rs b/tests/coverage-map/status-quo/test_harness.rs new file mode 100644 index 00000000000..12a755734c1 --- /dev/null +++ b/tests/coverage-map/status-quo/test_harness.rs @@ -0,0 +1,10 @@ +// Verify that the entry point injected by the test harness doesn't cause +// weird artifacts in the coverage report (e.g. issue #10749). + +// compile-flags: --test + +#[allow(dead_code)] +fn unused() {} + +#[test] +fn my_test() {} diff --git a/tests/coverage-map/status-quo/tight_inf_loop.cov-map b/tests/coverage-map/status-quo/tight_inf_loop.cov-map new file mode 100644 index 00000000000..76884212c14 --- /dev/null +++ b/tests/coverage-map/status-quo/tight_inf_loop.cov-map @@ -0,0 +1,12 @@ +Function name: tight_inf_loop::main +Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 01, 01, 01, 0d, 00, 02, 09, 00, 10, 02, 01, 06, 01, 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: 3 +- Code(Counter(0)) at (prev + 1, 1) to (start + 1, 13) +- Code(Zero) at (prev + 2, 9) to (start + 0, 16) +- Code(Expression(0, Sub)) at (prev + 1, 6) to (start + 1, 2) + = (c0 - c1) + diff --git a/tests/coverage-map/status-quo/tight_inf_loop.rs b/tests/coverage-map/status-quo/tight_inf_loop.rs new file mode 100644 index 00000000000..cef99027aaa --- /dev/null +++ b/tests/coverage-map/status-quo/tight_inf_loop.rs @@ -0,0 +1,5 @@ +fn main() { + if false { + loop {} + } +} diff --git a/tests/coverage-map/status-quo/try_error_result.cov-map b/tests/coverage-map/status-quo/try_error_result.cov-map new file mode 100644 index 00000000000..b52e78d1195 --- /dev/null +++ b/tests/coverage-map/status-quo/try_error_result.cov-map @@ -0,0 +1,226 @@ +Function name: <try_error_result::Thing1>::get_thing_2 +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 28, 05, 01, 18, 05, 02, 0d, 00, 14, 02, 02, 0d, 00, 1a, 07, 02, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 40, 5) to (start + 1, 24) +- Code(Counter(1)) at (prev + 2, 13) to (start + 0, 20) +- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 26) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 2, 5) to (start + 0, 6) + = (c1 + (c0 - c1)) + +Function name: <try_error_result::Thing2>::call +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 33, 05, 01, 18, 05, 02, 0d, 00, 14, 02, 02, 0d, 00, 13, 07, 02, 05, 00, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 51, 5) to (start + 1, 24) +- Code(Counter(1)) at (prev + 2, 13) to (start + 0, 20) +- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 19) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 2, 5) to (start + 0, 6) + = (c1 + (c0 - c1)) + +Function name: try_error_result::call +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 04, 01, 01, 14, 05, 02, 09, 00, 10, 02, 02, 09, 00, 0f, 07, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 20) +- Code(Counter(1)) at (prev + 2, 9) to (start + 0, 16) +- Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 15) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: try_error_result::main +Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 70, 01, 02, 0c, 05, 03, 05, 00, 06, 02, 02, 05, 00, 0b, 07, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 112, 1) to (start + 2, 12) +- Code(Counter(1)) at (prev + 3, 5) to (start + 0, 6) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 11) + = (c0 - c1) +- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) + = (c1 + (c0 - c1)) + +Function name: try_error_result::test1 +Raw bytes (77): 0x[01, 01, 09, 01, 07, 05, 09, 03, 0d, 1d, 11, 16, 1d, 03, 0d, 1f, 0d, 11, 23, 15, 19, 0b, 01, 0c, 01, 02, 17, 03, 07, 09, 00, 0e, 16, 02, 09, 04, 1a, 1d, 06, 0d, 00, 29, 11, 00, 29, 00, 2a, 0e, 01, 0d, 00, 2a, 15, 00, 2a, 00, 2b, 12, 04, 0d, 00, 2a, 19, 00, 2a, 00, 2b, 0d, 03, 05, 00, 0b, 1b, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 9 +- expression 0 operands: lhs = Counter(0), rhs = Expression(1, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Counter(7), rhs = Counter(4) +- expression 4 operands: lhs = Expression(5, Sub), rhs = Counter(7) +- expression 5 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 6 operands: lhs = Expression(7, Add), rhs = Counter(3) +- expression 7 operands: lhs = Counter(4), rhs = Expression(8, Add) +- expression 8 operands: lhs = Counter(5), rhs = Counter(6) +Number of file 0 mappings: 11 +- Code(Counter(0)) at (prev + 12, 1) to (start + 2, 23) +- Code(Expression(0, Add)) at (prev + 7, 9) to (start + 0, 14) + = (c0 + (c1 + c2)) +- Code(Expression(5, Sub)) at (prev + 2, 9) to (start + 4, 26) + = ((c0 + (c1 + c2)) - c3) +- Code(Counter(7)) at (prev + 6, 13) to (start + 0, 41) +- Code(Counter(4)) at (prev + 0, 41) to (start + 0, 42) +- Code(Expression(3, Sub)) at (prev + 1, 13) to (start + 0, 42) + = (c7 - c4) +- Code(Counter(5)) at (prev + 0, 42) to (start + 0, 43) +- Code(Expression(4, Sub)) at (prev + 4, 13) to (start + 0, 42) + = (((c0 + (c1 + c2)) - c3) - c7) +- Code(Counter(6)) at (prev + 0, 42) to (start + 0, 43) +- Code(Counter(3)) at (prev + 3, 5) to (start + 0, 11) +- Code(Expression(6, Add)) at (prev + 1, 1) to (start + 0, 2) + = ((c4 + (c5 + c6)) + c3) + +Function name: try_error_result::test2 +Raw bytes (373): 0x[01, 01, 41, 01, 07, 05, 09, 03, 0d, 41, 11, 52, 15, 41, 11, 4a, 1d, 4e, 19, 52, 15, 41, 11, 4e, 00, 52, 15, 41, 11, 4e, 19, 52, 15, 41, 11, 46, 00, 4a, 1d, 4e, 19, 52, 15, 41, 11, 6a, 25, 49, 21, 49, 21, 66, 00, 6a, 25, 49, 21, 9a, 01, 2d, 9e, 01, 29, a2, 01, 41, 03, 0d, a2, 01, 41, 03, 0d, 9e, 01, 29, a2, 01, 41, 03, 0d, 96, 01, 00, 9a, 01, 2d, 9e, 01, 29, a2, 01, 41, 03, 0d, ba, 01, 35, 45, 31, 45, 31, b6, 01, 00, ba, 01, 35, 45, 31, d2, 01, 3d, 4d, 39, 4d, 39, ce, 01, 00, d2, 01, 3d, 4d, 39, db, 01, 0d, 11, df, 01, e3, 01, f3, 01, 15, e7, 01, eb, 01, ef, 01, 19, 1d, 21, 25, f7, 01, fb, 01, 29, 2d, ff, 01, 83, 02, 31, 35, 39, 3d, 28, 01, 3c, 01, 03, 17, 03, 08, 09, 00, 0e, a2, 01, 02, 09, 04, 1a, 41, 06, 0d, 00, 2f, 11, 00, 2f, 00, 30, 52, 00, 31, 03, 35, 15, 04, 11, 00, 12, 4e, 02, 11, 04, 12, 46, 05, 11, 00, 14, 2b, 00, 17, 00, 41, 19, 00, 41, 00, 42, 4a, 00, 43, 00, 5f, 1d, 00, 5f, 00, 60, 43, 01, 0d, 00, 20, 66, 01, 11, 00, 14, 49, 00, 17, 00, 41, 21, 00, 41, 00, 42, 6a, 00, 43, 00, 60, 25, 00, 60, 00, 61, 63, 01, 0d, 00, 20, 96, 01, 04, 11, 00, 14, 9e, 01, 00, 17, 00, 42, 29, 00, 42, 00, 43, 9a, 01, 00, 44, 00, 61, 2d, 00, 61, 00, 62, 93, 01, 01, 0d, 00, 20, b6, 01, 01, 11, 00, 14, 45, 00, 17, 01, 36, 31, 01, 36, 00, 37, ba, 01, 01, 12, 00, 2f, 35, 00, 2f, 00, 30, b3, 01, 01, 0d, 00, 20, ce, 01, 01, 11, 00, 14, 4d, 00, 17, 01, 36, 39, 02, 11, 00, 12, d2, 01, 01, 12, 00, 2f, 3d, 01, 11, 00, 12, cb, 01, 02, 0d, 00, 20, 0d, 03, 05, 00, 0b, d7, 01, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 65 +- expression 0 operands: lhs = Counter(0), rhs = Expression(1, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Counter(16), rhs = Counter(4) +- expression 4 operands: lhs = Expression(20, Sub), rhs = Counter(5) +- expression 5 operands: lhs = Counter(16), rhs = Counter(4) +- expression 6 operands: lhs = Expression(18, Sub), rhs = Counter(7) +- expression 7 operands: lhs = Expression(19, Sub), rhs = Counter(6) +- expression 8 operands: lhs = Expression(20, Sub), rhs = Counter(5) +- expression 9 operands: lhs = Counter(16), rhs = Counter(4) +- expression 10 operands: lhs = Expression(19, Sub), rhs = Zero +- expression 11 operands: lhs = Expression(20, Sub), rhs = Counter(5) +- expression 12 operands: lhs = Counter(16), rhs = Counter(4) +- expression 13 operands: lhs = Expression(19, Sub), rhs = Counter(6) +- expression 14 operands: lhs = Expression(20, Sub), rhs = Counter(5) +- expression 15 operands: lhs = Counter(16), rhs = Counter(4) +- expression 16 operands: lhs = Expression(17, Sub), rhs = Zero +- expression 17 operands: lhs = Expression(18, Sub), rhs = Counter(7) +- expression 18 operands: lhs = Expression(19, Sub), rhs = Counter(6) +- expression 19 operands: lhs = Expression(20, Sub), rhs = Counter(5) +- expression 20 operands: lhs = Counter(16), rhs = Counter(4) +- expression 21 operands: lhs = Expression(26, Sub), rhs = Counter(9) +- expression 22 operands: lhs = Counter(18), rhs = Counter(8) +- expression 23 operands: lhs = Counter(18), rhs = Counter(8) +- expression 24 operands: lhs = Expression(25, Sub), rhs = Zero +- expression 25 operands: lhs = Expression(26, Sub), rhs = Counter(9) +- expression 26 operands: lhs = Counter(18), rhs = Counter(8) +- expression 27 operands: lhs = Expression(38, Sub), rhs = Counter(11) +- expression 28 operands: lhs = Expression(39, Sub), rhs = Counter(10) +- expression 29 operands: lhs = Expression(40, Sub), rhs = Counter(16) +- expression 30 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 31 operands: lhs = Expression(40, Sub), rhs = Counter(16) +- expression 32 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 33 operands: lhs = Expression(39, Sub), rhs = Counter(10) +- expression 34 operands: lhs = Expression(40, Sub), rhs = Counter(16) +- expression 35 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 36 operands: lhs = Expression(37, Sub), rhs = Zero +- expression 37 operands: lhs = Expression(38, Sub), rhs = Counter(11) +- expression 38 operands: lhs = Expression(39, Sub), rhs = Counter(10) +- expression 39 operands: lhs = Expression(40, Sub), rhs = Counter(16) +- expression 40 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 41 operands: lhs = Expression(46, Sub), rhs = Counter(13) +- expression 42 operands: lhs = Counter(17), rhs = Counter(12) +- expression 43 operands: lhs = Counter(17), rhs = Counter(12) +- expression 44 operands: lhs = Expression(45, Sub), rhs = Zero +- expression 45 operands: lhs = Expression(46, Sub), rhs = Counter(13) +- expression 46 operands: lhs = Counter(17), rhs = Counter(12) +- expression 47 operands: lhs = Expression(52, Sub), rhs = Counter(15) +- expression 48 operands: lhs = Counter(19), rhs = Counter(14) +- expression 49 operands: lhs = Counter(19), rhs = Counter(14) +- expression 50 operands: lhs = Expression(51, Sub), rhs = Zero +- expression 51 operands: lhs = Expression(52, Sub), rhs = Counter(15) +- expression 52 operands: lhs = Counter(19), rhs = Counter(14) +- expression 53 operands: lhs = Expression(54, Add), rhs = Counter(3) +- expression 54 operands: lhs = Counter(4), rhs = Expression(55, Add) +- expression 55 operands: lhs = Expression(56, Add), rhs = Expression(60, Add) +- expression 56 operands: lhs = Counter(5), rhs = Expression(57, Add) +- expression 57 operands: lhs = Expression(58, Add), rhs = Expression(59, Add) +- expression 58 operands: lhs = Counter(6), rhs = Counter(7) +- expression 59 operands: lhs = Counter(8), rhs = Counter(9) +- expression 60 operands: lhs = Expression(61, Add), rhs = Expression(62, Add) +- expression 61 operands: lhs = Counter(10), rhs = Counter(11) +- expression 62 operands: lhs = Expression(63, Add), rhs = Expression(64, Add) +- expression 63 operands: lhs = Counter(12), rhs = Counter(13) +- expression 64 operands: lhs = Counter(14), rhs = Counter(15) +Number of file 0 mappings: 40 +- Code(Counter(0)) at (prev + 60, 1) to (start + 3, 23) +- Code(Expression(0, Add)) at (prev + 8, 9) to (start + 0, 14) + = (c0 + (c1 + c2)) +- Code(Expression(40, Sub)) at (prev + 2, 9) to (start + 4, 26) + = ((c0 + (c1 + c2)) - c3) +- Code(Counter(16)) at (prev + 6, 13) to (start + 0, 47) +- Code(Counter(4)) at (prev + 0, 47) to (start + 0, 48) +- Code(Expression(20, Sub)) at (prev + 0, 49) to (start + 3, 53) + = (c16 - c4) +- Code(Counter(5)) at (prev + 4, 17) to (start + 0, 18) +- Code(Expression(19, Sub)) at (prev + 2, 17) to (start + 4, 18) + = ((c16 - c4) - c5) +- Code(Expression(17, Sub)) at (prev + 5, 17) to (start + 0, 20) + = ((((c16 - c4) - c5) - c6) - c7) +- Code(Expression(10, Add)) at (prev + 0, 23) to (start + 0, 65) + = (((c16 - c4) - c5) + Zero) +- Code(Counter(6)) at (prev + 0, 65) to (start + 0, 66) +- Code(Expression(18, Sub)) at (prev + 0, 67) to (start + 0, 95) + = (((c16 - c4) - c5) - c6) +- Code(Counter(7)) at (prev + 0, 95) to (start + 0, 96) +- Code(Expression(16, Add)) at (prev + 1, 13) to (start + 0, 32) + = (((((c16 - c4) - c5) - c6) - c7) + Zero) +- Code(Expression(25, Sub)) at (prev + 1, 17) to (start + 0, 20) + = ((c18 - c8) - c9) +- Code(Counter(18)) at (prev + 0, 23) to (start + 0, 65) +- Code(Counter(8)) at (prev + 0, 65) to (start + 0, 66) +- Code(Expression(26, Sub)) at (prev + 0, 67) to (start + 0, 96) + = (c18 - c8) +- Code(Counter(9)) at (prev + 0, 96) to (start + 0, 97) +- Code(Expression(24, Add)) at (prev + 1, 13) to (start + 0, 32) + = (((c18 - c8) - c9) + Zero) +- Code(Expression(37, Sub)) at (prev + 4, 17) to (start + 0, 20) + = (((((c0 + (c1 + c2)) - c3) - c16) - c10) - c11) +- Code(Expression(39, Sub)) at (prev + 0, 23) to (start + 0, 66) + = (((c0 + (c1 + c2)) - c3) - c16) +- Code(Counter(10)) at (prev + 0, 66) to (start + 0, 67) +- Code(Expression(38, Sub)) at (prev + 0, 68) to (start + 0, 97) + = ((((c0 + (c1 + c2)) - c3) - c16) - c10) +- Code(Counter(11)) at (prev + 0, 97) to (start + 0, 98) +- Code(Expression(36, Add)) at (prev + 1, 13) to (start + 0, 32) + = ((((((c0 + (c1 + c2)) - c3) - c16) - c10) - c11) + Zero) +- Code(Expression(45, Sub)) at (prev + 1, 17) to (start + 0, 20) + = ((c17 - c12) - c13) +- Code(Counter(17)) at (prev + 0, 23) to (start + 1, 54) +- Code(Counter(12)) at (prev + 1, 54) to (start + 0, 55) +- Code(Expression(46, Sub)) at (prev + 1, 18) to (start + 0, 47) + = (c17 - c12) +- Code(Counter(13)) at (prev + 0, 47) to (start + 0, 48) +- Code(Expression(44, Add)) at (prev + 1, 13) to (start + 0, 32) + = (((c17 - c12) - c13) + Zero) +- Code(Expression(51, Sub)) at (prev + 1, 17) to (start + 0, 20) + = ((c19 - c14) - c15) +- Code(Counter(19)) at (prev + 0, 23) to (start + 1, 54) +- Code(Counter(14)) at (prev + 2, 17) to (start + 0, 18) +- Code(Expression(52, Sub)) at (prev + 1, 18) to (start + 0, 47) + = (c19 - c14) +- Code(Counter(15)) at (prev + 1, 17) to (start + 0, 18) +- Code(Expression(50, Add)) at (prev + 2, 13) to (start + 0, 32) + = (((c19 - c14) - c15) + Zero) +- Code(Counter(3)) at (prev + 3, 5) to (start + 0, 11) +- Code(Expression(53, Add)) at (prev + 1, 1) to (start + 0, 2) + = ((c4 + ((c5 + ((c6 + c7) + (c8 + c9))) + ((c10 + c11) + ((c12 + c13) + (c14 + c15))))) + c3) + diff --git a/tests/coverage-map/status-quo/try_error_result.rs b/tests/coverage-map/status-quo/try_error_result.rs new file mode 100644 index 00000000000..557cbf22bfa --- /dev/null +++ b/tests/coverage-map/status-quo/try_error_result.rs @@ -0,0 +1,118 @@ +#![allow(unused_assignments)] +// failure-status: 1 + +fn call(return_error: bool) -> Result<(), ()> { + if return_error { + Err(()) + } else { + Ok(()) + } +} + +fn test1() -> Result<(), ()> { + let mut + countdown = 10 + ; + for + _ + in + 0..10 + { + countdown + -= 1 + ; + if + countdown < 5 + { + call(/*return_error=*/ true)?; + call(/*return_error=*/ false)?; + } + else + { + call(/*return_error=*/ false)?; + } + } + Ok(()) +} + +struct Thing1; +impl Thing1 { + fn get_thing_2(&self, return_error: bool) -> Result<Thing2, ()> { + if return_error { + Err(()) + } else { + Ok(Thing2 {}) + } + } +} + +struct Thing2; +impl Thing2 { + fn call(&self, return_error: bool) -> Result<u32, ()> { + if return_error { + Err(()) + } else { + Ok(57) + } + } +} + +fn test2() -> Result<(), ()> { + let thing1 = Thing1{}; + let mut + countdown = 10 + ; + for + _ + in + 0..10 + { + countdown + -= 1 + ; + if + countdown < 5 + { + thing1.get_thing_2(/*err=*/ false)?.call(/*err=*/ true).expect_err("call should fail"); + thing1 + . + get_thing_2(/*return_error=*/ false) + ? + . + call(/*return_error=*/ true) + . + expect_err( + "call should fail" + ); + let val = thing1.get_thing_2(/*return_error=*/ true)?.call(/*return_error=*/ true)?; + assert_eq!(val, 57); + let val = thing1.get_thing_2(/*return_error=*/ true)?.call(/*return_error=*/ false)?; + assert_eq!(val, 57); + } + else + { + let val = thing1.get_thing_2(/*return_error=*/ false)?.call(/*return_error=*/ false)?; + assert_eq!(val, 57); + let val = thing1 + .get_thing_2(/*return_error=*/ false)? + .call(/*return_error=*/ false)?; + assert_eq!(val, 57); + let val = thing1 + .get_thing_2(/*return_error=*/ false) + ? + .call(/*return_error=*/ false) + ? + ; + assert_eq!(val, 57); + } + } + Ok(()) +} + +fn main() -> Result<(), ()> { + test1().expect_err("test1 should fail"); + test2() + ? + ; + Ok(()) +} diff --git a/tests/coverage-map/status-quo/unused.cov-map b/tests/coverage-map/status-quo/unused.cov-map new file mode 100644 index 00000000000..c8b8f195fbd --- /dev/null +++ b/tests/coverage-map/status-quo/unused.cov-map @@ -0,0 +1,94 @@ +Function name: unused::foo::<f32> +Raw bytes (42): 0x[01, 01, 04, 01, 0f, 05, 09, 03, 0d, 05, 09, 06, 01, 03, 01, 01, 12, 03, 02, 0b, 00, 11, 0a, 01, 09, 00, 0f, 09, 00, 13, 00, 19, 0f, 01, 09, 00, 0f, 0d, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 4 +- expression 0 operands: lhs = Counter(0), rhs = Expression(3, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Counter(1), rhs = Counter(2) +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 3, 1) to (start + 1, 18) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 17) + = (c0 + (c1 + c2)) +- Code(Expression(2, Sub)) at (prev + 1, 9) to (start + 0, 15) + = ((c0 + (c1 + c2)) - c3) +- Code(Counter(2)) at (prev + 0, 19) to (start + 0, 25) +- Code(Expression(3, Add)) at (prev + 1, 9) to (start + 0, 15) + = (c1 + c2) +- Code(Counter(3)) at (prev + 2, 1) to (start + 0, 2) + +Function name: unused::foo::<u32> +Raw bytes (42): 0x[01, 01, 04, 01, 0f, 05, 09, 03, 0d, 05, 09, 06, 01, 03, 01, 01, 12, 03, 02, 0b, 00, 11, 0a, 01, 09, 00, 0f, 09, 00, 13, 00, 19, 0f, 01, 09, 00, 0f, 0d, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 4 +- expression 0 operands: lhs = Counter(0), rhs = Expression(3, Add) +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3) +- expression 3 operands: lhs = Counter(1), rhs = Counter(2) +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 3, 1) to (start + 1, 18) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 17) + = (c0 + (c1 + c2)) +- Code(Expression(2, Sub)) at (prev + 1, 9) to (start + 0, 15) + = ((c0 + (c1 + c2)) - c3) +- Code(Counter(2)) at (prev + 0, 19) to (start + 0, 25) +- Code(Expression(3, Add)) at (prev + 1, 9) to (start + 0, 15) + = (c1 + c2) +- Code(Counter(3)) at (prev + 2, 1) to (start + 0, 2) + +Function name: unused::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 25, 01, 04, 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 + 37, 1) to (start + 4, 2) + +Function name: unused::unused_func (unused) +Raw bytes (24): 0x[01, 01, 00, 04, 01, 13, 01, 01, 0e, 00, 01, 0f, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 19, 1) to (start + 1, 14) +- Code(Zero) at (prev + 1, 15) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Zero) at (prev + 1, 1) to (start + 0, 2) + +Function name: unused::unused_func2 (unused) +Raw bytes (24): 0x[01, 01, 00, 04, 01, 19, 01, 01, 0e, 00, 01, 0f, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 25, 1) to (start + 1, 14) +- Code(Zero) at (prev + 1, 15) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Zero) at (prev + 1, 1) to (start + 0, 2) + +Function name: unused::unused_func3 (unused) +Raw bytes (24): 0x[01, 01, 00, 04, 01, 1f, 01, 01, 0e, 00, 01, 0f, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 31, 1) to (start + 1, 14) +- Code(Zero) at (prev + 1, 15) to (start + 2, 6) +- Code(Zero) at (prev + 2, 6) to (start + 0, 7) +- Code(Zero) at (prev + 1, 1) to (start + 0, 2) + +Function name: unused::unused_template_func::<_> (unused) +Raw bytes (34): 0x[01, 01, 00, 06, 01, 0b, 01, 01, 12, 00, 02, 0b, 00, 11, 00, 01, 09, 00, 0f, 00, 00, 13, 00, 19, 00, 01, 09, 00, 0f, 00, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 6 +- Code(Counter(0)) at (prev + 11, 1) to (start + 1, 18) +- Code(Zero) at (prev + 2, 11) to (start + 0, 17) +- Code(Zero) at (prev + 1, 9) to (start + 0, 15) +- Code(Zero) at (prev + 0, 19) to (start + 0, 25) +- Code(Zero) at (prev + 1, 9) to (start + 0, 15) +- Code(Zero) at (prev + 2, 1) to (start + 0, 2) + diff --git a/tests/coverage-map/status-quo/unused.rs b/tests/coverage-map/status-quo/unused.rs new file mode 100644 index 00000000000..d985af13547 --- /dev/null +++ b/tests/coverage-map/status-quo/unused.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused_assignments, unused_must_use, unused_variables)] + +fn foo<T>(x: T) { + let mut i = 0; + while i < 10 { + i != 0 || i != 0; + i += 1; + } +} + +fn unused_template_func<T>(x: T) { + let mut i = 0; + while i < 10 { + i != 0 || i != 0; + i += 1; + } +} + +fn unused_func(mut a: u32) { + if a != 0 { + a += 1; + } +} + +fn unused_func2(mut a: u32) { + if a != 0 { + a += 1; + } +} + +fn unused_func3(mut a: u32) { + if a != 0 { + a += 1; + } +} + +fn main() -> Result<(), u8> { + foo::<u32>(0); + foo::<f32>(0.0); + Ok(()) +} diff --git a/tests/coverage-map/status-quo/while.cov-map b/tests/coverage-map/status-quo/while.cov-map new file mode 100644 index 00000000000..cfd2be96a0d --- /dev/null +++ b/tests/coverage-map/status-quo/while.cov-map @@ -0,0 +1,15 @@ +Function name: while::main +Raw bytes (28): 0x[01, 01, 02, 01, 05, 03, 05, 04, 01, 01, 01, 01, 10, 03, 02, 0b, 00, 14, 00, 00, 15, 01, 06, 06, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(0, Add), rhs = Counter(1) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 1, 1) to (start + 1, 16) +- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 20) + = (c0 + c1) +- Code(Zero) at (prev + 0, 21) to (start + 1, 6) +- Code(Expression(1, Sub)) at (prev + 2, 1) to (start + 0, 2) + = ((c0 + c1) - c1) + diff --git a/tests/coverage-map/status-quo/while.rs b/tests/coverage-map/status-quo/while.rs new file mode 100644 index 00000000000..781b90b3566 --- /dev/null +++ b/tests/coverage-map/status-quo/while.rs @@ -0,0 +1,5 @@ +fn main() { + let num = 9; + while num >= 10 { + } +} diff --git a/tests/coverage-map/status-quo/while_early_ret.cov-map b/tests/coverage-map/status-quo/while_early_ret.cov-map new file mode 100644 index 00000000000..369ebe891f1 --- /dev/null +++ b/tests/coverage-map/status-quo/while_early_ret.cov-map @@ -0,0 +1,26 @@ +Function name: while_early_ret::main +Raw bytes (61): 0x[01, 01, 06, 01, 05, 03, 09, 0e, 05, 03, 09, 17, 09, 0d, 11, 09, 01, 04, 01, 01, 1b, 03, 03, 09, 02, 0a, 0e, 05, 0d, 02, 0e, 0a, 06, 15, 02, 16, 0d, 04, 15, 00, 1b, 11, 04, 15, 00, 1b, 05, 03, 0a, 03, 0a, 09, 06, 05, 00, 0b, 13, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 6 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Expression(0, Add), rhs = Counter(2) +- expression 2 operands: lhs = Expression(3, Sub), rhs = Counter(1) +- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(2) +- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(2) +- expression 5 operands: lhs = Counter(3), rhs = Counter(4) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 27) +- Code(Expression(0, Add)) at (prev + 3, 9) to (start + 2, 10) + = (c0 + c1) +- Code(Expression(3, Sub)) at (prev + 5, 13) to (start + 2, 14) + = ((c0 + c1) - c2) +- Code(Expression(2, Sub)) at (prev + 6, 21) to (start + 2, 22) + = (((c0 + c1) - c2) - c1) +- Code(Counter(3)) at (prev + 4, 21) to (start + 0, 27) +- Code(Counter(4)) at (prev + 4, 21) to (start + 0, 27) +- Code(Counter(1)) at (prev + 3, 10) to (start + 3, 10) +- Code(Counter(2)) at (prev + 6, 5) to (start + 0, 11) +- Code(Expression(4, Add)) at (prev + 1, 1) to (start + 0, 2) + = ((c3 + c4) + c2) + diff --git a/tests/coverage-map/status-quo/while_early_ret.rs b/tests/coverage-map/status-quo/while_early_ret.rs new file mode 100644 index 00000000000..b2f0eee2cc0 --- /dev/null +++ b/tests/coverage-map/status-quo/while_early_ret.rs @@ -0,0 +1,42 @@ +#![allow(unused_assignments)] +// failure-status: 1 + +fn main() -> Result<(), u8> { + let mut countdown = 10; + while + countdown + > + 0 + { + if + countdown + < + 5 + { + return + if + countdown + > + 8 + { + Ok(()) + } + else + { + Err(1) + } + ; + } + countdown + -= + 1 + ; + } + Ok(()) +} + +// ISSUE(77553): Originally, this test had `Err(1)` on line 22 (instead of `Ok(())`) and +// `std::process::exit(2)` on line 26 (instead of `Err(1)`); and this worked as expected on Linux +// and MacOS. But on Windows (MSVC, at least), the call to `std::process::exit()` exits the program +// without saving the InstrProf coverage counters. The use of `std::process:exit()` is not critical +// to the coverage test for early returns, but this is a limitation that should be fixed. diff --git a/tests/coverage-map/status-quo/yield.cov-map b/tests/coverage-map/status-quo/yield.cov-map new file mode 100644 index 00000000000..16caa2db343 --- /dev/null +++ b/tests/coverage-map/status-quo/yield.cov-map @@ -0,0 +1,72 @@ +Function name: yield::main +Raw bytes (118): 0x[01, 01, 11, 01, 00, 05, 09, 0d, 00, 0d, 11, 32, 15, 0d, 11, 11, 15, 2e, 00, 32, 15, 0d, 11, 2e, 00, 32, 15, 0d, 11, 19, 1d, 21, 00, 25, 29, 2d, 00, 10, 01, 07, 01, 01, 16, 03, 06, 0b, 00, 2e, 0d, 01, 27, 00, 29, 07, 01, 0e, 00, 34, 0b, 02, 0b, 00, 2e, 32, 01, 22, 00, 27, 2e, 00, 2c, 00, 2e, 1b, 01, 0e, 00, 34, 1f, 03, 09, 00, 16, 2b, 07, 0b, 00, 2e, 21, 01, 27, 00, 29, 37, 01, 0e, 00, 34, 3b, 02, 0b, 00, 2e, 2d, 01, 27, 00, 29, 3f, 01, 0e, 00, 34, 43, 02, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 17 +- expression 0 operands: lhs = Counter(0), rhs = Zero +- expression 1 operands: lhs = Counter(1), rhs = Counter(2) +- expression 2 operands: lhs = Counter(3), rhs = Zero +- expression 3 operands: lhs = Counter(3), rhs = Counter(4) +- expression 4 operands: lhs = Expression(12, Sub), rhs = Counter(5) +- expression 5 operands: lhs = Counter(3), rhs = Counter(4) +- expression 6 operands: lhs = Counter(4), rhs = Counter(5) +- expression 7 operands: lhs = Expression(11, Sub), rhs = Zero +- expression 8 operands: lhs = Expression(12, Sub), rhs = Counter(5) +- expression 9 operands: lhs = Counter(3), rhs = Counter(4) +- expression 10 operands: lhs = Expression(11, Sub), rhs = Zero +- expression 11 operands: lhs = Expression(12, Sub), rhs = Counter(5) +- expression 12 operands: lhs = Counter(3), rhs = Counter(4) +- expression 13 operands: lhs = Counter(6), rhs = Counter(7) +- expression 14 operands: lhs = Counter(8), rhs = Zero +- expression 15 operands: lhs = Counter(9), rhs = Counter(10) +- expression 16 operands: lhs = Counter(11), rhs = Zero +Number of file 0 mappings: 16 +- Code(Counter(0)) at (prev + 7, 1) to (start + 1, 22) +- Code(Expression(0, Add)) at (prev + 6, 11) to (start + 0, 46) + = (c0 + Zero) +- Code(Counter(3)) at (prev + 1, 39) to (start + 0, 41) +- Code(Expression(1, Add)) at (prev + 1, 14) to (start + 0, 52) + = (c1 + c2) +- Code(Expression(2, Add)) at (prev + 2, 11) to (start + 0, 46) + = (c3 + Zero) +- Code(Expression(12, Sub)) at (prev + 1, 34) to (start + 0, 39) + = (c3 - c4) +- Code(Expression(11, Sub)) at (prev + 0, 44) to (start + 0, 46) + = ((c3 - c4) - c5) +- Code(Expression(6, Add)) at (prev + 1, 14) to (start + 0, 52) + = (c4 + c5) +- Code(Expression(7, Add)) at (prev + 3, 9) to (start + 0, 22) + = (((c3 - c4) - c5) + Zero) +- Code(Expression(10, Add)) at (prev + 7, 11) to (start + 0, 46) + = (((c3 - c4) - c5) + Zero) +- Code(Counter(8)) at (prev + 1, 39) to (start + 0, 41) +- Code(Expression(13, Add)) at (prev + 1, 14) to (start + 0, 52) + = (c6 + c7) +- Code(Expression(14, Add)) at (prev + 2, 11) to (start + 0, 46) + = (c8 + Zero) +- Code(Counter(11)) at (prev + 1, 39) to (start + 0, 41) +- Code(Expression(15, Add)) at (prev + 1, 14) to (start + 0, 52) + = (c9 + c10) +- Code(Expression(16, Add)) at (prev + 2, 1) to (start + 0, 2) + = (c11 + Zero) + +Function name: yield::main::{closure#0} +Raw bytes (14): 0x[01, 01, 00, 02, 01, 08, 1c, 01, 10, 05, 02, 10, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 8, 28) to (start + 1, 16) +- Code(Counter(1)) at (prev + 2, 16) to (start + 1, 6) + +Function name: yield::main::{closure#1} +Raw bytes (24): 0x[01, 01, 00, 04, 01, 16, 1c, 01, 10, 05, 02, 09, 00, 10, 09, 01, 09, 00, 10, 0d, 01, 10, 01, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 22, 28) to (start + 1, 16) +- Code(Counter(1)) at (prev + 2, 9) to (start + 0, 16) +- Code(Counter(2)) at (prev + 1, 9) to (start + 0, 16) +- Code(Counter(3)) at (prev + 1, 16) to (start + 1, 6) + diff --git a/tests/coverage-map/status-quo/yield.rs b/tests/coverage-map/status-quo/yield.rs new file mode 100644 index 00000000000..361275c9215 --- /dev/null +++ b/tests/coverage-map/status-quo/yield.rs @@ -0,0 +1,37 @@ +#![feature(generators, generator_trait)] +#![allow(unused_assignments)] + +use std::ops::{Generator, GeneratorState}; +use std::pin::Pin; + +fn main() { + let mut generator = || { + yield 1; + return "foo"; + }; + + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(1) => {} + _ => panic!("unexpected value from resume"), + } + match Pin::new(&mut generator).resume(()) { + GeneratorState::Complete("foo") => {} + _ => panic!("unexpected value from resume"), + } + + let mut generator = || { + yield 1; + yield 2; + yield 3; + return "foo"; + }; + + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(1) => {} + _ => panic!("unexpected value from resume"), + } + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(2) => {} + _ => panic!("unexpected value from resume"), + } +} diff --git a/tests/coverage-map/trivial.cov-map b/tests/coverage-map/trivial.cov-map new file mode 100644 index 00000000000..874e294a1c4 --- /dev/null +++ b/tests/coverage-map/trivial.cov-map @@ -0,0 +1,8 @@ +Function name: trivial::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 03, 01, 00, 0d] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 13) + diff --git a/tests/coverage-map/trivial.rs b/tests/coverage-map/trivial.rs new file mode 100644 index 00000000000..d0a9b44fb36 --- /dev/null +++ b/tests/coverage-map/trivial.rs @@ -0,0 +1,3 @@ +// compile-flags: --edition=2021 + +fn main() {} diff --git a/tests/debuginfo/pretty-std-collections.rs b/tests/debuginfo/pretty-std-collections.rs index 93597aa7e23..93a0dff6848 100644 --- a/tests/debuginfo/pretty-std-collections.rs +++ b/tests/debuginfo/pretty-std-collections.rs @@ -1,7 +1,6 @@ // ignore-windows failing on win32 bot // ignore-freebsd: gdb package too new // ignore-android: FIXME(#10381) -// ignore-macos: FIXME(#78665) // compile-flags:-g // The pretty printers being tested here require the patch from diff --git a/tests/debuginfo/regression-bad-location-list-67992.rs b/tests/debuginfo/regression-bad-location-list-67992.rs new file mode 100644 index 00000000000..cc7c4a0d71a --- /dev/null +++ b/tests/debuginfo/regression-bad-location-list-67992.rs @@ -0,0 +1,31 @@ +// compile-flags:-g + +// === GDB TESTS =================================================================================== + +// gdb-command:run + +// gdb-command:print a +// gdb-check:$1 = regression_bad_location_list_67992::Foo {x: [0 <repeats 1024 times>]} + +// === LLDB TESTS ================================================================================== + +// lldb-command:run +// lldb-command:print a +// lldbg-check:(regression_bad_location_list_67992::Foo) $0 = [...] +// lldbr-check:(regression_bad_location_list_67992::Foo) a = [...] + +const ARRAY_SIZE: usize = 1024; + +struct Foo { + x: [u64; ARRAY_SIZE], +} + +fn foo(a: Foo, i: usize) -> u64 { + a.x[i] // #break +} + +fn main() { + println!("Hello, world!"); + + println!("{}", foo(Foo { x: [0; ARRAY_SIZE] }, 42)); +} diff --git a/tests/mir-opt/bool_compare.opt1.InstSimplify.diff b/tests/mir-opt/bool_compare.opt1.InstSimplify.diff index 8d0011d5067..657c11516a1 100644 --- a/tests/mir-opt/bool_compare.opt1.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt1.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Ne(move _3, const true); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/bool_compare.opt2.InstSimplify.diff b/tests/mir-opt/bool_compare.opt2.InstSimplify.diff index 35f1068709b..bc8be62bd49 100644 --- a/tests/mir-opt/bool_compare.opt2.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt2.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Ne(const true, move _3); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/bool_compare.opt3.InstSimplify.diff b/tests/mir-opt/bool_compare.opt3.InstSimplify.diff index ab15c30ca11..034d5e44013 100644 --- a/tests/mir-opt/bool_compare.opt3.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt3.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Eq(move _3, const false); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/bool_compare.opt4.InstSimplify.diff b/tests/mir-opt/bool_compare.opt4.InstSimplify.diff index 40fd1cfe112..d3096da6c5a 100644 --- a/tests/mir-opt/bool_compare.opt4.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt4.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Eq(const false, move _3); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir b/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir index 80ac92d59f3..b06666c9dd7 100644 --- a/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir +++ b/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir @@ -2,7 +2,14 @@ /* generator_layout = GeneratorLayout { field_tys: { _0: GeneratorSavedTy { - ty: impl std::future::Future<Output = ()>, + ty: Alias( + Opaque, + AliasTy { + args: [ + ], + def_id: DefId(0:7 ~ async_await[ccf8]::a::{opaque#0}), + }, + ), source_info: SourceInfo { span: $DIR/async_await.rs:15:9: 15:14 (#8), scope: scope[0], @@ -10,7 +17,14 @@ ignore_for_traits: false, }, _1: GeneratorSavedTy { - ty: impl std::future::Future<Output = ()>, + ty: Alias( + Opaque, + AliasTy { + args: [ + ], + def_id: DefId(0:7 ~ async_await[ccf8]::a::{opaque#0}), + }, + ), source_info: SourceInfo { span: $DIR/async_await.rs:16:9: 16:14 (#10), scope: scope[0], diff --git a/tests/mir-opt/building/custom/debuginfo.numbered.built.after.mir b/tests/mir-opt/building/custom/debuginfo.numbered.built.after.mir new file mode 100644 index 00000000000..d8639253718 --- /dev/null +++ b/tests/mir-opt/building/custom/debuginfo.numbered.built.after.mir @@ -0,0 +1,11 @@ +// MIR for `numbered` after built + +fn numbered(_1: (u32, i32)) -> () { + debug first => (_1.0: u32); + debug second => (_1.0: u32); + let mut _0: (); + + bb0: { + return; + } +} diff --git a/tests/mir-opt/building/custom/debuginfo.pointee.built.after.mir b/tests/mir-opt/building/custom/debuginfo.pointee.built.after.mir new file mode 100644 index 00000000000..86cced6f801 --- /dev/null +++ b/tests/mir-opt/building/custom/debuginfo.pointee.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `pointee` after built + +fn pointee(_1: &mut Option<i32>) -> () { + debug foo => (((*_1) as variant#1).0: i32); + let mut _0: (); + + bb0: { + return; + } +} diff --git a/tests/mir-opt/building/custom/debuginfo.rs b/tests/mir-opt/building/custom/debuginfo.rs new file mode 100644 index 00000000000..bfdc3d3eacd --- /dev/null +++ b/tests/mir-opt/building/custom/debuginfo.rs @@ -0,0 +1,71 @@ +#![feature(custom_mir, core_intrinsics)] + +extern crate core; +use core::intrinsics::mir::*; + +// EMIT_MIR debuginfo.pointee.built.after.mir +#[custom_mir(dialect = "built")] +fn pointee(opt: &mut Option<i32>) { + mir!( + debug foo => Field::<i32>(Variant(*opt, 1), 0); + { + Return() + } + ) +} + +// EMIT_MIR debuginfo.numbered.built.after.mir +#[custom_mir(dialect = "analysis", phase = "post-cleanup")] +fn numbered(i: (u32, i32)) { + mir!( + debug first => i.0; + debug second => i.0; + { + Return() + } + ) +} + +struct S { x: f32 } + +// EMIT_MIR debuginfo.structured.built.after.mir +#[custom_mir(dialect = "analysis", phase = "post-cleanup")] +fn structured(i: S) { + mir!( + debug x => i.x; + { + Return() + } + ) +} + +// EMIT_MIR debuginfo.variant.built.after.mir +#[custom_mir(dialect = "built")] +fn variant(opt: Option<i32>) { + mir!( + debug inner => Field::<i32>(Variant(opt, 1), 0); + { + Return() + } + ) +} + +// EMIT_MIR debuginfo.variant_deref.built.after.mir +#[custom_mir(dialect = "built")] +fn variant_deref(opt: Option<&i32>) { + mir!( + debug pointer => Field::<&i32>(Variant(opt, 1), 0); + debug deref => *Field::<&i32>(Variant(opt, 1), 0); + { + Return() + } + ) +} + +fn main() { + numbered((5, 6)); + structured(S { x: 5. }); + variant(Some(5)); + variant_deref(Some(&5)); + pointee(&mut Some(5)); +} diff --git a/tests/mir-opt/building/custom/debuginfo.structured.built.after.mir b/tests/mir-opt/building/custom/debuginfo.structured.built.after.mir new file mode 100644 index 00000000000..d122b6bfe29 --- /dev/null +++ b/tests/mir-opt/building/custom/debuginfo.structured.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `structured` after built + +fn structured(_1: S) -> () { + debug x => (_1.0: f32); + let mut _0: (); + + bb0: { + return; + } +} diff --git a/tests/mir-opt/building/custom/debuginfo.variant.built.after.mir b/tests/mir-opt/building/custom/debuginfo.variant.built.after.mir new file mode 100644 index 00000000000..d173723fd89 --- /dev/null +++ b/tests/mir-opt/building/custom/debuginfo.variant.built.after.mir @@ -0,0 +1,10 @@ +// MIR for `variant` after built + +fn variant(_1: Option<i32>) -> () { + debug inner => ((_1 as variant#1).0: i32); + let mut _0: (); + + bb0: { + return; + } +} diff --git a/tests/mir-opt/building/custom/debuginfo.variant_deref.built.after.mir b/tests/mir-opt/building/custom/debuginfo.variant_deref.built.after.mir new file mode 100644 index 00000000000..37d5d1b2dfc --- /dev/null +++ b/tests/mir-opt/building/custom/debuginfo.variant_deref.built.after.mir @@ -0,0 +1,11 @@ +// MIR for `variant_deref` after built + +fn variant_deref(_1: Option<&i32>) -> () { + debug pointer => ((_1 as variant#1).0: &i32); + debug deref => (*((_1 as variant#1).0: &i32)); + let mut _0: (); + + bb0: { + return; + } +} diff --git a/tests/mir-opt/building/logical_or_in_conditional.rs b/tests/mir-opt/building/logical_or_in_conditional.rs new file mode 100644 index 00000000000..ae159f7e122 --- /dev/null +++ b/tests/mir-opt/building/logical_or_in_conditional.rs @@ -0,0 +1,39 @@ +// compile-flags: -Z validate-mir +#![feature(let_chains)] +struct Droppy(u8); +impl Drop for Droppy { + fn drop(&mut self) { + println!("drop {}", self.0); + } +} + +enum E { + A(u8), + B, +} + +impl E { + fn f() -> Self { + Self::A(1) + } +} + +fn always_true() -> bool { + true +} + +// EMIT_MIR logical_or_in_conditional.test_or.built.after.mir +fn test_or() { + if Droppy(0).0 > 0 || Droppy(1).0 > 1 {} +} + +// EMIT_MIR logical_or_in_conditional.test_complex.built.after.mir +fn test_complex() { + if let E::A(_) = E::f() && ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1) {} + + if !always_true() && let E::B = E::f() {} +} + +fn main() { + test_or(); +} diff --git a/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir b/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir new file mode 100644 index 00000000000..096aaec4a38 --- /dev/null +++ b/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir @@ -0,0 +1,186 @@ +// MIR for `test_complex` after built + +fn test_complex() -> () { + let mut _0: (); + let _1: (); + let mut _2: E; + let mut _3: isize; + let mut _4: bool; + let mut _5: bool; + let mut _6: u8; + let mut _7: Droppy; + let mut _8: bool; + let mut _9: u8; + let mut _10: Droppy; + let mut _11: bool; + let mut _12: E; + let mut _13: isize; + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = E::f() -> [return: bb1, unwind: bb31]; + } + + bb1: { + FakeRead(ForMatchedPlace(None), _2); + _3 = discriminant(_2); + switchInt(move _3) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + falseEdge -> [real: bb4, imaginary: bb3]; + } + + bb3: { + goto -> bb19; + } + + bb4: { + StorageLive(_4); + _4 = always_true() -> [return: bb5, unwind: bb31]; + } + + bb5: { + switchInt(move _4) -> [0: bb7, otherwise: bb6]; + } + + bb6: { + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = Droppy(const 0_u8); + _6 = (_7.0: u8); + _5 = Gt(move _6, const 0_u8); + switchInt(move _5) -> [0: bb9, otherwise: bb8]; + } + + bb7: { + goto -> bb13; + } + + bb8: { + drop(_7) -> [return: bb10, unwind: bb31]; + } + + bb9: { + goto -> bb11; + } + + bb10: { + StorageDead(_7); + StorageDead(_6); + goto -> bb16; + } + + bb11: { + drop(_7) -> [return: bb12, unwind: bb31]; + } + + bb12: { + StorageDead(_7); + StorageDead(_6); + goto -> bb13; + } + + bb13: { + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + _10 = Droppy(const 1_u8); + _9 = (_10.0: u8); + _8 = Gt(move _9, const 1_u8); + switchInt(move _8) -> [0: bb15, otherwise: bb14]; + } + + bb14: { + drop(_10) -> [return: bb16, unwind: bb31]; + } + + bb15: { + goto -> bb17; + } + + bb16: { + StorageDead(_10); + StorageDead(_9); + _1 = const (); + goto -> bb20; + } + + bb17: { + drop(_10) -> [return: bb18, unwind: bb31]; + } + + bb18: { + StorageDead(_10); + StorageDead(_9); + goto -> bb19; + } + + bb19: { + _1 = const (); + goto -> bb20; + } + + bb20: { + StorageDead(_8); + StorageDead(_5); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + StorageLive(_11); + _11 = always_true() -> [return: bb21, unwind: bb31]; + } + + bb21: { + switchInt(move _11) -> [0: bb23, otherwise: bb22]; + } + + bb22: { + goto -> bb29; + } + + bb23: { + goto -> bb24; + } + + bb24: { + StorageLive(_12); + _12 = E::f() -> [return: bb25, unwind: bb31]; + } + + bb25: { + FakeRead(ForMatchedPlace(None), _12); + _13 = discriminant(_12); + switchInt(move _13) -> [1: bb27, otherwise: bb26]; + } + + bb26: { + goto -> bb29; + } + + bb27: { + falseEdge -> [real: bb28, imaginary: bb26]; + } + + bb28: { + _0 = const (); + goto -> bb30; + } + + bb29: { + _0 = const (); + goto -> bb30; + } + + bb30: { + StorageDead(_11); + StorageDead(_12); + return; + } + + bb31 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/building/logical_or_in_conditional.test_or.built.after.mir b/tests/mir-opt/building/logical_or_in_conditional.test_or.built.after.mir new file mode 100644 index 00000000000..b84c17c2188 --- /dev/null +++ b/tests/mir-opt/building/logical_or_in_conditional.test_or.built.after.mir @@ -0,0 +1,87 @@ +// MIR for `test_or` after built + +fn test_or() -> () { + let mut _0: (); + let mut _1: bool; + let mut _2: u8; + let mut _3: Droppy; + let mut _4: bool; + let mut _5: u8; + let mut _6: Droppy; + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + _3 = Droppy(const 0_u8); + _2 = (_3.0: u8); + _1 = Gt(move _2, const 0_u8); + switchInt(move _1) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + drop(_3) -> [return: bb3, unwind: bb12]; + } + + bb2: { + goto -> bb4; + } + + bb3: { + StorageDead(_3); + StorageDead(_2); + goto -> bb8; + } + + bb4: { + drop(_3) -> [return: bb5, unwind: bb12]; + } + + bb5: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + _6 = Droppy(const 1_u8); + _5 = (_6.0: u8); + _4 = Gt(move _5, const 1_u8); + switchInt(move _4) -> [0: bb7, otherwise: bb6]; + } + + bb6: { + drop(_6) -> [return: bb8, unwind: bb12]; + } + + bb7: { + goto -> bb9; + } + + bb8: { + StorageDead(_6); + StorageDead(_5); + _0 = const (); + goto -> bb11; + } + + bb9: { + drop(_6) -> [return: bb10, unwind: bb12]; + } + + bb10: { + StorageDead(_6); + StorageDead(_5); + _0 = const (); + goto -> bb11; + } + + bb11: { + StorageDead(_4); + StorageDead(_1); + return; + } + + bb12 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff index 255ec94816c..ed47baa67da 100644 --- a/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff +++ b/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff @@ -33,14 +33,22 @@ let _15: bool; let _16: u32; scope 6 { - debug f => (bool, bool, u32){ .0 => _14, .1 => _15, .2 => _16, }; +- debug ((f: (bool, bool, u32)).0: bool) => _14; +- debug ((f: (bool, bool, u32)).1: bool) => _15; +- debug ((f: (bool, bool, u32)).2: u32) => _16; ++ debug ((f: (bool, bool, u32)).0: bool) => const true; ++ debug ((f: (bool, bool, u32)).1: bool) => const false; ++ debug ((f: (bool, bool, u32)).2: u32) => const 123_u32; let _10: std::option::Option<u16>; scope 7 { debug o => _10; let _17: u32; let _18: u32; scope 8 { - debug p => Point{ .0 => _17, .1 => _18, }; +- debug ((p: Point).0: u32) => _17; +- debug ((p: Point).1: u32) => _18; ++ debug ((p: Point).0: u32) => const 32_u32; ++ debug ((p: Point).1: u32) => const 32_u32; let _11: u32; scope 9 { - debug a => _11; diff --git a/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff b/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff index d1dbc7089a1..1768298d521 100644 --- a/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff +++ b/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff @@ -43,31 +43,33 @@ } bb3: { -- StorageDead(_6); - switchInt(move _5) -> [0: bb5, otherwise: bb4]; - } - - bb4: { +- StorageDead(_6); - _4 = const true; - goto -> bb6; - } - - bb5: { +- StorageDead(_6); - _4 = const false; - goto -> bb6; - } - - bb6: { -- StorageDead(_5); - switchInt(move _4) -> [0: bb8, otherwise: bb7]; - } - - bb7: { +- StorageDead(_5); - _3 = const true; - goto -> bb9; - } - - bb8: { +- StorageDead(_5); - _3 = const false; - goto -> bb9; - } diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff index 55c774d555d..e443c8991f9 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff @@ -34,11 +34,11 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = const 3_usize; + _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _8 = const false; -+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable]; ++ _8 = Lt(const 3_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff index dcab570ea77..592f43f4739 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff @@ -34,11 +34,11 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = const 3_usize; + _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; -+ _8 = const false; -+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue]; ++ _8 = Lt(const 3_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff index 55c774d555d..e443c8991f9 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff @@ -34,11 +34,11 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = const 3_usize; + _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; -+ _8 = const false; -+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable]; ++ _8 = Lt(const 3_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff index dcab570ea77..592f43f4739 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff @@ -34,11 +34,11 @@ StorageLive(_5); StorageLive(_6); _6 = const 3_usize; - _7 = const 3_usize; + _7 = Len((*_1)); - _8 = Lt(_6, _7); - assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; -+ _8 = const false; -+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue]; ++ _8 = Lt(const 3_usize, _7); ++ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue]; } bb1: { diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs index 7931c4f02ae..d6b1a93f304 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs @@ -1,8 +1,7 @@ // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// compile-flags: -Zmir-enable-passes=+NormalizeArrayLen - // EMIT_MIR_FOR_EACH_BIT_WIDTH + // EMIT_MIR bad_op_unsafe_oob_for_slices.main.ConstProp.diff #[allow(unconditional_panic)] fn main() { diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff index 6daef87dd2c..c2fd7f65f5e 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff @@ -24,5 +24,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc3 (size: 8, align: 4) { ++ 02 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff index 125407bf285..21a31f9aba3 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff @@ -24,5 +24,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc3 (size: 8, align: 4) { ++ 02 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff index ca0ce2888cd..c0efc873029 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff @@ -29,5 +29,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc3 (size: 2, align: 1) { ++ 03 00 │ .. } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff index d63fb9255a3..2aee6f164ae 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff @@ -29,5 +29,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc3 (size: 2, align: 1) { ++ 03 00 │ .. } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff index 51e17cf690a..7ba51ccdbf6 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff @@ -35,5 +35,9 @@ _0 = const (); return; } ++ } ++ ++ alloc3 (size: 2, align: 1) { ++ 00 01 │ .. } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff index 5ef201497fb..545b7f22f6e 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff @@ -35,5 +35,9 @@ _0 = const (); return; } ++ } ++ ++ alloc3 (size: 2, align: 1) { ++ 00 01 │ .. } diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff index 170c019782d..18341ba7db9 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff @@ -18,5 +18,13 @@ StorageDead(_2); return; } ++ } ++ ++ alloc8 (size: 2, align: 1) { ++ 00 00 │ .. ++ } ++ ++ alloc7 (size: 2, align: 1) { ++ 00 00 │ .. } diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff index 64227dfd78c..50763c10f0c 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff @@ -18,5 +18,13 @@ StorageDead(_2); return; } ++ } ++ ++ alloc8 (size: 2, align: 1) { ++ 00 00 │ .. ++ } ++ ++ alloc7 (size: 2, align: 1) { ++ 00 00 │ .. } diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff index e1f3f37b370..015180db896 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff @@ -23,5 +23,17 @@ StorageDead(_2); return; } ++ } ++ ++ alloc12 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc11 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc8 (size: 2, align: 1) { ++ 01 02 │ .. } diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff index aaa376a95cf..8e41705c1af 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff @@ -23,5 +23,17 @@ StorageDead(_2); return; } ++ } ++ ++ alloc12 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc11 (size: 2, align: 1) { ++ 01 02 │ .. ++ } ++ ++ alloc8 (size: 2, align: 1) { ++ 01 02 │ .. } diff --git a/tests/mir-opt/const_prop/large_array_index.rs b/tests/mir-opt/const_prop/large_array_index.rs index 6c03fe9d9c2..d226bd54671 100644 --- a/tests/mir-opt/const_prop/large_array_index.rs +++ b/tests/mir-opt/const_prop/large_array_index.rs @@ -1,6 +1,5 @@ // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// compile-flags: -Zmir-enable-passes=+NormalizeArrayLen // EMIT_MIR_FOR_EACH_BIT_WIDTH // EMIT_MIR large_array_index.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff index 0f118c7f59f..56a127ae31e 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff @@ -25,5 +25,13 @@ StorageDead(_1); return; } ++ } ++ ++ alloc7 (size: 8, align: 4) { ++ 2a 00 00 00 63 00 00 00 │ *...c... ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 2a 00 00 00 2b 00 00 00 │ *...+... } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff index a85dcf9c7ed..a1b433716c8 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff @@ -46,5 +46,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc7 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff index 15ef0fa4dff..2dc514194bc 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff @@ -46,5 +46,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc7 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/repeat.rs b/tests/mir-opt/const_prop/repeat.rs index 21dba84af37..fb8b825ee36 100644 --- a/tests/mir-opt/const_prop/repeat.rs +++ b/tests/mir-opt/const_prop/repeat.rs @@ -1,6 +1,5 @@ // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// compile-flags: -Zmir-enable-passes=+NormalizeArrayLen // EMIT_MIR_FOR_EACH_BIT_WIDTH // EMIT_MIR repeat.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff index f3b30e0dcde..6c9de476465 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff @@ -17,5 +17,9 @@ + _0 = const 4_u32; return; } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff index 79f85fcef11..0f079278c43 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff @@ -17,5 +17,9 @@ + _0 = const 4_u32; return; } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir index c8f3f641a6d..c2488f3944c 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir @@ -14,3 +14,7 @@ fn add() -> u32 { return; } } + +alloc5 (size: 8, align: 4) { + 04 00 00 00 00 __ __ __ │ .....░░░ +} diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir index 9a064697463..fa0b9c77eaf 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir @@ -14,3 +14,7 @@ fn add() -> u32 { return; } } + +alloc5 (size: 8, align: 4) { + 04 00 00 00 00 __ __ __ │ .....░░░ +} diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff index 9e705695ac0..988ef7dd225 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff @@ -29,5 +29,17 @@ StorageDead(_1); return; } ++ } ++ ++ alloc9 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ ++ } ++ ++ alloc8 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ ++ } ++ ++ alloc6 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff index 882dd97cc16..29844619720 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff @@ -29,5 +29,17 @@ StorageDead(_1); return; } ++ } ++ ++ alloc9 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ ++ } ++ ++ alloc8 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ ++ } ++ ++ alloc6 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.panic-abort.diff new file mode 100644 index 00000000000..212ddc5b154 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.panic-abort.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: [u32; 4]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; ++ _4 = const 4_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.panic-unwind.diff new file mode 100644 index 00000000000..5c53d4f4461 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.panic-unwind.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: [u32; 4]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; ++ _4 = const 4_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.panic-abort.diff new file mode 100644 index 00000000000..212ddc5b154 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.panic-abort.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: [u32; 4]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; ++ _4 = const 4_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.panic-unwind.diff new file mode 100644 index 00000000000..5c53d4f4461 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.panic-unwind.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: [u32; 4]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; ++ _4 = const 4_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/array_index.rs b/tests/mir-opt/dataflow-const-prop/array_index.rs new file mode 100644 index 00000000000..ddb3646ca9b --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/array_index.rs @@ -0,0 +1,8 @@ +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_BIT_WIDTH + +// EMIT_MIR array_index.main.DataflowConstProp.diff +fn main() { + let x: u32 = [0, 1, 2, 3][2]; +} diff --git a/tests/mir-opt/dataflow-const-prop/boolean_identities.rs b/tests/mir-opt/dataflow-const-prop/boolean_identities.rs new file mode 100644 index 00000000000..9e911e85b88 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/boolean_identities.rs @@ -0,0 +1,10 @@ +// unit-test: DataflowConstProp + +// EMIT_MIR boolean_identities.test.DataflowConstProp.diff +pub fn test(x: bool, y: bool) -> bool { + (y | true) & (x & false) +} + +fn main() { + test(true, false); +} diff --git a/tests/mir-opt/dataflow-const-prop/boolean_identities.test.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/boolean_identities.test.DataflowConstProp.diff new file mode 100644 index 00000000000..5440c38ce4b --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/boolean_identities.test.DataflowConstProp.diff @@ -0,0 +1,33 @@ +- // MIR for `test` before DataflowConstProp ++ // MIR for `test` after DataflowConstProp + + fn test(_1: bool, _2: bool) -> bool { + debug x => _1; + debug y => _2; + let mut _0: bool; + let mut _3: bool; + let mut _4: bool; + let mut _5: bool; + let mut _6: bool; + + bb0: { + StorageLive(_3); + StorageLive(_4); + _4 = _2; +- _3 = BitOr(move _4, const true); ++ _3 = const true; + StorageDead(_4); + StorageLive(_5); + StorageLive(_6); + _6 = _1; +- _5 = BitAnd(move _6, const false); ++ _5 = const false; + StorageDead(_6); +- _0 = BitAnd(move _3, move _5); ++ _0 = const false; + StorageDead(_5); + StorageDead(_3); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..07ac5b72e24 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff @@ -0,0 +1,63 @@ +- // MIR for `constant` before DataflowConstProp ++ // MIR for `constant` after DataflowConstProp + + fn constant() -> () { + let mut _0: (); + let _1: E; + let mut _3: isize; + scope 1 { + debug e => _1; + let _2: i32; + let _4: i32; + let _5: i32; + scope 2 { + debug x => _2; + } + scope 3 { + debug x => _4; + } + scope 4 { + debug x => _5; + } + } + + bb0: { + StorageLive(_1); + _1 = const _; + StorageLive(_2); +- _3 = discriminant(_1); +- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _3 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_5); + _5 = ((_1 as V2).0: i32); + _2 = _5; + StorageDead(_5); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_4); +- _4 = ((_1 as V1).0: i32); +- _2 = _4; ++ _4 = const 0_i32; ++ _2 = const 0_i32; + StorageDead(_4); + goto -> bb4; + } + + bb4: { + _0 = const (); + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..07ac5b72e24 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff @@ -0,0 +1,63 @@ +- // MIR for `constant` before DataflowConstProp ++ // MIR for `constant` after DataflowConstProp + + fn constant() -> () { + let mut _0: (); + let _1: E; + let mut _3: isize; + scope 1 { + debug e => _1; + let _2: i32; + let _4: i32; + let _5: i32; + scope 2 { + debug x => _2; + } + scope 3 { + debug x => _4; + } + scope 4 { + debug x => _5; + } + } + + bb0: { + StorageLive(_1); + _1 = const _; + StorageLive(_2); +- _3 = discriminant(_1); +- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _3 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_5); + _5 = ((_1 as V2).0: i32); + _2 = _5; + StorageDead(_5); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_4); +- _4 = ((_1 as V1).0: i32); +- _2 = _4; ++ _4 = const 0_i32; ++ _2 = const 0_i32; + StorageDead(_4); + goto -> bb4; + } + + bb4: { + _0 = const (); + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.32bit.diff index 775325c4d06..775325c4d06 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.32bit.diff diff --git a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..775325c4d06 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff @@ -0,0 +1,82 @@ +- // MIR for `multiple` before DataflowConstProp ++ // MIR for `multiple` after DataflowConstProp + + fn multiple(_1: bool, _2: u8) -> () { + debug x => _1; + debug i => _2; + let mut _0: (); + let _3: std::option::Option<u8>; + let mut _4: bool; + let mut _5: u8; + let mut _7: isize; + scope 1 { + debug e => _3; + let _6: u8; + let _8: u8; + scope 2 { + debug x => _6; + let _9: u8; + scope 4 { + debug y => _9; + } + } + scope 3 { + debug i => _8; + } + } + + bb0: { + StorageLive(_3); + StorageLive(_4); + _4 = _1; + switchInt(move _4) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + StorageLive(_5); + _5 = _2; + _3 = Option::<u8>::Some(move _5); + StorageDead(_5); + goto -> bb3; + } + + bb2: { + _3 = Option::<u8>::None; + goto -> bb3; + } + + bb3: { + StorageDead(_4); + StorageLive(_6); + _7 = discriminant(_3); + switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb5]; + } + + bb4: { + _6 = const 0_u8; + goto -> bb7; + } + + bb5: { + unreachable; + } + + bb6: { + StorageLive(_8); + _8 = ((_3 as Some).0: u8); + _6 = _8; + StorageDead(_8); + goto -> bb7; + } + + bb7: { + StorageLive(_9); + _9 = _6; + _0 = const (); + StorageDead(_9); + StorageDead(_6); + StorageDead(_3); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff index 960e69ee916..960e69ee916 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..960e69ee916 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff @@ -0,0 +1,26 @@ +- // MIR for `mutate_discriminant` before DataflowConstProp ++ // MIR for `mutate_discriminant` after DataflowConstProp + + fn mutate_discriminant() -> u8 { + let mut _0: u8; + let mut _1: std::option::Option<NonZeroUsize>; + let mut _2: isize; + + bb0: { + discriminant(_1) = 1; + (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; + _2 = discriminant(_1); + switchInt(_2) -> [0: bb1, otherwise: bb2]; + } + + bb1: { + _0 = const 1_u8; + return; + } + + bb2: { + _0 = const 2_u8; + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 79a20d7ef45..5a10e9e883d 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -1,9 +1,11 @@ // unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_BIT_WIDTH #![feature(custom_mir, core_intrinsics, rustc_attrs)] use std::intrinsics::mir::*; +#[derive(Copy, Clone)] enum E { V1(i32), V2(i32) @@ -15,6 +17,24 @@ fn simple() { let x = match e { E::V1(x) => x, E::V2(x) => x }; } +// EMIT_MIR enum.constant.DataflowConstProp.diff +fn constant() { + const C: E = E::V1(0); + let e = C; + let x = match e { E::V1(x) => x, E::V2(x) => x }; +} + +// EMIT_MIR enum.statics.DataflowConstProp.diff +fn statics() { + static C: E = E::V1(0); + let e = C; + let x = match e { E::V1(x) => x, E::V2(x) => x }; + + static RC: &E = &E::V2(4); + let e = RC; + let x = match e { E::V1(x) => x, E::V2(x) => x }; +} + #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] struct NonZeroUsize(usize); @@ -63,6 +83,8 @@ fn multiple(x: bool, i: u8) { fn main() { simple(); + constant(); + statics(); mutate_discriminant(); multiple(false, 5); } diff --git a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff index 3946e7c7d96..3946e7c7d96 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff diff --git a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..3946e7c7d96 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff @@ -0,0 +1,63 @@ +- // MIR for `simple` before DataflowConstProp ++ // MIR for `simple` after DataflowConstProp + + fn simple() -> () { + let mut _0: (); + let _1: E; + let mut _3: isize; + scope 1 { + debug e => _1; + let _2: i32; + let _4: i32; + let _5: i32; + scope 2 { + debug x => _2; + } + scope 3 { + debug x => _4; + } + scope 4 { + debug x => _5; + } + } + + bb0: { + StorageLive(_1); + _1 = E::V1(const 0_i32); + StorageLive(_2); +- _3 = discriminant(_1); +- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _3 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_5); + _5 = ((_1 as V2).0: i32); + _2 = _5; + StorageDead(_5); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_4); +- _4 = ((_1 as V1).0: i32); +- _2 = _4; ++ _4 = const 0_i32; ++ _2 = const 0_i32; + StorageDead(_4); + goto -> bb4; + } + + bb4: { + _0 = const (); + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..ae8b44c953e --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff @@ -0,0 +1,126 @@ +- // MIR for `statics` before DataflowConstProp ++ // MIR for `statics` after DataflowConstProp + + fn statics() -> () { + let mut _0: (); + let _1: E; + let mut _2: &E; + let mut _4: isize; + let mut _8: &&E; + let mut _10: isize; + scope 1 { + debug e => _1; + let _3: i32; + let _5: i32; + let _6: i32; + scope 2 { + debug x => _3; + let _7: &E; + scope 5 { + debug e => _7; + let _9: &i32; + let _11: &i32; + let _12: &i32; + scope 6 { + debug x => _9; + } + scope 7 { + debug x => _11; + } + scope 8 { + debug x => _12; + } + } + } + scope 3 { + debug x => _5; + } + scope 4 { + debug x => _6; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = const {alloc1: &E}; + _1 = (*_2); + StorageDead(_2); + StorageLive(_3); +- _4 = discriminant(_1); +- switchInt(move _4) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _4 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_6); + _6 = ((_1 as V2).0: i32); + _3 = _6; + StorageDead(_6); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_5); +- _5 = ((_1 as V1).0: i32); +- _3 = _5; ++ _5 = const 0_i32; ++ _3 = const 0_i32; + StorageDead(_5); + goto -> bb4; + } + + bb4: { + StorageLive(_7); + StorageLive(_8); + _8 = const {alloc2: &&E}; + _7 = (*_8); + StorageDead(_8); + StorageLive(_9); + _10 = discriminant((*_7)); + switchInt(move _10) -> [0: bb6, 1: bb5, otherwise: bb2]; + } + + bb5: { + StorageLive(_12); + _12 = &(((*_7) as V2).0: i32); + _9 = &(*_12); + StorageDead(_12); + goto -> bb7; + } + + bb6: { + StorageLive(_11); + _11 = &(((*_7) as V1).0: i32); + _9 = _11; + StorageDead(_11); + goto -> bb7; + } + + bb7: { + _0 = const (); + StorageDead(_9); + StorageDead(_7); + StorageDead(_3); + StorageDead(_1); + return; + } + } + + alloc2 (static: RC, size: 4, align: 4) { + ╾─alloc14─╼ │ ╾──╼ + } + + alloc14 (size: 8, align: 4) { + 01 00 00 00 04 00 00 00 │ ........ + } + + alloc1 (static: statics::C, size: 8, align: 4) { + 00 00 00 00 00 00 00 00 │ ........ + } + diff --git a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..63799b3bac3 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff @@ -0,0 +1,126 @@ +- // MIR for `statics` before DataflowConstProp ++ // MIR for `statics` after DataflowConstProp + + fn statics() -> () { + let mut _0: (); + let _1: E; + let mut _2: &E; + let mut _4: isize; + let mut _8: &&E; + let mut _10: isize; + scope 1 { + debug e => _1; + let _3: i32; + let _5: i32; + let _6: i32; + scope 2 { + debug x => _3; + let _7: &E; + scope 5 { + debug e => _7; + let _9: &i32; + let _11: &i32; + let _12: &i32; + scope 6 { + debug x => _9; + } + scope 7 { + debug x => _11; + } + scope 8 { + debug x => _12; + } + } + } + scope 3 { + debug x => _5; + } + scope 4 { + debug x => _6; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = const {alloc1: &E}; + _1 = (*_2); + StorageDead(_2); + StorageLive(_3); +- _4 = discriminant(_1); +- switchInt(move _4) -> [0: bb3, 1: bb1, otherwise: bb2]; ++ _4 = const 0_isize; ++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; + } + + bb1: { + StorageLive(_6); + _6 = ((_1 as V2).0: i32); + _3 = _6; + StorageDead(_6); + goto -> bb4; + } + + bb2: { + unreachable; + } + + bb3: { + StorageLive(_5); +- _5 = ((_1 as V1).0: i32); +- _3 = _5; ++ _5 = const 0_i32; ++ _3 = const 0_i32; + StorageDead(_5); + goto -> bb4; + } + + bb4: { + StorageLive(_7); + StorageLive(_8); + _8 = const {alloc2: &&E}; + _7 = (*_8); + StorageDead(_8); + StorageLive(_9); + _10 = discriminant((*_7)); + switchInt(move _10) -> [0: bb6, 1: bb5, otherwise: bb2]; + } + + bb5: { + StorageLive(_12); + _12 = &(((*_7) as V2).0: i32); + _9 = &(*_12); + StorageDead(_12); + goto -> bb7; + } + + bb6: { + StorageLive(_11); + _11 = &(((*_7) as V1).0: i32); + _9 = _11; + StorageDead(_11); + goto -> bb7; + } + + bb7: { + _0 = const (); + StorageDead(_9); + StorageDead(_7); + StorageDead(_3); + StorageDead(_1); + return; + } + } + + alloc2 (static: RC, size: 8, align: 8) { + ╾───────alloc14───────╼ │ ╾──────╼ + } + + alloc14 (size: 8, align: 4) { + 01 00 00 00 04 00 00 00 │ ........ + } + + alloc1 (static: statics::C, size: 8, align: 4) { + 00 00 00 00 00 00 00 00 │ ........ + } + diff --git a/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff index 08b599f9f5d..355f28b03db 100644 --- a/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff @@ -39,19 +39,20 @@ StorageLive(_4); - _4 = _1; - _3 = Eq(move _4, const 1_i32); +- switchInt(move _3) -> [0: bb2, otherwise: bb1]; + _4 = const 1_i32; + _3 = const true; - StorageDead(_4); -- switchInt(move _3) -> [0: bb2, otherwise: bb1]; + switchInt(const true) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_4); _2 = const 2_i32; goto -> bb3; } bb2: { + StorageDead(_4); _2 = const 3_i32; goto -> bb3; } @@ -70,20 +71,21 @@ StorageLive(_9); - _9 = _1; - _8 = Eq(move _9, const 1_i32); +- switchInt(move _8) -> [0: bb5, otherwise: bb4]; + _9 = const 1_i32; + _8 = const true; - StorageDead(_9); -- switchInt(move _8) -> [0: bb5, otherwise: bb4]; + switchInt(const true) -> [0: bb5, otherwise: bb4]; } bb4: { + StorageDead(_9); - _7 = _1; + _7 = const 1_i32; goto -> bb6; } bb5: { + StorageDead(_9); StorageLive(_10); _10 = _1; _7 = Add(move _10, const 1_i32); diff --git a/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.32bit.panic-abort.diff new file mode 100644 index 00000000000..6c612d46725 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.32bit.panic-abort.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u8; + let mut _2: [u8; 5000]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u8; 5000]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; ++ _4 = const 5000_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.32bit.panic-unwind.diff new file mode 100644 index 00000000000..87024da2628 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.32bit.panic-unwind.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u8; + let mut _2: [u8; 5000]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u8; 5000]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; ++ _4 = const 5000_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.64bit.panic-abort.diff new file mode 100644 index 00000000000..6c612d46725 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.64bit.panic-abort.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u8; + let mut _2: [u8; 5000]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u8; 5000]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; ++ _4 = const 5000_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.64bit.panic-unwind.diff new file mode 100644 index 00000000000..87024da2628 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/large_array_index.main.DataflowConstProp.64bit.panic-unwind.diff @@ -0,0 +1,39 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u8; + let mut _2: [u8; 5000]; + let _3: usize; + let mut _4: usize; + let mut _5: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = [const 0_u8; 5000]; + StorageLive(_3); + _3 = const 2_usize; +- _4 = Len(_2); +- _5 = Lt(_3, _4); +- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; ++ _4 = const 5000_usize; ++ _5 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 5000_usize, const 2_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = _2[_3]; ++ _1 = _2[2 of 3]; + StorageDead(_3); + StorageDead(_2); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/large_array_index.rs b/tests/mir-opt/dataflow-const-prop/large_array_index.rs new file mode 100644 index 00000000000..af13c7d1020 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/large_array_index.rs @@ -0,0 +1,9 @@ +// unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// EMIT_MIR_FOR_EACH_BIT_WIDTH + +// EMIT_MIR large_array_index.main.DataflowConstProp.diff +fn main() { + // check that we don't propagate this, because it's too large + let x: u8 = [0_u8; 5000][2]; +} diff --git a/tests/mir-opt/dataflow-const-prop/mult_by_zero.rs b/tests/mir-opt/dataflow-const-prop/mult_by_zero.rs new file mode 100644 index 00000000000..dbea1480445 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/mult_by_zero.rs @@ -0,0 +1,10 @@ +// unit-test: DataflowConstProp + +// EMIT_MIR mult_by_zero.test.DataflowConstProp.diff +fn test(x : i32) -> i32 { + x * 0 +} + +fn main() { + test(10); +} diff --git a/tests/mir-opt/dataflow-const-prop/mult_by_zero.test.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/mult_by_zero.test.DataflowConstProp.diff new file mode 100644 index 00000000000..91bc10a562f --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/mult_by_zero.test.DataflowConstProp.diff @@ -0,0 +1,18 @@ +- // MIR for `test` before DataflowConstProp ++ // MIR for `test` after DataflowConstProp + + fn test(_1: i32) -> i32 { + debug x => _1; + let mut _0: i32; + let mut _2: i32; + + bb0: { + StorageLive(_2); + _2 = _1; +- _0 = Mul(move _2, const 0_i32); ++ _0 = const 0_i32; + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-abort.diff new file mode 100644 index 00000000000..c61414b6541 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-abort.diff @@ -0,0 +1,76 @@ +- // MIR for `concrete` before DataflowConstProp ++ // MIR for `concrete` after DataflowConstProp + + fn concrete() -> () { + let mut _0: (); + let _1: usize; + let mut _2: usize; + let mut _4: usize; + let mut _6: usize; + let mut _8: usize; + scope 1 { + debug x => _1; + let _3: usize; + scope 2 { + debug y => _3; + let _5: usize; + scope 3 { + debug z0 => _5; + let _7: usize; + scope 4 { + debug z1 => _7; + } + } + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); +- _2 = OffsetOf(Alpha, [0]); +- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable]; ++ _2 = const 4_usize; ++ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); +- _4 = OffsetOf(Alpha, [1]); +- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable]; ++ _4 = const 0_usize; ++ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_4); + StorageLive(_5); + StorageLive(_6); +- _6 = OffsetOf(Alpha, [2, 0]); +- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable]; ++ _6 = const 2_usize; ++ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_6); + StorageLive(_7); + StorageLive(_8); +- _8 = OffsetOf(Alpha, [2, 1]); +- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable]; ++ _8 = const 3_usize; ++ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_8); + _0 = const (); + StorageDead(_7); + StorageDead(_5); + StorageDead(_3); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-unwind.diff new file mode 100644 index 00000000000..0c3939a3456 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-unwind.diff @@ -0,0 +1,76 @@ +- // MIR for `concrete` before DataflowConstProp ++ // MIR for `concrete` after DataflowConstProp + + fn concrete() -> () { + let mut _0: (); + let _1: usize; + let mut _2: usize; + let mut _4: usize; + let mut _6: usize; + let mut _8: usize; + scope 1 { + debug x => _1; + let _3: usize; + scope 2 { + debug y => _3; + let _5: usize; + scope 3 { + debug z0 => _5; + let _7: usize; + scope 4 { + debug z1 => _7; + } + } + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); +- _2 = OffsetOf(Alpha, [0]); +- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue]; ++ _2 = const 4_usize; ++ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); +- _4 = OffsetOf(Alpha, [1]); +- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue]; ++ _4 = const 0_usize; ++ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_4); + StorageLive(_5); + StorageLive(_6); +- _6 = OffsetOf(Alpha, [2, 0]); +- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue]; ++ _6 = const 2_usize; ++ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_6); + StorageLive(_7); + StorageLive(_8); +- _8 = OffsetOf(Alpha, [2, 1]); +- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue]; ++ _8 = const 3_usize; ++ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_8); + _0 = const (); + StorageDead(_7); + StorageDead(_5); + StorageDead(_3); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-abort.diff new file mode 100644 index 00000000000..d54d4687060 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-abort.diff @@ -0,0 +1,72 @@ +- // MIR for `generic` before DataflowConstProp ++ // MIR for `generic` after DataflowConstProp + + fn generic() -> () { + let mut _0: (); + let _1: usize; + let mut _2: usize; + let mut _4: usize; + let mut _6: usize; + let mut _8: usize; + scope 1 { + debug gx => _1; + let _3: usize; + scope 2 { + debug gy => _3; + let _5: usize; + scope 3 { + debug dx => _5; + let _7: usize; + scope 4 { + debug dy => _7; + } + } + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = OffsetOf(Gamma<T>, [0]); + _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); + _4 = OffsetOf(Gamma<T>, [1]); + _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_4); + StorageLive(_5); + StorageLive(_6); +- _6 = OffsetOf(Delta<T>, [1]); +- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable]; ++ _6 = const 0_usize; ++ _5 = must_use::<usize>(const 0_usize) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_6); + StorageLive(_7); + StorageLive(_8); +- _8 = OffsetOf(Delta<T>, [2]); +- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable]; ++ _8 = const 2_usize; ++ _7 = must_use::<usize>(const 2_usize) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_8); + _0 = const (); + StorageDead(_7); + StorageDead(_5); + StorageDead(_3); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-unwind.diff new file mode 100644 index 00000000000..6032a2274ef --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-unwind.diff @@ -0,0 +1,72 @@ +- // MIR for `generic` before DataflowConstProp ++ // MIR for `generic` after DataflowConstProp + + fn generic() -> () { + let mut _0: (); + let _1: usize; + let mut _2: usize; + let mut _4: usize; + let mut _6: usize; + let mut _8: usize; + scope 1 { + debug gx => _1; + let _3: usize; + scope 2 { + debug gy => _3; + let _5: usize; + scope 3 { + debug dx => _5; + let _7: usize; + scope 4 { + debug dy => _7; + } + } + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = OffsetOf(Gamma<T>, [0]); + _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); + _4 = OffsetOf(Gamma<T>, [1]); + _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_4); + StorageLive(_5); + StorageLive(_6); +- _6 = OffsetOf(Delta<T>, [1]); +- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue]; ++ _6 = const 0_usize; ++ _5 = must_use::<usize>(const 0_usize) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_6); + StorageLive(_7); + StorageLive(_8); +- _8 = OffsetOf(Delta<T>, [2]); +- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue]; ++ _8 = const 2_usize; ++ _7 = must_use::<usize>(const 2_usize) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_8); + _0 = const (); + StorageDead(_7); + StorageDead(_5); + StorageDead(_3); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/offset_of.rs b/tests/mir-opt/dataflow-const-prop/offset_of.rs new file mode 100644 index 00000000000..ccc90790e52 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/offset_of.rs @@ -0,0 +1,49 @@ +// unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY + +#![feature(offset_of)] + +use std::marker::PhantomData; +use std::mem::offset_of; + +struct Alpha { + x: u8, + y: u16, + z: Beta, +} + +struct Beta(u8, u8); + +struct Gamma<T> { + x: u8, + y: u16, + _t: T, +} + +#[repr(C)] +struct Delta<T> { + _phantom: PhantomData<T>, + x: u8, + y: u16, +} + +// EMIT_MIR offset_of.concrete.DataflowConstProp.diff +fn concrete() { + let x = offset_of!(Alpha, x); + let y = offset_of!(Alpha, y); + let z0 = offset_of!(Alpha, z.0); + let z1 = offset_of!(Alpha, z.1); +} + +// EMIT_MIR offset_of.generic.DataflowConstProp.diff +fn generic<T>() { + let gx = offset_of!(Gamma<T>, x); + let gy = offset_of!(Gamma<T>, y); + let dx = offset_of!(Delta<T>, x); + let dy = offset_of!(Delta<T>, y); +} + +fn main() { + concrete(); + generic::<()>(); +} diff --git a/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.32bit.panic-abort.diff new file mode 100644 index 00000000000..a18ef6c9db7 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.32bit.panic-abort.diff @@ -0,0 +1,43 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: u32; + let mut _3: [u32; 8]; + let _4: usize; + let mut _5: usize; + let mut _6: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + _3 = [const 42_u32; 8]; + StorageLive(_4); + _4 = const 2_usize; +- _5 = Len(_3); +- _6 = Lt(_4, _5); +- assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind unreachable]; ++ _5 = const 8_usize; ++ _6 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _2 = _3[_4]; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); + StorageDead(_2); + StorageDead(_4); + StorageDead(_3); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.32bit.panic-unwind.diff new file mode 100644 index 00000000000..3356ef98b14 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.32bit.panic-unwind.diff @@ -0,0 +1,43 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: u32; + let mut _3: [u32; 8]; + let _4: usize; + let mut _5: usize; + let mut _6: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + _3 = [const 42_u32; 8]; + StorageLive(_4); + _4 = const 2_usize; +- _5 = Len(_3); +- _6 = Lt(_4, _5); +- assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind continue]; ++ _5 = const 8_usize; ++ _6 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _2 = _3[_4]; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); + StorageDead(_2); + StorageDead(_4); + StorageDead(_3); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.64bit.panic-abort.diff new file mode 100644 index 00000000000..a18ef6c9db7 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.64bit.panic-abort.diff @@ -0,0 +1,43 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: u32; + let mut _3: [u32; 8]; + let _4: usize; + let mut _5: usize; + let mut _6: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + _3 = [const 42_u32; 8]; + StorageLive(_4); + _4 = const 2_usize; +- _5 = Len(_3); +- _6 = Lt(_4, _5); +- assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind unreachable]; ++ _5 = const 8_usize; ++ _6 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _2 = _3[_4]; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); + StorageDead(_2); + StorageDead(_4); + StorageDead(_3); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.64bit.panic-unwind.diff new file mode 100644 index 00000000000..3356ef98b14 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/repeat.main.DataflowConstProp.64bit.panic-unwind.diff @@ -0,0 +1,43 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: u32; + let mut _3: [u32; 8]; + let _4: usize; + let mut _5: usize; + let mut _6: bool; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + _3 = [const 42_u32; 8]; + StorageLive(_4); + _4 = const 2_usize; +- _5 = Len(_3); +- _6 = Lt(_4, _5); +- assert(move _6, "index out of bounds: the length is {} but the index is {}", move _5, _4) -> [success: bb1, unwind continue]; ++ _5 = const 8_usize; ++ _6 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 8_usize, const 2_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _2 = _3[_4]; ++ _2 = _3[2 of 3]; + _1 = Add(move _2, const 0_u32); + StorageDead(_2); + StorageDead(_4); + StorageDead(_3); + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/repeat.rs b/tests/mir-opt/dataflow-const-prop/repeat.rs new file mode 100644 index 00000000000..9fa353e44c5 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/repeat.rs @@ -0,0 +1,8 @@ +// unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// EMIT_MIR_FOR_EACH_BIT_WIDTH + +// EMIT_MIR repeat.main.DataflowConstProp.diff +fn main() { + let x: u32 = [42; 8][2] + 0; +} diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff new file mode 100644 index 00000000000..e99b413f708 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff @@ -0,0 +1,77 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: &[u32]; + let mut _3: &[u32; 3]; + let _4: &[u32; 3]; + let _5: [u32; 3]; + let _6: usize; + let mut _7: usize; + let mut _8: bool; + let mut _10: &[u32]; + let _11: usize; + let mut _12: usize; + let mut _13: bool; + let mut _14: &[u32; 3]; + scope 1 { + debug local => _1; + let _9: u32; + scope 2 { + debug constant => _9; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _14 = const _; + _4 = _14; + _3 = _4; + _2 = move _3 as &[u32] (PointerCoercion(Unsize)); + StorageDead(_3); + StorageLive(_6); + _6 = const 1_usize; +- _7 = Len((*_2)); +- _8 = Lt(_6, _7); +- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; ++ _7 = const 3_usize; ++ _8 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = (*_2)[_6]; ++ _1 = (*_2)[1 of 2]; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); + StorageLive(_9); + StorageLive(_10); + _10 = const _; + StorageLive(_11); + _11 = const 1_usize; +- _12 = Len((*_10)); +- _13 = Lt(_11, _12); +- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind unreachable]; + } + + bb2: { +- _9 = (*_10)[_11]; ++ _9 = (*_10)[1 of 2]; + StorageDead(_11); + StorageDead(_10); + _0 = const (); + StorageDead(_9); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff new file mode 100644 index 00000000000..759a793fbf3 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff @@ -0,0 +1,77 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: &[u32]; + let mut _3: &[u32; 3]; + let _4: &[u32; 3]; + let _5: [u32; 3]; + let _6: usize; + let mut _7: usize; + let mut _8: bool; + let mut _10: &[u32]; + let _11: usize; + let mut _12: usize; + let mut _13: bool; + let mut _14: &[u32; 3]; + scope 1 { + debug local => _1; + let _9: u32; + scope 2 { + debug constant => _9; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _14 = const _; + _4 = _14; + _3 = _4; + _2 = move _3 as &[u32] (PointerCoercion(Unsize)); + StorageDead(_3); + StorageLive(_6); + _6 = const 1_usize; +- _7 = Len((*_2)); +- _8 = Lt(_6, _7); +- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; ++ _7 = const 3_usize; ++ _8 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = (*_2)[_6]; ++ _1 = (*_2)[1 of 2]; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); + StorageLive(_9); + StorageLive(_10); + _10 = const _; + StorageLive(_11); + _11 = const 1_usize; +- _12 = Len((*_10)); +- _13 = Lt(_11, _12); +- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind continue]; + } + + bb2: { +- _9 = (*_10)[_11]; ++ _9 = (*_10)[1 of 2]; + StorageDead(_11); + StorageDead(_10); + _0 = const (); + StorageDead(_9); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff new file mode 100644 index 00000000000..e99b413f708 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff @@ -0,0 +1,77 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: &[u32]; + let mut _3: &[u32; 3]; + let _4: &[u32; 3]; + let _5: [u32; 3]; + let _6: usize; + let mut _7: usize; + let mut _8: bool; + let mut _10: &[u32]; + let _11: usize; + let mut _12: usize; + let mut _13: bool; + let mut _14: &[u32; 3]; + scope 1 { + debug local => _1; + let _9: u32; + scope 2 { + debug constant => _9; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _14 = const _; + _4 = _14; + _3 = _4; + _2 = move _3 as &[u32] (PointerCoercion(Unsize)); + StorageDead(_3); + StorageLive(_6); + _6 = const 1_usize; +- _7 = Len((*_2)); +- _8 = Lt(_6, _7); +- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable]; ++ _7 = const 3_usize; ++ _8 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable]; + } + + bb1: { +- _1 = (*_2)[_6]; ++ _1 = (*_2)[1 of 2]; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); + StorageLive(_9); + StorageLive(_10); + _10 = const _; + StorageLive(_11); + _11 = const 1_usize; +- _12 = Len((*_10)); +- _13 = Lt(_11, _12); +- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind unreachable]; + } + + bb2: { +- _9 = (*_10)[_11]; ++ _9 = (*_10)[1 of 2]; + StorageDead(_11); + StorageDead(_10); + _0 = const (); + StorageDead(_9); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff new file mode 100644 index 00000000000..759a793fbf3 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff @@ -0,0 +1,77 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let _1: u32; + let mut _2: &[u32]; + let mut _3: &[u32; 3]; + let _4: &[u32; 3]; + let _5: [u32; 3]; + let _6: usize; + let mut _7: usize; + let mut _8: bool; + let mut _10: &[u32]; + let _11: usize; + let mut _12: usize; + let mut _13: bool; + let mut _14: &[u32; 3]; + scope 1 { + debug local => _1; + let _9: u32; + scope 2 { + debug constant => _9; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _14 = const _; + _4 = _14; + _3 = _4; + _2 = move _3 as &[u32] (PointerCoercion(Unsize)); + StorageDead(_3); + StorageLive(_6); + _6 = const 1_usize; +- _7 = Len((*_2)); +- _8 = Lt(_6, _7); +- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue]; ++ _7 = const 3_usize; ++ _8 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue]; + } + + bb1: { +- _1 = (*_2)[_6]; ++ _1 = (*_2)[1 of 2]; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); + StorageLive(_9); + StorageLive(_10); + _10 = const _; + StorageLive(_11); + _11 = const 1_usize; +- _12 = Len((*_10)); +- _13 = Lt(_11, _12); +- assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue]; ++ _12 = const 3_usize; ++ _13 = const true; ++ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb2, unwind continue]; + } + + bb2: { +- _9 = (*_10)[_11]; ++ _9 = (*_10)[1 of 2]; + StorageDead(_11); + StorageDead(_10); + _0 = const (); + StorageDead(_9); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.rs b/tests/mir-opt/dataflow-const-prop/slice_len.rs new file mode 100644 index 00000000000..41367e48497 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/slice_len.rs @@ -0,0 +1,12 @@ +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// unit-test: DataflowConstProp +// compile-flags: -Zmir-enable-passes=+InstSimplify +// EMIT_MIR_FOR_EACH_BIT_WIDTH + +// EMIT_MIR slice_len.main.DataflowConstProp.diff +fn main() { + let local = (&[1u32, 2, 3] as &[u32])[1]; + + const SLICE: &[u32] = &[1, 2, 3]; + let constant = SLICE[1]; +} diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..2de6ba307d5 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff @@ -0,0 +1,129 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let mut _1: S; + let mut _3: i32; + let mut _5: i32; + let mut _6: i32; + let mut _11: BigStruct; + let mut _16: &&BigStruct; + let mut _17: &BigStruct; + let mut _18: &BigStruct; + let mut _19: &BigStruct; + let mut _20: &BigStruct; + let mut _21: &BigStruct; + scope 1 { + debug s => _1; + let _2: i32; + scope 2 { + debug a => _2; + let _4: i32; + scope 3 { + debug b => _4; + let _7: S; + let _8: u8; + let _9: f32; + let _10: S; + scope 4 { + debug a => _7; + debug b => _8; + debug c => _9; + debug d => _10; + let _12: S; + let _13: u8; + let _14: f32; + let _15: S; + scope 5 { + debug a => _12; + debug b => _13; + debug c => _14; + debug d => _15; + } + } + } + } + } + + bb0: { + StorageLive(_1); + _1 = S(const 1_i32); + StorageLive(_2); + StorageLive(_3); +- _3 = (_1.0: i32); +- _2 = Add(move _3, const 2_i32); ++ _3 = const 1_i32; ++ _2 = const 3_i32; + StorageDead(_3); + (_1.0: i32) = const 3_i32; + StorageLive(_4); + StorageLive(_5); +- _5 = _2; ++ _5 = const 3_i32; + StorageLive(_6); +- _6 = (_1.0: i32); +- _4 = Add(move _5, move _6); ++ _6 = const 3_i32; ++ _4 = const 6_i32; + StorageDead(_6); + StorageDead(_5); + StorageLive(_11); + _11 = const _; + StorageLive(_7); +- _7 = (_11.0: S); ++ _7 = const S(1_i32); + StorageLive(_8); +- _8 = (_11.1: u8); ++ _8 = const 5_u8; + StorageLive(_9); +- _9 = (_11.2: f32); ++ _9 = const 7f32; + StorageLive(_10); +- _10 = (_11.3: S); ++ _10 = const S(13_i32); + StorageDead(_11); + StorageLive(_16); + _16 = const {alloc1: &&BigStruct}; + _17 = deref_copy (*_16); + StorageLive(_12); + _18 = deref_copy (*_16); +- _12 = ((*_18).0: S); ++ _12 = const S(1_i32); + StorageLive(_13); + _19 = deref_copy (*_16); +- _13 = ((*_19).1: u8); ++ _13 = const 5_u8; + StorageLive(_14); + _20 = deref_copy (*_16); +- _14 = ((*_20).2: f32); ++ _14 = const 7f32; + StorageLive(_15); + _21 = deref_copy (*_16); +- _15 = ((*_21).3: S); ++ _15 = const S(13_i32); + StorageDead(_16); + _0 = const (); + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); + StorageDead(_12); + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + return; + } + } + + alloc1 (static: STAT, size: 4, align: 4) { + ╾─alloc15─╼ │ ╾──╼ + } + + alloc15 (size: 16, align: 4) { + 01 00 00 00 00 00 e0 40 0d 00 00 00 05 __ __ __ │ .......@.....░░░ + } + diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..71a28f2165b --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff @@ -0,0 +1,129 @@ +- // MIR for `main` before DataflowConstProp ++ // MIR for `main` after DataflowConstProp + + fn main() -> () { + let mut _0: (); + let mut _1: S; + let mut _3: i32; + let mut _5: i32; + let mut _6: i32; + let mut _11: BigStruct; + let mut _16: &&BigStruct; + let mut _17: &BigStruct; + let mut _18: &BigStruct; + let mut _19: &BigStruct; + let mut _20: &BigStruct; + let mut _21: &BigStruct; + scope 1 { + debug s => _1; + let _2: i32; + scope 2 { + debug a => _2; + let _4: i32; + scope 3 { + debug b => _4; + let _7: S; + let _8: u8; + let _9: f32; + let _10: S; + scope 4 { + debug a => _7; + debug b => _8; + debug c => _9; + debug d => _10; + let _12: S; + let _13: u8; + let _14: f32; + let _15: S; + scope 5 { + debug a => _12; + debug b => _13; + debug c => _14; + debug d => _15; + } + } + } + } + } + + bb0: { + StorageLive(_1); + _1 = S(const 1_i32); + StorageLive(_2); + StorageLive(_3); +- _3 = (_1.0: i32); +- _2 = Add(move _3, const 2_i32); ++ _3 = const 1_i32; ++ _2 = const 3_i32; + StorageDead(_3); + (_1.0: i32) = const 3_i32; + StorageLive(_4); + StorageLive(_5); +- _5 = _2; ++ _5 = const 3_i32; + StorageLive(_6); +- _6 = (_1.0: i32); +- _4 = Add(move _5, move _6); ++ _6 = const 3_i32; ++ _4 = const 6_i32; + StorageDead(_6); + StorageDead(_5); + StorageLive(_11); + _11 = const _; + StorageLive(_7); +- _7 = (_11.0: S); ++ _7 = const S(1_i32); + StorageLive(_8); +- _8 = (_11.1: u8); ++ _8 = const 5_u8; + StorageLive(_9); +- _9 = (_11.2: f32); ++ _9 = const 7f32; + StorageLive(_10); +- _10 = (_11.3: S); ++ _10 = const S(13_i32); + StorageDead(_11); + StorageLive(_16); + _16 = const {alloc1: &&BigStruct}; + _17 = deref_copy (*_16); + StorageLive(_12); + _18 = deref_copy (*_16); +- _12 = ((*_18).0: S); ++ _12 = const S(1_i32); + StorageLive(_13); + _19 = deref_copy (*_16); +- _13 = ((*_19).1: u8); ++ _13 = const 5_u8; + StorageLive(_14); + _20 = deref_copy (*_16); +- _14 = ((*_20).2: f32); ++ _14 = const 7f32; + StorageLive(_15); + _21 = deref_copy (*_16); +- _15 = ((*_21).3: S); ++ _15 = const S(13_i32); + StorageDead(_16); + _0 = const (); + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); + StorageDead(_12); + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + StorageDead(_7); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + return; + } + } + + alloc1 (static: STAT, size: 8, align: 8) { + ╾───────alloc15───────╼ │ ╾──────╼ + } + + alloc15 (size: 16, align: 4) { + 01 00 00 00 00 00 e0 40 0d 00 00 00 05 __ __ __ │ .......@.....░░░ + } + diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff deleted file mode 100644 index 914bc8ac47e..00000000000 --- a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff +++ /dev/null @@ -1,51 +0,0 @@ -- // MIR for `main` before DataflowConstProp -+ // MIR for `main` after DataflowConstProp - - fn main() -> () { - let mut _0: (); - let mut _1: S; - let mut _3: i32; - let mut _5: i32; - let mut _6: i32; - scope 1 { - debug s => _1; - let _2: i32; - scope 2 { - debug a => _2; - let _4: i32; - scope 3 { - debug b => _4; - } - } - } - - bb0: { - StorageLive(_1); - _1 = S(const 1_i32); - StorageLive(_2); - StorageLive(_3); -- _3 = (_1.0: i32); -- _2 = Add(move _3, const 2_i32); -+ _3 = const 1_i32; -+ _2 = const 3_i32; - StorageDead(_3); - (_1.0: i32) = const 3_i32; - StorageLive(_4); - StorageLive(_5); -- _5 = _2; -+ _5 = const 3_i32; - StorageLive(_6); -- _6 = (_1.0: i32); -- _4 = Add(move _5, move _6); -+ _6 = const 3_i32; -+ _4 = const 6_i32; - StorageDead(_6); - StorageDead(_5); - _0 = const (); - StorageDead(_4); - StorageDead(_2); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/dataflow-const-prop/struct.rs b/tests/mir-opt/dataflow-const-prop/struct.rs index 841b279e03e..e92a1676d3f 100644 --- a/tests/mir-opt/dataflow-const-prop/struct.rs +++ b/tests/mir-opt/dataflow-const-prop/struct.rs @@ -1,11 +1,22 @@ // unit-test: DataflowConstProp +// EMIT_MIR_FOR_EACH_BIT_WIDTH +#[derive(Copy, Clone)] struct S(i32); +#[derive(Copy, Clone)] +struct BigStruct(S, u8, f32, S); + // EMIT_MIR struct.main.DataflowConstProp.diff fn main() { let mut s = S(1); let a = s.0 + 2; s.0 = 3; let b = a + s.0; + + const VAL: BigStruct = BigStruct(S(1), 5, 7., S(13)); + let BigStruct(a, b, c, d) = VAL; + + static STAT: &BigStruct = &BigStruct(S(1), 5, 7., S(13)); + let BigStruct(a, b, c, d) = *STAT; } diff --git a/tests/mir-opt/dataflow-const-prop/transmute.from_char.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.from_char.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..52f096ac0e4 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.from_char.DataflowConstProp.32bit.diff @@ -0,0 +1,15 @@ +- // MIR for `from_char` before DataflowConstProp ++ // MIR for `from_char` after DataflowConstProp + + fn from_char() -> i32 { + let mut _0: i32; + scope 1 { + } + + bb0: { +- _0 = const 'R' as i32 (Transmute); ++ _0 = const 82_i32; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.from_char.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.from_char.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..52f096ac0e4 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.from_char.DataflowConstProp.64bit.diff @@ -0,0 +1,15 @@ +- // MIR for `from_char` before DataflowConstProp ++ // MIR for `from_char` after DataflowConstProp + + fn from_char() -> i32 { + let mut _0: i32; + scope 1 { + } + + bb0: { +- _0 = const 'R' as i32 (Transmute); ++ _0 = const 82_i32; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.invalid_bool.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.invalid_bool.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..3972eb209a1 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.invalid_bool.DataflowConstProp.32bit.diff @@ -0,0 +1,15 @@ +- // MIR for `invalid_bool` before DataflowConstProp ++ // MIR for `invalid_bool` after DataflowConstProp + + fn invalid_bool() -> bool { + let mut _0: bool; + scope 1 { + } + + bb0: { +- _0 = const -1_i8 as bool (Transmute); ++ _0 = const {transmute(0xff): bool}; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.invalid_bool.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.invalid_bool.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..3972eb209a1 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.invalid_bool.DataflowConstProp.64bit.diff @@ -0,0 +1,15 @@ +- // MIR for `invalid_bool` before DataflowConstProp ++ // MIR for `invalid_bool` after DataflowConstProp + + fn invalid_bool() -> bool { + let mut _0: bool; + scope 1 { + } + + bb0: { +- _0 = const -1_i8 as bool (Transmute); ++ _0 = const {transmute(0xff): bool}; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.invalid_char.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.invalid_char.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..837dabde42a --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.invalid_char.DataflowConstProp.32bit.diff @@ -0,0 +1,15 @@ +- // MIR for `invalid_char` before DataflowConstProp ++ // MIR for `invalid_char` after DataflowConstProp + + fn invalid_char() -> char { + let mut _0: char; + scope 1 { + } + + bb0: { +- _0 = const _ as char (Transmute); ++ _0 = const {transmute(0x7fffffff): char}; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.invalid_char.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.invalid_char.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..837dabde42a --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.invalid_char.DataflowConstProp.64bit.diff @@ -0,0 +1,15 @@ +- // MIR for `invalid_char` before DataflowConstProp ++ // MIR for `invalid_char` after DataflowConstProp + + fn invalid_char() -> char { + let mut _0: char; + scope 1 { + } + + bb0: { +- _0 = const _ as char (Transmute); ++ _0 = const {transmute(0x7fffffff): char}; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.less_as_i8.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.less_as_i8.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..6091e169e8e --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.less_as_i8.DataflowConstProp.32bit.diff @@ -0,0 +1,18 @@ +- // MIR for `less_as_i8` before DataflowConstProp ++ // MIR for `less_as_i8` after DataflowConstProp + + fn less_as_i8() -> i8 { + let mut _0: i8; + let mut _1: std::cmp::Ordering; + scope 1 { + } + + bb0: { + StorageLive(_1); + _1 = Less; + _0 = move _1 as i8 (Transmute); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.less_as_i8.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.less_as_i8.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..6091e169e8e --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.less_as_i8.DataflowConstProp.64bit.diff @@ -0,0 +1,18 @@ +- // MIR for `less_as_i8` before DataflowConstProp ++ // MIR for `less_as_i8` after DataflowConstProp + + fn less_as_i8() -> i8 { + let mut _0: i8; + let mut _1: std::cmp::Ordering; + scope 1 { + } + + bb0: { + StorageLive(_1); + _1 = Less; + _0 = move _1 as i8 (Transmute); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.rs b/tests/mir-opt/dataflow-const-prop/transmute.rs new file mode 100644 index 00000000000..c25e33ab0b6 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.rs @@ -0,0 +1,63 @@ +// unit-test: DataflowConstProp +// compile-flags: -O --crate-type=lib +// ignore-endian-big +// EMIT_MIR_FOR_EACH_BIT_WIDTH + +use std::mem::transmute; + +// EMIT_MIR transmute.less_as_i8.DataflowConstProp.diff +pub fn less_as_i8() -> i8 { + unsafe { transmute(std::cmp::Ordering::Less) } +} + +// EMIT_MIR transmute.from_char.DataflowConstProp.diff +pub fn from_char() -> i32 { + unsafe { transmute('R') } +} + +// EMIT_MIR transmute.valid_char.DataflowConstProp.diff +pub fn valid_char() -> char { + unsafe { transmute(0x52_u32) } +} + +// EMIT_MIR transmute.invalid_char.DataflowConstProp.diff +pub unsafe fn invalid_char() -> char { + unsafe { transmute(i32::MAX) } +} + +// EMIT_MIR transmute.invalid_bool.DataflowConstProp.diff +pub unsafe fn invalid_bool() -> bool { + unsafe { transmute(-1_i8) } +} + +// EMIT_MIR transmute.undef_union_as_integer.DataflowConstProp.diff +pub unsafe fn undef_union_as_integer() -> u32 { + union Union32 { value: u32, unit: () } + unsafe { transmute(Union32 { unit: () }) } +} + +// EMIT_MIR transmute.unreachable_direct.DataflowConstProp.diff +pub unsafe fn unreachable_direct() -> ! { + let x: Never = unsafe { transmute(()) }; + match x {} +} + +// EMIT_MIR transmute.unreachable_ref.DataflowConstProp.diff +pub unsafe fn unreachable_ref() -> ! { + let x: &Never = unsafe { transmute(1_usize) }; + match *x {} +} + +// EMIT_MIR transmute.unreachable_mut.DataflowConstProp.diff +pub unsafe fn unreachable_mut() -> ! { + let x: &mut Never = unsafe { transmute(1_usize) }; + match *x {} +} + +// EMIT_MIR transmute.unreachable_box.DataflowConstProp.diff +pub unsafe fn unreachable_box() -> ! { + let x: Box<Never> = unsafe { transmute(1_usize) }; + match *x {} +} + +enum Never {} diff --git a/tests/mir-opt/dataflow-const-prop/transmute.undef_union_as_integer.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.undef_union_as_integer.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..fc0634b1f8f --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.undef_union_as_integer.DataflowConstProp.32bit.diff @@ -0,0 +1,22 @@ +- // MIR for `undef_union_as_integer` before DataflowConstProp ++ // MIR for `undef_union_as_integer` after DataflowConstProp + + fn undef_union_as_integer() -> u32 { + let mut _0: u32; + let mut _1: undef_union_as_integer::Union32; + let mut _2: (); + scope 1 { + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = (); + _1 = Union32 { value: move _2 }; + StorageDead(_2); + _0 = move _1 as u32 (Transmute); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.undef_union_as_integer.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.undef_union_as_integer.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..fc0634b1f8f --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.undef_union_as_integer.DataflowConstProp.64bit.diff @@ -0,0 +1,22 @@ +- // MIR for `undef_union_as_integer` before DataflowConstProp ++ // MIR for `undef_union_as_integer` after DataflowConstProp + + fn undef_union_as_integer() -> u32 { + let mut _0: u32; + let mut _1: undef_union_as_integer::Union32; + let mut _2: (); + scope 1 { + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = (); + _1 = Union32 { value: move _2 }; + StorageDead(_2); + _0 = move _1 as u32 (Transmute); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..d0c298ba233 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff @@ -0,0 +1,20 @@ +- // MIR for `unreachable_box` before DataflowConstProp ++ // MIR for `unreachable_box` after DataflowConstProp + + fn unreachable_box() -> ! { + let mut _0: !; + let _1: std::boxed::Box<Never>; + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); +- _1 = const 1_usize as std::boxed::Box<Never> (Transmute); ++ _1 = const Box::<Never>(Unique::<Never> {{ pointer: NonNull::<Never> {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData::<Never> }}, std::alloc::Global); + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..d0c298ba233 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff @@ -0,0 +1,20 @@ +- // MIR for `unreachable_box` before DataflowConstProp ++ // MIR for `unreachable_box` after DataflowConstProp + + fn unreachable_box() -> ! { + let mut _0: !; + let _1: std::boxed::Box<Never>; + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); +- _1 = const 1_usize as std::boxed::Box<Never> (Transmute); ++ _1 = const Box::<Never>(Unique::<Never> {{ pointer: NonNull::<Never> {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData::<Never> }}, std::alloc::Global); + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_direct.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_direct.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..acbb5cd1bc7 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_direct.DataflowConstProp.32bit.diff @@ -0,0 +1,22 @@ +- // MIR for `unreachable_direct` before DataflowConstProp ++ // MIR for `unreachable_direct` after DataflowConstProp + + fn unreachable_direct() -> ! { + let mut _0: !; + let _1: Never; + let mut _2: (); + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = (); + _1 = move _2 as Never (Transmute); + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_direct.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_direct.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..acbb5cd1bc7 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_direct.DataflowConstProp.64bit.diff @@ -0,0 +1,22 @@ +- // MIR for `unreachable_direct` before DataflowConstProp ++ // MIR for `unreachable_direct` after DataflowConstProp + + fn unreachable_direct() -> ! { + let mut _0: !; + let _1: Never; + let mut _2: (); + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = (); + _1 = move _2 as Never (Transmute); + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_mut.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_mut.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..2ffaeea72db --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_mut.DataflowConstProp.32bit.diff @@ -0,0 +1,24 @@ +- // MIR for `unreachable_mut` before DataflowConstProp ++ // MIR for `unreachable_mut` after DataflowConstProp + + fn unreachable_mut() -> ! { + let mut _0: !; + let _1: &mut Never; + let mut _2: &mut Never; + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); + StorageLive(_2); +- _2 = const 1_usize as &mut Never (Transmute); ++ _2 = const {0x1 as &mut Never}; + _1 = &mut (*_2); + StorageDead(_2); + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_mut.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_mut.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..2ffaeea72db --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_mut.DataflowConstProp.64bit.diff @@ -0,0 +1,24 @@ +- // MIR for `unreachable_mut` before DataflowConstProp ++ // MIR for `unreachable_mut` after DataflowConstProp + + fn unreachable_mut() -> ! { + let mut _0: !; + let _1: &mut Never; + let mut _2: &mut Never; + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); + StorageLive(_2); +- _2 = const 1_usize as &mut Never (Transmute); ++ _2 = const {0x1 as &mut Never}; + _1 = &mut (*_2); + StorageDead(_2); + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_ref.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_ref.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..31fcaafc5bc --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_ref.DataflowConstProp.32bit.diff @@ -0,0 +1,20 @@ +- // MIR for `unreachable_ref` before DataflowConstProp ++ // MIR for `unreachable_ref` after DataflowConstProp + + fn unreachable_ref() -> ! { + let mut _0: !; + let _1: &Never; + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); +- _1 = const 1_usize as &Never (Transmute); ++ _1 = const {0x1 as &Never}; + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_ref.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_ref.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..31fcaafc5bc --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_ref.DataflowConstProp.64bit.diff @@ -0,0 +1,20 @@ +- // MIR for `unreachable_ref` before DataflowConstProp ++ // MIR for `unreachable_ref` after DataflowConstProp + + fn unreachable_ref() -> ! { + let mut _0: !; + let _1: &Never; + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); +- _1 = const 1_usize as &Never (Transmute); ++ _1 = const {0x1 as &Never}; + unreachable; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.valid_char.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.valid_char.DataflowConstProp.32bit.diff new file mode 100644 index 00000000000..402ef754a64 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.valid_char.DataflowConstProp.32bit.diff @@ -0,0 +1,15 @@ +- // MIR for `valid_char` before DataflowConstProp ++ // MIR for `valid_char` after DataflowConstProp + + fn valid_char() -> char { + let mut _0: char; + scope 1 { + } + + bb0: { +- _0 = const 82_u32 as char (Transmute); ++ _0 = const 'R'; + return; + } + } + diff --git a/tests/mir-opt/dataflow-const-prop/transmute.valid_char.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.valid_char.DataflowConstProp.64bit.diff new file mode 100644 index 00000000000..402ef754a64 --- /dev/null +++ b/tests/mir-opt/dataflow-const-prop/transmute.valid_char.DataflowConstProp.64bit.diff @@ -0,0 +1,15 @@ +- // MIR for `valid_char` before DataflowConstProp ++ // MIR for `valid_char` after DataflowConstProp + + fn valid_char() -> char { + let mut _0: char; + scope 1 { + } + + bb0: { +- _0 = const 82_u32 as char (Transmute); ++ _0 = const 'R'; + return; + } + } + diff --git a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff index 9d9a7a1e485..ec5f5c1f1fc 100644 --- a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff +++ b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff @@ -64,5 +64,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc15 (size: 8, align: 4) { ++ 02 00 00 00 05 20 00 00 │ ..... .. } diff --git a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff index 9d9a7a1e485..9bf8637ec76 100644 --- a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff +++ b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff @@ -64,5 +64,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc15 (size: 16, align: 8) { ++ 02 00 00 00 00 00 00 00 05 20 00 00 00 00 00 00 │ ......... ...... } diff --git a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff index 4306f38b82a..7dc6d21a907 100644 --- a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff +++ b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff @@ -64,5 +64,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc14 (size: 8, align: 4) { ++ 05 20 00 00 01 00 00 00 │ . ...... } diff --git a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff index 4306f38b82a..0b000876a86 100644 --- a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff +++ b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff @@ -64,5 +64,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc14 (size: 16, align: 8) { ++ 05 20 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ . .............. } diff --git a/tests/mir-opt/equal_true.opt.InstSimplify.diff b/tests/mir-opt/equal_true.opt.InstSimplify.diff index 7b38862e4d5..88a51000c93 100644 --- a/tests/mir-opt/equal_true.opt.InstSimplify.diff +++ b/tests/mir-opt/equal_true.opt.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Eq(move _3, const true); + _2 = move _3; - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_i32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_i32; goto -> bb3; } diff --git a/tests/mir-opt/funky_arms.rs b/tests/mir-opt/funky_arms.rs index 6b4f4c80560..79fd9457ce1 100644 --- a/tests/mir-opt/funky_arms.rs +++ b/tests/mir-opt/funky_arms.rs @@ -9,7 +9,7 @@ use core::num::flt2dec; use std::fmt::{Formatter, Result}; // EMIT_MIR funky_arms.float_to_exponential_common.ConstProp.diff -fn float_to_exponential_common<T>(fmt: &mut Formatter<'_>, num: &T, upper: bool) -> Result +pub fn float_to_exponential_common<T>(fmt: &mut Formatter<'_>, num: &T, upper: bool) -> Result where T: flt2dec::DecodableFloat, { diff --git a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir b/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir index 958078b9706..acbb7904985 100644 --- a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir +++ b/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-abort.mir @@ -2,7 +2,11 @@ /* generator_layout = GeneratorLayout { field_tys: { _0: GeneratorSavedTy { - ty: std::string::String, + ty: Adt( + std::string::String, + [ + ], + ), source_info: SourceInfo { span: $DIR/generator_drop_cleanup.rs:11:13: 11:15 (#0), scope: scope[0], diff --git a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir b/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir index 7e050e585b1..c17d4421542 100644 --- a/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir +++ b/tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.panic-unwind.mir @@ -2,7 +2,11 @@ /* generator_layout = GeneratorLayout { field_tys: { _0: GeneratorSavedTy { - ty: std::string::String, + ty: Adt( + std::string::String, + [ + ], + ), source_info: SourceInfo { span: $DIR/generator_drop_cleanup.rs:11:13: 11:15 (#0), scope: scope[0], diff --git a/tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir b/tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir index 13d703b908c..e33f5f59de1 100644 --- a/tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir +++ b/tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir @@ -2,7 +2,11 @@ /* generator_layout = GeneratorLayout { field_tys: { _0: GeneratorSavedTy { - ty: HasDrop, + ty: Adt( + HasDrop, + [ + ], + ), source_info: SourceInfo { span: $DIR/generator_tiny.rs:20:13: 20:15 (#0), scope: scope[0], diff --git a/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff index 8483b89f814..15319586062 100644 --- a/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff @@ -12,16 +12,17 @@ StorageLive(_3); _3 = _1; _2 = Eq(move _3, const -42f32); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_i32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_i32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff index 837841b009b..fedbd6cdd24 100644 --- a/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 'x'); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [120: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff index 3cbf912996c..9c38d8fe065 100644 --- a/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 42_i8); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [42: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff index 8d6f3b2249e..8c85ce78565 100644 --- a/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff @@ -14,40 +14,36 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 42_u32); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [42: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb6; } bb2: { -+ StorageDead(_3); + StorageDead(_3); StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = Ne(move _5, const 21_u32); -- StorageDead(_5); - switchInt(move _4) -> [0: bb4, otherwise: bb3]; + nop; -+ nop; + switchInt(move _5) -> [21: bb4, otherwise: bb3]; } bb3: { -+ StorageDead(_5); + StorageDead(_5); _0 = const 1_u32; goto -> bb5; } bb4: { -+ StorageDead(_5); + StorageDead(_5); _0 = const 2_u32; goto -> bb5; } diff --git a/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff index e2566b13c59..876ed61e9fa 100644 --- a/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const -42_i32); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [4294967254: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff index dc8da5b44b2..ed3eb47dd3d 100644 --- a/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 42_u32); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [42: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff index 9db0d385da7..d675695eb10 100644 --- a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff @@ -18,11 +18,11 @@ StorageLive(_3); _3 = _1; _2 = Gt(move _3, const 0_i32); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); StorageLive(_4); _4 = _1; _0 = move _4 as u32 (IntToInt); @@ -32,6 +32,7 @@ } bb2: { + StorageDead(_3); StorageLive(_6); - _6 = panic() -> unwind unreachable; + StorageLive(_7); diff --git a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff index 5663b462400..1142616115f 100644 --- a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff @@ -18,11 +18,11 @@ StorageLive(_3); _3 = _1; _2 = Gt(move _3, const 0_i32); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); StorageLive(_4); _4 = _1; _0 = move _4 as u32 (IntToInt); @@ -32,6 +32,7 @@ } bb2: { + StorageDead(_3); StorageLive(_6); - _6 = panic() -> unwind continue; + StorageLive(_7); diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff index f61632728ba..9d8f272abea 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff @@ -33,12 +33,10 @@ _3 = &_4; _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); - _8 = Len((*_2)); + _8 = const 3_usize; _9 = const 3_usize; -- _10 = Eq(move _8, const 3_usize); -- switchInt(move _10) -> [0: bb1, otherwise: bb2]; -+ nop; -+ switchInt(move _8) -> [3: bb2, otherwise: bb1]; + _10 = const true; + goto -> bb2; } bb1: { diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff index f6c337be10f..738b0b1b3e5 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff @@ -33,12 +33,10 @@ _3 = &_4; _2 = move _3 as &[T] (PointerCoercion(Unsize)); StorageDead(_3); - _8 = Len((*_2)); + _8 = const 3_usize; _9 = const 3_usize; -- _10 = Eq(move _8, const 3_usize); -- switchInt(move _10) -> [0: bb1, otherwise: bb2]; -+ nop; -+ switchInt(move _8) -> [3: bb2, otherwise: bb1]; + _10 = const true; + goto -> bb2; } bb1: { diff --git a/tests/mir-opt/issue_99325.main.built.after.mir b/tests/mir-opt/issue_99325.main.built.after.32bit.mir index aef89c7f9f7..132b713356e 100644 --- a/tests/mir-opt/issue_99325.main.built.after.mir +++ b/tests/mir-opt/issue_99325.main.built.after.32bit.mir @@ -1,8 +1,8 @@ // MIR for `main` after built | User Type Annotations -| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &'static [u8; 4], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} -| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &'static [u8; 4], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} +| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} +| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | fn main() -> () { let mut _0: (); @@ -16,51 +16,49 @@ fn main() -> () { let _8: &&[u8]; let _9: &&[u8; 4]; let mut _10: bool; - let mut _11: bool; - let mut _12: &&[u8]; - let mut _13: &&[u8; 4]; - let mut _14: !; - let _16: !; - let mut _17: core::panicking::AssertKind; - let mut _18: &&[u8]; - let _19: &&[u8]; - let mut _20: &&[u8; 4]; - let _21: &&[u8; 4]; - let mut _22: std::option::Option<std::fmt::Arguments<'_>>; - let _23: (); - let mut _24: (&&[u8], &&[u8; 4]); - let mut _25: &&[u8]; - let _26: &[u8]; - let mut _27: &&[u8; 4]; - let _28: &[u8; 4]; - let _29: &&[u8]; - let _30: &&[u8; 4]; - let mut _31: bool; - let mut _32: bool; - let mut _33: &&[u8]; - let mut _34: &&[u8; 4]; - let mut _35: !; - let _37: !; - let mut _38: core::panicking::AssertKind; - let mut _39: &&[u8]; - let _40: &&[u8]; - let mut _41: &&[u8; 4]; - let _42: &&[u8; 4]; - let mut _43: std::option::Option<std::fmt::Arguments<'_>>; + let mut _11: &&[u8]; + let mut _12: &&[u8; 4]; + let mut _13: !; + let _15: !; + let mut _16: core::panicking::AssertKind; + let mut _17: &&[u8]; + let _18: &&[u8]; + let mut _19: &&[u8; 4]; + let _20: &&[u8; 4]; + let mut _21: std::option::Option<std::fmt::Arguments<'_>>; + let _22: (); + let mut _23: (&&[u8], &&[u8; 4]); + let mut _24: &&[u8]; + let _25: &[u8]; + let mut _26: &&[u8; 4]; + let _27: &[u8; 4]; + let _28: &&[u8]; + let _29: &&[u8; 4]; + let mut _30: bool; + let mut _31: &&[u8]; + let mut _32: &&[u8; 4]; + let mut _33: !; + let _35: !; + let mut _36: core::panicking::AssertKind; + let mut _37: &&[u8]; + let _38: &&[u8]; + let mut _39: &&[u8; 4]; + let _40: &&[u8; 4]; + let mut _41: std::option::Option<std::fmt::Arguments<'_>>; scope 1 { debug left_val => _8; debug right_val => _9; - let _15: core::panicking::AssertKind; + let _14: core::panicking::AssertKind; scope 2 { - debug kind => _15; + debug kind => _14; } } scope 3 { - debug left_val => _29; - debug right_val => _30; - let _36: core::panicking::AssertKind; + debug left_val => _28; + debug right_val => _29; + let _34: core::panicking::AssertKind; scope 4 { - debug kind => _36; + debug kind => _34; } } @@ -69,7 +67,7 @@ fn main() -> () { StorageLive(_2); StorageLive(_3); StorageLive(_4); - _4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb19]; + _4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb21]; } bb1: { @@ -90,179 +88,185 @@ fn main() -> () { _9 = (_2.1: &&[u8; 4]); StorageLive(_10); StorageLive(_11); + _11 = &(*_8); StorageLive(_12); - _12 = &(*_8); - StorageLive(_13); - _13 = &(*_9); - _11 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _12, move _13) -> [return: bb2, unwind: bb19]; + _12 = &(*_9); + _10 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _11, move _12) -> [return: bb2, unwind: bb21]; } bb2: { - StorageDead(_13); - StorageDead(_12); - _10 = Not(move _11); - StorageDead(_11); switchInt(move _10) -> [0: bb4, otherwise: bb3]; } bb3: { + StorageDead(_12); + StorageDead(_11); + goto -> bb8; + } + + bb4: { + goto -> bb5; + } + + bb5: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + _14 = core::panicking::AssertKind::Eq; + FakeRead(ForLet(None), _14); StorageLive(_15); - _15 = core::panicking::AssertKind::Eq; - FakeRead(ForLet(None), _15); StorageLive(_16); + _16 = move _14; StorageLive(_17); - _17 = move _15; StorageLive(_18); + _18 = &(*_8); + _17 = &(*_18); StorageLive(_19); - _19 = &(*_8); - _18 = &(*_19); StorageLive(_20); + _20 = &(*_9); + _19 = &(*_20); StorageLive(_21); - _21 = &(*_9); - _20 = &(*_21); - StorageLive(_22); - _22 = Option::<Arguments<'_>>::None; - _16 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _17, move _18, move _20, move _22) -> bb19; - } - - bb4: { - goto -> bb7; + _21 = Option::<Arguments<'_>>::None; + _15 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _16, move _17, move _19, move _21) -> bb21; } - bb5: { - StorageDead(_22); - StorageDead(_20); - StorageDead(_18); - StorageDead(_17); + bb6: { StorageDead(_21); StorageDead(_19); + StorageDead(_17); StorageDead(_16); + StorageDead(_20); + StorageDead(_18); StorageDead(_15); + StorageDead(_14); unreachable; } - bb6: { - goto -> bb8; + bb7: { + goto -> bb9; } - bb7: { + bb8: { _1 = const (); - goto -> bb8; + goto -> bb9; } - bb8: { + bb9: { StorageDead(_10); StorageDead(_9); StorageDead(_8); - goto -> bb9; + goto -> bb10; } - bb9: { + bb10: { StorageDead(_7); StorageDead(_6); StorageDead(_4); StorageDead(_2); StorageDead(_1); + StorageLive(_22); StorageLive(_23); StorageLive(_24); StorageLive(_25); - StorageLive(_26); - _26 = function_with_bytes::<&*b"AAAA">() -> [return: bb10, unwind: bb19]; + _25 = function_with_bytes::<&*b"AAAA">() -> [return: bb11, unwind: bb21]; } - bb10: { - _25 = &_26; + bb11: { + _24 = &_25; + StorageLive(_26); StorageLive(_27); + _27 = const b"AAAA"; + _26 = &_27; + _23 = (move _24, move _26); + StorageDead(_26); + StorageDead(_24); + FakeRead(ForMatchedPlace(None), _23); StorageLive(_28); - _28 = const b"AAAA"; - _27 = &_28; - _24 = (move _25, move _27); - StorageDead(_27); - StorageDead(_25); - FakeRead(ForMatchedPlace(None), _24); + _28 = (_23.0: &&[u8]); StorageLive(_29); - _29 = (_24.0: &&[u8]); + _29 = (_23.1: &&[u8; 4]); StorageLive(_30); - _30 = (_24.1: &&[u8; 4]); StorageLive(_31); + _31 = &(*_28); StorageLive(_32); - StorageLive(_33); - _33 = &(*_29); - StorageLive(_34); - _34 = &(*_30); - _32 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _33, move _34) -> [return: bb11, unwind: bb19]; + _32 = &(*_29); + _30 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _31, move _32) -> [return: bb12, unwind: bb21]; } - bb11: { - StorageDead(_34); - StorageDead(_33); - _31 = Not(move _32); + bb12: { + switchInt(move _30) -> [0: bb14, otherwise: bb13]; + } + + bb13: { StorageDead(_32); - switchInt(move _31) -> [0: bb13, otherwise: bb12]; + StorageDead(_31); + goto -> bb18; } - bb12: { + bb14: { + goto -> bb15; + } + + bb15: { + StorageDead(_32); + StorageDead(_31); + StorageLive(_34); + _34 = core::panicking::AssertKind::Eq; + FakeRead(ForLet(None), _34); + StorageLive(_35); StorageLive(_36); - _36 = core::panicking::AssertKind::Eq; - FakeRead(ForLet(None), _36); + _36 = move _34; StorageLive(_37); StorageLive(_38); - _38 = move _36; + _38 = &(*_28); + _37 = &(*_38); StorageLive(_39); StorageLive(_40); _40 = &(*_29); _39 = &(*_40); StorageLive(_41); - StorageLive(_42); - _42 = &(*_30); - _41 = &(*_42); - StorageLive(_43); - _43 = Option::<Arguments<'_>>::None; - _37 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _38, move _39, move _41, move _43) -> bb19; - } - - bb13: { - goto -> bb16; + _41 = Option::<Arguments<'_>>::None; + _35 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _36, move _37, move _39, move _41) -> bb21; } - bb14: { - StorageDead(_43); + bb16: { StorageDead(_41); StorageDead(_39); - StorageDead(_38); - StorageDead(_42); - StorageDead(_40); StorageDead(_37); StorageDead(_36); + StorageDead(_40); + StorageDead(_38); + StorageDead(_35); + StorageDead(_34); unreachable; } - bb15: { - goto -> bb17; + bb17: { + goto -> bb19; } - bb16: { - _23 = const (); - goto -> bb17; + bb18: { + _22 = const (); + goto -> bb19; } - bb17: { - StorageDead(_31); + bb19: { StorageDead(_30); StorageDead(_29); - goto -> bb18; + StorageDead(_28); + goto -> bb20; } - bb18: { - StorageDead(_28); - StorageDead(_26); - StorageDead(_24); + bb20: { + StorageDead(_27); + StorageDead(_25); StorageDead(_23); + StorageDead(_22); _0 = const (); return; } - bb19 (cleanup): { + bb21 (cleanup): { resume; } } diff --git a/tests/mir-opt/issue_99325.main.built.after.64bit.mir b/tests/mir-opt/issue_99325.main.built.after.64bit.mir new file mode 100644 index 00000000000..132b713356e --- /dev/null +++ b/tests/mir-opt/issue_99325.main.built.after.64bit.mir @@ -0,0 +1,276 @@ +// MIR for `main` after built + +| User Type Annotations +| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} +| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} +| +fn main() -> () { + let mut _0: (); + let _1: (); + let mut _2: (&&[u8], &&[u8; 4]); + let mut _3: &&[u8]; + let _4: &[u8]; + let mut _5: &&[u8; 4]; + let _6: &[u8; 4]; + let _7: [u8; 4]; + let _8: &&[u8]; + let _9: &&[u8; 4]; + let mut _10: bool; + let mut _11: &&[u8]; + let mut _12: &&[u8; 4]; + let mut _13: !; + let _15: !; + let mut _16: core::panicking::AssertKind; + let mut _17: &&[u8]; + let _18: &&[u8]; + let mut _19: &&[u8; 4]; + let _20: &&[u8; 4]; + let mut _21: std::option::Option<std::fmt::Arguments<'_>>; + let _22: (); + let mut _23: (&&[u8], &&[u8; 4]); + let mut _24: &&[u8]; + let _25: &[u8]; + let mut _26: &&[u8; 4]; + let _27: &[u8; 4]; + let _28: &&[u8]; + let _29: &&[u8; 4]; + let mut _30: bool; + let mut _31: &&[u8]; + let mut _32: &&[u8; 4]; + let mut _33: !; + let _35: !; + let mut _36: core::panicking::AssertKind; + let mut _37: &&[u8]; + let _38: &&[u8]; + let mut _39: &&[u8; 4]; + let _40: &&[u8; 4]; + let mut _41: std::option::Option<std::fmt::Arguments<'_>>; + scope 1 { + debug left_val => _8; + debug right_val => _9; + let _14: core::panicking::AssertKind; + scope 2 { + debug kind => _14; + } + } + scope 3 { + debug left_val => _28; + debug right_val => _29; + let _34: core::panicking::AssertKind; + scope 4 { + debug kind => _34; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb21]; + } + + bb1: { + _3 = &_4; + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = [const 65_u8, const 65_u8, const 65_u8, const 65_u8]; + _6 = &_7; + _5 = &_6; + _2 = (move _3, move _5); + StorageDead(_5); + StorageDead(_3); + FakeRead(ForMatchedPlace(None), _2); + StorageLive(_8); + _8 = (_2.0: &&[u8]); + StorageLive(_9); + _9 = (_2.1: &&[u8; 4]); + StorageLive(_10); + StorageLive(_11); + _11 = &(*_8); + StorageLive(_12); + _12 = &(*_9); + _10 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _11, move _12) -> [return: bb2, unwind: bb21]; + } + + bb2: { + switchInt(move _10) -> [0: bb4, otherwise: bb3]; + } + + bb3: { + StorageDead(_12); + StorageDead(_11); + goto -> bb8; + } + + bb4: { + goto -> bb5; + } + + bb5: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + _14 = core::panicking::AssertKind::Eq; + FakeRead(ForLet(None), _14); + StorageLive(_15); + StorageLive(_16); + _16 = move _14; + StorageLive(_17); + StorageLive(_18); + _18 = &(*_8); + _17 = &(*_18); + StorageLive(_19); + StorageLive(_20); + _20 = &(*_9); + _19 = &(*_20); + StorageLive(_21); + _21 = Option::<Arguments<'_>>::None; + _15 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _16, move _17, move _19, move _21) -> bb21; + } + + bb6: { + StorageDead(_21); + StorageDead(_19); + StorageDead(_17); + StorageDead(_16); + StorageDead(_20); + StorageDead(_18); + StorageDead(_15); + StorageDead(_14); + unreachable; + } + + bb7: { + goto -> bb9; + } + + bb8: { + _1 = const (); + goto -> bb9; + } + + bb9: { + StorageDead(_10); + StorageDead(_9); + StorageDead(_8); + goto -> bb10; + } + + bb10: { + StorageDead(_7); + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + StorageLive(_22); + StorageLive(_23); + StorageLive(_24); + StorageLive(_25); + _25 = function_with_bytes::<&*b"AAAA">() -> [return: bb11, unwind: bb21]; + } + + bb11: { + _24 = &_25; + StorageLive(_26); + StorageLive(_27); + _27 = const b"AAAA"; + _26 = &_27; + _23 = (move _24, move _26); + StorageDead(_26); + StorageDead(_24); + FakeRead(ForMatchedPlace(None), _23); + StorageLive(_28); + _28 = (_23.0: &&[u8]); + StorageLive(_29); + _29 = (_23.1: &&[u8; 4]); + StorageLive(_30); + StorageLive(_31); + _31 = &(*_28); + StorageLive(_32); + _32 = &(*_29); + _30 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _31, move _32) -> [return: bb12, unwind: bb21]; + } + + bb12: { + switchInt(move _30) -> [0: bb14, otherwise: bb13]; + } + + bb13: { + StorageDead(_32); + StorageDead(_31); + goto -> bb18; + } + + bb14: { + goto -> bb15; + } + + bb15: { + StorageDead(_32); + StorageDead(_31); + StorageLive(_34); + _34 = core::panicking::AssertKind::Eq; + FakeRead(ForLet(None), _34); + StorageLive(_35); + StorageLive(_36); + _36 = move _34; + StorageLive(_37); + StorageLive(_38); + _38 = &(*_28); + _37 = &(*_38); + StorageLive(_39); + StorageLive(_40); + _40 = &(*_29); + _39 = &(*_40); + StorageLive(_41); + _41 = Option::<Arguments<'_>>::None; + _35 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _36, move _37, move _39, move _41) -> bb21; + } + + bb16: { + StorageDead(_41); + StorageDead(_39); + StorageDead(_37); + StorageDead(_36); + StorageDead(_40); + StorageDead(_38); + StorageDead(_35); + StorageDead(_34); + unreachable; + } + + bb17: { + goto -> bb19; + } + + bb18: { + _22 = const (); + goto -> bb19; + } + + bb19: { + StorageDead(_30); + StorageDead(_29); + StorageDead(_28); + goto -> bb20; + } + + bb20: { + StorageDead(_27); + StorageDead(_25); + StorageDead(_23); + StorageDead(_22); + _0 = const (); + return; + } + + bb21 (cleanup): { + resume; + } +} + +alloc4 (size: 4, align: 1) { + 41 41 41 41 │ AAAA +} diff --git a/tests/mir-opt/issue_99325.rs b/tests/mir-opt/issue_99325.rs index fe819cddb2c..3603228a502 100644 --- a/tests/mir-opt/issue_99325.rs +++ b/tests/mir-opt/issue_99325.rs @@ -1,3 +1,5 @@ +// EMIT_MIR_FOR_EACH_BIT_WIDTH + #![feature(adt_const_params)] #![allow(incomplete_features)] diff --git a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff index 6174d5259d0..5242c5f6afd 100644 --- a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff @@ -32,12 +32,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -52,6 +52,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff index 60c0772d8ec..a9e99933b12 100644 --- a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff @@ -32,12 +32,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -52,6 +52,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff index e2de1845296..7749ba6beca 100644 --- a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff @@ -35,12 +35,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -55,6 +55,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); StorageLive(_11); _11 = const 0_usize; _12 = Len((*_2)); diff --git a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff index eb81e0eea2c..fcc2c1653dc 100644 --- a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff @@ -35,12 +35,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -55,6 +55,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); StorageLive(_11); _11 = const 0_usize; _12 = Len((*_2)); diff --git a/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-abort.diff index 95a4a83d663..b2cf3cc1cca 100644 --- a/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-abort.diff @@ -12,6 +12,7 @@ StorageLive(_2); _2 = &raw const (*_1); - _0 = read_via_copy::<Never>(move _2) -> unwind unreachable; ++ _0 = (*_2); + unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-unwind.diff index 95a4a83d663..b2cf3cc1cca 100644 --- a/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.panic-unwind.diff @@ -12,6 +12,7 @@ StorageLive(_2); _2 = &raw const (*_1); - _0 = read_via_copy::<Never>(move _2) -> unwind unreachable; ++ _0 = (*_2); + unreachable; } } diff --git a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff index 70b33fb703b..7f752ca0f5a 100644 --- a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff +++ b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff @@ -28,12 +28,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_7); _7 = _1; _8 = Len((*_2)); @@ -48,6 +48,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff index 310b3b26ac5..d73b563a0e5 100644 --- a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff +++ b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff @@ -28,12 +28,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_7); _7 = _1; _8 = Len((*_2)); @@ -48,6 +48,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff index b5edbfee0fc..5a71bef9341 100644 --- a/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff @@ -40,39 +40,43 @@ - } - - bb3: { +- switchInt(move _5) -> [0: bb5, otherwise: bb4]; +- } +- +- bb4: { + StorageLive(_7); + _7 = move _6; + _5 = Ne(_7, const false); + StorageDead(_7); ++ StorageLive(_8); ++ _8 = move _5; StorageDead(_6); -- switchInt(move _5) -> [0: bb5, otherwise: bb4]; -- } -- -- bb4: { - _4 = const true; - goto -> bb6; - } - - bb5: { +- StorageDead(_6); - _4 = const false; - goto -> bb6; - } - - bb6: { -+ StorageLive(_8); -+ _8 = move _5; -+ _4 = Ne(_8, const false); -+ StorageDead(_8); - StorageDead(_5); - switchInt(move _4) -> [0: bb8, otherwise: bb7]; - } - - bb7: { ++ _4 = Ne(_8, const false); ++ StorageDead(_8); ++ StorageLive(_9); ++ _9 = move _4; + StorageDead(_5); - _3 = const true; - goto -> bb9; - } - - bb8: { +- StorageDead(_5); - _3 = const false; - goto -> bb9; - } @@ -82,8 +86,6 @@ - } - - bb10: { -+ StorageLive(_9); -+ _9 = move _4; + _3 = Ne(_9, const false); + StorageDead(_9); + StorageLive(_10); diff --git a/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir b/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir index 56b0f816573..c581d0f8471 100644 --- a/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir +++ b/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir @@ -22,7 +22,7 @@ | fn main() -> () { let mut _0: (); - let mut _1: [usize; Const { ty: usize, kind: Leaf(0x00000003) }]; + let mut _1: [usize; ValTree(Leaf(0x00000003): usize)]; let _3: usize; let mut _4: usize; let mut _5: bool; diff --git a/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir b/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir index 83b851eed74..48243e34d08 100644 --- a/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir +++ b/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir @@ -22,7 +22,7 @@ | fn main() -> () { let mut _0: (); - let mut _1: [usize; Const { ty: usize, kind: Leaf(0x0000000000000003) }]; + let mut _1: [usize; ValTree(Leaf(0x0000000000000003): usize)]; let _3: usize; let mut _4: usize; let mut _5: bool; diff --git a/tests/mir-opt/not_equal_false.opt.InstSimplify.diff b/tests/mir-opt/not_equal_false.opt.InstSimplify.diff index 71353be24a6..1342966aa15 100644 --- a/tests/mir-opt/not_equal_false.opt.InstSimplify.diff +++ b/tests/mir-opt/not_equal_false.opt.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Ne(move _3, const false); + _2 = move _3; - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir index c7fd397fcd4..838e30fa35e 100644 --- a/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir @@ -7,130 +7,111 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool { let mut _3: u32; let mut _4: u32; let mut _5: bool; - let mut _6: bool; + let mut _6: u32; let mut _7: u32; - let mut _8: u32; - let mut _9: bool; - let mut _10: bool; - let mut _11: u32; + let mut _8: bool; + let mut _9: u32; + let mut _10: u32; + let mut _11: bool; let mut _12: u32; - let mut _13: bool; + let mut _13: u32; let mut _14: bool; let mut _15: u32; let mut _16: u32; - let mut _17: bool; - let mut _18: u32; - let mut _19: u32; - let mut _20: bool; bb0: { - StorageLive(_14); - StorageLive(_10); - StorageLive(_6); StorageLive(_5); StorageLive(_3); _3 = ((*_1).0: u32); StorageLive(_4); _4 = ((*_2).0: u32); _5 = Eq(move _3, move _4); - StorageDead(_4); - StorageDead(_3); switchInt(move _5) -> [0: bb1, otherwise: bb2]; } bb1: { - _6 = const false; - goto -> bb3; + StorageDead(_4); + StorageDead(_3); + goto -> bb8; } bb2: { - StorageLive(_9); - StorageLive(_7); - _7 = ((*_1).1: u32); + StorageDead(_4); + StorageDead(_3); StorageLive(_8); - _8 = ((*_2).1: u32); - _9 = Eq(move _7, move _8); - StorageDead(_8); - StorageDead(_7); - _6 = move _9; - goto -> bb3; + StorageLive(_6); + _6 = ((*_1).1: u32); + StorageLive(_7); + _7 = ((*_2).1: u32); + _8 = Eq(move _6, move _7); + switchInt(move _8) -> [0: bb3, otherwise: bb4]; } bb3: { - StorageDead(_9); - StorageDead(_5); - switchInt(move _6) -> [0: bb4, otherwise: bb5]; + StorageDead(_7); + StorageDead(_6); + goto -> bb8; } bb4: { - _10 = const false; - goto -> bb6; + StorageDead(_7); + StorageDead(_6); + StorageLive(_11); + StorageLive(_9); + _9 = ((*_1).2: u32); + StorageLive(_10); + _10 = ((*_2).2: u32); + _11 = Eq(move _9, move _10); + switchInt(move _11) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageLive(_13); - StorageLive(_11); - _11 = ((*_1).2: u32); - StorageLive(_12); - _12 = ((*_2).2: u32); - _13 = Eq(move _11, move _12); - StorageDead(_12); - StorageDead(_11); - _10 = move _13; - goto -> bb6; + StorageDead(_10); + StorageDead(_9); + goto -> bb8; } bb6: { - StorageDead(_13); - StorageDead(_6); - switchInt(move _10) -> [0: bb7, otherwise: bb8]; + StorageDead(_10); + StorageDead(_9); + StorageLive(_14); + StorageLive(_12); + _12 = ((*_1).3: u32); + StorageLive(_13); + _13 = ((*_2).3: u32); + _14 = Eq(move _12, move _13); + switchInt(move _14) -> [0: bb7, otherwise: bb9]; } bb7: { - _14 = const false; - goto -> bb9; + StorageDead(_13); + StorageDead(_12); + goto -> bb8; } bb8: { - StorageLive(_17); + _0 = const false; + goto -> bb10; + } + + bb9: { + StorageDead(_13); + StorageDead(_12); StorageLive(_15); - _15 = ((*_1).3: u32); + _15 = ((*_1).4: u32); StorageLive(_16); - _16 = ((*_2).3: u32); - _17 = Eq(move _15, move _16); + _16 = ((*_2).4: u32); + _0 = Eq(move _15, move _16); StorageDead(_16); StorageDead(_15); - _14 = move _17; - goto -> bb9; - } - - bb9: { - StorageDead(_17); - StorageDead(_10); - switchInt(move _14) -> [0: bb10, otherwise: bb11]; + goto -> bb10; } bb10: { - _0 = const false; - goto -> bb12; - } - - bb11: { - StorageLive(_20); - StorageLive(_18); - _18 = ((*_1).4: u32); - StorageLive(_19); - _19 = ((*_2).4: u32); - _20 = Eq(move _18, move _19); - StorageDead(_19); - StorageDead(_18); - _0 = move _20; - goto -> bb12; - } - - bb12: { - StorageDead(_20); StorageDead(_14); + StorageDead(_11); + StorageDead(_8); + StorageDead(_5); return; } } diff --git a/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir index 1e619bc9704..8452fa12f31 100644 --- a/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir @@ -27,12 +27,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_4); _4 = ((*_2).0: u32); _5 = Ne(move _3, move _4); - StorageDead(_4); - StorageDead(_3); switchInt(move _5) -> [0: bb1, otherwise: bb10]; } bb1: { + StorageDead(_4); + StorageDead(_3); StorageDead(_5); StorageLive(_8); StorageLive(_6); @@ -40,12 +40,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_7); _7 = ((*_2).1: u32); _8 = Ne(move _6, move _7); - StorageDead(_7); - StorageDead(_6); switchInt(move _8) -> [0: bb2, otherwise: bb9]; } bb2: { + StorageDead(_7); + StorageDead(_6); StorageDead(_8); StorageLive(_11); StorageLive(_9); @@ -53,12 +53,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_10); _10 = ((*_2).2: u32); _11 = Ne(move _9, move _10); - StorageDead(_10); - StorageDead(_9); switchInt(move _11) -> [0: bb3, otherwise: bb8]; } bb3: { + StorageDead(_10); + StorageDead(_9); StorageDead(_11); StorageLive(_14); StorageLive(_12); @@ -66,12 +66,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_13); _13 = ((*_2).3: u32); _14 = Ne(move _12, move _13); - StorageDead(_13); - StorageDead(_12); switchInt(move _14) -> [0: bb4, otherwise: bb7]; } bb4: { + StorageDead(_13); + StorageDead(_12); StorageDead(_14); StorageLive(_17); StorageLive(_15); @@ -79,42 +79,52 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_16); _16 = ((*_2).4: u32); _17 = Ne(move _15, move _16); - StorageDead(_16); - StorageDead(_15); switchInt(move _17) -> [0: bb5, otherwise: bb6]; } bb5: { + StorageDead(_16); + StorageDead(_15); StorageDead(_17); _0 = const true; goto -> bb11; } bb6: { + StorageDead(_16); + StorageDead(_15); _0 = const false; StorageDead(_17); goto -> bb11; } bb7: { + StorageDead(_13); + StorageDead(_12); _0 = const false; StorageDead(_14); goto -> bb11; } bb8: { + StorageDead(_10); + StorageDead(_9); _0 = const false; StorageDead(_11); goto -> bb11; } bb9: { + StorageDead(_7); + StorageDead(_6); _0 = const false; StorageDead(_8); goto -> bb11; } bb10: { + StorageDead(_4); + StorageDead(_3); _0 = const false; StorageDead(_5); goto -> bb11; diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir index b2ea96f033e..75f81c5aaca 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir @@ -40,16 +40,22 @@ fn step_forward(_1: u32, _2: usize) -> u32 { _5 = Eq(_4, const 1_isize); _6 = Not(move _5); StorageDead(_5); - StorageDead(_3); - StorageDead(_8); - switchInt(move _6) -> [0: bb3, otherwise: bb2]; + switchInt(move _6) -> [0: bb2, otherwise: bb3]; } bb2: { - assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb3, unwind continue]; + StorageDead(_3); + StorageDead(_8); + goto -> bb4; } bb3: { + StorageDead(_3); + StorageDead(_8); + assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb4, unwind continue]; + } + + bb4: { StorageDead(_6); StorageLive(_7); _7 = _2 as u32 (IntToInt); diff --git a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir index 2e51faeba5a..0d79f2de10d 100644 --- a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir @@ -63,17 +63,19 @@ fn int_range(_1: usize, _2: usize) -> () { _7 = Lt(move _5, move _6); StorageDead(_6); StorageDead(_5); - StorageDead(_16); - StorageDead(_15); switchInt(move _7) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_16); + StorageDead(_15); _8 = Option::<usize>::None; goto -> bb5; } bb3: { + StorageDead(_16); + StorageDead(_15); _9 = (_4.0: usize); StorageLive(_10); _10 = <usize as Step>::forward_unchecked(_9, const 1_usize) -> [return: bb4, unwind continue]; diff --git a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir index 26919dd98dd..630babaa821 100644 --- a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir @@ -10,23 +10,53 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 { scope 2 { scope 3 { debug result => _0; - scope 6 (inlined std::ptr::write::<u32>) { + scope 16 (inlined std::ptr::write::<u32>) { debug dst => _1; debug src => _2; - scope 7 { + scope 17 { } } } scope 4 (inlined std::ptr::read::<u32>) { debug src => _1; scope 5 { + scope 6 (inlined std::ptr::read::runtime::<u32>) { + debug src => _1; + scope 7 (inlined intrinsics::is_aligned_and_not_null::<u32>) { + debug ptr => _1; + scope 8 (inlined ptr::const_ptr::<impl *const u32>::is_null) { + debug self => _1; + let mut _3: *const u8; + scope 9 { + scope 10 (inlined ptr::const_ptr::<impl *const T>::is_null::runtime_impl) { + debug ptr => _3; + scope 11 (inlined ptr::const_ptr::<impl *const u8>::addr) { + debug self => _3; + scope 12 { + scope 13 (inlined ptr::const_ptr::<impl *const u8>::cast::<()>) { + debug self => _3; + } + } + } + } + } + } + scope 14 (inlined ptr::const_ptr::<impl *const u32>::is_aligned) { + debug self => _1; + scope 15 (inlined align_of::<u32>) { + } + } + } + } } } } } bb0: { + StorageLive(_3); _0 = (*_1); + StorageDead(_3); (*_1) = _2; return; } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff index 2c607b4c055..681e9666e0f 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-abort.diff @@ -55,5 +55,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff index b6929f3f93c..db16b8d82d2 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.32bit.panic-unwind.diff @@ -55,5 +55,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff index 2c607b4c055..681e9666e0f 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-abort.diff @@ -55,5 +55,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff index b6929f3f93c..db16b8d82d2 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.ConstProp.64bit.panic-unwind.diff @@ -55,5 +55,9 @@ StorageDead(_1); return; } ++ } ++ ++ alloc5 (size: 8, align: 4) { ++ 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir index d76b46bdd94..9664ccfb094 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -66,17 +66,19 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_19); - StorageDead(_18); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_19); + StorageDead(_18); _9 = Option::<u32>::None; goto -> bb5; } bb3: { + StorageDead(_19); + StorageDead(_18); _10 = (_5.0: u32); StorageLive(_11); _11 = <u32 as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 35f7356d47a..dc8b46b6c08 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -66,17 +66,19 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_19); - StorageDead(_18); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_19); + StorageDead(_18); _9 = Option::<u32>::None; goto -> bb5; } bb3: { + StorageDead(_19); + StorageDead(_18); _10 = (_5.0: u32); StorageLive(_11); _11 = <u32 as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind: bb11]; diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir index 7360aa3e698..fff713b5a79 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir @@ -38,17 +38,19 @@ fn range_iter_next(_1: &mut std::ops::Range<u32>) -> Option<u32> { _4 = Lt(move _2, move _3); StorageDead(_3); StorageDead(_2); - StorageDead(_8); - StorageDead(_7); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_8); + StorageDead(_7); _0 = Option::<u32>::None; goto -> bb4; } bb2: { + StorageDead(_8); + StorageDead(_7); _5 = ((*_1).0: u32); StorageLive(_6); _6 = <u32 as Step>::forward_unchecked(_5, const 1_usize) -> [return: bb3, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir index 61957082d8b..cc12c0122b7 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir @@ -38,17 +38,19 @@ fn range_iter_next(_1: &mut std::ops::Range<u32>) -> Option<u32> { _4 = Lt(move _2, move _3); StorageDead(_3); StorageDead(_2); - StorageDead(_8); - StorageDead(_7); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_8); + StorageDead(_7); _0 = Option::<u32>::None; goto -> bb4; } bb2: { + StorageDead(_8); + StorageDead(_7); _5 = ((*_1).0: u32); StorageLive(_6); _6 = <u32 as Step>::forward_unchecked(_5, const 1_usize) -> [return: bb3, unwind continue]; diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir index 1488779f93b..ddfd5b0fefc 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir @@ -12,30 +12,27 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 let _10: &usize; let _11: &usize; let mut _16: bool; - let mut _17: bool; - let _18: &usize; - let mut _23: bool; - let _24: &usize; - let mut _29: bool; - let mut _30: bool; - let _31: &usize; - let mut _36: bool; + let _17: &usize; + let mut _22: bool; + let _23: &usize; + let mut _28: bool; + let _29: &usize; + let mut _34: &&usize; + let mut _35: &&usize; + let mut _36: &&usize; let mut _37: &&usize; let mut _38: &&usize; let mut _39: &&usize; let mut _40: &&usize; let mut _41: &&usize; - let mut _42: &&usize; - let mut _43: &&usize; - let mut _44: &&usize; scope 1 { debug a => _4; debug b => _6; debug c => _8; debug d => _10; scope 2 (inlined cmp::impls::<impl PartialOrd for &usize>::le) { - debug self => _37; - debug other => _38; + debug self => _34; + debug other => _35; let mut _12: &usize; let mut _13: &usize; scope 3 (inlined cmp::impls::<impl PartialOrd for usize>::le) { @@ -46,39 +43,39 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 } } scope 4 (inlined cmp::impls::<impl PartialOrd for &usize>::le) { - debug self => _41; - debug other => _42; - let mut _25: &usize; - let mut _26: &usize; + debug self => _36; + debug other => _37; + let mut _18: &usize; + let mut _19: &usize; scope 5 (inlined cmp::impls::<impl PartialOrd for usize>::le) { - debug self => _25; - debug other => _26; - let mut _27: usize; - let mut _28: usize; + debug self => _18; + debug other => _19; + let mut _20: usize; + let mut _21: usize; } } scope 6 (inlined cmp::impls::<impl PartialOrd for &usize>::le) { - debug self => _39; - debug other => _40; - let mut _19: &usize; - let mut _20: &usize; + debug self => _38; + debug other => _39; + let mut _24: &usize; + let mut _25: &usize; scope 7 (inlined cmp::impls::<impl PartialOrd for usize>::le) { - debug self => _19; - debug other => _20; - let mut _21: usize; - let mut _22: usize; + debug self => _24; + debug other => _25; + let mut _26: usize; + let mut _27: usize; } } scope 8 (inlined cmp::impls::<impl PartialOrd for &usize>::le) { - debug self => _43; - debug other => _44; - let mut _32: &usize; - let mut _33: &usize; + debug self => _40; + debug other => _41; + let mut _30: &usize; + let mut _31: &usize; scope 9 (inlined cmp::impls::<impl PartialOrd for usize>::le) { - debug self => _32; - debug other => _33; - let mut _34: usize; - let mut _35: usize; + debug self => _30; + debug other => _31; + let mut _32: usize; + let mut _33: usize; } } } @@ -96,10 +93,9 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 StorageLive(_10); _9 = deref_copy (*_2); _10 = &((*_9).3: usize); - StorageLive(_17); StorageLive(_16); - StorageLive(_37); - StorageLive(_38); + StorageLive(_34); + StorageLive(_35); StorageLive(_11); _11 = _8; _12 = deref_copy _4; @@ -111,109 +107,109 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 _16 = Le(move _14, move _15); StorageDead(_15); StorageDead(_14); - StorageDead(_11); - StorageDead(_38); - StorageDead(_37); switchInt(move _16) -> [0: bb1, otherwise: bb2]; } bb1: { - _17 = const false; - goto -> bb3; + StorageDead(_11); + StorageDead(_35); + StorageDead(_34); + goto -> bb4; } bb2: { - StorageLive(_23); - StorageLive(_39); - StorageLive(_40); - StorageLive(_18); - _18 = _6; - _19 = deref_copy _10; - _20 = deref_copy _18; + StorageDead(_11); + StorageDead(_35); + StorageDead(_34); + StorageLive(_22); + StorageLive(_36); + StorageLive(_37); + StorageLive(_17); + _17 = _6; + _18 = deref_copy _10; + _19 = deref_copy _17; + StorageLive(_20); + _20 = (*_18); StorageLive(_21); _21 = (*_19); - StorageLive(_22); - _22 = (*_20); - _23 = Le(move _21, move _22); - StorageDead(_22); + _22 = Le(move _20, move _21); StorageDead(_21); - StorageDead(_18); - StorageDead(_40); - StorageDead(_39); - _17 = move _23; - goto -> bb3; + StorageDead(_20); + switchInt(move _22) -> [0: bb3, otherwise: bb8]; } bb3: { - StorageDead(_23); - StorageDead(_16); - switchInt(move _17) -> [0: bb4, otherwise: bb8]; + StorageDead(_17); + StorageDead(_37); + StorageDead(_36); + goto -> bb4; } bb4: { - StorageLive(_30); - StorageLive(_29); - StorageLive(_41); - StorageLive(_42); - StorageLive(_24); - _24 = _4; - _25 = deref_copy _8; - _26 = deref_copy _24; + StorageLive(_28); + StorageLive(_38); + StorageLive(_39); + StorageLive(_23); + _23 = _4; + _24 = deref_copy _8; + _25 = deref_copy _23; + StorageLive(_26); + _26 = (*_24); StorageLive(_27); _27 = (*_25); - StorageLive(_28); - _28 = (*_26); - _29 = Le(move _27, move _28); - StorageDead(_28); + _28 = Le(move _26, move _27); StorageDead(_27); - StorageDead(_24); - StorageDead(_42); - StorageDead(_41); - switchInt(move _29) -> [0: bb5, otherwise: bb6]; + StorageDead(_26); + switchInt(move _28) -> [0: bb5, otherwise: bb6]; } bb5: { - _30 = const false; + StorageDead(_23); + StorageDead(_39); + StorageDead(_38); + _0 = const false; goto -> bb7; } bb6: { - StorageLive(_36); - StorageLive(_43); - StorageLive(_44); - StorageLive(_31); - _31 = _10; - _32 = deref_copy _6; - _33 = deref_copy _31; - StorageLive(_34); - _34 = (*_32); - StorageLive(_35); - _35 = (*_33); - _36 = Le(move _34, move _35); - StorageDead(_35); - StorageDead(_34); - StorageDead(_31); - StorageDead(_44); - StorageDead(_43); - _30 = move _36; + StorageDead(_23); + StorageDead(_39); + StorageDead(_38); + StorageLive(_40); + StorageLive(_41); + StorageLive(_29); + _29 = _10; + _30 = deref_copy _6; + _31 = deref_copy _29; + StorageLive(_32); + _32 = (*_30); + StorageLive(_33); + _33 = (*_31); + _0 = Le(move _32, move _33); + StorageDead(_33); + StorageDead(_32); + StorageDead(_29); + StorageDead(_41); + StorageDead(_40); goto -> bb7; } bb7: { - StorageDead(_36); - StorageDead(_29); - _0 = move _30; + StorageDead(_28); goto -> bb9; } bb8: { + StorageDead(_17); + StorageDead(_37); + StorageDead(_36); _0 = const true; goto -> bb9; } bb9: { - StorageDead(_30); - StorageDead(_17); + StorageDead(_22); + StorageDead(_16); StorageDead(_10); StorageDead(_8); StorageDead(_6); diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir index bab9f0b58aa..7e70c6290a8 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir @@ -13,9 +13,6 @@ fn variant_b::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:11:25: 11:41], let mut _11: bool; let mut _12: bool; let mut _13: bool; - let mut _14: bool; - let mut _15: bool; - let mut _16: bool; scope 1 { debug a => _4; debug b => _6; @@ -32,64 +29,46 @@ fn variant_b::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:11:25: 11:41], _8 = ((*_7).2: usize); _9 = deref_copy (*_2); _10 = ((*_9).3: usize); - StorageLive(_12); StorageLive(_11); _11 = Le(_4, _8); - switchInt(move _11) -> [0: bb1, otherwise: bb2]; + switchInt(move _11) -> [0: bb2, otherwise: bb1]; } bb1: { - _12 = const false; - goto -> bb3; + StorageLive(_12); + _12 = Le(_10, _6); + switchInt(move _12) -> [0: bb2, otherwise: bb6]; } bb2: { StorageLive(_13); - _13 = Le(_10, _6); - _12 = move _13; - goto -> bb3; + _13 = Le(_8, _4); + switchInt(move _13) -> [0: bb3, otherwise: bb4]; } bb3: { - StorageDead(_13); - StorageDead(_11); - switchInt(move _12) -> [0: bb4, otherwise: bb8]; + _0 = const false; + goto -> bb5; } bb4: { - StorageLive(_15); - StorageLive(_14); - _14 = Le(_8, _4); - switchInt(move _14) -> [0: bb5, otherwise: bb6]; + _0 = Le(_6, _10); + goto -> bb5; } bb5: { - _15 = const false; + StorageDead(_13); goto -> bb7; } bb6: { - StorageLive(_16); - _16 = Le(_6, _10); - _15 = move _16; + _0 = const true; goto -> bb7; } bb7: { - StorageDead(_16); - StorageDead(_14); - _0 = move _15; - goto -> bb9; - } - - bb8: { - _0 = const true; - goto -> bb9; - } - - bb9: { - StorageDead(_15); StorageDead(_12); + StorageDead(_11); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir index 07a58309ee4..8590c9d3b83 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir @@ -58,16 +58,17 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_3); _3 = Len((*_1)); _4 = Lt(_2, move _3); - StorageDead(_3); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_3); _0 = const Option::<&mut u32>::None; goto -> bb3; } bb2: { + StorageDead(_3); StorageLive(_8); StorageLive(_5); _5 = &raw mut (*_1); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir index 07a58309ee4..8590c9d3b83 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir @@ -58,16 +58,17 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_3); _3 = Len((*_1)); _4 = Lt(_2, move _3); - StorageDead(_3); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_3); _0 = const Option::<&mut u32>::None; goto -> bb3; } bb2: { + StorageDead(_3); StorageLive(_8); StorageLive(_5); _5 = &raw mut (*_1); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index 2f5d356a26d..2fd669aeeb6 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -8,46 +8,63 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> let mut _4: usize; scope 1 (inlined core::slice::<impl [u32]>::get_unchecked_mut::<std::ops::Range<usize>>) { debug self => _1; - debug index => std::ops::Range<usize>{ .0 => _3, .1 => _4, }; + debug ((index: std::ops::Range<usize>).0: usize) => _3; + debug ((index: std::ops::Range<usize>).1: usize) => _4; let mut _5: *mut [u32]; let mut _13: *mut [u32]; scope 2 { scope 3 (inlined <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked_mut) { - debug self => std::ops::Range<usize>{ .0 => _3, .1 => _4, }; + debug ((self: std::ops::Range<usize>).0: usize) => _3; + debug ((self: std::ops::Range<usize>).1: usize) => _4; debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; - let _14: usize; let _15: usize; + let _16: usize; scope 4 { - debug this => std::ops::Range<usize>{ .0 => _14, .1 => _15, }; + debug ((this: std::ops::Range<usize>).0: usize) => _15; + debug ((this: std::ops::Range<usize>).1: usize) => _16; scope 5 { let _6: usize; scope 6 { debug new_len => _6; - scope 7 (inlined ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { + scope 11 (inlined ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { debug self => _5; } - scope 8 (inlined ptr::mut_ptr::<impl *mut u32>::add) { + scope 12 (inlined ptr::mut_ptr::<impl *mut u32>::add) { debug self => _7; debug count => _3; - scope 9 { + scope 13 { } } - scope 10 (inlined slice_from_raw_parts_mut::<u32>) { + scope 14 (inlined slice_from_raw_parts_mut::<u32>) { debug data => _8; debug len => _6; let mut _9: *mut (); - scope 11 (inlined ptr::mut_ptr::<impl *mut u32>::cast::<()>) { + scope 15 (inlined ptr::mut_ptr::<impl *mut u32>::cast::<()>) { debug self => _8; } - scope 12 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { debug data_address => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 13 { + scope 17 { + } + } + } + } + scope 7 (inlined <std::ops::Range<usize> as SliceIndex<[T]>>::get_unchecked_mut::runtime::<u32>) { + debug ((this: std::ops::Range<usize>).0: usize) => _15; + debug ((this: std::ops::Range<usize>).1: usize) => _16; + debug slice => _5; + scope 8 (inlined ptr::mut_ptr::<impl *mut [u32]>::len) { + debug self => _5; + let mut _14: *const [u32]; + scope 9 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _14; + scope 10 { } } } @@ -63,9 +80,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> _4 = move (_2.1: usize); StorageLive(_5); _5 = &raw mut (*_1); + StorageLive(_6); StorageLive(_14); StorageLive(_15); - StorageLive(_6); + StorageLive(_16); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); @@ -86,9 +104,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_6); - StorageDead(_14); + StorageDead(_16); StorageDead(_15); + StorageDead(_14); + StorageDead(_6); StorageDead(_5); _0 = &mut (*_13); return; diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 2f5d356a26d..2fd669aeeb6 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -8,46 +8,63 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> let mut _4: usize; scope 1 (inlined core::slice::<impl [u32]>::get_unchecked_mut::<std::ops::Range<usize>>) { debug self => _1; - debug index => std::ops::Range<usize>{ .0 => _3, .1 => _4, }; + debug ((index: std::ops::Range<usize>).0: usize) => _3; + debug ((index: std::ops::Range<usize>).1: usize) => _4; let mut _5: *mut [u32]; let mut _13: *mut [u32]; scope 2 { scope 3 (inlined <std::ops::Range<usize> as SliceIndex<[u32]>>::get_unchecked_mut) { - debug self => std::ops::Range<usize>{ .0 => _3, .1 => _4, }; + debug ((self: std::ops::Range<usize>).0: usize) => _3; + debug ((self: std::ops::Range<usize>).1: usize) => _4; debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; - let _14: usize; let _15: usize; + let _16: usize; scope 4 { - debug this => std::ops::Range<usize>{ .0 => _14, .1 => _15, }; + debug ((this: std::ops::Range<usize>).0: usize) => _15; + debug ((this: std::ops::Range<usize>).1: usize) => _16; scope 5 { let _6: usize; scope 6 { debug new_len => _6; - scope 7 (inlined ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { + scope 11 (inlined ptr::mut_ptr::<impl *mut [u32]>::as_mut_ptr) { debug self => _5; } - scope 8 (inlined ptr::mut_ptr::<impl *mut u32>::add) { + scope 12 (inlined ptr::mut_ptr::<impl *mut u32>::add) { debug self => _7; debug count => _3; - scope 9 { + scope 13 { } } - scope 10 (inlined slice_from_raw_parts_mut::<u32>) { + scope 14 (inlined slice_from_raw_parts_mut::<u32>) { debug data => _8; debug len => _6; let mut _9: *mut (); - scope 11 (inlined ptr::mut_ptr::<impl *mut u32>::cast::<()>) { + scope 15 (inlined ptr::mut_ptr::<impl *mut u32>::cast::<()>) { debug self => _8; } - scope 12 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { debug data_address => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 13 { + scope 17 { + } + } + } + } + scope 7 (inlined <std::ops::Range<usize> as SliceIndex<[T]>>::get_unchecked_mut::runtime::<u32>) { + debug ((this: std::ops::Range<usize>).0: usize) => _15; + debug ((this: std::ops::Range<usize>).1: usize) => _16; + debug slice => _5; + scope 8 (inlined ptr::mut_ptr::<impl *mut [u32]>::len) { + debug self => _5; + let mut _14: *const [u32]; + scope 9 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _14; + scope 10 { } } } @@ -63,9 +80,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> _4 = move (_2.1: usize); StorageLive(_5); _5 = &raw mut (*_1); + StorageLive(_6); StorageLive(_14); StorageLive(_15); - StorageLive(_6); + StorageLive(_16); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); @@ -86,9 +104,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_6); - StorageDead(_14); + StorageDead(_16); StorageDead(_15); + StorageDead(_14); + StorageDead(_6); StorageDead(_5); _0 = &mut (*_13); return; diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir index 4edf4b4fb44..4afe2eda188 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir @@ -75,17 +75,19 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_22); - StorageDead(_21); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_22); + StorageDead(_21); _9 = Option::<usize>::None; goto -> bb5; } bb3: { + StorageDead(_22); + StorageDead(_21); _10 = (_5.0: usize); StorageLive(_11); _11 = <usize as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir index 8bd072fd625..48092608d9c 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir @@ -75,17 +75,19 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_22); - StorageDead(_21); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_22); + StorageDead(_21); _9 = Option::<usize>::None; goto -> bb5; } bb3: { + StorageDead(_22); + StorageDead(_21); _10 = (_5.0: usize); StorageLive(_11); _11 = <usize as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind: bb12]; diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir index 70efdbf4b34..566b6af95ba 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir @@ -19,17 +19,16 @@ fn array_casts() -> () { let mut _18: &usize; let _19: usize; let mut _22: bool; - let mut _23: bool; + let mut _23: usize; let mut _24: usize; - let mut _25: usize; - let mut _26: !; - let _28: !; - let mut _29: core::panicking::AssertKind; - let mut _30: &usize; - let _31: &usize; - let mut _32: &usize; - let _33: &usize; - let mut _34: std::option::Option<std::fmt::Arguments<'_>>; + let mut _25: !; + let _27: !; + let mut _28: core::panicking::AssertKind; + let mut _29: &usize; + let _30: &usize; + let mut _31: &usize; + let _32: &usize; + let mut _33: std::option::Option<std::fmt::Arguments<'_>>; scope 1 { debug x => _1; let _2: *mut usize; @@ -45,15 +44,15 @@ fn array_casts() -> () { debug p => _9; let _20: &usize; let _21: &usize; - let mut _35: &usize; + let mut _34: &usize; scope 6 { } scope 7 { debug left_val => _20; debug right_val => _21; - let _27: core::panicking::AssertKind; + let _26: core::panicking::AssertKind; scope 8 { - debug kind => _27; + debug kind => _26; } } } @@ -110,9 +109,9 @@ fn array_casts() -> () { _15 = (*_16); _14 = &_15; StorageLive(_18); - _35 = const _; - Retag(_35); - _18 = &(*_35); + _34 = const _; + Retag(_34); + _18 = &(*_34); _13 = (move _14, move _18); Retag(_13); StorageDead(_18); @@ -125,39 +124,16 @@ fn array_casts() -> () { Retag(_21); StorageLive(_22); StorageLive(_23); + _23 = (*_20); StorageLive(_24); - _24 = (*_20); - StorageLive(_25); - _25 = (*_21); - _23 = Eq(move _24, move _25); - StorageDead(_25); - StorageDead(_24); - _22 = Not(move _23); - StorageDead(_23); + _24 = (*_21); + _22 = Eq(move _23, move _24); switchInt(move _22) -> [0: bb4, otherwise: bb3]; } bb3: { - StorageLive(_27); - _27 = core::panicking::AssertKind::Eq; - StorageLive(_28); - StorageLive(_29); - _29 = move _27; - StorageLive(_30); - StorageLive(_31); - _31 = &(*_20); - _30 = &(*_31); - StorageLive(_32); - StorageLive(_33); - _33 = &(*_21); - _32 = &(*_33); - StorageLive(_34); - _34 = Option::<Arguments<'_>>::None; - Retag(_34); - _28 = core::panicking::assert_failed::<usize, usize>(move _29, move _30, move _32, move _34) -> unwind unreachable; - } - - bb4: { + StorageDead(_24); + StorageDead(_23); _12 = const (); StorageDead(_22); StorageDead(_21); @@ -173,4 +149,26 @@ fn array_casts() -> () { StorageDead(_1); return; } + + bb4: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_26); + _26 = core::panicking::AssertKind::Eq; + StorageLive(_27); + StorageLive(_28); + _28 = move _26; + StorageLive(_29); + StorageLive(_30); + _30 = &(*_20); + _29 = &(*_30); + StorageLive(_31); + StorageLive(_32); + _32 = &(*_21); + _31 = &(*_32); + StorageLive(_33); + _33 = Option::<Arguments<'_>>::None; + Retag(_33); + _27 = core::panicking::assert_failed::<usize, usize>(move _28, move _29, move _31, move _33) -> unwind unreachable; + } } diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir index cfa9628d498..d0d3176320b 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir @@ -19,17 +19,16 @@ fn array_casts() -> () { let mut _18: &usize; let _19: usize; let mut _22: bool; - let mut _23: bool; + let mut _23: usize; let mut _24: usize; - let mut _25: usize; - let mut _26: !; - let _28: !; - let mut _29: core::panicking::AssertKind; - let mut _30: &usize; - let _31: &usize; - let mut _32: &usize; - let _33: &usize; - let mut _34: std::option::Option<std::fmt::Arguments<'_>>; + let mut _25: !; + let _27: !; + let mut _28: core::panicking::AssertKind; + let mut _29: &usize; + let _30: &usize; + let mut _31: &usize; + let _32: &usize; + let mut _33: std::option::Option<std::fmt::Arguments<'_>>; scope 1 { debug x => _1; let _2: *mut usize; @@ -45,15 +44,15 @@ fn array_casts() -> () { debug p => _9; let _20: &usize; let _21: &usize; - let mut _35: &usize; + let mut _34: &usize; scope 6 { } scope 7 { debug left_val => _20; debug right_val => _21; - let _27: core::panicking::AssertKind; + let _26: core::panicking::AssertKind; scope 8 { - debug kind => _27; + debug kind => _26; } } } @@ -110,9 +109,9 @@ fn array_casts() -> () { _15 = (*_16); _14 = &_15; StorageLive(_18); - _35 = const _; - Retag(_35); - _18 = &(*_35); + _34 = const _; + Retag(_34); + _18 = &(*_34); _13 = (move _14, move _18); Retag(_13); StorageDead(_18); @@ -125,39 +124,16 @@ fn array_casts() -> () { Retag(_21); StorageLive(_22); StorageLive(_23); + _23 = (*_20); StorageLive(_24); - _24 = (*_20); - StorageLive(_25); - _25 = (*_21); - _23 = Eq(move _24, move _25); - StorageDead(_25); - StorageDead(_24); - _22 = Not(move _23); - StorageDead(_23); + _24 = (*_21); + _22 = Eq(move _23, move _24); switchInt(move _22) -> [0: bb4, otherwise: bb3]; } bb3: { - StorageLive(_27); - _27 = core::panicking::AssertKind::Eq; - StorageLive(_28); - StorageLive(_29); - _29 = move _27; - StorageLive(_30); - StorageLive(_31); - _31 = &(*_20); - _30 = &(*_31); - StorageLive(_32); - StorageLive(_33); - _33 = &(*_21); - _32 = &(*_33); - StorageLive(_34); - _34 = Option::<Arguments<'_>>::None; - Retag(_34); - _28 = core::panicking::assert_failed::<usize, usize>(move _29, move _30, move _32, move _34) -> unwind continue; - } - - bb4: { + StorageDead(_24); + StorageDead(_23); _12 = const (); StorageDead(_22); StorageDead(_21); @@ -173,4 +149,26 @@ fn array_casts() -> () { StorageDead(_1); return; } + + bb4: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_26); + _26 = core::panicking::AssertKind::Eq; + StorageLive(_27); + StorageLive(_28); + _28 = move _26; + StorageLive(_29); + StorageLive(_30); + _30 = &(*_20); + _29 = &(*_30); + StorageLive(_31); + StorageLive(_32); + _32 = &(*_21); + _31 = &(*_32); + StorageLive(_33); + _33 = Option::<Arguments<'_>>::None; + Retag(_33); + _27 = core::panicking::assert_failed::<usize, usize>(move _28, move _29, move _31, move _33) -> unwind continue; + } } diff --git a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff index bb14b909a95..b020d1baafa 100644 --- a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff @@ -33,7 +33,8 @@ + let _32: u32; scope 1 { - debug foo => _1; -+ debug foo => Foo<T>{ .0 => _31, .1 => _32, }; ++ debug ((foo: Foo<T>).0: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>) => _31; ++ debug ((foo: Foo<T>).1: u32) => _32; let _5: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>; scope 2 { debug x => _5; diff --git a/tests/mir-opt/sroa/structs.constant.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/structs.constant.ScalarReplacementOfAggregates.diff index 7ee0431692c..1330f9b3ac8 100644 --- a/tests/mir-opt/sroa/structs.constant.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/structs.constant.ScalarReplacementOfAggregates.diff @@ -8,7 +8,8 @@ + let _5: u8; scope 1 { - debug y => _1; -+ debug y => (usize, u8){ .0 => _4, .1 => _5, }; ++ debug ((y: (usize, u8)).0: usize) => _4; ++ debug ((y: (usize, u8)).1: u8) => _5; let _2: usize; scope 2 { debug t => _2; diff --git a/tests/mir-opt/sroa/structs.copies.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/structs.copies.ScalarReplacementOfAggregates.diff index 0a1de891aee..3621338635e 100644 --- a/tests/mir-opt/sroa/structs.copies.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/structs.copies.ScalarReplacementOfAggregates.diff @@ -11,7 +11,10 @@ + let _14: std::option::Option<isize>; scope 1 { - debug y => _2; -+ debug y => Foo{ .0 => _11, .1 => _12, .2 => _13, .3 => _14, }; ++ debug ((y: Foo).0: u8) => _11; ++ debug ((y: Foo).1: ()) => _12; ++ debug ((y: Foo).2: &str) => _13; ++ debug ((y: Foo).3: std::option::Option<isize>) => _14; let _3: u8; scope 2 { debug t => _3; @@ -25,7 +28,10 @@ + let _10: std::option::Option<isize>; scope 4 { - debug z => _5; -+ debug z => Foo{ .0 => _7, .1 => _8, .2 => _9, .3 => _10, }; ++ debug ((z: Foo).0: u8) => _7; ++ debug ((z: Foo).1: ()) => _8; ++ debug ((z: Foo).2: &str) => _9; ++ debug ((z: Foo).3: std::option::Option<isize>) => _10; let _6: (); scope 5 { debug a => _6; diff --git a/tests/mir-opt/sroa/structs.ref_copies.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/structs.ref_copies.ScalarReplacementOfAggregates.diff index d7c57c293c4..304bf2fb1a7 100644 --- a/tests/mir-opt/sroa/structs.ref_copies.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/structs.ref_copies.ScalarReplacementOfAggregates.diff @@ -11,7 +11,10 @@ + let _8: std::option::Option<isize>; scope 1 { - debug y => _2; -+ debug y => Foo{ .0 => _5, .1 => _6, .2 => _7, .3 => _8, }; ++ debug ((y: Foo).0: u8) => _5; ++ debug ((y: Foo).1: ()) => _6; ++ debug ((y: Foo).2: &str) => _7; ++ debug ((y: Foo).3: std::option::Option<isize>) => _8; let _3: u8; scope 2 { debug t => _3; diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index 7d7f682130d..fd9386be8f3 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -79,7 +79,7 @@ pub const a_test: test::TestDescAndFn = }; fn a_test() {} #[rustc_main] -#[no_coverage] +#[coverage(off)] pub fn main() -> () { extern crate test; test::test_main_static(&[&a_test, &m_test, &z_test]) diff --git a/tests/run-coverage/closure_macro.coverage b/tests/run-coverage/closure_macro.coverage index 1bfd2013da8..0f2c917e090 100644 --- a/tests/run-coverage/closure_macro.coverage +++ b/tests/run-coverage/closure_macro.coverage @@ -1,5 +1,5 @@ LL| |// compile-flags: --edition=2018 - LL| |#![feature(no_coverage)] + LL| |#![feature(coverage_attribute)] LL| | LL| |macro_rules! bail { LL| | ($msg:literal $(,)?) => { diff --git a/tests/run-coverage/closure_macro.rs b/tests/run-coverage/closure_macro.rs index 5e3b00d1ef5..9b289141c2e 100644 --- a/tests/run-coverage/closure_macro.rs +++ b/tests/run-coverage/closure_macro.rs @@ -1,5 +1,5 @@ // compile-flags: --edition=2018 -#![feature(no_coverage)] +#![feature(coverage_attribute)] macro_rules! bail { ($msg:literal $(,)?) => { diff --git a/tests/run-coverage/closure_macro_async.coverage b/tests/run-coverage/closure_macro_async.coverage index 018e3160e4f..74247f1bc6f 100644 --- a/tests/run-coverage/closure_macro_async.coverage +++ b/tests/run-coverage/closure_macro_async.coverage @@ -1,5 +1,5 @@ LL| |// compile-flags: --edition=2018 - LL| |#![feature(no_coverage)] + LL| |#![feature(coverage_attribute)] LL| | LL| |macro_rules! bail { LL| | ($msg:literal $(,)?) => { @@ -40,7 +40,7 @@ LL| 1| Ok(()) LL| 1|} LL| | - LL| |#[no_coverage] + LL| |#[coverage(off)] LL| |fn main() { LL| | executor::block_on(test()).unwrap(); LL| |} @@ -52,18 +52,18 @@ LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, LL| | }; LL| | - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output { LL| | let mut future = unsafe { Pin::new_unchecked(&mut future) }; LL| | use std::hint::unreachable_unchecked; LL| | static VTABLE: RawWakerVTable = RawWakerVTable::new( - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| unsafe { unreachable_unchecked() }, // clone - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| unsafe { unreachable_unchecked() }, // wake - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| (), LL| | ); LL| | let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; diff --git a/tests/run-coverage/closure_macro_async.rs b/tests/run-coverage/closure_macro_async.rs index 3d6bdb38a2a..b4275599e59 100644 --- a/tests/run-coverage/closure_macro_async.rs +++ b/tests/run-coverage/closure_macro_async.rs @@ -1,5 +1,5 @@ // compile-flags: --edition=2018 -#![feature(no_coverage)] +#![feature(coverage_attribute)] macro_rules! bail { ($msg:literal $(,)?) => { @@ -39,7 +39,7 @@ pub async fn test() -> Result<(), String> { Ok(()) } -#[no_coverage] +#[coverage(off)] fn main() { executor::block_on(test()).unwrap(); } @@ -51,18 +51,18 @@ mod executor { task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, }; - #[no_coverage] + #[coverage(off)] pub fn block_on<F: Future>(mut future: F) -> F::Output { let mut future = unsafe { Pin::new_unchecked(&mut future) }; use std::hint::unreachable_unchecked; static VTABLE: RawWakerVTable = RawWakerVTable::new( - #[no_coverage] + #[coverage(off)] |_| unsafe { unreachable_unchecked() }, // clone - #[no_coverage] + #[coverage(off)] |_| unsafe { unreachable_unchecked() }, // wake - #[no_coverage] + #[coverage(off)] |_| unsafe { unreachable_unchecked() }, // wake_by_ref - #[no_coverage] + #[coverage(off)] |_| (), ); let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; diff --git a/tests/run-coverage/lazy_boolean.coverage b/tests/run-coverage/lazy_boolean.coverage index 2d927a08356..8f14082ef68 100644 --- a/tests/run-coverage/lazy_boolean.coverage +++ b/tests/run-coverage/lazy_boolean.coverage @@ -32,7 +32,7 @@ ^0 LL| | LL| | if - LL| 1| ! + LL| | ! LL| 1| is_true LL| 0| { LL| 0| a = 2 diff --git a/tests/run-coverage/no_cov_crate.coverage b/tests/run-coverage/no_cov_crate.coverage index 73f6fbd0c2b..f5a0322bf3e 100644 --- a/tests/run-coverage/no_cov_crate.coverage +++ b/tests/run-coverage/no_cov_crate.coverage @@ -1,17 +1,17 @@ - LL| |// Enables `no_coverage` on the entire crate - LL| |#![feature(no_coverage)] + LL| |// Enables `coverage(off)` on the entire crate + LL| |#![feature(coverage_attribute)] LL| | - LL| |#[no_coverage] + LL| |#[coverage(off)] LL| |fn do_not_add_coverage_1() { LL| | println!("called but not covered"); LL| |} LL| | LL| |fn do_not_add_coverage_2() { - LL| | #![no_coverage] + LL| | #![coverage(off)] LL| | println!("called but not covered"); LL| |} LL| | - LL| |#[no_coverage] + LL| |#[coverage(off)] LL| |#[allow(dead_code)] LL| |fn do_not_add_coverage_not_called() { LL| | println!("not called and not covered"); @@ -33,7 +33,7 @@ LL| |// FIXME: These test-cases illustrate confusing results of nested functions. LL| |// See https://github.com/rust-lang/rust/issues/93319 LL| |mod nested_fns { - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | pub fn outer_not_covered(is_true: bool) { LL| 1| fn inner(is_true: bool) { LL| 1| if is_true { @@ -50,7 +50,7 @@ LL| 1| println!("called and covered"); LL| 1| inner_not_covered(is_true); LL| 1| - LL| 1| #[no_coverage] + 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"); diff --git a/tests/run-coverage/no_cov_crate.rs b/tests/run-coverage/no_cov_crate.rs index 5b748aeefb7..e12e4bc55e3 100644 --- a/tests/run-coverage/no_cov_crate.rs +++ b/tests/run-coverage/no_cov_crate.rs @@ -1,17 +1,17 @@ -// Enables `no_coverage` on the entire crate -#![feature(no_coverage)] +// Enables `coverage(off)` on the entire crate +#![feature(coverage_attribute)] -#[no_coverage] +#[coverage(off)] fn do_not_add_coverage_1() { println!("called but not covered"); } fn do_not_add_coverage_2() { - #![no_coverage] + #![coverage(off)] println!("called but not covered"); } -#[no_coverage] +#[coverage(off)] #[allow(dead_code)] fn do_not_add_coverage_not_called() { println!("not called and not covered"); @@ -33,7 +33,7 @@ fn add_coverage_not_called() { // FIXME: These test-cases illustrate confusing results of nested functions. // See https://github.com/rust-lang/rust/issues/93319 mod nested_fns { - #[no_coverage] + #[coverage(off)] pub fn outer_not_covered(is_true: bool) { fn inner(is_true: bool) { if is_true { @@ -50,7 +50,7 @@ mod nested_fns { println!("called and covered"); inner_not_covered(is_true); - #[no_coverage] + #[coverage(off)] fn inner_not_covered(is_true: bool) { if is_true { println!("called but not covered"); diff --git a/tests/run-make-fulldeps/issue-19371/foo.rs b/tests/run-make-fulldeps/issue-19371/foo.rs index 68132638759..1c9d33dcc8e 100644 --- a/tests/run-make-fulldeps/issue-19371/foo.rs +++ b/tests/run-make-fulldeps/issue-19371/foo.rs @@ -61,6 +61,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { override_queries: None, make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), + expanded_args: Default::default(), }; interface::run_compiler(config, |compiler| { diff --git a/tests/run-make-fulldeps/obtain-borrowck/driver.rs b/tests/run-make-fulldeps/obtain-borrowck/driver.rs index 04c551cf4bb..b59a65a713f 100644 --- a/tests/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/tests/run-make-fulldeps/obtain-borrowck/driver.rs @@ -27,7 +27,7 @@ use rustc_interface::{Config, Queries}; use rustc_middle::query::queries::mir_borrowck::ProvidedValue; use rustc_middle::query::{ExternProviders, Providers}; use rustc_middle::ty::TyCtxt; -use rustc_session::{Session, EarlyErrorHandler}; +use rustc_session::Session; use std::cell::RefCell; use std::collections::HashMap; use std::thread_local; @@ -58,7 +58,6 @@ impl rustc_driver::Callbacks for CompilerCalls { // the result. fn after_analysis<'tcx>( &mut self, - _handler: &EarlyErrorHandler, compiler: &Compiler, queries: &'tcx Queries<'tcx>, ) -> Compilation { diff --git a/tests/run-make/compressed-debuginfo/Makefile b/tests/run-make/compressed-debuginfo/Makefile new file mode 100644 index 00000000000..f9e4927d008 --- /dev/null +++ b/tests/run-make/compressed-debuginfo/Makefile @@ -0,0 +1,15 @@ +# ignore-cross-compile +include ../tools.mk + +# only-linux +# min-llvm-version: 16.0 +# +# This tests debuginfo-compression. + +all: zlib zstandard + +zlib: + test "`$(RUSTC) --crate-name=foo --crate-type=lib --emit=obj -C debuginfo=full -Z debuginfo-compression=zlib foo.rs 2>&1 | sed 's/.*unknown.*zlib.*/missing/' | head -n 1`" = missing || readelf -t $(TMPDIR)/foo.o | grep -q ZLIB + +zstandard: + test "`$(RUSTC) --crate-name=foo --crate-type=lib --emit=obj -C debuginfo=full -Z debuginfo-compression=zstd foo.rs 2>&1 | sed 's/.*unknown.*zstd.*/missing/' | head -n 1`" = missing || readelf -t $(TMPDIR)/foo.o | grep -q ZST diff --git a/tests/run-make/compressed-debuginfo/foo.rs b/tests/run-make/compressed-debuginfo/foo.rs new file mode 100644 index 00000000000..185ce22450c --- /dev/null +++ b/tests/run-make/compressed-debuginfo/foo.rs @@ -0,0 +1,3 @@ +pub fn foo() -> i32 { + 42 +} diff --git a/tests/run-make/emit-path-unhashed/Makefile b/tests/run-make/emit-path-unhashed/Makefile index 74047fe5f86..611f8578140 100644 --- a/tests/run-make/emit-path-unhashed/Makefile +++ b/tests/run-make/emit-path-unhashed/Makefile @@ -5,10 +5,10 @@ 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 $(TMPDIR)/libfoo.rlib > $(TMPDIR)/base.txt - $(RUSTC) -Zls $(OUT)/a/libfoo.rlib > $(TMPDIR)/a.txt - $(RUSTC) -Zls $(OUT)/b/libfoo.rlib > $(TMPDIR)/b.txt - $(RUSTC) -Zls $(OUT)/c/libfoo.rlib > $(TMPDIR)/c.txt + $(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 diff --git a/tests/run-make/issue-88756-default-output/output-default.stdout b/tests/run-make/issue-88756-default-output/output-default.stdout index de8ff0e5f89..f5981045b03 100644 --- a/tests/run-make/issue-88756-default-output/output-default.stdout +++ b/tests/run-make/issue-88756-default-output/output-default.stdout @@ -100,7 +100,7 @@ Options: check if given theme is valid --resource-suffix PATH suffix to add to CSS and JavaScript files, e.g., - "light.css" will become "light-suffix.css" + "search-index.js" will become "search-index-suffix.js" --edition EDITION edition to use when compiling rust code (default: 2015) diff --git a/tests/run-make/ls-metadata/Makefile b/tests/run-make/ls-metadata/Makefile index 123dd64e15c..f03569baef7 100644 --- a/tests/run-make/ls-metadata/Makefile +++ b/tests/run-make/ls-metadata/Makefile @@ -3,6 +3,6 @@ include ../tools.mk all: $(RUSTC) foo.rs - $(RUSTC) -Z ls $(TMPDIR)/foo + $(RUSTC) -Z ls=root $(TMPDIR)/foo touch $(TMPDIR)/bar - $(RUSTC) -Z ls $(TMPDIR)/bar + $(RUSTC) -Z ls=root $(TMPDIR)/bar diff --git a/tests/run-make/lto-linkage-used-attr/Makefile b/tests/run-make/lto-linkage-used-attr/Makefile new file mode 100644 index 00000000000..e78b83890ed --- /dev/null +++ b/tests/run-make/lto-linkage-used-attr/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# Verify that the impl_* symbols are preserved. #108030 +# only-x86_64-unknown-linux-gnu +# min-llvm-version: 17 + +all: + $(RUSTC) -Cdebuginfo=0 -Copt-level=3 lib.rs + $(RUSTC) -Clto=fat -Cdebuginfo=0 -Copt-level=3 main.rs diff --git a/tests/run-make/lto-linkage-used-attr/lib.rs b/tests/run-make/lto-linkage-used-attr/lib.rs new file mode 100644 index 00000000000..0a92ea9cd22 --- /dev/null +++ b/tests/run-make/lto-linkage-used-attr/lib.rs @@ -0,0 +1,50 @@ +#![crate_type = "rlib"] +#![crate_type = "cdylib"] + +#[macro_export] +macro_rules! asm_func { + ($name:expr, $body:expr $(, $($args:tt)*)?) => { + core::arch::global_asm!( + concat!( + ".p2align 4\n", + ".hidden ", $name, "\n", + ".global ", $name, "\n", + ".type ", $name, ",@function\n", + $name, ":\n", + $body, + ".size ", $name, ",.-", $name, + ) + $(, $($args)*)? + ); + }; +} + +macro_rules! libcall_trampoline { + ($libcall:ident ; $libcall_impl:ident) => { + asm_func!( + stringify!($libcall), + concat!( + " + .cfi_startproc simple + .cfi_def_cfa_offset 0 + jmp {} + .cfi_endproc + ", + ), + sym $libcall_impl + ); + }; +} + +pub mod trampolines { + extern "C" { + pub fn table_fill_funcref(); + pub fn table_fill_externref(); + } + + unsafe extern "C" fn impl_table_fill_funcref() {} + unsafe extern "C" fn impl_table_fill_externref() {} + + libcall_trampoline!(table_fill_funcref ; impl_table_fill_funcref); + libcall_trampoline!(table_fill_externref ; impl_table_fill_externref); +} diff --git a/tests/run-make/lto-linkage-used-attr/main.rs b/tests/run-make/lto-linkage-used-attr/main.rs new file mode 100644 index 00000000000..256b02e5b0b --- /dev/null +++ b/tests/run-make/lto-linkage-used-attr/main.rs @@ -0,0 +1,10 @@ +extern crate lib; + +use lib::trampolines::*; + +fn main() { + unsafe { + table_fill_externref(); + table_fill_funcref(); + } +} diff --git a/tests/run-make/metadata-dep-info/Makefile b/tests/run-make/metadata-dep-info/Makefile new file mode 100644 index 00000000000..f9043f21433 --- /dev/null +++ b/tests/run-make/metadata-dep-info/Makefile @@ -0,0 +1,13 @@ +include ../tools.mk + +ifdef RUSTC_BLESS_TEST + RUSTC_TEST_OP = cp +else + RUSTC_TEST_OP = $(DIFF) +endif + +all: + $(RUSTC) --emit=metadata,dep-info --crate-type lib dash-separated.rs -C extra-filename=_something-extra + # Strip TMPDIR since it is a machine specific absolute path + sed "s%.*[/\\]%%" "$(TMPDIR)"/dash-separated_something-extra.d > "$(TMPDIR)"/dash-separated_something-extra.normalized.d + $(RUSTC_TEST_OP) "$(TMPDIR)"/dash-separated_something-extra.normalized.d dash-separated_something-extra.normalized.d diff --git a/tests/run-make/metadata-dep-info/dash-separated.rs b/tests/run-make/metadata-dep-info/dash-separated.rs new file mode 100644 index 00000000000..4202afd3d08 --- /dev/null +++ b/tests/run-make/metadata-dep-info/dash-separated.rs @@ -0,0 +1,4 @@ +//! It is important that this file has at least one `-` in the file name since +//! we want to test that it becomes a `_` when appropriate. + +pub struct Foo; diff --git a/tests/run-make/metadata-dep-info/dash-separated_something-extra.normalized.d b/tests/run-make/metadata-dep-info/dash-separated_something-extra.normalized.d new file mode 100644 index 00000000000..497d76b4ea1 --- /dev/null +++ b/tests/run-make/metadata-dep-info/dash-separated_something-extra.normalized.d @@ -0,0 +1,5 @@ +libdash_separated_something-extra.rmeta: dash-separated.rs + +dash-separated_something-extra.d: dash-separated.rs + +dash-separated.rs: diff --git a/tests/run-make/output-filename-overwrites-input/Makefile b/tests/run-make/output-filename-overwrites-input/Makefile index 605b86b253e..fe5d231382d 100644 --- a/tests/run-make/output-filename-overwrites-input/Makefile +++ b/tests/run-make/output-filename-overwrites-input/Makefile @@ -8,7 +8,7 @@ all: cp bar.rs $(TMPDIR)/bar.rlib $(RUSTC) $(TMPDIR)/bar.rlib -o $(TMPDIR)/bar.rlib 2>&1 \ | $(CGREP) -e "the input file \".*bar.rlib\" would be overwritten by the generated executable" - $(RUSTC) foo.rs 2>&1 && $(RUSTC) -Z ls $(TMPDIR)/foo 2>&1 + $(RUSTC) foo.rs 2>&1 && $(RUSTC) -Z ls=root $(TMPDIR)/foo 2>&1 cp foo.rs $(TMPDIR)/foo.rs $(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo.rs 2>&1 \ | $(CGREP) -e "the input file \".*foo.rs\" would be overwritten by the generated executable" diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/Makefile b/tests/run-make/pdb-buildinfo-cl-cmd/Makefile new file mode 100644 index 00000000000..a7be301a5b0 --- /dev/null +++ b/tests/run-make/pdb-buildinfo-cl-cmd/Makefile @@ -0,0 +1,16 @@ +include ../tools.mk + +# only-windows-msvc + +# tests if the pdb contains the following information in the LF_BUILDINFO: +# 1. the commandline args to compile it (cmd) +# 2. full path to the compiler (cl) + +# we just do a stringsearch on the pdb, as these need to show up at least once, as the LF_BUILDINFO is created for each cgu +# actual parsing would be better, but this is a simple and good enough solution for now + +all: + $(RUSTC_ORIGINAL) main.rs -g --crate-name my_crate_name --crate-type bin -C metadata=dc9ef878b0a48666 --out-dir $(TMPDIR) + cat '$(TMPDIR)/my_crate_name.pdb' | grep -F '$(RUSTC_ORIGINAL)' +# using a file containing the string so I don't have problems with escaping quotes and spaces + cat '$(TMPDIR)/my_crate_name.pdb' | grep -f 'stringlist.txt' diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/main.rs b/tests/run-make/pdb-buildinfo-cl-cmd/main.rs new file mode 100644 index 00000000000..f79c691f085 --- /dev/null +++ b/tests/run-make/pdb-buildinfo-cl-cmd/main.rs @@ -0,0 +1,2 @@ +fn main() { +} diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt b/tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt new file mode 100644 index 00000000000..634e9f19e89 --- /dev/null +++ b/tests/run-make/pdb-buildinfo-cl-cmd/stringlist.txt @@ -0,0 +1 @@ +"main.rs" "-g" "--crate-name" "my_crate_name" "--crate-type" "bin" "-C" "metadata=dc9ef878b0a48666" "--out-dir" \ No newline at end of file diff --git a/tests/run-make/pgo-branch-weights/Makefile b/tests/run-make/pgo-branch-weights/Makefile index c60206a1f34..4c9f8b2493a 100644 --- a/tests/run-make/pgo-branch-weights/Makefile +++ b/tests/run-make/pgo-branch-weights/Makefile @@ -1,5 +1,6 @@ # needs-profiler-support # ignore-windows-gnu +# ignore-cross-compile # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works # properly. Since we only have GCC on the CI ignore the test for now. diff --git a/tests/run-make/pgo-gen-lto/Makefile b/tests/run-make/pgo-gen-lto/Makefile index 3f2f6a838b5..8b647846af3 100644 --- a/tests/run-make/pgo-gen-lto/Makefile +++ b/tests/run-make/pgo-gen-lto/Makefile @@ -1,5 +1,6 @@ # needs-profiler-support # ignore-windows-gnu +# ignore-cross-compile # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works # properly. Since we only have GCC on the CI ignore the test for now. diff --git a/tests/run-make/pgo-gen/Makefile b/tests/run-make/pgo-gen/Makefile index 4623a74957b..bf32cfdb802 100644 --- a/tests/run-make/pgo-gen/Makefile +++ b/tests/run-make/pgo-gen/Makefile @@ -1,5 +1,6 @@ # needs-profiler-support # ignore-windows-gnu +# ignore-cross-compile # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works # properly. Since we only have GCC on the CI ignore the test for now. diff --git a/tests/run-make/pgo-indirect-call-promotion/Makefile b/tests/run-make/pgo-indirect-call-promotion/Makefile index 45302215cc6..542eb244d39 100644 --- a/tests/run-make/pgo-indirect-call-promotion/Makefile +++ b/tests/run-make/pgo-indirect-call-promotion/Makefile @@ -1,5 +1,6 @@ # needs-profiler-support # ignore-windows-gnu +# ignore-cross-compile # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works # properly. Since we only have GCC on the CI ignore the test for now. diff --git a/tests/run-make/pgo-use/Makefile b/tests/run-make/pgo-use/Makefile index 3bac9b77aa3..9f440118dae 100644 --- a/tests/run-make/pgo-use/Makefile +++ b/tests/run-make/pgo-use/Makefile @@ -1,5 +1,6 @@ # needs-profiler-support # ignore-windows-gnu +# ignore-cross-compile # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works # properly. Since we only have GCC on the CI ignore the test for now. diff --git a/tests/run-make/pointer-auth-link-with-c/Makefile b/tests/run-make/pointer-auth-link-with-c/Makefile index dffbd303582..8fcf10e2096 100644 --- a/tests/run-make/pointer-auth-link-with-c/Makefile +++ b/tests/run-make/pointer-auth-link-with-c/Makefile @@ -1,6 +1,7 @@ include ../tools.mk # only-aarch64 +# ignore-cross-compile all: $(COMPILE_OBJ) $(TMPDIR)/test.o test.c diff --git a/tests/run-make/print-cfg/Makefile b/tests/run-make/print-cfg/Makefile index 654c303b3e2..6b153e5b54e 100644 --- a/tests/run-make/print-cfg/Makefile +++ b/tests/run-make/print-cfg/Makefile @@ -13,19 +13,19 @@ all: default output_to_file output_to_file: # Backend-independent, printed by rustc_driver_impl/src/lib.rs - $(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt -Z unstable-options + $(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt $(CGREP) windows < $(TMPDIR)/cfg.txt # Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs - $(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt -Z unstable-options + $(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt $(CGREP) dynamic-no-pic < $(TMPDIR)/relocation-models.txt # Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs - $(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt -Z unstable-options + $(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt $(CGREP) reference-types < $(TMPDIR)/target-features.txt # Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp - $(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt -Z unstable-options + $(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt $(CGREP) generic < $(TMPDIR)/target-cpus.txt ifdef IS_WINDOWS diff --git a/tests/run-make/profile/Makefile b/tests/run-make/profile/Makefile index fffc051adbf..7919b18ba74 100644 --- a/tests/run-make/profile/Makefile +++ b/tests/run-make/profile/Makefile @@ -1,4 +1,5 @@ # needs-profiler-support +# ignore-cross-compile include ../tools.mk diff --git a/tests/run-make/rustdoc-themes/Makefile b/tests/run-make/rustdoc-themes/Makefile index a6d9a43addf..a4980eb0b3e 100644 --- a/tests/run-make/rustdoc-themes/Makefile +++ b/tests/run-make/rustdoc-themes/Makefile @@ -5,6 +5,7 @@ include ../tools.mk OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes" all: - cp $(S)/src/librustdoc/html/static/css/themes/light.css $(TMPDIR)/test.css + awk '/Begin theme: light/ {in_theme=1;next} /End theme:/ {in_theme=0} { if (in_theme) print }' \ + < '$(S)/src/librustdoc/html/static/css/noscript.css' > '$(TMPDIR)/test.css' $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --theme $(TMPDIR)/test.css $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs diff --git a/tests/rustdoc-gui/code-color.goml b/tests/rustdoc-gui/code-color.goml index 833fa05db42..92bdfb25b00 100644 --- a/tests/rustdoc-gui/code-color.goml +++ b/tests/rustdoc-gui/code-color.goml @@ -19,6 +19,18 @@ define-function: ( }, ) -call-function: ("check-colors", ("ayu", "rgb(230, 225, 207)", "rgb(255, 180, 84)")) -call-function: ("check-colors", ("dark", "rgb(221, 221, 221)", "rgb(221, 221, 221)")) -call-function: ("check-colors", ("light", "rgb(0, 0, 0)", "rgb(0, 0, 0)")) +call-function: ("check-colors", { + "theme": "ayu", + "doc_code_color": "#e6e1cf", + "doc_inline_code_color": "#ffb454", +}) +call-function: ("check-colors", { + "theme": "dark", + "doc_code_color": "#ddd", + "doc_inline_code_color": "#ddd", +}) +call-function: ("check-colors", { + "theme": "light", + "doc_code_color": "black", + "doc_inline_code_color": "black", +}) diff --git a/tests/rustdoc-gui/help-page.goml b/tests/rustdoc-gui/help-page.goml index 6e880302f28..84c20355500 100644 --- a/tests/rustdoc-gui/help-page.goml +++ b/tests/rustdoc-gui/help-page.goml @@ -33,21 +33,21 @@ define-function: ( call-function: ("check-colors", { "theme": "ayu", - "color": "rgb(197, 197, 197)", - "background": "rgb(49, 69, 89)", - "box_shadow": "rgb(92, 103, 115)", + "color": "#c5c5c5", + "background": "#314559", + "box_shadow": "#5c6773", }) call-function: ("check-colors", { "theme": "dark", - "color": "rgb(0, 0, 0)", - "background": "rgb(250, 251, 252)", - "box_shadow": "rgb(198, 203, 209)", + "color": "#000", + "background": "#fafbfc", + "box_shadow": "#c6cbd1", }) call-function: ("check-colors", { "theme": "light", - "color": "rgb(0, 0, 0)", - "background": "rgb(250, 251, 252)", - "box_shadow": "rgb(198, 203, 209)", + "color": "#000", + "background": "#fafbfc", + "box_shadow": "#c6cbd1", }) // This test ensures that opening the help popover without switching pages works. diff --git a/tests/rustdoc-gui/search-no-result.goml b/tests/rustdoc-gui/search-no-result.goml index 46d1856b4d6..e7c64791256 100644 --- a/tests/rustdoc-gui/search-no-result.goml +++ b/tests/rustdoc-gui/search-no-result.goml @@ -21,16 +21,16 @@ define-function: ( call-function: ("check-no-result", { "theme": "ayu", - "link": "rgb(57, 175, 215)", - "link_hover": "rgb(57, 175, 215)", + "link": "#39afd7", + "link_hover": "#39afd7", }) call-function: ("check-no-result", { "theme": "dark", - "link": "rgb(210, 153, 29)", - "link_hover": "rgb(210, 153, 29)", + "link": "#d2991d", + "link_hover": "#d2991d", }) call-function: ("check-no-result", { "theme": "light", - "link": "rgb(56, 115, 173)", - "link_hover": "rgb(56, 115, 173)", + "link": "#3873ad", + "link_hover": "#3873ad", }) diff --git a/tests/rustdoc-gui/search-result-color.goml b/tests/rustdoc-gui/search-result-color.goml index f9f81c5ba04..44677dfbfef 100644 --- a/tests/rustdoc-gui/search-result-color.goml +++ b/tests/rustdoc-gui/search-result-color.goml @@ -151,7 +151,7 @@ assert-css: ( ) assert-css: ( "//*[@class='result-name']//*[text()='test_docs::']/ancestor::a", - {"color": "#fff", "background-color": "rgb(60, 60, 60)"}, + {"color": "#fff", "background-color": "#3c3c3c"}, ) // Dark theme diff --git a/tests/rustdoc-gui/sidebar-source-code.goml b/tests/rustdoc-gui/sidebar-source-code.goml index 69c589741cb..92b9045b734 100644 --- a/tests/rustdoc-gui/sidebar-source-code.goml +++ b/tests/rustdoc-gui/sidebar-source-code.goml @@ -73,7 +73,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']" // Only "another_folder" should be "open" in "lib2". assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']" // All other trees should be collapsed. -assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 9) +assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 10) // We now switch to mobile mode. set-window-size: (600, 600) diff --git a/tests/rustdoc-gui/sidebar.goml b/tests/rustdoc-gui/sidebar.goml index 913d72932b9..520481d3bba 100644 --- a/tests/rustdoc-gui/sidebar.goml +++ b/tests/rustdoc-gui/sidebar.goml @@ -25,24 +25,24 @@ call-function: ( "check-colors", { "theme": "ayu", - "color": "rgb(197, 197, 197)", - "background_color": "rgb(20, 25, 31)", + "color": "#c5c5c5", + "background_color": "#14191f", } ) call-function: ( "check-colors", { "theme": "dark", - "color": "rgb(221, 221, 221)", - "background_color": "rgb(80, 80, 80)", + "color": "#ddd", + "background_color": "#505050", } ) call-function: ( "check-colors", { "theme": "light", - "color": "rgb(0, 0, 0)", - "background_color": "rgb(245, 245, 245)", + "color": "black", + "background_color": "#f5f5f5", } ) @@ -55,7 +55,7 @@ assert-text: (".sidebar > .location", "Crate test_docs") assert-count: (".sidebar .location", 1) assert-count: (".sidebar h2", 1) assert-text: ("#all-types", "All Items") -assert-css: ("#all-types", {"color": "rgb(53, 109, 164)"}) +assert-css: ("#all-types", {"color": "#356da4"}) // We check that we have the crates list and that the "current" on is "test_docs". assert-text: (".sidebar-elems ul.crate > li > a.current", "test_docs") // And we're also supposed to have the list of items in the current module. @@ -88,7 +88,7 @@ assert-property: ("html", {"scrollTop": "0"}) // We now go back to the crate page to click on the "lib2" crate link. go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" assert-property: (".sidebar", {"clientWidth": "200"}) -assert-css: (".sidebar-elems ul.crate > li:first-child > a", {"color": "rgb(53, 109, 164)"}) +assert-css: (".sidebar-elems ul.crate > li:first-child > a", {"color": "#356da4"}) click: ".sidebar-elems ul.crate > li:first-child > a" // PAGE: lib2/index.html @@ -140,7 +140,7 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" assert-property: (".sidebar", {"clientWidth": "200"}) click: "//ul[@class='block mod']/preceding-sibling::h3/a" // PAGE: index.html -assert-css: ("#modules", {"background-color": "rgb(253, 255, 211)"}) +assert-css: ("#modules", {"background-color": "#fdffd3"}) // Finally, assert that the `[+]/[−]` toggle doesn't affect sidebar width. click: "#toggle-all-docs" diff --git a/tests/rustdoc-gui/src/theme_css/Cargo.lock b/tests/rustdoc-gui/src/theme_css/Cargo.lock new file mode 100644 index 00000000000..7ad6737a4d0 --- /dev/null +++ b/tests/rustdoc-gui/src/theme_css/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "theme_css" +version = "0.1.0" diff --git a/tests/rustdoc-gui/src/theme_css/Cargo.toml b/tests/rustdoc-gui/src/theme_css/Cargo.toml new file mode 100644 index 00000000000..798e64f9309 --- /dev/null +++ b/tests/rustdoc-gui/src/theme_css/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "theme_css" +version = "0.1.0" +edition = "2018" + +[lib] +path = "lib.rs" diff --git a/tests/rustdoc-gui/src/theme_css/custom-theme.css b/tests/rustdoc-gui/src/theme_css/custom-theme.css new file mode 100644 index 00000000000..260ef87f6ea --- /dev/null +++ b/tests/rustdoc-gui/src/theme_css/custom-theme.css @@ -0,0 +1,99 @@ +:root { + --main-background-color: red; + --main-color: black; + --settings-input-color: #2196f3; + --settings-input-border-color: #717171; + --settings-button-color: #000; + --settings-button-border-focus: #717171; + --sidebar-background-color: #f5f5f5; + --sidebar-background-color-hover: #e0e0e0; + --code-block-background-color: #f5f5f5; + --scrollbar-track-background-color: #dcdcdc; + --scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6); + --scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9; + --headings-border-bottom-color: #ddd; + --border-color: #e0e0e0; + --button-background-color: #fff; + --right-side-color: grey; + --code-attribute-color: #999; + --toggles-color: #999; + --toggle-filter: none; + --search-input-focused-border-color: #66afe9; + --copy-path-button-color: #999; + --copy-path-img-filter: invert(50%); + --copy-path-img-hover-filter: invert(35%); + --codeblock-error-hover-color: rgb(255, 0, 0); + --codeblock-error-color: rgba(255, 0, 0, .5); + --codeblock-ignore-hover-color: rgb(255, 142, 0); + --codeblock-ignore-color: rgba(255, 142, 0, .6); + --warning-border-color: #ff8e00; + --type-link-color: #ad378a; + --trait-link-color: #6e4fc9; + --assoc-item-link-color: #3873ad; + --function-link-color: #ad7c37; + --macro-link-color: #068000; + --keyword-link-color: #3873ad; + --mod-link-color: #3873ad; + --link-color: #3873ad; + --sidebar-link-color: #356da4; + --sidebar-current-link-background-color: #fff; + --search-result-link-focus-background-color: #ccc; + --search-result-border-color: #aaa3; + --search-color: #000; + --search-error-code-background-color: #d0cccc; + --search-results-alias-color: #000; + --search-results-grey-color: #999; + --search-tab-title-count-color: #888; + --search-tab-button-not-selected-border-top-color: #e6e6e6; + --search-tab-button-not-selected-background: #e6e6e6; + --search-tab-button-selected-border-top-color: #0089ff; + --search-tab-button-selected-background: #fff; + --stab-background-color: #fff5d6; + --stab-code-color: #000; + --code-highlight-kw-color: #8959a8; + --code-highlight-kw-2-color: #4271ae; + --code-highlight-lifetime-color: #b76514; + --code-highlight-prelude-color: #4271ae; + --code-highlight-prelude-val-color: #c82829; + --code-highlight-number-color: #718c00; + --code-highlight-string-color: #718c00; + --code-highlight-literal-color: #c82829; + --code-highlight-attribute-color: #c82829; + --code-highlight-self-color: #c82829; + --code-highlight-macro-color: #3e999f; + --code-highlight-question-mark-color: #ff9011; + --code-highlight-comment-color: #8e908c; + --code-highlight-doc-comment-color: #4d4d4c; + --src-line-numbers-span-color: #c67e2d; + --src-line-number-highlighted-background-color: #fdffd3; + --test-arrow-color: #f5f5f5; + --test-arrow-background-color: rgba(78, 139, 202, 0.2); + --test-arrow-hover-color: #f5f5f5; + --test-arrow-hover-background-color: rgb(78, 139, 202); + --target-background-color: #fdffd3; + --target-border-color: #ad7c37; + --kbd-color: #000; + --kbd-background: #fafbfc; + --kbd-box-shadow-color: #c6cbd1; + --rust-logo-filter: initial; + /* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */ + --crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg) + brightness(114%) contrast(76%); + --crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) + brightness(96%) contrast(93%); + --crate-search-hover-border: #717171; + --src-sidebar-background-selected: #fff; + --src-sidebar-background-hover: #e0e0e0; + --table-alt-row-background-color: #f5f5f5; + --codeblock-link-background: #eee; + --scrape-example-toggle-line-background: #ccc; + --scrape-example-toggle-line-hover-background: #999; + --scrape-example-code-line-highlight: #fcffd6; + --scrape-example-code-line-highlight-focus: #f6fdb0; + --scrape-example-help-border-color: #555; + --scrape-example-help-color: #333; + --scrape-example-help-hover-border-color: #000; + --scrape-example-help-hover-color: #000; + --scrape-example-code-wrapper-background-start: rgba(255, 255, 255, 1); + --scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0); +} diff --git a/tests/rustdoc-gui/src/theme_css/lib.rs b/tests/rustdoc-gui/src/theme_css/lib.rs new file mode 100644 index 00000000000..e9f3265fa6b --- /dev/null +++ b/tests/rustdoc-gui/src/theme_css/lib.rs @@ -0,0 +1,2 @@ +// compile-flags: --theme custom-theme.css +//! <div class="custom-text">custom text</div> diff --git a/tests/rustdoc-gui/theme-change.goml b/tests/rustdoc-gui/theme-change.goml index e4b031b735e..fdaf9d6289a 100644 --- a/tests/rustdoc-gui/theme-change.goml +++ b/tests/rustdoc-gui/theme-change.goml @@ -65,3 +65,36 @@ assert-local-storage: { "rustdoc-theme": "light" } reload: wait-for: "#settings" assert: "#preferred-light-theme.setting-line.hidden" + +// Ensures that the custom theme feature is working as expected. +go-to: "file://" + |DOC_PATH| + "/theme_css/index.html" +set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"} +reload: + +store-value: (background_light, "white") +store-value: (background_dark, "#353535") +store-value: (background_ayu, "#0f1419") +store-value: (background_custom_theme, "red") + +click: "#settings-menu" +wait-for: "#theme-ayu" +click: "#theme-ayu" +// should be the ayu theme so let's check the color. +wait-for-css: ("body", { "background-color": |background_ayu| }) +assert-local-storage: { "rustdoc-theme": "ayu" } +assert-text: (".custom-text", "custom text") +click: "#theme-light" +// should be the light theme so let's check the color. +wait-for-css: ("body", { "background-color": |background_light| }) +assert-local-storage: { "rustdoc-theme": "light" } +assert-text: (".custom-text", "custom text") +click: "#theme-dark" +// Should be the dark theme so let's check the color. +wait-for-css: ("body", { "background-color": |background_dark| }) +assert-local-storage: { "rustdoc-theme": "dark" } +assert-text: (".custom-text", "custom text") +click: "#theme-custom-theme" +// Should be the custom theme so let's check the color. +wait-for-css: ("body", { "background-color": |background_custom_theme| }) +assert-local-storage: { "rustdoc-theme": "custom-theme" } +assert-text: (".custom-text", "custom text") diff --git a/tests/rustdoc-js-std/full-path-function.js b/tests/rustdoc-js-std/full-path-function.js new file mode 100644 index 00000000000..ac157b3aadf --- /dev/null +++ b/tests/rustdoc-js-std/full-path-function.js @@ -0,0 +1,7 @@ +const EXPECTED = { + 'query': 'vec::vec -> usize', + 'others': [ + { 'path': 'std::vec::Vec', 'name': 'len' }, + { 'path': 'std::vec::Vec', 'name': 'capacity' }, + ], +}; diff --git a/tests/rustdoc-js/full-path-function.js b/tests/rustdoc-js/full-path-function.js new file mode 100644 index 00000000000..48be51b156f --- /dev/null +++ b/tests/rustdoc-js/full-path-function.js @@ -0,0 +1,43 @@ +// exact-check + +const EXPECTED = [ + { + 'query': 'sac -> usize', + 'others': [ + { 'path': 'full_path_function::b::Sac', 'name': 'bar' }, + { 'path': 'full_path_function::b::Sac', 'name': 'len' }, + { 'path': 'full_path_function::sac::Sac', 'name': 'len' }, + ], + }, + { + 'query': 'b::sac -> usize', + 'others': [ + { 'path': 'full_path_function::b::Sac', 'name': 'bar' }, + { 'path': 'full_path_function::b::Sac', 'name': 'len' }, + ], + }, + { + 'query': 'b::sac -> u32', + 'others': [ + { 'path': 'full_path_function::b::Sac', 'name': 'bar2' }, + ], + }, + { + 'query': 'string::string -> u32', + 'others': [ + { 'path': 'full_path_function::b::Sac', 'name': 'string' }, + ], + }, + { + 'query': 'alloc::string::string -> u32', + 'others': [ + { 'path': 'full_path_function::b::Sac', 'name': 'string' }, + ], + }, + { + 'query': 'alloc::string -> u32', + 'others': [ + { 'path': 'full_path_function::b::Sac', 'name': 'string' }, + ], + }, +]; diff --git a/tests/rustdoc-js/full-path-function.rs b/tests/rustdoc-js/full-path-function.rs new file mode 100644 index 00000000000..8dcc3f2b69d --- /dev/null +++ b/tests/rustdoc-js/full-path-function.rs @@ -0,0 +1,17 @@ +pub mod sac { + pub struct Sac; + + impl Sac { + pub fn len(&self) -> usize { 0 } + } +} + +pub mod b { + pub struct Sac; + impl Sac { + pub fn len(&self) -> usize { 0 } + pub fn bar(&self, w: u32) -> usize { 0 } + pub fn bar2(&self, w: u32) -> u32 { 0 } + pub fn string(w: String) -> u32 { 0 } + } +} diff --git a/tests/rustdoc-ui/custom_code_classes_in_docs-warning.rs b/tests/rustdoc-ui/custom_code_classes_in_docs-warning.rs new file mode 100644 index 00000000000..dd8759b7e37 --- /dev/null +++ b/tests/rustdoc-ui/custom_code_classes_in_docs-warning.rs @@ -0,0 +1,85 @@ +// This test ensures that warnings are working as expected for "custom_code_classes_in_docs" +// feature. + +#![feature(custom_code_classes_in_docs)] +#![deny(warnings)] +#![feature(no_core)] +#![no_core] + +/// ```{. } +/// main; +/// ``` +//~^^^ ERROR unexpected ` ` character after `.` +pub fn foo() {} + +/// ```{class= a} +/// main; +/// ``` +//~^^^ ERROR unexpected ` ` character after `=` +pub fn foo2() {} + +/// ```{#id} +/// main; +/// ``` +//~^^^ ERROR unexpected character `#` +pub fn foo3() {} + +/// ```{{ +/// main; +/// ``` +//~^^^ ERROR unexpected character `{` +pub fn foo4() {} + +/// ```} +/// main; +/// ``` +//~^^^ ERROR unexpected character `}` +pub fn foo5() {} + +/// ```) +/// main; +/// ``` +//~^^^ ERROR unexpected character `)` +pub fn foo6() {} + +/// ```{class=} +/// main; +/// ``` +//~^^^ ERROR unexpected `}` character after `=` +pub fn foo7() {} + +/// ```( +/// main; +/// ``` +//~^^^ ERROR unclosed comment: missing `)` at the end +pub fn foo8() {} + +/// ```{class=one=two} +/// main; +/// ``` +//~^^^ ERROR unexpected `=` +pub fn foo9() {} + +/// ```{.one.two} +/// main; +/// ``` +//~^^^ ERROR unexpected `.` character +pub fn foo10() {} + +/// ```{class=.one} +/// main; +/// ``` +//~^^^ ERROR unexpected `.` character after `=` +pub fn foo11() {} + +/// ```{class=one.two} +/// main; +/// ``` +//~^^^ ERROR unexpected `.` character +pub fn foo12() {} + +/// ```{(comment)} +/// main; +/// ``` +//~^^^ ERROR unexpected character `(` +pub fn foo13() {} diff --git a/tests/rustdoc-ui/custom_code_classes_in_docs-warning.stderr b/tests/rustdoc-ui/custom_code_classes_in_docs-warning.stderr new file mode 100644 index 00000000000..3e0dc4b2f7a --- /dev/null +++ b/tests/rustdoc-ui/custom_code_classes_in_docs-warning.stderr @@ -0,0 +1,113 @@ +error: unexpected ` ` character after `.` + --> $DIR/custom_code_classes_in_docs-warning.rs:9:1 + | +LL | / /// ```{. } +LL | | /// main; +LL | | /// ``` + | |_______^ + | +note: the lint level is defined here + --> $DIR/custom_code_classes_in_docs-warning.rs:5:9 + | +LL | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(warnings)]` + +error: unexpected ` ` character after `=` + --> $DIR/custom_code_classes_in_docs-warning.rs:15:1 + | +LL | / /// ```{class= a} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected character `#` + --> $DIR/custom_code_classes_in_docs-warning.rs:21:1 + | +LL | / /// ```{#id} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected character `{` + --> $DIR/custom_code_classes_in_docs-warning.rs:27:1 + | +LL | / /// ```{{ +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected character `}` + --> $DIR/custom_code_classes_in_docs-warning.rs:33:1 + | +LL | / /// ```} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected character `)` + --> $DIR/custom_code_classes_in_docs-warning.rs:39:1 + | +LL | / /// ```) +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected `}` character after `=` + --> $DIR/custom_code_classes_in_docs-warning.rs:45:1 + | +LL | / /// ```{class=} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unclosed comment: missing `)` at the end + --> $DIR/custom_code_classes_in_docs-warning.rs:51:1 + | +LL | / /// ```( +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected `=` character + --> $DIR/custom_code_classes_in_docs-warning.rs:57:1 + | +LL | / /// ```{class=one=two} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected `.` character + --> $DIR/custom_code_classes_in_docs-warning.rs:63:1 + | +LL | / /// ```{.one.two} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected `.` character after `=` + --> $DIR/custom_code_classes_in_docs-warning.rs:69:1 + | +LL | / /// ```{class=.one} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected `.` character + --> $DIR/custom_code_classes_in_docs-warning.rs:75:1 + | +LL | / /// ```{class=one.two} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: unexpected character `(` + --> $DIR/custom_code_classes_in_docs-warning.rs:81:1 + | +LL | / /// ```{(comment)} +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: aborting due to 13 previous errors + diff --git a/tests/rustdoc-ui/custom_code_classes_in_docs-warning3.rs b/tests/rustdoc-ui/custom_code_classes_in_docs-warning3.rs new file mode 100644 index 00000000000..57d9038cb0c --- /dev/null +++ b/tests/rustdoc-ui/custom_code_classes_in_docs-warning3.rs @@ -0,0 +1,17 @@ +// This test ensures that warnings are working as expected for "custom_code_classes_in_docs" +// feature. + +#![feature(custom_code_classes_in_docs)] +#![deny(warnings)] +#![feature(no_core)] +#![no_core] + +/// ```{class="} +/// main; +/// ``` +//~^^^ ERROR unclosed quote string +//~| ERROR unclosed quote string +/// ```" +/// main; +/// ``` +pub fn foo() {} diff --git a/tests/rustdoc-ui/custom_code_classes_in_docs-warning3.stderr b/tests/rustdoc-ui/custom_code_classes_in_docs-warning3.stderr new file mode 100644 index 00000000000..4f2ded78c29 --- /dev/null +++ b/tests/rustdoc-ui/custom_code_classes_in_docs-warning3.stderr @@ -0,0 +1,33 @@ +error: unclosed quote string `"` + --> $DIR/custom_code_classes_in_docs-warning3.rs:9:1 + | +LL | / /// ```{class="} +LL | | /// main; +LL | | /// ``` +LL | | +... | +LL | | /// main; +LL | | /// ``` + | |_______^ + | +note: the lint level is defined here + --> $DIR/custom_code_classes_in_docs-warning3.rs:5:9 + | +LL | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(warnings)]` + +error: unclosed quote string `"` + --> $DIR/custom_code_classes_in_docs-warning3.rs:9:1 + | +LL | / /// ```{class="} +LL | | /// main; +LL | | /// ``` +LL | | +... | +LL | | /// main; +LL | | /// ``` + | |_______^ + +error: aborting due to 2 previous errors + diff --git a/tests/rustdoc-ui/feature-gate-custom_code_classes_in_docs.rs b/tests/rustdoc-ui/feature-gate-custom_code_classes_in_docs.rs new file mode 100644 index 00000000000..8aa13b2d5d1 --- /dev/null +++ b/tests/rustdoc-ui/feature-gate-custom_code_classes_in_docs.rs @@ -0,0 +1,5 @@ +/// ```{class=language-c} +/// int main(void) { return 0; } +/// ``` +//~^^^ ERROR 1:1: 3:8: custom classes in code blocks are unstable [E0658] +pub struct Bar; diff --git a/tests/rustdoc-ui/feature-gate-custom_code_classes_in_docs.stderr b/tests/rustdoc-ui/feature-gate-custom_code_classes_in_docs.stderr new file mode 100644 index 00000000000..c41ebfc8073 --- /dev/null +++ b/tests/rustdoc-ui/feature-gate-custom_code_classes_in_docs.stderr @@ -0,0 +1,15 @@ +error[E0658]: custom classes in code blocks are unstable + --> $DIR/feature-gate-custom_code_classes_in_docs.rs:1:1 + | +LL | / /// ```{class=language-c} +LL | | /// int main(void) { return 0; } +LL | | /// ``` + | |_______^ + | + = note: see issue #79483 <https://github.com/rust-lang/rust/issues/79483> for more information + = help: add `#![feature(custom_code_classes_in_docs)]` to the crate attributes to enable + = note: found these custom classes: class=language-c + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/rustdoc-ui/issues/issue-91713.stdout b/tests/rustdoc-ui/issues/issue-91713.stdout index 16783524363..bbea7e5c212 100644 --- a/tests/rustdoc-ui/issues/issue-91713.stdout +++ b/tests/rustdoc-ui/issues/issue-91713.stdout @@ -1,4 +1,5 @@ Available passes for running rustdoc: +check-custom-code-classes - check for custom code classes without the feature-gate enabled check_doc_test_visibility - run various visibility-related lints on doctests strip-hidden - strips all `#[doc(hidden)]` items from the output strip-private - strips all private items from a crate which cannot be seen externally, implies strip-priv-imports @@ -10,6 +11,7 @@ calculate-doc-coverage - counts the number of items with and without documentati run-lints - runs some of rustdoc's lints Default passes for rustdoc: +check-custom-code-classes collect-trait-impls check_doc_test_visibility strip-hidden (when not --document-hidden-items) diff --git a/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs b/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs new file mode 100644 index 00000000000..f4e020b3b95 --- /dev/null +++ b/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs @@ -0,0 +1,5 @@ +pub struct InlineOne<A> { + pub inline: A +} + +pub type InlineU64 = InlineOne<u64>; diff --git a/tests/rustdoc/const-generics/const-generic-defaults.rs b/tests/rustdoc/const-generics/const-generic-defaults.rs index f781c6a62f2..7a0a794112d 100644 --- a/tests/rustdoc/const-generics/const-generic-defaults.rs +++ b/tests/rustdoc/const-generics/const-generic-defaults.rs @@ -1,5 +1,5 @@ #![crate_name = "foo"] // @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \ -// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);' +// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(' pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T); diff --git a/tests/rustdoc/const-generics/const-generics-docs.rs b/tests/rustdoc/const-generics/const-generics-docs.rs index 828486a41d4..70a9518f05b 100644 --- a/tests/rustdoc/const-generics/const-generics-docs.rs +++ b/tests/rustdoc/const-generics/const-generics-docs.rs @@ -33,7 +33,7 @@ impl<const N: usize> Trait<N> for [u8; N] {} // @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \ // 'pub struct Foo<const N: usize> where u8: Trait<N>' pub struct Foo<const N: usize> where u8: Trait<N>; -// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>(_)' +// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>(' pub struct Bar<T, const N: usize>([T; N]); // @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl<const M: usize> Foo<M>where u8: Trait<M>' @@ -92,7 +92,7 @@ macro_rules! define_me { } // @has foo/struct.Foz.html '//pre[@class="rust item-decl"]' \ -// 'pub struct Foz<const N: usize>(_);' +// 'pub struct Foz<const N: usize>(/* private fields */);' define_me!(Foz<N>); trait Q { diff --git a/tests/rustdoc/custom_code_classes.rs b/tests/rustdoc/custom_code_classes.rs new file mode 100644 index 00000000000..cd20d8b7d6c --- /dev/null +++ b/tests/rustdoc/custom_code_classes.rs @@ -0,0 +1,28 @@ +// Test for `custom_code_classes_in_docs` feature. + +#![feature(custom_code_classes_in_docs)] +#![crate_name = "foo"] +#![feature(no_core)] +#![no_core] + +// @has 'foo/struct.Bar.html' +// @has - '//*[@id="main-content"]//pre[@class="language-whatever hoho-c"]' 'main;' +// @has - '//*[@id="main-content"]//pre[@class="language-whatever2 haha-c"]' 'main;' +// @has - '//*[@id="main-content"]//pre[@class="language-whatever4 huhu-c"]' 'main;' + +/// ```{class=hoho-c},whatever +/// main; +/// ``` +/// +/// Testing multiple kinds of orders. +/// +/// ```whatever2 {class=haha-c} +/// main; +/// ``` +/// +/// Testing with multiple "unknown". Only the first should be used. +/// +/// ```whatever4,{.huhu-c} whatever5 +/// main; +/// ``` +pub struct Bar; diff --git a/tests/rustdoc/inline_cross/auxiliary/dyn_trait.rs b/tests/rustdoc/inline_cross/auxiliary/dyn_trait.rs index 644d0699e9d..df88530071b 100644 --- a/tests/rustdoc/inline_cross/auxiliary/dyn_trait.rs +++ b/tests/rustdoc/inline_cross/auxiliary/dyn_trait.rs @@ -65,3 +65,22 @@ pub trait HigherRankedBoundTrait1<'e> where for<'l> Self: 'e + 'l {} pub trait AmbiguousBoundTrait<'a, 'b>: 'a + 'b {} pub struct AmbiguousBoundWrapper<'a, 'b, T: ?Sized + 'a + 'b>(&'a T, &'b T); + +// Trait objects inside of another trait object, a trait bound or an associated type. + +pub trait Inner {} +pub trait Outer<T: ?Sized> {} +pub trait Base { + type Type<T: ?Sized>; +} +impl Base for () { + type Type<T: ?Sized> = (); +} + +pub type NestedTraitObjects = dyn Outer<dyn Inner>; + +pub fn apit_rpit(o: impl Outer<dyn Inner>) -> impl Outer<dyn Inner> { + o +} + +pub type AssocTy = <() as Base>::Type<dyn Inner>; diff --git a/tests/rustdoc/inline_cross/dyn_trait.rs b/tests/rustdoc/inline_cross/dyn_trait.rs index 1de01af83d1..679972f035a 100644 --- a/tests/rustdoc/inline_cross/dyn_trait.rs +++ b/tests/rustdoc/inline_cross/dyn_trait.rs @@ -128,3 +128,18 @@ pub use dyn_trait::BareAmbiguousBoundEarly1; // @has user/type.BareAmbiguousBoundStatic.html // @has - '//*[@class="rust item-decl"]//code' "dyn AmbiguousBoundTrait<'o, 'o> + 'static;" pub use dyn_trait::BareAmbiguousBoundStatic; + +// Regression test for issue #115179: + +// @has user/type.NestedTraitObjects.html +// @has - '//*[@class="rust item-decl"]//code' "dyn Outer<dyn Inner>;" +pub use dyn_trait::NestedTraitObjects; + +// @has user/fn.apit_rpit.html +// @has - '//pre[@class="rust item-decl"]' \ +// "apit_rpit(o: impl Outer<dyn Inner>) -> impl Outer<dyn Inner>" +pub use dyn_trait::apit_rpit; + +// @has user/type.AssocTy.html +// @has - '//*[@class="rust item-decl"]//code' "<() as Base>::Type<dyn Inner>" +pub use dyn_trait::AssocTy; diff --git a/tests/rustdoc/issue-32077-type-alias-impls.rs b/tests/rustdoc/issue-32077-type-alias-impls.rs new file mode 100644 index 00000000000..ac486c36ad0 --- /dev/null +++ b/tests/rustdoc/issue-32077-type-alias-impls.rs @@ -0,0 +1,66 @@ +// Regression test for <https://github.com/rust-lang/rust/issues/32077>. + +#![crate_name = "foo"] + +pub struct GenericStruct<T>(T); + +impl<T> GenericStruct<T> { + pub fn on_gen(arg: T) {} +} + +impl GenericStruct<u32> { + pub fn on_u32(arg: u32) {} +} + +pub trait Foo {} +pub trait Bar {} + +impl<T> Foo for GenericStruct<T> {} +impl Bar for GenericStruct<u32> {} + +// @has 'foo/type.TypedefStruct.html' +// We check that "Aliased type" is also present as a title in the sidebar. +// @has - '//*[@class="sidebar-elems"]//h3/a[@href="#aliased-type"]' 'Aliased type' +// We check that we have the implementation of the type alias itself. +// @has - '//*[@id="impl-TypedefStruct"]/h3' 'impl TypedefStruct' +// @has - '//*[@id="method.on_alias"]/h4' 'pub fn on_alias()' +// @has - '//*[@id="impl-GenericStruct%3CT%3E"]/h3' 'impl<T> GenericStruct<T>' +// @has - '//*[@id="method.on_gen"]/h4' 'pub fn on_gen(arg: T)' +// @has - '//*[@id="impl-Foo-for-GenericStruct%3CT%3E"]/h3' 'impl<T> Foo for GenericStruct<T>' +// This trait implementation doesn't match the type alias parameters so shouldn't appear in docs. +// @!has - '//h3' 'impl Bar for GenericStruct<u32> {}' +// Same goes for the `Deref` impl. +// @!has - '//h2' 'Methods from Deref<Target = u32>' +// @count - '//nav[@class="sidebar"]//a' 'on_alias' 1 +// @count - '//nav[@class="sidebar"]//a' 'on_gen' 1 +// @count - '//nav[@class="sidebar"]//a' 'Foo' 1 +// @!has - '//nav[@class="sidebar"]//a' 'Bar' +// @!has - '//nav[@class="sidebar"]//a' 'on_u32' +pub type TypedefStruct = GenericStruct<u8>; + +impl TypedefStruct { + pub fn on_alias() {} +} + +impl std::ops::Deref for GenericStruct<u32> { + type Target = u32; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +pub struct Wrap<T>(GenericStruct<T>); + +// @has 'foo/type.Alias.html' +// @has - '//h2' 'Methods from Deref<Target = u32>' +// @has - '//*[@id="impl-Deref-for-Wrap%3CT%3E"]/h3' 'impl<T> Deref for Wrap<T>' +pub type Alias = Wrap<u32>; + +impl<T> std::ops::Deref for Wrap<T> { + type Target = GenericStruct<T>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} diff --git a/tests/rustdoc/issue-88600.rs b/tests/rustdoc/issue-88600.rs index db0d102b741..f89af472f6e 100644 --- a/tests/rustdoc/issue-88600.rs +++ b/tests/rustdoc/issue-88600.rs @@ -8,10 +8,10 @@ pub struct S; // @has issue_88600/enum.FooEnum.html pub enum FooEnum { - // @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)' + // @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(/* private fields */)' // @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0 HiddenTupleItem(#[doc(hidden)] H), - // @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)' + // @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(/* private fields */)' // @count - '//*[@id="variant.MultipleHidden.field.0"]' 0 // @count - '//*[@id="variant.MultipleHidden.field.1"]' 0 MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H), diff --git a/tests/rustdoc/private-fields-tuple-struct.rs b/tests/rustdoc/private-fields-tuple-struct.rs new file mode 100644 index 00000000000..c6989dd8cdf --- /dev/null +++ b/tests/rustdoc/private-fields-tuple-struct.rs @@ -0,0 +1,15 @@ +// This test checks the diplay of "/* private fields */" sentence in tuple structs. +#![crate_name = "foo"] + +// @has 'foo/struct.A.html' '//*[@class="rust item-decl"]/code' 'pub struct A(pub u8, _);' +pub struct A(pub u8, u8); +// @has 'foo/struct.B.html' '//*[@class="rust item-decl"]/code' 'pub struct B(_, pub u8);' +pub struct B(u8, pub u8); +// @has 'foo/struct.C.html' '//*[@class="rust item-decl"]/code' 'pub struct C(_, pub u8, _);' +pub struct C(u8, pub u8, u8); +// @has 'foo/struct.D.html' '//*[@class="rust item-decl"]/code' 'pub struct D(pub u8, _, pub u8);' +pub struct D(pub u8, u8, pub u8); +// @has 'foo/struct.E.html' '//*[@class="rust item-decl"]/code' 'pub struct E(/* private fields */);' +pub struct E(u8); +// @has 'foo/struct.F.html' '//*[@class="rust item-decl"]/code' 'pub struct F(/* private fields */);' +pub struct F(u8, u8); diff --git a/tests/rustdoc/show-const-contents.rs b/tests/rustdoc/show-const-contents.rs index 69e742ee747..91df03adbbc 100644 --- a/tests/rustdoc/show-const-contents.rs +++ b/tests/rustdoc/show-const-contents.rs @@ -47,7 +47,7 @@ pub struct MyTypeWithStr(&'static str); // @!hasraw show_const_contents/constant.MY_TYPE_WITH_STR.html '; //' pub const MY_TYPE_WITH_STR: MyTypeWithStr = MyTypeWithStr("show this"); -// @hasraw show_const_contents/constant.PI.html '= 3.14159265358979323846264338327950288f32;' +// @hasraw show_const_contents/constant.PI.html '= 3.14159265358979323846264338327950288_f32;' // @hasraw show_const_contents/constant.PI.html '; // 3.14159274f32' pub use std::f32::consts::PI; diff --git a/tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs b/tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs new file mode 100644 index 00000000000..ff84352d716 --- /dev/null +++ b/tests/rustdoc/typedef-inner-variants-lazy_type_alias.rs @@ -0,0 +1,34 @@ +#![crate_name = "inner_types_lazy"] + +#![feature(lazy_type_alias)] +#![allow(incomplete_features)] + +// @has 'inner_types_lazy/struct.Pair.html' +pub struct Pair<A, B> { + pub first: A, + pub second: B, +} + +// @has 'inner_types_lazy/type.ReversedTypesPair.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @count - '//span[@class="where fmt-newline"]' 0 +pub type ReversedTypesPair<Q, R> = Pair<R, Q>; + +// @has 'inner_types_lazy/type.ReadWrite.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @count - '//span[@class="where fmt-newline"]' 2 +pub type ReadWrite<R, W> = Pair<R, W> +where + R: std::io::Read, + W: std::io::Write; + +// @has 'inner_types_lazy/type.VecPair.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @count - '//span[@class="where fmt-newline"]' 0 +pub type VecPair<U, V> = Pair<Vec<U>, Vec<V>>; diff --git a/tests/rustdoc/typedef-inner-variants.rs b/tests/rustdoc/typedef-inner-variants.rs new file mode 100644 index 00000000000..b734714fd64 --- /dev/null +++ b/tests/rustdoc/typedef-inner-variants.rs @@ -0,0 +1,119 @@ +// This test checks different combinations of structs, enums, and unions +// for the "Show Aliased Type" feature on type definition. + +#![crate_name = "inner_variants"] + +// aux-build:cross_crate_generic_typedef.rs +extern crate cross_crate_generic_typedef; + +pub struct Adt; +pub struct Ty; +pub struct TyCtxt; + +pub trait Interner { + type Adt; + type Ty; +} + +impl Interner for TyCtxt { + type Adt = Adt; + type Ty = Ty; +} + +// @has 'inner_variants/type.AliasTy.html' +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 0 +pub type AliasTy = Ty; + +// @has 'inner_variants/enum.IrTyKind.html' +pub enum IrTyKind<A, I: Interner> { + /// Doc comment for AdtKind + AdtKind(I::Adt), + /// and another one for TyKind + TyKind(I::Adt, <I as Interner>::Ty), + // no comment + StructKind { a: A, }, + #[doc(hidden)] + Unspecified, +} + +// @has 'inner_variants/type.NearlyTyKind.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 1 +// @count - '//*[@id="fields"]' 0 +pub type NearlyTyKind<A> = IrTyKind<A, TyCtxt>; + +// @has 'inner_variants/type.TyKind.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 1 +// @count - '//*[@id="fields"]' 0 +// @count - '//*[@class="variant"]' 3 +// @matches - '//pre[@class="rust item-decl"]//code' "enum TyKind" +// @has - '//pre[@class="rust item-decl"]//code/a[1]' "Adt" +// @has - '//pre[@class="rust item-decl"]//code/a[2]' "Adt" +// @has - '//pre[@class="rust item-decl"]//code/a[3]' "Ty" +// @has - '//pre[@class="rust item-decl"]//code/a[4]' "i64" +pub type TyKind = IrTyKind<i64, TyCtxt>; + +// @has 'inner_variants/union.OneOr.html' +pub union OneOr<A: Copy> { + pub one: i64, + pub or: A, +} + +// @has 'inner_variants/type.OneOrF64.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @count - '//*[@class="structfield small-section-header"]' 2 +// @matches - '//pre[@class="rust item-decl"]//code' "union OneOrF64" +pub type OneOrF64 = OneOr<f64>; + +// @has 'inner_variants/struct.One.html' +pub struct One<T> { + pub val: T, + #[doc(hidden)] + pub __hidden: T, + __private: T, +} + +// @has 'inner_variants/type.OneU64.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @count - '//*[@class="structfield small-section-header"]' 1 +// @matches - '//pre[@class="rust item-decl"]//code' "struct OneU64" +// @matches - '//pre[@class="rust item-decl"]//code' "pub val" +pub type OneU64 = One<u64>; + +// @has 'inner_variants/struct.OnceA.html' +pub struct OnceA<'a, A> { + pub a: &'a A, +} + +// @has 'inner_variants/type.Once.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @matches - '//pre[@class="rust item-decl"]//code' "struct Once<'a>" +// @matches - '//pre[@class="rust item-decl"]//code' "&'a" +pub type Once<'a> = OnceA<'a, i64>; + +// @has 'inner_variants/struct.HighlyGenericStruct.html' +pub struct HighlyGenericStruct<A, B, C, D> { + pub z: (A, B, C, D) +} + +// @has 'inner_variants/type.HighlyGenericAABB.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +// @matches - '//pre[@class="rust item-decl"]//code' "struct HighlyGenericAABB<A, B>" +// @matches - '//pre[@class="rust item-decl"]//code' "pub z" +pub type HighlyGenericAABB<A, B> = HighlyGenericStruct<A, A, B, B>; + +// @has 'inner_variants/type.InlineU64.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 0 +// @count - '//*[@id="fields"]' 1 +pub use cross_crate_generic_typedef::InlineU64; diff --git a/tests/rustdoc/where.SWhere_Simd_item-decl.html b/tests/rustdoc/where.SWhere_Simd_item-decl.html index 3e72ba2b74f..46708b9e4e9 100644 --- a/tests/rustdoc/where.SWhere_Simd_item-decl.html +++ b/tests/rustdoc/where.SWhere_Simd_item-decl.html @@ -1,3 +1,3 @@ -<pre class="rust item-decl"><code>pub struct Simd<T>(_) +<pre class="rust item-decl"><code>pub struct Simd<T>(/* private fields */) <span class="where">where T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre> diff --git a/tests/rustdoc/where.alpha_trait_decl.html b/tests/rustdoc/where.alpha_trait_decl.html index a7700055c9a..0c0b2d1ceca 100644 --- a/tests/rustdoc/where.alpha_trait_decl.html +++ b/tests/rustdoc/where.alpha_trait_decl.html @@ -1,3 +1,3 @@ -<code>pub struct Alpha<A>(_) +<code>pub struct Alpha<A>(/* private fields */) <span class="where">where A: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code> \ No newline at end of file diff --git a/tests/rustdoc/where.rs b/tests/rustdoc/where.rs index 2aa9c8b5461..aea02c14039 100644 --- a/tests/rustdoc/where.rs +++ b/tests/rustdoc/where.rs @@ -4,7 +4,7 @@ use std::io::Lines; pub trait MyTrait { fn dummy(&self) { } } -// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>(_) where A: MyTrait" +// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>(/* private fields */) where A: MyTrait" // @snapshot alpha_trait_decl - '//*[@class="rust item-decl"]/code' pub struct Alpha<A>(A) where A: MyTrait; // @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B>where B: MyTrait" diff --git a/tests/ui-fulldeps/plugin/lint-group-plugin-deny-cmdline.stderr b/tests/ui-fulldeps/plugin/lint-group-plugin-deny-cmdline.stderr index 20486d596d9..6e17bbde021 100644 --- a/tests/ui-fulldeps/plugin/lint-group-plugin-deny-cmdline.stderr +++ b/tests/ui-fulldeps/plugin/lint-group-plugin-deny-cmdline.stderr @@ -13,6 +13,7 @@ LL | fn lintme() { } | ^^^^^^^^^^^^^^^ | = note: `-D test-lint` implied by `-D lint-me` + = help: to override `-D lint-me` add `#[allow(test_lint)]` error: item is named 'pleaselintme' --> $DIR/lint-group-plugin-deny-cmdline.rs:12:1 @@ -21,6 +22,7 @@ LL | fn pleaselintme() { } | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D please-lint` implied by `-D lint-me` + = help: to override `-D lint-me` add `#[allow(please_lint)]` error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui-fulldeps/plugin/lint-tool-cmdline-allow.stderr b/tests/ui-fulldeps/plugin/lint-tool-cmdline-allow.stderr index b060e3a3e38..0e661795999 100644 --- a/tests/ui-fulldeps/plugin/lint-tool-cmdline-allow.stderr +++ b/tests/ui-fulldeps/plugin/lint-tool-cmdline-allow.stderr @@ -1,9 +1,12 @@ -warning: lint name `test_lint` is deprecated and does not have an effect anymore. Use: clippy::test_lint +warning: lint name `test_lint` is deprecated and may not have an effect in the future. | + = help: change it to clippy::test_lint = note: requested on the command line with `-A test_lint` + = note: `#[warn(renamed_and_removed_lints)]` on by default -warning: lint name `test_lint` is deprecated and does not have an effect anymore. Use: clippy::test_lint +warning: lint name `test_lint` is deprecated and may not have an effect in the future. | + = help: change it to clippy::test_lint = note: requested on the command line with `-A test_lint` warning: item is named 'lintme' @@ -22,8 +25,9 @@ LL | #![plugin(lint_tool_test)] | = note: `#[warn(deprecated)]` on by default -warning: lint name `test_lint` is deprecated and does not have an effect anymore. Use: clippy::test_lint +warning: lint name `test_lint` is deprecated and may not have an effect in the future. | + = help: change it to clippy::test_lint = note: requested on the command line with `-A test_lint` warning: 5 warnings emitted diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index ae375dfab90..541be7ebbc0 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -80,14 +80,20 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { let seg = PathSegment::from_ident(Ident::from_str("x")); iter_exprs(depth - 1, &mut |e| { g(ExprKind::MethodCall(Box::new(MethodCall { - seg: seg.clone(), receiver: e, args: thin_vec![make_x()], span: DUMMY_SP - })) - )}); + seg: seg.clone(), + receiver: e, + args: thin_vec![make_x()], + span: DUMMY_SP, + }))) + }); iter_exprs(depth - 1, &mut |e| { g(ExprKind::MethodCall(Box::new(MethodCall { - seg: seg.clone(), receiver: make_x(), args: thin_vec![e], span: DUMMY_SP - })) - )}); + seg: seg.clone(), + receiver: make_x(), + args: thin_vec![e], + span: DUMMY_SP, + }))) + }); } 2..=7 => { let op = Spanned { @@ -174,7 +180,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { 18 => { let pat = P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None }); - iter_exprs(depth - 1, &mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP))) + iter_exprs(depth - 1, &mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, None))) } _ => panic!("bad counter value in iter_exprs"), } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr index 8c876213ae0..e014fc8c693 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr @@ -23,7 +23,7 @@ LL | arg: NotIntoDiagnosticArg, | = help: normalized in stderr note: required by a bound in `Diagnostic::set_arg` - --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:960:5 + --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:968:5 error: aborting due to 2 previous errors diff --git a/tests/ui-fulldeps/stable-mir/compilation-result.rs b/tests/ui-fulldeps/stable-mir/compilation-result.rs new file mode 100644 index 00000000000..23a9e2a064c --- /dev/null +++ b/tests/ui-fulldeps/stable-mir/compilation-result.rs @@ -0,0 +1,77 @@ +// run-pass +// Test StableMIR behavior when different results are given + +// ignore-stage1 +// ignore-cross-compile +// ignore-remote +// edition: 2021 + +#![feature(rustc_private)] +#![feature(assert_matches)] + +extern crate rustc_middle; +extern crate rustc_smir; + +use rustc_middle::ty::TyCtxt; +use rustc_smir::{rustc_internal, stable_mir}; +use std::io::Write; +use std::ops::ControlFlow; + +/// This test will generate and analyze a dummy crate using the stable mir. +/// For that, it will first write the dummy crate into a file. +/// Then it will create a `StableMir` using custom arguments and then +/// it will run the compiler. +fn main() { + let path = "input_compilation_result_test.rs"; + generate_input(&path).unwrap(); + let args = vec!["rustc".to_string(), path.to_string()]; + test_continue(args.clone()); + test_break(args.clone()); + test_failed(args.clone()); + test_skipped(args); +} + +fn test_continue(args: Vec<String>) { + let continue_fn = |_: TyCtxt| ControlFlow::Continue::<(), bool>(true); + let result = rustc_internal::StableMir::new(args, continue_fn).run(); + assert_eq!(result, Ok(true)); +} + +fn test_break(args: Vec<String>) { + let continue_fn = |_: TyCtxt| ControlFlow::Break::<bool, i32>(false); + let result = rustc_internal::StableMir::new(args, continue_fn).run(); + assert_eq!(result, Err(stable_mir::CompilerError::Interrupted(false))); +} + +fn test_skipped(mut args: Vec<String>) { + args.push("--version".to_string()); + let unreach_fn = |_: TyCtxt| -> ControlFlow<()> { unreachable!() }; + let result = rustc_internal::StableMir::new(args, unreach_fn).run(); + assert_eq!(result, Err(stable_mir::CompilerError::Skipped)); +} + +fn test_failed(mut args: Vec<String>) { + args.push("--cfg=broken".to_string()); + let unreach_fn = |_: TyCtxt| -> ControlFlow<()> { unreachable!() }; + let result = rustc_internal::StableMir::new(args, unreach_fn).run(); + assert_eq!(result, Err(stable_mir::CompilerError::CompilationFailed)); +} + +fn generate_input(path: &str) -> std::io::Result<()> { + let mut file = std::fs::File::create(path)?; + write!( + file, + r#" + // This should trigger a compilation failure when enabled. + #[cfg(broken)] + mod broken_mod {{ + fn call_invalid() {{ + invalid_fn(); + }} + }} + + fn main() {{}} + "# + )?; + Ok(()) +} diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs index f55d7d599f1..a11720c4b55 100644 --- a/tests/ui-fulldeps/stable-mir/crate-info.rs +++ b/tests/ui-fulldeps/stable-mir/crate-info.rs @@ -8,27 +8,26 @@ #![feature(rustc_private)] #![feature(assert_matches)] +#![feature(control_flow_enum)] -extern crate rustc_driver; extern crate rustc_hir; -extern crate rustc_interface; extern crate rustc_middle; -extern crate rustc_session; extern crate rustc_smir; -use rustc_driver::{Callbacks, Compilation, RunCompiler}; use rustc_hir::def::DefKind; -use rustc_interface::{interface, Queries}; use rustc_middle::ty::TyCtxt; -use rustc_session::EarlyErrorHandler; -use rustc_smir::{rustc_internal, stable_mir}; +use rustc_smir::{ + rustc_internal, + stable_mir::{self, fold::Foldable}, +}; use std::assert_matches::assert_matches; use std::io::Write; +use std::ops::ControlFlow; const CRATE_NAME: &str = "input"; /// This function uses the Stable MIR APIs to get information about the test crate. -fn test_stable_mir(tcx: TyCtxt<'_>) { +fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> { // Get the local crate using stable_mir API. let local = stable_mir::local_crate(); assert_eq!(&local.name, CRATE_NAME); @@ -114,6 +113,52 @@ fn test_stable_mir(tcx: TyCtxt<'_>) { stable_mir::mir::Terminator::Assert { .. } => {} other => panic!("{other:?}"), } + + let monomorphic = get_item(tcx, &items, (DefKind::Fn, "monomorphic")).unwrap(); + for block in monomorphic.body().blocks { + match &block.terminator { + stable_mir::mir::Terminator::Call { func, .. } => match func { + stable_mir::mir::Operand::Constant(c) => match &c.literal.literal { + stable_mir::ty::ConstantKind::Allocated(alloc) => { + assert!(alloc.bytes.is_empty()); + match c.literal.ty.kind() { + stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::FnDef( + def, + mut args, + )) => { + let func = def.body(); + match func.locals[1] + .fold(&mut args) + .continue_value() + .unwrap() + .kind() + { + stable_mir::ty::TyKind::RigidTy( + stable_mir::ty::RigidTy::Uint(_), + ) => {} + stable_mir::ty::TyKind::RigidTy( + stable_mir::ty::RigidTy::Tuple(_), + ) => {} + other => panic!("{other:?}"), + } + } + other => panic!("{other:?}"), + } + } + other => panic!("{other:?}"), + }, + other => panic!("{other:?}"), + }, + stable_mir::mir::Terminator::Return => {} + other => panic!("{other:?}"), + } + } + + let foo_const = get_item(tcx, &items, (DefKind::Const, "FOO")).unwrap(); + // Ensure we don't panic trying to get the body of a constant. + foo_const.body(); + + ControlFlow::Continue(()) } // Use internal API to find a function in a crate. @@ -130,8 +175,8 @@ fn get_item<'a>( /// This test will generate and analyze a dummy crate using the stable mir. /// For that, it will first write the dummy crate into a file. -/// It will invoke the compiler using a custom Callback implementation, which will -/// invoke Stable MIR APIs after the compiler has finished its analysis. +/// Then it will create a `StableMir` using custom arguments and then +/// it will run the compiler. fn main() { let path = "input.rs"; generate_input(&path).unwrap(); @@ -142,29 +187,7 @@ fn main() { CRATE_NAME.to_string(), path.to_string(), ]; - rustc_driver::catch_fatal_errors(|| { - RunCompiler::new(&args, &mut SMirCalls {}).run().unwrap(); - }) - .unwrap(); -} - -struct SMirCalls {} - -impl Callbacks for SMirCalls { - /// Called after analysis. Return value instructs the compiler whether to - /// continue the compilation afterwards (defaults to `Compilation::Continue`) - fn after_analysis<'tcx>( - &mut self, - _handler: &EarlyErrorHandler, - _compiler: &interface::Compiler, - queries: &'tcx Queries<'tcx>, - ) -> Compilation { - queries.global_ctxt().unwrap().enter(|tcx| { - rustc_smir::rustc_internal::run(tcx, || test_stable_mir(tcx)); - }); - // No need to keep going. - Compilation::Stop - } + rustc_internal::StableMir::new(args, test_stable_mir).run().unwrap(); } fn generate_input(path: &str) -> std::io::Result<()> { @@ -172,6 +195,18 @@ fn generate_input(path: &str) -> std::io::Result<()> { write!( file, r#" + pub const FOO: u32 = 1 + 2; + + fn generic<T, const U: usize>(t: T) -> [(); U] {{ + _ = t; + [(); U] + }} + + pub fn monomorphic() {{ + generic::<(), 5>(()); + generic::<u32, 0>(45); + }} + mod foo {{ pub fn bar(i: i32) -> i64 {{ i as i64 diff --git a/tests/ui/abi/compatibility.rs b/tests/ui/abi/compatibility.rs new file mode 100644 index 00000000000..b3e75bb8233 --- /dev/null +++ b/tests/ui/abi/compatibility.rs @@ -0,0 +1,194 @@ +// check-pass +#![feature(rustc_attrs, unsized_fn_params, transparent_unions)] +#![allow(unused, improper_ctypes_definitions, internal_features)] +use std::marker::PhantomData; +use std::mem::ManuallyDrop; +use std::num::NonZeroI32; +use std::ptr::NonNull; + +// FIXME: a bunch of targets are broken in various ways. +// Hence there are `cfg` throughout this test to disable parts of it on those targets. +// sparc64: https://github.com/rust-lang/rust/issues/115336 +// mips64: https://github.com/rust-lang/rust/issues/115404 +// riscv64: https://github.com/rust-lang/rust/issues/115481 +// loongarch64: https://github.com/rust-lang/rust/issues/115509 + +macro_rules! assert_abi_compatible { + ($name:ident, $t1:ty, $t2:ty) => { + mod $name { + use super::*; + // Declaring a `type` doesn't even check well-formedness, so we also declare a function. + fn check_wf(_x: $t1, _y: $t2) {} + // Test argument and return value, `Rust` and `C` ABIs. + #[rustc_abi(assert_eq)] + type TestRust = (fn($t1) -> $t1, fn($t2) -> $t2); + #[rustc_abi(assert_eq)] + type TestC = (extern "C" fn($t1) -> $t1, extern "C" fn($t2) -> $t2); + } + }; +} + +#[derive(Copy, Clone)] +struct Zst; + +#[repr(C)] +struct ReprC1<T: ?Sized>(T); +#[repr(C)] +struct ReprC2Int<T>(i32, T); +#[repr(C)] +struct ReprC2Float<T>(f32, T); +#[repr(C)] +struct ReprC4<T>(T, Vec<i32>, Zst, T); +#[repr(C)] +struct ReprC4Mixed<T>(T, f32, i32, T); +#[repr(C)] +enum ReprCEnum<T> { + Variant1, + Variant2(T), +} +#[repr(C)] +union ReprCUnion<T> { + nothing: (), + something: ManuallyDrop<T>, +} + +macro_rules! test_abi_compatible { + ($name:ident, $t1:ty, $t2:ty) => { + mod $name { + use super::*; + assert_abi_compatible!(plain, $t1, $t2); + // We also do some tests with differences in fields of `repr(C)` types. + assert_abi_compatible!(repr_c_1, ReprC1<$t1>, ReprC1<$t2>); + assert_abi_compatible!(repr_c_2_int, ReprC2Int<$t1>, ReprC2Int<$t2>); + assert_abi_compatible!(repr_c_2_float, ReprC2Float<$t1>, ReprC2Float<$t2>); + assert_abi_compatible!(repr_c_4, ReprC4<$t1>, ReprC4<$t2>); + assert_abi_compatible!(repr_c_4mixed, ReprC4Mixed<$t1>, ReprC4Mixed<$t2>); + assert_abi_compatible!(repr_c_enum, ReprCEnum<$t1>, ReprCEnum<$t2>); + assert_abi_compatible!(repr_c_union, ReprCUnion<$t1>, ReprCUnion<$t2>); + } + }; +} + +// Compatibility of pointers is probably de-facto guaranteed, +// but that does not seem to be documented. +test_abi_compatible!(ptr_mut, *const i32, *mut i32); +test_abi_compatible!(ptr_pointee, *const i32, *const Vec<i32>); +test_abi_compatible!(ref_mut, &i32, &mut i32); +test_abi_compatible!(ref_ptr, &i32, *const i32); +test_abi_compatible!(box_ptr, Box<i32>, *const i32); +test_abi_compatible!(nonnull_ptr, NonNull<i32>, *const i32); +test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32); + +// Some further guarantees we will likely (have to) make. +test_abi_compatible!(zst_unit, Zst, ()); +#[cfg(not(any(target_arch = "sparc64")))] +test_abi_compatible!(zst_array, Zst, [u8; 0]); +test_abi_compatible!(nonzero_int, NonZeroI32, i32); + +// `DispatchFromDyn` relies on ABI compatibility. +// This is interesting since these types are not `repr(transparent)`. +test_abi_compatible!(rc, std::rc::Rc<i32>, *mut i32); +test_abi_compatible!(arc, std::sync::Arc<i32>, *mut i32); + +// `repr(transparent)` compatibility. +#[repr(transparent)] +struct Wrapper1<T: ?Sized>(T); +#[repr(transparent)] +struct Wrapper2<T: ?Sized>((), Zst, T); +#[repr(transparent)] +struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>); +#[repr(transparent)] +union WrapperUnion<T> { + nothing: (), + something: ManuallyDrop<T>, +} + +macro_rules! test_transparent { + ($name:ident, $t:ty) => { + mod $name { + use super::*; + test_abi_compatible!(wrap1, $t, Wrapper1<$t>); + test_abi_compatible!(wrap2, $t, Wrapper2<$t>); + test_abi_compatible!(wrap3, $t, Wrapper3<$t>); + #[cfg(not(any(target_arch = "riscv64", target_arch = "loongarch64")))] + test_abi_compatible!(wrap4, $t, WrapperUnion<$t>); + } + }; +} + +test_transparent!(simple, i32); +test_transparent!(reference, &'static i32); +test_transparent!(zst, Zst); +test_transparent!(unit, ()); +test_transparent!(enum_, Option<i32>); +test_transparent!(enum_niched, Option<&'static i32>); +#[cfg(not(any(target_arch = "mips64", target_arch = "sparc64")))] +mod tuples { + use super::*; + // mixing in some floats since they often get special treatment + test_transparent!(pair, (i32, f32)); + // chosen to fit into 64bit + test_transparent!(triple, (i8, i16, f32)); + // Pure-float types that are not ScalarPair seem to be tricky. + test_transparent!(triple_f32, (f32, f32, f32)); + test_transparent!(triple_f64, (f64, f64, f64)); + // and also something that's larger than 2 pointers + test_transparent!(tuple, (i32, f32, i64, f64)); +} +// Some targets have special rules for arrays. +#[cfg(not(any(target_arch = "mips64", target_arch = "sparc64")))] +mod arrays { + use super::*; + test_transparent!(empty_array, [u32; 0]); + test_transparent!(empty_1zst_array, [u8; 0]); + test_transparent!(small_array, [i32; 2]); // chosen to fit into 64bit + test_transparent!(large_array, [i32; 16]); +} + +// Some tests with unsized types (not all wrappers are compatible with that). +macro_rules! test_transparent_unsized { + ($name:ident, $t:ty) => { + mod $name { + use super::*; + assert_abi_compatible!(wrap1, $t, Wrapper1<$t>); + assert_abi_compatible!(wrap1_reprc, ReprC1<$t>, ReprC1<Wrapper1<$t>>); + assert_abi_compatible!(wrap2, $t, Wrapper2<$t>); + assert_abi_compatible!(wrap2_reprc, ReprC1<$t>, ReprC1<Wrapper2<$t>>); + } + }; +} + +#[cfg(not(any(target_arch = "mips64", target_arch = "sparc64")))] +mod unsized_ { + use super::*; + test_transparent_unsized!(str_, str); + test_transparent_unsized!(slice, [u8]); + test_transparent_unsized!(dyn_trait, dyn std::any::Any); +} + +// RFC 3391 <https://rust-lang.github.io/rfcs/3391-result_ffi_guarantees.html>. +macro_rules! test_nonnull { + ($name:ident, $t:ty) => { + mod $name { + use super::*; + test_abi_compatible!(option, Option<$t>, $t); + test_abi_compatible!(result_err_unit, Result<$t, ()>, $t); + test_abi_compatible!(result_ok_unit, Result<(), $t>, $t); + test_abi_compatible!(result_err_zst, Result<$t, Zst>, $t); + test_abi_compatible!(result_ok_zst, Result<Zst, $t>, $t); + test_abi_compatible!(result_err_arr, Result<$t, [i8; 0]>, $t); + test_abi_compatible!(result_ok_arr, Result<[i8; 0], $t>, $t); + } + } +} + +test_nonnull!(ref_, &i32); +test_nonnull!(mut_, &mut i32); +test_nonnull!(ref_unsized, &[i32]); +test_nonnull!(mut_unsized, &mut [i32]); +test_nonnull!(fn_, fn()); +test_nonnull!(nonnull, NonNull<i32>); +test_nonnull!(nonnull_unsized, NonNull<dyn std::fmt::Debug>); +test_nonnull!(non_zero, NonZeroI32); + +fn main() {} diff --git a/tests/ui/abi/debug.rs b/tests/ui/abi/debug.rs index 13464be275e..77715ee4023 100644 --- a/tests/ui/abi/debug.rs +++ b/tests/ui/abi/debug.rs @@ -9,15 +9,45 @@ #![feature(rustc_attrs)] #![crate_type = "lib"] +struct S(u16); + #[rustc_abi(debug)] fn test(_x: u8) -> bool { true } //~ ERROR: fn_abi +#[rustc_abi(debug)] +type TestFnPtr = fn(bool) -> u8; //~ ERROR: fn_abi #[rustc_abi(debug)] fn test_generic<T>(_x: *const T) { } //~ ERROR: fn_abi -struct S(u16); +#[rustc_abi(debug)] +const C: () = (); //~ ERROR: can only be applied to + +impl S { + #[rustc_abi(debug)] + const C: () = (); //~ ERROR: can only be applied to +} + impl S { #[rustc_abi(debug)] fn assoc_test(&self) { } //~ ERROR: fn_abi } + +#[rustc_abi(assert_eq)] +type TestAbiEq = (fn(bool), fn(bool)); + +#[rustc_abi(assert_eq)] +type TestAbiNe = (fn(u8), fn(u32)); //~ ERROR: ABIs are not compatible + +#[rustc_abi(assert_eq)] +type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32])); //~ ERROR: ABIs are not compatible + +#[rustc_abi(assert_eq)] +type TestAbiNeFloat = (fn(f32), fn(u32)); //~ ERROR: ABIs are not compatible + +// Sign matters on some targets (such as s390x), so let's make sure we never accept this. +#[rustc_abi(assert_eq)] +type TestAbiNeSign = (fn(i32), fn(u32)); //~ ERROR: ABIs are not compatible + +#[rustc_abi(assert_eq)] +type TestAbiEqNonsense = (fn((str, str)), fn((str, str))); //~ ERROR: cannot be known at compilation time diff --git a/tests/ui/abi/debug.stderr b/tests/ui/abi/debug.stderr index 4f4ee3de4b8..00fc7d1ece1 100644 --- a/tests/ui/abi/debug.stderr +++ b/tests/ui/abi/debug.stderr @@ -1,4 +1,4 @@ -error: fn_abi_of_instance(test) = FnAbi { +error: fn_abi_of(test) = FnAbi { args: [ ArgAbi { layout: TyAndLayout { @@ -87,12 +87,106 @@ error: fn_abi_of_instance(test) = FnAbi { conv: Rust, can_unwind: $SOME_BOOL, } - --> $DIR/debug.rs:13:1 + --> $DIR/debug.rs:15:1 | LL | fn test(_x: u8) -> bool { true } | ^^^^^^^^^^^^^^^^^^^^^^^ -error: fn_abi_of_instance(test_generic) = FnAbi { +error: fn_abi_of(TestFnPtr) = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: bool, + layout: Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + ), + fields: Primitive, + largest_niche: Some( + Niche { + offset: Size(0 bytes), + value: Int( + I8, + false, + ), + valid_range: 0..=1, + }, + ), + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: Zext, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: u8, + layout: Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=255, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + --> $DIR/debug.rs:18:1 + | +LL | type TestFnPtr = fn(bool) -> u8; + | ^^^^^^^^^^^^^^ + +error: fn_abi_of(test_generic) = FnAbi { args: [ ArgAbi { layout: TyAndLayout { @@ -163,12 +257,616 @@ error: fn_abi_of_instance(test_generic) = FnAbi { conv: Rust, can_unwind: $SOME_BOOL, } - --> $DIR/debug.rs:17:1 + --> $DIR/debug.rs:21:1 | LL | fn test_generic<T>(_x: *const T) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: fn_abi_of_instance(assoc_test) = FnAbi { +error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions + --> $DIR/debug.rs:24:1 + | +LL | const C: () = (); + | ^^^^^^^^^^^ + +error: ABIs are not compatible + left ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: u8, + layout: Layout { + size: Size(1 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I8, + false, + ), + valid_range: 0..=255, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + right ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: u32, + layout: Layout { + size: $SOME_SIZE, + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I32, + false, + ), + valid_range: $FULL, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + --> $DIR/debug.rs:40:1 + | +LL | type TestAbiNe = (fn(u8), fn(u32)); + | ^^^^^^^^^^^^^^ + +error: ABIs are not compatible + left ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: [u8; 32], + layout: Layout { + size: Size(32 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Array { + stride: Size(1 bytes), + count: 32, + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Indirect { + attrs: ArgAttributes { + regular: NoAlias | NoCapture | NonNull | NoUndef, + arg_ext: None, + pointee_size: Size(32 bytes), + pointee_align: Some( + Align(1 bytes), + ), + }, + meta_attrs: None, + on_stack: false, + }, + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + right ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: [u32; 32], + layout: Layout { + size: Size(128 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Array { + stride: Size(4 bytes), + count: 32, + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Indirect { + attrs: ArgAttributes { + regular: NoAlias | NoCapture | NonNull | NoUndef, + arg_ext: None, + pointee_size: Size(128 bytes), + pointee_align: Some( + Align(4 bytes), + ), + }, + meta_attrs: None, + on_stack: false, + }, + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + --> $DIR/debug.rs:43:1 + | +LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32])); + | ^^^^^^^^^^^^^^^^^^^^ + +error: ABIs are not compatible + left ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: f32, + layout: Layout { + size: $SOME_SIZE, + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: F32, + valid_range: $FULL, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + right ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: u32, + layout: Layout { + size: $SOME_SIZE, + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I32, + false, + ), + valid_range: $FULL, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + --> $DIR/debug.rs:46:1 + | +LL | type TestAbiNeFloat = (fn(f32), fn(u32)); + | ^^^^^^^^^^^^^^^^^^^ + +error: ABIs are not compatible + left ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: i32, + layout: Layout { + size: $SOME_SIZE, + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I32, + true, + ), + valid_range: $FULL, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + right ABI = FnAbi { + args: [ + ArgAbi { + layout: TyAndLayout { + ty: u32, + layout: Layout { + size: $SOME_SIZE, + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Scalar( + Initialized { + value: Int( + I32, + false, + ), + valid_range: $FULL, + }, + ), + fields: Primitive, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Direct( + ArgAttributes { + regular: NoUndef, + arg_ext: None, + pointee_size: Size(0 bytes), + pointee_align: None, + }, + ), + }, + ], + ret: ArgAbi { + layout: TyAndLayout { + ty: (), + layout: Layout { + size: Size(0 bytes), + align: AbiAndPrefAlign { + abi: $SOME_ALIGN, + pref: $SOME_ALIGN, + }, + abi: Aggregate { + sized: true, + }, + fields: Arbitrary { + offsets: [], + memory_index: [], + }, + largest_niche: None, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: $SOME_ALIGN, + }, + }, + mode: Ignore, + }, + c_variadic: false, + fixed_count: 1, + conv: Rust, + can_unwind: $SOME_BOOL, + } + --> $DIR/debug.rs:50:1 + | +LL | type TestAbiNeSign = (fn(i32), fn(u32)); + | ^^^^^^^^^^^^^^^^^^ + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/debug.rs:53:46 + | +LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str))); + | ^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: only the last element of a tuple may have a dynamically sized type + +error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions + --> $DIR/debug.rs:28:5 + | +LL | const C: () = (); + | ^^^^^^^^^^^ + +error: fn_abi_of(assoc_test) = FnAbi { args: [ ArgAbi { layout: TyAndLayout { @@ -251,10 +949,11 @@ error: fn_abi_of_instance(assoc_test) = FnAbi { conv: Rust, can_unwind: $SOME_BOOL, } - --> $DIR/debug.rs:22:5 + --> $DIR/debug.rs:33:5 | LL | fn assoc_test(&self) { } | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 11 previous errors +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/argument-suggestions/two-mismatch-notes.stderr b/tests/ui/argument-suggestions/two-mismatch-notes.stderr index 38cf23ddc38..70cc60255c7 100644 --- a/tests/ui/argument-suggestions/two-mismatch-notes.stderr +++ b/tests/ui/argument-suggestions/two-mismatch-notes.stderr @@ -11,7 +11,6 @@ LL | foo(f, w); | ^ = note: expected fn pointer `fn(i32)` found fn item `fn(u32) {f}` - = note: when the arguments and return types match, functions can be coerced to function pointers note: expected `Wrapper<i32>`, found `Wrapper<isize>` --> $DIR/two-mismatch-notes.rs:10:12 | diff --git a/tests/ui/associated-consts/associated-const-array-len.stderr b/tests/ui/associated-consts/associated-const-array-len.stderr index 0e0dec35b53..e3db45810fd 100644 --- a/tests/ui/associated-consts/associated-const-array-len.stderr +++ b/tests/ui/associated-consts/associated-const-array-len.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied | LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2]; | ^^^ the trait `Foo` is not implemented for `i32` + | +help: this trait has no implementations, consider adding one + --> $DIR/associated-const-array-len.rs:1:1 + | +LL | trait Foo { + | ^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/associated-consts/double-elided.rs b/tests/ui/associated-consts/double-elided.rs new file mode 100644 index 00000000000..fd0317781bb --- /dev/null +++ b/tests/ui/associated-consts/double-elided.rs @@ -0,0 +1,12 @@ +struct S; + +impl S { + const C: &&str = &""; + //~^ WARN `&` without an explicit lifetime name cannot be used here + //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + //~| WARN `&` without an explicit lifetime name cannot be used here + //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + //~| ERROR in type `&&str`, reference has a longer lifetime than the data it references +} + +fn main() {} diff --git a/tests/ui/associated-consts/double-elided.stderr b/tests/ui/associated-consts/double-elided.stderr new file mode 100644 index 00000000000..ba4e6a23e27 --- /dev/null +++ b/tests/ui/associated-consts/double-elided.stderr @@ -0,0 +1,47 @@ +warning: `&` without an explicit lifetime name cannot be used here + --> $DIR/double-elided.rs:4:14 + | +LL | const C: &&str = &""; + | ^ + | + = 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 #115010 <https://github.com/rust-lang/rust/issues/115010> + = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default +help: use the `'static` lifetime + | +LL | const C: &'static &str = &""; + | +++++++ + +warning: `&` without an explicit lifetime name cannot be used here + --> $DIR/double-elided.rs:4:15 + | +LL | const C: &&str = &""; + | ^ + | + = 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 #115010 <https://github.com/rust-lang/rust/issues/115010> +help: use the `'static` lifetime + | +LL | const C: &&'static str = &""; + | +++++++ + +error[E0491]: in type `&&str`, reference has a longer lifetime than the data it references + --> $DIR/double-elided.rs:4:5 + | +LL | const C: &&str = &""; + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: the pointer is valid for the anonymous lifetime as defined here + --> $DIR/double-elided.rs:4:14 + | +LL | const C: &&str = &""; + | ^ +note: but the referenced data is only valid for the anonymous lifetime as defined here + --> $DIR/double-elided.rs:4:14 + | +LL | const C: &&str = &""; + | ^ + +error: aborting due to previous error; 2 warnings emitted + +For more information about this error, try `rustc --explain E0491`. diff --git a/tests/ui/associated-consts/issue-105330.stderr b/tests/ui/associated-consts/issue-105330.stderr index e9fe3a5e514..927422fa8dc 100644 --- a/tests/ui/associated-consts/issue-105330.stderr +++ b/tests/ui/associated-consts/issue-105330.stderr @@ -51,6 +51,11 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied LL | foo::<Demo>()(); | ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-105330.rs:1:1 + | +LL | pub trait TraitWAssocConst { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `foo` --> $DIR/issue-105330.rs:11:11 | @@ -87,6 +92,11 @@ error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied LL | foo::<Demo>(); | ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-105330.rs:1:1 + | +LL | pub trait TraitWAssocConst { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `foo` --> $DIR/issue-105330.rs:11:11 | diff --git a/tests/ui/associated-inherent-types/private-in-public.rs b/tests/ui/associated-inherent-types/private-in-public.rs index e9e189f95c9..7797a2a16a5 100644 --- a/tests/ui/associated-inherent-types/private-in-public.rs +++ b/tests/ui/associated-inherent-types/private-in-public.rs @@ -1,26 +1,15 @@ +// check-pass + #![feature(inherent_associated_types)] -#![feature(type_privacy_lints)] #![allow(incomplete_features)] #![crate_type = "lib"] -#![deny(private_in_public)] -#![warn(private_interfaces)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. pub type PubAlias0 = PubTy::PrivAssocTy; -//~^ ERROR private associated type `PubTy::PrivAssocTy` in public interface (error E0446) -//~| WARNING this was previously accepted -//~| WARNING associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0` +//~^ WARNING associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0` pub type PubAlias1 = PrivTy::PubAssocTy; -//~^ ERROR private type `PrivTy` in public interface (error E0446) -//~| WARNING this was previously accepted -//~| WARNING type `PrivTy` is more private than the item `PubAlias1` +//~^ WARNING type `PrivTy` is more private than the item `PubAlias1` pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>; -//~^ ERROR private type `PrivTy` in public interface (error E0446) -//~| WARNING this was previously accepted -//~| WARNING type `PrivTy` is more private than the item `PubAlias2` +//~^ WARNING type `PrivTy` is more private than the item `PubAlias2` pub struct PubTy; impl PubTy { diff --git a/tests/ui/associated-inherent-types/private-in-public.stderr b/tests/ui/associated-inherent-types/private-in-public.stderr index 65d187c1bcd..076bbd78ae9 100644 --- a/tests/ui/associated-inherent-types/private-in-public.stderr +++ b/tests/ui/associated-inherent-types/private-in-public.stderr @@ -1,75 +1,39 @@ -error: private associated type `PubTy::PrivAssocTy` in public interface (error E0446) - --> $DIR/private-in-public.rs:12:1 - | -LL | pub type PubAlias0 = PubTy::PrivAssocTy; - | ^^^^^^^^^^^^^^^^^^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> -note: the lint level is defined here - --> $DIR/private-in-public.rs:5:9 - | -LL | #![deny(private_in_public)] - | ^^^^^^^^^^^^^^^^^ - warning: associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0` - --> $DIR/private-in-public.rs:12:1 + --> $DIR/private-in-public.rs:7:1 | LL | pub type PubAlias0 = PubTy::PrivAssocTy; | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias0` is reachable at visibility `pub` | note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public.rs:27:5 + --> $DIR/private-in-public.rs:16:5 | LL | type PrivAssocTy = (); | ^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/private-in-public.rs:6:9 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^ - -error: private type `PrivTy` in public interface (error E0446) - --> $DIR/private-in-public.rs:16:1 - | -LL | pub type PubAlias1 = PrivTy::PubAssocTy; - | ^^^^^^^^^^^^^^^^^^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> + = note: `#[warn(private_interfaces)]` on by default warning: type `PrivTy` is more private than the item `PubAlias1` - --> $DIR/private-in-public.rs:16:1 + --> $DIR/private-in-public.rs:9:1 | LL | pub type PubAlias1 = PrivTy::PubAssocTy; | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias1` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public.rs:31:1 + --> $DIR/private-in-public.rs:20:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ -error: private type `PrivTy` in public interface (error E0446) - --> $DIR/private-in-public.rs:20:1 - | -LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>; - | ^^^^^^^^^^^^^^^^^^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - warning: type `PrivTy` is more private than the item `PubAlias2` - --> $DIR/private-in-public.rs:20:1 + --> $DIR/private-in-public.rs:11:1 | LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>; | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias2` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public.rs:31:1 + --> $DIR/private-in-public.rs:20:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ -error: aborting due to 3 previous errors; 3 warnings emitted +warning: 3 warnings emitted diff --git a/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr b/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr index c2da4f57696..edce1045e24 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr @@ -13,12 +13,12 @@ error: future cannot be sent between threads safely LL | is_send(foo::<T>()); | ^^^^^^^^^^ future returned by `foo` is not `Send` | - = help: within `impl Future<Output = Result<(), ()>>`, the trait `Send` is not implemented for `impl Future<Output = Result<(), ()>>` + = help: within `impl Future<Output = Result<(), ()>>`, the trait `Send` is not implemented for `impl Future<Output = Result<(), ()>> { <T as Foo>::method() }` note: future is not `Send` as it awaits another future which is not `Send` --> $DIR/basic.rs:13:5 | LL | T::method().await?; - | ^^^^^^^^^^^ await occurs here on type `impl Future<Output = Result<(), ()>>`, which is not `Send` + | ^^^^^^^^^^^ await occurs here on type `impl Future<Output = Result<(), ()>> { <T as Foo>::method() }`, which is not `Send` note: required by a bound in `is_send` --> $DIR/basic.rs:17:20 | diff --git a/tests/ui/associated-type-bounds/suggest-removing-impl.rs b/tests/ui/associated-type-bounds/suggest-removing-impl.rs new file mode 100644 index 00000000000..242cd85727d --- /dev/null +++ b/tests/ui/associated-type-bounds/suggest-removing-impl.rs @@ -0,0 +1,14 @@ +trait Tr { + type Assoc: impl Sized; + //~^ ERROR expected a trait, found type + //~| HELP use the trait bounds directly + + fn fn_with_generics<T>() + where + T: impl Sized + //~^ ERROR expected a trait, found type + //~| HELP use the trait bounds directly + {} +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/suggest-removing-impl.stderr b/tests/ui/associated-type-bounds/suggest-removing-impl.stderr new file mode 100644 index 00000000000..875b2db6deb --- /dev/null +++ b/tests/ui/associated-type-bounds/suggest-removing-impl.stderr @@ -0,0 +1,26 @@ +error: expected a trait, found type + --> $DIR/suggest-removing-impl.rs:2:17 + | +LL | type Assoc: impl Sized; + | ^^^^^^^^^^ + | +help: use the trait bounds directly + | +LL - type Assoc: impl Sized; +LL + type Assoc: Sized; + | + +error: expected a trait, found type + --> $DIR/suggest-removing-impl.rs:8:12 + | +LL | T: impl Sized + | ^^^^^^^^^^ + | +help: use the trait bounds directly + | +LL - T: impl Sized +LL + T: Sized + | + +error: aborting due to 2 previous errors + diff --git a/tests/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.stderr b/tests/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.stderr index 8c3463a2832..fbc4ccd4cf4 100644 --- a/tests/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.stderr +++ b/tests/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): Add<A>` is not satisfied | LL | r = r + a; | ^ the trait `Add<A>` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/associated-types-ICE-when-projecting-out-of-err.rs:15:1 + | +LL | trait Add<RHS=Self> { + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr b/tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr index bd3ee2abd2c..b3f2e16ba0d 100644 --- a/tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr +++ b/tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(T, U): Get` is not satisfied | LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {} | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)` + | +help: this trait has no implementations, consider adding one + --> $DIR/associated-types-no-suitable-supertrait.rs:12:1 + | +LL | trait Get { + | ^^^^^^^^^ error[E0277]: the trait bound `Self: Get` is not satisfied --> $DIR/associated-types-no-suitable-supertrait.rs:17:40 diff --git a/tests/ui/associated-types/defaults-suitability.stderr b/tests/ui/associated-types/defaults-suitability.stderr index 4b2094691f8..0a8ad0f89e2 100644 --- a/tests/ui/associated-types/defaults-suitability.stderr +++ b/tests/ui/associated-types/defaults-suitability.stderr @@ -58,6 +58,11 @@ error[E0277]: the trait bound `(): Foo<Self>` is not satisfied LL | type Assoc: Foo<Self> = (); | ^^ the trait `Foo<Self>` is not implemented for `()` | +help: this trait has no implementations, consider adding one + --> $DIR/defaults-suitability.rs:27:1 + | +LL | trait Foo<T> { + | ^^^^^^^^^^^^ note: required by a bound in `Bar::Assoc` --> $DIR/defaults-suitability.rs:34:17 | diff --git a/tests/ui/associated-types/issue-23595-2.stderr b/tests/ui/associated-types/issue-23595-2.stderr index dded673f6ee..73effa9f955 100644 --- a/tests/ui/associated-types/issue-23595-2.stderr +++ b/tests/ui/associated-types/issue-23595-2.stderr @@ -2,7 +2,7 @@ error[E0220]: associated type `anything_here_kills_it` not found for `Self` --> $DIR/issue-23595-2.rs:6:22 | LL | type B = C<Self::anything_here_kills_it>; - | ^^^^^^^^^^^^^^^^^^^^^^ associated type `anything_here_kills_it` not found + | ^^^^^^^^^^^^^^^^^^^^^^ help: `Self` has the following associated type: `B` error: aborting due to previous error diff --git a/tests/ui/issues/issue-32323.rs b/tests/ui/associated-types/issue-32323.rs index 5078f5523c9..5078f5523c9 100644 --- a/tests/ui/issues/issue-32323.rs +++ b/tests/ui/associated-types/issue-32323.rs diff --git a/tests/ui/issues/issue-32323.stderr b/tests/ui/associated-types/issue-32323.stderr index 8212c607e11..8212c607e11 100644 --- a/tests/ui/issues/issue-32323.stderr +++ b/tests/ui/associated-types/issue-32323.stderr diff --git a/tests/ui/associated-types/issue-59324.stderr b/tests/ui/associated-types/issue-59324.stderr index a84b599b52b..266e22d4726 100644 --- a/tests/ui/associated-types/issue-59324.stderr +++ b/tests/ui/associated-types/issue-59324.stderr @@ -48,6 +48,12 @@ error[E0277]: the trait bound `(): Foo` is not satisfied | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-59324.rs:3:1 + | +LL | pub trait Foo: NotFoo { + | ^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bug: Foo` is not satisfied --> $DIR/issue-59324.rs:19:10 diff --git a/tests/ui/associated-types/issue-64855.stderr b/tests/ui/associated-types/issue-64855.stderr index 6ad795c1117..f1016f0e3a1 100644 --- a/tests/ui/associated-types/issue-64855.stderr +++ b/tests/ui/associated-types/issue-64855.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied | LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ; | ^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<T>` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-64855.rs:1:1 + | +LL | pub trait Foo { + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/associated-types/issue-85103-layout-debug.rs b/tests/ui/associated-types/issue-85103-layout-debug.rs new file mode 100644 index 00000000000..77c9876ffa5 --- /dev/null +++ b/tests/ui/associated-types/issue-85103-layout-debug.rs @@ -0,0 +1,9 @@ +#![feature(rustc_attrs)] + +use std::borrow::Cow; + +#[rustc_layout(debug)] +type Edges<'a, E> = Cow<'a, [E]>; +//~^ the trait bound `[E]: ToOwned` is not satisfied + +fn main() {} diff --git a/tests/ui/associated-types/issue-85103-layout-debug.stderr b/tests/ui/associated-types/issue-85103-layout-debug.stderr new file mode 100644 index 00000000000..0bdea10ba47 --- /dev/null +++ b/tests/ui/associated-types/issue-85103-layout-debug.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `[E]: ToOwned` is not satisfied + --> $DIR/issue-85103-layout-debug.rs:6:21 + | +LL | type Edges<'a, E> = Cow<'a, [E]>; + | ^^^^^^^^^^^^ the trait `ToOwned` is not implemented for `[E]` + | +note: required by a bound in `Cow` + --> $SRC_DIR/alloc/src/borrow.rs:LL:COL +help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement + | +LL | type Edges<'a, E> where [E]: ToOwned = Cow<'a, [E]>; + | ++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/associated-types/issue-85103.rs b/tests/ui/associated-types/issue-85103.rs deleted file mode 100644 index 9c6a419e9f7..00000000000 --- a/tests/ui/associated-types/issue-85103.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(rustc_attrs)] - -use std::borrow::Cow; - -#[rustc_layout(debug)] -type Edges<'a, E> = Cow<'a, [E]>; -//~^ 6:1: 6:18: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized - -fn main() {} diff --git a/tests/ui/associated-types/issue-85103.stderr b/tests/ui/associated-types/issue-85103.stderr deleted file mode 100644 index 17f7148074c..00000000000 --- a/tests/ui/associated-types/issue-85103.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized - --> $DIR/issue-85103.rs:6:1 - | -LL | type Edges<'a, E> = Cow<'a, [E]>; - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/associated-types/point-at-type-on-obligation-failure-2.stderr b/tests/ui/associated-types/point-at-type-on-obligation-failure-2.stderr index 3b4689e08cc..056d9201b4a 100644 --- a/tests/ui/associated-types/point-at-type-on-obligation-failure-2.stderr +++ b/tests/ui/associated-types/point-at-type-on-obligation-failure-2.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied LL | type Assoc = bool; | ^^^^ the trait `Bar` is not implemented for `bool` | +help: this trait has no implementations, consider adding one + --> $DIR/point-at-type-on-obligation-failure-2.rs:1:1 + | +LL | trait Bar {} + | ^^^^^^^^^ note: required by a bound in `Foo::Assoc` --> $DIR/point-at-type-on-obligation-failure-2.rs:4:17 | @@ -16,6 +21,11 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied LL | type Assoc = bool; | ^^^^ the trait `Bar` is not implemented for `bool` | +help: this trait has no implementations, consider adding one + --> $DIR/point-at-type-on-obligation-failure-2.rs:1:1 + | +LL | trait Bar {} + | ^^^^^^^^^ note: required by a bound in `Baz::Assoc` --> $DIR/point-at-type-on-obligation-failure-2.rs:13:18 | @@ -31,6 +41,11 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied LL | type Assoc = bool; | ^^^^ the trait `Bar` is not implemented for `bool` | +help: this trait has no implementations, consider adding one + --> $DIR/point-at-type-on-obligation-failure-2.rs:1:1 + | +LL | trait Bar {} + | ^^^^^^^^^ note: required by a bound in `Bat::Assoc` --> $DIR/point-at-type-on-obligation-failure-2.rs:24:27 | diff --git a/tests/ui/async-await/async-is-unwindsafe.stderr b/tests/ui/async-await/async-is-unwindsafe.stderr index 5d29325c827..c855e902ba9 100644 --- a/tests/ui/async-await/async-is-unwindsafe.stderr +++ b/tests/ui/async-await/async-is-unwindsafe.stderr @@ -15,7 +15,7 @@ LL | | }); | within this `[async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6]` | = help: within `[async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6]`, the trait `UnwindSafe` is not implemented for `&mut Context<'_>` - = note: `UnwindSafe` is implemented for `&std::task::Context<'_>`, but not for `&mut std::task::Context<'_>` + = note: `UnwindSafe` is implemented for `&Context<'_>`, but not for `&mut Context<'_>` note: future does not implement `UnwindSafe` as this value is used across an await --> $DIR/async-is-unwindsafe.rs:25:18 | diff --git a/tests/ui/async-await/in-trait/async-example-desugared-extra.rs b/tests/ui/async-await/in-trait/async-example-desugared-extra.rs index 81e1e59a362..3505690f1ec 100644 --- a/tests/ui/async-await/in-trait/async-example-desugared-extra.rs +++ b/tests/ui/async-await/in-trait/async-example-desugared-extra.rs @@ -2,14 +2,14 @@ // edition: 2021 #![feature(async_fn_in_trait)] -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] #![allow(incomplete_features)] use std::future::Future; use std::pin::Pin; use std::task::Poll; -trait MyTrait { +pub trait MyTrait { async fn foo(&self) -> i32; } @@ -27,8 +27,7 @@ impl Future for MyFuture { } impl MyTrait for i32 { - // FIXME: this should eventually require `#[refine]` to compile, because it also provides - // `Clone`. + #[expect(refining_impl_trait)] fn foo(&self) -> impl Future<Output = i32> + Clone { MyFuture(*self) } diff --git a/tests/ui/async-await/in-trait/async-example-desugared.rs b/tests/ui/async-await/in-trait/async-example-desugared.rs index fb92ec78674..0a5023176fe 100644 --- a/tests/ui/async-await/in-trait/async-example-desugared.rs +++ b/tests/ui/async-await/in-trait/async-example-desugared.rs @@ -12,7 +12,7 @@ trait MyTrait { } impl MyTrait for i32 { - fn foo(&self) -> impl Future<Output = i32> + '_ { + fn foo(&self) -> impl Future<Output = i32> { async { *self } } } diff --git a/tests/ui/async-await/large_moves.attribute.stderr b/tests/ui/async-await/large_moves.attribute.stderr index ef9fd78ffe3..1d1999462ce 100644 --- a/tests/ui/async-await/large_moves.attribute.stderr +++ b/tests/ui/async-await/large_moves.attribute.stderr @@ -1,5 +1,5 @@ error: moving 10024 bytes - --> $DIR/large_moves.rs:19:14 + --> $DIR/large_moves.rs:21:14 | LL | let z = (x, 42); | ^ value moved from here @@ -12,12 +12,28 @@ LL | #![deny(large_assignments)] | ^^^^^^^^^^^^^^^^^ error: moving 10024 bytes - --> $DIR/large_moves.rs:20:13 + --> $DIR/large_moves.rs:22:13 | LL | let a = z.0; | ^^^ value moved from here | = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` -error: aborting due to 2 previous errors +error: moving 9999 bytes + --> $DIR/large_moves.rs:27:13 + | +LL | let _ = NotBox::new([0; 9999]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 9999 bytes + --> $DIR/large_moves.rs:41:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: aborting due to 4 previous errors diff --git a/tests/ui/async-await/large_moves.option.stderr b/tests/ui/async-await/large_moves.option.stderr index ef9fd78ffe3..1d1999462ce 100644 --- a/tests/ui/async-await/large_moves.option.stderr +++ b/tests/ui/async-await/large_moves.option.stderr @@ -1,5 +1,5 @@ error: moving 10024 bytes - --> $DIR/large_moves.rs:19:14 + --> $DIR/large_moves.rs:21:14 | LL | let z = (x, 42); | ^ value moved from here @@ -12,12 +12,28 @@ LL | #![deny(large_assignments)] | ^^^^^^^^^^^^^^^^^ error: moving 10024 bytes - --> $DIR/large_moves.rs:20:13 + --> $DIR/large_moves.rs:22:13 | LL | let a = z.0; | ^^^ value moved from here | = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` -error: aborting due to 2 previous errors +error: moving 9999 bytes + --> $DIR/large_moves.rs:27:13 + | +LL | let _ = NotBox::new([0; 9999]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 9999 bytes + --> $DIR/large_moves.rs:41:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: aborting due to 4 previous errors diff --git a/tests/ui/async-await/large_moves.rs b/tests/ui/async-await/large_moves.rs index faf6c66c612..62b12104694 100644 --- a/tests/ui/async-await/large_moves.rs +++ b/tests/ui/async-await/large_moves.rs @@ -9,6 +9,8 @@ // edition:2018 // compile-flags: -Zmir-opt-level=0 +use std::{sync::Arc, rc::Rc}; + fn main() { let x = async { let y = [0; 9999]; @@ -19,8 +21,24 @@ fn main() { let z = (x, 42); //~ ERROR large_assignments let a = z.0; //~ ERROR large_assignments let b = z.1; + let _ = Arc::new([0; 9999]); // OK! + let _ = Box::new([0; 9999]); // OK! + let _ = Rc::new([0; 9999]); // OK! + let _ = NotBox::new([0; 9999]); //~ ERROR large_assignments } async fn thing(y: &[u8]) { dbg!(y); } + +struct NotBox { + data: [u8; 9999], +} + +impl NotBox { + fn new(data: [u8; 9999]) -> Self { + Self { + data, //~ ERROR large_assignments + } + } +} diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr new file mode 100644 index 00000000000..3b63ec45804 --- /dev/null +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.current.stderr @@ -0,0 +1,27 @@ +warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:8: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[E0277]: `impl Future<Output = ()> { <_ as Foo>::bar() }` cannot be sent between threads safely + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:23:11 + | +LL | build(Bar); + | ----- ^^^ `impl Future<Output = ()> { <_ as Foo>::bar() }` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `for<'a> Send` is not implemented for `impl Future<Output = ()> { <_ as Foo>::bar() }` +note: required by a bound in `build` + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:20:39 + | +LL | fn build<T>(_: T) where T: Foo<bar(): Send> {} + | ^^^^ required by this bound in `build` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr new file mode 100644 index 00000000000..6fab7178767 --- /dev/null +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.next.stderr @@ -0,0 +1,11 @@ +warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/normalizing-self-auto-trait-issue-109924.rs:8: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 + +warning: 1 warning emitted + 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 new file mode 100644 index 00000000000..b2cd9707db9 --- /dev/null +++ b/tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs @@ -0,0 +1,24 @@ +// revisions: current next +//[current] known-bug: #109924 +//[next] check-pass +//[next] compile-flags: -Ztrait-solver=next +// edition:2021 + +#![feature(async_fn_in_trait)] +#![feature(return_type_notation)] +//[next]~^ WARN the feature `return_type_notation` is incomplete + +trait Foo { + async fn bar(&self); +} + +struct Bar; +impl Foo for Bar { + async fn bar(&self) {} +} + +fn build<T>(_: T) where T: Foo<bar(): Send> {} + +fn main() { + build(Bar); +} diff --git a/tests/ui/attributes/issue-115264-expr-field.rs b/tests/ui/attributes/issue-115264-expr-field.rs new file mode 100644 index 00000000000..f53ac4aee66 --- /dev/null +++ b/tests/ui/attributes/issue-115264-expr-field.rs @@ -0,0 +1,17 @@ +// Regression test for issue 115264 +// Tests that retrieving the ident of the X::foo field +// in main() does not cause an ICE + +// check-pass + +#[allow(dead_code)] +struct X { + foo: i32, +} + +fn main() { + let _ = X { + #[doc(alias = "StructItem")] + foo: 123, + }; +} diff --git a/tests/ui/attributes/issue-115264-pat-field.rs b/tests/ui/attributes/issue-115264-pat-field.rs new file mode 100644 index 00000000000..8c6bbe16726 --- /dev/null +++ b/tests/ui/attributes/issue-115264-pat-field.rs @@ -0,0 +1,19 @@ +// Regression test for issue 115264 +// Tests that retrieving the ident of 'foo' variable in +// the pattern inside main() does not cause an ICE + +// check-pass + +struct X { + foo: i32, +} + +#[allow(unused_variables)] +fn main() { + let X { + #[doc(alias = "StructItem")] + foo + } = X { + foo: 123 + }; +} diff --git a/tests/ui/borrowck/issue-114374-invalid-help-fmt-args.rs b/tests/ui/borrowck/issue-114374-invalid-help-fmt-args.rs new file mode 100644 index 00000000000..4a6c2f9ed06 --- /dev/null +++ b/tests/ui/borrowck/issue-114374-invalid-help-fmt-args.rs @@ -0,0 +1,16 @@ +#![allow(dead_code)] + +fn bar<'a>(_: std::fmt::Arguments<'a>) {} +fn main() { + let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3); + //~^ ERROR temporary value dropped while borrowed + + bar(x); + + let foo = format_args!("{}", "hi"); + //~^ ERROR temporary value dropped while borrowed + bar(foo); + + let foo = format_args!("hi"); // no placeholder in arguments, so no error + bar(foo); +} diff --git a/tests/ui/borrowck/issue-114374-invalid-help-fmt-args.stderr b/tests/ui/borrowck/issue-114374-invalid-help-fmt-args.stderr new file mode 100644 index 00000000000..8221505b100 --- /dev/null +++ b/tests/ui/borrowck/issue-114374-invalid-help-fmt-args.stderr @@ -0,0 +1,33 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/issue-114374-invalid-help-fmt-args.rs:5:13 + | +LL | let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement + | | + | creates a temporary value which is freed while still in use +... +LL | bar(x); + | - borrow later used here + | + = note: the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used + = note: to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html> + = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0716]: temporary value dropped while borrowed + --> $DIR/issue-114374-invalid-help-fmt-args.rs:10:15 + | +LL | let foo = format_args!("{}", "hi"); + | ^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement + | | + | creates a temporary value which is freed while still in use +LL | +LL | bar(foo); + | --- borrow later used here + | + = note: the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used + = note: to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html> + = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/borrowck/issue-115259-suggest-iter-mut.fixed b/tests/ui/borrowck/issue-115259-suggest-iter-mut.fixed new file mode 100644 index 00000000000..4653fe7375d --- /dev/null +++ b/tests/ui/borrowck/issue-115259-suggest-iter-mut.fixed @@ -0,0 +1,20 @@ +// run-rustfix +#![allow(unused_mut)] +#![allow(dead_code)] + +pub trait Layer { + fn process(&mut self) -> u32; +} + +pub struct State { + layers: Vec<Box<dyn Layer>>, +} + +impl State { + pub fn process(&mut self) -> u32 { + self.layers.iter_mut().fold(0, |result, mut layer| result + layer.process()) + //~^ ERROR cannot borrow `**layer` as mutable, as it is behind a `&` reference + } +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-115259-suggest-iter-mut.rs b/tests/ui/borrowck/issue-115259-suggest-iter-mut.rs new file mode 100644 index 00000000000..e0f6ab1321f --- /dev/null +++ b/tests/ui/borrowck/issue-115259-suggest-iter-mut.rs @@ -0,0 +1,20 @@ +// run-rustfix +#![allow(unused_mut)] +#![allow(dead_code)] + +pub trait Layer { + fn process(&mut self) -> u32; +} + +pub struct State { + layers: Vec<Box<dyn Layer>>, +} + +impl State { + pub fn process(&mut self) -> u32 { + self.layers.iter().fold(0, |result, mut layer| result + layer.process()) + //~^ ERROR cannot borrow `**layer` as mutable, as it is behind a `&` reference + } +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr b/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr new file mode 100644 index 00000000000..7e0fc2cf298 --- /dev/null +++ b/tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr @@ -0,0 +1,16 @@ +error[E0596]: cannot borrow `**layer` as mutable, as it is behind a `&` reference + --> $DIR/issue-115259-suggest-iter-mut.rs:15:65 + | +LL | self.layers.iter().fold(0, |result, mut layer| result + layer.process()) + | --------- ^^^^^ `layer` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | | + | consider changing this binding's type to be: `&mut Box<dyn Layer>` + | +help: you may want to use `iter_mut` here + | +LL | self.layers.iter_mut().fold(0, |result, mut layer| result + layer.process()) + | ~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.fixed b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.fixed new file mode 100644 index 00000000000..f02374d8e11 --- /dev/null +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.fixed @@ -0,0 +1,36 @@ +// run-rustfix +#![allow(unused_mut)] +#![allow(dead_code)] +use std::path::PathBuf; + +#[derive(Clone)] +struct Container { + things: Vec<PathBuf>, +} + +impl Container { + fn things(&mut self) -> &[PathBuf] { + &self.things + } +} + +// contains containers +struct ContainerContainer { + contained: Vec<Container>, +} + +impl ContainerContainer { + fn contained(&self) -> &[Container] { + &self.contained + } + + fn all_the_things(&mut self) -> &[PathBuf] { + let mut vec = self.contained.clone(); + let _a = + vec.iter_mut().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>(); + //~^ ERROR cannot borrow `*container` as mutable, as it is behind a `&` reference + unimplemented!(); + } +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.rs b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.rs new file mode 100644 index 00000000000..2d0b837a946 --- /dev/null +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.rs @@ -0,0 +1,36 @@ +// run-rustfix +#![allow(unused_mut)] +#![allow(dead_code)] +use std::path::PathBuf; + +#[derive(Clone)] +struct Container { + things: Vec<PathBuf>, +} + +impl Container { + fn things(&mut self) -> &[PathBuf] { + &self.things + } +} + +// contains containers +struct ContainerContainer { + contained: Vec<Container>, +} + +impl ContainerContainer { + fn contained(&self) -> &[Container] { + &self.contained + } + + fn all_the_things(&mut self) -> &[PathBuf] { + let mut vec = self.contained.clone(); + let _a = + vec.iter().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>(); + //~^ ERROR cannot borrow `*container` as mutable, as it is behind a `&` reference + unimplemented!(); + } +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr new file mode 100644 index 00000000000..19f194100a1 --- /dev/null +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr @@ -0,0 +1,16 @@ +error[E0596]: cannot borrow `*container` as mutable, as it is behind a `&` reference + --> $DIR/issue-62387-suggest-iter-mut-2.rs:30:45 + | +LL | vec.iter().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>(); + | --------- ^^^^^^^^^ `container` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | | + | consider changing this binding's type to be: `&mut Container` + | +help: you may want to use `iter_mut` here + | +LL | vec.iter_mut().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>(); + | ~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut.fixed b/tests/ui/borrowck/issue-62387-suggest-iter-mut.fixed new file mode 100644 index 00000000000..8bf2625de6d --- /dev/null +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut.fixed @@ -0,0 +1,30 @@ +// run-rustfix +#![allow(unused_mut)] +#![allow(dead_code)] + +#[derive(Debug)] +struct A { + a: i32, +} + +impl A { + fn double(&mut self) { + self.a += self.a + } +} + +fn baz() { + let mut v = [A { a: 4 }]; + v.iter_mut().for_each(|a| a.double()); + //~^ ERROR cannot borrow `*a` as mutable, as it is behind a `&` reference + println!("{:?}", v); +} + +fn bar() { + let mut v = [A { a: 4 }]; + v.iter_mut().rev().rev().for_each(|a| a.double()); + //~^ ERROR cannot borrow `*a` as mutable, as it is behind a `&` reference + println!("{:?}", v); +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut.rs b/tests/ui/borrowck/issue-62387-suggest-iter-mut.rs new file mode 100644 index 00000000000..39bc30bf294 --- /dev/null +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut.rs @@ -0,0 +1,30 @@ +// run-rustfix +#![allow(unused_mut)] +#![allow(dead_code)] + +#[derive(Debug)] +struct A { + a: i32, +} + +impl A { + fn double(&mut self) { + self.a += self.a + } +} + +fn baz() { + let mut v = [A { a: 4 }]; + v.iter().for_each(|a| a.double()); + //~^ ERROR cannot borrow `*a` as mutable, as it is behind a `&` reference + println!("{:?}", v); +} + +fn bar() { + let mut v = [A { a: 4 }]; + v.iter().rev().rev().for_each(|a| a.double()); + //~^ ERROR cannot borrow `*a` as mutable, as it is behind a `&` reference + println!("{:?}", v); +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr b/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr new file mode 100644 index 00000000000..fd58e433020 --- /dev/null +++ b/tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr @@ -0,0 +1,29 @@ +error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference + --> $DIR/issue-62387-suggest-iter-mut.rs:18:27 + | +LL | v.iter().for_each(|a| a.double()); + | - ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | | + | consider changing this binding's type to be: `&mut A` + | +help: you may want to use `iter_mut` here + | +LL | v.iter_mut().for_each(|a| a.double()); + | ~~~~~~~~ + +error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference + --> $DIR/issue-62387-suggest-iter-mut.rs:25:39 + | +LL | v.iter().rev().rev().for_each(|a| a.double()); + | - ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | | + | consider changing this binding's type to be: `&mut A` + | +help: you may want to use `iter_mut` here + | +LL | v.iter_mut().rev().rev().for_each(|a| a.double()); + | ~~~~~~~~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/c-variadic/variadic-ffi-1.stderr b/tests/ui/c-variadic/variadic-ffi-1.stderr index c7899338197..4beea83d8a5 100644 --- a/tests/ui/c-variadic/variadic-ffi-1.stderr +++ b/tests/ui/c-variadic/variadic-ffi-1.stderr @@ -46,7 +46,6 @@ LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo; | = note: expected fn pointer `unsafe extern "C" fn(_, _)` found fn item `unsafe extern "C" fn(_, _, ...) {foo}` - = note: when the arguments and return types match, functions can be coerced to function pointers error[E0308]: mismatched types --> $DIR/variadic-ffi-1.rs:26:54 @@ -58,7 +57,6 @@ LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar; | = note: expected fn pointer `extern "C" fn(_, _, ...)` found fn item `extern "C" fn(_, _) {bar}` - = note: when the arguments and return types match, functions can be coerced to function pointers error[E0617]: can't pass `f32` to variadic function --> $DIR/variadic-ffi-1.rs:28:19 diff --git a/tests/ui/c-variadic/variadic-ffi-2.rs b/tests/ui/c-variadic/variadic-ffi-2.rs index c34b7e55f6a..67a0a9a1dec 100644 --- a/tests/ui/c-variadic/variadic-ffi-2.rs +++ b/tests/ui/c-variadic/variadic-ffi-2.rs @@ -3,10 +3,13 @@ fn baz(f: extern "stdcall" fn(usize, ...)) { //~^ ERROR: C-variadic function must have a compatible calling convention, - // like C, cdecl, win64, sysv64 or efiapi + // like C, cdecl, aapcs, win64, sysv64 or efiapi f(22, 44); } +fn aapcs(f: extern "aapcs" fn(usize, ...)) { + f(22, 44); +} fn sysv(f: extern "sysv64" fn(usize, ...)) { f(22, 44); } diff --git a/tests/ui/c-variadic/variadic-ffi-2.stderr b/tests/ui/c-variadic/variadic-ffi-2.stderr index e21001ecaf8..8884fc6fb2a 100644 --- a/tests/ui/c-variadic/variadic-ffi-2.stderr +++ b/tests/ui/c-variadic/variadic-ffi-2.stderr @@ -1,4 +1,4 @@ -error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `win64`, `sysv64` or `efiapi` +error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `aapcs`, `win64`, `sysv64` or `efiapi` --> $DIR/variadic-ffi-2.rs:4:11 | LL | fn baz(f: extern "stdcall" fn(usize, ...)) { diff --git a/tests/ui/cast/cast-as-bool.rs b/tests/ui/cast/cast-as-bool.rs index fbebc80d91c..750a88f97eb 100644 --- a/tests/ui/cast/cast-as-bool.rs +++ b/tests/ui/cast/cast-as-bool.rs @@ -1,12 +1,48 @@ fn main() { - let u = 5 as bool; //~ ERROR cannot cast as `bool` + let u = 5 as bool; //~ ERROR cannot cast `i32` as `bool` //~| HELP compare with zero instead //~| SUGGESTION 5 != 0 - let t = (1 + 2) as bool; //~ ERROR cannot cast as `bool` + let t = (1 + 2) as bool; //~ ERROR cannot cast `i32` as `bool` //~| HELP compare with zero instead //~| SUGGESTION (1 + 2) != 0 + let _ = 5_u32 as bool; //~ ERROR cannot cast `u32` as `bool` + //~| HELP compare with zero instead + + let _ = 64.0_f64 as bool; //~ ERROR cannot cast `f64` as `bool` + //~| HELP compare with zero instead + + // Enums that can normally be cast to integers can't be cast to `bool`, just like integers. + // Note that enums that cannot be cast to integers can't be cast to anything at *all* + // so that's not tested here. + enum IntEnum { + Zero, + One, + Two + } + let _ = IntEnum::One as bool; //~ ERROR cannot cast `IntEnum` as `bool` + + fn uwu(_: u8) -> String { + todo!() + } + + unsafe fn owo() {} + + // fn item to bool + let _ = uwu as bool; //~ ERROR cannot cast `fn(u8) -> String {uwu}` as `bool` + // unsafe fn item + let _ = owo as bool; //~ ERROR cannot cast `unsafe fn() {owo}` as `bool` + + // fn ptr to bool + let _ = uwu as fn(u8) -> String as bool; //~ ERROR cannot cast `fn(u8) -> String` as `bool` + + let _ = 'x' as bool; //~ ERROR cannot cast `char` as `bool` + + let ptr = 1 as *const (); + + let _ = ptr as bool; //~ ERROR cannot cast `*const ()` as `bool` + let v = "hello" as bool; //~^ ERROR casting `&'static str` as `bool` is invalid //~| HELP consider using the `is_empty` method on `&'static str` to determine if it contains anything diff --git a/tests/ui/cast/cast-as-bool.stderr b/tests/ui/cast/cast-as-bool.stderr index 19ac8f10fec..852fb30cc20 100644 --- a/tests/ui/cast/cast-as-bool.stderr +++ b/tests/ui/cast/cast-as-bool.stderr @@ -1,18 +1,66 @@ -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `i32` as `bool` --> $DIR/cast-as-bool.rs:2:13 | LL | let u = 5 as bool; | ^^^^^^^^^ help: compare with zero instead: `5 != 0` -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `i32` as `bool` --> $DIR/cast-as-bool.rs:6:13 | LL | let t = (1 + 2) as bool; | ^^^^^^^^^^^^^^^ help: compare with zero instead: `(1 + 2) != 0` -error[E0606]: casting `&'static str` as `bool` is invalid +error[E0054]: cannot cast `u32` as `bool` --> $DIR/cast-as-bool.rs:10:13 | +LL | let _ = 5_u32 as bool; + | ^^^^^^^^^^^^^ help: compare with zero instead: `5_u32 != 0` + +error[E0054]: cannot cast `f64` as `bool` + --> $DIR/cast-as-bool.rs:13:13 + | +LL | let _ = 64.0_f64 as bool; + | ^^^^^^^^^^^^^^^^ help: compare with zero instead: `64.0_f64 != 0` + +error[E0054]: cannot cast `IntEnum` as `bool` + --> $DIR/cast-as-bool.rs:24:13 + | +LL | let _ = IntEnum::One as bool; + | ^^^^^^^^^^^^^^^^^^^^ unsupported cast + +error[E0054]: cannot cast `fn(u8) -> String {uwu}` as `bool` + --> $DIR/cast-as-bool.rs:33:13 + | +LL | let _ = uwu as bool; + | ^^^^^^^^^^^ unsupported cast + +error[E0054]: cannot cast `unsafe fn() {owo}` as `bool` + --> $DIR/cast-as-bool.rs:35:13 + | +LL | let _ = owo as bool; + | ^^^^^^^^^^^ unsupported cast + +error[E0054]: cannot cast `fn(u8) -> String` as `bool` + --> $DIR/cast-as-bool.rs:38:13 + | +LL | let _ = uwu as fn(u8) -> String as bool; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported cast + +error[E0054]: cannot cast `char` as `bool` + --> $DIR/cast-as-bool.rs:40:13 + | +LL | let _ = 'x' as bool; + | ^^^^^^^^^^^ unsupported cast + +error[E0054]: cannot cast `*const ()` as `bool` + --> $DIR/cast-as-bool.rs:44:13 + | +LL | let _ = ptr as bool; + | ^^^^^^^^^^^ unsupported cast + +error[E0606]: casting `&'static str` as `bool` is invalid + --> $DIR/cast-as-bool.rs:46:13 + | LL | let v = "hello" as bool; | ^^^^^^^^^^^^^^^ | @@ -21,7 +69,7 @@ help: consider using the `is_empty` method on `&'static str` to determine if it LL | let v = !"hello".is_empty(); | + ~~~~~~~~~~~ -error: aborting due to 3 previous errors +error: aborting due to 11 previous errors Some errors have detailed explanations: E0054, E0606. For more information about an error, try `rustc --explain E0054`. diff --git a/tests/ui/cast/cast-rfc0401-2.rs b/tests/ui/cast/cast-rfc0401-2.rs index 7709aa34104..70604a587ea 100644 --- a/tests/ui/cast/cast-rfc0401-2.rs +++ b/tests/ui/cast/cast-rfc0401-2.rs @@ -4,5 +4,5 @@ fn main() { let _ = 3 as bool; - //~^ ERROR cannot cast as `bool` + //~^ ERROR cannot cast `i32` as `bool` } diff --git a/tests/ui/cast/cast-rfc0401-2.stderr b/tests/ui/cast/cast-rfc0401-2.stderr index 52f6af78a9b..5dc21ca847c 100644 --- a/tests/ui/cast/cast-rfc0401-2.stderr +++ b/tests/ui/cast/cast-rfc0401-2.stderr @@ -1,4 +1,4 @@ -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `i32` as `bool` --> $DIR/cast-rfc0401-2.rs:6:13 | LL | let _ = 3 as bool; diff --git a/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr b/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr index 3a5fad15421..0807f459029 100644 --- a/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr +++ b/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr @@ -45,7 +45,8 @@ note: `E2` defined here | LL | pub enum E2 { A, B } | ^^^^^^^^^^^ - = note: the matched value is of type `E2`, which is marked as non-exhaustive + = note: the matched value is of type `E2` + = note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL | let _e = || { match e2 { E2::A => (), E2::B => (), _ => todo!() } }; diff --git a/tests/ui/closures/2229_closure_analysis/repr_packed.rs b/tests/ui/closures/2229_closure_analysis/repr_packed.rs index f23670f63ac..8c23454fae9 100644 --- a/tests/ui/closures/2229_closure_analysis/repr_packed.rs +++ b/tests/ui/closures/2229_closure_analysis/repr_packed.rs @@ -3,7 +3,8 @@ #![feature(rustc_attrs)] // `u8` aligned at a byte and are unaffected by repr(packed). -// Therefore we can precisely (and safely) capture references to both the fields. +// Therefore we *could* precisely (and safely) capture references to both the fields, +// but we don't, since we don't want capturing to change when field types change alignment. fn test_alignment_not_affected() { #[repr(packed)] struct Foo { x: u8, y: u8 } @@ -17,11 +18,10 @@ fn test_alignment_not_affected() { //~^ ERROR: First Pass analysis includes: //~| ERROR: Min Capture analysis includes: let z1: &u8 = &foo.x; - //~^ NOTE: Capturing foo[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture foo[(0, 0)] -> ImmBorrow + //~^ NOTE: Capturing foo[] -> ImmBorrow let z2: &mut u8 = &mut foo.y; - //~^ NOTE: Capturing foo[(1, 0)] -> MutBorrow - //~| NOTE: Min Capture foo[(1, 0)] -> MutBorrow + //~^ NOTE: Capturing foo[] -> MutBorrow + //~| NOTE: Min Capture foo[] -> MutBorrow *z2 = 42; diff --git a/tests/ui/closures/2229_closure_analysis/repr_packed.stderr b/tests/ui/closures/2229_closure_analysis/repr_packed.stderr index 580061ebc6e..32b3d844c6e 100644 --- a/tests/ui/closures/2229_closure_analysis/repr_packed.stderr +++ b/tests/ui/closures/2229_closure_analysis/repr_packed.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/repr_packed.rs:13:17 + --> $DIR/repr_packed.rs:14:17 | LL | let mut c = #[rustc_capture_analysis] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let c = #[rustc_capture_analysis] = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable error: First Pass analysis includes: - --> $DIR/repr_packed.rs:16:5 + --> $DIR/repr_packed.rs:17:5 | LL | / || { LL | | @@ -37,19 +37,19 @@ LL | | println!("({}, {})", z1, z2); LL | | }; | |_____^ | -note: Capturing foo[(0, 0)] -> ImmBorrow - --> $DIR/repr_packed.rs:19:24 +note: Capturing foo[] -> ImmBorrow + --> $DIR/repr_packed.rs:20:24 | LL | let z1: &u8 = &foo.x; | ^^^^^ -note: Capturing foo[(1, 0)] -> MutBorrow +note: Capturing foo[] -> MutBorrow --> $DIR/repr_packed.rs:22:32 | LL | let z2: &mut u8 = &mut foo.y; | ^^^^^ error: Min Capture analysis includes: - --> $DIR/repr_packed.rs:16:5 + --> $DIR/repr_packed.rs:17:5 | LL | / || { LL | | @@ -60,12 +60,7 @@ LL | | println!("({}, {})", z1, z2); LL | | }; | |_____^ | -note: Min Capture foo[(0, 0)] -> ImmBorrow - --> $DIR/repr_packed.rs:19:24 - | -LL | let z1: &u8 = &foo.x; - | ^^^^^ -note: Min Capture foo[(1, 0)] -> MutBorrow +note: Min Capture foo[] -> MutBorrow --> $DIR/repr_packed.rs:22:32 | LL | let z2: &mut u8 = &mut foo.y; diff --git a/tests/ui/issues/issue-11873.rs b/tests/ui/closures/issue-11873.rs index d3bd05caf38..d3bd05caf38 100644 --- a/tests/ui/issues/issue-11873.rs +++ b/tests/ui/closures/issue-11873.rs diff --git a/tests/ui/issues/issue-11873.stderr b/tests/ui/closures/issue-11873.stderr index c814eedd226..c814eedd226 100644 --- a/tests/ui/issues/issue-11873.stderr +++ b/tests/ui/closures/issue-11873.stderr diff --git a/tests/ui/issues/issue-25439.rs b/tests/ui/closures/issue-25439.rs index 4f73ff3e38b..4f73ff3e38b 100644 --- a/tests/ui/issues/issue-25439.rs +++ b/tests/ui/closures/issue-25439.rs diff --git a/tests/ui/issues/issue-25439.stderr b/tests/ui/closures/issue-25439.stderr index dadae23fdf3..dadae23fdf3 100644 --- a/tests/ui/issues/issue-25439.stderr +++ b/tests/ui/closures/issue-25439.stderr diff --git a/tests/ui/codegen/subtyping-enforces-type-equality.rs b/tests/ui/codegen/subtyping-enforces-type-equality.rs new file mode 100644 index 00000000000..a5ffcb3f854 --- /dev/null +++ b/tests/ui/codegen/subtyping-enforces-type-equality.rs @@ -0,0 +1,48 @@ +// ignore-pass +// build-pass +// edition:2021 +use std::future::Future; +use std::pin::Pin; + +type BoxFuture<T> = Pin<Box<dyn Future<Output = T>>>; + +fn main() { + let _ = wrapper_call(handler); +} + +async fn wrapper_call(handler: impl Handler) { + handler.call().await; +} +async fn handler() { + f(&()).await; +} +async fn f<'a>(db: impl Acquire<'a>) { + db.acquire().await; +} + +trait Handler { + type Future: Future; + fn call(self) -> Self::Future; +} + +impl<Fut, F> Handler for F +where + F: Fn() -> Fut, + Fut: Future, +{ + type Future = Fut; + fn call(self) -> Self::Future { + loop {} + } +} + +trait Acquire<'a> { + type Connection; + fn acquire(self) -> BoxFuture<Self::Connection>; +} +impl<'a> Acquire<'a> for &'a () { + type Connection = Self; + fn acquire(self) -> BoxFuture<Self> { + loop {} + } +} diff --git a/tests/ui/codegen/subtyping-enforces-type-equality.stderr b/tests/ui/codegen/subtyping-enforces-type-equality.stderr new file mode 100644 index 00000000000..870ca0f839f --- /dev/null +++ b/tests/ui/codegen/subtyping-enforces-type-equality.stderr @@ -0,0 +1 @@ +WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type. See the issues/114858 diff --git a/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr b/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr index 2e2dac288a1..a3a37fd2775 100644 --- a/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr +++ b/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr @@ -6,6 +6,11 @@ LL | takes_t(t); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/coherence-unsafe-trait-object-impl.rs:6:1 + | +LL | trait Trait: Sized { + | ^^^^^^^^^^^^^^^^^^ note: required by a bound in `takes_t` --> $DIR/coherence-unsafe-trait-object-impl.rs:10:15 | diff --git a/tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr b/tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr index f315ba82130..89289767b83 100644 --- a/tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr +++ b/tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr @@ -6,13 +6,11 @@ LL | #[derive(PartialEq, Default)] ... LL | impl<T, Q> PartialEq<Q> for Interval<T> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the first impl is here -... -LL | Q: ?Sized + PartialOrd, - | ---------- `Interval<_>: PartialOrd` may be considered to hold in future releases, causing the impls to overlap | = 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 #114040 <https://github.com/rust-lang/rust/issues/114040> = note: impls that are not considered to overlap may be considered to overlap in the future + = note: `Interval<_>: PartialOrd` may be considered to hold in future releases, causing the impls to overlap note: the lint level is defined here --> $DIR/warn-when-cycle-is-error-in-coherence.rs:1:9 | diff --git a/tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr b/tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr index cb51d9b1ea5..b3a27566026 100644 --- a/tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr +++ b/tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` i | LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]` + | +help: this trait has no implementations, consider adding one + --> $DIR/dont-evaluate-array-len-on-err-1.rs:9:1 + | +LL | trait Foo { + | ^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/const-generics/early/const-param-from-outer-fn.rs b/tests/ui/const-generics/early/const-param-from-outer-fn.rs index c3b418ee3f8..ee57f3c4fc3 100644 --- a/tests/ui/const-generics/early/const-param-from-outer-fn.rs +++ b/tests/ui/const-generics/early/const-param-from-outer-fn.rs @@ -1,6 +1,6 @@ fn foo<const X: u32>() { fn bar() -> u32 { - X //~ ERROR can't use generic parameters from outer function + X //~ ERROR can't use generic parameters from outer item } } diff --git a/tests/ui/const-generics/early/const-param-from-outer-fn.stderr b/tests/ui/const-generics/early/const-param-from-outer-fn.stderr index e3bf38b702e..826f2657905 100644 --- a/tests/ui/const-generics/early/const-param-from-outer-fn.stderr +++ b/tests/ui/const-generics/early/const-param-from-outer-fn.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/const-param-from-outer-fn.rs:3:9 | LL | fn foo<const X: u32>() { - | - const parameter from outer function + | - const parameter from outer item LL | fn bar() -> u32 { - | - help: try using a local generic parameter instead: `<X>` + | - help: try introducing a local generic parameter here: `<X>` LL | X - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to previous error diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs index e5464a4253f..8023b998a40 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -1,12 +1,6 @@ #![crate_type = "lib"] #![feature(generic_const_exprs)] -#![feature(type_privacy_lints)] #![allow(incomplete_features)] -#![warn(private_interfaces)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. pub struct Const<const U: u8>; @@ -21,7 +15,6 @@ where { type AssocTy = Const<{ my_const_fn(U) }>; //~^ ERROR private type - //~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy` fn assoc_fn() -> Self::AssocTy { Const } diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr index 16fae6b5c63..2d9de8805bb 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr @@ -1,5 +1,5 @@ error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/eval-privacy.rs:22:5 + --> $DIR/eval-privacy.rs:16:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type @@ -7,23 +7,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>; LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private -warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy` - --> $DIR/eval-privacy.rs:22:5 - | -LL | type AssocTy = Const<{ my_const_fn(U) }>; - | ^^^^^^^^^^^^ associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub` - | -note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)` - --> $DIR/eval-privacy.rs:30:1 - | -LL | const fn my_const_fn(val: u8) -> u8 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/eval-privacy.rs:5:9 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-85848.stderr b/tests/ui/const-generics/generic_const_exprs/issue-85848.stderr index e50ac671eca..9391b1c1a17 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-85848.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-85848.stderr @@ -6,7 +6,11 @@ LL | writes_to_specific_path(&cap); | | | required by a bound introduced by this call | - = help: the trait `Delegates<U>` is implemented for `T` +help: this trait has no implementations, consider adding one + --> $DIR/issue-85848.rs:4:1 + | +LL | trait _Contains<T> { + | ^^^^^^^^^^^^^^^^^^ note: required for `&C` to implement `Contains<(), true>` --> $DIR/issue-85848.rs:21:12 | diff --git a/tests/ui/const-generics/issues/issue-86530.stderr b/tests/ui/const-generics/issues/issue-86530.stderr index 620ed4f0fb2..d02808f7c56 100644 --- a/tests/ui/const-generics/issues/issue-86530.stderr +++ b/tests/ui/const-generics/issues/issue-86530.stderr @@ -6,6 +6,11 @@ LL | z(" "); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/issue-86530.rs:4:1 + | +LL | pub trait X { + | ^^^^^^^^^^^ note: required by a bound in `z` --> $DIR/issue-86530.rs:10:8 | diff --git a/tests/ui/const-generics/late-bound-vars/in_closure.rs b/tests/ui/const-generics/late-bound-vars/in_closure.rs index 4fdf603b05f..6549cad629b 100644 --- a/tests/ui/const-generics/late-bound-vars/in_closure.rs +++ b/tests/ui/const-generics/late-bound-vars/in_closure.rs @@ -1,4 +1,4 @@ -// failure-status: 101 +// failure-status: 1 // known-bug: unknown // error-pattern:internal compiler error // normalize-stderr-test "internal compiler error.*" -> "" @@ -22,7 +22,10 @@ #![feature(generic_const_exprs)] #![allow(incomplete_features)] -const fn inner<'a>() -> usize where &'a (): Sized { +const fn inner<'a>() -> usize +where + &'a (): Sized, +{ 3 } diff --git a/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs new file mode 100644 index 00000000000..0bf2f0e6669 --- /dev/null +++ b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs @@ -0,0 +1,5 @@ +#![crate_type = "lib"] + +struct Bug([u8; panic!{"\t"}]); +//~^ ERROR evaluation of constant value failed +//~| NOTE: in this expansion of panic! diff --git a/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr new file mode 100644 index 00000000000..82c63dd176d --- /dev/null +++ b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr @@ -0,0 +1,11 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const_panic-normalize-tabs-115498.rs:3:17 + | +LL | struct Bug([u8; panic!{"\t"}]); + | ^^^^^^^^^^^^ the evaluated program panicked at ' ', $DIR/const_panic-normalize-tabs-115498.rs:3:17 + | + = 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 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/ub-uninhabit.rs b/tests/ui/consts/const-eval/ub-uninhabit.rs index 10edae437ee..01600f545ae 100644 --- a/tests/ui/consts/const-eval/ub-uninhabit.rs +++ b/tests/ui/consts/const-eval/ub-uninhabit.rs @@ -1,7 +1,10 @@ // Strip out raw byte dumps to make comparison platform-independent: // normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" // normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP" +#![feature(core_intrinsics)] +#![feature(never_type)] +use std::intrinsics; use std::mem; #[derive(Copy, Clone)] @@ -15,11 +18,24 @@ union MaybeUninit<T: Copy> { const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR evaluation of constant value failed +//~| constructing invalid value const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; //~^ ERROR it is undefined behavior to use this value +//~| constructing invalid value const BAD_BAD_ARRAY: [Bar; 1] = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR evaluation of constant value failed +//~| constructing invalid value + + +const READ_NEVER: () = unsafe { + let mem = [0u32; 8]; + let ptr = mem.as_ptr().cast::<!>(); + let _val = intrinsics::read_via_copy(ptr); + //~^ ERROR evaluation of constant value failed + //~| constructing invalid value +}; + fn main() {} diff --git a/tests/ui/consts/const-eval/ub-uninhabit.stderr b/tests/ui/consts/const-eval/ub-uninhabit.stderr index f1ad0f04d3d..d26f4e03666 100644 --- a/tests/ui/consts/const-eval/ub-uninhabit.stderr +++ b/tests/ui/consts/const-eval/ub-uninhabit.stderr @@ -1,11 +1,11 @@ error[E0080]: evaluation of constant value failed - --> $DIR/ub-uninhabit.rs:16:35 + --> $DIR/ub-uninhabit.rs:19:35 | LL | const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a value of uninhabited type `Bar` error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-uninhabit.rs:19:1 + --> $DIR/ub-uninhabit.rs:23:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar @@ -16,11 +16,17 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; } error[E0080]: evaluation of constant value failed - --> $DIR/ub-uninhabit.rs:22:42 + --> $DIR/ub-uninhabit.rs:27:42 | LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { MaybeUninit { uninit: () }.init }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered a value of uninhabited type `Bar` -error: aborting due to 3 previous errors +error[E0080]: evaluation of constant value failed + --> $DIR/ub-uninhabit.rs:35:16 + | +LL | let _val = intrinsics::read_via_copy(ptr); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a value of the never type `!` + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/drop-maybe_uninit.rs b/tests/ui/consts/drop-maybe_uninit.rs new file mode 100644 index 00000000000..2fdeae5f185 --- /dev/null +++ b/tests/ui/consts/drop-maybe_uninit.rs @@ -0,0 +1,17 @@ +// build-pass + +pub const fn f<T, const N: usize>(_: [std::mem::MaybeUninit<T>; N]) {} + +pub struct Blubb<T>(*const T); + +pub const fn g<T, const N: usize>(_: [Blubb<T>; N]) {} + +pub struct Blorb<const N: usize>([String; N]); + +pub const fn h(_: Blorb<0>) {} + +pub struct Wrap(Blorb<0>); + +pub const fn i(_: Wrap) {} + +fn main() {} diff --git a/tests/ui/consts/issue-105536-const-val-roundtrip-ptr-eq.rs b/tests/ui/consts/issue-105536-const-val-roundtrip-ptr-eq.rs new file mode 100644 index 00000000000..1615399be32 --- /dev/null +++ b/tests/ui/consts/issue-105536-const-val-roundtrip-ptr-eq.rs @@ -0,0 +1,31 @@ +// run-pass + +// This does not reflect a stable guarantee (we guarantee very little for equality of pointers +// around `const`), but it would be good to understand what is happening if these assertions ever +// fail. +use std::ptr::NonNull; +use std::slice::from_raw_parts; + +const PTR_U8: *const u8 = NonNull::dangling().as_ptr(); +const CONST_U8_REF: &[u8] = unsafe { from_raw_parts(PTR_U8, 0) }; +const CONST_U8_PTR: *const u8 = unsafe { from_raw_parts(PTR_U8, 0).as_ptr() }; +static STATIC_U8_REF: &[u8] = unsafe { from_raw_parts(PTR_U8, 0) }; + +const PTR_U16: *const u16 = NonNull::dangling().as_ptr(); +const CONST_U16_REF: &[u16] = unsafe { from_raw_parts(PTR_U16, 0) }; + +const fn const_u8_fn() -> &'static [u8] { + unsafe { from_raw_parts(PTR_U8, 0) } +} + +fn main() { + let ptr_u8 = unsafe { from_raw_parts(PTR_U8, 0) }.as_ptr(); + let ptr_u16 = unsafe { from_raw_parts(PTR_U16, 0) }.as_ptr(); + + assert_eq!(ptr_u8, PTR_U8); + assert_eq!(ptr_u8, CONST_U8_PTR); + assert_eq!(ptr_u8, const_u8_fn().as_ptr()); + assert_eq!(ptr_u8, STATIC_U8_REF.as_ptr()); + assert_eq!(ptr_u16, CONST_U16_REF.as_ptr()); + assert_eq!(ptr_u8, CONST_U8_REF.as_ptr()); +} diff --git a/tests/ui/cross/cross-fn-cache-hole.stderr b/tests/ui/cross/cross-fn-cache-hole.stderr index 7e15562b081..79d1713934b 100644 --- a/tests/ui/cross/cross-fn-cache-hole.stderr +++ b/tests/ui/cross/cross-fn-cache-hole.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `i32: Bar<u32>` is not satisfied LL | where i32: Foo<u32, A> | ^^^^^^^^^^^^^^^^ the trait `Bar<u32>` is not implemented for `i32` | +help: this trait has no implementations, consider adding one + --> $DIR/cross-fn-cache-hole.rs:11:1 + | +LL | trait Bar<X> { } + | ^^^^^^^^^^^^ = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable diff --git a/tests/ui/derive-uninhabited-enum-38885.stderr b/tests/ui/derive-uninhabited-enum-38885.stderr index dcdf8f8430f..3fabf446dc3 100644 --- a/tests/ui/derive-uninhabited-enum-38885.stderr +++ b/tests/ui/derive-uninhabited-enum-38885.stderr @@ -9,6 +9,7 @@ LL | Void(Void), | = note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `-W dead-code` implied by `-W unused` + = help: to override `-W unused` add `#[allow(dead_code)]` warning: 1 warning emitted diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index 6bfc859bfe8..3d9f8129d93 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -60,7 +60,7 @@ impl ::core::marker::StructuralEq for Empty { } impl ::core::cmp::Eq for Empty { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -135,7 +135,7 @@ impl ::core::marker::StructuralEq for Point { } impl ::core::cmp::Eq for Point { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<u32>; } @@ -221,7 +221,7 @@ impl ::core::marker::StructuralEq for PackedPoint { } impl ::core::cmp::Eq for PackedPoint { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<u32>; } @@ -334,7 +334,7 @@ impl ::core::marker::StructuralEq for Big { } impl ::core::cmp::Eq for Big { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<u32>; } @@ -500,7 +500,7 @@ impl ::core::marker::StructuralEq for Unsized { } impl ::core::cmp::Eq for Unsized { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<[u32]>; } @@ -615,7 +615,7 @@ impl<T: ::core::cmp::Eq + Trait, U: ::core::cmp::Eq> ::core::cmp::Eq for Generic<T, U> where T::A: ::core::cmp::Eq { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<T>; let _: ::core::cmp::AssertParamIsEq<T::A>; @@ -738,7 +738,7 @@ impl<T: ::core::cmp::Eq + ::core::marker::Copy + Trait, U: ::core::cmp::Eq + T::A: ::core::cmp::Eq + ::core::marker::Copy { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<T>; let _: ::core::cmp::AssertParamIsEq<T::A>; @@ -821,7 +821,7 @@ impl ::core::marker::StructuralEq for Enum0 { } impl ::core::cmp::Eq for Enum0 { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -892,7 +892,7 @@ impl ::core::marker::StructuralEq for Enum1 { } impl ::core::cmp::Eq for Enum1 { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<u32>; } @@ -959,7 +959,7 @@ impl ::core::marker::StructuralEq for Fieldless1 { } impl ::core::cmp::Eq for Fieldless1 { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -1034,7 +1034,7 @@ impl ::core::marker::StructuralEq for Fieldless { } impl ::core::cmp::Eq for Fieldless { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -1142,7 +1142,7 @@ impl ::core::marker::StructuralEq for Mixed { } impl ::core::cmp::Eq for Mixed { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<u32>; let _: ::core::cmp::AssertParamIsEq<Option<u32>>; @@ -1270,7 +1270,7 @@ impl ::core::marker::StructuralEq for Fielded { } impl ::core::cmp::Eq for Fielded { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<u32>; let _: ::core::cmp::AssertParamIsEq<bool>; @@ -1393,7 +1393,7 @@ impl<T: ::core::cmp::Eq, U: ::core::cmp::Eq> ::core::cmp::Eq for EnumGeneric<T, U> { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<T>; let _: ::core::cmp::AssertParamIsEq<U>; diff --git a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs index a686ed9c84e..b08e291621f 100644 --- a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs +++ b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs @@ -1,12 +1,12 @@ #[diagnostic::non_existing_attribute] //~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] -//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes] +//~|WARNING unknown diagnostic attribute [unknown_or_malformed_diagnostic_attributes] pub trait Bar { } #[diagnostic::non_existing_attribute(with_option = "foo")] //~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] -//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes] +//~|WARNING unknown diagnostic attribute [unknown_or_malformed_diagnostic_attributes] struct Foo; fn main() { diff --git a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr index 45c95cbb3c7..017d00e2c8e 100644 --- a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr +++ b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr @@ -4,7 +4,7 @@ error[E0658]: `#[diagnostic]` attribute name space is experimental LL | #[diagnostic::non_existing_attribute] | ^^^^^^^^^^ | - = note: see issue #94785 <https://github.com/rust-lang/rust/issues/94785> for more information + = note: see issue #111996 <https://github.com/rust-lang/rust/issues/111996> for more information = help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable error[E0658]: `#[diagnostic]` attribute name space is experimental @@ -13,7 +13,7 @@ error[E0658]: `#[diagnostic]` attribute name space is experimental LL | #[diagnostic::non_existing_attribute(with_option = "foo")] | ^^^^^^^^^^ | - = note: see issue #94785 <https://github.com/rust-lang/rust/issues/94785> for more information + = note: see issue #111996 <https://github.com/rust-lang/rust/issues/111996> for more information = help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable warning: unknown diagnostic attribute @@ -22,7 +22,7 @@ warning: unknown diagnostic attribute LL | #[diagnostic::non_existing_attribute] | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(unknown_diagnostic_attributes)]` on by default + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default warning: unknown diagnostic attribute --> $DIR/feature-gate-diagnostic_namespace.rs:7:15 diff --git a/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr b/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr index 4f9b7ba2bcf..753077b365e 100644 --- a/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr +++ b/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr @@ -4,7 +4,7 @@ warning: unknown diagnostic attribute LL | #[diagnostic::non_existing_attribute] | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(unknown_diagnostic_attributes)]` on by default + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default warning: unknown diagnostic attribute --> $DIR/non_existing_attributes_accepted.rs:8:15 diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs new file mode 100644 index 00000000000..00fb59d14d7 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs @@ -0,0 +1,37 @@ +#![feature(diagnostic_namespace)] + +#[diagnostic::on_unimplemented(unsupported = "foo")] +//~^WARN malformed `on_unimplemented` attribute +//~|WARN malformed `on_unimplemented` attribute +trait Foo {} + +#[diagnostic::on_unimplemented(message = "Baz")] +//~^WARN `#[diagnostic::on_unimplemented]` can only be applied to trait definitions +struct Bar {} + +#[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")] +//~^WARN malformed `on_unimplemented` attribute +//~|WARN malformed `on_unimplemented` attribute +trait Baz {} + +#[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))] +//~^WARN malformed `on_unimplemented` attribute +//~|WARN malformed `on_unimplemented` attribute +trait Boom {} + +#[diagnostic::on_unimplemented = "boom"] +//~^WARN malformed `on_unimplemented` attribute +trait Doom {} + +fn take_foo(_: impl Foo) {} +fn take_baz(_: impl Baz) {} +fn take_boom(_: impl Boom) {} + +fn main() { + take_foo(1_i32); + //~^ERROR the trait bound `i32: Foo` is not satisfied + take_baz(1_i32); + //~^ERROR Boom + take_boom(1_i32); + //~^ERROR Boom +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr new file mode 100644 index 00000000000..bb1b29ef248 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr @@ -0,0 +1,110 @@ +warning: `#[diagnostic::on_unimplemented]` can only be applied to trait definitions + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:8:1 + | +LL | #[diagnostic::on_unimplemented(message = "Baz")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:3:32 + | +LL | #[diagnostic::on_unimplemented(unsupported = "foo")] + | ^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:12:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")] + | ^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:17:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:22:1 + | +LL | #[diagnostic::on_unimplemented = "boom"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:3:32 + | +LL | #[diagnostic::on_unimplemented(unsupported = "foo")] + | ^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `i32: Foo` is not satisfied + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:14 + | +LL | take_foo(1_i32); + | -------- ^^^^^ the trait `Foo` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:6:1 + | +LL | trait Foo {} + | ^^^^^^^^^ +note: required by a bound in `take_foo` + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:26:21 + | +LL | fn take_foo(_: impl Foo) {} + | ^^^ required by this bound in `take_foo` + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:12:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")] + | ^^^^^^^^^^^^^^^^^^^ + +error[E0277]: Boom + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:33:14 + | +LL | take_baz(1_i32); + | -------- ^^^^^ the trait `Baz` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:15:1 + | +LL | trait Baz {} + | ^^^^^^^^^ +note: required by a bound in `take_baz` + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:27:21 + | +LL | fn take_baz(_: impl Baz) {} + | ^^^ required by this bound in `take_baz` + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:17:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: Boom + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:35:15 + | +LL | take_boom(1_i32); + | --------- ^^^^^ the trait `Boom` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:20:1 + | +LL | trait Boom {} + | ^^^^^^^^^^ +note: required by a bound in `take_boom` + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:28:22 + | +LL | fn take_boom(_: impl Boom) {} + | ^^^^ required by this bound in `take_boom` + +error: aborting due to 3 previous errors; 8 warnings emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs new file mode 100644 index 00000000000..609a840c118 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs @@ -0,0 +1,7 @@ +#[diagnostic::on_unimplemented(message = "Foo")] +//~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] +pub trait Bar { +} + +fn main() { +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.stderr new file mode 100644 index 00000000000..21f02e3a73b --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.stderr @@ -0,0 +1,12 @@ +error[E0658]: `#[diagnostic]` attribute name space is experimental + --> $DIR/feature-gate-diagnostic_on_unimplemented.rs:1:3 + | +LL | #[diagnostic::on_unimplemented(message = "Foo")] + | ^^^^^^^^^^ + | + = note: see issue #111996 <https://github.com/rust-lang/rust/issues/111996> for more information + = help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.rs b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.rs new file mode 100644 index 00000000000..797edbc9ec5 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.rs @@ -0,0 +1,11 @@ +#![feature(diagnostic_namespace)] + +#[diagnostic::on_unimplemented(message = "Foo", label = "Bar", note = "Baz")] +trait Foo {} + +fn takes_foo(_: impl Foo) {} + +fn main() { + takes_foo(()); + //~^ERROR Foo +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.stderr new file mode 100644 index 00000000000..549c7caa720 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.stderr @@ -0,0 +1,24 @@ +error[E0277]: Foo + --> $DIR/on_unimplemented_simple.rs:9:15 + | +LL | takes_foo(()); + | --------- ^^ Bar + | | + | required by a bound introduced by this call + | + = help: the trait `Foo` is not implemented for `()` + = note: Baz +help: this trait has no implementations, consider adding one + --> $DIR/on_unimplemented_simple.rs:4:1 + | +LL | trait Foo {} + | ^^^^^^^^^ +note: required by a bound in `takes_foo` + --> $DIR/on_unimplemented_simple.rs:6:22 + | +LL | fn takes_foo(_: impl Foo) {} + | ^^^ required by this bound in `takes_foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/drop-bounds/drop-bounds-impl-drop.rs b/tests/ui/drop-bounds/drop-bounds-impl-drop.rs index 063efc7b31a..15aebdf1bc9 100644 --- a/tests/ui/drop-bounds/drop-bounds-impl-drop.rs +++ b/tests/ui/drop-bounds/drop-bounds-impl-drop.rs @@ -2,13 +2,13 @@ #![deny(drop_bounds)] // As a special exemption, `impl Drop` in the return position raises no error. // This allows a convenient way to return an unnamed drop guard. -fn voldemort_type() -> impl Drop { - struct Voldemort; - impl Drop for Voldemort { +fn unnameable_type() -> impl Drop { + struct Unnameable; + impl Drop for Unnameable { fn drop(&mut self) {} } - Voldemort + Unnameable } fn main() { - let _ = voldemort_type(); + let _ = unnameable_type(); } diff --git a/tests/ui/dst/dst-bad-coerce1.stderr b/tests/ui/dst/dst-bad-coerce1.stderr index 2c75518c298..455d15e935f 100644 --- a/tests/ui/dst/dst-bad-coerce1.stderr +++ b/tests/ui/dst/dst-bad-coerce1.stderr @@ -15,6 +15,11 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied LL | let f3: &Fat<dyn Bar> = f2; | ^^ the trait `Bar` is not implemented for `Foo` | +help: this trait has no implementations, consider adding one + --> $DIR/dst-bad-coerce1.rs:10:1 + | +LL | trait Bar { fn bar(&self) {} } + | ^^^^^^^^^ = note: required for the cast from `&Fat<Foo>` to `&Fat<dyn Bar>` error[E0308]: mismatched types @@ -34,6 +39,11 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied LL | let f3: &(dyn Bar,) = f2; | ^^ the trait `Bar` is not implemented for `Foo` | +help: this trait has no implementations, consider adding one + --> $DIR/dst-bad-coerce1.rs:10:1 + | +LL | trait Bar { fn bar(&self) {} } + | ^^^^^^^^^ = note: required for the cast from `&(Foo,)` to `&(dyn Bar,)` error: aborting due to 4 previous errors diff --git a/tests/ui/dyn-star/error.stderr b/tests/ui/dyn-star/error.stderr index ae54b9ca707..e039bb6f1c8 100644 --- a/tests/ui/dyn-star/error.stderr +++ b/tests/ui/dyn-star/error.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `{integer}: Foo` is not satisfied | LL | let dyn_i: dyn* Foo = i; | ^ the trait `Foo` is not implemented for `{integer}` + | +help: this trait has no implementations, consider adding one + --> $DIR/error.rs:6:1 + | +LL | trait Foo {} + | ^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/error-codes/E0040.stderr b/tests/ui/error-codes/E0040.stderr index 9fcda1a9385..839be79d28d 100644 --- a/tests/ui/error-codes/E0040.stderr +++ b/tests/ui/error-codes/E0040.stderr @@ -2,10 +2,12 @@ error[E0040]: explicit use of destructor method --> $DIR/E0040.rs:16:7 | LL | x.drop(); - | --^^^^-- - | | | - | | explicit destructor calls not allowed - | help: consider using `drop` function: `drop(x)` + | ^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL | drop(x); + | +++++ ~ error: aborting due to previous error diff --git a/tests/ui/error-codes/E0054.stderr b/tests/ui/error-codes/E0054.stderr index 6b1092760fb..ea81f4476a7 100644 --- a/tests/ui/error-codes/E0054.stderr +++ b/tests/ui/error-codes/E0054.stderr @@ -1,4 +1,4 @@ -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `i32` as `bool` --> $DIR/E0054.rs:3:24 | LL | let x_is_nonzero = x as bool; diff --git a/tests/ui/error-codes/E0220.stderr b/tests/ui/error-codes/E0220.stderr index 11763ce788d..e03eadacae4 100644 --- a/tests/ui/error-codes/E0220.stderr +++ b/tests/ui/error-codes/E0220.stderr @@ -2,7 +2,7 @@ error[E0220]: associated type `F` not found for `Trait` --> $DIR/E0220.rs:5:22 | LL | type Foo = dyn Trait<F=i32>; - | ^ associated type `F` not found + | ^ help: `Trait` has the following associated type: `Bar` error[E0191]: the value of the associated type `Bar` (from trait `Trait`) must be specified --> $DIR/E0220.rs:5:16 diff --git a/tests/ui/error-codes/E0277.stderr b/tests/ui/error-codes/E0277.stderr index 440e43dff81..0b0d2b09720 100644 --- a/tests/ui/error-codes/E0277.stderr +++ b/tests/ui/error-codes/E0277.stderr @@ -21,6 +21,11 @@ LL | some_func(5i32); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/E0277.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ note: required by a bound in `some_func` --> $DIR/E0277.rs:7:17 | diff --git a/tests/ui/error-codes/E0401.stderr b/tests/ui/error-codes/E0401.stderr index fa4b91cacef..928c8d11d20 100644 --- a/tests/ui/error-codes/E0401.stderr +++ b/tests/ui/error-codes/E0401.stderr @@ -1,26 +1,26 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:4:39 | LL | fn foo<T>(x: T) { - | - type parameter from outer function + | - type parameter from outer item LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) { - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `T,` + | help: try introducing a local generic parameter here: `T,` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:9:16 | LL | fn foo<T>(x: T) { - | - type parameter from outer function + | - type parameter from outer item ... LL | fn baz<U, - | - help: try using a local generic parameter instead: `T,` + | - help: try introducing a local generic parameter here: `T,` ... LL | (y: T) { - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:24:25 | LL | impl<T> Iterator for A<T> { @@ -29,8 +29,8 @@ LL | impl<T> Iterator for A<T> { LL | fn helper(sel: &Self) -> u8 { | ^^^^ | | - | use of generic parameter from outer function - | use a type here instead + | use of generic parameter from outer item + | refer to the type directly here instead error[E0282]: type annotations needed --> $DIR/E0401.rs:11:5 diff --git a/tests/ui/error-codes/E0445.rs b/tests/ui/error-codes/E0445.rs deleted file mode 100644 index 9f29c81673e..00000000000 --- a/tests/ui/error-codes/E0445.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![feature(type_privacy_lints)] -#[warn(private_bounds)] -#[warn(private_interfaces)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. - -trait Foo { - fn dummy(&self) { } -} - -pub trait Bar : Foo {} -//~^ ERROR private trait `Foo` in public interface [E0445] -//~| WARNING trait `Foo` is more private than the item `Bar` -pub struct Bar2<T: Foo>(pub T); -//~^ ERROR private trait `Foo` in public interface [E0445] -//~| WARNING trait `Foo` is more private than the item `Bar2` -pub fn foo<T: Foo> (t: T) {} -//~^ ERROR private trait `Foo` in public interface [E0445] -//~| WARNING trait `Foo` is more private than the item `foo` - -fn main() {} diff --git a/tests/ui/error-codes/E0445.stderr b/tests/ui/error-codes/E0445.stderr deleted file mode 100644 index 4f940868ff9..00000000000 --- a/tests/ui/error-codes/E0445.stderr +++ /dev/null @@ -1,71 +0,0 @@ -error[E0445]: private trait `Foo` in public interface - --> $DIR/E0445.rs:13:1 - | -LL | trait Foo { - | --------- `Foo` declared as private -... -LL | pub trait Bar : Foo {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private trait - -warning: trait `Foo` is more private than the item `Bar` - --> $DIR/E0445.rs:13:1 - | -LL | pub trait Bar : Foo {} - | ^^^^^^^^^^^^^^^^^^^ trait `Bar` is reachable at visibility `pub` - | -note: but trait `Foo` is only usable at visibility `pub(crate)` - --> $DIR/E0445.rs:9:1 - | -LL | trait Foo { - | ^^^^^^^^^ -note: the lint level is defined here - --> $DIR/E0445.rs:2:8 - | -LL | #[warn(private_bounds)] - | ^^^^^^^^^^^^^^ - -error[E0445]: private trait `Foo` in public interface - --> $DIR/E0445.rs:16:1 - | -LL | trait Foo { - | --------- `Foo` declared as private -... -LL | pub struct Bar2<T: Foo>(pub T); - | ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait - -warning: trait `Foo` is more private than the item `Bar2` - --> $DIR/E0445.rs:16:1 - | -LL | pub struct Bar2<T: Foo>(pub T); - | ^^^^^^^^^^^^^^^^^^^^^^^ struct `Bar2` is reachable at visibility `pub` - | -note: but trait `Foo` is only usable at visibility `pub(crate)` - --> $DIR/E0445.rs:9:1 - | -LL | trait Foo { - | ^^^^^^^^^ - -error[E0445]: private trait `Foo` in public interface - --> $DIR/E0445.rs:19:1 - | -LL | trait Foo { - | --------- `Foo` declared as private -... -LL | pub fn foo<T: Foo> (t: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait - -warning: trait `Foo` is more private than the item `foo` - --> $DIR/E0445.rs:19:1 - | -LL | pub fn foo<T: Foo> (t: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub` - | -note: but trait `Foo` is only usable at visibility `pub(crate)` - --> $DIR/E0445.rs:9:1 - | -LL | trait Foo { - | ^^^^^^^^^ - -error: aborting due to 3 previous errors; 3 warnings emitted - -For more information about this error, try `rustc --explain E0445`. diff --git a/tests/ui/error-codes/E0446.rs b/tests/ui/error-codes/E0446.rs index f61c7e54616..6d6c4f97c06 100644 --- a/tests/ui/error-codes/E0446.rs +++ b/tests/ui/error-codes/E0446.rs @@ -1,9 +1,14 @@ -mod foo { - struct Bar(u32); +struct Bar; +trait PrivTr {} - pub fn bar() -> Bar { //~ ERROR E0446 - Bar(0) - } +pub trait PubTr { + type Alias1; + type Alias2; +} + +impl PubTr for u8 { + type Alias1 = Bar; //~ ERROR E0446 + type Alias2 = Box<dyn PrivTr>; //~ ERROR E0446 } fn main() {} diff --git a/tests/ui/error-codes/E0446.stderr b/tests/ui/error-codes/E0446.stderr index b6a195c40a9..2951e69d1c2 100644 --- a/tests/ui/error-codes/E0446.stderr +++ b/tests/ui/error-codes/E0446.stderr @@ -1,12 +1,21 @@ error[E0446]: private type `Bar` in public interface - --> $DIR/E0446.rs:4:5 + --> $DIR/E0446.rs:10:5 | -LL | struct Bar(u32); - | ---------- `Bar` declared as private -LL | -LL | pub fn bar() -> Bar { - | ^^^^^^^^^^^^^^^^^^^ can't leak private type +LL | struct Bar; + | ---------- `Bar` declared as private +... +LL | type Alias1 = Bar; + | ^^^^^^^^^^^ can't leak private type -error: aborting due to previous error +error[E0446]: private trait `PrivTr` in public interface + --> $DIR/E0446.rs:11:5 + | +LL | trait PrivTr {} + | ------------ `PrivTr` declared as private +... +LL | type Alias2 = Box<dyn PrivTr>; + | ^^^^^^^^^^^ can't leak private trait + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/error-codes/E0602.rs b/tests/ui/error-codes/E0602.rs index 8fadce526d9..77d28838a10 100644 --- a/tests/ui/error-codes/E0602.rs +++ b/tests/ui/error-codes/E0602.rs @@ -1,6 +1,8 @@ // compile-flags:-D bogus +// check-pass // error-pattern:E0602 // error-pattern:requested on the command line with `-D bogus` +// error-pattern:`#[warn(unknown_lints)]` on by default fn main() {} diff --git a/tests/ui/error-codes/E0602.stderr b/tests/ui/error-codes/E0602.stderr index 2b372263345..60ecec7cdd7 100644 --- a/tests/ui/error-codes/E0602.stderr +++ b/tests/ui/error-codes/E0602.stderr @@ -1,11 +1,16 @@ -error[E0602]: unknown lint: `bogus` +warning[E0602]: unknown lint: `bogus` | = note: requested on the command line with `-D bogus` + = note: `#[warn(unknown_lints)]` on by default -error[E0602]: unknown lint: `bogus` +warning[E0602]: unknown lint: `bogus` | = note: requested on the command line with `-D bogus` -error: aborting due to 2 previous errors +warning[E0602]: unknown lint: `bogus` + | + = note: requested on the command line with `-D bogus` + +warning: 3 warnings emitted For more information about this error, try `rustc --explain E0602`. diff --git a/tests/ui/error-codes/E0609-private-method.rs b/tests/ui/error-codes/E0609-private-method.rs new file mode 100644 index 00000000000..dfa97ad9a6f --- /dev/null +++ b/tests/ui/error-codes/E0609-private-method.rs @@ -0,0 +1,16 @@ +// This error is an E0609 and *not* an E0615 because the fact that the method exists is not +// relevant. +mod foo { + pub struct Foo { + x: u32, + } + + impl Foo { + fn method(&self) {} + } +} + +fn main() { + let f = foo::Foo { x: 0 }; + f.method; //~ ERROR E0609 +} diff --git a/tests/ui/error-codes/E0609-private-method.stderr b/tests/ui/error-codes/E0609-private-method.stderr new file mode 100644 index 00000000000..d2a11e90627 --- /dev/null +++ b/tests/ui/error-codes/E0609-private-method.stderr @@ -0,0 +1,9 @@ +error[E0609]: no field `method` on type `Foo` + --> $DIR/E0609-private-method.rs:15:7 + | +LL | f.method; + | ^^^^^^ unknown field + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. diff --git a/tests/ui/error-festival.stderr b/tests/ui/error-festival.stderr index e8ee1d96942..74a2bc8d768 100644 --- a/tests/ui/error-festival.stderr +++ b/tests/ui/error-festival.stderr @@ -59,7 +59,7 @@ error[E0605]: non-primitive cast: `u8` as `Vec<u8>` LL | x as Vec<u8>; | ^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `{integer}` as `bool` --> $DIR/error-festival.rs:33:24 | LL | let x_is_nonzero = x as bool; diff --git a/tests/ui/explicit/explicit-call-to-dtor.stderr b/tests/ui/explicit/explicit-call-to-dtor.stderr index f3c9bf6cccd..f2e0b73b6c5 100644 --- a/tests/ui/explicit/explicit-call-to-dtor.stderr +++ b/tests/ui/explicit/explicit-call-to-dtor.stderr @@ -2,10 +2,12 @@ error[E0040]: explicit use of destructor method --> $DIR/explicit-call-to-dtor.rs:15:7 | LL | x.drop(); - | --^^^^-- - | | | - | | explicit destructor calls not allowed - | help: consider using `drop` function: `drop(x)` + | ^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL | drop(x); + | +++++ ~ error: aborting due to previous error diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr b/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr index c7067117349..5fa42fcf191 100644 --- a/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr +++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr @@ -2,10 +2,12 @@ error[E0040]: explicit use of destructor method --> $DIR/explicit-call-to-supertrait-dtor.rs:22:14 | LL | self.drop(); - | -----^^^^-- - | | | - | | explicit destructor calls not allowed - | help: consider using `drop` function: `drop(self)` + | ^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL | drop(self); + | +++++ ~ error: aborting due to previous error diff --git a/tests/ui/expr/if/bad-if-let-suggestion.rs b/tests/ui/expr/if/bad-if-let-suggestion.rs index a8b2a283039..99d584ac7a5 100644 --- a/tests/ui/expr/if/bad-if-let-suggestion.rs +++ b/tests/ui/expr/if/bad-if-let-suggestion.rs @@ -4,9 +4,8 @@ fn a() { if let x = 1 && i = 2 {} //~^ ERROR cannot find value `i` in this scope - //~| ERROR `let` expressions in this position are unstable //~| ERROR mismatched types - //~| ERROR `let` expressions are not supported here + //~| ERROR expected expression, found `let` statement } fn b() { diff --git a/tests/ui/expr/if/bad-if-let-suggestion.stderr b/tests/ui/expr/if/bad-if-let-suggestion.stderr index 3a53a20b453..20ac9ca76ba 100644 --- a/tests/ui/expr/if/bad-if-let-suggestion.stderr +++ b/tests/ui/expr/if/bad-if-let-suggestion.stderr @@ -1,4 +1,4 @@ -error: `let` expressions are not supported here +error: expected expression, found `let` statement --> $DIR/bad-if-let-suggestion.rs:5:8 | LL | if let x = 1 && i = 2 {} @@ -13,7 +13,7 @@ LL | if let x = 1 && i = 2 {} | ^ not found in this scope error[E0425]: cannot find value `i` in this scope - --> $DIR/bad-if-let-suggestion.rs:13:9 + --> $DIR/bad-if-let-suggestion.rs:12:9 | LL | fn a() { | ------ similarly named function `a` defined here @@ -22,7 +22,7 @@ LL | if (i + j) = i {} | ^ help: a function with a similar name exists: `a` error[E0425]: cannot find value `j` in this scope - --> $DIR/bad-if-let-suggestion.rs:13:13 + --> $DIR/bad-if-let-suggestion.rs:12:13 | LL | fn a() { | ------ similarly named function `a` defined here @@ -31,7 +31,7 @@ LL | if (i + j) = i {} | ^ help: a function with a similar name exists: `a` error[E0425]: cannot find value `i` in this scope - --> $DIR/bad-if-let-suggestion.rs:13:18 + --> $DIR/bad-if-let-suggestion.rs:12:18 | LL | fn a() { | ------ similarly named function `a` defined here @@ -40,7 +40,7 @@ LL | if (i + j) = i {} | ^ help: a function with a similar name exists: `a` error[E0425]: cannot find value `x` in this scope - --> $DIR/bad-if-let-suggestion.rs:20:8 + --> $DIR/bad-if-let-suggestion.rs:19:8 | LL | fn a() { | ------ similarly named function `a` defined here @@ -48,15 +48,6 @@ LL | fn a() { LL | if x[0] = 1 {} | ^ help: a function with a similar name exists: `a` -error[E0658]: `let` expressions in this position are unstable - --> $DIR/bad-if-let-suggestion.rs:5:8 - | -LL | if let x = 1 && i = 2 {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - error[E0308]: mismatched types --> $DIR/bad-if-let-suggestion.rs:5:8 | @@ -68,7 +59,7 @@ help: you might have meant to compare for equality LL | if let x = 1 && i == 2 {} | + -error: aborting due to 8 previous errors +error: aborting due to 7 previous errors -Some errors have detailed explanations: E0308, E0425, E0658. +Some errors have detailed explanations: E0308, E0425. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/feature-gates/feature-gate-coverage-attribute.rs b/tests/ui/feature-gates/feature-gate-coverage-attribute.rs new file mode 100644 index 00000000000..0a463755f13 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-coverage-attribute.rs @@ -0,0 +1,14 @@ +#![crate_type = "lib"] +#![feature(no_coverage)] //~ ERROR feature has been removed [E0557] + +#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(coverage)` +struct Foo { + a: u8, + b: u32, +} + +#[coverage(off)] //~ ERROR the `#[coverage]` attribute is an experimental feature +fn requires_feature_coverage() -> bool { + let bar = Foo { a: 0, b: 0 }; + bar == Foo { a: 0, b: 0 } +} diff --git a/tests/ui/feature-gates/feature-gate-coverage-attribute.stderr b/tests/ui/feature-gates/feature-gate-coverage-attribute.stderr new file mode 100644 index 00000000000..0131a19a39d --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-coverage-attribute.stderr @@ -0,0 +1,21 @@ +error[E0557]: feature has been removed + --> $DIR/feature-gate-coverage-attribute.rs:2:12 + | +LL | #![feature(no_coverage)] + | ^^^^^^^^^^^ feature has been removed + | + = note: renamed to `coverage_attribute` + +error[E0658]: the `#[coverage]` attribute is an experimental feature + --> $DIR/feature-gate-coverage-attribute.rs:10:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information + = help: add `#![feature(coverage_attribute)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0557, E0658. +For more information about an error, try `rustc --explain E0557`. diff --git a/tests/ui/feature-gates/feature-gate-no_coverage.rs b/tests/ui/feature-gates/feature-gate-no_coverage.rs deleted file mode 100644 index fd4c6f76059..00000000000 --- a/tests/ui/feature-gates/feature-gate-no_coverage.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![crate_type = "lib"] - -#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(no_coverage)` -struct Foo { - a: u8, - b: u32, -} - -#[no_coverage] //~ ERROR the `#[no_coverage]` attribute is an experimental feature -fn requires_feature_no_coverage() -> bool { - let bar = Foo { a: 0, b: 0 }; - bar == Foo { a: 0, b: 0 } -} diff --git a/tests/ui/feature-gates/feature-gate-no_coverage.stderr b/tests/ui/feature-gates/feature-gate-no_coverage.stderr deleted file mode 100644 index f7167e0b771..00000000000 --- a/tests/ui/feature-gates/feature-gate-no_coverage.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: the `#[no_coverage]` attribute is an experimental feature - --> $DIR/feature-gate-no_coverage.rs:9:1 - | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ - | - = note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information - = help: add `#![feature(no_coverage)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs b/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs index aad64c9d073..8bb9736f1b4 100644 --- a/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs +++ b/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs @@ -1,11 +1,5 @@ // check-pass -#![warn(private_interfaces)] //~ WARN unknown lint - //~| WARN unknown lint - //~| WARN unknown lint -#![warn(private_bounds)] //~ WARN unknown lint - //~| WARN unknown lint - //~| WARN unknown lint #![warn(unnameable_types)] //~ WARN unknown lint //~| WARN unknown lint //~| WARN unknown lint diff --git a/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr b/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr index 79cc974cca1..4349fea6f89 100644 --- a/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr +++ b/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr @@ -1,26 +1,5 @@ -warning: unknown lint: `private_interfaces` - --> $DIR/feature-gate-type_privacy_lints.rs:3:1 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `private_interfaces` lint is unstable - = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information - = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable - = note: `#[warn(unknown_lints)]` on by default - -warning: unknown lint: `private_bounds` - --> $DIR/feature-gate-type_privacy_lints.rs:6:1 - | -LL | #![warn(private_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `private_bounds` lint is unstable - = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information - = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable - warning: unknown lint: `unnameable_types` - --> $DIR/feature-gate-type_privacy_lints.rs:9:1 + --> $DIR/feature-gate-type_privacy_lints.rs:3:1 | LL | #![warn(unnameable_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,29 +7,10 @@ LL | #![warn(unnameable_types)] = note: the `unnameable_types` lint is unstable = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable - -warning: unknown lint: `private_interfaces` - --> $DIR/feature-gate-type_privacy_lints.rs:3:1 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `private_interfaces` lint is unstable - = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information - = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable - -warning: unknown lint: `private_bounds` - --> $DIR/feature-gate-type_privacy_lints.rs:6:1 - | -LL | #![warn(private_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `private_bounds` lint is unstable - = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information - = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable + = note: `#[warn(unknown_lints)]` on by default warning: unknown lint: `unnameable_types` - --> $DIR/feature-gate-type_privacy_lints.rs:9:1 + --> $DIR/feature-gate-type_privacy_lints.rs:3:1 | LL | #![warn(unnameable_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,28 +19,8 @@ LL | #![warn(unnameable_types)] = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable -warning: unknown lint: `private_interfaces` - --> $DIR/feature-gate-type_privacy_lints.rs:3:1 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `private_interfaces` lint is unstable - = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information - = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable - -warning: unknown lint: `private_bounds` - --> $DIR/feature-gate-type_privacy_lints.rs:6:1 - | -LL | #![warn(private_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `private_bounds` lint is unstable - = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information - = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable - warning: unknown lint: `unnameable_types` - --> $DIR/feature-gate-type_privacy_lints.rs:9:1 + --> $DIR/feature-gate-type_privacy_lints.rs:3:1 | LL | #![warn(unnameable_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,5 +29,5 @@ LL | #![warn(unnameable_types)] = note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable -warning: 9 warnings emitted +warning: 3 warnings emitted diff --git a/tests/ui/feature-gates/print-with-path.cfg.stderr b/tests/ui/feature-gates/print-with-path.cfg.stderr deleted file mode 100644 index a6c51baa320..00000000000 --- a/tests/ui/feature-gates/print-with-path.cfg.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: the `-Z unstable-options` flag must also be passed to enable the path print option - diff --git a/tests/ui/feature-gates/print-with-path.rs b/tests/ui/feature-gates/print-with-path.rs deleted file mode 100644 index f929c14c218..00000000000 --- a/tests/ui/feature-gates/print-with-path.rs +++ /dev/null @@ -1,7 +0,0 @@ -// check-fail -// revisions: cfg target-features target-cpus -// [cfg]compile-flags: --print cfg=cfg.txt -// [target-cpus]compile-flags: --print target-cpu=target_cpu.txt -// [target-features]compile-flags: --print target-features=target_features.txt - -fn main() {} diff --git a/tests/ui/feature-gates/print-with-path.target-cpus.stderr b/tests/ui/feature-gates/print-with-path.target-cpus.stderr deleted file mode 100644 index a6c51baa320..00000000000 --- a/tests/ui/feature-gates/print-with-path.target-cpus.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: the `-Z unstable-options` flag must also be passed to enable the path print option - diff --git a/tests/ui/feature-gates/print-with-path.target-features.stderr b/tests/ui/feature-gates/print-with-path.target-features.stderr deleted file mode 100644 index a6c51baa320..00000000000 --- a/tests/ui/feature-gates/print-with-path.target-features.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: the `-Z unstable-options` flag must also be passed to enable the path print option - diff --git a/tests/ui/fmt/raw-idents.rs b/tests/ui/fmt/raw-idents.rs new file mode 100644 index 00000000000..29a74c55a4a --- /dev/null +++ b/tests/ui/fmt/raw-idents.rs @@ -0,0 +1,17 @@ +// Regression test for https://github.com/rust-lang/rust/issues/115466 + +// The "identifier" in format strings is parsed as an IDENTIFIER_OR_KEYWORD, not an IDENTIFIER. +// Test that there is an actionable diagnostic if a RAW_IDENTIFIER is used instead. + +fn main() { + let r#type = "foobar"; + println!("It is {r#type}"); //~ ERROR: invalid format string: raw identifiers are not supported + println!(r##"It still is {r#type}"##); //~ ERROR: invalid format string: raw identifiers are not supported + println!(concat!("{r#", "type}")); //~ ERROR: invalid format string: raw identifiers are not supported + println!("{\x72\x23type:?}"); //~ ERROR: invalid format string: raw identifiers are not supported + + // OK + println!("{type}"); + println!("{let}", let = r#type); + println!("{let}", r#let = r#type); +} diff --git a/tests/ui/fmt/raw-idents.stderr b/tests/ui/fmt/raw-idents.stderr new file mode 100644 index 00000000000..2ddc114d286 --- /dev/null +++ b/tests/ui/fmt/raw-idents.stderr @@ -0,0 +1,44 @@ +error: invalid format string: raw identifiers are not supported + --> $DIR/raw-idents.rs:8:22 + | +LL | println!("It is {r#type}"); + | --^^^^ + | | + | raw identifier used here in format string + | help: remove the `r#` + | + = note: identifiers in format strings can be keywords and don't need to be prefixed with `r#` + +error: invalid format string: raw identifiers are not supported + --> $DIR/raw-idents.rs:9:31 + | +LL | println!(r##"It still is {r#type}"##); + | --^^^^ + | | + | raw identifier used here in format string + | help: remove the `r#` + | + = note: identifiers in format strings can be keywords and don't need to be prefixed with `r#` + +error: invalid format string: raw identifiers are not supported + --> $DIR/raw-idents.rs:10:14 + | +LL | println!(concat!("{r#", "type}")); + | ^^^^^^^^^^^^^^^^^^^^^^^ raw identifier used here in format string + | + = note: identifiers in format strings can be keywords and don't need to be prefixed with `r#` + = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: invalid format string: raw identifiers are not supported + --> $DIR/raw-idents.rs:11:16 + | +LL | println!("{\x72\x23type:?}"); + | --------^^^^ + | | + | raw identifier used here in format string + | help: remove the `r#` + | + = note: identifiers in format strings can be keywords and don't need to be prefixed with `r#` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/fn/fn-pointer-mismatch.stderr b/tests/ui/fn/fn-pointer-mismatch.stderr index a674babcb32..87ece845b83 100644 --- a/tests/ui/fn/fn-pointer-mismatch.stderr +++ b/tests/ui/fn/fn-pointer-mismatch.stderr @@ -80,7 +80,6 @@ LL | let e: &fn(u32) -> u32 = &foo; = note: expected reference `&fn(u32) -> u32` found reference `&fn(u32) -> u32 {foo}` = note: fn items are distinct from fn pointers - = note: when the arguments and return types match, functions can be coerced to function pointers help: consider casting to a fn pointer | LL | let e: &fn(u32) -> u32 = &(foo as fn(u32) -> u32); diff --git a/tests/ui/fn/keyword-order.stderr b/tests/ui/fn/keyword-order.stderr index d3b140c8528..97d8f91b1ee 100644 --- a/tests/ui/fn/keyword-order.stderr +++ b/tests/ui/fn/keyword-order.stderr @@ -11,6 +11,8 @@ error: expected item, found keyword `pub` | LL | default pub const async unsafe extern fn err() {} | ^^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 2 previous errors diff --git a/tests/ui/fn/signature-error-reporting-under-verbose.rs b/tests/ui/fn/signature-error-reporting-under-verbose.rs index 12ff113c913..d00cbd8a0f2 100644 --- a/tests/ui/fn/signature-error-reporting-under-verbose.rs +++ b/tests/ui/fn/signature-error-reporting-under-verbose.rs @@ -12,5 +12,4 @@ fn main() { //~| NOTE expected fn pointer, found fn item //~| NOTE expected fn pointer `fn(i32, u32)` //~| NOTE arguments to this function are incorrect - //~| NOTE when the arguments and return types match, functions can be coerced to function pointers } diff --git a/tests/ui/fn/signature-error-reporting-under-verbose.stderr b/tests/ui/fn/signature-error-reporting-under-verbose.stderr index f4498db7259..067ee824d5d 100644 --- a/tests/ui/fn/signature-error-reporting-under-verbose.stderr +++ b/tests/ui/fn/signature-error-reporting-under-verbose.stderr @@ -8,7 +8,6 @@ LL | needs_ptr(foo); | = note: expected fn pointer `fn(i32, u32)` found fn item `fn(i32, i32) {foo}` - = note: when the arguments and return types match, functions can be coerced to function pointers note: function defined here --> $DIR/signature-error-reporting-under-verbose.rs:5:4 | diff --git a/tests/ui/generic-associated-types/issue-101020.stderr b/tests/ui/generic-associated-types/issue-101020.stderr index 5c8db617c17..91967fb8509 100644 --- a/tests/ui/generic-associated-types/issue-101020.stderr +++ b/tests/ui/generic-associated-types/issue-101020.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<'a> &'a mut (): Foo<&'a mut ()>` is not satis LL | (&mut EmptyIter).consume(()); | ^^^^^^^ the trait `for<'a> Foo<&'a mut ()>` is not implemented for `&'a mut ()` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-101020.rs:28:1 + | +LL | trait Foo<T> {} + | ^^^^^^^^^^^^ note: required for `&'a mut ()` to implement `for<'a> FuncInput<'a, &'a mut ()>` --> $DIR/issue-101020.rs:27:20 | diff --git a/tests/ui/generics/issue-94432-garbage-ice.rs b/tests/ui/generics/issue-94432-garbage-ice.rs index d0709e2d2a4..4ddb3a7e9f8 100644 --- a/tests/ui/generics/issue-94432-garbage-ice.rs +++ b/tests/ui/generics/issue-94432-garbage-ice.rs @@ -4,7 +4,7 @@ fn�a<e>(){fn�p(){e}} //~ ERROR unknown start of token: \u{fffd} //~^ ERROR unknown start of token: \u{fffd} -//~^^ ERROR can't use generic parameters from outer function [E0401] +//~^^ ERROR can't use generic parameters from outer item [E0401] //~^^^ WARN type parameter `e` should have an upper camel case name fn main(){} diff --git a/tests/ui/generics/issue-98432.rs b/tests/ui/generics/issue-98432.rs index 780c50d6ffa..c31dea76c09 100644 --- a/tests/ui/generics/issue-98432.rs +++ b/tests/ui/generics/issue-98432.rs @@ -2,7 +2,7 @@ struct Struct<T>(T); impl<T> Struct<T> { const CONST: fn() = || { - struct _Obligation where T:; //~ ERROR can't use generic parameters from outer function + struct _Obligation where T:; //~ ERROR can't use generic parameters from outer item }; } diff --git a/tests/ui/generics/issue-98432.stderr b/tests/ui/generics/issue-98432.stderr index c7b5c33618d..0736d94106e 100644 --- a/tests/ui/generics/issue-98432.stderr +++ b/tests/ui/generics/issue-98432.stderr @@ -1,13 +1,13 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-98432.rs:5:34 | LL | impl<T> Struct<T> { - | - type parameter from outer function + | - type parameter from outer item LL | const CONST: fn() = || { LL | struct _Obligation where T:; - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<T>` + | help: try introducing a local generic parameter here: `<T>` error: aborting due to previous error diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-89118.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-89118.stderr index edef6ccd34e..7fe803550bd 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-89118.stderr +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-89118.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied LL | C: StackContext, | ^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-89118.rs:1:1 + | +LL | trait BufferMut {} + | ^^^^^^^^^^^^^^^ note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>` --> $DIR/issue-89118.rs:5:23 | @@ -26,6 +31,11 @@ error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied LL | impl<C> EthernetWorker<C> {} | ^^^^^^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-89118.rs:1:1 + | +LL | trait BufferMut {} + | ^^^^^^^^^^^^^^^ note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>` --> $DIR/issue-89118.rs:5:23 | @@ -48,6 +58,11 @@ error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied LL | type Handler = Ctx<C::Dispatcher>; | ^^^^^^^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-89118.rs:1:1 + | +LL | trait BufferMut {} + | ^^^^^^^^^^^^^^^ note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>` --> $DIR/issue-89118.rs:5:23 | diff --git a/tests/ui/impl-trait/async_scope_creep.rs b/tests/ui/impl-trait/async_scope_creep.rs index 7a9d64d339f..9a8831a299e 100644 --- a/tests/ui/impl-trait/async_scope_creep.rs +++ b/tests/ui/impl-trait/async_scope_creep.rs @@ -1,6 +1,7 @@ #![feature(type_alias_impl_trait)] // edition:2021 -// check-pass +//[rpit] check-pass +// revisions: tait rpit struct Pending {} @@ -12,15 +13,23 @@ impl AsyncRead for i32 {} type PendingReader<'a> = impl AsyncRead + 'a; -type OpeningReadFuture<'a> = - impl std::future::Future<Output = Result<PendingReader<'a>, CantOpen>>; +#[cfg(tait)] +type OpeningReadFuture<'a> = impl std::future::Future<Output = Result<PendingReader<'a>, CantOpen>>; impl Pending { async fn read(&mut self) -> Result<impl AsyncRead + '_, CantOpen> { Ok(42) } + #[cfg(tait)] fn read_fut(&mut self) -> OpeningReadFuture<'_> { + self.read() //[tait]~ ERROR: cannot satisfy `impl AsyncRead + 'a == PendingReader<'a>` + } + + #[cfg(rpit)] + fn read_fut( + &mut self, + ) -> impl std::future::Future<Output = Result<PendingReader<'_>, CantOpen>> { self.read() } } diff --git a/tests/ui/impl-trait/async_scope_creep.tait.stderr b/tests/ui/impl-trait/async_scope_creep.tait.stderr new file mode 100644 index 00000000000..165096a0574 --- /dev/null +++ b/tests/ui/impl-trait/async_scope_creep.tait.stderr @@ -0,0 +1,9 @@ +error[E0284]: type annotations needed: cannot satisfy `impl AsyncRead + 'a == PendingReader<'a>` + --> $DIR/async_scope_creep.rs:26:9 + | +LL | self.read() + | ^^^^^^^^^^^ cannot satisfy `impl AsyncRead + 'a == PendingReader<'a>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs index cfc2193f633..6e99402113a 100644 --- a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs +++ b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs @@ -1,4 +1,4 @@ -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] use std::ops::Deref; @@ -8,6 +8,7 @@ pub trait Foo { pub struct Foreign; impl Foo for Foreign { + #[expect(refining_impl_trait)] fn bar(self) -> &'static () { &() } diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs index ff7ad4bf389..fbbbb8585d1 100644 --- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs +++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.rs @@ -2,7 +2,7 @@ #![feature(return_position_impl_trait_in_trait)] -trait Iterable { +pub trait Iterable { type Item<'a> where Self: 'a; @@ -17,6 +17,7 @@ impl<'a, I: 'a + Iterable> Iterable for &'a I { //~^ ERROR impl has stricter requirements than trait fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> { + //~^ WARN impl trait in impl method signature does not match trait method signature (*self).iter() } } diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr index 106b8a7c804..a5fb338ea4e 100644 --- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr +++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr @@ -12,6 +12,22 @@ help: copy the `where` clause predicates from the trait LL | where Self: 'b; | ~~~~~~~~~~~~~~ -error: aborting due to previous error +warning: impl trait in impl method signature does not match trait method signature + --> $DIR/bad-item-bound-within-rpitit.rs:19:28 + | +LL | fn iter(&self) -> impl '_ + Iterator<Item = Self::Item<'_>>; + | ----------------------------------------- return type from trait method defined here +... +LL | fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> { + | ^^ this bound is stronger than that defined on the trait + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: `#[warn(refining_impl_trait)]` on by default +help: replace the return type so that it matches the trait + | +LL | fn iter(&self) -> impl Iterator<Item = <Self as Iterable>::Item<'_>> + '_ { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error; 1 warning emitted For more information about this error, try `rustc --explain E0276`. diff --git a/tests/ui/impl-trait/in-trait/deep-match-works.rs b/tests/ui/impl-trait/in-trait/deep-match-works.rs index 78cff97c616..fc290f11f9d 100644 --- a/tests/ui/impl-trait/in-trait/deep-match-works.rs +++ b/tests/ui/impl-trait/in-trait/deep-match-works.rs @@ -1,15 +1,16 @@ // check-pass -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] #![allow(incomplete_features)] -struct Wrapper<T>(T); +pub struct Wrapper<T>(T); -trait Foo { +pub trait Foo { fn bar() -> Wrapper<impl Sized>; } impl Foo for () { + #[expect(refining_impl_trait)] fn bar() -> Wrapper<i32> { Wrapper(0) } diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs index b0c93a02935..6285d7786d5 100644 --- a/tests/ui/impl-trait/in-trait/foreign.rs +++ b/tests/ui/impl-trait/in-trait/foreign.rs @@ -1,14 +1,25 @@ // check-pass // aux-build: rpitit.rs +#![feature(lint_reasons)] + extern crate rpitit; use rpitit::{Foo, Foreign}; use std::sync::Arc; // Implement an RPITIT from another crate. -struct Local; +pub struct Local; impl Foo for Local { + #[expect(refining_impl_trait)] + fn bar(self) -> Arc<String> { + Arc::new(String::new()) + } +} + +struct LocalIgnoreRefining; +impl Foo for LocalIgnoreRefining { + #[deny(refining_impl_trait)] fn bar(self) -> Arc<String> { Arc::new(String::new()) } @@ -23,4 +34,5 @@ fn main() { let &() = Foreign.bar(); let x: Arc<String> = Local.bar(); + let x: Arc<String> = LocalIgnoreRefining.bar(); } diff --git a/tests/ui/impl-trait/in-trait/issue-102140.stderr b/tests/ui/impl-trait/in-trait/issue-102140.stderr index 5d55b9fa4f9..18bb63745d7 100644 --- a/tests/ui/impl-trait/in-trait/issue-102140.stderr +++ b/tests/ui/impl-trait/in-trait/issue-102140.stderr @@ -6,7 +6,11 @@ LL | MyTrait::foo(&self) | | | required by a bound introduced by this call | - = help: the trait `MyTrait` is implemented for `Outer` +help: consider removing the leading `&`-reference + | +LL - MyTrait::foo(&self) +LL + MyTrait::foo(self) + | error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied --> $DIR/issue-102140.rs:23:9 diff --git a/tests/ui/impl-trait/in-trait/issue-102571.rs b/tests/ui/impl-trait/in-trait/issue-102571.rs index 61c91e64417..ccb53031c44 100644 --- a/tests/ui/impl-trait/in-trait/issue-102571.rs +++ b/tests/ui/impl-trait/in-trait/issue-102571.rs @@ -8,14 +8,6 @@ trait Foo { fn bar(self) -> impl Deref<Target = impl Display + ?Sized>; } -struct A; - -impl Foo for A { - fn bar(self) -> &'static str { - "Hello, world" - } -} - fn foo<T: Foo>(t: T) { let () = t.bar(); //~^ ERROR mismatched types diff --git a/tests/ui/impl-trait/in-trait/issue-102571.stderr b/tests/ui/impl-trait/in-trait/issue-102571.stderr index 87219941d91..594b9ae9cd6 100644 --- a/tests/ui/impl-trait/in-trait/issue-102571.stderr +++ b/tests/ui/impl-trait/in-trait/issue-102571.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-102571.rs:20:9 + --> $DIR/issue-102571.rs:12:9 | LL | let () = t.bar(); | ^^ ------- this expression has type `impl Deref<Target = impl std::fmt::Display + ?Sized>` diff --git a/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs b/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs new file mode 100644 index 00000000000..49d36d6c99c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs @@ -0,0 +1,19 @@ +// check-pass + +#![feature(associated_type_bounds, return_position_impl_trait_in_trait)] + +trait Trait { + type Type; + + fn method(&self) -> impl Trait<Type: '_>; +} + +impl Trait for () { + type Type = (); + + fn method(&self) -> impl Trait<Type: '_> { + () + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/nested-rpitit.rs b/tests/ui/impl-trait/in-trait/nested-rpitit.rs index 65285e3a3cc..58ba1acaf14 100644 --- a/tests/ui/impl-trait/in-trait/nested-rpitit.rs +++ b/tests/ui/impl-trait/in-trait/nested-rpitit.rs @@ -1,26 +1,28 @@ // check-pass -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] #![allow(incomplete_features)] use std::fmt::Display; use std::ops::Deref; -trait Foo { +pub trait Foo { fn bar(self) -> impl Deref<Target = impl Display + ?Sized>; } -struct A; +pub struct A; impl Foo for A { + #[expect(refining_impl_trait)] fn bar(self) -> &'static str { "Hello, world" } } -struct B; +pub struct B; impl Foo for B { + #[expect(refining_impl_trait)] fn bar(self) -> Box<i32> { Box::new(42) } diff --git a/tests/ui/impl-trait/in-trait/object-safety-sized.rs b/tests/ui/impl-trait/in-trait/object-safety-sized.rs new file mode 100644 index 00000000000..f221cfbb176 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/object-safety-sized.rs @@ -0,0 +1,23 @@ +// check-pass +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + +#![feature(return_position_impl_trait_in_trait)] + +fn main() { + let vec: Vec<Box<dyn Trait>> = Vec::new(); + + for i in vec { + i.fn_2(); + } +} + +trait OtherTrait {} + +trait Trait { + fn fn_1(&self) -> impl OtherTrait + where + Self: Sized; + + fn fn_2(&self) -> bool; +} diff --git a/tests/ui/impl-trait/in-trait/object-safety.rs b/tests/ui/impl-trait/in-trait/object-safety.rs index 9a231e59b09..d1c9fba4e99 100644 --- a/tests/ui/impl-trait/in-trait/object-safety.rs +++ b/tests/ui/impl-trait/in-trait/object-safety.rs @@ -8,7 +8,7 @@ trait Foo { } impl Foo for u32 { - fn baz(&self) -> u32 { + fn baz(&self) -> impl Debug { 32 } } diff --git a/tests/ui/impl-trait/in-trait/refine.rs b/tests/ui/impl-trait/in-trait/refine.rs new file mode 100644 index 00000000000..a91f9b3e722 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/refine.rs @@ -0,0 +1,48 @@ +#![feature(return_position_impl_trait_in_trait, async_fn_in_trait)] +#![deny(refining_impl_trait)] + +pub trait Foo { + fn bar() -> impl Sized; +} + +pub struct A; +impl Foo for A { + fn bar() -> impl Copy {} + //~^ ERROR impl method signature does not match trait method signature +} + +pub struct B; +impl Foo for B { + fn bar() {} + //~^ ERROR impl method signature does not match trait method signature +} + +pub struct C; +impl Foo for C { + fn bar() -> () {} + //~^ ERROR impl method signature does not match trait method signature +} + +struct Private; +impl Foo for Private { + fn bar() -> () {} +} + +pub trait Arg<A> { + fn bar() -> impl Sized; +} +impl Arg<Private> for A { + fn bar() -> () {} +} + +pub trait Late { + fn bar<'a>(&'a self) -> impl Sized + 'a; +} + +pub struct D; +impl Late for D { + fn bar(&self) -> impl Copy + '_ {} + //~^ ERROR impl method signature does not match trait method signature +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/refine.stderr b/tests/ui/impl-trait/in-trait/refine.stderr new file mode 100644 index 00000000000..29aa08e25bb --- /dev/null +++ b/tests/ui/impl-trait/in-trait/refine.stderr @@ -0,0 +1,67 @@ +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:10:22 + | +LL | fn bar() -> impl Sized; + | ---------- return type from trait method defined here +... +LL | fn bar() -> impl Copy {} + | ^^^^ this bound is stronger than that defined on the trait + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate +note: the lint level is defined here + --> $DIR/refine.rs:2:9 + | +LL | #![deny(refining_impl_trait)] + | ^^^^^^^^^^^^^^^^^^^ +help: replace the return type so that it matches the trait + | +LL | fn bar() -> impl Sized {} + | ~~~~~~~~~~ + +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:16:5 + | +LL | fn bar() -> impl Sized; + | ---------- return type from trait method defined here +... +LL | fn bar() {} + | ^^^^^^^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate +help: replace the return type so that it matches the trait + | +LL | fn bar() -> impl Sized {} + | +++++++++++++ + +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:22:17 + | +LL | fn bar() -> impl Sized; + | ---------- return type from trait method defined here +... +LL | fn bar() -> () {} + | ^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate +help: replace the return type so that it matches the trait + | +LL | fn bar() -> impl Sized {} + | ~~~~~~~~~~ + +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:44:27 + | +LL | fn bar<'a>(&'a self) -> impl Sized + 'a; + | --------------- return type from trait method defined here +... +LL | fn bar(&self) -> impl Copy + '_ {} + | ^^^^ this bound is stronger than that defined on the trait + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate +help: replace the return type so that it matches the trait + | +LL | fn bar(&self) -> impl Sized + '_ {} + | ~~~~~~~~~~~~~~~ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/impl-trait/in-trait/reveal.rs b/tests/ui/impl-trait/in-trait/reveal.rs index d6ede1cc495..b1b46d75b8f 100644 --- a/tests/ui/impl-trait/in-trait/reveal.rs +++ b/tests/ui/impl-trait/in-trait/reveal.rs @@ -1,13 +1,14 @@ // check-pass -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] #![allow(incomplete_features)] -trait Foo { +pub trait Foo { fn f() -> Box<impl Sized>; } impl Foo for () { + #[expect(refining_impl_trait)] fn f() -> Box<String> { Box::new(String::new()) } diff --git a/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs b/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs index 7682884f879..44a2b430344 100644 --- a/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs +++ b/tests/ui/impl-trait/in-trait/rpitit-shadowed-by-missing-adt.rs @@ -1,6 +1,6 @@ // issue: 113903 -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] use std::ops::Deref; @@ -10,6 +10,7 @@ pub trait Tr { } impl Tr for () { + #[expect(refining_impl_trait)] fn w() -> &'static () { &() } diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr b/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr index 186580f5756..468cf12f1bc 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.failure.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/signature-mismatch.rs:77:10 + --> $DIR/signature-mismatch.rs:79:10 | LL | &'a self, | -------- this parameter and the return type are declared with different lifetimes... diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.rs b/tests/ui/impl-trait/in-trait/signature-mismatch.rs index c84a3b8f46b..685c0f06e88 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.rs +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.rs @@ -2,18 +2,17 @@ // revisions: success failure //[success] check-pass -#![feature(return_position_impl_trait_in_trait)] -#![allow(incomplete_features)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] use std::future::Future; -trait Captures<'a> {} +pub trait Captures<'a> {} impl<T> Captures<'_> for T {} -trait Captures2<'a, 'b> {} +pub trait Captures2<'a, 'b> {} impl<T> Captures2<'_, '_> for T {} -trait AsyncTrait { +pub trait AsyncTrait { #[cfg(success)] fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>; @@ -45,6 +44,7 @@ impl AsyncTrait for Struct { // Does not capture more lifetimes that trait def'n, since trait def'n // implicitly captures all in-scope lifetimes. #[cfg(success)] + #[expect(refining_impl_trait)] fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { async move { buff.to_vec() } } @@ -52,6 +52,7 @@ impl AsyncTrait for Struct { // Does not capture more lifetimes that trait def'n, since trait def'n // implicitly captures all in-scope lifetimes. #[cfg(success)] + #[expect(refining_impl_trait)] fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { async move { buff.to_vec() } } @@ -59,6 +60,7 @@ impl AsyncTrait for Struct { // Does not capture more lifetimes that trait def'n, since trait def'n // implicitly captures all in-scope lifetimes. #[cfg(success)] + #[expect(refining_impl_trait)] fn async_fn_multiple<'a, 'b>( &'a self, buff: &'b [u8], diff --git a/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs b/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs index c9ee877db8e..41fc285883a 100644 --- a/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs +++ b/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs @@ -1,10 +1,10 @@ // check-pass #![feature(specialization)] -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] #![allow(incomplete_features)] -trait Foo { +pub trait Foo { fn bar(&self) -> impl Sized; } @@ -12,6 +12,7 @@ impl<U> Foo for U where U: Copy, { + #[expect(refining_impl_trait)] fn bar(&self) -> U { *self } diff --git a/tests/ui/impl-trait/in-trait/success.rs b/tests/ui/impl-trait/in-trait/success.rs index 4cbe682b46f..7d415ea17a4 100644 --- a/tests/ui/impl-trait/in-trait/success.rs +++ b/tests/ui/impl-trait/in-trait/success.rs @@ -1,29 +1,32 @@ // check-pass -#![feature(return_position_impl_trait_in_trait)] +#![feature(return_position_impl_trait_in_trait, lint_reasons)] #![allow(incomplete_features)] use std::fmt::Display; -trait Foo { +pub trait Foo { fn bar(&self) -> impl Display; } impl Foo for i32 { + #[expect(refining_impl_trait)] fn bar(&self) -> i32 { *self } } impl Foo for &'static str { + #[expect(refining_impl_trait)] fn bar(&self) -> &'static str { *self } } -struct Yay; +pub struct Yay; impl Foo for Yay { + #[expect(refining_impl_trait)] fn bar(&self) -> String { String::from(":^)") } diff --git a/tests/ui/impl-trait/issue-108591.rs b/tests/ui/impl-trait/issue-108591.rs index 6b9d14941f2..91ea2e9fb85 100644 --- a/tests/ui/impl-trait/issue-108591.rs +++ b/tests/ui/impl-trait/issue-108591.rs @@ -13,7 +13,8 @@ impl MyTy<'_> { } } -type Opaque<'a> = impl Sized; +type Opaque2 = impl Sized; +type Opaque<'a> = Opaque2; fn define<'a>() -> Opaque<'a> {} fn test<'a>() { diff --git a/tests/ui/impl-trait/issue-108592.rs b/tests/ui/impl-trait/issue-108592.rs index 58a0ed9bf1a..953fffc4898 100644 --- a/tests/ui/impl-trait/issue-108592.rs +++ b/tests/ui/impl-trait/issue-108592.rs @@ -11,7 +11,8 @@ fn test_closure() { closure(&opaque()); } -type Opaque<'a> = impl Sized; +type Opaque2 = impl Sized; +type Opaque<'a> = Opaque2; fn define<'a>() -> Opaque<'a> {} fn test_tait(_: &Opaque<'_>) { diff --git a/tests/ui/impl-trait/issue-86465.rs b/tests/ui/impl-trait/issue-86465.rs index 8c7b41d73b7..a79bb6474d8 100644 --- a/tests/ui/impl-trait/issue-86465.rs +++ b/tests/ui/impl-trait/issue-86465.rs @@ -1,10 +1,6 @@ #![feature(type_alias_impl_trait)] -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type X<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type X<'a, 'b> = impl std::fmt::Debug; fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) { (a, a) diff --git a/tests/ui/impl-trait/issue-86465.stderr b/tests/ui/impl-trait/issue-86465.stderr index b949b2b4245..90d6904ed61 100644 --- a/tests/ui/impl-trait/issue-86465.stderr +++ b/tests/ui/impl-trait/issue-86465.stderr @@ -1,5 +1,5 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/issue-86465.rs:10:5 + --> $DIR/issue-86465.rs:6:5 | LL | (a, a) | ^^^^^^ diff --git a/tests/ui/impl-trait/lifetime-ambiguity-regression.rs b/tests/ui/impl-trait/lifetime-ambiguity-regression.rs new file mode 100644 index 00000000000..ce6ae3786e1 --- /dev/null +++ b/tests/ui/impl-trait/lifetime-ambiguity-regression.rs @@ -0,0 +1,13 @@ +//! This test shows a situation where through subtle compiler changes we can +//! suddenly infer a different lifetime in the hidden type, and thus not meet +//! the opaque type bounds anymore. In this case `'a` and `'b` are equal, so +//! picking either is fine, but then we'll fail an identity check of the hidden +//! type and the expected hidden type. + +// check-pass + +fn test<'a: 'b, 'b: 'a>() -> impl IntoIterator<Item = (&'a u8, impl Into<(&'b u8, &'a u8)>)> { + None::<(_, (_, _))> +} + +fn main() {} diff --git a/tests/ui/implied-bounds/implied-bounds-unconstrained-1.rs b/tests/ui/implied-bounds/implied-bounds-unconstrained-1.rs new file mode 100644 index 00000000000..025e5176ff7 --- /dev/null +++ b/tests/ui/implied-bounds/implied-bounds-unconstrained-1.rs @@ -0,0 +1,28 @@ +// check-pass + +// Regression test for #112832. +pub trait QueryDb { + type Db; +} + +pub struct QueryTable<Q, DB> { + db: DB, + storage: Q, +} + +// We normalize `<Q as QueryDb>::Db` to `<Q as AsyncQueryFunction<'d>>::SendDb` +// using the where-bound. 'd is an unconstrained region variable which previously +// triggered an assert. +impl<Q> QueryTable<Q, <Q as QueryDb>::Db> where Q: for<'d> AsyncQueryFunction<'d> {} + +pub trait AsyncQueryFunction<'d>: QueryDb<Db = <Self as AsyncQueryFunction<'d>>::SendDb> { + type SendDb: 'd; +} + +pub trait QueryStorageOpsAsync<Q> +where + Q: for<'d> AsyncQueryFunction<'d>, +{ +} + +fn main() {} diff --git a/tests/ui/implied-bounds/implied-bounds-unconstrained-2.rs b/tests/ui/implied-bounds/implied-bounds-unconstrained-2.rs new file mode 100644 index 00000000000..976054facee --- /dev/null +++ b/tests/ui/implied-bounds/implied-bounds-unconstrained-2.rs @@ -0,0 +1,20 @@ +// check-pass + +// Another minimized regression test for #112832. +trait Trait { + type Assoc; +} + +trait Sub<'a>: Trait<Assoc = <Self as Sub<'a>>::SubAssoc> { + type SubAssoc; +} + +// By using the where-clause we normalize `<T as Trait>::Assoc` to +// `<T as Sub<'a>>::SubAssoc` where `'a` is an unconstrained region +// variable. +fn foo<T>(x: <T as Trait>::Assoc) +where + for<'a> T: Sub<'a>, +{} + +fn main() {} diff --git a/tests/ui/imports/ambiguous-4.rs b/tests/ui/imports/ambiguous-4.rs index 10f883339c3..24ae33784c5 100644 --- a/tests/ui/imports/ambiguous-4.rs +++ b/tests/ui/imports/ambiguous-4.rs @@ -1,4 +1,4 @@ -// check-pass +// build-pass // aux-build: ../ambiguous-4-extern.rs extern crate ambiguous_4_extern; diff --git a/tests/ui/imports/import-after-macro-expand-10.rs b/tests/ui/imports/import-after-macro-expand-10.rs new file mode 100644 index 00000000000..b3520c42dfc --- /dev/null +++ b/tests/ui/imports/import-after-macro-expand-10.rs @@ -0,0 +1,17 @@ +// check-pass + +mod b { + pub mod http { + pub struct HeaderMap; + } + + pub use self::http::*; + #[derive(Debug)] + pub struct HeaderMap; +} + +use crate::b::*; + +fn main() { + let h: crate::b::HeaderMap = HeaderMap; +} diff --git a/tests/ui/imports/import-after-macro-expand-11.rs b/tests/ui/imports/import-after-macro-expand-11.rs new file mode 100644 index 00000000000..2b81dfc236a --- /dev/null +++ b/tests/ui/imports/import-after-macro-expand-11.rs @@ -0,0 +1,21 @@ +// check-pass + +#[derive(Debug)] +struct H; + +mod p { + use super::*; + + #[derive(Clone)] + struct H; + + mod t { + use super::*; + + fn f() { + let h: crate::p::H = H; + } + } +} + +fn main() {} diff --git a/tests/ui/imports/import-after-macro-expand-12.rs b/tests/ui/imports/import-after-macro-expand-12.rs new file mode 100644 index 00000000000..f92e8c12fca --- /dev/null +++ b/tests/ui/imports/import-after-macro-expand-12.rs @@ -0,0 +1,34 @@ +// check-pass +// https://github.com/rust-lang/rust/issues/115377 + +use module::*; + +mod module { + pub enum B {} + impl B { + pub const ASSOC: u8 = 0; + } +} + +#[derive()] +pub enum B {} +impl B { + pub const ASSOC: u16 = 0; +} + +macro_rules! m { + ($right:expr) => { + $right + }; +} + +fn main() { + let a: u16 = { + use self::*; + B::ASSOC + }; + let b: u16 = m!({ + use self::*; + B::ASSOC + }); +} diff --git a/tests/ui/imports/import-after-macro-expand-13.rs b/tests/ui/imports/import-after-macro-expand-13.rs new file mode 100644 index 00000000000..fd640002c3e --- /dev/null +++ b/tests/ui/imports/import-after-macro-expand-13.rs @@ -0,0 +1,22 @@ +// check-pass +// similar as `import-after-macro-expand-6.rs` + +use crate::a::HeaderMap; + +mod b { + pub mod http { + pub struct HeaderMap; + } + + pub use self::http::*; + #[derive(Debug)] + pub struct HeaderMap; +} + +mod a { + pub use crate::b::*; +} + +fn main() { + let h: crate::b::HeaderMap = HeaderMap; +} diff --git a/tests/ui/imports/import-after-macro-expand-14.rs b/tests/ui/imports/import-after-macro-expand-14.rs new file mode 100644 index 00000000000..4d461a0e20c --- /dev/null +++ b/tests/ui/imports/import-after-macro-expand-14.rs @@ -0,0 +1,22 @@ +// check-pass + +use crate::a::HeaderMap; + +mod b { + pub mod http { + #[derive(Clone)] + pub struct HeaderMap; + } + + pub use self::http::*; + #[derive(Debug)] + pub struct HeaderMap; +} + +mod a { + pub use crate::b::*; +} + +fn main() { + let h: crate::b::HeaderMap = HeaderMap; +} diff --git a/tests/ui/imports/import-after-macro-expand-2.rs b/tests/ui/imports/import-after-macro-expand-2.rs index b3996d48840..ff773fc8272 100644 --- a/tests/ui/imports/import-after-macro-expand-2.rs +++ b/tests/ui/imports/import-after-macro-expand-2.rs @@ -12,9 +12,7 @@ mod tests { use super::*; fn test_thing() { - let thing: crate::thing::Thing = Thing::Bar; - // FIXME: `thing` should refer to `crate::Thing`, - // FIXME: but doesn't currently refer to it due to backward compatibility + let thing: crate::Thing = Thing::Foo; } } diff --git a/tests/ui/imports/import-after-macro-expand-4.rs b/tests/ui/imports/import-after-macro-expand-4.rs index 02cc3f01af9..fc0a232a93c 100644 --- a/tests/ui/imports/import-after-macro-expand-4.rs +++ b/tests/ui/imports/import-after-macro-expand-4.rs @@ -1,3 +1,4 @@ +// check-pass // https://github.com/rust-lang/rust/pull/113242#issuecomment-1616034904 // similar with `import-after-macro-expand-2.rs` @@ -10,16 +11,6 @@ pub use a::*; mod c { use crate::*; pub struct S(Vec<P>); - //~^ ERROR the size for values of type - //~| WARNING trait objects without an explicit - //~| WARNING this is accepted in the current edition - //~| WARNING trait objects without an explicit - //~| WARNING this is accepted in the current edition - //~| WARNING trait objects without an explicit - //~| WARNING this is accepted in the current edition - - // FIXME: should works, but doesn't currently refer - // to it due to backward compatibility } #[derive(Clone)] diff --git a/tests/ui/imports/import-after-macro-expand-4.stderr b/tests/ui/imports/import-after-macro-expand-4.stderr deleted file mode 100644 index 01f70cfc5bf..00000000000 --- a/tests/ui/imports/import-after-macro-expand-4.stderr +++ /dev/null @@ -1,53 +0,0 @@ -warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/import-after-macro-expand-4.rs:12:22 - | -LL | pub struct S(Vec<P>); - | ^ - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> - = note: `#[warn(bare_trait_objects)]` on by default -help: use `dyn` - | -LL | pub struct S(Vec<dyn P>); - | +++ - -warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/import-after-macro-expand-4.rs:12:22 - | -LL | pub struct S(Vec<P>); - | ^ - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> -help: use `dyn` - | -LL | pub struct S(Vec<dyn P>); - | +++ - -warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/import-after-macro-expand-4.rs:12:22 - | -LL | pub struct S(Vec<P>); - | ^ - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> -help: use `dyn` - | -LL | pub struct S(Vec<dyn P>); - | +++ - -error[E0277]: the size for values of type `(dyn a::P + 'static)` cannot be known at compilation time - --> $DIR/import-after-macro-expand-4.rs:12:18 - | -LL | pub struct S(Vec<P>); - | ^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `(dyn a::P + 'static)` -note: required by a bound in `Vec` - --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - -error: aborting due to previous error; 3 warnings emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/imports/import-after-macro-expand-6.rs b/tests/ui/imports/import-after-macro-expand-6.rs index ab5bb37a175..bff8efebca6 100644 --- a/tests/ui/imports/import-after-macro-expand-6.rs +++ b/tests/ui/imports/import-after-macro-expand-6.rs @@ -18,7 +18,5 @@ mod b { use crate::a::HeaderMap; fn main() { - let h: crate::b::http::HeaderMap = HeaderMap; - // FIXME: should refer to `crate::b::HeaderMap`, - // FIXME: but doesn't currently refer to it due to backward compatibility + let h: crate::b::HeaderMap = HeaderMap; } diff --git a/tests/ui/imports/import-after-macro-expand-9.rs b/tests/ui/imports/import-after-macro-expand-9.rs new file mode 100644 index 00000000000..deee42c3b84 --- /dev/null +++ b/tests/ui/imports/import-after-macro-expand-9.rs @@ -0,0 +1,17 @@ +// check-pass + +use crate::b::*; + +mod b { + pub mod http { + pub struct HeaderMap; + } + + pub use self::http::*; + #[derive(Debug)] + pub struct HeaderMap; +} + +fn main() { + let h: crate::b::HeaderMap = HeaderMap; +} diff --git a/tests/ui/infinite/infinite-type-alias-mutual-recursion.feature.stderr b/tests/ui/infinite/infinite-type-alias-mutual-recursion.feature.stderr new file mode 100644 index 00000000000..8b8fc46dfc5 --- /dev/null +++ b/tests/ui/infinite/infinite-type-alias-mutual-recursion.feature.stderr @@ -0,0 +1,27 @@ +error[E0275]: overflow evaluating the requirement `X2` + --> $DIR/infinite-type-alias-mutual-recursion.rs:6:11 + | +LL | type X1 = X2; + | ^^ + | + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + +error[E0275]: overflow evaluating the requirement `X3` + --> $DIR/infinite-type-alias-mutual-recursion.rs:9:11 + | +LL | type X2 = X3; + | ^^ + | + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + +error[E0275]: overflow evaluating the requirement `X1` + --> $DIR/infinite-type-alias-mutual-recursion.rs:11:11 + | +LL | type X3 = X1; + | ^^ + | + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/infinite/infinite-type-alias-mutual-recursion.stderr b/tests/ui/infinite/infinite-type-alias-mutual-recursion.gated.stderr index bbdb1f70b80..ec63688fa8b 100644 --- a/tests/ui/infinite/infinite-type-alias-mutual-recursion.stderr +++ b/tests/ui/infinite/infinite-type-alias-mutual-recursion.gated.stderr @@ -1,16 +1,16 @@ error[E0391]: cycle detected when expanding type alias `X1` - --> $DIR/infinite-type-alias-mutual-recursion.rs:1:11 + --> $DIR/infinite-type-alias-mutual-recursion.rs:6:11 | LL | type X1 = X2; | ^^ | note: ...which requires expanding type alias `X2`... - --> $DIR/infinite-type-alias-mutual-recursion.rs:3:11 + --> $DIR/infinite-type-alias-mutual-recursion.rs:9:11 | LL | type X2 = X3; | ^^ note: ...which requires expanding type alias `X3`... - --> $DIR/infinite-type-alias-mutual-recursion.rs:4:11 + --> $DIR/infinite-type-alias-mutual-recursion.rs:11:11 | LL | type X3 = X1; | ^^ @@ -19,12 +19,13 @@ LL | type X3 = X1; = help: consider using a struct, enum, or union instead to break the cycle = help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information note: cycle used when collecting item types in top-level module - --> $DIR/infinite-type-alias-mutual-recursion.rs:1:1 + --> $DIR/infinite-type-alias-mutual-recursion.rs:3:1 | -LL | / type X1 = X2; +LL | / #![cfg_attr(feature, feature(lazy_type_alias))] +LL | | #![allow(incomplete_features)] LL | | -LL | | type X2 = X3; -LL | | type X3 = X1; +LL | | type X1 = X2; +... | LL | | LL | | fn main() {} | |____________^ diff --git a/tests/ui/infinite/infinite-type-alias-mutual-recursion.rs b/tests/ui/infinite/infinite-type-alias-mutual-recursion.rs index 5381eedcfac..90c941c634e 100644 --- a/tests/ui/infinite/infinite-type-alias-mutual-recursion.rs +++ b/tests/ui/infinite/infinite-type-alias-mutual-recursion.rs @@ -1,6 +1,14 @@ +// revisions: feature gated + +#![cfg_attr(feature, feature(lazy_type_alias))] +#![allow(incomplete_features)] + type X1 = X2; -//~^ ERROR cycle detected when expanding type alias `X1` +//[gated]~^ ERROR cycle detected when expanding type alias `X1` +//[feature]~^^ ERROR: overflow evaluating the requirement `X2` type X2 = X3; +//[feature]~^ ERROR: overflow evaluating the requirement `X3` type X3 = X1; +//[feature]~^ ERROR: overflow evaluating the requirement `X1` fn main() {} diff --git a/tests/ui/infinite/infinite-vec-type-recursion.feature.stderr b/tests/ui/infinite/infinite-vec-type-recursion.feature.stderr new file mode 100644 index 00000000000..3a146215905 --- /dev/null +++ b/tests/ui/infinite/infinite-vec-type-recursion.feature.stderr @@ -0,0 +1,11 @@ +error[E0275]: overflow evaluating the requirement `X` + --> $DIR/infinite-vec-type-recursion.rs:6:10 + | +LL | type X = Vec<X>; + | ^^^^^^ + | + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/infinite/infinite-vec-type-recursion.stderr b/tests/ui/infinite/infinite-vec-type-recursion.gated.stderr index a21b033a9a9..e47d9b652fb 100644 --- a/tests/ui/infinite/infinite-vec-type-recursion.stderr +++ b/tests/ui/infinite/infinite-vec-type-recursion.gated.stderr @@ -1,5 +1,5 @@ error[E0391]: cycle detected when expanding type alias `X` - --> $DIR/infinite-vec-type-recursion.rs:1:14 + --> $DIR/infinite-vec-type-recursion.rs:6:14 | LL | type X = Vec<X>; | ^ @@ -9,11 +9,14 @@ LL | type X = Vec<X>; = help: consider using a struct, enum, or union instead to break the cycle = help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information note: cycle used when collecting item types in top-level module - --> $DIR/infinite-vec-type-recursion.rs:1:1 + --> $DIR/infinite-vec-type-recursion.rs:3:1 | -LL | / type X = Vec<X>; -LL | | +LL | / #![cfg_attr(feature, feature(lazy_type_alias))] +LL | | #![allow(incomplete_features)] LL | | +LL | | type X = Vec<X>; +... | +LL | | #[rustfmt::skip] LL | | fn main() { let b: X = Vec::new(); } | |____________________________________^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information diff --git a/tests/ui/infinite/infinite-vec-type-recursion.rs b/tests/ui/infinite/infinite-vec-type-recursion.rs index 35681822598..71ab4a33013 100644 --- a/tests/ui/infinite/infinite-vec-type-recursion.rs +++ b/tests/ui/infinite/infinite-vec-type-recursion.rs @@ -1,4 +1,11 @@ +// revisions: feature gated + +#![cfg_attr(feature, feature(lazy_type_alias))] +#![allow(incomplete_features)] + type X = Vec<X>; -//~^ ERROR cycle detected +//[gated]~^ ERROR cycle detected +//[feature]~^^ ERROR: overflow evaluating the requirement `X` +#[rustfmt::skip] fn main() { let b: X = Vec::new(); } diff --git a/tests/ui/inner-static-type-parameter.rs b/tests/ui/inner-static-type-parameter.rs index c08ccd29d80..a1994e7529c 100644 --- a/tests/ui/inner-static-type-parameter.rs +++ b/tests/ui/inner-static-type-parameter.rs @@ -4,7 +4,7 @@ enum Bar<T> { What } //~ ERROR parameter `T` is never used fn foo<T>() { static a: Bar<T> = Bar::What; -//~^ ERROR can't use generic parameters from outer function +//~^ ERROR can't use generic parameters from outer item } fn main() { diff --git a/tests/ui/inner-static-type-parameter.stderr b/tests/ui/inner-static-type-parameter.stderr index e4e449e4159..ff6558e494b 100644 --- a/tests/ui/inner-static-type-parameter.stderr +++ b/tests/ui/inner-static-type-parameter.stderr @@ -1,10 +1,10 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/inner-static-type-parameter.rs:6:19 | LL | fn foo<T>() { - | - type parameter from outer function + | - type parameter from outer item LL | static a: Bar<T> = Bar::What; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error[E0392]: parameter `T` is never used --> $DIR/inner-static-type-parameter.rs:3:10 diff --git a/tests/ui/issues/issue-10764.stderr b/tests/ui/issues/issue-10764.stderr index fcb45affe2c..4d8a85a1397 100644 --- a/tests/ui/issues/issue-10764.stderr +++ b/tests/ui/issues/issue-10764.stderr @@ -8,7 +8,6 @@ LL | fn main() { f(bar) } | = note: expected fn pointer `fn()` found fn item `extern "C" fn() {bar}` - = note: when the arguments and return types match, functions can be coerced to function pointers note: function defined here --> $DIR/issue-10764.rs:1:4 | diff --git a/tests/ui/issues/issue-18389.rs b/tests/ui/issues/issue-18389.rs index 05a5decf462..26b607f4081 100644 --- a/tests/ui/issues/issue-18389.rs +++ b/tests/ui/issues/issue-18389.rs @@ -1,9 +1,4 @@ -#![feature(type_privacy_lints)] -#![warn(private_bounds)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. +// check-pass use std::any::Any; use std::any::TypeId; @@ -12,8 +7,7 @@ trait Private<P, R> { fn call(&self, p: P, r: R); } pub trait Public: Private< -//~^ ERROR private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface -//~| WARNING trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public` +//~^ WARNING trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public` <Self as Public>::P, <Self as Public>::R > { diff --git a/tests/ui/issues/issue-18389.stderr b/tests/ui/issues/issue-18389.stderr index 18ffc4177d7..4706d1ba177 100644 --- a/tests/ui/issues/issue-18389.stderr +++ b/tests/ui/issues/issue-18389.stderr @@ -1,39 +1,19 @@ -error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface - --> $DIR/issue-18389.rs:14:1 - | -LL | trait Private<P, R> { - | ------------------- `Private<<Self as Public>::P, <Self as Public>::R>` declared as private -... -LL | / pub trait Public: Private< -LL | | -LL | | -LL | | <Self as Public>::P, -LL | | <Self as Public>::R -LL | | > { - | |_^ can't leak private trait - warning: trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public` - --> $DIR/issue-18389.rs:14:1 + --> $DIR/issue-18389.rs:9:1 | LL | / pub trait Public: Private< LL | | -LL | | LL | | <Self as Public>::P, LL | | <Self as Public>::R LL | | > { | |_^ trait `Public` is reachable at visibility `pub` | note: but trait `Private<<Self as Public>::P, <Self as Public>::R>` is only usable at visibility `pub(crate)` - --> $DIR/issue-18389.rs:11:1 + --> $DIR/issue-18389.rs:6:1 | LL | trait Private<P, R> { | ^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/issue-18389.rs:2:9 - | -LL | #![warn(private_bounds)] - | ^^^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default -error: aborting due to previous error; 1 warning emitted +warning: 1 warning emitted -For more information about this error, try `rustc --explain E0445`. diff --git a/tests/ui/issues/issue-18611.stderr b/tests/ui/issues/issue-18611.stderr index bd18d46223e..784b9b984e9 100644 --- a/tests/ui/issues/issue-18611.stderr +++ b/tests/ui/issues/issue-18611.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `isize: HasState` is not satisfied | LL | fn add_state(op: <isize as HasState>::State) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasState` is not implemented for `isize` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-18611.rs:5:1 + | +LL | trait HasState { + | ^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/issues/issue-25076.stderr b/tests/ui/issues/issue-25076.stderr index 159cc484c5d..065bf7def42 100644 --- a/tests/ui/issues/issue-25076.stderr +++ b/tests/ui/issues/issue-25076.stderr @@ -6,6 +6,11 @@ LL | do_fold(bot(), ()); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/issue-25076.rs:3:1 + | +LL | trait InOut<T> { type Out; } + | ^^^^^^^^^^^^^^ note: required by a bound in `do_fold` --> $DIR/issue-25076.rs:5:18 | diff --git a/tests/ui/issues/issue-3214.rs b/tests/ui/issues/issue-3214.rs index e3c07bb3f72..b2c27f5be95 100644 --- a/tests/ui/issues/issue-3214.rs +++ b/tests/ui/issues/issue-3214.rs @@ -1,6 +1,6 @@ fn foo<T>() { struct Foo { - x: T, //~ ERROR can't use generic parameters from outer function + x: T, //~ ERROR can't use generic parameters from outer item } impl<T> Drop for Foo<T> { diff --git a/tests/ui/issues/issue-3214.stderr b/tests/ui/issues/issue-3214.stderr index 7a2d772f0a1..5b57c1baf90 100644 --- a/tests/ui/issues/issue-3214.stderr +++ b/tests/ui/issues/issue-3214.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-3214.rs:3:12 | LL | fn foo<T>() { - | - type parameter from outer function + | - type parameter from outer item LL | struct Foo { - | - help: try using a local generic parameter instead: `<T>` + | - help: try introducing a local generic parameter here: `<T>` LL | x: T, - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-3214.rs:6:22 diff --git a/tests/ui/issues/issue-35570.stderr b/tests/ui/issues/issue-35570.stderr index 2697d46bdb2..197e80ac097 100644 --- a/tests/ui/issues/issue-35570.stderr +++ b/tests/ui/issues/issue-35570.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied | LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) { | ^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-35570.rs:4:1 + | +LL | trait Trait2<'a> { + | ^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/issues/issue-5997-enum.rs b/tests/ui/issues/issue-5997-enum.rs index 3ff4e036c60..0b1857ae3df 100644 --- a/tests/ui/issues/issue-5997-enum.rs +++ b/tests/ui/issues/issue-5997-enum.rs @@ -1,6 +1,6 @@ fn f<Z>() -> bool { enum E { V(Z) } - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item true } diff --git a/tests/ui/issues/issue-5997-enum.stderr b/tests/ui/issues/issue-5997-enum.stderr index 3a79215d3ae..d07258ea7a2 100644 --- a/tests/ui/issues/issue-5997-enum.stderr +++ b/tests/ui/issues/issue-5997-enum.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-5997-enum.rs:2:16 | LL | fn f<Z>() -> bool { - | - type parameter from outer function + | - type parameter from outer item LL | enum E { V(Z) } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<Z>` + | help: try introducing a local generic parameter here: `<Z>` error: aborting due to previous error diff --git a/tests/ui/issues/issue-5997-struct.rs b/tests/ui/issues/issue-5997-struct.rs index 6cf510b0a9d..19d994b0dfb 100644 --- a/tests/ui/issues/issue-5997-struct.rs +++ b/tests/ui/issues/issue-5997-struct.rs @@ -1,5 +1,5 @@ fn f<T>() -> bool { - struct S(T); //~ ERROR can't use generic parameters from outer function + struct S(T); //~ ERROR can't use generic parameters from outer item true } diff --git a/tests/ui/issues/issue-5997-struct.stderr b/tests/ui/issues/issue-5997-struct.stderr index d2e97f76771..83229e02c6c 100644 --- a/tests/ui/issues/issue-5997-struct.stderr +++ b/tests/ui/issues/issue-5997-struct.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-5997-struct.rs:2:14 | LL | fn f<T>() -> bool { - | - type parameter from outer function + | - type parameter from outer item LL | struct S(T); - | -^ use of generic parameter from outer function + | -^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<T>` + | help: try introducing a local generic parameter here: `<T>` error: aborting due to previous error diff --git a/tests/ui/issues/issue-60218.stderr b/tests/ui/issues/issue-60218.stderr index 563690c9a5d..ae3c4d12025 100644 --- a/tests/ui/issues/issue-60218.stderr +++ b/tests/ui/issues/issue-60218.stderr @@ -6,6 +6,11 @@ LL | trigger_error(vec![], |x: &u32| x) | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/issue-60218.rs:7:1 + | +LL | pub trait Foo {} + | ^^^^^^^^^^^^^ note: required by a bound in `trigger_error` --> $DIR/issue-60218.rs:13:72 | diff --git a/tests/ui/issues/issue-66353.stderr b/tests/ui/issues/issue-66353.stderr index 71530f58220..7ab7547b42d 100644 --- a/tests/ui/issues/issue-66353.stderr +++ b/tests/ui/issues/issue-66353.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): _A` is not satisfied | LL | _Func::< <() as _A>::AssocT >::func(()); | ^^ the trait `_A` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-66353.rs:7:1 + | +LL | trait _A { + | ^^^^^^^^ error[E0277]: the trait bound `(): _Func<_>` is not satisfied --> $DIR/issue-66353.rs:12:41 @@ -11,6 +17,12 @@ LL | _Func::< <() as _A>::AssocT >::func(()); | ----------------------------------- ^^ the trait `_Func<_>` is not implemented for `()` | | | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-66353.rs:3:1 + | +LL | trait _Func<T> { + | ^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/layout/debug.rs b/tests/ui/layout/debug.rs index b74a8d3b917..65f2f3b89af 100644 --- a/tests/ui/layout/debug.rs +++ b/tests/ui/layout/debug.rs @@ -17,6 +17,9 @@ type Test = Result<i32, i32>; //~ ERROR: layout_of #[rustc_layout(debug)] type T = impl std::fmt::Debug; //~ ERROR: layout_of +fn f() -> T { + 0i32 +} #[rustc_layout(debug)] pub union V { //~ ERROR: layout_of @@ -63,6 +66,13 @@ union P5 { zst: [u16; 0], byte: u8 } //~ ERROR: layout_of #[rustc_layout(debug)] type X = std::mem::MaybeUninit<u8>; //~ ERROR: layout_of -fn f() -> T { - 0i32 +#[rustc_layout(debug)] +const C: () = (); //~ ERROR: can only be applied to + +impl S { + #[rustc_layout(debug)] + const C: () = (); //~ ERROR: can only be applied to } + +#[rustc_layout(debug)] +type Impossible = (str, str); //~ ERROR: cannot be known at compilation time diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr index c20a0198ccb..5162a771b4d 100644 --- a/tests/ui/layout/debug.stderr +++ b/tests/ui/layout/debug.stderr @@ -162,7 +162,7 @@ error: layout_of(U) = Layout { LL | union U { f1: (i32, i32), f3: i32 } | ^^^^^^^ -error: layout_of(std::result::Result<i32, i32>) = Layout { +error: layout_of(Result<i32, i32>) = Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), @@ -344,7 +344,7 @@ error: layout_of(V) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:22:1 + --> $DIR/debug.rs:25:1 | LL | pub union V { | ^^^^^^^^^^^ @@ -368,7 +368,7 @@ error: layout_of(W) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:28:1 + --> $DIR/debug.rs:31:1 | LL | pub union W { | ^^^^^^^^^^^ @@ -392,7 +392,7 @@ error: layout_of(Y) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:34:1 + --> $DIR/debug.rs:37:1 | LL | pub union Y { | ^^^^^^^^^^^ @@ -416,7 +416,7 @@ error: layout_of(P1) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:41:1 + --> $DIR/debug.rs:44:1 | LL | union P1 { x: u32 } | ^^^^^^^^ @@ -440,7 +440,7 @@ error: layout_of(P2) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:45:1 + --> $DIR/debug.rs:48:1 | LL | union P2 { x: (u32, u32) } | ^^^^^^^^ @@ -464,7 +464,7 @@ error: layout_of(P3) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:53:1 + --> $DIR/debug.rs:56:1 | LL | union P3 { x: F32x4 } | ^^^^^^^^ @@ -488,7 +488,7 @@ error: layout_of(P4) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:57:1 + --> $DIR/debug.rs:60:1 | LL | union P4 { x: E } | ^^^^^^^^ @@ -517,12 +517,12 @@ error: layout_of(P5) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:61:1 + --> $DIR/debug.rs:64:1 | LL | union P5 { zst: [u16; 0], byte: u8 } | ^^^^^^^^ -error: layout_of(std::mem::MaybeUninit<u8>) = Layout { +error: layout_of(MaybeUninit<u8>) = Layout { size: Size(1 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), @@ -546,10 +546,32 @@ error: layout_of(std::mem::MaybeUninit<u8>) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:64:1 + --> $DIR/debug.rs:67:1 | LL | type X = std::mem::MaybeUninit<u8>; | ^^^^^^ -error: aborting due to 14 previous errors +error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases + --> $DIR/debug.rs:70:1 + | +LL | const C: () = (); + | ^^^^^^^^^^^ + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/debug.rs:78:19 + | +LL | type Impossible = (str, str); + | ^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: only the last element of a tuple may have a dynamically sized type + +error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases + --> $DIR/debug.rs:74:5 + | +LL | const C: () = (); + | ^^^^^^^^^^^ + +error: aborting due to 17 previous errors +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/layout/homogeneous-aggr-transparent.rs b/tests/ui/layout/homogeneous-aggr-transparent.rs new file mode 100644 index 00000000000..9703d2bf294 --- /dev/null +++ b/tests/ui/layout/homogeneous-aggr-transparent.rs @@ -0,0 +1,44 @@ +#![feature(rustc_attrs)] +#![feature(transparent_unions)] +use std::marker::PhantomData; + +// Regression test for #115664. We want to ensure that `repr(transparent)` wrappers do not affect +// the result of `homogeneous_aggregate`. + +type Tuple = (f32, f32, f32); + +struct Zst; + +#[repr(transparent)] +struct Wrapper1<T>(T); +#[repr(transparent)] +struct Wrapper2<T>((), Zst, T); +#[repr(transparent)] +struct Wrapper3<T>(T, [u8; 0], PhantomData<u64>); +#[repr(transparent)] +union WrapperUnion<T: Copy> { + nothing: (), + something: T, +} + +#[rustc_layout(homogeneous_aggregate)] +pub type Test0 = Tuple; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test1 = Wrapper1<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test2 = Wrapper2<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test3 = Wrapper3<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +#[rustc_layout(homogeneous_aggregate)] +pub type Test4 = WrapperUnion<Tuple>; +//~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + +fn main() {} diff --git a/tests/ui/layout/homogeneous-aggr-transparent.stderr b/tests/ui/layout/homogeneous-aggr-transparent.stderr new file mode 100644 index 00000000000..99eb703ac82 --- /dev/null +++ b/tests/ui/layout/homogeneous-aggr-transparent.stderr @@ -0,0 +1,32 @@ +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:25:1 + | +LL | pub type Test0 = Tuple; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:29:1 + | +LL | pub type Test1 = Wrapper1<Tuple>; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:33:1 + | +LL | pub type Test2 = Wrapper2<Tuple>; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:37:1 + | +LL | pub type Test3 = Wrapper3<Tuple>; + | ^^^^^^^^^^^^^^ + +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) })) + --> $DIR/homogeneous-aggr-transparent.rs:41:1 + | +LL | pub type Test4 = WrapperUnion<Tuple>; + | ^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/ui/layout/layout-cycle.rs b/tests/ui/layout/layout-cycle.rs new file mode 100644 index 00000000000..85685058e49 --- /dev/null +++ b/tests/ui/layout/layout-cycle.rs @@ -0,0 +1,31 @@ +// build-fail +//~^ ERROR: a cycle occurred during layout computation +//~| ERROR: cycle detected when computing layout of + +// Issue #111176 -- ensure that we do not emit ICE on layout cycles + +use std::mem; + +pub struct S<T: Tr> { + pub f: <T as Tr>::I, +} + +pub trait Tr { + type I: Tr; +} + +impl<T: Tr> Tr for S<T> { + type I = S<S<T>>; +} + +impl Tr for () { + type I = (); +} + +fn foo<T: Tr>() -> usize { + mem::size_of::<S<T>>() +} + +fn main() { + println!("{}", foo::<S<()>>()); +} diff --git a/tests/ui/layout/layout-cycle.stderr b/tests/ui/layout/layout-cycle.stderr new file mode 100644 index 00000000000..a3cdb7edcc2 --- /dev/null +++ b/tests/ui/layout/layout-cycle.stderr @@ -0,0 +1,11 @@ +error[E0391]: cycle detected when computing layout of `S<S<()>>` + | + = note: ...which requires computing layout of `<S<()> as Tr>::I`... + = note: ...which again requires computing layout of `S<S<()>>`, completing the cycle + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: failed to get layout for S<S<()>>: a cycle occurred during layout computation + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/layout/zero-sized-array-enum-niche.stderr b/tests/ui/layout/zero-sized-array-enum-niche.stderr index df9f1cc8d10..8161f97dde0 100644 --- a/tests/ui/layout/zero-sized-array-enum-niche.stderr +++ b/tests/ui/layout/zero-sized-array-enum-niche.stderr @@ -1,4 +1,4 @@ -error: layout_of(std::result::Result<[u32; 0], bool>) = Layout { +error: layout_of(Result<[u32; 0], bool>) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), @@ -232,7 +232,7 @@ error: layout_of(MultipleAlignments) = Layout { LL | enum MultipleAlignments { | ^^^^^^^^^^^^^^^^^^^^^^^ -error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) = Layout { +error: layout_of(Result<[u32; 0], Packed<NonZeroU16>>) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), @@ -337,7 +337,7 @@ error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) = LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>; | ^^^^^^^^^^^^^^^^^^^^^^^ -error: layout_of(std::result::Result<[u32; 0], Packed<U16IsZero>>) = Layout { +error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), diff --git a/tests/ui/lifetimes/anonymize-unnamed-bound-vars-in-binders.rs b/tests/ui/lifetimes/anonymize-unnamed-bound-vars-in-binders.rs new file mode 100644 index 00000000000..05e3763e9d1 --- /dev/null +++ b/tests/ui/lifetimes/anonymize-unnamed-bound-vars-in-binders.rs @@ -0,0 +1,27 @@ +// build-pass +// issue: #115807 + +trait Chip: for<'a> TraitWithLifetime<'a> + SomeMarker { + fn compute(&self); +} + +trait SomeMarker {} + +trait TraitWithLifetime<'a>: SomeMarker {} + +trait Machine { + fn run(); +} + +struct BasicMachine; + +impl Machine for BasicMachine { + fn run() { + let chips: [&dyn Chip; 0] = []; + let _ = chips.map(|chip| chip.compute()); + } +} + +fn main() { + BasicMachine::run(); +} diff --git a/tests/ui/lifetimes/issue-95023.stderr b/tests/ui/lifetimes/issue-95023.stderr index 5b93eff8614..6361d8ad30b 100644 --- a/tests/ui/lifetimes/issue-95023.stderr +++ b/tests/ui/lifetimes/issue-95023.stderr @@ -36,7 +36,7 @@ error[E0220]: associated type `B` not found for `Self` --> $DIR/issue-95023.rs:6:44 | LL | fn foo<const N: usize>(&self) -> Self::B<{N}>; - | ^ associated type `B` not found + | ^ help: `Self` has the following associated type: `Output` error: aborting due to 5 previous errors diff --git a/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr b/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr index ef1127c59ac..421ab3fcf4e 100644 --- a/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr +++ b/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `Result<(), _>: Future` is not satisfied | LL | fn foo() -> impl Future<Item=(), Error=Box<dyn Error>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Future` is not implemented for `Result<(), _>` + | +help: this trait has no implementations, consider adding one + --> $DIR/lifetime-elision-return-type-trait.rs:1:1 + | +LL | trait Future { + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/limits/issue-55878.stderr b/tests/ui/limits/issue-55878.stderr index 510b36edd8f..f0c7210dde7 100644 --- a/tests/ui/limits/issue-55878.stderr +++ b/tests/ui/limits/issue-55878.stderr @@ -1,6 +1,8 @@ -error[E0080]: values of the type `[u8; usize::MAX]` are too big for the current architecture +error[E0080]: evaluation of constant value failed --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | + = note: values of the type `[u8; usize::MAX]` are too big for the current architecture + | note: inside `std::mem::size_of::<[u8; usize::MAX]>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL note: inside `main` diff --git a/tests/ui/limits/issue-56762.rs b/tests/ui/limits/issue-56762.rs index ed7ee4da85d..1c7facb045d 100644 --- a/tests/ui/limits/issue-56762.rs +++ b/tests/ui/limits/issue-56762.rs @@ -14,8 +14,10 @@ impl TooBigArray { } static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); -//~^ ERROR values of the type `[u8; 2305843009213693951]` are too big +//~^ ERROR could not evaluate static initializer +//~| too big static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; -//~^ ERROR values of the type `[u8; 2305843009213693951]` are too big +//~^ ERROR could not evaluate static initializer +//~| too big fn main() { } diff --git a/tests/ui/limits/issue-56762.stderr b/tests/ui/limits/issue-56762.stderr index 29f2a8859ee..3a6c3559ac1 100644 --- a/tests/ui/limits/issue-56762.stderr +++ b/tests/ui/limits/issue-56762.stderr @@ -1,14 +1,14 @@ -error[E0080]: values of the type `[u8; 2305843009213693951]` are too big for the current architecture +error[E0080]: could not evaluate static initializer --> $DIR/issue-56762.rs:16:1 | LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843009213693951]` are too big for the current architecture -error[E0080]: values of the type `[u8; 2305843009213693951]` are too big for the current architecture - --> $DIR/issue-56762.rs:18:1 +error[E0080]: could not evaluate static initializer + --> $DIR/issue-56762.rs:19:1 | LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843009213693951]` are too big for the current architecture error: aborting due to 2 previous errors diff --git a/tests/ui/linkage-attr/common-linkage-non-zero-init.rs b/tests/ui/linkage-attr/common-linkage-non-zero-init.rs new file mode 100644 index 00000000000..ce8d9848e42 --- /dev/null +++ b/tests/ui/linkage-attr/common-linkage-non-zero-init.rs @@ -0,0 +1,14 @@ +// build-fail +// failure-status: 101 +// known-bug: #109681 + +// This test verifies that we continue to hit the LLVM error for common linkage with non-zero +// initializers, since it generates invalid LLVM IR. +// Linkages are internal features marked as perma-unstable, so we don't need to fix the issue +// for now. +#![crate_type="lib"] +#![feature(linkage)] + +#[linkage = "common"] +#[no_mangle] +pub static TEST: bool = true; diff --git a/tests/ui/linkage-attr/common-linkage-non-zero-init.stderr b/tests/ui/linkage-attr/common-linkage-non-zero-init.stderr new file mode 100644 index 00000000000..667bb3ec130 --- /dev/null +++ b/tests/ui/linkage-attr/common-linkage-non-zero-init.stderr @@ -0,0 +1,3 @@ +'common' global must have a zero initializer! +ptr @TEST +LLVM ERROR: Broken module found, compilation aborted! diff --git a/tests/ui/lint-group-forbid-always-trumps-cli.stderr b/tests/ui/lint-group-forbid-always-trumps-cli.stderr index 8910af87ca2..cd042179cce 100644 --- a/tests/ui/lint-group-forbid-always-trumps-cli.stderr +++ b/tests/ui/lint-group-forbid-always-trumps-cli.stderr @@ -5,6 +5,7 @@ LL | let x = 1; | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `-F unused-variables` implied by `-F unused` + = help: to override `-F unused` add `#[allow(unused_variables)]` error: aborting due to previous error diff --git a/tests/ui/lint/cli-unknown-force-warn.rs b/tests/ui/lint/cli-unknown-force-warn.rs index f3dea87a6b6..a9e4e4a6017 100644 --- a/tests/ui/lint/cli-unknown-force-warn.rs +++ b/tests/ui/lint/cli-unknown-force-warn.rs @@ -1,7 +1,11 @@ // Checks that rustc correctly errors when passed an invalid lint with // `--force-warn`. This is a regression test for issue #86958. -// + +// check-pass // compile-flags: --force-warn foo-qux + // error-pattern: unknown lint: `foo_qux` +// error-pattern: requested on the command line with `--force-warn foo_qux` +// error-pattern: `#[warn(unknown_lints)]` on by default fn main() {} diff --git a/tests/ui/lint/cli-unknown-force-warn.stderr b/tests/ui/lint/cli-unknown-force-warn.stderr index 9ce9f405aee..2ee718a8c8e 100644 --- a/tests/ui/lint/cli-unknown-force-warn.stderr +++ b/tests/ui/lint/cli-unknown-force-warn.stderr @@ -1,11 +1,16 @@ -error[E0602]: unknown lint: `foo_qux` +warning[E0602]: unknown lint: `foo_qux` | = note: requested on the command line with `--force-warn foo_qux` + = note: `#[warn(unknown_lints)]` on by default -error[E0602]: unknown lint: `foo_qux` +warning[E0602]: unknown lint: `foo_qux` | = note: requested on the command line with `--force-warn foo_qux` -error: aborting due to 2 previous errors +warning[E0602]: unknown lint: `foo_qux` + | + = note: requested on the command line with `--force-warn foo_qux` + +warning: 3 warnings emitted For more information about this error, try `rustc --explain E0602`. diff --git a/tests/ui/lint/command-line-lint-group-deny.stderr b/tests/ui/lint/command-line-lint-group-deny.stderr index 04c3f6f2637..59d8429ea69 100644 --- a/tests/ui/lint/command-line-lint-group-deny.stderr +++ b/tests/ui/lint/command-line-lint-group-deny.stderr @@ -5,6 +5,7 @@ LL | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing` | = note: `-D non-snake-case` implied by `-D bad-style` + = help: to override `-D bad-style` add `#[allow(non_snake_case)]` error: aborting due to previous error diff --git a/tests/ui/lint/command-line-lint-group-forbid.stderr b/tests/ui/lint/command-line-lint-group-forbid.stderr index 73678214063..486d32a9f08 100644 --- a/tests/ui/lint/command-line-lint-group-forbid.stderr +++ b/tests/ui/lint/command-line-lint-group-forbid.stderr @@ -5,6 +5,7 @@ LL | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing` | = note: `-F non-snake-case` implied by `-F bad-style` + = help: to override `-F bad-style` add `#[allow(non_snake_case)]` error: aborting due to previous error diff --git a/tests/ui/lint/command-line-lint-group-warn.stderr b/tests/ui/lint/command-line-lint-group-warn.stderr index e9c80b4ef21..cfe346a5bf6 100644 --- a/tests/ui/lint/command-line-lint-group-warn.stderr +++ b/tests/ui/lint/command-line-lint-group-warn.stderr @@ -5,6 +5,7 @@ LL | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing` | = note: `-W non-snake-case` implied by `-W bad-style` + = help: to override `-W bad-style` add `#[allow(non_snake_case)]` warning: 1 warning emitted diff --git a/tests/ui/lint/expr-field.rs b/tests/ui/lint/expr-field.rs new file mode 100644 index 00000000000..638fbf521c4 --- /dev/null +++ b/tests/ui/lint/expr-field.rs @@ -0,0 +1,15 @@ +// check-pass + +pub struct A { + pub x: u32, +} + +#[deny(unused_comparisons)] +pub fn foo(y: u32) -> A { + A { + #[allow(unused_comparisons)] + x: if y < 0 { 1 } else { 2 }, + } +} + +fn main() {} diff --git a/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr b/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr index d1b764b3414..01c2ed84c63 100644 --- a/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr +++ b/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr @@ -7,6 +7,7 @@ LL | 0...100 => true, = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> = note: `--force-warn ellipsis-inclusive-range-patterns` implied by `--force-warn rust-2021-compatibility` + = help: to override `--force-warn rust-2021-compatibility` add `#[allow(ellipsis_inclusive_range_patterns)]` warning: 1 warning emitted diff --git a/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr b/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr index dc7b1b7b98d..e925a195fb1 100644 --- a/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr +++ b/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr @@ -5,6 +5,7 @@ LL | pub fn FUNCTION() {} | ^^^^^^^^ help: convert the identifier to snake case: `function` | = note: `--force-warn non-snake-case` implied by `--force-warn nonstandard-style` + = help: to override `--force-warn nonstandard-style` add `#[allow(non_snake_case)]` warning: 1 warning emitted diff --git a/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr b/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr index e17630fd358..b0cd3ddd26f 100644 --- a/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr +++ b/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr @@ -7,6 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms` + = help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]` help: use `dyn` | LL | pub fn function(_x: Box<dyn SomeTrait>) {} diff --git a/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr b/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr index 72198541a70..8c841916c93 100644 --- a/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr +++ b/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr @@ -7,6 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms` + = help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]` help: use `dyn` | LL | pub fn function(_x: Box<dyn SomeTrait>) {} diff --git a/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr b/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr index 52c870ac28a..c0144205d6a 100644 --- a/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr +++ b/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr @@ -7,6 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms` + = help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]` help: use `dyn` | LL | pub fn function(_x: Box<dyn SomeTrait>) {} diff --git a/tests/ui/lint/future-incompat-test.stderr b/tests/ui/lint/future-incompat-test.stderr index 52674a84384..2951f904fb5 100644 --- a/tests/ui/lint/future-incompat-test.stderr +++ b/tests/ui/lint/future-incompat-test.stderr @@ -6,4 +6,5 @@ LL | let x = 1; | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `-A unused-variables` implied by `-A unused` + = help: to override `-A unused` add `#[allow(unused_variables)]` diff --git a/tests/ui/lint/issue-99387.rs b/tests/ui/lint/issue-99387.rs index ba5031167e3..571d4194fe7 100644 --- a/tests/ui/lint/issue-99387.rs +++ b/tests/ui/lint/issue-99387.rs @@ -2,7 +2,7 @@ //! opaque types. #![feature(type_alias_impl_trait)] -#![allow(private_in_public)] +#![allow(private_interfaces)] pub type Successors<'a> = impl Iterator<Item = &'a ()>; diff --git a/tests/ui/lint/lint-ctypes-94223.rs b/tests/ui/lint/lint-ctypes-94223.rs index 70dd2a71f26..ac24f61b0ac 100644 --- a/tests/ui/lint/lint-ctypes-94223.rs +++ b/tests/ui/lint/lint-ctypes-94223.rs @@ -24,6 +24,13 @@ enum BadUnion { type Foo = extern "C" fn([u8]); //~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe +pub trait FooTrait { + type FooType; +} + +pub type Foo2<T> = extern "C" fn(Option<&<T as FooTrait>::FooType>); +//~^ ERROR `extern` fn uses type `Option<&<T as FooTrait>::FooType>`, which is not FFI-safe + pub struct FfiUnsafe; #[allow(improper_ctypes_definitions)] diff --git a/tests/ui/lint/lint-ctypes-94223.stderr b/tests/ui/lint/lint-ctypes-94223.stderr index 49e64ed5140..bd127cf6004 100644 --- a/tests/ui/lint/lint-ctypes-94223.stderr +++ b/tests/ui/lint/lint-ctypes-94223.stderr @@ -66,8 +66,17 @@ LL | type Foo = extern "C" fn([u8]); = help: consider using a raw pointer instead = note: slices have no C equivalent +error: `extern` fn uses type `Option<&<T as FooTrait>::FooType>`, which is not FFI-safe + --> $DIR/lint-ctypes-94223.rs:31:20 + | +LL | pub type Foo2<T> = extern "C" fn(Option<&<T as FooTrait>::FooType>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum + = note: enum has no representation hint + error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe - --> $DIR/lint-ctypes-94223.rs:34:17 + --> $DIR/lint-ctypes-94223.rs:41:17 | LL | pub static BAD: extern "C" fn(FfiUnsafe) = f; | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -75,13 +84,13 @@ LL | pub static BAD: extern "C" fn(FfiUnsafe) = f; = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here - --> $DIR/lint-ctypes-94223.rs:27:1 + --> $DIR/lint-ctypes-94223.rs:34:1 | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe - --> $DIR/lint-ctypes-94223.rs:37:30 + --> $DIR/lint-ctypes-94223.rs:44:30 | LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f); | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -89,13 +98,13 @@ LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUns = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here - --> $DIR/lint-ctypes-94223.rs:27:1 + --> $DIR/lint-ctypes-94223.rs:34:1 | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe - --> $DIR/lint-ctypes-94223.rs:37:56 + --> $DIR/lint-ctypes-94223.rs:44:56 | LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f); | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -103,13 +112,13 @@ LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUns = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here - --> $DIR/lint-ctypes-94223.rs:27:1 + --> $DIR/lint-ctypes-94223.rs:34:1 | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe - --> $DIR/lint-ctypes-94223.rs:41:22 + --> $DIR/lint-ctypes-94223.rs:48:22 | LL | pub const BAD_CONST: extern "C" fn(FfiUnsafe) = f; | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -117,10 +126,10 @@ LL | pub const BAD_CONST: extern "C" fn(FfiUnsafe) = f; = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout note: the type is defined here - --> $DIR/lint-ctypes-94223.rs:27:1 + --> $DIR/lint-ctypes-94223.rs:34:1 | LL | pub struct FfiUnsafe; | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/lint/lint-ctypes-fn.rs b/tests/ui/lint/lint-ctypes-fn.rs index d3b36a9d59c..14831e24718 100644 --- a/tests/ui/lint/lint-ctypes-fn.rs +++ b/tests/ui/lint/lint-ctypes-fn.rs @@ -1,6 +1,6 @@ #![feature(rustc_private)] -#![allow(private_in_public)] +#![allow(private_interfaces)] #![deny(improper_ctypes_definitions)] extern crate libc; diff --git a/tests/ui/lint/lint-ctypes-option-nonnull-unsized.rs b/tests/ui/lint/lint-ctypes-option-nonnull-unsized.rs new file mode 100644 index 00000000000..ca08eb23a57 --- /dev/null +++ b/tests/ui/lint/lint-ctypes-option-nonnull-unsized.rs @@ -0,0 +1,8 @@ +#![deny(improper_ctypes_definitions)] + +extern "C" fn foo<T: ?Sized + 'static>() -> Option<&'static T> { + //~^ ERROR `extern` fn uses type `Option<&T>`, which is not FFI-safe + None +} + +fn main() {} diff --git a/tests/ui/lint/lint-ctypes-option-nonnull-unsized.stderr b/tests/ui/lint/lint-ctypes-option-nonnull-unsized.stderr new file mode 100644 index 00000000000..f59fb3cc750 --- /dev/null +++ b/tests/ui/lint/lint-ctypes-option-nonnull-unsized.stderr @@ -0,0 +1,16 @@ +error: `extern` fn uses type `Option<&T>`, which is not FFI-safe + --> $DIR/lint-ctypes-option-nonnull-unsized.rs:3:45 + | +LL | extern "C" fn foo<T: ?Sized + 'static>() -> Option<&'static T> { + | ^^^^^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum + = note: enum has no representation hint +note: the lint level is defined here + --> $DIR/lint-ctypes-option-nonnull-unsized.rs:1:9 + | +LL | #![deny(improper_ctypes_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/lint/lint-ctypes.rs b/tests/ui/lint/lint-ctypes.rs index 9165e14b7ff..3dd731625f4 100644 --- a/tests/ui/lint/lint-ctypes.rs +++ b/tests/ui/lint/lint-ctypes.rs @@ -1,6 +1,6 @@ #![feature(rustc_private)] -#![allow(private_in_public)] +#![allow(private_interfaces)] #![deny(improper_ctypes)] extern crate libc; diff --git a/tests/ui/lint/lint-pre-expansion-extern-module.stderr b/tests/ui/lint/lint-pre-expansion-extern-module.stderr index ce3e8806a9e..8a6e1531d5f 100644 --- a/tests/ui/lint/lint-pre-expansion-extern-module.stderr +++ b/tests/ui/lint/lint-pre-expansion-extern-module.stderr @@ -7,6 +7,7 @@ LL | pub fn try() {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> = note: `-W keyword-idents` implied by `-W rust-2018-compatibility` + = help: to override `-W rust-2018-compatibility` add `#[allow(keyword_idents)]` warning: 1 warning emitted diff --git a/tests/ui/lint/lint-removed-cmdline-deny.rs b/tests/ui/lint/lint-removed-cmdline-deny.rs new file mode 100644 index 00000000000..8cf91cf60eb --- /dev/null +++ b/tests/ui/lint/lint-removed-cmdline-deny.rs @@ -0,0 +1,13 @@ +// The raw_pointer_derived lint warns about its removal +// cc #30346 + +// compile-flags:-D renamed-and-removed-lints -D raw_pointer_derive + +// error-pattern:lint `raw_pointer_derive` has been removed +// error-pattern:requested on the command line with `-D raw_pointer_derive` +// error-pattern:requested on the command line with `-D renamed-and-removed-lints` + +#![warn(unused)] + +#[deny(warnings)] +fn main() { let unused = (); } diff --git a/tests/ui/lint/lint-removed-cmdline-deny.stderr b/tests/ui/lint/lint-removed-cmdline-deny.stderr new file mode 100644 index 00000000000..80c85d01e53 --- /dev/null +++ b/tests/ui/lint/lint-removed-cmdline-deny.stderr @@ -0,0 +1,28 @@ +error: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok + | + = note: requested on the command line with `-D raw_pointer_derive` + = note: requested on the command line with `-D renamed-and-removed-lints` + +error: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok + | + = note: requested on the command line with `-D raw_pointer_derive` + +error: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok + | + = note: requested on the command line with `-D raw_pointer_derive` + +error: unused variable: `unused` + --> $DIR/lint-removed-cmdline-deny.rs:13:17 + | +LL | fn main() { let unused = (); } + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` + | +note: the lint level is defined here + --> $DIR/lint-removed-cmdline-deny.rs:12:8 + | +LL | #[deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(warnings)]` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/lint/lint-removed-cmdline.rs b/tests/ui/lint/lint-removed-cmdline.rs index 462beabb945..34373df3a9c 100644 --- a/tests/ui/lint/lint-removed-cmdline.rs +++ b/tests/ui/lint/lint-removed-cmdline.rs @@ -4,6 +4,7 @@ // compile-flags:-D raw_pointer_derive // error-pattern:lint `raw_pointer_derive` has been removed +// error-pattern:`#[warn(renamed_and_removed_lints)]` on by default // error-pattern:requested on the command line with `-D raw_pointer_derive` #![warn(unused)] diff --git a/tests/ui/lint/lint-removed-cmdline.stderr b/tests/ui/lint/lint-removed-cmdline.stderr index 9be532ef234..ebfae34ade9 100644 --- a/tests/ui/lint/lint-removed-cmdline.stderr +++ b/tests/ui/lint/lint-removed-cmdline.stderr @@ -1,6 +1,7 @@ warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok | = note: requested on the command line with `-D raw_pointer_derive` + = note: `#[warn(renamed_and_removed_lints)]` on by default warning: lint `raw_pointer_derive` has been removed: using derive with raw pointers is ok | @@ -11,13 +12,13 @@ warning: lint `raw_pointer_derive` has been removed: using derive with raw point = note: requested on the command line with `-D raw_pointer_derive` error: unused variable: `unused` - --> $DIR/lint-removed-cmdline.rs:12:17 + --> $DIR/lint-removed-cmdline.rs:13:17 | LL | fn main() { let unused = (); } | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` | note: the lint level is defined here - --> $DIR/lint-removed-cmdline.rs:11:8 + --> $DIR/lint-removed-cmdline.rs:12:8 | LL | #[deny(warnings)] | ^^^^^^^^ diff --git a/tests/ui/lint/lint-renamed-cmdline-deny.rs b/tests/ui/lint/lint-renamed-cmdline-deny.rs new file mode 100644 index 00000000000..01629aaca80 --- /dev/null +++ b/tests/ui/lint/lint-renamed-cmdline-deny.rs @@ -0,0 +1,10 @@ +// compile-flags:-D renamed-and-removed-lints -D bare_trait_object + +// error-pattern:lint `bare_trait_object` has been renamed to `bare_trait_objects` +// error-pattern:use the new name `bare_trait_objects` +// error-pattern:requested on the command line with `-D bare_trait_object` +// error-pattern:requested on the command line with `-D renamed-and-removed-lints` +// error-pattern:unused + +#[deny(unused)] +fn main() { let unused = (); } diff --git a/tests/ui/lint/lint-renamed-cmdline-deny.stderr b/tests/ui/lint/lint-renamed-cmdline-deny.stderr new file mode 100644 index 00000000000..df22ef60daf --- /dev/null +++ b/tests/ui/lint/lint-renamed-cmdline-deny.stderr @@ -0,0 +1,31 @@ +error: lint `bare_trait_object` has been renamed to `bare_trait_objects` + | + = help: use the new name `bare_trait_objects` + = note: requested on the command line with `-D bare_trait_object` + = note: requested on the command line with `-D renamed-and-removed-lints` + +error: lint `bare_trait_object` has been renamed to `bare_trait_objects` + | + = help: use the new name `bare_trait_objects` + = note: requested on the command line with `-D bare_trait_object` + +error: lint `bare_trait_object` has been renamed to `bare_trait_objects` + | + = help: use the new name `bare_trait_objects` + = note: requested on the command line with `-D bare_trait_object` + +error: unused variable: `unused` + --> $DIR/lint-renamed-cmdline-deny.rs:10:17 + | +LL | fn main() { let unused = (); } + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` + | +note: the lint level is defined here + --> $DIR/lint-renamed-cmdline-deny.rs:9:8 + | +LL | #[deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/lint/lint-renamed-cmdline.rs b/tests/ui/lint/lint-renamed-cmdline.rs index c873771e308..fba7c33311d 100644 --- a/tests/ui/lint/lint-renamed-cmdline.rs +++ b/tests/ui/lint/lint-renamed-cmdline.rs @@ -2,6 +2,7 @@ // error-pattern:lint `bare_trait_object` has been renamed to `bare_trait_objects` // error-pattern:requested on the command line with `-D bare_trait_object` +// error-pattern:`#[warn(renamed_and_removed_lints)]` on by default // error-pattern:unused #[deny(unused)] diff --git a/tests/ui/lint/lint-renamed-cmdline.stderr b/tests/ui/lint/lint-renamed-cmdline.stderr index 8dfd61ac927..a41284003ed 100644 --- a/tests/ui/lint/lint-renamed-cmdline.stderr +++ b/tests/ui/lint/lint-renamed-cmdline.stderr @@ -1,23 +1,27 @@ warning: lint `bare_trait_object` has been renamed to `bare_trait_objects` | + = help: use the new name `bare_trait_objects` = note: requested on the command line with `-D bare_trait_object` + = note: `#[warn(renamed_and_removed_lints)]` on by default warning: lint `bare_trait_object` has been renamed to `bare_trait_objects` | + = help: use the new name `bare_trait_objects` = note: requested on the command line with `-D bare_trait_object` warning: lint `bare_trait_object` has been renamed to `bare_trait_objects` | + = help: use the new name `bare_trait_objects` = note: requested on the command line with `-D bare_trait_object` error: unused variable: `unused` - --> $DIR/lint-renamed-cmdline.rs:8:17 + --> $DIR/lint-renamed-cmdline.rs:9:17 | LL | fn main() { let unused = (); } | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` | note: the lint level is defined here - --> $DIR/lint-renamed-cmdline.rs:7:8 + --> $DIR/lint-renamed-cmdline.rs:8:8 | LL | #[deny(unused)] | ^^^^^^ diff --git a/tests/ui/lint/lint-unexported-no-mangle.stderr b/tests/ui/lint/lint-unexported-no-mangle.stderr index a11ee769c7c..85852782222 100644 --- a/tests/ui/lint/lint-unexported-no-mangle.stderr +++ b/tests/ui/lint/lint-unexported-no-mangle.stderr @@ -1,6 +1,7 @@ warning: lint `private_no_mangle_fns` has been removed: no longer a warning, `#[no_mangle]` functions always exported | = note: requested on the command line with `-F private_no_mangle_fns` + = note: `#[warn(renamed_and_removed_lints)]` on by default warning: lint `private_no_mangle_statics` has been removed: no longer a warning, `#[no_mangle]` statics always exported | diff --git a/tests/ui/lint/lint-unknown-lint-cmdline-allow.rs b/tests/ui/lint/lint-unknown-lint-cmdline-allow.rs new file mode 100644 index 00000000000..c7f8d434c04 --- /dev/null +++ b/tests/ui/lint/lint-unknown-lint-cmdline-allow.rs @@ -0,0 +1,4 @@ +// check-pass +// compile-flags:-A unknown-lints -D bogus -D dead_cod + +fn main() { } diff --git a/tests/ui/lint/lint-unknown-lint-cmdline-deny.rs b/tests/ui/lint/lint-unknown-lint-cmdline-deny.rs new file mode 100644 index 00000000000..31bc2047356 --- /dev/null +++ b/tests/ui/lint/lint-unknown-lint-cmdline-deny.rs @@ -0,0 +1,9 @@ +// compile-flags:-D unknown-lints -D bogus -D dead_cod + +// error-pattern:unknown lint: `bogus` +// error-pattern:requested on the command line with `-D bogus` +// error-pattern:requested on the command line with `-D dead_cod` +// error-pattern:requested on the command line with `-D unknown-lints` +// error-pattern:did you mean: `dead_code` + +fn main() { } diff --git a/tests/ui/lint/lint-unknown-lint-cmdline-deny.stderr b/tests/ui/lint/lint-unknown-lint-cmdline-deny.stderr new file mode 100644 index 00000000000..677b5edc894 --- /dev/null +++ b/tests/ui/lint/lint-unknown-lint-cmdline-deny.stderr @@ -0,0 +1,31 @@ +error[E0602]: unknown lint: `bogus` + | + = note: requested on the command line with `-D bogus` + = note: requested on the command line with `-D unknown-lints` + +error[E0602]: unknown lint: `dead_cod` + | + = help: did you mean: `dead_code` + = note: requested on the command line with `-D dead_cod` + +error[E0602]: unknown lint: `bogus` + | + = note: requested on the command line with `-D bogus` + +error[E0602]: unknown lint: `dead_cod` + | + = help: did you mean: `dead_code` + = note: requested on the command line with `-D dead_cod` + +error[E0602]: unknown lint: `bogus` + | + = note: requested on the command line with `-D bogus` + +error[E0602]: unknown lint: `dead_cod` + | + = help: did you mean: `dead_code` + = note: requested on the command line with `-D dead_cod` + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0602`. diff --git a/tests/ui/lint/lint-unknown-lint-cmdline.rs b/tests/ui/lint/lint-unknown-lint-cmdline.rs index 7f3f55fbad0..81539cb6dc1 100644 --- a/tests/ui/lint/lint-unknown-lint-cmdline.rs +++ b/tests/ui/lint/lint-unknown-lint-cmdline.rs @@ -1,7 +1,9 @@ +// check-pass // compile-flags:-D bogus -D dead_cod // error-pattern:unknown lint: `bogus` // error-pattern:requested on the command line with `-D bogus` +// error-pattern:`#[warn(unknown_lints)]` on by default // error-pattern:unknown lint: `dead_cod` // error-pattern:requested on the command line with `-D dead_cod` // error-pattern:did you mean: `dead_code` diff --git a/tests/ui/lint/lint-unknown-lint-cmdline.stderr b/tests/ui/lint/lint-unknown-lint-cmdline.stderr index 3855d552792..10db76ac4f1 100644 --- a/tests/ui/lint/lint-unknown-lint-cmdline.stderr +++ b/tests/ui/lint/lint-unknown-lint-cmdline.stderr @@ -1,21 +1,31 @@ -error[E0602]: unknown lint: `bogus` +warning[E0602]: unknown lint: `bogus` | = note: requested on the command line with `-D bogus` + = note: `#[warn(unknown_lints)]` on by default -error[E0602]: unknown lint: `dead_cod` +warning[E0602]: unknown lint: `dead_cod` | = help: did you mean: `dead_code` = note: requested on the command line with `-D dead_cod` -error[E0602]: unknown lint: `bogus` +warning[E0602]: unknown lint: `bogus` | = note: requested on the command line with `-D bogus` -error[E0602]: unknown lint: `dead_cod` +warning[E0602]: unknown lint: `dead_cod` | = help: did you mean: `dead_code` = note: requested on the command line with `-D dead_cod` -error: aborting due to 4 previous errors +warning[E0602]: unknown lint: `bogus` + | + = note: requested on the command line with `-D bogus` + +warning[E0602]: unknown lint: `dead_cod` + | + = help: did you mean: `dead_code` + = note: requested on the command line with `-D dead_cod` + +warning: 6 warnings emitted For more information about this error, try `rustc --explain E0602`. diff --git a/tests/ui/lint/no-coverage.rs b/tests/ui/lint/no-coverage.rs index 07906a43472..907d25d333e 100644 --- a/tests/ui/lint/no-coverage.rs +++ b/tests/ui/lint/no-coverage.rs @@ -1,55 +1,55 @@ #![feature(extern_types)] -#![feature(no_coverage)] +#![feature(coverage_attribute)] #![feature(impl_trait_in_assoc_type)] #![warn(unused_attributes)] -#![no_coverage] -//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +#![coverage(off)] +//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly -#[no_coverage] -//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +#[coverage(off)] +//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly trait Trait { - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code const X: u32; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type T; type U; } -#[no_coverage] -//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +#[coverage(off)] +//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly impl Trait for () { const X: u32 = 0; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type T = Self; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type U = impl Trait; //~ ERROR unconstrained opaque type } extern "C" { - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code static X: u32; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type T; } -#[no_coverage] +#[coverage(off)] fn main() { - #[no_coverage] - //~^ WARN `#[no_coverage]` may only be applied to function definitions + #[coverage(off)] + //~^ WARN `#[coverage]` may only be applied to function definitions let _ = (); match () { - #[no_coverage] - //~^ WARN `#[no_coverage]` may only be applied to function definitions + #[coverage(off)] + //~^ WARN `#[coverage]` may only be applied to function definitions () => (), } - #[no_coverage] - //~^ WARN `#[no_coverage]` may only be applied to function definitions + #[coverage(off)] + //~^ WARN `#[coverage]` may only be applied to function definitions return (); } diff --git a/tests/ui/lint/no-coverage.stderr b/tests/ui/lint/no-coverage.stderr index 404efbeac1e..a87b0fb49f0 100644 --- a/tests/ui/lint/no-coverage.stderr +++ b/tests/ui/lint/no-coverage.stderr @@ -1,8 +1,8 @@ -warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly --> $DIR/no-coverage.rs:8:1 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/no-coverage.rs:4:9 @@ -10,83 +10,83 @@ note: the lint level is defined here LL | #![warn(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly --> $DIR/no-coverage.rs:20:1 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` may only be applied to function definitions +warning: `#[coverage]` may only be applied to function definitions --> $DIR/no-coverage.rs:42:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` may only be applied to function definitions +warning: `#[coverage]` may only be applied to function definitions --> $DIR/no-coverage.rs:47:9 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` may only be applied to function definitions +warning: `#[coverage]` may only be applied to function definitions --> $DIR/no-coverage.rs:52:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:11:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | const X: u32; | ------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:14:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type T; | ------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:25:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type T = Self; | -------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:28:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type U = impl Trait; | -------------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:33:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | static X: u32; | -------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:36:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type T; | ------- not coverable code -warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly --> $DIR/no-coverage.rs:5:1 | -LL | #![no_coverage] - | ^^^^^^^^^^^^^^^ +LL | #![coverage(off)] + | ^^^^^^^^^^^^^^^^^ error: unconstrained opaque type --> $DIR/no-coverage.rs:29:14 diff --git a/tests/ui/lint/ptr_null_checks.rs b/tests/ui/lint/ptr_null_checks.rs index e677ea3094d..3028084e962 100644 --- a/tests/ui/lint/ptr_null_checks.rs +++ b/tests/ui/lint/ptr_null_checks.rs @@ -38,15 +38,15 @@ fn main() { if (&mut 8 as *mut i32).is_null() {} //~^ WARN references are not nullable if ptr::from_mut(&mut 8).is_null() {} - //~^ WARN references are not nullable + //~^ WARN call is never null if (&8 as *const i32).is_null() {} //~^ WARN references are not nullable if ptr::from_ref(&8).is_null() {} - //~^ WARN references are not nullable + //~^ WARN call is never null if ptr::from_ref(&8).cast_mut().is_null() {} - //~^ WARN references are not nullable + //~^ WARN call is never null if (ptr::from_ref(&8).cast_mut() as *mut i32).is_null() {} - //~^ WARN references are not nullable + //~^ WARN call is never null if (&8 as *const i32) == std::ptr::null() {} //~^ WARN references are not nullable let ref_num = &8; @@ -65,6 +65,12 @@ fn main() { if (&*{ static_i32() } as *const i32).is_null() {} //~^ WARN references are not nullable + // ---------------- Functions ------------------- + if ptr::NonNull::new(&mut 8).unwrap().as_ptr().is_null() {} + //~^ WARN call is never null + if ptr::NonNull::<u8>::dangling().as_ptr().is_null() {} + //~^ WARN call is never null + // ---------------------------------------------- const ZPTR: *const () = 0 as *const _; const NOT_ZPTR: *const () = 1 as *const _; diff --git a/tests/ui/lint/ptr_null_checks.stderr b/tests/ui/lint/ptr_null_checks.stderr index 3cee1804b62..0edc1b86536 100644 --- a/tests/ui/lint/ptr_null_checks.stderr +++ b/tests/ui/lint/ptr_null_checks.stderr @@ -117,13 +117,11 @@ LL | if (&mut 8 as *mut i32).is_null() {} | | | expression has type `&mut i32` -warning: references are not nullable, so checking them for null will always return false +warning: returned pointer of `from_mut` call is never null, so checking it for null will always return false --> $DIR/ptr_null_checks.rs:40:8 | LL | if ptr::from_mut(&mut 8).is_null() {} - | ^^^^^^^^^^^^^^------^^^^^^^^^^^ - | | - | expression has type `&mut i32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: references are not nullable, so checking them for null will always return false --> $DIR/ptr_null_checks.rs:42:8 @@ -133,29 +131,23 @@ LL | if (&8 as *const i32).is_null() {} | | | expression has type `&i32` -warning: references are not nullable, so checking them for null will always return false +warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false --> $DIR/ptr_null_checks.rs:44:8 | LL | if ptr::from_ref(&8).is_null() {} - | ^^^^^^^^^^^^^^--^^^^^^^^^^^ - | | - | expression has type `&i32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: references are not nullable, so checking them for null will always return false +warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false --> $DIR/ptr_null_checks.rs:46:8 | LL | if ptr::from_ref(&8).cast_mut().is_null() {} - | ^^^^^^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^^ - | | - | expression has type `&i32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: references are not nullable, so checking them for null will always return false +warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false --> $DIR/ptr_null_checks.rs:48:8 | LL | if (ptr::from_ref(&8).cast_mut() as *mut i32).is_null() {} - | ^^^^^^^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expression has type `&i32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: references are not nullable, so checking them for null will always return false --> $DIR/ptr_null_checks.rs:50:8 @@ -221,5 +213,17 @@ LL | if (&*{ static_i32() } as *const i32).is_null() {} | | | expression has type `&i32` -warning: 25 warnings emitted +warning: returned pointer of `as_ptr` call is never null, so checking it for null will always return false + --> $DIR/ptr_null_checks.rs:69:8 + | +LL | if ptr::NonNull::new(&mut 8).unwrap().as_ptr().is_null() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: returned pointer of `as_ptr` call is never null, so checking it for null will always return false + --> $DIR/ptr_null_checks.rs:71:8 + | +LL | if ptr::NonNull::<u8>::dangling().as_ptr().is_null() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: 27 warnings emitted diff --git a/tests/ui/lint/reference_casting.rs b/tests/ui/lint/reference_casting.rs index 92d985948ec..7745d4ef4c3 100644 --- a/tests/ui/lint/reference_casting.rs +++ b/tests/ui/lint/reference_casting.rs @@ -36,6 +36,10 @@ unsafe fn ref_to_mut() { //~^ ERROR casting `&T` to `&mut T` is undefined behavior let _num = &mut *std::mem::transmute::<_, *mut i32>(num); //~^ ERROR casting `&T` to `&mut T` is undefined behavior + let _num = &mut *std::cell::UnsafeCell::raw_get( + //~^ ERROR casting `&T` to `&mut T` is undefined behavior + num as *const i32 as *const std::cell::UnsafeCell<i32> + ); let deferred = num as *const i32 as *mut i32; let _num = &mut *deferred; @@ -50,6 +54,16 @@ unsafe fn ref_to_mut() { &mut *((this as *const _) as *mut _) //~^ ERROR casting `&T` to `&mut T` is undefined behavior } + + fn as_mut<T>(x: &T) -> &mut T { + unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + //~^ ERROR casting `&T` to `&mut T` is undefined behavior + } + + fn as_mut_i32(x: &i32) -> &mut i32 { + unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + //~^ ERROR casting `&T` to `&mut T` is undefined behavior + } } unsafe fn assign_to_ref() { @@ -111,6 +125,20 @@ unsafe fn no_warn() { let mut value = 3; let value: *const i32 = &mut value; *(value as *const i16 as *mut i16) = 42; + + fn safe_as_mut<T>(x: &std::cell::UnsafeCell<T>) -> &mut T { + unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + } + + fn cell_as_mut(x: &std::cell::Cell<i32>) -> &mut i32 { + unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + } + + #[repr(transparent)] + struct DoesContainUnsafeCell(std::cell::UnsafeCell<i32>); + fn safe_as_mut2(x: &DoesContainUnsafeCell) -> &mut DoesContainUnsafeCell { + unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + } } fn main() {} diff --git a/tests/ui/lint/reference_casting.stderr b/tests/ui/lint/reference_casting.stderr index 47b95460ec3..1189942c809 100644 --- a/tests/ui/lint/reference_casting.stderr +++ b/tests/ui/lint/reference_casting.stderr @@ -80,7 +80,19 @@ LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` - --> $DIR/reference_casting.rs:41:16 + --> $DIR/reference_casting.rs:39:16 + | +LL | let _num = &mut *std::cell::UnsafeCell::raw_get( + | ________________^ +LL | | +LL | | num as *const i32 as *const std::cell::UnsafeCell<i32> +LL | | ); + | |_____^ + | + = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> + +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` + --> $DIR/reference_casting.rs:45:16 | LL | let deferred = num as *const i32 as *mut i32; | ----------------------------- casting happend here @@ -90,7 +102,7 @@ LL | let _num = &mut *deferred; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` - --> $DIR/reference_casting.rs:44:16 + --> $DIR/reference_casting.rs:48:16 | LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32; | ---------------------------------------------------------------------------- casting happend here @@ -100,7 +112,7 @@ LL | let _num = &mut *deferred; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` - --> $DIR/reference_casting.rs:46:16 + --> $DIR/reference_casting.rs:50:16 | LL | let _num = &mut *(num as *const _ as usize as *mut i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,15 +120,31 @@ LL | let _num = &mut *(num as *const _ as usize as *mut i32); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` - --> $DIR/reference_casting.rs:50:9 + --> $DIR/reference_casting.rs:54:9 | LL | &mut *((this as *const _) as *mut _) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` + --> $DIR/reference_casting.rs:59:18 + | +LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> + +error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` + --> $DIR/reference_casting.rs:64:18 + | +LL | unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> + error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:60:5 + --> $DIR/reference_casting.rs:74:5 | LL | *(a as *const _ as *mut _) = String::from("Replaced"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -124,7 +152,7 @@ LL | *(a as *const _ as *mut _) = String::from("Replaced"); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:62:5 + --> $DIR/reference_casting.rs:76:5 | LL | *(a as *const _ as *mut String) += " world"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +160,7 @@ LL | *(a as *const _ as *mut String) += " world"; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:64:5 + --> $DIR/reference_casting.rs:78:5 | LL | *std::ptr::from_ref(num).cast_mut() += 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -140,7 +168,7 @@ LL | *std::ptr::from_ref(num).cast_mut() += 1; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:66:5 + --> $DIR/reference_casting.rs:80:5 | LL | *std::ptr::from_ref({ num }).cast_mut() += 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -148,7 +176,7 @@ LL | *std::ptr::from_ref({ num }).cast_mut() += 1; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:68:5 + --> $DIR/reference_casting.rs:82:5 | LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +184,7 @@ LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:70:5 + --> $DIR/reference_casting.rs:84:5 | LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -164,7 +192,7 @@ LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:72:5 + --> $DIR/reference_casting.rs:86:5 | LL | *std::mem::transmute::<_, *mut i32>(num) += 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -172,7 +200,7 @@ LL | *std::mem::transmute::<_, *mut i32>(num) += 1; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:74:5 + --> $DIR/reference_casting.rs:88:5 | LL | / std::ptr::write( LL | | @@ -184,7 +212,7 @@ LL | | ); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:81:5 + --> $DIR/reference_casting.rs:95:5 | LL | let value = num as *const i32 as *mut i32; | ----------------------------- casting happend here @@ -194,7 +222,7 @@ LL | *value = 1; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:83:5 + --> $DIR/reference_casting.rs:97:5 | LL | *(num as *const i32).cast::<i32>().cast_mut() = 2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -202,7 +230,7 @@ LL | *(num as *const i32).cast::<i32>().cast_mut() = 2; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:85:5 + --> $DIR/reference_casting.rs:99:5 | LL | *(num as *const _ as usize as *mut i32) = 2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +238,7 @@ LL | *(num as *const _ as usize as *mut i32) = 2; = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:87:5 + --> $DIR/reference_casting.rs:101:5 | LL | let value = num as *const i32 as *mut i32; | ----------------------------- casting happend here @@ -221,7 +249,7 @@ LL | std::ptr::write(value, 2); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:89:5 + --> $DIR/reference_casting.rs:103:5 | LL | let value = num as *const i32 as *mut i32; | ----------------------------- casting happend here @@ -232,7 +260,7 @@ LL | std::ptr::write_unaligned(value, 2); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:91:5 + --> $DIR/reference_casting.rs:105:5 | LL | let value = num as *const i32 as *mut i32; | ----------------------------- casting happend here @@ -243,12 +271,12 @@ LL | std::ptr::write_volatile(value, 2); = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/reference_casting.rs:95:9 + --> $DIR/reference_casting.rs:109:9 | LL | *(this as *const _ as *mut _) = a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> -error: aborting due to 29 previous errors +error: aborting due to 32 previous errors diff --git a/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs b/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs index 54d86c31fb4..ba32fb566e8 100644 --- a/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs +++ b/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs @@ -26,6 +26,32 @@ fn doc_comment_on_expr(num: u8) -> bool { num == 3 } +fn doc_comment_on_expr_field() -> bool { + struct S { foo: i32 } + + let x = S { + /// useless doc comment + //~^ ERROR: unused doc comment + foo: 3 + }; + + true +} + +fn doc_comment_on_pat_field() -> bool { + struct S { foo: i32 } + + let S { + /// useless doc comment + //~^ ERROR: unused doc comment + foo + } = S { + foo: 3 + }; + + true +} + fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} //~^ ERROR: unused doc comment diff --git a/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr b/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr index 078b780d8b9..b5aa6215797 100644 --- a/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr +++ b/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr @@ -42,7 +42,29 @@ LL | num == 3 = help: use `//` for a plain comment error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:29:27 + --> $DIR/unused-doc-comments-edge-cases.rs:33:9 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | foo: 3 + | ------ rustdoc does not generate documentation for expression fields + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:45:9 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | foo + | --- rustdoc does not generate documentation for pattern fields + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:55:27 | LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} | ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters @@ -50,7 +72,7 @@ LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} = help: use `//` for a plain comment error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:33:5 + --> $DIR/unused-doc-comments-edge-cases.rs:59:5 | LL | /// unused doc comment | ^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +85,7 @@ LL | | } = help: use `//` for a plain comment error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:40:1 + --> $DIR/unused-doc-comments-edge-cases.rs:66:1 | LL | /// unused doc comment | ^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +111,7 @@ help: you might have meant to return this value LL | return true; | ++++++ + -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0308, E0658. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/lint/unused/unused-parens-issue-106413.rs b/tests/ui/lint/unused/unused-parens-issue-106413.rs new file mode 100644 index 00000000000..7e76ab073b4 --- /dev/null +++ b/tests/ui/lint/unused/unused-parens-issue-106413.rs @@ -0,0 +1,32 @@ +// check-pass +#![warn(unused_parens)] + +fn id<T>(t: T) -> T { t } + +fn main() { + // This should not warn + let _ = 1 as (i32) < 2; + let _ = id(1 as (i32) < 2); + let _ = id(1 as i32) + as (i32) < 2; + // These should warn + let _ = 1 as ((i32)) < 2; //~WARN unnecessary parentheses + let _ = 1 as (i32); //~WARN unnecessary parentheses + let _ = 1 as (i32) > 2; //~WARN unnecessary parentheses + let _ = id(1 as (i32)) //~WARN unnecessary parentheses + as (i32) < 2; + let _ = id(1 as (i32)) < 2; //~WARN unnecessary parentheses + + // This should not warn + let _ = 1 as (i32) << 2; + let _ = id(1 as (i32) << 2); + let _ = id(1 as i32) + as (i32) << 2; + // These should warn + let _ = 1 as ((i32)) << 2; //~WARN unnecessary parentheses + let _ = 1 as (i32); //~WARN unnecessary parentheses + let _ = 1 as (i32) >> 2; //~WARN unnecessary parentheses + let _ = id(1 as (i32)) //~WARN unnecessary parentheses + as (i32) << 2; + let _ = id(1 as (i32)) << 2; //~WARN unnecessary parentheses +} diff --git a/tests/ui/lint/unused/unused-parens-issue-106413.stderr b/tests/ui/lint/unused/unused-parens-issue-106413.stderr new file mode 100644 index 00000000000..d2d8f76d967 --- /dev/null +++ b/tests/ui/lint/unused/unused-parens-issue-106413.stderr @@ -0,0 +1,127 @@ +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:13:19 + | +LL | let _ = 1 as ((i32)) < 2; + | ^ ^ + | +note: the lint level is defined here + --> $DIR/unused-parens-issue-106413.rs:2:9 + | +LL | #![warn(unused_parens)] + | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let _ = 1 as ((i32)) < 2; +LL + let _ = 1 as (i32) < 2; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:14:18 + | +LL | let _ = 1 as (i32); + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = 1 as (i32); +LL + let _ = 1 as i32; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:15:18 + | +LL | let _ = 1 as (i32) > 2; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = 1 as (i32) > 2; +LL + let _ = 1 as i32 > 2; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:16:21 + | +LL | let _ = id(1 as (i32)) + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = id(1 as (i32)) +LL + let _ = id(1 as i32) + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:18:21 + | +LL | let _ = id(1 as (i32)) < 2; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = id(1 as (i32)) < 2; +LL + let _ = id(1 as i32) < 2; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:26:19 + | +LL | let _ = 1 as ((i32)) << 2; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = 1 as ((i32)) << 2; +LL + let _ = 1 as (i32) << 2; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:27:18 + | +LL | let _ = 1 as (i32); + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = 1 as (i32); +LL + let _ = 1 as i32; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:28:18 + | +LL | let _ = 1 as (i32) >> 2; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = 1 as (i32) >> 2; +LL + let _ = 1 as i32 >> 2; + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:29:21 + | +LL | let _ = id(1 as (i32)) + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = id(1 as (i32)) +LL + let _ = id(1 as i32) + | + +warning: unnecessary parentheses around type + --> $DIR/unused-parens-issue-106413.rs:31:21 + | +LL | let _ = id(1 as (i32)) << 2; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = id(1 as (i32)) << 2; +LL + let _ = id(1 as i32) << 2; + | + +warning: 10 warnings emitted + diff --git a/tests/ui/issues/issue-69225-SCEVAddExpr-wrap-flag.rs b/tests/ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs index 6e030f1cc48..6e030f1cc48 100644 --- a/tests/ui/issues/issue-69225-SCEVAddExpr-wrap-flag.rs +++ b/tests/ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs diff --git a/tests/ui/issues/issue-69225-layout-repeated-checked-add.rs b/tests/ui/loops/issue-69225-layout-repeated-checked-add.rs index 7f43e4d1a51..7f43e4d1a51 100644 --- a/tests/ui/issues/issue-69225-layout-repeated-checked-add.rs +++ b/tests/ui/loops/issue-69225-layout-repeated-checked-add.rs diff --git a/tests/ui/issues/issue-39467.rs b/tests/ui/macros/issue-39467.rs index 397751e4ec3..397751e4ec3 100644 --- a/tests/ui/issues/issue-39467.rs +++ b/tests/ui/macros/issue-39467.rs diff --git a/tests/ui/macros/must-use-in-macro-55516.stderr b/tests/ui/macros/must-use-in-macro-55516.stderr index 8878b0eea0f..7bf4aaab51c 100644 --- a/tests/ui/macros/must-use-in-macro-55516.stderr +++ b/tests/ui/macros/must-use-in-macro-55516.stderr @@ -6,6 +6,7 @@ LL | write!(&mut example, "{}", 42); | = note: this `Result` may be an `Err` variant, which should be handled = note: `-W unused-must-use` implied by `-W unused` + = help: to override `-W unused` add `#[allow(unused_must_use)]` = note: this warning originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) warning: 1 warning emitted diff --git a/tests/ui/match/match_non_exhaustive.stderr b/tests/ui/match/match_non_exhaustive.stderr index 46ee8d5179e..7b8bdfe0053 100644 --- a/tests/ui/match/match_non_exhaustive.stderr +++ b/tests/ui/match/match_non_exhaustive.stderr @@ -45,7 +45,8 @@ note: `E2` defined here | LL | pub enum E2 { A, B } | ^^^^^^^^^^^ - = note: the matched value is of type `E2`, which is marked as non-exhaustive + = note: the matched value is of type `E2` + = note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL | match e2 { E2::A => (), E2::B => (), _ => todo!() }; diff --git a/tests/ui/issues/issue-3707.rs b/tests/ui/methods/issue-3707.rs index 0817c51ee4e..0817c51ee4e 100644 --- a/tests/ui/issues/issue-3707.rs +++ b/tests/ui/methods/issue-3707.rs diff --git a/tests/ui/issues/issue-3707.stderr b/tests/ui/methods/issue-3707.stderr index 07c8101cbc6..07c8101cbc6 100644 --- a/tests/ui/issues/issue-3707.stderr +++ b/tests/ui/methods/issue-3707.stderr diff --git a/tests/ui/mir/issue-92893.rs b/tests/ui/mir/issue-92893.rs index 635050f376c..6127d267ebc 100644 --- a/tests/ui/mir/issue-92893.rs +++ b/tests/ui/mir/issue-92893.rs @@ -1,7 +1,5 @@ struct Bug<A = [(); (let a = (), 1).1]> { - //~^ `let` expressions are not supported here - //~| `let` expressions in this position are unstable [E0658] - //~| expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement a: A } diff --git a/tests/ui/mir/issue-92893.stderr b/tests/ui/mir/issue-92893.stderr index 4a0fcce31d7..6c1a9dc0317 100644 --- a/tests/ui/mir/issue-92893.stderr +++ b/tests/ui/mir/issue-92893.stderr @@ -3,24 +3,8 @@ error: expected expression, found `let` statement | LL | struct Bug<A = [(); (let a = (), 1).1]> { | ^^^ - -error: `let` expressions are not supported here - --> $DIR/issue-92893.rs:1:22 - | -LL | struct Bug<A = [(); (let a = (), 1).1]> { - | ^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error[E0658]: `let` expressions in this position are unstable - --> $DIR/issue-92893.rs:1:22 - | -LL | struct Bug<A = [(); (let a = (), 1).1]> { - | ^^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error: aborting due to 3 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/mir/mir-inlining/always-encode-mirs.rs b/tests/ui/mir/mir-inlining/always-encode-mirs.rs new file mode 100644 index 00000000000..f3731996cf2 --- /dev/null +++ b/tests/ui/mir/mir-inlining/always-encode-mirs.rs @@ -0,0 +1,12 @@ +// Regression test for MIR inlining with -Zalways-encode-mir enabled in the auxiliary crate. +// Previously we inlined function not eligible for inlining which lead to linking error: +// undefined reference to `internal::S' +// +// aux-build:internal.rs +// build-pass +// compile-flags: -O +extern crate internal; + +fn main() { + println!("{}", internal::f()); +} diff --git a/tests/ui/mir/mir-inlining/auxiliary/internal.rs b/tests/ui/mir/mir-inlining/auxiliary/internal.rs new file mode 100644 index 00000000000..fa0f9c2da41 --- /dev/null +++ b/tests/ui/mir/mir-inlining/auxiliary/internal.rs @@ -0,0 +1,7 @@ +// compile-flags: -Zalways-encode-mir + +static S: usize = 42; + +pub fn f() -> &'static usize { + &S +} diff --git a/tests/ui/mismatched_types/cast-rfc0401.stderr b/tests/ui/mismatched_types/cast-rfc0401.stderr index 6b9ac3c5852..0cea60746bf 100644 --- a/tests/ui/mismatched_types/cast-rfc0401.stderr +++ b/tests/ui/mismatched_types/cast-rfc0401.stderr @@ -82,13 +82,13 @@ error[E0606]: casting `f32` as `*const u8` is invalid LL | let _ = f as *const u8; | ^^^^^^^^^^^^^^ -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `i32` as `bool` --> $DIR/cast-rfc0401.rs:39:13 | LL | let _ = 3_i32 as bool; | ^^^^^^^^^^^^^ help: compare with zero instead: `3_i32 != 0` -error[E0054]: cannot cast as `bool` +error[E0054]: cannot cast `E` as `bool` --> $DIR/cast-rfc0401.rs:40:13 | LL | let _ = E::A as bool; diff --git a/tests/ui/issues/issue-13033.rs b/tests/ui/mismatched_types/issue-13033.rs index fdb356e70c5..fdb356e70c5 100644 --- a/tests/ui/issues/issue-13033.rs +++ b/tests/ui/mismatched_types/issue-13033.rs diff --git a/tests/ui/issues/issue-13033.stderr b/tests/ui/mismatched_types/issue-13033.stderr index db2c1189e1e..db2c1189e1e 100644 --- a/tests/ui/issues/issue-13033.stderr +++ b/tests/ui/mismatched_types/issue-13033.stderr diff --git a/tests/ui/mismatched_types/normalize-fn-sig.stderr b/tests/ui/mismatched_types/normalize-fn-sig.stderr index e3a0646550c..252e56387ba 100644 --- a/tests/ui/mismatched_types/normalize-fn-sig.stderr +++ b/tests/ui/mismatched_types/normalize-fn-sig.stderr @@ -8,7 +8,6 @@ LL | needs_i32_ref_fn(foo::<()>); | = note: expected fn pointer `fn(&'static i32, i32)` found fn item `fn(i32, &'static i32) {foo::<()>}` - = note: when the arguments and return types match, functions can be coerced to function pointers note: function defined here --> $DIR/normalize-fn-sig.rs:11:4 | diff --git a/tests/ui/issues/issue-34721.fixed b/tests/ui/moves/issue-34721.fixed index f135ad3836e..f135ad3836e 100644 --- a/tests/ui/issues/issue-34721.fixed +++ b/tests/ui/moves/issue-34721.fixed diff --git a/tests/ui/issues/issue-34721.rs b/tests/ui/moves/issue-34721.rs index 14dd01766aa..14dd01766aa 100644 --- a/tests/ui/issues/issue-34721.rs +++ b/tests/ui/moves/issue-34721.rs diff --git a/tests/ui/issues/issue-34721.stderr b/tests/ui/moves/issue-34721.stderr index f2bf22227db..f2bf22227db 100644 --- a/tests/ui/issues/issue-34721.stderr +++ b/tests/ui/moves/issue-34721.stderr diff --git a/tests/ui/namespace/namespace-mix.stderr b/tests/ui/namespace/namespace-mix.stderr index 3ac5e96c574..4eff08ead42 100644 --- a/tests/ui/namespace/namespace-mix.stderr +++ b/tests/ui/namespace/namespace-mix.stderr @@ -114,6 +114,11 @@ LL | check(m1::S{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -128,6 +133,11 @@ LL | check(m2::S{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -142,6 +152,11 @@ LL | check(m2::S); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -156,6 +171,11 @@ LL | check(xm1::S{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -170,6 +190,11 @@ LL | check(xm2::S{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -184,6 +209,11 @@ LL | check(xm2::S); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -198,6 +228,11 @@ LL | check(m3::TS{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -212,6 +247,11 @@ LL | check(m3::TS); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -226,6 +266,11 @@ LL | check(m4::TS{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -240,6 +285,11 @@ LL | check(m4::TS); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -254,6 +304,11 @@ LL | check(xm3::TS{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -268,6 +323,11 @@ LL | check(xm3::TS); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -282,6 +342,11 @@ LL | check(xm4::TS{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -296,6 +361,11 @@ LL | check(xm4::TS); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -310,6 +380,11 @@ LL | check(m5::US{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -324,6 +399,11 @@ LL | check(m5::US); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -338,6 +418,11 @@ LL | check(m6::US{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -352,6 +437,11 @@ LL | check(m6::US); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -366,6 +456,11 @@ LL | check(xm5::US{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -380,6 +475,11 @@ LL | check(xm5::US); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -394,6 +494,11 @@ LL | check(xm6::US{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -408,6 +513,11 @@ LL | check(xm6::US); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -422,6 +532,11 @@ LL | check(m7::V{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -436,6 +551,11 @@ LL | check(m8::V{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -450,6 +570,11 @@ LL | check(m8::V); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -464,6 +589,11 @@ LL | check(xm7::V{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -478,6 +608,11 @@ LL | check(xm8::V{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -492,6 +627,11 @@ LL | check(xm8::V); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -506,6 +646,11 @@ LL | check(m9::TV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -520,6 +665,11 @@ LL | check(m9::TV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -534,6 +684,11 @@ LL | check(mA::TV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -548,6 +703,11 @@ LL | check(mA::TV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -562,6 +722,11 @@ LL | check(xm9::TV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -576,6 +741,11 @@ LL | check(xm9::TV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -590,6 +760,11 @@ LL | check(xmA::TV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -604,6 +779,11 @@ LL | check(xmA::TV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -618,6 +798,11 @@ LL | check(mB::UV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -632,6 +817,11 @@ LL | check(mB::UV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -646,6 +836,11 @@ LL | check(mC::UV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -660,6 +855,11 @@ LL | check(mC::UV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -674,6 +874,11 @@ LL | check(xmB::UV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -688,6 +893,11 @@ LL | check(xmB::UV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -702,6 +912,11 @@ LL | check(xmC::UV{}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | @@ -716,6 +931,11 @@ LL | check(xmC::UV); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/namespace-mix.rs:20:1 + | +LL | trait Impossible {} + | ^^^^^^^^^^^^^^^^ note: required by a bound in `check` --> $DIR/namespace-mix.rs:21:13 | diff --git a/tests/ui/nested-ty-params.rs b/tests/ui/nested-ty-params.rs index 85413acdb14..25bac1ba24b 100644 --- a/tests/ui/nested-ty-params.rs +++ b/tests/ui/nested-ty-params.rs @@ -1,4 +1,4 @@ -// error-pattern:can't use generic parameters from outer function +// error-pattern:can't use generic parameters from outer item fn hd<U>(v: Vec<U> ) -> U { fn hd1(w: [U]) -> U { return w[0]; } diff --git a/tests/ui/nested-ty-params.stderr b/tests/ui/nested-ty-params.stderr index 8f4746f5ec3..a9cdec66719 100644 --- a/tests/ui/nested-ty-params.stderr +++ b/tests/ui/nested-ty-params.stderr @@ -1,22 +1,22 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/nested-ty-params.rs:3:16 | LL | fn hd<U>(v: Vec<U> ) -> U { - | - type parameter from outer function + | - type parameter from outer item LL | fn hd1(w: [U]) -> U { return w[0]; } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<U>` + | help: try introducing a local generic parameter here: `<U>` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/nested-ty-params.rs:3:23 | LL | fn hd<U>(v: Vec<U> ) -> U { - | - type parameter from outer function + | - type parameter from outer item LL | fn hd1(w: [U]) -> U { return w[0]; } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<U>` + | help: try introducing a local generic parameter here: `<U>` error: aborting due to 2 previous errors diff --git a/tests/ui/never_type/feature-gate-never_type_fallback.stderr b/tests/ui/never_type/feature-gate-never_type_fallback.stderr index 2db1cc4b776..56aafbb4ce8 100644 --- a/tests/ui/never_type/feature-gate-never_type_fallback.stderr +++ b/tests/ui/never_type/feature-gate-never_type_fallback.stderr @@ -8,6 +8,11 @@ LL | foo(panic!()) | | this tail expression is of type `()` | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/feature-gate-never_type_fallback.rs:7:1 + | +LL | trait T {} + | ^^^^^^^ note: required by a bound in `foo` --> $DIR/feature-gate-never_type_fallback.rs:13:16 | diff --git a/tests/ui/never_type/impl_trait_fallback3.stderr b/tests/ui/never_type/impl_trait_fallback3.stderr index 5d5d216fb9b..821d141569e 100644 --- a/tests/ui/never_type/impl_trait_fallback3.stderr +++ b/tests/ui/never_type/impl_trait_fallback3.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): T` is not satisfied | LL | fn a() -> Foo { | ^^^ the trait `T` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/impl_trait_fallback3.rs:5:1 + | +LL | trait T { + | ^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/never_type/impl_trait_fallback4.stderr b/tests/ui/never_type/impl_trait_fallback4.stderr index f2e216e9044..67421ba8da7 100644 --- a/tests/ui/never_type/impl_trait_fallback4.stderr +++ b/tests/ui/never_type/impl_trait_fallback4.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): T` is not satisfied | LL | fn foo() -> impl T { | ^^^^^^ the trait `T` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/impl_trait_fallback4.rs:3:1 + | +LL | trait T { + | ^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/nll/missing-universe-cause-issue-114907.rs b/tests/ui/nll/missing-universe-cause-issue-114907.rs new file mode 100644 index 00000000000..94acdccfcf2 --- /dev/null +++ b/tests/ui/nll/missing-universe-cause-issue-114907.rs @@ -0,0 +1,40 @@ +// This is a non-regression test for issue #114907 where an ICE happened because of missing +// `UniverseInfo`s accessed during diagnostics. +// +// A couple notes: +// - the `FnOnce` bounds need an arg that is a reference +// - a custom `Drop` is needed somewhere in the type that `accept` returns, to create universes +// during liveness and dropck outlives computation + +// check-fail + +trait Role { + type Inner; +} + +struct HandshakeCallback<C>(C); +impl<C: FnOnce(&())> Role for HandshakeCallback<C> { + type Inner = (); +} + +struct Handshake<R: Role> { + _inner: Option<R::Inner>, +} +impl<R: Role> Drop for Handshake<R> { + fn drop(&mut self) {} +} + +fn accept<C: FnOnce(&())>(_: C) -> Handshake<HandshakeCallback<C>> { + todo!() +} + +fn main() { + let callback = |_| {}; + accept(callback); + //~^ ERROR mismatched types + //~| ERROR mismatched types + //~| ERROR implementation of `FnOnce` is not general enough + //~| ERROR implementation of `FnOnce` is not general enough + //~| ERROR higher-ranked subtype error + //~| ERROR higher-ranked subtype error +} diff --git a/tests/ui/nll/missing-universe-cause-issue-114907.stderr b/tests/ui/nll/missing-universe-cause-issue-114907.stderr new file mode 100644 index 00000000000..c3dd4257a73 --- /dev/null +++ b/tests/ui/nll/missing-universe-cause-issue-114907.stderr @@ -0,0 +1,79 @@ +error[E0308]: mismatched types + --> $DIR/missing-universe-cause-issue-114907.rs:33:5 + | +LL | accept(callback); + | ^^^^^^^^^^^^^^^^ one type is more general than the other + | + = note: expected trait `for<'a> FnOnce<(&'a (),)>` + found trait `FnOnce<(&(),)>` +note: this closure does not fulfill the lifetime requirements + --> $DIR/missing-universe-cause-issue-114907.rs:32:20 + | +LL | let callback = |_| {}; + | ^^^ +note: the lifetime requirement is introduced here + --> $DIR/missing-universe-cause-issue-114907.rs:27:14 + | +LL | fn accept<C: FnOnce(&())>(_: C) -> Handshake<HandshakeCallback<C>> { + | ^^^^^^^^^^^ +help: consider specifying the type of the closure parameters + | +LL | let callback = |_: &_| {}; + | ~~~~~~~ + +error: implementation of `FnOnce` is not general enough + --> $DIR/missing-universe-cause-issue-114907.rs:33:5 + | +LL | accept(callback); + | ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough + | + = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`... + = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2` + +error: implementation of `FnOnce` is not general enough + --> $DIR/missing-universe-cause-issue-114907.rs:33:5 + | +LL | accept(callback); + | ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough + | + = note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`... + = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2` + +error[E0308]: mismatched types + --> $DIR/missing-universe-cause-issue-114907.rs:33:5 + | +LL | accept(callback); + | ^^^^^^^^^^^^^^^^ one type is more general than the other + | + = note: expected trait `for<'a> FnOnce<(&'a (),)>` + found trait `FnOnce<(&(),)>` +note: this closure does not fulfill the lifetime requirements + --> $DIR/missing-universe-cause-issue-114907.rs:32:20 + | +LL | let callback = |_| {}; + | ^^^ +note: the lifetime requirement is introduced here + --> $DIR/missing-universe-cause-issue-114907.rs:20:21 + | +LL | struct Handshake<R: Role> { + | ^^^^ +help: consider specifying the type of the closure parameters + | +LL | let callback = |_: &_| {}; + | ~~~~~~~ + +error: higher-ranked subtype error + --> $DIR/missing-universe-cause-issue-114907.rs:33:21 + | +LL | accept(callback); + | ^ + +error: higher-ranked subtype error + --> $DIR/missing-universe-cause-issue-114907.rs:33:21 + | +LL | accept(callback); + | ^ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_used.rs b/tests/ui/object-safety/assoc_type_bounds_sized_used.rs index cf5345b1c1d..d59fc1712ea 100644 --- a/tests/ui/object-safety/assoc_type_bounds_sized_used.rs +++ b/tests/ui/object-safety/assoc_type_bounds_sized_used.rs @@ -1,6 +1,5 @@ -//! This test checks that even if some associated types have -//! `where Self: Sized` bounds, those without still need to be -//! mentioned in trait objects. +//! This test checks that associated types with `Self: Sized` cannot be projected +//! from a `dyn Trait`. trait Bop { type Bar: Default @@ -16,5 +15,4 @@ fn bop<T: Bop + ?Sized>() { fn main() { bop::<dyn Bop>(); - //~^ ERROR: the size for values of type `dyn Bop` cannot be known at compilation time } diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr b/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr index 6b5bc360349..224d33fb2da 100644 --- a/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr +++ b/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr @@ -1,5 +1,5 @@ error[E0599]: the function or associated item `default` exists for associated type `<T as Bop>::Bar`, but its trait bounds were not satisfied - --> $DIR/assoc_type_bounds_sized_used.rs:12:30 + --> $DIR/assoc_type_bounds_sized_used.rs:11:30 | LL | let _ = <T as Bop>::Bar::default(); | ^^^^^^^ function or associated item cannot be called on `<T as Bop>::Bar` due to unsatisfied trait bounds @@ -13,7 +13,7 @@ LL | fn bop<T: Bop + ?Sized>() where T: Sized { | ++++++++++++++ error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/assoc_type_bounds_sized_used.rs:12:14 + --> $DIR/assoc_type_bounds_sized_used.rs:11:14 | LL | fn bop<T: Bop + ?Sized>() { | - this type parameter needs to be `Sized` @@ -21,7 +21,7 @@ LL | let _ = <T as Bop>::Bar::default(); | ^ doesn't have a size known at compile-time | note: required by a bound in `Bop::Bar` - --> $DIR/assoc_type_bounds_sized_used.rs:8:15 + --> $DIR/assoc_type_bounds_sized_used.rs:7:15 | LL | type Bar: Default | --- required by a bound in this associated type @@ -34,20 +34,7 @@ LL - fn bop<T: Bop + ?Sized>() { LL + fn bop<T: Bop>() { | -error[E0277]: the size for values of type `dyn Bop` cannot be known at compilation time - --> $DIR/assoc_type_bounds_sized_used.rs:18:11 - | -LL | bop::<dyn Bop>(); - | ^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `dyn Bop` -note: required by a bound in `bop` - --> $DIR/assoc_type_bounds_sized_used.rs:11:11 - | -LL | fn bop<T: Bop + ?Sized>() { - | ^^^ required by this bound in `bop` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0277, E0599. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs b/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs new file mode 100644 index 00000000000..0b30a88fdd4 --- /dev/null +++ b/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs @@ -0,0 +1,25 @@ +// check-pass +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + +trait Foo { + type Bar<'a> + where + Self: Sized; + + fn test(&self); +} + +impl Foo for () { + type Bar<'a> = () where Self: Sized; + + fn test(&self) {} +} + +fn test(x: &dyn Foo) { + x.test(); +} + +fn main() { + test(&()); +} diff --git a/tests/ui/on-unimplemented/on-trait.stderr b/tests/ui/on-unimplemented/on-trait.stderr index 4b040f1ac5a..4847a1a5a61 100644 --- a/tests/ui/on-unimplemented/on-trait.stderr +++ b/tests/ui/on-unimplemented/on-trait.stderr @@ -5,6 +5,11 @@ LL | let y: Option<Vec<u8>> = collect(x.iter()); // this should give approxi | ^^^^^^^ a collection of type `Option<Vec<u8>>` cannot be built from an iterator over elements of type `&u8` | = help: the trait `MyFromIterator<&u8>` is not implemented for `Option<Vec<u8>>` +help: this trait has no implementations, consider adding one + --> $DIR/on-trait.rs:17:1 + | +LL | trait MyFromIterator<A> { + | ^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `collect` --> $DIR/on-trait.rs:22:39 | @@ -18,6 +23,11 @@ LL | let x: String = foobar(); | ^^^^^^ test error `String` with `u8` `_` `u32` in `Foo` | = help: the trait `Foo<u8, _, u32>` is not implemented for `String` +help: this trait has no implementations, consider adding one + --> $DIR/on-trait.rs:7:3 + | +LL | pub trait Foo<Bar, Baz, Quux> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `foobar` --> $DIR/on-trait.rs:12:24 | diff --git a/tests/ui/on-unimplemented/parent-label.stderr b/tests/ui/on-unimplemented/parent-label.stderr index 8cd7412fd9d..101a41512d2 100644 --- a/tests/ui/on-unimplemented/parent-label.stderr +++ b/tests/ui/on-unimplemented/parent-label.stderr @@ -8,6 +8,11 @@ LL | f(Foo {}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/parent-label.rs:6:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `f` --> $DIR/parent-label.rs:10:9 | @@ -24,6 +29,11 @@ LL | f(Foo {}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/parent-label.rs:6:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `f` --> $DIR/parent-label.rs:10:9 | @@ -41,6 +51,11 @@ LL | f(Foo {}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/parent-label.rs:6:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `f` --> $DIR/parent-label.rs:10:9 | @@ -58,6 +73,11 @@ LL | f(Foo {}); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/parent-label.rs:6:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `f` --> $DIR/parent-label.rs:10:9 | diff --git a/tests/ui/parser/default-unmatched.stderr b/tests/ui/parser/default-unmatched.stderr index 331e003f63c..de142411d69 100644 --- a/tests/ui/parser/default-unmatched.stderr +++ b/tests/ui/parser/default-unmatched.stderr @@ -11,6 +11,8 @@ error: expected item, found reserved keyword `do` | LL | default do | ^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 2 previous errors diff --git a/tests/ui/parser/impl-parsing.stderr b/tests/ui/parser/impl-parsing.stderr index 755addf1452..a57cc075ccc 100644 --- a/tests/ui/parser/impl-parsing.stderr +++ b/tests/ui/parser/impl-parsing.stderr @@ -35,6 +35,8 @@ error: expected item, found keyword `unsafe` | LL | default unsafe FAIL | ^^^^^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 6 previous errors diff --git a/tests/ui/parser/issue-101477-enum.stderr b/tests/ui/parser/issue-101477-enum.stderr index 1edca391e8f..94130671f1c 100644 --- a/tests/ui/parser/issue-101477-enum.stderr +++ b/tests/ui/parser/issue-101477-enum.stderr @@ -11,6 +11,8 @@ error: expected item, found `==` | LL | B == 2 | ^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-113110-non-item-at-module-root.rs b/tests/ui/parser/issues/issue-113110-non-item-at-module-root.rs new file mode 100644 index 00000000000..3b6f4304369 --- /dev/null +++ b/tests/ui/parser/issues/issue-113110-non-item-at-module-root.rs @@ -0,0 +1 @@ + 5 //~ ERROR expected item, found `5` diff --git a/tests/ui/parser/issues/issue-113110-non-item-at-module-root.stderr b/tests/ui/parser/issues/issue-113110-non-item-at-module-root.stderr new file mode 100644 index 00000000000..0789c4548a0 --- /dev/null +++ b/tests/ui/parser/issues/issue-113110-non-item-at-module-root.stderr @@ -0,0 +1,10 @@ +error: expected item, found `5` + --> $DIR/issue-113110-non-item-at-module-root.rs:1:2 + | +LL | 5 + | ^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> + +error: aborting due to previous error + diff --git a/tests/ui/parser/issues/issue-115780-pat-lt-bracket-in-macro-call.rs b/tests/ui/parser/issues/issue-115780-pat-lt-bracket-in-macro-call.rs new file mode 100644 index 00000000000..3421333b8a0 --- /dev/null +++ b/tests/ui/parser/issues/issue-115780-pat-lt-bracket-in-macro-call.rs @@ -0,0 +1,21 @@ +// Regression test for issue #115780. +// Ensure that we don't emit a parse error for the token sequence `Ident "<" Ty` in pattern position +// if we are inside a macro call since it can be valid input for a subsequent macro rule. +// See also #103534. + +// check-pass + +macro_rules! mdo { + ($p: pat =<< $e: expr ; $( $t: tt )*) => { + $e.and_then(|$p| mdo! { $( $t )* }) + }; + (ret<$ty: ty> $e: expr;) => { Some::<$ty>($e) }; +} + +fn main() { + mdo! { + x_val =<< Some(0); + y_val =<< Some(1); + ret<(i32, i32)> (x_val, y_val); + }; +} diff --git a/tests/ui/parser/issues/issue-17904-2.stderr b/tests/ui/parser/issues/issue-17904-2.stderr index 9c7fdf6ccb4..7185a5e5752 100644 --- a/tests/ui/parser/issues/issue-17904-2.stderr +++ b/tests/ui/parser/issues/issue-17904-2.stderr @@ -3,6 +3,8 @@ error: expected item, found keyword `where` | LL | struct Bar<T> { x: T } where T: Copy | ^^^^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to previous error diff --git a/tests/ui/parser/issues/issue-43196.stderr b/tests/ui/parser/issues/issue-43196.stderr index 4f7ed5cc6fd..15bbb158cd1 100644 --- a/tests/ui/parser/issues/issue-43196.stderr +++ b/tests/ui/parser/issues/issue-43196.stderr @@ -11,6 +11,8 @@ error: expected item, found `|` | LL | | | ^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-62913.stderr b/tests/ui/parser/issues/issue-62913.stderr index 6f385e8dc17..c33e4683728 100644 --- a/tests/ui/parser/issues/issue-62913.stderr +++ b/tests/ui/parser/issues/issue-62913.stderr @@ -17,6 +17,8 @@ error: expected item, found `"\u\"` | LL | "\u\" | ^^^^^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 3 previous errors diff --git a/tests/ui/parser/issues/issue-68890.stderr b/tests/ui/parser/issues/issue-68890.stderr index 2a3bf6b41f0..0d7b53a67c5 100644 --- a/tests/ui/parser/issues/issue-68890.stderr +++ b/tests/ui/parser/issues/issue-68890.stderr @@ -15,6 +15,8 @@ error: expected item, found `)` | LL | enum e{A((?'a a+?+l))} | ^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 3 previous errors diff --git a/tests/ui/parser/macro/macro-expand-to-field.rs b/tests/ui/parser/macro/macro-expand-to-field.rs index 155872f7a5d..533511ecf5a 100644 --- a/tests/ui/parser/macro/macro-expand-to-field.rs +++ b/tests/ui/parser/macro/macro-expand-to-field.rs @@ -1,5 +1,7 @@ // compile-flags: --crate-type=lib +// https://github.com/rust-lang/rust/issues/113766 + macro_rules! field { ($name:ident:$type:ty) => { $name:$type @@ -13,15 +15,14 @@ macro_rules! variant { } struct Struct { + //~^ NOTE while parsing this struct field!(bar:u128), //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` //~| NOTE unexpected token after this a: u32, b: u32, - field!(recovers:()), //~ NOTE macros cannot expand to struct fields - //~^ ERROR unexpected token: `!` - //~^^ NOTE unexpected token after this + field!(recovers:()), } enum EnumVariant { @@ -35,7 +36,7 @@ enum EnumVariant { //~^ NOTE macros cannot expand to enum variants //~| ERROR unexpected token: `!` //~| NOTE unexpected token after this - Data { + Data { //~ NOTE while parsing this struct field!(x:u32), //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` @@ -44,27 +45,35 @@ enum EnumVariant { } enum EnumVariantField { - Named { + Named { //~ NOTE while parsing this struct field!(oopsies:()), //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` //~| unexpected token after this field!(oopsies2:()), - //~^ NOTE macros cannot expand to struct fields - //~| ERROR unexpected token: `!` - //~| unexpected token after this }, } union Union { + //~^ NOTE while parsing this union A: u32, field!(oopsies:()), //~^ NOTE macros cannot expand to union fields //~| ERROR unexpected token: `!` - //~| unexpected token after this + //~| NOTE unexpected token after this B: u32, field!(recovers:()), - //~^ NOTE macros cannot expand to union fields +} + +// https://github.com/rust-lang/rust/issues/114636 + +#[derive(Debug)] +pub struct Lazy { + //~^ NOTE while parsing this struct + unreachable!() + //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` - //~| unexpected token after this + //~| NOTE unexpected token after this } + +fn main() {} diff --git a/tests/ui/parser/macro/macro-expand-to-field.stderr b/tests/ui/parser/macro/macro-expand-to-field.stderr index adcd032f5c0..0bb71800081 100644 --- a/tests/ui/parser/macro/macro-expand-to-field.stderr +++ b/tests/ui/parser/macro/macro-expand-to-field.stderr @@ -1,21 +1,16 @@ error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:16:10 + --> $DIR/macro-expand-to-field.rs:19:10 | +LL | struct Struct { + | ------ while parsing this struct +LL | LL | field!(bar:u128), | ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:22:10 - | -LL | field!(recovers:()), - | ^ unexpected token after this - | - = note: macros cannot expand to struct fields - -error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:28:12 + --> $DIR/macro-expand-to-field.rs:29:12 | LL | variant!(whoops), | ^ unexpected token after this @@ -23,7 +18,7 @@ LL | variant!(whoops), = note: macros cannot expand to enum variants error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:34:12 + --> $DIR/macro-expand-to-field.rs:35:12 | LL | variant!(recovers), | ^ unexpected token after this @@ -31,44 +26,46 @@ LL | variant!(recovers), = note: macros cannot expand to enum variants error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:39:14 + --> $DIR/macro-expand-to-field.rs:40:14 | +LL | Data { + | ---- while parsing this struct LL | field!(x:u32), | ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:48:14 + --> $DIR/macro-expand-to-field.rs:49:14 | +LL | Named { + | ----- while parsing this struct LL | field!(oopsies:()), | ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:52:14 - | -LL | field!(oopsies2:()), - | ^ unexpected token after this - | - = note: macros cannot expand to struct fields - -error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:61:10 + --> $DIR/macro-expand-to-field.rs:60:10 | +LL | union Union { + | ----- while parsing this union +... LL | field!(oopsies:()), | ^ unexpected token after this | = note: macros cannot expand to union fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:66:10 + --> $DIR/macro-expand-to-field.rs:73:16 | -LL | field!(recovers:()), - | ^ unexpected token after this +LL | pub struct Lazy { + | ---- while parsing this struct +LL | +LL | unreachable!() + | ^ unexpected token after this | - = note: macros cannot expand to union fields + = note: macros cannot expand to struct fields -error: aborting due to 9 previous errors +error: aborting due to 7 previous errors diff --git a/tests/ui/parser/shebang/shebang-doc-comment.stderr b/tests/ui/parser/shebang/shebang-doc-comment.stderr index 2227d45ec5a..a36b2a2f72b 100644 --- a/tests/ui/parser/shebang/shebang-doc-comment.stderr +++ b/tests/ui/parser/shebang/shebang-doc-comment.stderr @@ -3,6 +3,8 @@ error: expected item, found `[` | LL | [allow(unused_variables)] | ^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to previous error diff --git a/tests/ui/parser/struct-literal-in-if.rs b/tests/ui/parser/struct-literal-in-if.rs index 2ce2c8f1899..c4a253c3da2 100644 --- a/tests/ui/parser/struct-literal-in-if.rs +++ b/tests/ui/parser/struct-literal-in-if.rs @@ -14,4 +14,9 @@ fn main() { }.hi() { println!("yo"); } + if let true = Foo { //~ ERROR struct literals are not allowed here + x: 3 + }.hi() { + println!("yo"); + } } diff --git a/tests/ui/parser/struct-literal-in-if.stderr b/tests/ui/parser/struct-literal-in-if.stderr index b5a9864bbc4..8b72469fcf5 100644 --- a/tests/ui/parser/struct-literal-in-if.stderr +++ b/tests/ui/parser/struct-literal-in-if.stderr @@ -14,5 +14,21 @@ LL | x: 3 LL ~ }).hi() { | -error: aborting due to previous error +error: struct literals are not allowed here + --> $DIR/struct-literal-in-if.rs:17:19 + | +LL | if let true = Foo { + | ___________________^ +LL | | x: 3 +LL | | }.hi() { + | |_____^ + | +help: surround the struct literal with parentheses + | +LL ~ if let true = (Foo { +LL | x: 3 +LL ~ }).hi() { + | + +error: aborting due to 2 previous errors diff --git a/tests/ui/parser/struct-literal-in-match-guard.rs b/tests/ui/parser/struct-literal-in-match-guard.rs index bf0551b5c97..bbee60e2817 100644 --- a/tests/ui/parser/struct-literal-in-match-guard.rs +++ b/tests/ui/parser/struct-literal-in-match-guard.rs @@ -3,6 +3,8 @@ // Unlike `if` condition, `match` guards accept struct literals. // This is detected in <https://github.com/rust-lang/rust/pull/74566#issuecomment-663613705>. +#![feature(if_let_guard)] + #[derive(PartialEq)] struct Foo { x: isize, @@ -11,6 +13,7 @@ struct Foo { fn foo(f: Foo) { match () { () if f == Foo { x: 42 } => {} + () if let Foo { x: 0.. } = Foo { x: 42 } => {} _ => {} } } diff --git a/tests/ui/parser/struct-literal-in-while.rs b/tests/ui/parser/struct-literal-in-while.rs index 5000ce85b7f..86931f7888d 100644 --- a/tests/ui/parser/struct-literal-in-while.rs +++ b/tests/ui/parser/struct-literal-in-while.rs @@ -14,4 +14,9 @@ fn main() { }.hi() { println!("yo"); } + while let true = Foo { //~ ERROR struct literals are not allowed here + x: 3 + }.hi() { + println!("yo"); + } } diff --git a/tests/ui/parser/struct-literal-in-while.stderr b/tests/ui/parser/struct-literal-in-while.stderr index 17e9277e074..13d003608a1 100644 --- a/tests/ui/parser/struct-literal-in-while.stderr +++ b/tests/ui/parser/struct-literal-in-while.stderr @@ -14,5 +14,21 @@ LL | x: 3 LL ~ }).hi() { | -error: aborting due to previous error +error: struct literals are not allowed here + --> $DIR/struct-literal-in-while.rs:17:22 + | +LL | while let true = Foo { + | ______________________^ +LL | | x: 3 +LL | | }.hi() { + | |_____^ + | +help: surround the struct literal with parentheses + | +LL ~ while let true = (Foo { +LL | x: 3 +LL ~ }).hi() { + | + +error: aborting due to 2 previous errors diff --git a/tests/ui/parser/virtual-structs.stderr b/tests/ui/parser/virtual-structs.stderr index a5211d83f84..268fc105796 100644 --- a/tests/ui/parser/virtual-structs.stderr +++ b/tests/ui/parser/virtual-structs.stderr @@ -3,6 +3,8 @@ error: expected item, found reserved keyword `virtual` | LL | virtual struct SuperStruct { | ^^^^^^^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to previous error diff --git a/tests/ui/pattern/issue-114896.rs b/tests/ui/pattern/issue-114896.rs new file mode 100644 index 00000000000..cde37f658d6 --- /dev/null +++ b/tests/ui/pattern/issue-114896.rs @@ -0,0 +1,7 @@ +fn main() { + fn x(a: &char) { + let &b = a; + b.make_ascii_uppercase(); +//~^ cannot borrow `b` as mutable, as it is not declared as mutable + } +} diff --git a/tests/ui/pattern/issue-114896.stderr b/tests/ui/pattern/issue-114896.stderr new file mode 100644 index 00000000000..ffeb7bc1365 --- /dev/null +++ b/tests/ui/pattern/issue-114896.stderr @@ -0,0 +1,11 @@ +error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable + --> $DIR/issue-114896.rs:4:9 + | +LL | let &b = a; + | -- help: consider changing this to be mutable: `&(mut b)` +LL | b.make_ascii_uppercase(); + | ^ cannot borrow as mutable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/pattern/usefulness/auxiliary/non-exhaustive.rs b/tests/ui/pattern/usefulness/auxiliary/non-exhaustive.rs new file mode 100644 index 00000000000..6f459b8268f --- /dev/null +++ b/tests/ui/pattern/usefulness/auxiliary/non-exhaustive.rs @@ -0,0 +1,2 @@ +#[non_exhaustive] +pub enum NonExhaustiveEnum { A, B } diff --git a/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs new file mode 100644 index 00000000000..0ee7856c680 --- /dev/null +++ b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs @@ -0,0 +1,12 @@ +fn main() { + let a = ""; + let b = ""; + match (a, b) { + //~^ ERROR non-exhaustive patterns: `(&_, _)` not covered [E0004] + //~| NOTE pattern `(&_, _)` not covered + //~| NOTE the matched value is of type `(&str, &str)` + //~| NOTE `&str` cannot be matched exhaustively, so a wildcard `_` is necessary + ("a", "b") => {} + ("c", "d") => {} + } +} diff --git a/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr new file mode 100644 index 00000000000..771fc320a13 --- /dev/null +++ b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr @@ -0,0 +1,17 @@ +error[E0004]: non-exhaustive patterns: `(&_, _)` not covered + --> $DIR/issue-105479-str-non-exhaustiveness.rs:4:11 + | +LL | match (a, b) { + | ^^^^^^ pattern `(&_, _)` not covered + | + = note: the matched value is of type `(&str, &str)` + = note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ ("c", "d") => {}, +LL + (&_, _) => todo!() + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/issue-30240.stderr b/tests/ui/pattern/usefulness/issue-30240.stderr index ff755d681ac..da8bbdffbf6 100644 --- a/tests/ui/pattern/usefulness/issue-30240.stderr +++ b/tests/ui/pattern/usefulness/issue-30240.stderr @@ -5,6 +5,7 @@ LL | match "world" { | ^^^^^^^ pattern `&_` not covered | = note: the matched value is of type `&str` + = note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ "hello" => {}, @@ -18,6 +19,7 @@ LL | match "world" { | ^^^^^^^ pattern `&_` not covered | = note: the matched value is of type `&str` + = note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ "hello" => {}, diff --git a/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.rs b/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.rs new file mode 100644 index 00000000000..3a8a74d1fd6 --- /dev/null +++ b/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.rs @@ -0,0 +1,18 @@ +// aux-build:non-exhaustive.rs + +extern crate non_exhaustive; + +use non_exhaustive::NonExhaustiveEnum; + +fn main() { + match Some(NonExhaustiveEnum::A) { + //~^ ERROR non-exhaustive patterns: `Some(_)` not covered [E0004] + //~| NOTE pattern `Some(_)` not covered + //~| NOTE `Option<NonExhaustiveEnum>` defined here + //~| NOTE the matched value is of type `Option<NonExhaustiveEnum>` + //~| NOTE `NonExhaustiveEnum` is marked as non-exhaustive + Some(NonExhaustiveEnum::A) => {} + Some(NonExhaustiveEnum::B) => {} + None => {} + } +} diff --git a/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr b/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr new file mode 100644 index 00000000000..9fbd871db7c --- /dev/null +++ b/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr @@ -0,0 +1,22 @@ +error[E0004]: non-exhaustive patterns: `Some(_)` not covered + --> $DIR/nested-non-exhaustive-enums.rs:8:11 + | +LL | match Some(NonExhaustiveEnum::A) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Some(_)` not covered + | +note: `Option<NonExhaustiveEnum>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<NonExhaustiveEnum>` + = note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(_) => todo!() + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/privacy/associated-item-privacy-inherent.rs b/tests/ui/privacy/associated-item-privacy-inherent.rs index 7b7c734a99a..81703ae1067 100644 --- a/tests/ui/privacy/associated-item-privacy-inherent.rs +++ b/tests/ui/privacy/associated-item-privacy-inherent.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces)] mod priv_nominal { pub struct Pub; diff --git a/tests/ui/privacy/associated-item-privacy-trait.rs b/tests/ui/privacy/associated-item-privacy-trait.rs index c686a21772e..db77a6a7258 100644 --- a/tests/ui/privacy/associated-item-privacy-trait.rs +++ b/tests/ui/privacy/associated-item-privacy-trait.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces, private_bounds)] mod priv_trait { trait PrivTr { diff --git a/tests/ui/privacy/associated-item-privacy-type-binding.rs b/tests/ui/privacy/associated-item-privacy-type-binding.rs index 9826b83a35d..95a4fbf639c 100644 --- a/tests/ui/privacy/associated-item-privacy-type-binding.rs +++ b/tests/ui/privacy/associated-item-privacy-type-binding.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces, private_bounds)] mod priv_trait { trait PrivTr { diff --git a/tests/ui/privacy/effective_visibilities_full_priv.rs b/tests/ui/privacy/effective_visibilities_full_priv.rs index a26ae3bd122..b96eddcab67 100644 --- a/tests/ui/privacy/effective_visibilities_full_priv.rs +++ b/tests/ui/privacy/effective_visibilities_full_priv.rs @@ -1,5 +1,5 @@ #![feature(rustc_attrs)] -#![allow(private_in_public)] +#![allow(private_interfaces)] struct SemiPriv; diff --git a/tests/ui/privacy/issue-30079.rs b/tests/ui/privacy/issue-30079.rs index a02a932d057..ddba629f528 100644 --- a/tests/ui/privacy/issue-30079.rs +++ b/tests/ui/privacy/issue-30079.rs @@ -3,8 +3,7 @@ struct SemiPriv; mod m1 { struct Priv; impl ::SemiPriv { - pub fn f(_: Priv) {} //~ WARN private type `m1::Priv` in public interface - //~^ WARNING hard error + pub fn f(_: Priv) {} //~ WARN type `m1::Priv` is more private than the item `m1::<impl SemiPriv>::f` } impl Priv { diff --git a/tests/ui/privacy/issue-30079.stderr b/tests/ui/privacy/issue-30079.stderr index 9179ff339bf..f1facba7cd2 100644 --- a/tests/ui/privacy/issue-30079.stderr +++ b/tests/ui/privacy/issue-30079.stderr @@ -1,15 +1,18 @@ -warning: private type `m1::Priv` in public interface (error E0446) +warning: type `m1::Priv` is more private than the item `m1::<impl SemiPriv>::f` --> $DIR/issue-30079.rs:6:9 | LL | pub fn f(_: Priv) {} - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ associated function `m1::<impl SemiPriv>::f` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default +note: but type `m1::Priv` is only usable at visibility `pub(self)` + --> $DIR/issue-30079.rs:4:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default error[E0446]: private type `m2::Priv` in public interface - --> $DIR/issue-30079.rs:18:9 + --> $DIR/issue-30079.rs:17:9 | LL | struct Priv; | ----------- `m2::Priv` declared as private @@ -18,7 +21,7 @@ LL | type Target = Priv; | ^^^^^^^^^^^ can't leak private type error[E0446]: private type `m3::Priv` in public interface - --> $DIR/issue-30079.rs:35:9 + --> $DIR/issue-30079.rs:34:9 | LL | struct Priv; | ----------- `m3::Priv` declared as private diff --git a/tests/ui/privacy/private-bounds-locally-allowed.rs b/tests/ui/privacy/private-bounds-locally-allowed.rs new file mode 100644 index 00000000000..96a007a64f6 --- /dev/null +++ b/tests/ui/privacy/private-bounds-locally-allowed.rs @@ -0,0 +1,7 @@ +// check-pass +// compile-flags: --crate-type=lib + +#[allow(private_bounds)] +pub trait Foo: FooImpl {} + +trait FooImpl {} diff --git a/tests/ui/privacy/private-in-public-assoc-ty.rs b/tests/ui/privacy/private-in-public-assoc-ty.rs index d4d379bdb73..5f7c4bcf265 100644 --- a/tests/ui/privacy/private-in-public-assoc-ty.rs +++ b/tests/ui/privacy/private-in-public-assoc-ty.rs @@ -22,14 +22,11 @@ mod m { // applies only to the aliased types, not bounds. pub trait PubTr { type Alias1: PrivTr; - //~^ WARN private trait `PrivTr` in public interface - //~| WARN this was previously accepted + //~^ WARN trait `PrivTr` is more private than the item `PubTr::Alias1` type Alias2: PubTrAux1<Priv> = u8; - //~^ WARN private type `Priv` in public interface - //~| WARN this was previously accepted + //~^ WARN type `Priv` is more private than the item `PubTr::Alias2` type Alias3: PubTrAux2<A = Priv> = u8; - //~^ WARN private type `Priv` in public interface - //~| WARN this was previously accepted + //~^ WARN type `Priv` is more private than the item `PubTr::Alias3` type Alias4 = Priv; //~^ ERROR private type `Priv` in public interface diff --git a/tests/ui/privacy/private-in-public-assoc-ty.stderr b/tests/ui/privacy/private-in-public-assoc-ty.stderr index a59027d81d2..0931e6d9971 100644 --- a/tests/ui/privacy/private-in-public-assoc-ty.stderr +++ b/tests/ui/privacy/private-in-public-assoc-ty.stderr @@ -7,36 +7,45 @@ LL | struct Priv; LL | type A = Priv; | ^^^^^^ can't leak private type -warning: private trait `PrivTr` in public interface (error E0445) +warning: trait `PrivTr` is more private than the item `PubTr::Alias1` --> $DIR/private-in-public-assoc-ty.rs:24:9 | LL | type Alias1: PrivTr; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias1` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default +note: but trait `PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-assoc-ty.rs:9:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default -warning: private type `Priv` in public interface (error E0446) - --> $DIR/private-in-public-assoc-ty.rs:27:9 +warning: type `Priv` is more private than the item `PubTr::Alias2` + --> $DIR/private-in-public-assoc-ty.rs:26:9 | LL | type Alias2: PubTrAux1<Priv> = u8; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias2` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-assoc-ty.rs:8:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -warning: private type `Priv` in public interface (error E0446) - --> $DIR/private-in-public-assoc-ty.rs:30:9 +warning: type `Priv` is more private than the item `PubTr::Alias3` + --> $DIR/private-in-public-assoc-ty.rs:28:9 | LL | type Alias3: PubTrAux2<A = Priv> = u8; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias3` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-assoc-ty.rs:8:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public-assoc-ty.rs:34:9 + --> $DIR/private-in-public-assoc-ty.rs:31:9 | LL | struct Priv; | ----------- `Priv` declared as private @@ -45,7 +54,7 @@ LL | type Alias4 = Priv; | ^^^^^^^^^^^ can't leak private type error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public-assoc-ty.rs:41:9 + --> $DIR/private-in-public-assoc-ty.rs:38:9 | LL | struct Priv; | ----------- `Priv` declared as private @@ -53,8 +62,8 @@ LL | struct Priv; LL | type Alias1 = Priv; | ^^^^^^^^^^^ can't leak private type -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/private-in-public-assoc-ty.rs:44:9 +error[E0446]: private trait `PrivTr` in public interface + --> $DIR/private-in-public-assoc-ty.rs:41:9 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -64,5 +73,4 @@ LL | type Exist = impl PrivTr; error: aborting due to 4 previous errors; 3 warnings emitted -Some errors have detailed explanations: E0445, E0446. -For more information about an error, try `rustc --explain E0445`. +For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/private-in-public-lint.rs b/tests/ui/privacy/private-in-public-lint.rs deleted file mode 100644 index 8b6e4360160..00000000000 --- a/tests/ui/privacy/private-in-public-lint.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod m1 { - pub struct Pub; - struct Priv; - - impl Pub { - pub fn f() -> Priv {Priv} //~ ERROR private type `m1::Priv` in public interface - } -} - -mod m2 { - pub struct Pub; - struct Priv; - - impl Pub { - pub fn f() -> Priv {Priv} //~ ERROR private type `m2::Priv` in public interface - } -} - -fn main() {} diff --git a/tests/ui/privacy/private-in-public-lint.stderr b/tests/ui/privacy/private-in-public-lint.stderr deleted file mode 100644 index 1e98e3bed14..00000000000 --- a/tests/ui/privacy/private-in-public-lint.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0446]: private type `m1::Priv` in public interface - --> $DIR/private-in-public-lint.rs:6:9 - | -LL | struct Priv; - | ----------- `m1::Priv` declared as private -... -LL | pub fn f() -> Priv {Priv} - | ^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `m2::Priv` in public interface - --> $DIR/private-in-public-lint.rs:15:9 - | -LL | struct Priv; - | ----------- `m2::Priv` declared as private -... -LL | pub fn f() -> Priv {Priv} - | ^^^^^^^^^^^^^^^^^^ can't leak private type - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/private-in-public-non-principal-2.rs b/tests/ui/privacy/private-in-public-non-principal-2.rs index db451d33429..d7223c647c0 100644 --- a/tests/ui/privacy/private-in-public-non-principal-2.rs +++ b/tests/ui/privacy/private-in-public-non-principal-2.rs @@ -1,7 +1,7 @@ #![feature(auto_traits)] #![feature(negative_impls)] -#[allow(private_in_public)] +#[allow(private_interfaces)] mod m { pub trait PubPrincipal {} auto trait PrivNonPrincipal {} diff --git a/tests/ui/privacy/private-in-public-non-principal.rs b/tests/ui/privacy/private-in-public-non-principal.rs index a2284c93027..e348a181651 100644 --- a/tests/ui/privacy/private-in-public-non-principal.rs +++ b/tests/ui/privacy/private-in-public-non-principal.rs @@ -1,19 +1,11 @@ #![feature(auto_traits)] #![feature(negative_impls)] -#![feature(type_privacy_lints)] -#![deny(private_interfaces)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. pub trait PubPrincipal {} auto trait PrivNonPrincipal {} pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } -//~^ WARN private trait `PrivNonPrincipal` in public interface -//~| WARN this was previously accepted -//~| ERROR trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` +//~^ WARN trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` #[deny(missing_docs)] fn container() { diff --git a/tests/ui/privacy/private-in-public-non-principal.stderr b/tests/ui/privacy/private-in-public-non-principal.stderr index 1387f59cbde..63512f462f5 100644 --- a/tests/ui/privacy/private-in-public-non-principal.stderr +++ b/tests/ui/privacy/private-in-public-non-principal.stderr @@ -1,41 +1,27 @@ -warning: private trait `PrivNonPrincipal` in public interface (error E0445) - --> $DIR/private-in-public-non-principal.rs:13:1 - | -LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default - -error: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` - --> $DIR/private-in-public-non-principal.rs:13:1 +warning: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` + --> $DIR/private-in-public-non-principal.rs:7:1 | LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `leak_dyn_nonprincipal` is reachable at visibility `pub` | note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public-non-principal.rs:11:1 + --> $DIR/private-in-public-non-principal.rs:5:1 | LL | auto trait PrivNonPrincipal {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/private-in-public-non-principal.rs:4:9 - | -LL | #![deny(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default error: missing documentation for an associated function - --> $DIR/private-in-public-non-principal.rs:21:9 + --> $DIR/private-in-public-non-principal.rs:13:9 | LL | pub fn check_doc_lint() {} | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/private-in-public-non-principal.rs:18:8 + --> $DIR/private-in-public-non-principal.rs:10:8 | LL | #[deny(missing_docs)] | ^^^^^^^^^^^^ -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to previous error; 1 warning emitted diff --git a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs index fe6ed46734c..3fb543e9624 100644 --- a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs +++ b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs @@ -1,7 +1,7 @@ // build-pass (FIXME(62277): could be check-pass?) #![feature(impl_trait_in_assoc_type)] #![feature(type_alias_impl_trait)] -#![deny(private_in_public)] +#![deny(private_interfaces, private_bounds)] pub type Pub = impl Default; diff --git a/tests/ui/privacy/private-in-public-warn.rs b/tests/ui/privacy/private-in-public-warn.rs index 0fa1de975b0..99d318e36be 100644 --- a/tests/ui/privacy/private-in-public-warn.rs +++ b/tests/ui/privacy/private-in-public-warn.rs @@ -2,7 +2,7 @@ // This test also ensures that the checks are performed even inside private modules. #![feature(associated_type_defaults)] -#![deny(private_in_public)] +#![deny(private_interfaces, private_bounds)] #![allow(improper_ctypes)] mod types { @@ -12,30 +12,21 @@ mod types { type Alias; } - pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + pub type Alias = Priv; //~ ERROR type `types::Priv` is more private than the item `types::Alias` pub enum E { - V1(Priv), //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + V1(Priv), //~ ERROR type `types::Priv` is more private than the item `E::V1::0` + V2 { field: Priv }, //~ ERROR type `types::Priv` is more private than the item `E::V2::field` } pub trait Tr { - const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + const C: Priv = Priv; //~ ERROR type `types::Priv` is more private than the item `Tr::C` type Alias = Priv; //~ ERROR private type `types::Priv` in public interface - fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + fn f1(arg: Priv) {} //~ ERROR type `types::Priv` is more private than the item `Tr::f1` + fn f2() -> Priv { panic!() } //~ ERROR type `types::Priv` is more private than the item `Tr::f2` } extern "C" { - pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error - pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface - //~^ WARNING hard error + pub static ES: Priv; //~ ERROR type `types::Priv` is more private than the item `types::ES` + pub fn ef1(arg: Priv); //~ ERROR type `types::Priv` is more private than the item `types::ef1` + pub fn ef2() -> Priv; //~ ERROR type `types::Priv` is more private than the item `types::ef2` } impl PubTr for Pub { type Alias = Priv; //~ ERROR private type `types::Priv` in public interface @@ -47,22 +38,16 @@ mod traits { pub struct Pub<T>(T); pub trait PubTr {} - pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface - //~| WARNING hard error - //~| WARNING bounds on generic parameters are not enforced in type aliases - pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error - pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + pub type Alias<T: PrivTr> = T; //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Alias` + //~^ WARNING bounds on generic parameters are not enforced in type aliases + pub trait Tr1: PrivTr {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr1` + pub trait Tr2<T: PrivTr> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr2` pub trait Tr3 { type Alias: PrivTr; - //~^ ERROR private trait `traits::PrivTr` in public interface - //~| WARNING hard error - fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + //~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias` + fn f<T: PrivTr>(arg: T) {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f` } - impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>` impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates } @@ -72,20 +57,16 @@ mod traits_where { pub trait PubTr {} pub type Alias<T> where T: PrivTr = T; - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Alias` //~| WARNING where clauses are not enforced in type aliases pub trait Tr2<T> where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2` pub trait Tr3 { fn f<T>(arg: T) where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f` } impl<T> Pub<T> where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + //~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` impl<T> PubTr for Pub<T> where T: PrivTr {} // OK, trait impl predicates } @@ -96,14 +77,10 @@ mod generics { pub trait PubTr<T> {} pub trait Tr1: PrivTr<Pub> {} - //~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface - //~| WARNING hard error - pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error - pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error - pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error + //~^ ERROR trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1` + pub trait Tr2: PubTr<Priv> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr2` + pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr3` + pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR type `generics::Priv` is more private than the item `Tr4` } mod impls { @@ -200,8 +177,7 @@ mod aliases_pub { pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK impl PrivAlias { - pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface - //~^ WARNING hard error + pub fn f(arg: Priv) {} //~ ERROR type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f` } impl PrivUseAliasTr for PrivUseAlias { type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface @@ -244,13 +220,10 @@ mod aliases_priv { } pub trait Tr1: PrivUseAliasTr {} - //~^ ERROR private trait `PrivTr1` in public interface - //~| WARNING hard error + //~^ ERROR trait `PrivTr1` is more private than the item `aliases_priv::Tr1` pub trait Tr2: PrivUseAliasTr<PrivAlias> {} - //~^ ERROR private trait `PrivTr1<Priv2>` in public interface - //~| WARNING hard error - //~| ERROR private type `Priv2` in public interface - //~| WARNING hard error + //~^ ERROR trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2` + //~| ERROR type `Priv2` is more private than the item `aliases_priv::Tr2` impl PrivUseAlias { pub fn f(arg: Priv) {} // OK diff --git a/tests/ui/privacy/private-in-public-warn.stderr b/tests/ui/privacy/private-in-public-warn.stderr index 66f91ce6fd6..6497b7ff535 100644 --- a/tests/ui/privacy/private-in-public-warn.stderr +++ b/tests/ui/privacy/private-in-public-warn.stderr @@ -1,46 +1,58 @@ -error: private type `types::Priv` in public interface (error E0446) +error: type `types::Priv` is more private than the item `types::Alias` --> $DIR/private-in-public-warn.rs:15:5 | LL | pub type Alias = Priv; - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ type alias `types::Alias` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ note: the lint level is defined here --> $DIR/private-in-public-warn.rs:5:9 | -LL | #![deny(private_in_public)] - | ^^^^^^^^^^^^^^^^^ +LL | #![deny(private_interfaces, private_bounds)] + | ^^^^^^^^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:18:12 +error: type `types::Priv` is more private than the item `E::V1::0` + --> $DIR/private-in-public-warn.rs:17:12 | LL | V1(Priv), - | ^^^^ + | ^^^^ field `E::V1::0` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:20:14 +error: type `types::Priv` is more private than the item `E::V2::field` + --> $DIR/private-in-public-warn.rs:18:14 | LL | V2 { field: Priv }, - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ field `E::V2::field` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:24:9 +error: type `types::Priv` is more private than the item `Tr::C` + --> $DIR/private-in-public-warn.rs:21:9 | LL | const C: Priv = Priv; - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ associated constant `Tr::C` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public-warn.rs:26:9 + --> $DIR/private-in-public-warn.rs:22:9 | LL | struct Priv; | ----------- `types::Priv` declared as private @@ -48,53 +60,68 @@ LL | struct Priv; LL | type Alias = Priv; | ^^^^^^^^^^ can't leak private type -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:27:9 +error: type `types::Priv` is more private than the item `Tr::f1` + --> $DIR/private-in-public-warn.rs:23:9 | LL | fn f1(arg: Priv) {} - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ associated function `Tr::f1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:29:9 +error: type `types::Priv` is more private than the item `Tr::f2` + --> $DIR/private-in-public-warn.rs:24:9 | LL | fn f2() -> Priv { panic!() } - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ associated function `Tr::f2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:33:9 +error: type `types::Priv` is more private than the item `types::ES` + --> $DIR/private-in-public-warn.rs:27:9 | LL | pub static ES: Priv; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:35:9 +error: type `types::Priv` is more private than the item `types::ef1` + --> $DIR/private-in-public-warn.rs:28:9 | LL | pub fn ef1(arg: Priv); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error: private type `types::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:37:9 +error: type `types::Priv` is more private than the item `types::ef2` + --> $DIR/private-in-public-warn.rs:29:9 | LL | pub fn ef2() -> Priv; - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public-warn.rs:41:9 + --> $DIR/private-in-public-warn.rs:32:9 | LL | struct Priv; | ----------- `types::Priv` declared as private @@ -102,134 +129,181 @@ LL | struct Priv; LL | type Alias = Priv; | ^^^^^^^^^^ can't leak private type -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:50:5 +error: trait `traits::PrivTr` is more private than the item `traits::Alias` + --> $DIR/private-in-public-warn.rs:41:5 | LL | pub type Alias<T: PrivTr> = T; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `traits::Alias` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/private-in-public-warn.rs:5:29 + | +LL | #![deny(private_interfaces, private_bounds)] + | ^^^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:53:5 +error: trait `traits::PrivTr` is more private than the item `traits::Tr1` + --> $DIR/private-in-public-warn.rs:43:5 | LL | pub trait Tr1: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr1` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:55:5 +error: trait `traits::PrivTr` is more private than the item `traits::Tr2` + --> $DIR/private-in-public-warn.rs:44:5 | LL | pub trait Tr2<T: PrivTr> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr2` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:58:9 +error: trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias` + --> $DIR/private-in-public-warn.rs:46:9 | LL | type Alias: PrivTr; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ associated type `traits::Tr3::Alias` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:61:9 +error: trait `traits::PrivTr` is more private than the item `traits::Tr3::f` + --> $DIR/private-in-public-warn.rs:48:9 | LL | fn f<T: PrivTr>(arg: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Tr3::f` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:64:5 +error: trait `traits::PrivTr` is more private than the item `traits::Pub<T>` + --> $DIR/private-in-public-warn.rs:50:5 | LL | impl<T: PrivTr> Pub<T> {} - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:74:5 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias` + --> $DIR/private-in-public-warn.rs:59:5 | LL | pub type Alias<T> where T: PrivTr = T; - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:78:5 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2` + --> $DIR/private-in-public-warn.rs:62:5 | LL | pub trait Tr2<T> where T: PrivTr {} - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:82:9 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f` + --> $DIR/private-in-public-warn.rs:65:9 | LL | fn f<T>(arg: T) where T: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Tr3::f` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:86:5 +error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` + --> $DIR/private-in-public-warn.rs:68:5 | LL | impl<T> Pub<T> where T: PrivTr {} - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `generics::PrivTr<generics::Pub>` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:98:5 +error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1` + --> $DIR/private-in-public-warn.rs:79:5 | LL | pub trait Tr1: PrivTr<Pub> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)` + | +note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:76:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | trait PrivTr<T> {} + | ^^^^^^^^^^^^^^^ -error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:101:5 +error: type `generics::Priv` is more private than the item `generics::Tr2` + --> $DIR/private-in-public-warn.rs:81:5 | LL | pub trait Tr2: PubTr<Priv> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ -error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:103:5 +error: type `generics::Priv` is more private than the item `generics::Tr3` + --> $DIR/private-in-public-warn.rs:82:5 | LL | pub trait Tr3: PubTr<[Priv; 1]> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr3` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 + | +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ -error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:105:5 +error: type `generics::Priv` is more private than the item `Tr4` + --> $DIR/private-in-public-warn.rs:83:5 | LL | pub trait Tr4: PubTr<Pub<Priv>> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ error[E0446]: private type `impls::Priv` in public interface - --> $DIR/private-in-public-warn.rs:132:9 + --> $DIR/private-in-public-warn.rs:109:9 | LL | struct Priv; | ----------- `impls::Priv` declared as private @@ -237,17 +311,20 @@ LL | struct Priv; LL | type Alias = Priv; | ^^^^^^^^^^ can't leak private type -error: private type `aliases_pub::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:203:9 +error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f` + --> $DIR/private-in-public-warn.rs:180:9 | LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::<impl Pub2>::f` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:153:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:207:9 + --> $DIR/private-in-public-warn.rs:183:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -256,7 +333,7 @@ LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:210:9 + --> $DIR/private-in-public-warn.rs:186:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -265,7 +342,7 @@ LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:213:9 + --> $DIR/private-in-public-warn.rs:189:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -274,7 +351,7 @@ LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:216:9 + --> $DIR/private-in-public-warn.rs:192:9 | LL | struct Priv; | ----------- `aliases_pub::Priv` declared as private @@ -282,35 +359,44 @@ LL | struct Priv; LL | type Check = Priv; | ^^^^^^^^^^ can't leak private type -error: private trait `PrivTr1` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:246:5 +error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1` + --> $DIR/private-in-public-warn.rs:222:5 | LL | pub trait Tr1: PrivUseAliasTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `PrivTr1` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:208:5 + | +LL | trait PrivTr1<T = u8> { + | ^^^^^^^^^^^^^^^^^^^^^ -error: private trait `PrivTr1<Priv2>` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:249:5 +error: trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2` + --> $DIR/private-in-public-warn.rs:224:5 | LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)` | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +note: but trait `PrivTr1<Priv2>` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:208:5 + | +LL | trait PrivTr1<T = u8> { + | ^^^^^^^^^^^^^^^^^^^^^ -error: private type `Priv2` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:249:5 +error: type `Priv2` is more private than the item `aliases_priv::Tr2` + --> $DIR/private-in-public-warn.rs:224:5 | LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)` + | +note: but type `Priv2` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:206:5 | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> +LL | struct Priv2; + | ^^^^^^^^^^^^ warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/private-in-public-warn.rs:50:23 + --> $DIR/private-in-public-warn.rs:41:23 | LL | pub type Alias<T: PrivTr> = T; | ^^^^^^ @@ -323,7 +409,7 @@ LL + pub type Alias<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/private-in-public-warn.rs:74:29 + --> $DIR/private-in-public-warn.rs:59:29 | LL | pub type Alias<T> where T: PrivTr = T; | ^^^^^^^^^ diff --git a/tests/ui/privacy/private-in-public.rs b/tests/ui/privacy/private-in-public.rs index dbd1c483f81..f54f9e38faa 100644 --- a/tests/ui/privacy/private-in-public.rs +++ b/tests/ui/privacy/private-in-public.rs @@ -1,3 +1,5 @@ +// check-pass + // Private types and traits are not allowed in public interfaces. // This test also ensures that the checks are performed even inside private modules. @@ -10,16 +12,16 @@ mod types { type Alias; } - pub const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - pub static S: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - pub fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface - pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface - pub struct S1(pub Priv); //~ ERROR private type `types::Priv` in public interface - pub struct S2 { pub field: Priv } //~ ERROR private type `types::Priv` in public interface + pub const C: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `C` + pub static S: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `S` + pub fn f1(arg: Priv) {} //~ WARNING `types::Priv` is more private than the item `types::f1` + pub fn f2() -> Priv { panic!() } //~ WARNING type `types::Priv` is more private than the item `types::f2` + pub struct S1(pub Priv); //~ WARNING type `types::Priv` is more private than the item `types::S1::0` + pub struct S2 { pub field: Priv } //~ WARNING `types::Priv` is more private than the item `S2::field` impl Pub { - pub const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface - pub fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface - pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface + pub const C: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `types::Pub::C` + pub fn f1(arg: Priv) {} //~ WARNING type `types::Priv` is more private than the item `types::Pub::f1` + pub fn f2() -> Priv { panic!() } //~ WARNING type `types::Priv` is more private than the item `types::Pub::f2` } } @@ -28,11 +30,11 @@ mod traits { pub struct Pub<T>(T); pub trait PubTr {} - pub enum E<T: PrivTr> { V(T) } //~ ERROR private trait `traits::PrivTr` in public interface - pub fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface - pub struct S1<T: PrivTr>(T); //~ ERROR private trait `traits::PrivTr` in public interface - impl<T: PrivTr> Pub<T> { //~ ERROR private trait `traits::PrivTr` in public interface - pub fn f<U: PrivTr>(arg: U) {} //~ ERROR private trait `traits::PrivTr` in public interface + pub enum E<T: PrivTr> { V(T) } //~ WARNING trait `traits::PrivTr` is more private than the item `traits::E` + pub fn f<T: PrivTr>(arg: T) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::f` + pub struct S1<T: PrivTr>(T); //~ WARNING trait `traits::PrivTr` is more private than the item `traits::S1` + impl<T: PrivTr> Pub<T> { //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub<T>` + pub fn f<U: PrivTr>(arg: U) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub::<T>::f` } } @@ -42,15 +44,15 @@ mod traits_where { pub trait PubTr {} pub enum E<T> where T: PrivTr { V(T) } - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::E` pub fn f<T>(arg: T) where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::f` pub struct S1<T>(T) where T: PrivTr; - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::S1` impl<T> Pub<T> where T: PrivTr { - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` pub fn f<U>(arg: U) where U: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface + //~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::Pub::<T>::f` } } @@ -60,10 +62,10 @@ mod generics { trait PrivTr<T> {} pub trait PubTr<T> {} - pub fn f1(arg: [Priv; 1]) {} //~ ERROR private type `generics::Priv` in public interface - pub fn f2(arg: Pub<Priv>) {} //~ ERROR private type `generics::Priv` in public interface + pub fn f1(arg: [Priv; 1]) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f1` + pub fn f2(arg: Pub<Priv>) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f2` pub fn f3(arg: Priv<Pub>) {} - //~^ ERROR private type `generics::Priv<generics::Pub>` in public interface + //~^ WARNING type `generics::Priv<generics::Pub>` is more private than the item `generics::f3` } mod impls { @@ -77,7 +79,7 @@ mod impls { } impl Pub { - pub fn f(arg: Priv) {} //~ ERROR private type `impls::Priv` in public interface + pub fn f(arg: Priv) {} //~ WARNING type `impls::Priv` is more private than the item `impls::Pub::f` } } @@ -102,11 +104,11 @@ mod aliases_pub { // This should be OK, but associated type aliases are not substituted yet pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - //~^ ERROR private trait `aliases_pub::PrivTr` in public interface - //~| ERROR private type `aliases_pub::Priv` in public interface + //~^ WARNING trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3` + //~| WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3` impl PrivUseAlias { - pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface + pub fn f(arg: Priv) {} } } @@ -128,11 +130,11 @@ mod aliases_priv { } impl PrivTr for Priv {} - pub fn f1(arg: PrivUseAlias) {} //~ ERROR private type `Priv1` in public interface - pub fn f2(arg: PrivAlias) {} //~ ERROR private type `Priv2` in public interface + pub fn f1(arg: PrivUseAlias) {} //~ WARNING type `Priv1` is more private than the item `aliases_priv::f1` + pub fn f2(arg: PrivAlias) {} //~ WARNING type `Priv2` is more private than the item `aliases_priv::f2` pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - //~^ ERROR private trait `aliases_priv::PrivTr` in public interface - //~| ERROR private type `aliases_priv::Priv` in public interface + //~^ WARNING trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3` + //~| WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3` } mod aliases_params { @@ -141,8 +143,8 @@ mod aliases_params { type Result<T> = ::std::result::Result<T, Priv>; pub fn f2(arg: PrivAliasGeneric) {} - //~^ ERROR private type `aliases_params::Priv` in public interface - pub fn f3(arg: Result<u8>) {} //~ ERROR private type `aliases_params::Priv` in public interface + //~^ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f2` + pub fn f3(arg: Result<u8>) {} //~ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f3` } fn main() {} diff --git a/tests/ui/privacy/private-in-public.stderr b/tests/ui/privacy/private-in-public.stderr index 887eebf53ef..d8f9fd00716 100644 --- a/tests/ui/privacy/private-in-public.stderr +++ b/tests/ui/privacy/private-in-public.stderr @@ -1,292 +1,376 @@ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:13:5 +warning: type `types::Priv` is more private than the item `C` + --> $DIR/private-in-public.rs:15:5 | -LL | struct Priv; - | ----------- `types::Priv` declared as private -... LL | pub const C: Priv = Priv; - | ^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:14:5 + | ^^^^^^^^^^^^^^^^^ constant `C` is reachable at visibility `pub(crate)` | -LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub static S: Priv = Priv; - | ^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:15:5 +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f1(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default -error[E0446]: private type `types::Priv` in public interface +warning: type `types::Priv` is more private than the item `S` --> $DIR/private-in-public.rs:16:5 | +LL | pub static S: Priv = Priv; + | ^^^^^^^^^^^^^^^^^^ static `S` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f2() -> Priv { panic!() } - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:17:19 +warning: type `types::Priv` is more private than the item `types::f1` + --> $DIR/private-in-public.rs:17:5 + | +LL | pub fn f1(arg: Priv) {} + | ^^^^^^^^^^^^^^^^^^^^ function `types::f1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub struct S1(pub Priv); - | ^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:18:21 +warning: type `types::Priv` is more private than the item `types::f2` + --> $DIR/private-in-public.rs:18:5 + | +LL | pub fn f2() -> Priv { panic!() } + | ^^^^^^^^^^^^^^^^^^^ function `types::f2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub struct S2 { pub field: Priv } - | ^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:20:9 +warning: type `types::Priv` is more private than the item `types::S1::0` + --> $DIR/private-in-public.rs:19:19 + | +LL | pub struct S1(pub Priv); + | ^^^^^^^^ field `types::S1::0` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub const C: Priv = Priv; - | ^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:21:9 +warning: type `types::Priv` is more private than the item `S2::field` + --> $DIR/private-in-public.rs:20:21 + | +LL | pub struct S2 { pub field: Priv } + | ^^^^^^^^^^^^^^^ field `S2::field` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f1(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `types::Priv` in public interface +warning: type `types::Priv` is more private than the item `types::Pub::C` --> $DIR/private-in-public.rs:22:9 | +LL | pub const C: Priv = Priv; + | ^^^^^^^^^^^^^^^^^ associated constant `types::Pub::C` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | LL | struct Priv; - | ----------- `types::Priv` declared as private -... -LL | pub fn f2() -> Priv { panic!() } - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:31:5 +warning: type `types::Priv` is more private than the item `types::Pub::f1` + --> $DIR/private-in-public.rs:23:9 | -LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub enum E<T: PrivTr> { V(T) } - | ^^^^^^^^^^^^^^^^^^^^^ can't leak private trait +LL | pub fn f1(arg: Priv) {} + | ^^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::f1` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:32:5 +warning: type `types::Priv` is more private than the item `types::Pub::f2` + --> $DIR/private-in-public.rs:24:9 | -LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub fn f<T: PrivTr>(arg: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait +LL | pub fn f2() -> Priv { panic!() } + | ^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::f2` is reachable at visibility `pub(crate)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:9:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface +warning: trait `traits::PrivTr` is more private than the item `traits::E` --> $DIR/private-in-public.rs:33:5 | +LL | pub enum E<T: PrivTr> { V(T) } + | ^^^^^^^^^^^^^^^^^^^^^ enum `traits::E` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 + | LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub struct S1<T: PrivTr>(T); - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ + = note: `#[warn(private_bounds)]` on by default -error[E0445]: private trait `traits::PrivTr` in public interface +warning: trait `traits::PrivTr` is more private than the item `traits::f` --> $DIR/private-in-public.rs:34:5 | +LL | pub fn f<T: PrivTr>(arg: T) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `traits::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 + | LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | impl<T: PrivTr> Pub<T> { - | ^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:35:9 +warning: trait `traits::PrivTr` is more private than the item `traits::S1` + --> $DIR/private-in-public.rs:35:5 + | +LL | pub struct S1<T: PrivTr>(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^ struct `traits::S1` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 | LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub fn f<U: PrivTr>(arg: U) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface - --> $DIR/private-in-public.rs:44:5 +warning: trait `traits::PrivTr` is more private than the item `traits::Pub<T>` + --> $DIR/private-in-public.rs:36:5 + | +LL | impl<T: PrivTr> Pub<T> { + | ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | pub enum E<T> where T: PrivTr { V(T) } - | ^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits::PrivTr` is more private than the item `traits::Pub::<T>::f` + --> $DIR/private-in-public.rs:37:9 + | +LL | pub fn f<U: PrivTr>(arg: U) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Pub::<T>::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:29:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::E` --> $DIR/private-in-public.rs:46:5 | +LL | pub enum E<T> where T: PrivTr { V(T) } + | ^^^^^^^^^^^^^ enum `traits_where::E` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | pub fn f<T>(arg: T) where T: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::f` --> $DIR/private-in-public.rs:48:5 | +LL | pub fn f<T>(arg: T) where T: PrivTr {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `traits_where::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | pub struct S1<T>(T) where T: PrivTr; - | ^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::S1` --> $DIR/private-in-public.rs:50:5 | +LL | pub struct S1<T>(T) where T: PrivTr; + | ^^^^^^^^^^^^^^^^ struct `traits_where::S1` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... -LL | impl<T> Pub<T> where T: PrivTr { - | ^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface - --> $DIR/private-in-public.rs:52:9 +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>` + --> $DIR/private-in-public.rs:52:5 + | +LL | impl<T> Pub<T> where T: PrivTr { + | ^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 | LL | trait PrivTr {} - | ------------ `traits_where::PrivTr` declared as private -... + | ^^^^^^^^^^^^ + +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub::<T>::f` + --> $DIR/private-in-public.rs:54:9 + | LL | pub fn f<U>(arg: U) where U: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Pub::<T>::f` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:42:5 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error[E0446]: private type `generics::Priv` in public interface - --> $DIR/private-in-public.rs:63:5 +warning: type `generics::Priv` is more private than the item `generics::f1` + --> $DIR/private-in-public.rs:65:5 | -LL | struct Priv<T = u8>(T); - | ------------------- `generics::Priv` declared as private -... LL | pub fn f1(arg: [Priv; 1]) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `generics::Priv` in public interface - --> $DIR/private-in-public.rs:64:5 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f1` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:60:5 | LL | struct Priv<T = u8>(T); - | ------------------- `generics::Priv` declared as private -... -LL | pub fn f2(arg: Pub<Priv>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `generics::Priv<generics::Pub>` in public interface - --> $DIR/private-in-public.rs:65:5 +warning: type `generics::Priv` is more private than the item `generics::f2` + --> $DIR/private-in-public.rs:66:5 + | +LL | pub fn f2(arg: Pub<Priv>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f2` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:60:5 | LL | struct Priv<T = u8>(T); - | ------------------- `generics::Priv<generics::Pub>` declared as private -... + | ^^^^^^^^^^^^^^^^^^^ + +warning: type `generics::Priv<generics::Pub>` is more private than the item `generics::f3` + --> $DIR/private-in-public.rs:67:5 + | LL | pub fn f3(arg: Priv<Pub>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f3` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv<generics::Pub>` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:60:5 + | +LL | struct Priv<T = u8>(T); + | ^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `impls::Priv` in public interface - --> $DIR/private-in-public.rs:80:9 +warning: type `impls::Priv` is more private than the item `impls::Pub::f` + --> $DIR/private-in-public.rs:82:9 | -LL | struct Priv; - | ----------- `impls::Priv` declared as private -... LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^ associated function `impls::Pub::f` is reachable at visibility `pub(crate)` + | +note: but type `impls::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:72:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error[E0445]: private trait `aliases_pub::PrivTr` in public interface - --> $DIR/private-in-public.rs:104:5 +warning: trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3` + --> $DIR/private-in-public.rs:106:5 | -LL | trait PrivTr { - | ------------ `aliases_pub::PrivTr` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)` + | +note: but trait `aliases_pub::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:100:5 + | +LL | trait PrivTr { + | ^^^^^^^^^^^^ -error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public.rs:104:5 +warning: type `aliases_pub::Priv` is more private than the item `aliases_pub::f3` + --> $DIR/private-in-public.rs:106:5 | -LL | struct Priv; - | ----------- `aliases_pub::Priv` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public.rs:109:9 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)` + | +note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:87:5 | LL | struct Priv; - | ----------- `aliases_pub::Priv` declared as private -... -LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `Priv1` in public interface - --> $DIR/private-in-public.rs:131:5 +warning: type `Priv1` is more private than the item `aliases_priv::f1` + --> $DIR/private-in-public.rs:133:5 | -LL | struct Priv1; - | ------------ `Priv1` declared as private -... LL | pub fn f1(arg: PrivUseAlias) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f1` is reachable at visibility `pub(crate)` + | +note: but type `Priv1` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:118:5 + | +LL | struct Priv1; + | ^^^^^^^^^^^^ -error[E0446]: private type `Priv2` in public interface - --> $DIR/private-in-public.rs:132:5 +warning: type `Priv2` is more private than the item `aliases_priv::f2` + --> $DIR/private-in-public.rs:134:5 | -LL | struct Priv2; - | ------------ `Priv2` declared as private -... LL | pub fn f2(arg: PrivAlias) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f2` is reachable at visibility `pub(crate)` + | +note: but type `Priv2` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:119:5 + | +LL | struct Priv2; + | ^^^^^^^^^^^^ -error[E0445]: private trait `aliases_priv::PrivTr` in public interface - --> $DIR/private-in-public.rs:133:5 +warning: trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3` + --> $DIR/private-in-public.rs:135:5 | -LL | trait PrivTr { - | ------------ `aliases_priv::PrivTr` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)` + | +note: but trait `aliases_priv::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:128:5 + | +LL | trait PrivTr { + | ^^^^^^^^^^^^ -error[E0446]: private type `aliases_priv::Priv` in public interface - --> $DIR/private-in-public.rs:133:5 +warning: type `aliases_priv::Priv` is more private than the item `aliases_priv::f3` + --> $DIR/private-in-public.rs:135:5 | -LL | struct Priv; - | ----------- `aliases_priv::Priv` declared as private -... LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `aliases_params::Priv` in public interface - --> $DIR/private-in-public.rs:143:5 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)` + | +note: but type `aliases_priv::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:116:5 | LL | struct Priv; - | ----------- `aliases_params::Priv` declared as private -... -LL | pub fn f2(arg: PrivAliasGeneric) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `aliases_params::Priv` in public interface +warning: type `aliases_params::Priv` is more private than the item `aliases_params::f2` --> $DIR/private-in-public.rs:145:5 | +LL | pub fn f2(arg: PrivAliasGeneric) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_params::f2` is reachable at visibility `pub(crate)` + | +note: but type `aliases_params::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:141:5 + | LL | struct Priv; - | ----------- `aliases_params::Priv` declared as private -... + | ^^^^^^^^^^^ + +warning: type `aliases_params::Priv` is more private than the item `aliases_params::f3` + --> $DIR/private-in-public.rs:147:5 + | LL | pub fn f3(arg: Result<u8>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_params::f3` is reachable at visibility `pub(crate)` + | +note: but type `aliases_params::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public.rs:141:5 + | +LL | struct Priv; + | ^^^^^^^^^^^ -error: aborting due to 32 previous errors +warning: 31 warnings emitted -Some errors have detailed explanations: E0445, E0446. -For more information about an error, try `rustc --explain E0445`. diff --git a/tests/ui/privacy/private-inferred-type-2.rs b/tests/ui/privacy/private-inferred-type-2.rs index 15b263b3814..1c4c52bea28 100644 --- a/tests/ui/privacy/private-inferred-type-2.rs +++ b/tests/ui/privacy/private-inferred-type-2.rs @@ -1,4 +1,5 @@ // aux-build:private-inferred-type.rs +#![allow(private_interfaces)] extern crate private_inferred_type as ext; diff --git a/tests/ui/privacy/private-inferred-type-2.stderr b/tests/ui/privacy/private-inferred-type-2.stderr index 3a0fc03b4d5..8a905f5d88a 100644 --- a/tests/ui/privacy/private-inferred-type-2.stderr +++ b/tests/ui/privacy/private-inferred-type-2.stderr @@ -1,17 +1,17 @@ error: type `Priv` is private - --> $DIR/private-inferred-type-2.rs:16:5 + --> $DIR/private-inferred-type-2.rs:17:5 | LL | m::Pub::get_priv; | ^^^^^^^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-inferred-type-2.rs:17:5 + --> $DIR/private-inferred-type-2.rs:18:5 | LL | m::Pub::static_method; | ^^^^^^^^^^^^^^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-inferred-type-2.rs:18:5 + --> $DIR/private-inferred-type-2.rs:19:5 | LL | ext::Pub::static_method; | ^^^^^^^^^^^^^^^^^^^^^^^ private type diff --git a/tests/ui/privacy/private-inferred-type.rs b/tests/ui/privacy/private-inferred-type.rs index e8743dd968f..8c07226fe0e 100644 --- a/tests/ui/privacy/private-inferred-type.rs +++ b/tests/ui/privacy/private-inferred-type.rs @@ -1,5 +1,5 @@ #![feature(decl_macro)] -#![allow(private_in_public)] +#![allow(private_interfaces)] mod m { fn priv_fn() {} diff --git a/tests/ui/privacy/private-type-in-interface.rs b/tests/ui/privacy/private-type-in-interface.rs index 7fbdbaf5f31..39e0bf23cac 100644 --- a/tests/ui/privacy/private-type-in-interface.rs +++ b/tests/ui/privacy/private-type-in-interface.rs @@ -1,6 +1,7 @@ // aux-build:private-inferred-type.rs #![allow(warnings)] +#![allow(private_interfaces)] extern crate private_inferred_type as ext; diff --git a/tests/ui/privacy/private-type-in-interface.stderr b/tests/ui/privacy/private-type-in-interface.stderr index 4e87caa3415..03225d84fdb 100644 --- a/tests/ui/privacy/private-type-in-interface.stderr +++ b/tests/ui/privacy/private-type-in-interface.stderr @@ -1,53 +1,53 @@ error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:15:9 + --> $DIR/private-type-in-interface.rs:16:9 | LL | fn f(_: m::Alias) {} | ^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:15:6 + --> $DIR/private-type-in-interface.rs:16:6 | LL | fn f(_: m::Alias) {} | ^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:17:13 + --> $DIR/private-type-in-interface.rs:18:13 | LL | fn f_ext(_: ext::Alias) {} | ^^^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:17:10 + --> $DIR/private-type-in-interface.rs:18:10 | LL | fn f_ext(_: ext::Alias) {} | ^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:21:6 + --> $DIR/private-type-in-interface.rs:22:6 | LL | impl m::Alias {} | ^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:22:14 + --> $DIR/private-type-in-interface.rs:23:14 | LL | impl Tr1 for ext::Alias {} | ^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:23:10 + --> $DIR/private-type-in-interface.rs:24:10 | LL | type A = <m::Alias as m::Trait>::X; | ^^^^^^^^^^^^^^^^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-type-in-interface.rs:27:11 + --> $DIR/private-type-in-interface.rs:28:11 | LL | fn g() -> impl Tr2<m::Alias> { 0 } | ^^^^^^^^^^^^^^^^^^ private type error: type `ext::Priv` is private - --> $DIR/private-type-in-interface.rs:28:15 + --> $DIR/private-type-in-interface.rs:29:15 | LL | fn g_ext() -> impl Tr2<ext::Alias> { 0 } | ^^^^^^^^^^^^^^^^^^^^ private type diff --git a/tests/ui/privacy/restricted/private-in-public.rs b/tests/ui/privacy/restricted/private-in-public.rs index 1e3dbdf73b9..80a7e6ad0a7 100644 --- a/tests/ui/privacy/restricted/private-in-public.rs +++ b/tests/ui/privacy/restricted/private-in-public.rs @@ -1,10 +1,11 @@ +// check-pass mod foo { struct Priv; mod bar { use foo::Priv; pub(super) fn f(_: Priv) {} - pub(crate) fn g(_: Priv) {} //~ ERROR E0446 - pub(crate) fn h(_: Priv) {} //~ ERROR E0446 + pub(crate) fn g(_: Priv) {} + pub(crate) fn h(_: Priv) {} } } diff --git a/tests/ui/privacy/restricted/private-in-public.stderr b/tests/ui/privacy/restricted/private-in-public.stderr deleted file mode 100644 index 65d996f0f07..00000000000 --- a/tests/ui/privacy/restricted/private-in-public.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public.rs:6:9 - | -LL | struct Priv; - | ----------- `Priv` declared as private -... -LL | pub(crate) fn g(_: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public.rs:7:9 - | -LL | struct Priv; - | ----------- `Priv` declared as private -... -LL | pub(crate) fn h(_: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/unnameable_types.rs b/tests/ui/privacy/unnameable_types.rs index 46e24915259..c6c5561c3c4 100644 --- a/tests/ui/privacy/unnameable_types.rs +++ b/tests/ui/privacy/unnameable_types.rs @@ -1,5 +1,4 @@ #![feature(type_privacy_lints)] -#![allow(private_in_public)] #![deny(unnameable_types)] mod m { @@ -21,10 +20,10 @@ mod m { } } -pub trait Voldemort<T> {} +pub trait Unnameable<T> {} -impl Voldemort<m::PubStruct> for i32 {} -impl Voldemort<m::PubE> for i32 {} -impl<T> Voldemort<T> for u32 where T: m::PubTr {} +impl Unnameable<m::PubStruct> for i32 {} +impl Unnameable<m::PubE> for i32 {} +impl<T> Unnameable<T> for u32 where T: m::PubTr {} fn main() {} diff --git a/tests/ui/privacy/unnameable_types.stderr b/tests/ui/privacy/unnameable_types.stderr index 90412752575..d68a11c9728 100644 --- a/tests/ui/privacy/unnameable_types.stderr +++ b/tests/ui/privacy/unnameable_types.stderr @@ -1,23 +1,23 @@ error: struct `PubStruct` is reachable but cannot be named - --> $DIR/unnameable_types.rs:6:5 + --> $DIR/unnameable_types.rs:5:5 | LL | pub struct PubStruct(pub i32); | ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` | note: the lint level is defined here - --> $DIR/unnameable_types.rs:3:9 + --> $DIR/unnameable_types.rs:2:9 | LL | #![deny(unnameable_types)] | ^^^^^^^^^^^^^^^^ error: enum `PubE` is reachable but cannot be named - --> $DIR/unnameable_types.rs:8:5 + --> $DIR/unnameable_types.rs:7:5 | LL | pub enum PubE { | ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` error: trait `PubTr` is reachable but cannot be named - --> $DIR/unnameable_types.rs:12:5 + --> $DIR/unnameable_types.rs:11:5 | LL | pub trait PubTr { | ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` diff --git a/tests/ui/privacy/where-priv-type.rs b/tests/ui/privacy/where-priv-type.rs index 2e0a6b3e72c..cd9cce7ec3e 100644 --- a/tests/ui/privacy/where-priv-type.rs +++ b/tests/ui/privacy/where-priv-type.rs @@ -3,14 +3,7 @@ #![crate_type = "lib"] #![feature(generic_const_exprs)] -#![feature(type_privacy_lints)] #![allow(incomplete_features)] -#![warn(private_bounds)] -#![warn(private_interfaces)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. struct PrivTy; trait PrivTr {} @@ -23,42 +16,33 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } pub struct S -//~^ WARNING private type `PrivTy` in public interface -//~| WARNING hard error -//~| WARNING type `PrivTy` is more private than the item `S` +//~^ WARNING type `PrivTy` is more private than the item `S` where PrivTy: {} pub enum E -//~^ WARNING private type `PrivTy` in public interface -//~| WARNING hard error -//~| WARNING type `PrivTy` is more private than the item `E` +//~^ WARNING type `PrivTy` is more private than the item `E` where PrivTy: {} pub fn f() -//~^ WARNING private type `PrivTy` in public interface -//~| WARNING hard error -//~| WARNING type `PrivTy` is more private than the item `f` +//~^ WARNING type `PrivTy` is more private than the item `f` where PrivTy: {} impl S -//~^ ERROR private type `PrivTy` in public interface -//~| WARNING type `PrivTy` is more private than the item `S` +//~^ WARNING type `PrivTy` is more private than the item `S` where PrivTy: { pub fn f() - //~^ WARNING private type `PrivTy` in public interface - //~| WARNING hard error - //~| WARNING type `PrivTy` is more private than the item `S::f` + //~^ WARNING type `PrivTy` is more private than the item `S::f` where PrivTy: {} @@ -90,7 +74,6 @@ where { type AssocTy = Const<{ my_const_fn(U) }>; //~^ ERROR private type - //~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy` fn assoc_fn() -> Self::AssocTy { Const } diff --git a/tests/ui/privacy/where-priv-type.stderr b/tests/ui/privacy/where-priv-type.stderr index d6baf22b3fb..dcc249c6351 100644 --- a/tests/ui/privacy/where-priv-type.stderr +++ b/tests/ui/privacy/where-priv-type.stderr @@ -1,136 +1,72 @@ -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:25:1 - | -LL | pub struct S - | ^^^^^^^^^^^^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - = note: `#[warn(private_in_public)]` on by default - warning: type `PrivTy` is more private than the item `S` - --> $DIR/where-priv-type.rs:25:1 + --> $DIR/where-priv-type.rs:18:1 | LL | pub struct S | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:15:1 + --> $DIR/where-priv-type.rs:8:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/where-priv-type.rs:8:9 - | -LL | #![warn(private_bounds)] - | ^^^^^^^^^^^^^^ - -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:34:1 - | -LL | pub enum E - | ^^^^^^^^^^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> + = note: `#[warn(private_bounds)]` on by default warning: type `PrivTy` is more private than the item `E` - --> $DIR/where-priv-type.rs:34:1 + --> $DIR/where-priv-type.rs:25:1 | LL | pub enum E | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:15:1 + --> $DIR/where-priv-type.rs:8:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:43:1 - | -LL | / pub fn f() -LL | | -LL | | -LL | | -LL | | where -LL | | PrivTy: - | |___________^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - warning: type `PrivTy` is more private than the item `f` - --> $DIR/where-priv-type.rs:43:1 + --> $DIR/where-priv-type.rs:32:1 | LL | / pub fn f() LL | | -LL | | -LL | | LL | | where LL | | PrivTy: | |___________^ function `f` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:15:1 + --> $DIR/where-priv-type.rs:8:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ -error[E0446]: private type `PrivTy` in public interface - --> $DIR/where-priv-type.rs:52:1 - | -LL | struct PrivTy; - | ------------- `PrivTy` declared as private -... -LL | impl S - | ^^^^^^ can't leak private type - warning: type `PrivTy` is more private than the item `S` - --> $DIR/where-priv-type.rs:52:1 + --> $DIR/where-priv-type.rs:39:1 | LL | impl S | ^^^^^^ implementation `S` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:15:1 + --> $DIR/where-priv-type.rs:8:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ -warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:58:5 - | -LL | / pub fn f() -LL | | -LL | | -LL | | -LL | | where -LL | | PrivTy: - | |_______________^ - | - = 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 #34537 <https://github.com/rust-lang/rust/issues/34537> - warning: type `PrivTy` is more private than the item `S::f` - --> $DIR/where-priv-type.rs:58:5 + --> $DIR/where-priv-type.rs:44:5 | LL | / pub fn f() LL | | -LL | | -LL | | LL | | where LL | | PrivTy: | |_______________^ associated function `S::f` is reachable at visibility `pub` | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:15:1 + --> $DIR/where-priv-type.rs:8:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/where-priv-type.rs:91:5 + --> $DIR/where-priv-type.rs:75:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type @@ -138,23 +74,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>; LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private -warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy` - --> $DIR/where-priv-type.rs:91:5 - | -LL | type AssocTy = Const<{ my_const_fn(U) }>; - | ^^^^^^^^^^^^ associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub` - | -note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:99:1 - | -LL | const fn my_const_fn(val: u8) -> u8 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/where-priv-type.rs:9:9 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors; 10 warnings emitted +error: aborting due to previous error; 5 warnings emitted For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs index c59fdb7c7a9..d5e797b52b3 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -1,14 +1,10 @@ +// check-pass + // priv-in-pub lint tests where the private trait bounds a public type #![crate_type = "lib"] #![feature(generic_const_exprs)] -#![feature(type_privacy_lints)] #![allow(incomplete_features)] -#![warn(private_bounds)] - -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. struct PrivTy; trait PrivTr {} @@ -22,38 +18,33 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } pub struct S -//~^ ERROR private trait `PrivTr` in public interface -//~| WARNING trait `PrivTr` is more private than the item `S` +//~^ WARNING trait `PrivTr` is more private than the item `S` where PubTy: PrivTr {} pub enum E -//~^ ERROR private trait `PrivTr` in public interface -//~| WARNING trait `PrivTr` is more private than the item `E` +//~^ WARNING trait `PrivTr` is more private than the item `E` where PubTy: PrivTr {} pub fn f() -//~^ ERROR private trait `PrivTr` in public interface -//~| WARNING trait `PrivTr` is more private than the item `f` +//~^ WARNING trait `PrivTr` is more private than the item `f` where PubTy: PrivTr {} impl S -//~^ ERROR private trait `PrivTr` in public interface -//~| WARNING trait `PrivTr` is more private than the item `S` +//~^ WARNING trait `PrivTr` is more private than the item `S` where PubTy: PrivTr { pub fn f() - //~^ ERROR private trait `PrivTr` in public interface - //~| WARNING trait `PrivTr` is more private than the item `S::f` + //~^ WARNING trait `PrivTr` is more private than the item `S::f` where PubTy: PrivTr {} diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr index e2d7ce44692..c476874332c 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -1,129 +1,69 @@ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:24:1 - | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... -LL | pub struct S - | ^^^^^^^^^^^^ can't leak private trait - warning: trait `PrivTr` is more private than the item `S` - --> $DIR/where-pub-type-impls-priv-trait.rs:24:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:20:1 | LL | pub struct S | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/where-pub-type-impls-priv-trait.rs:7:9 - | -LL | #![warn(private_bounds)] - | ^^^^^^^^^^^^^^ - -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:32:1 - | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... -LL | pub enum E - | ^^^^^^^^^^ can't leak private trait + = note: `#[warn(private_bounds)]` on by default warning: trait `PrivTr` is more private than the item `E` - --> $DIR/where-pub-type-impls-priv-trait.rs:32:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:27:1 | LL | pub enum E | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 - | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... -LL | / pub fn f() -LL | | -LL | | -LL | | where -LL | | PubTy: PrivTr - | |_________________^ can't leak private trait - warning: trait `PrivTr` is more private than the item `f` - --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:34:1 | LL | / pub fn f() LL | | -LL | | LL | | where LL | | PubTy: PrivTr | |_________________^ function `f` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:48:1 - | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... -LL | impl S - | ^^^^^^ can't leak private trait - warning: trait `PrivTr` is more private than the item `S` - --> $DIR/where-pub-type-impls-priv-trait.rs:48:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:41:1 | LL | impl S | ^^^^^^ implementation `S` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ -error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:54:5 - | -LL | trait PrivTr {} - | ------------ `PrivTr` declared as private -... -LL | / pub fn f() -LL | | -LL | | -LL | | where -LL | | PubTy: PrivTr - | |_____________________^ can't leak private trait - warning: trait `PrivTr` is more private than the item `S::f` - --> $DIR/where-pub-type-impls-priv-trait.rs:54:5 + --> $DIR/where-pub-type-impls-priv-trait.rs:46:5 | LL | / pub fn f() LL | | -LL | | LL | | where LL | | PubTy: PrivTr | |_____________________^ associated function `S::f` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ -error: aborting due to 5 previous errors; 5 warnings emitted +warning: 5 warnings emitted -For more information about this error, try `rustc --explain E0445`. diff --git a/tests/ui/proc-macro/allowed-signatures.rs b/tests/ui/proc-macro/allowed-signatures.rs index 86850876112..ce327901b1a 100644 --- a/tests/ui/proc-macro/allowed-signatures.rs +++ b/tests/ui/proc-macro/allowed-signatures.rs @@ -3,7 +3,7 @@ // no-prefer-dynamic #![crate_type = "proc-macro"] -#![allow(private_in_public)] +#![allow(private_interfaces)] extern crate proc_macro; use proc_macro::TokenStream; diff --git a/tests/ui/proc-macro/bad-projection.stderr b/tests/ui/proc-macro/bad-projection.stderr index 8a8246376fe..8716defa17a 100644 --- a/tests/ui/proc-macro/bad-projection.stderr +++ b/tests/ui/proc-macro/bad-projection.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): Project` is not satisfied | LL | pub fn uwu() -> <() as Project>::Assoc {} | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Project` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/bad-projection.rs:9:1 + | +LL | trait Project { + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs index cdeea6224b2..7930964c83b 100644 --- a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs +++ b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs @@ -1,44 +1,24 @@ -#![feature(type_privacy_lints)] -#![allow(non_camel_case_types)] // genus is always capitalized -#![warn(private_interfaces)] -//~^ NOTE the lint level is defined here +// check-pass -// In this test both old and new private-in-public diagnostic were emitted. -// Old diagnostic will be deleted soon. -// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. +#![allow(non_camel_case_types)] // genus is always capitalized pub(crate) struct Snail; -//~^ NOTE `Snail` declared as private -//~| NOTE but type `Snail` is only usable at visibility `pub(crate)` mod sea { pub(super) struct Turtle; - //~^ NOTE `Turtle` declared as crate-private - //~| NOTE but type `Turtle` is only usable at visibility `pub(crate)` } struct Tortoise; -//~^ NOTE `Tortoise` declared as private -//~| NOTE but type `Tortoise` is only usable at visibility `pub(crate)` pub struct Shell<T> { pub(crate) creature: T, } pub type Helix_pomatia = Shell<Snail>; -//~^ ERROR private type `Snail` in public interface -//~| WARNING type `Snail` is more private than the item `Helix_pomatia` -//~| NOTE can't leak private type -//~| NOTE type alias `Helix_pomatia` is reachable at visibility `pub` +//~^ WARNING type `Snail` is more private than the item `Helix_pomatia` pub type Dermochelys_coriacea = Shell<sea::Turtle>; -//~^ ERROR crate-private type `Turtle` in public interface -//~| WARNING type `Turtle` is more private than the item `Dermochelys_coriacea` -//~| NOTE can't leak crate-private type -//~| NOTE type alias `Dermochelys_coriacea` is reachable at visibility `pub` +//~^ WARNING type `Turtle` is more private than the item `Dermochelys_coriacea` pub type Testudo_graeca = Shell<Tortoise>; -//~^ ERROR private type `Tortoise` in public interface -//~| WARNING type `Tortoise` is more private than the item `Testudo_graeca` -//~| NOTE can't leak private type -//~| NOTE type alias `Testudo_graeca` is reachable at visibility `pub` +//~^ WARNING type `Tortoise` is more private than the item `Testudo_graeca` fn main() {} diff --git a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr index 20e51e1901f..26dfa2e7d4f 100644 --- a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr +++ b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr @@ -1,71 +1,39 @@ -error[E0446]: private type `Snail` in public interface - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1 - | -LL | pub(crate) struct Snail; - | ----------------------- `Snail` declared as private -... -LL | pub type Helix_pomatia = Shell<Snail>; - | ^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - warning: type `Snail` is more private than the item `Helix_pomatia` - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:17:1 | LL | pub type Helix_pomatia = Shell<Snail>; | ^^^^^^^^^^^^^^^^^^^^^^ type alias `Helix_pomatia` is reachable at visibility `pub` | note: but type `Snail` is only usable at visibility `pub(crate)` - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:10:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:5:1 | LL | pub(crate) struct Snail; | ^^^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:3:9 - | -LL | #![warn(private_interfaces)] - | ^^^^^^^^^^^^^^^^^^ - -error[E0446]: crate-private type `Turtle` in public interface - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:33:1 - | -LL | pub(super) struct Turtle; - | ------------------------ `Turtle` declared as crate-private -... -LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-private type + = note: `#[warn(private_interfaces)]` on by default warning: type `Turtle` is more private than the item `Dermochelys_coriacea` - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:33:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:19:1 | LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `Dermochelys_coriacea` is reachable at visibility `pub` | note: but type `Turtle` is only usable at visibility `pub(crate)` - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:15:5 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:8:5 | LL | pub(super) struct Turtle; | ^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `Tortoise` in public interface - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:38:1 - | -LL | struct Tortoise; - | --------------- `Tortoise` declared as private -... -LL | pub type Testudo_graeca = Shell<Tortoise>; - | ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - warning: type `Tortoise` is more private than the item `Testudo_graeca` - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:38:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:21:1 | LL | pub type Testudo_graeca = Shell<Tortoise>; | ^^^^^^^^^^^^^^^^^^^^^^^ type alias `Testudo_graeca` is reachable at visibility `pub` | note: but type `Tortoise` is only usable at visibility `pub(crate)` - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:20:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:11:1 | LL | struct Tortoise; | ^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors; 3 warnings emitted +warning: 3 warnings emitted -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/pub/pub-restricted-error-fn.stderr b/tests/ui/pub/pub-restricted-error-fn.stderr index 0511a821a7a..ca5d8e1b58e 100644 --- a/tests/ui/pub/pub-restricted-error-fn.stderr +++ b/tests/ui/pub/pub-restricted-error-fn.stderr @@ -11,6 +11,8 @@ error: expected item, found `(` | LL | pub(crate) () fn foo() {} | ^ expected item + | + = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> error: aborting due to 2 previous errors diff --git a/tests/ui/range/range-1.stderr b/tests/ui/range/range-1.stderr index 277d9b2682d..96c1ffb2f7e 100644 --- a/tests/ui/range/range-1.stderr +++ b/tests/ui/range/range-1.stderr @@ -19,7 +19,7 @@ LL | for i in false..true {} i64 i128 usize - and 5 others + and 8 others = note: required for `std::ops::Range<bool>` to implement `Iterator` = note: required for `std::ops::Range<bool>` to implement `IntoIterator` diff --git a/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr b/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr index f2328cf3b24..a9a92b7a695 100644 --- a/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr +++ b/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr @@ -8,7 +8,6 @@ LL | let _: fn(&mut &isize, &mut &isize) = a; | = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)` found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}` - = note: when the arguments and return types match, functions can be coerced to function pointers error: aborting due to previous error diff --git a/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr b/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr index 9c5004981d5..e96559937d4 100644 --- a/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr +++ b/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr @@ -8,7 +8,6 @@ LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; | = note: expected fn pointer `for<'a, 'b, 'c, 'd, 'e, 'f> fn(&'a mut &'b isize, &'c mut &'d isize, &'e mut &'f isize)` found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a::<'_, '_, '_>}` - = note: when the arguments and return types match, functions can be coerced to function pointers error: aborting due to previous error diff --git a/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr b/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr index 766a3d0337c..8d82ff958ff 100644 --- a/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr +++ b/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr @@ -8,7 +8,6 @@ LL | want_G(baz); | = note: expected fn pointer `for<'cx> fn(&'cx S) -> &'static S` found fn item `for<'a> fn(&'a S) -> &'a S {baz}` - = note: when the arguments and return types match, functions can be coerced to function pointers note: function defined here --> $DIR/regions-fn-subtyping-return-static-fail.rs:20:4 | diff --git a/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr b/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr index 2fab2986567..53a5612d24f 100644 --- a/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr +++ b/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr @@ -8,7 +8,6 @@ LL | let _: fn(&mut &isize, &mut &isize) = a; | = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)` found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}` - = note: when the arguments and return types match, functions can be coerced to function pointers error: aborting due to previous error diff --git a/tests/ui/reify-intrinsic.stderr b/tests/ui/reify-intrinsic.stderr index 9f9034a30c7..310b6c224e0 100644 --- a/tests/ui/reify-intrinsic.stderr +++ b/tests/ui/reify-intrinsic.stderr @@ -8,7 +8,6 @@ LL | let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = std::mem::tr | = note: expected fn pointer `unsafe extern "rust-intrinsic" fn(isize) -> usize` found fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` - = note: when the arguments and return types match, functions can be coerced to function pointers error[E0606]: casting `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` as `unsafe extern "rust-intrinsic" fn(isize) -> usize` is invalid --> $DIR/reify-intrinsic.rs:11:13 diff --git a/tests/ui/resolve/bad-type-env-capture.stderr b/tests/ui/resolve/bad-type-env-capture.stderr index b6282c2d070..941b6b7a68c 100644 --- a/tests/ui/resolve/bad-type-env-capture.stderr +++ b/tests/ui/resolve/bad-type-env-capture.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/bad-type-env-capture.rs:2:15 | LL | fn foo<T>() { - | - type parameter from outer function + | - type parameter from outer item LL | fn bar(b: T) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<T>` + | help: try introducing a local generic parameter here: `<T>` error: aborting due to previous error diff --git a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr new file mode 100644 index 00000000000..4f853829279 --- /dev/null +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr @@ -0,0 +1,28 @@ +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:12:20 + | +LL | fn outer<T: Tr>() { // outer function + | - type parameter from outer item +LL | const K: u32 = T::C; + | ^^^^ use of generic parameter from outer item + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:19:24 + | +LL | impl<T> Tr for T { // outer impl block + | - type parameter from outer item +LL | const C: u32 = { +LL | const I: u32 = T::C; + | ^^^^ use of generic parameter from outer item + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:27:20 + | +LL | struct S<T: Tr>(U32<{ // outer struct + | - type parameter from outer item +LL | const _: u32 = T::C; + | ^^^^ use of generic parameter from outer item + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0401`. diff --git a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr new file mode 100644 index 00000000000..1cb55842bc6 --- /dev/null +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr @@ -0,0 +1,34 @@ +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:12:20 + | +LL | fn outer<T: Tr>() { // outer function + | - type parameter from outer item +LL | const K: u32 = T::C; + | - ^^^^ use of generic parameter from outer item + | | + | help: try introducing a local generic parameter here: `<T>` + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:19:24 + | +LL | impl<T> Tr for T { // outer impl block + | - type parameter from outer item +LL | const C: u32 = { +LL | const I: u32 = T::C; + | - ^^^^ use of generic parameter from outer item + | | + | help: try introducing a local generic parameter here: `<T>` + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:27:20 + | +LL | struct S<T: Tr>(U32<{ // outer struct + | - type parameter from outer item +LL | const _: u32 = T::C; + | - ^^^^ use of generic parameter from outer item + | | + | help: try introducing a local generic parameter here: `<T>` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0401`. diff --git a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs new file mode 100644 index 00000000000..e5647d72cba --- /dev/null +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs @@ -0,0 +1,39 @@ +// Regression test for issue #115720. +// If a const item contains generic params from an outer items, only suggest +// turning the const item generic if the feature `generic_const_items` is enabled. + +// revisions: default generic_const_items + +#![cfg_attr(generic_const_items, feature(generic_const_items))] +#![feature(generic_const_exprs)] // only used for the test case "outer struct" +#![allow(incomplete_features)] + +fn outer<T: Tr>() { // outer function + const K: u32 = T::C; + //~^ ERROR can't use generic parameters from outer item + //[generic_const_items]~| HELP try introducing a local generic parameter here +} + +impl<T> Tr for T { // outer impl block + const C: u32 = { + const I: u32 = T::C; + //~^ ERROR can't use generic parameters from outer item + //[generic_const_items]~| HELP try introducing a local generic parameter here + I + }; +} + +struct S<T: Tr>(U32<{ // outer struct + const _: u32 = T::C; + //~^ ERROR can't use generic parameters from outer item + //[generic_const_items]~| HELP try introducing a local generic parameter here + 0 +}>); + +trait Tr { + const C: u32; +} + +struct U32<const N: u32>; + +fn main() {} diff --git a/tests/ui/resolve/issue-12796.rs b/tests/ui/resolve/issue-12796.rs index 942d6b9a568..de3e73437f0 100644 --- a/tests/ui/resolve/issue-12796.rs +++ b/tests/ui/resolve/issue-12796.rs @@ -1,7 +1,7 @@ trait Trait { fn outer(&self) { fn inner(_: &Self) { - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } } diff --git a/tests/ui/resolve/issue-12796.stderr b/tests/ui/resolve/issue-12796.stderr index a01fd2d6542..ef59d00360b 100644 --- a/tests/ui/resolve/issue-12796.stderr +++ b/tests/ui/resolve/issue-12796.stderr @@ -1,10 +1,10 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-12796.rs:3:22 | LL | fn inner(_: &Self) { | ^^^^ | | - | use of generic parameter from outer function + | use of generic parameter from outer item | can't use `Self` here error: aborting due to previous error diff --git a/tests/ui/resolve/issue-3021-c.rs b/tests/ui/resolve/issue-3021-c.rs index 94ed1fdf781..bd21d124423 100644 --- a/tests/ui/resolve/issue-3021-c.rs +++ b/tests/ui/resolve/issue-3021-c.rs @@ -1,8 +1,8 @@ fn siphash<T>() { trait U { - fn g(&self, x: T) -> T; //~ ERROR can't use generic parameters from outer function - //~^ ERROR can't use generic parameters from outer function + fn g(&self, x: T) -> T; //~ ERROR can't use generic parameters from outer item + //~^ ERROR can't use generic parameters from outer item } } diff --git a/tests/ui/resolve/issue-3021-c.stderr b/tests/ui/resolve/issue-3021-c.stderr index 5176efc3a6b..537bbaf7b6a 100644 --- a/tests/ui/resolve/issue-3021-c.stderr +++ b/tests/ui/resolve/issue-3021-c.stderr @@ -1,24 +1,24 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-3021-c.rs:4:24 | LL | fn siphash<T>() { - | - type parameter from outer function + | - type parameter from outer item LL | LL | trait U { - | - help: try using a local generic parameter instead: `<T>` + | - help: try introducing a local generic parameter here: `<T>` LL | fn g(&self, x: T) -> T; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-3021-c.rs:4:30 | LL | fn siphash<T>() { - | - type parameter from outer function + | - type parameter from outer item LL | LL | trait U { - | - help: try using a local generic parameter instead: `<T>` + | - help: try introducing a local generic parameter here: `<T>` LL | fn g(&self, x: T) -> T; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to 2 previous errors diff --git a/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs b/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs index ce45f630e48..4fa3f12d024 100644 --- a/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs +++ b/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs @@ -1,7 +1,7 @@ unsafe fn foo<A>() { extern "C" { static baz: *const A; - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } let bar: *const u64 = core::mem::transmute(&baz); diff --git a/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr b/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr index 6bbf76dd1fb..3e9c3fd11b7 100644 --- a/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr +++ b/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr @@ -1,11 +1,11 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65025-extern-static-parent-generics.rs:3:28 | LL | unsafe fn foo<A>() { - | - type parameter from outer function + | - type parameter from outer item LL | extern "C" { LL | static baz: *const A; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to previous error diff --git a/tests/ui/resolve/issue-65035-static-with-parent-generics.rs b/tests/ui/resolve/issue-65035-static-with-parent-generics.rs index f96c04841dd..bc99584a8d2 100644 --- a/tests/ui/resolve/issue-65035-static-with-parent-generics.rs +++ b/tests/ui/resolve/issue-65035-static-with-parent-generics.rs @@ -1,26 +1,26 @@ fn f<T>() { extern "C" { static a: *const T; - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } fn g<T: Default>() { static a: *const T = Default::default(); - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } fn h<const N: usize>() { extern "C" { static a: [u8; N]; - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } fn i<const N: usize>() { static a: [u8; N] = [0; N]; - //~^ ERROR can't use generic parameters from outer function - //~| ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item + //~| ERROR can't use generic parameters from outer item } fn main() {} diff --git a/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr b/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr index 7ed572f80b8..f1fe1a6002c 100644 --- a/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr +++ b/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr @@ -1,44 +1,44 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:3:26 | LL | fn f<T>() { - | - type parameter from outer function + | - type parameter from outer item LL | extern "C" { LL | static a: *const T; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:9:22 | LL | fn g<T: Default>() { - | - type parameter from outer function + | - type parameter from outer item LL | static a: *const T = Default::default(); - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:15:24 | LL | fn h<const N: usize>() { - | - const parameter from outer function + | - const parameter from outer item LL | extern "C" { LL | static a: [u8; N]; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:21:20 | LL | fn i<const N: usize>() { - | - const parameter from outer function + | - const parameter from outer item LL | static a: [u8; N] = [0; N]; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:21:29 | LL | fn i<const N: usize>() { - | - const parameter from outer function + | - const parameter from outer item LL | static a: [u8; N] = [0; N]; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to 5 previous errors diff --git a/tests/ui/issues/issue-6642.rs b/tests/ui/resolve/issue-6642.rs index f80f6fffe89..f80f6fffe89 100644 --- a/tests/ui/issues/issue-6642.rs +++ b/tests/ui/resolve/issue-6642.rs diff --git a/tests/ui/issues/issue-6642.stderr b/tests/ui/resolve/issue-6642.stderr index 6668108d024..6668108d024 100644 --- a/tests/ui/issues/issue-6642.stderr +++ b/tests/ui/resolve/issue-6642.stderr diff --git a/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs b/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs index c77a66524f7..2d5f34c62a6 100644 --- a/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs +++ b/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs @@ -6,7 +6,7 @@ trait TraitA<A> { fn outer(&self) { enum Foo<B> { Variance(A) - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } } @@ -14,21 +14,21 @@ trait TraitA<A> { trait TraitB<A> { fn outer(&self) { struct Foo<B>(A); - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } trait TraitC<A> { fn outer(&self) { struct Foo<B> { a: A } - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } trait TraitD<A> { fn outer(&self) { fn foo<B>(a: A) { } - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } diff --git a/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr b/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr index 0a6d1cc3bcd..1ab56fdc504 100644 --- a/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr +++ b/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr @@ -1,46 +1,46 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:8:22 | LL | trait TraitA<A> { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | enum Foo<B> { - | - help: try using a local generic parameter instead: `A,` + | - help: try introducing a local generic parameter here: `A,` LL | Variance(A) - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:16:23 | LL | trait TraitB<A> { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | struct Foo<B>(A); - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `A,` + | help: try introducing a local generic parameter here: `A,` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:23:28 | LL | trait TraitC<A> { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | struct Foo<B> { a: A } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `A,` + | help: try introducing a local generic parameter here: `A,` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:30:22 | LL | trait TraitD<A> { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | fn foo<B>(a: A) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `A,` + | help: try introducing a local generic parameter here: `A,` error: aborting due to 4 previous errors diff --git a/tests/ui/resolve/suggest-import-without-clobbering-attrs.fixed b/tests/ui/resolve/suggest-import-without-clobbering-attrs.fixed new file mode 100644 index 00000000000..fc68884fe9c --- /dev/null +++ b/tests/ui/resolve/suggest-import-without-clobbering-attrs.fixed @@ -0,0 +1,16 @@ +// run-rustfix +// compile-flags: --cfg=whatever -Aunused + +use y::z; +#[cfg(whatever)] +use y::Whatever; + +mod y { + pub(crate) fn z() {} + pub(crate) struct Whatever; +} + +fn main() { + z(); + //~^ ERROR cannot find function `z` in this scope +} diff --git a/tests/ui/resolve/suggest-import-without-clobbering-attrs.rs b/tests/ui/resolve/suggest-import-without-clobbering-attrs.rs new file mode 100644 index 00000000000..38a1095703b --- /dev/null +++ b/tests/ui/resolve/suggest-import-without-clobbering-attrs.rs @@ -0,0 +1,15 @@ +// run-rustfix +// compile-flags: --cfg=whatever -Aunused + +#[cfg(whatever)] +use y::Whatever; + +mod y { + pub(crate) fn z() {} + pub(crate) struct Whatever; +} + +fn main() { + z(); + //~^ ERROR cannot find function `z` in this scope +} diff --git a/tests/ui/resolve/suggest-import-without-clobbering-attrs.stderr b/tests/ui/resolve/suggest-import-without-clobbering-attrs.stderr new file mode 100644 index 00000000000..d3574851d5c --- /dev/null +++ b/tests/ui/resolve/suggest-import-without-clobbering-attrs.stderr @@ -0,0 +1,14 @@ +error[E0425]: cannot find function `z` in this scope + --> $DIR/suggest-import-without-clobbering-attrs.rs:13:5 + | +LL | z(); + | ^ not found in this scope + | +help: consider importing this function + | +LL + use y::z; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/resolve/use-self-in-inner-fn.rs b/tests/ui/resolve/use-self-in-inner-fn.rs index eccb315feb1..f4dfa4c40ab 100644 --- a/tests/ui/resolve/use-self-in-inner-fn.rs +++ b/tests/ui/resolve/use-self-in-inner-fn.rs @@ -4,9 +4,9 @@ impl A { //~^ NOTE `Self` type implicitly declared here, by this `impl` fn banana(&mut self) { fn peach(this: &Self) { - //~^ ERROR can't use generic parameters from outer function - //~| NOTE use of generic parameter from outer function - //~| NOTE use a type here instead + //~^ ERROR can't use generic parameters from outer item + //~| NOTE use of generic parameter from outer item + //~| NOTE refer to the type directly here instead } } } diff --git a/tests/ui/resolve/use-self-in-inner-fn.stderr b/tests/ui/resolve/use-self-in-inner-fn.stderr index 96609349924..832aaacaf49 100644 --- a/tests/ui/resolve/use-self-in-inner-fn.stderr +++ b/tests/ui/resolve/use-self-in-inner-fn.stderr @@ -1,4 +1,4 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/use-self-in-inner-fn.rs:6:25 | LL | impl A { @@ -7,8 +7,8 @@ LL | impl A { LL | fn peach(this: &Self) { | ^^^^ | | - | use of generic parameter from outer function - | use a type here instead + | use of generic parameter from outer item + | refer to the type directly here instead error: aborting due to previous error diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr index 872cb9b8bc6..4e7f3098ab4 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr @@ -28,7 +28,8 @@ note: `NonExhaustiveEnum` defined here | LL | pub enum NonExhaustiveEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `NonExhaustiveEnum`, which is marked as non-exhaustive + = note: the matched value is of type `NonExhaustiveEnum` + = note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ NonExhaustiveEnum::Struct { .. } => "third", @@ -46,7 +47,7 @@ note: `NonExhaustiveEnum` defined here | LL | pub enum NonExhaustiveEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `NonExhaustiveEnum`, which is marked as non-exhaustive + = note: the matched value is of type `NonExhaustiveEnum` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ match enum_unit { diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs index 3beb20f0a37..b8c0eb3e6d6 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs @@ -8,14 +8,10 @@ fn _if_let_guard() { //~^ ERROR `if let` guards are experimental () if (let 0 = 1) => {} - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement () if (((let 0 = 1))) => {} - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement () if true && let 0 = 1 => {} //~^ ERROR `if let` guards are experimental @@ -26,36 +22,22 @@ fn _if_let_guard() { //~| ERROR `let` expressions in this position are unstable () if (let 0 = 1) && true => {} - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement () if true && (let 0 = 1) => {} - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement () if (let 0 = 1) && (let 0 = 1) => {} - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} //~^ ERROR `if let` guards are experimental //~| ERROR `let` expressions in this position are unstable //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable - //~| ERROR `let` expressions in this position are unstable //~| ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here () if let Range { start: _, end: _ } = (true..true) && false => {} @@ -76,13 +58,9 @@ fn _macros() { } } use_expr!((let 0 = 1 && 0 == 0)); - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement use_expr!((let 0 = 1)); - //~^ ERROR `let` expressions in this position are unstable - //~| ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement match () { #[cfg(FALSE)] () if let 0 = 1 => {} diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr index dc182ce464a..62534b555b2 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.stderr @@ -2,87 +2,6 @@ error: expected expression, found `let` statement --> $DIR/feature-gate.rs:10:16 | LL | () if (let 0 = 1) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:15:18 - | -LL | () if (((let 0 = 1))) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:28:16 - | -LL | () if (let 0 = 1) && true => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:33:24 - | -LL | () if true && (let 0 = 1) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:38:16 - | -LL | () if (let 0 = 1) && (let 0 = 1) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:38:31 - | -LL | () if (let 0 = 1) && (let 0 = 1) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:46:42 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:46:55 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:46:68 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:78:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:82:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^ - -error: no rules expected the token `let` - --> $DIR/feature-gate.rs:92:15 - | -LL | macro_rules! use_expr { - | --------------------- when calling this macro -... -LL | use_expr!(let 0 = 1); - | ^^^ no rules expected this token in macro call - | -note: while trying to match meta-variable `$e:expr` - --> $DIR/feature-gate.rs:71:10 - | -LL | ($e:expr) => { - | ^^^^^^^ - -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:10:16 - | -LL | () if (let 0 = 1) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions @@ -92,135 +11,140 @@ note: `let`s wrapped in parentheses are not supported in a context with let chai LL | () if (let 0 = 1) => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:15:18 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:13:18 | LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:15:18 + --> $DIR/feature-gate.rs:13:18 | LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:28:16 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:24:16 | LL | () if (let 0 = 1) && true => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:28:16 + --> $DIR/feature-gate.rs:24:16 | LL | () if (let 0 = 1) && true => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:33:24 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:27:24 | LL | () if true && (let 0 = 1) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:33:24 + --> $DIR/feature-gate.rs:27:24 | LL | () if true && (let 0 = 1) => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:38:16 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:30:16 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:38:16 + --> $DIR/feature-gate.rs:30:16 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:38:31 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:30:31 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:38:31 + --> $DIR/feature-gate.rs:30:31 | LL | () if (let 0 = 1) && (let 0 = 1) => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:46:42 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:46:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:46:55 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:34:55 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:46:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:46:68 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:34:68 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:46:42 + --> $DIR/feature-gate.rs:34:42 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:78:16 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:60:16 | LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:78:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/feature-gate.rs:82:16 +error: expected expression, found `let` statement + --> $DIR/feature-gate.rs:62:16 | LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/feature-gate.rs:82:16 + +error: no rules expected the token `let` + --> $DIR/feature-gate.rs:70:15 | -LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ +LL | macro_rules! use_expr { + | --------------------- when calling this macro +... +LL | use_expr!(let 0 = 1); + | ^^^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr` + --> $DIR/feature-gate.rs:53:10 + | +LL | ($e:expr) => { + | ^^^^^^^ error[E0658]: `if let` guards are experimental --> $DIR/feature-gate.rs:7:12 @@ -233,7 +157,7 @@ LL | () if let 0 = 1 => {} = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:20:12 + --> $DIR/feature-gate.rs:16:12 | LL | () if true && let 0 = 1 => {} | ^^^^^^^^^^^^^^^^^^^^ @@ -243,7 +167,7 @@ LL | () if true && let 0 = 1 => {} = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:24:12 + --> $DIR/feature-gate.rs:20:12 | LL | () if let 0 = 1 && true => {} | ^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +177,7 @@ LL | () if let 0 = 1 && true => {} = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:46:12 + --> $DIR/feature-gate.rs:34:12 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +187,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:61:12 + --> $DIR/feature-gate.rs:43:12 | LL | () if let Range { start: _, end: _ } = (true..true) && false => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -273,7 +197,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {} = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` error[E0658]: `if let` guards are experimental - --> $DIR/feature-gate.rs:88:12 + --> $DIR/feature-gate.rs:66:12 | LL | () if let 0 = 1 => {} | ^^^^^^^^^^^^ @@ -283,25 +207,7 @@ LL | () if let 0 = 1 => {} = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>` error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:10:16 - | -LL | () if (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:15:18 - | -LL | () if (((let 0 = 1))) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:20:23 + --> $DIR/feature-gate.rs:16:23 | LL | () if true && let 0 = 1 => {} | ^^^^^^^^^ @@ -310,7 +216,7 @@ LL | () if true && let 0 = 1 => {} = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:24:15 + --> $DIR/feature-gate.rs:20:15 | LL | () if let 0 = 1 && true => {} | ^^^^^^^^^ @@ -319,43 +225,7 @@ LL | () if let 0 = 1 && true => {} = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:28:16 - | -LL | () if (let 0 = 1) && true => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:33:24 - | -LL | () if true && (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:38:16 - | -LL | () if (let 0 = 1) && (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:38:31 - | -LL | () if (let 0 = 1) && (let 0 = 1) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:46:15 + --> $DIR/feature-gate.rs:34:15 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ @@ -364,7 +234,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:46:28 + --> $DIR/feature-gate.rs:34:28 | LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} | ^^^^^^^^^ @@ -373,34 +243,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = = help: add `#![feature(let_chains)]` to the crate attributes to enable error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:46:42 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:46:55 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:46:68 - | -LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {} - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:61:15 + --> $DIR/feature-gate.rs:43:15 | LL | () if let Range { start: _, end: _ } = (true..true) && false => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -408,24 +251,6 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {} = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information = help: add `#![feature(let_chains)]` to the crate attributes to enable -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:78:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:82:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error: aborting due to 45 previous errors +error: aborting due to 23 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr index 41a20bf8ae1..00c1c303d2b 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/macro-expanded.stderr @@ -7,6 +7,7 @@ LL | ($e:expr) => { let Some(x) = $e } LL | () if m!(Some(5)) => {} | ----------- in this macro invocation | + = note: only supported directly in conditions of `if` and `while` expressions = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/parens.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/parens.rs index 9cb27c73b14..f12824db9c0 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/parens.rs +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/parens.rs @@ -19,9 +19,7 @@ fn main() { () if let 0 = 1 => {} () if (let 0 = 1) => {} //~^ ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here () if (((let 0 = 1))) => {} //~^ ERROR expected expression, found `let` statement - //~| ERROR `let` expressions are not supported here } } diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr index 85df360daab..0c16d9c5442 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/parens.stderr @@ -2,27 +2,29 @@ error: expected expression, found `let` statement --> $DIR/parens.rs:10:16 | LL | () if (let 0 = 1) => {} - | ^^^ + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/parens.rs:10:16 + | +LL | () if (let 0 = 1) => {} + | ^^^^^^^^^ error: expected expression, found `let` statement --> $DIR/parens.rs:12:18 | LL | () if (((let 0 = 1))) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/parens.rs:20:16 + | ^^^^^^^^^ | -LL | () if (let 0 = 1) => {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/parens.rs:23:18 + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/parens.rs:12:18 | LL | () if (((let 0 = 1))) => {} - | ^^^ + | ^^^^^^^^^ -error: `let` expressions are not supported here +error: expected expression, found `let` statement --> $DIR/parens.rs:20:16 | LL | () if (let 0 = 1) => {} @@ -35,18 +37,18 @@ note: `let`s wrapped in parentheses are not supported in a context with let chai LL | () if (let 0 = 1) => {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/parens.rs:23:18 +error: expected expression, found `let` statement + --> $DIR/parens.rs:22:18 | LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/parens.rs:23:18 + --> $DIR/parens.rs:22:18 | LL | () if (((let 0 = 1))) => {} | ^^^^^^^^^ -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr b/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr index b0ac5dc44ad..e08ffe42d6a 100644 --- a/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr +++ b/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr @@ -13,7 +13,6 @@ LL | let foo: fn() = foo; found fn item `fn() {foo}` = note: fn items are distinct from fn pointers = note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers - = note: when the arguments and return types match, functions can be coerced to function pointers help: consider casting to a fn pointer | LL | let foo: fn() = foo as fn(); diff --git a/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr b/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr index b0ac5dc44ad..e08ffe42d6a 100644 --- a/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr +++ b/tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr @@ -13,7 +13,6 @@ LL | let foo: fn() = foo; found fn item `fn() {foo}` = note: fn items are distinct from fn pointers = note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers - = note: when the arguments and return types match, functions can be coerced to function pointers help: consider casting to a fn pointer | LL | let foo: fn() = foo as fn(); diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.rs index e6dee2a1d06..cb3be59bee0 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.rs @@ -3,7 +3,7 @@ fn let_or_guard(x: Result<Option<i32>, ()>) { match x { Ok(opt) if let Some(4) = opt || false => {} - //~^ ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement _ => {} } } diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr index 26850998cc4..4b85fdd5050 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ast-validate-guards.stderr @@ -1,4 +1,4 @@ -error: `let` expressions are not supported here +error: expected expression, found `let` statement --> $DIR/ast-validate-guards.rs:5:20 | LL | Ok(opt) if let Some(4) = opt || false => {} diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.rs new file mode 100644 index 00000000000..530458064b2 --- /dev/null +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.rs @@ -0,0 +1,14 @@ +// Regression test for #104172 + +const N: usize = { + struct U; + !let y = 42; + //~^ ERROR expected expression, found `let` statement + 3 +}; + +struct S { + x: [(); N] +} + +fn main() {} diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr new file mode 100644 index 00000000000..3eaccde3b74 --- /dev/null +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.stderr @@ -0,0 +1,10 @@ +error: expected expression, found `let` statement + --> $DIR/avoid-invalid-mir.rs:5:6 + | +LL | !let y = 42; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: aborting due to previous error + diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs index e0dded15217..2c0571a7bdd 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs @@ -1,19 +1,18 @@ +// check-pass + fn and_chain() { let z; if true && { z = 3; true} && z == 3 {} - //~^ ERROR E0381 } fn and_chain_2() { let z; true && { z = 3; true} && z == 3; - //~^ ERROR E0381 } fn or_chain() { let z; if false || { z = 3; false} || z == 3 {} - //~^ ERROR E0381 } fn main() { diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr deleted file mode 100644 index 30d5a6779fc..00000000000 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error[E0381]: used binding `z` is possibly-uninitialized - --> $DIR/chains-without-let.rs:3:34 - | -LL | let z; - | - binding declared here but left uninitialized -LL | if true && { z = 3; true} && z == 3 {} - | ----- ^ `z` used here but it is possibly-uninitialized - | | - | binding initialized here in some conditions - -error[E0381]: used binding `z` is possibly-uninitialized - --> $DIR/chains-without-let.rs:9:31 - | -LL | let z; - | - binding declared here but left uninitialized -LL | true && { z = 3; true} && z == 3; - | ----- ^ `z` used here but it is possibly-uninitialized - | | - | binding initialized here in some conditions - -error[E0381]: used binding `z` is possibly-uninitialized - --> $DIR/chains-without-let.rs:15:36 - | -LL | let z; - | - binding declared here but left uninitialized -LL | if false || { z = 3; false} || z == 3 {} - | ----- ^ `z` used here but it is possibly-uninitialized - | | - | binding initialized here in some conditions - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0381`. diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs new file mode 100644 index 00000000000..096036bb133 --- /dev/null +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.rs @@ -0,0 +1,340 @@ +// Check that we don't suggest enabling a feature for code that's +// not accepted even with that feature. + +#![allow(irrefutable_let_patterns)] + +use std::ops::Range; + +fn main() {} + +fn _if() { + if (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + if (((let 0 = 1))) {} + //~^ ERROR expected expression, found `let` statement + + if (let 0 = 1) && true {} + //~^ ERROR expected expression, found `let` statement + + if true && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + if (let 0 = 1) && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + + if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement +} + +fn _while() { + while (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + while (((let 0 = 1))) {} + //~^ ERROR expected expression, found `let` statement + + while (let 0 = 1) && true {} + //~^ ERROR expected expression, found `let` statement + + while true && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + + while (let 0 = 1) && (let 0 = 1) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + + while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement +} + +fn _macros() { + macro_rules! use_expr { + ($e:expr) => { + if $e {} + while $e {} + } + } + use_expr!((let 0 = 1 && 0 == 0)); + //~^ ERROR expected expression, found `let` statement + use_expr!((let 0 = 1)); + //~^ ERROR expected expression, found `let` statement +} + +fn nested_within_if_expr() { + if &let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + if !let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + if *let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + if -let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + fn _check_try_binds_tighter() -> Result<(), ()> { + if let 0 = 0? {} + //~^ ERROR the `?` operator can only be applied to values that implement `Try` + Ok(()) + } + if (let 0 = 0)? {} + //~^ ERROR expected expression, found `let` statement + + if true || let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + if (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + if true && (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + if true || (true && let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + + let mut x = true; + if x = let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + if true..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + if ..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + if (let 0 = 0).. {} + //~^ ERROR expected expression, found `let` statement + + // Binds as `(let ... = true)..true &&/|| false`. + if let Range { start: _, end: _ } = true..true && false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + if let Range { start: _, end: _ } = true..true || false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: F, end } = F)..(|| true)`. + const F: fn() -> bool = || true; + if let Range { start: F, end } = F..|| true {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: true, end } = t)..(&&false)`. + let t = &&true; + if let Range { start: true, end } = t..&&false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + if let true = let true = true {} + //~^ ERROR expected expression, found `let` statement +} + +fn nested_within_while_expr() { + while &let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + while !let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + while *let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + while -let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + fn _check_try_binds_tighter() -> Result<(), ()> { + while let 0 = 0? {} + //~^ ERROR the `?` operator can only be applied to values that implement `Try` + Ok(()) + } + while (let 0 = 0)? {} + //~^ ERROR expected expression, found `let` statement + + while true || let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + while (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + while true && (true || let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + while true || (true && let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + + let mut x = true; + while x = let 0 = 0 {} + //~^ ERROR expected expression, found `let` statement + + while true..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + while ..(let 0 = 0) {} + //~^ ERROR expected expression, found `let` statement + while (let 0 = 0).. {} + //~^ ERROR expected expression, found `let` statement + + // Binds as `(let ... = true)..true &&/|| false`. + while let Range { start: _, end: _ } = true..true && false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + while let Range { start: _, end: _ } = true..true || false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: F, end } = F)..(|| true)`. + const F: fn() -> bool = || true; + while let Range { start: F, end } = F..|| true {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + // Binds as `(let Range { start: true, end } = t)..(&&false)`. + let t = &&true; + while let Range { start: true, end } = t..&&false {} + //~^ ERROR expected expression, found `let` statement + //~| ERROR mismatched types + + while let true = let true = true {} + //~^ ERROR expected expression, found `let` statement +} + +fn not_error_because_clarified_intent() { + if let Range { start: _, end: _ } = (true..true || false) { } + + if let Range { start: _, end: _ } = (true..true && false) { } + + while let Range { start: _, end: _ } = (true..true || false) { } + + while let Range { start: _, end: _ } = (true..true && false) { } +} + +fn outside_if_and_while_expr() { + &let 0 = 0; + //~^ ERROR expected expression, found `let` statement + + !let 0 = 0; + //~^ ERROR expected expression, found `let` statement + *let 0 = 0; + //~^ ERROR expected expression, found `let` statement + -let 0 = 0; + //~^ ERROR expected expression, found `let` statement + let _ = let _ = 3; + //~^ ERROR expected expression, found `let` statement + + fn _check_try_binds_tighter() -> Result<(), ()> { + let 0 = 0?; + //~^ ERROR the `?` operator can only be applied to values that implement `Try` + Ok(()) + } + (let 0 = 0)?; + //~^ ERROR expected expression, found `let` statement + + true || let 0 = 0; + //~^ ERROR expected expression, found `let` statement + (true || let 0 = 0); + //~^ ERROR expected expression, found `let` statement + true && (true || let 0 = 0); + //~^ ERROR expected expression, found `let` statement + + let mut x = true; + x = let 0 = 0; + //~^ ERROR expected expression, found `let` statement + + true..(let 0 = 0); + //~^ ERROR expected expression, found `let` statement + ..(let 0 = 0); + //~^ ERROR expected expression, found `let` statement + (let 0 = 0)..; + //~^ ERROR expected expression, found `let` statement + + (let Range { start: _, end: _ } = true..true || false); + //~^ ERROR mismatched types + //~| ERROR expected expression, found `let` statement + + (let true = let true = true); + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + + { + #[cfg(FALSE)] + let x = true && let y = 1; + //~^ ERROR expected expression, found `let` statement + } + + #[cfg(FALSE)] + { + [1, 2, 3][let _ = ()] + //~^ ERROR expected expression, found `let` statement + } + + // Check function tail position. + &let 0 = 0 + //~^ ERROR expected expression, found `let` statement +} + +// Let's make sure that `let` inside const generic arguments are considered. +fn inside_const_generic_arguments() { + struct A<const B: bool>; + impl<const B: bool> A<{B}> { const O: u32 = 5; } + + if let A::<{ + true && let 1 = 1 + //~^ ERROR expected expression, found `let` statement + }>::O = 5 {} + + while let A::<{ + true && let 1 = 1 + //~^ ERROR expected expression, found `let` statement + }>::O = 5 {} + + if A::<{ + true && let 1 = 1 + //~^ ERROR expected expression, found `let` statement + }>::O == 5 {} + + // In the cases above we have `ExprKind::Block` to help us out. + // Below however, we would not have a block and so an implementation might go + // from visiting expressions to types without banning `let` expressions down the tree. + // This tests ensures that we are not caught by surprise should the parser + // admit non-IDENT expressions in const generic arguments. + + if A::< + true && let 1 = 1 + //~^ ERROR expressions must be enclosed in braces + //~| ERROR expected expression, found `let` statement + >::O == 5 {} +} + +fn with_parenthesis() { + let opt = Some(Some(1i32)); + + if (let Some(a) = opt && true) { + //~^ ERROR expected expression, found `let` statement + } + + if (let Some(a) = opt) && true { + //~^ ERROR expected expression, found `let` statement + } + if (let Some(a) = opt) && (let Some(b) = a) { + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + } + + if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + } + if (let Some(a) = opt && (let Some(b) = a)) && true { + //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement + } + if (let Some(a) = opt && (true)) && true { + //~^ ERROR expected expression, found `let` statement + } + + #[cfg(FALSE)] + let x = (true && let y = 1); + //~^ ERROR expected expression, found `let` statement + + #[cfg(FALSE)] + { + ([1, 2, 3][let _ = ()]) + //~^ ERROR expected expression, found `let` statement + } +} diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr new file mode 100644 index 00000000000..31f389512ed --- /dev/null +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions-without-feature-gate.stderr @@ -0,0 +1,1021 @@ +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:11:9 + | +LL | if (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:11:9 + | +LL | if (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:14:11 + | +LL | if (((let 0 = 1))) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:14:11 + | +LL | if (((let 0 = 1))) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:17:9 + | +LL | if (let 0 = 1) && true {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:17:9 + | +LL | if (let 0 = 1) && true {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:20:17 + | +LL | if true && (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:20:17 + | +LL | if true && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:23:9 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:23:9 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:23:24 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:23:24 + | +LL | if (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:27:22 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:27:35 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:27:9 + | +LL | if (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:34:12 + | +LL | while (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:34:12 + | +LL | while (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:37:14 + | +LL | while (((let 0 = 1))) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:37:14 + | +LL | while (((let 0 = 1))) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:40:12 + | +LL | while (let 0 = 1) && true {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:40:12 + | +LL | while (let 0 = 1) && true {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:43:20 + | +LL | while true && (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:43:20 + | +LL | while true && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:46:12 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:46:12 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:46:27 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:46:27 + | +LL | while (let 0 = 1) && (let 0 = 1) {} + | ^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:50:25 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:50:38 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:50:12 + | +LL | while (let 2 = 3 && let 3 = 4 && let 4 = 5) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:70:9 + | +LL | if &let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:73:9 + | +LL | if !let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:75:9 + | +LL | if *let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:77:9 + | +LL | if -let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:85:9 + | +LL | if (let 0 = 0)? {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:88:16 + | +LL | if true || let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `||` operators are not supported in let chain expressions + --> $DIR/disallowed-positions-without-feature-gate.rs:88:13 + | +LL | if true || let 0 = 0 {} + | ^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:90:17 + | +LL | if (true || let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:92:25 + | +LL | if true && (true || let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:94:25 + | +LL | if true || (true && let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:98:12 + | +LL | if x = let 0 = 0 {} + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:101:15 + | +LL | if true..(let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:104:11 + | +LL | if ..(let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:106:9 + | +LL | if (let 0 = 0).. {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:110:8 + | +LL | if let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:113:8 + | +LL | if let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:119:8 + | +LL | if let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:125:8 + | +LL | if let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:129:19 + | +LL | if let true = let true = true {} + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:134:12 + | +LL | while &let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:137:12 + | +LL | while !let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:139:12 + | +LL | while *let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:141:12 + | +LL | while -let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:149:12 + | +LL | while (let 0 = 0)? {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:152:19 + | +LL | while true || let 0 = 0 {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `||` operators are not supported in let chain expressions + --> $DIR/disallowed-positions-without-feature-gate.rs:152:16 + | +LL | while true || let 0 = 0 {} + | ^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:154:20 + | +LL | while (true || let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:156:28 + | +LL | while true && (true || let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:158:28 + | +LL | while true || (true && let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:162:15 + | +LL | while x = let 0 = 0 {} + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:165:18 + | +LL | while true..(let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:168:14 + | +LL | while ..(let 0 = 0) {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:170:12 + | +LL | while (let 0 = 0).. {} + | ^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:174:11 + | +LL | while let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:177:11 + | +LL | while let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:183:11 + | +LL | while let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:189:11 + | +LL | while let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:193:22 + | +LL | while let true = let true = true {} + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:208:6 + | +LL | &let 0 = 0; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:211:6 + | +LL | !let 0 = 0; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:213:6 + | +LL | *let 0 = 0; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:215:6 + | +LL | -let 0 = 0; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:217:13 + | +LL | let _ = let _ = 3; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:225:6 + | +LL | (let 0 = 0)?; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:228:13 + | +LL | true || let 0 = 0; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:230:14 + | +LL | (true || let 0 = 0); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:232:22 + | +LL | true && (true || let 0 = 0); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:236:9 + | +LL | x = let 0 = 0; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:239:12 + | +LL | true..(let 0 = 0); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:241:8 + | +LL | ..(let 0 = 0); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:243:6 + | +LL | (let 0 = 0)..; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:246:6 + | +LL | (let Range { start: _, end: _ } = true..true || false); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:250:6 + | +LL | (let true = let true = true); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:250:17 + | +LL | (let true = let true = true); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:256:25 + | +LL | let x = true && let y = 1; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:262:19 + | +LL | [1, 2, 3][let _ = ()] + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:267:6 + | +LL | &let 0 = 0 + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:277:17 + | +LL | true && let 1 = 1 + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:282:17 + | +LL | true && let 1 = 1 + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:287:17 + | +LL | true && let 1 = 1 + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:298:17 + | +LL | true && let 1 = 1 + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expressions must be enclosed in braces to be used as const generic arguments + --> $DIR/disallowed-positions-without-feature-gate.rs:298:9 + | +LL | true && let 1 = 1 + | ^^^^^^^^^^^^^^^^^ + | +help: enclose the `const` expression in braces + | +LL | { true && let 1 = 1 } + | + + + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:307:9 + | +LL | if (let Some(a) = opt && true) { + | ^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:307:9 + | +LL | if (let Some(a) = opt && true) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:311:9 + | +LL | if (let Some(a) = opt) && true { + | ^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:311:9 + | +LL | if (let Some(a) = opt) && true { + | ^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:314:9 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:314:9 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:314:32 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:314:32 + | +LL | if (let Some(a) = opt) && (let Some(b) = a) { + | ^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:319:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:319:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:319:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:319:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { + | ^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:323:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:323:9 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:323:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:323:31 + | +LL | if (let Some(a) = opt && (let Some(b) = a)) && true { + | ^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:327:9 + | +LL | if (let Some(a) = opt && (true)) && true { + | ^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions +note: `let`s wrapped in parentheses are not supported in a context with let chains + --> $DIR/disallowed-positions-without-feature-gate.rs:327:9 + | +LL | if (let Some(a) = opt && (true)) && true { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:332:22 + | +LL | let x = (true && let y = 1); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:337:20 + | +LL | ([1, 2, 3][let _ = ()]) + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:63:16 + | +LL | use_expr!((let 0 = 1 && 0 == 0)); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions-without-feature-gate.rs:65:16 + | +LL | use_expr!((let 0 = 1)); + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:101:8 + | +LL | if true..(let 0 = 0) {} + | ^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` + | + = note: expected type `bool` + found struct `std::ops::Range<bool>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:110:12 + | +LL | if let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:113:12 + | +LL | if let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:119:12 + | +LL | if let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `fn() -> bool` + | | + | expected fn pointer, found `Range<_>` + | + = note: expected fn pointer `fn() -> bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:125:12 + | +LL | if let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0277]: the `?` operator can only be applied to values that implement `Try` + --> $DIR/disallowed-positions-without-feature-gate.rs:81:20 + | +LL | if let 0 = 0? {} + | ^^ the `?` operator cannot be applied to type `{integer}` + | + = help: the trait `Try` is not implemented for `{integer}` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:165:11 + | +LL | while true..(let 0 = 0) {} + | ^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` + | + = note: expected type `bool` + found struct `std::ops::Range<bool>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:174:15 + | +LL | while let Range { start: _, end: _ } = true..true && false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:177:15 + | +LL | while let Range { start: _, end: _ } = true..true || false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:183:15 + | +LL | while let Range { start: F, end } = F..|| true {} + | ^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `fn() -> bool` + | | + | expected fn pointer, found `Range<_>` + | + = note: expected fn pointer `fn() -> bool` + found struct `std::ops::Range<_>` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:189:15 + | +LL | while let Range { start: true, end } = t..&&false {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0277]: the `?` operator can only be applied to values that implement `Try` + --> $DIR/disallowed-positions-without-feature-gate.rs:145:23 + | +LL | while let 0 = 0? {} + | ^^ the `?` operator cannot be applied to type `{integer}` + | + = help: the trait `Try` is not implemented for `{integer}` + +error[E0308]: mismatched types + --> $DIR/disallowed-positions-without-feature-gate.rs:246:10 + | +LL | (let Range { start: _, end: _ } = true..true || false); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` + | | + | expected `bool`, found `Range<_>` + | + = note: expected type `bool` + found struct `std::ops::Range<_>` + +error[E0277]: the `?` operator can only be applied to values that implement `Try` + --> $DIR/disallowed-positions-without-feature-gate.rs:221:17 + | +LL | let 0 = 0?; + | ^^ the `?` operator cannot be applied to type `{integer}` + | + = help: the trait `Try` is not implemented for `{integer}` + +error: aborting due to 105 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs index 2a9a5472b2e..4ac3ea53a08 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs @@ -27,64 +27,46 @@ fn main() {} fn _if() { if (let 0 = 1) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if (((let 0 = 1))) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if (let 0 = 1) && true {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if true && (let 0 = 1) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if (let 0 = 1) && (let 0 = 1) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement } fn _while() { while (let 0 = 1) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while (((let 0 = 1))) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while (let 0 = 1) && true {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while true && (let 0 = 1) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while (let 0 = 1) && (let 0 = 1) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement } @@ -97,32 +79,21 @@ fn _macros() { } } use_expr!((let 0 = 1 && 0 == 0)); - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement use_expr!((let 0 = 1)); - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } fn nested_within_if_expr() { if &let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if !let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if *let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR type `bool` cannot be dereferenced - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if -let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR cannot apply unary operator `-` to type `bool` - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement fn _check_try_binds_tighter() -> Result<(), ()> { if let 0 = 0? {} @@ -130,91 +101,63 @@ fn nested_within_if_expr() { Ok(()) } if (let 0 = 0)? {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR the `?` operator can only be applied to values that implement `Try` - //~| ERROR the `?` operator can only be used in a function that returns `Result` - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if true || let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if (true || let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if true && (true || let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if true || (true && let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement let mut x = true; if x = let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if true..(let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement if ..(let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement if (let 0 = 0).. {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement // Binds as `(let ... = true)..true &&/|| false`. if let Range { start: _, end: _ } = true..true && false {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types if let Range { start: _, end: _ } = true..true || false {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types // Binds as `(let Range { start: F, end } = F)..(|| true)`. const F: fn() -> bool = || true; if let Range { start: F, end } = F..|| true {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types // Binds as `(let Range { start: true, end } = t)..(&&false)`. let t = &&true; if let Range { start: true, end } = t..&&false {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types if let true = let true = true {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } fn nested_within_while_expr() { while &let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while !let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while *let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR type `bool` cannot be dereferenced - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while -let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR cannot apply unary operator `-` to type `bool` - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement fn _check_try_binds_tighter() -> Result<(), ()> { while let 0 = 0? {} @@ -222,72 +165,51 @@ fn nested_within_while_expr() { Ok(()) } while (let 0 = 0)? {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR the `?` operator can only be applied to values that implement `Try` - //~| ERROR the `?` operator can only be used in a function that returns `Result` - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while true || let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while (true || let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while true && (true || let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while true || (true && let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement let mut x = true; while x = let 0 = 0 {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while true..(let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement while ..(let 0 = 0) {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement while (let 0 = 0).. {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement // Binds as `(let ... = true)..true &&/|| false`. while let Range { start: _, end: _ } = true..true && false {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types while let Range { start: _, end: _ } = true..true || false {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types // Binds as `(let Range { start: F, end } = F)..(|| true)`. const F: fn() -> bool = || true; while let Range { start: F, end } = F..|| true {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types // Binds as `(let Range { start: true, end } = t)..(&&false)`. let t = &&true; while let Range { start: true, end } = t..&&false {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR mismatched types + //~^ ERROR expected expression, found `let` statement //~| ERROR mismatched types while let true = let true = true {} - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } fn not_error_because_clarified_intent() { @@ -302,20 +224,14 @@ fn not_error_because_clarified_intent() { fn outside_if_and_while_expr() { &let 0 = 0; - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement !let 0 = 0; - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement *let 0 = 0; - //~^ ERROR `let` expressions are not supported here - //~| ERROR type `bool` cannot be dereferenced - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement -let 0 = 0; - //~^ ERROR `let` expressions are not supported here - //~| ERROR cannot apply unary operator `-` to type `bool` - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement fn _check_try_binds_tighter() -> Result<(), ()> { let 0 = 0?; @@ -323,44 +239,32 @@ fn outside_if_and_while_expr() { Ok(()) } (let 0 = 0)?; - //~^ ERROR `let` expressions are not supported here - //~| ERROR the `?` operator can only be used in a function that returns `Result` - //~| ERROR the `?` operator can only be applied to values that implement `Try` - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement true || let 0 = 0; - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement (true || let 0 = 0); - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement true && (true || let 0 = 0); - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement let mut x = true; x = let 0 = 0; - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement true..(let 0 = 0); - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement ..(let 0 = 0); - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement (let 0 = 0)..; - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement (let Range { start: _, end: _ } = true..true || false); - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types + //~^ ERROR mismatched types //~| ERROR expected expression, found `let` statement (let true = let true = true); - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement { @@ -377,9 +281,7 @@ fn outside_if_and_while_expr() { // Check function tail position. &let 0 = 0 - //~^ ERROR `let` expressions are not supported here - //~| ERROR mismatched types - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } // Let's make sure that `let` inside const generic arguments are considered. @@ -389,20 +291,17 @@ fn inside_const_generic_arguments() { if let A::<{ true && let 1 = 1 - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement }>::O = 5 {} while let A::<{ true && let 1 = 1 - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement }>::O = 5 {} if A::<{ true && let 1 = 1 - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement }>::O == 5 {} // In the cases above we have `ExprKind::Block` to help us out. @@ -413,8 +312,7 @@ fn inside_const_generic_arguments() { if A::< true && let 1 = 1 - //~^ ERROR `let` expressions are not supported here - //~| ERROR expressions must be enclosed in braces + //~^ ERROR expressions must be enclosed in braces //~| ERROR expected expression, found `let` statement >::O == 5 {} } @@ -423,38 +321,29 @@ fn with_parenthesis() { let opt = Some(Some(1i32)); if (let Some(a) = opt && true) { - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } if (let Some(a) = opt) && true { - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } if (let Some(a) = opt) && (let Some(b) = a) { - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement } if let Some(a) = opt && (true && true) { } if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement } if (let Some(a) = opt && (let Some(b) = a)) && true { - //~^ ERROR `let` expressions are not supported here - //~| ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement } if (let Some(a) = opt && (true)) && true { - //~^ ERROR `let` expressions are not supported here - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement } if (true && (true)) && let Some(a) = opt { diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr index 81933173c25..ab58abf4d46 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.stderr @@ -2,503 +2,6 @@ error: expected expression, found `let` statement --> $DIR/disallowed-positions.rs:29:9 | LL | if (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:33:11 - | -LL | if (((let 0 = 1))) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:37:9 - | -LL | if (let 0 = 1) && true {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:41:17 - | -LL | if true && (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:45:9 - | -LL | if (let 0 = 1) && (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:45:24 - | -LL | if (let 0 = 1) && (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:51:35 - | -LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:51:48 - | -LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:51:61 - | -LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:61:12 - | -LL | while (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:65:14 - | -LL | while (((let 0 = 1))) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:69:12 - | -LL | while (let 0 = 1) && true {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:73:20 - | -LL | while true && (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:77:12 - | -LL | while (let 0 = 1) && (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:77:27 - | -LL | while (let 0 = 1) && (let 0 = 1) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:83:38 - | -LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:83:51 - | -LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:83:64 - | -LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:110:9 - | -LL | if &let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:115:9 - | -LL | if !let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:118:9 - | -LL | if *let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:122:9 - | -LL | if -let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:132:9 - | -LL | if (let 0 = 0)? {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:138:16 - | -LL | if true || let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:141:17 - | -LL | if (true || let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:144:25 - | -LL | if true && (true || let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:147:25 - | -LL | if true || (true && let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:152:12 - | -LL | if x = let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:157:15 - | -LL | if true..(let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:161:11 - | -LL | if ..(let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:165:9 - | -LL | if (let 0 = 0).. {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:196:19 - | -LL | if let true = let true = true {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:202:12 - | -LL | while &let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:207:12 - | -LL | while !let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:210:12 - | -LL | while *let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:214:12 - | -LL | while -let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:224:12 - | -LL | while (let 0 = 0)? {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:230:19 - | -LL | while true || let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:233:20 - | -LL | while (true || let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:236:28 - | -LL | while true && (true || let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:239:28 - | -LL | while true || (true && let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:244:15 - | -LL | while x = let 0 = 0 {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:249:18 - | -LL | while true..(let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:253:14 - | -LL | while ..(let 0 = 0) {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:257:12 - | -LL | while (let 0 = 0).. {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:288:22 - | -LL | while let true = let true = true {} - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:304:6 - | -LL | &let 0 = 0; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:308:6 - | -LL | !let 0 = 0; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:311:6 - | -LL | *let 0 = 0; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:315:6 - | -LL | -let 0 = 0; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:325:6 - | -LL | (let 0 = 0)?; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:331:13 - | -LL | true || let 0 = 0; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:334:14 - | -LL | (true || let 0 = 0); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:337:22 - | -LL | true && (true || let 0 = 0); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:342:9 - | -LL | x = let 0 = 0; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:346:12 - | -LL | true..(let 0 = 0); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:349:8 - | -LL | ..(let 0 = 0); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:352:6 - | -LL | (let 0 = 0)..; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:356:6 - | -LL | (let Range { start: _, end: _ } = true..true || false); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:361:6 - | -LL | (let true = let true = true); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:361:17 - | -LL | (let true = let true = true); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:368:25 - | -LL | let x = true && let y = 1; - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:374:19 - | -LL | [1, 2, 3][let _ = ()] - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:379:6 - | -LL | &let 0 = 0 - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:391:17 - | -LL | true && let 1 = 1 - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:397:17 - | -LL | true && let 1 = 1 - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:403:17 - | -LL | true && let 1 = 1 - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:415:17 - | -LL | true && let 1 = 1 - | ^^^ - -error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/disallowed-positions.rs:415:9 - | -LL | true && let 1 = 1 - | ^^^^^^^^^^^^^^^^^ - | -help: enclose the `const` expression in braces - | -LL | { true && let 1 = 1 } - | + + - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:425:9 - | -LL | if (let Some(a) = opt && true) { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:430:9 - | -LL | if (let Some(a) = opt) && true { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:434:9 - | -LL | if (let Some(a) = opt) && (let Some(b) = a) { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:434:32 - | -LL | if (let Some(a) = opt) && (let Some(b) = a) { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:443:9 - | -LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:443:31 - | -LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:449:9 - | -LL | if (let Some(a) = opt && (let Some(b) = a)) && true { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:449:31 - | -LL | if (let Some(a) = opt && (let Some(b) = a)) && true { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:455:9 - | -LL | if (let Some(a) = opt && (true)) && true { - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:472:22 - | -LL | let x = (true && let y = 1); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:477:20 - | -LL | ([1, 2, 3][let _ = ()]) - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:99:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^ - -error: expected expression, found `let` statement - --> $DIR/disallowed-positions.rs:103:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^ - -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:29:9 - | -LL | if (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions @@ -508,1012 +11,863 @@ note: `let`s wrapped in parentheses are not supported in a context with let chai LL | if (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:33:11 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:32:11 | LL | if (((let 0 = 1))) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:33:11 + --> $DIR/disallowed-positions.rs:32:11 | LL | if (((let 0 = 1))) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:37:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:35:9 | LL | if (let 0 = 1) && true {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:37:9 + --> $DIR/disallowed-positions.rs:35:9 | LL | if (let 0 = 1) && true {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:41:17 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:38:17 | LL | if true && (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:41:17 + --> $DIR/disallowed-positions.rs:38:17 | LL | if true && (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:45:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:41:9 | LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:45:9 + --> $DIR/disallowed-positions.rs:41:9 | LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:45:24 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:41:24 | LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:45:24 + --> $DIR/disallowed-positions.rs:41:24 | LL | if (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:51:35 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:45:35 | LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:51:35 + --> $DIR/disallowed-positions.rs:45:35 | LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:51:48 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:45:48 | LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:51:35 + --> $DIR/disallowed-positions.rs:45:35 | LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:51:61 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:45:61 | LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:51:35 + --> $DIR/disallowed-positions.rs:45:35 | LL | if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:61:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:52:12 | LL | while (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:61:12 + --> $DIR/disallowed-positions.rs:52:12 | LL | while (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:65:14 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:55:14 | LL | while (((let 0 = 1))) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:65:14 + --> $DIR/disallowed-positions.rs:55:14 | LL | while (((let 0 = 1))) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:69:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:58:12 | LL | while (let 0 = 1) && true {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:69:12 + --> $DIR/disallowed-positions.rs:58:12 | LL | while (let 0 = 1) && true {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:73:20 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:61:20 | LL | while true && (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:73:20 + --> $DIR/disallowed-positions.rs:61:20 | LL | while true && (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:77:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:64:12 | LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:77:12 + --> $DIR/disallowed-positions.rs:64:12 | LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:77:27 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:64:27 | LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:77:27 + --> $DIR/disallowed-positions.rs:64:27 | LL | while (let 0 = 1) && (let 0 = 1) {} | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:83:38 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:68:38 | LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:83:38 + --> $DIR/disallowed-positions.rs:68:38 | LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:83:51 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:68:51 | LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:83:38 + --> $DIR/disallowed-positions.rs:68:38 | LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:83:64 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:68:64 | LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:83:38 + --> $DIR/disallowed-positions.rs:68:38 | LL | while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:99:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^ - | - = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:99:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^^^^^^^^^^^ - -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:99:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^ - | - = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:99:16 - | -LL | use_expr!((let 0 = 1 && 0 == 0)); - | ^^^^^^^^^^^^^^^^^^^ - -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:103:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ - | - = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:103:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ - -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:103:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ - | - = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:103:16 - | -LL | use_expr!((let 0 = 1)); - | ^^^^^^^^^ - -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:110:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:88:9 | LL | if &let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:115:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:91:9 | LL | if !let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:118:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:93:9 | LL | if *let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:122:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:95:9 | LL | if -let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:132:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:103:9 | LL | if (let 0 = 0)? {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:132:9 - | -LL | if (let 0 = 0)? {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:138:16 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:106:16 | LL | if true || let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:138:13 + --> $DIR/disallowed-positions.rs:106:13 | LL | if true || let 0 = 0 {} | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:141:17 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:108:17 | LL | if (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:141:14 - | -LL | if (true || let 0 = 0) {} - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:144:25 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:110:25 | LL | if true && (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:144:22 - | -LL | if true && (true || let 0 = 0) {} - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:147:25 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:112:25 | LL | if true || (true && let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:147:17 - | -LL | if true || (true && let 0 = 0) {} - | ^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:152:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:116:12 | LL | if x = let 0 = 0 {} - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:157:15 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:119:15 | LL | if true..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:157:15 - | -LL | if true..(let 0 = 0) {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:161:11 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:122:11 | LL | if ..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:161:11 - | -LL | if ..(let 0 = 0) {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:165:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:124:9 | LL | if (let 0 = 0).. {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:165:9 - | -LL | if (let 0 = 0).. {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:171:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:128:8 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:175:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:131:8 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:182:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:137:8 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:190:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:143:8 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:196:19 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:147:19 | LL | if let true = let true = true {} - | ^^^^^^^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:202:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:152:12 | LL | while &let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:207:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:155:12 | LL | while !let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:210:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:157:12 | LL | while *let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:214:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:159:12 | LL | while -let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:224:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:167:12 | LL | while (let 0 = 0)? {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:224:12 - | -LL | while (let 0 = 0)? {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:230:19 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:170:19 | LL | while true || let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:230:16 + --> $DIR/disallowed-positions.rs:170:16 | LL | while true || let 0 = 0 {} | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:233:20 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:172:20 | LL | while (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:233:17 - | -LL | while (true || let 0 = 0) {} - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:236:28 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:174:28 | LL | while true && (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:236:25 - | -LL | while true && (true || let 0 = 0) {} - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:239:28 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:176:28 | LL | while true || (true && let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:239:20 - | -LL | while true || (true && let 0 = 0) {} - | ^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:244:15 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:180:15 | LL | while x = let 0 = 0 {} - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:249:18 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:183:18 | LL | while true..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:249:18 - | -LL | while true..(let 0 = 0) {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:253:14 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:186:14 | LL | while ..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:253:14 - | -LL | while ..(let 0 = 0) {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:257:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:188:12 | LL | while (let 0 = 0).. {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:257:12 - | -LL | while (let 0 = 0).. {} - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:263:11 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:192:11 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:267:11 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:195:11 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:274:11 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:201:11 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:282:11 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:207:11 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:288:22 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:211:22 | LL | while let true = let true = true {} - | ^^^^^^^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:304:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:226:6 | LL | &let 0 = 0; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:308:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:229:6 | LL | !let 0 = 0; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:311:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:231:6 | LL | *let 0 = 0; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:315:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:233:6 | LL | -let 0 = 0; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:325:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:241:6 | LL | (let 0 = 0)?; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:325:6 - | -LL | (let 0 = 0)?; - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:331:13 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:244:13 | LL | true || let 0 = 0; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:331:10 - | -LL | true || let 0 = 0; - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:334:14 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:246:14 | LL | (true || let 0 = 0); - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:334:11 - | -LL | (true || let 0 = 0); - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:337:22 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:248:22 | LL | true && (true || let 0 = 0); - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `||` operators are not supported in let chain expressions - --> $DIR/disallowed-positions.rs:337:19 - | -LL | true && (true || let 0 = 0); - | ^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:342:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:252:9 | LL | x = let 0 = 0; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:346:12 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:255:12 | LL | true..(let 0 = 0); - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:346:12 - | -LL | true..(let 0 = 0); - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:349:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:257:8 | LL | ..(let 0 = 0); - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:349:8 - | -LL | ..(let 0 = 0); - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:352:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:259:6 | LL | (let 0 = 0)..; - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:352:6 - | -LL | (let 0 = 0)..; - | ^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:356:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:262:6 | LL | (let Range { start: _, end: _ } = true..true || false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:361:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:266:6 | LL | (let true = let true = true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:361:6 + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:266:17 | LL | (let true = let true = true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:272:25 + | +LL | let x = true && let y = 1; + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:278:19 + | +LL | [1, 2, 3][let _ = ()] + | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:379:6 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:283:6 | LL | &let 0 = 0 - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:391:17 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:293:17 | LL | true && let 1 = 1 - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:397:17 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:298:17 | LL | true && let 1 = 1 - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:403:17 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:303:17 | LL | true && let 1 = 1 - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:415:17 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:314:17 | LL | true && let 1 = 1 - | ^^^^^^^^^ + | ^^^ | = note: only supported directly in conditions of `if` and `while` expressions -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:425:9 +error: expressions must be enclosed in braces to be used as const generic arguments + --> $DIR/disallowed-positions.rs:314:9 + | +LL | true && let 1 = 1 + | ^^^^^^^^^^^^^^^^^ + | +help: enclose the `const` expression in braces + | +LL | { true && let 1 = 1 } + | + + + +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:323:9 | LL | if (let Some(a) = opt && true) { | ^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:425:9 + --> $DIR/disallowed-positions.rs:323:9 | LL | if (let Some(a) = opt && true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:430:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:327:9 | LL | if (let Some(a) = opt) && true { | ^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:430:9 + --> $DIR/disallowed-positions.rs:327:9 | LL | if (let Some(a) = opt) && true { | ^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:434:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:330:9 | LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:434:9 + --> $DIR/disallowed-positions.rs:330:9 | LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:434:32 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:330:32 | LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:434:32 + --> $DIR/disallowed-positions.rs:330:32 | LL | if (let Some(a) = opt) && (let Some(b) = a) { | ^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:443:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:337:9 | LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:443:9 + --> $DIR/disallowed-positions.rs:337:9 | LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:443:31 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:337:31 | LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:443:31 + --> $DIR/disallowed-positions.rs:337:31 | LL | if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { | ^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:449:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:341:9 | LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:449:9 + --> $DIR/disallowed-positions.rs:341:9 | LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:449:31 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:341:31 | LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:449:31 + --> $DIR/disallowed-positions.rs:341:31 | LL | if (let Some(a) = opt && (let Some(b) = a)) && true { | ^^^^^^^^^^^^^^^ -error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:455:9 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:345:9 | LL | if (let Some(a) = opt && (true)) && true { | ^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions note: `let`s wrapped in parentheses are not supported in a context with let chains - --> $DIR/disallowed-positions.rs:455:9 + --> $DIR/disallowed-positions.rs:345:9 | LL | if (let Some(a) = opt && (true)) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:110:8 - | -LL | if &let 0 = 0 {} - | ^^^^^^^^^^ expected `bool`, found `&bool` - | -help: consider removing the borrow - | -LL - if &let 0 = 0 {} -LL + if let 0 = 0 {} - | - -error[E0614]: type `bool` cannot be dereferenced - --> $DIR/disallowed-positions.rs:118:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:361:22 | -LL | if *let 0 = 0 {} - | ^^^^^^^^^^ - -error[E0600]: cannot apply unary operator `-` to type `bool` - --> $DIR/disallowed-positions.rs:122:8 +LL | let x = (true && let y = 1); + | ^^^ | -LL | if -let 0 = 0 {} - | ^^^^^^^^^^ cannot apply unary operator `-` + = note: only supported directly in conditions of `if` and `while` expressions -error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:132:8 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:366:20 | -LL | if (let 0 = 0)? {} - | ^^^^^^^^^^^^ the `?` operator cannot be applied to type `bool` +LL | ([1, 2, 3][let _ = ()]) + | ^^^ | - = help: the trait `Try` is not implemented for `bool` + = note: only supported directly in conditions of `if` and `while` expressions -error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) - --> $DIR/disallowed-positions.rs:132:19 +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:81:16 | -LL | fn nested_within_if_expr() { - | -------------------------- this function should return `Result` or `Option` to accept `?` -... -LL | if (let 0 = 0)? {} - | ^ cannot use the `?` operator in a function that returns `()` +LL | use_expr!((let 0 = 1 && 0 == 0)); + | ^^^ | - = help: the trait `FromResidual<_>` is not implemented for `()` + = note: only supported directly in conditions of `if` and `while` expressions -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:152:8 - | -LL | if x = let 0 = 0 {} - | ^^^^^^^^^^^^^ expected `bool`, found `()` +error: expected expression, found `let` statement + --> $DIR/disallowed-positions.rs:83:16 | -help: you might have meant to compare for equality +LL | use_expr!((let 0 = 1)); + | ^^^ | -LL | if x == let 0 = 0 {} - | + + = note: only supported directly in conditions of `if` and `while` expressions error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:157:8 + --> $DIR/disallowed-positions.rs:119:8 | LL | if true..(let 0 = 0) {} | ^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` @@ -1522,25 +876,7 @@ LL | if true..(let 0 = 0) {} found struct `std::ops::Range<bool>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:161:8 - | -LL | if ..(let 0 = 0) {} - | ^^^^^^^^^^^^^ expected `bool`, found `RangeTo<bool>` - | - = note: expected type `bool` - found struct `RangeTo<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:165:8 - | -LL | if (let 0 = 0).. {} - | ^^^^^^^^^^^^^ expected `bool`, found `RangeFrom<bool>` - | - = note: expected type `bool` - found struct `RangeFrom<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:171:12 + --> $DIR/disallowed-positions.rs:128:12 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -1551,16 +887,7 @@ LL | if let Range { start: _, end: _ } = true..true && false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:171:8 - | -LL | if let Range { start: _, end: _ } = true..true && false {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:175:12 + --> $DIR/disallowed-positions.rs:131:12 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -1571,16 +898,7 @@ LL | if let Range { start: _, end: _ } = true..true || false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:175:8 - | -LL | if let Range { start: _, end: _ } = true..true || false {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:182:12 + --> $DIR/disallowed-positions.rs:137:12 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `fn() -> bool` @@ -1591,29 +909,7 @@ LL | if let Range { start: F, end } = F..|| true {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:182:41 - | -LL | if let Range { start: F, end } = F..|| true {} - | ^^^^^^^ expected `bool`, found closure - | - = note: expected type `bool` - found closure `[closure@$DIR/disallowed-positions.rs:182:41: 182:43]` -help: use parentheses to call this closure - | -LL | if let Range { start: F, end } = F..(|| true)() {} - | + +++ - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:182:8 - | -LL | if let Range { start: F, end } = F..|| true {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:190:12 + --> $DIR/disallowed-positions.rs:143:12 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` @@ -1623,29 +919,8 @@ LL | if let Range { start: true, end } = t..&&false {} = note: expected type `bool` found struct `std::ops::Range<_>` -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:190:44 - | -LL | if let Range { start: true, end } = t..&&false {} - | ^^^^^^^ expected `bool`, found `&&bool` - | -help: consider removing the `&&` - | -LL - if let Range { start: true, end } = t..&&false {} -LL + if let Range { start: true, end } = t..false {} - | - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:190:8 - | -LL | if let Range { start: true, end } = t..&&false {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:128:20 + --> $DIR/disallowed-positions.rs:99:20 | LL | if let 0 = 0? {} | ^^ the `?` operator cannot be applied to type `{integer}` @@ -1653,61 +928,7 @@ LL | if let 0 = 0? {} = help: the trait `Try` is not implemented for `{integer}` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:202:11 - | -LL | while &let 0 = 0 {} - | ^^^^^^^^^^ expected `bool`, found `&bool` - | -help: consider removing the borrow - | -LL - while &let 0 = 0 {} -LL + while let 0 = 0 {} - | - -error[E0614]: type `bool` cannot be dereferenced - --> $DIR/disallowed-positions.rs:210:11 - | -LL | while *let 0 = 0 {} - | ^^^^^^^^^^ - -error[E0600]: cannot apply unary operator `-` to type `bool` - --> $DIR/disallowed-positions.rs:214:11 - | -LL | while -let 0 = 0 {} - | ^^^^^^^^^^ cannot apply unary operator `-` - -error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:224:11 - | -LL | while (let 0 = 0)? {} - | ^^^^^^^^^^^^ the `?` operator cannot be applied to type `bool` - | - = help: the trait `Try` is not implemented for `bool` - -error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) - --> $DIR/disallowed-positions.rs:224:22 - | -LL | fn nested_within_while_expr() { - | ----------------------------- this function should return `Result` or `Option` to accept `?` -... -LL | while (let 0 = 0)? {} - | ^ cannot use the `?` operator in a function that returns `()` - | - = help: the trait `FromResidual<_>` is not implemented for `()` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:244:11 - | -LL | while x = let 0 = 0 {} - | ^^^^^^^^^^^^^ expected `bool`, found `()` - | -help: you might have meant to compare for equality - | -LL | while x == let 0 = 0 {} - | + - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:249:11 + --> $DIR/disallowed-positions.rs:183:11 | LL | while true..(let 0 = 0) {} | ^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` @@ -1716,25 +937,7 @@ LL | while true..(let 0 = 0) {} found struct `std::ops::Range<bool>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:253:11 - | -LL | while ..(let 0 = 0) {} - | ^^^^^^^^^^^^^ expected `bool`, found `RangeTo<bool>` - | - = note: expected type `bool` - found struct `RangeTo<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:257:11 - | -LL | while (let 0 = 0).. {} - | ^^^^^^^^^^^^^ expected `bool`, found `RangeFrom<bool>` - | - = note: expected type `bool` - found struct `RangeFrom<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:263:15 + --> $DIR/disallowed-positions.rs:192:15 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -1745,16 +948,7 @@ LL | while let Range { start: _, end: _ } = true..true && false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:263:11 - | -LL | while let Range { start: _, end: _ } = true..true && false {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:267:15 + --> $DIR/disallowed-positions.rs:195:15 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -1765,16 +959,7 @@ LL | while let Range { start: _, end: _ } = true..true || false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:267:11 - | -LL | while let Range { start: _, end: _ } = true..true || false {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:274:15 + --> $DIR/disallowed-positions.rs:201:15 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `fn() -> bool` @@ -1785,29 +970,7 @@ LL | while let Range { start: F, end } = F..|| true {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:274:44 - | -LL | while let Range { start: F, end } = F..|| true {} - | ^^^^^^^ expected `bool`, found closure - | - = note: expected type `bool` - found closure `[closure@$DIR/disallowed-positions.rs:274:44: 274:46]` -help: use parentheses to call this closure - | -LL | while let Range { start: F, end } = F..(|| true)() {} - | + +++ - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:274:11 - | -LL | while let Range { start: F, end } = F..|| true {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:282:15 + --> $DIR/disallowed-positions.rs:207:15 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` @@ -1817,68 +980,16 @@ LL | while let Range { start: true, end } = t..&&false {} = note: expected type `bool` found struct `std::ops::Range<_>` -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:282:47 - | -LL | while let Range { start: true, end } = t..&&false {} - | ^^^^^^^ expected `bool`, found `&&bool` - | -help: consider removing the `&&` - | -LL - while let Range { start: true, end } = t..&&false {} -LL + while let Range { start: true, end } = t..false {} - | - -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:282:11 - | -LL | while let Range { start: true, end } = t..&&false {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `Range<bool>` - | - = note: expected type `bool` - found struct `std::ops::Range<bool>` - error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:220:23 + --> $DIR/disallowed-positions.rs:163:23 | LL | while let 0 = 0? {} | ^^ the `?` operator cannot be applied to type `{integer}` | = help: the trait `Try` is not implemented for `{integer}` -error[E0614]: type `bool` cannot be dereferenced - --> $DIR/disallowed-positions.rs:311:5 - | -LL | *let 0 = 0; - | ^^^^^^^^^^ - -error[E0600]: cannot apply unary operator `-` to type `bool` - --> $DIR/disallowed-positions.rs:315:5 - | -LL | -let 0 = 0; - | ^^^^^^^^^^ cannot apply unary operator `-` - -error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:325:5 - | -LL | (let 0 = 0)?; - | ^^^^^^^^^^^^ the `?` operator cannot be applied to type `bool` - | - = help: the trait `Try` is not implemented for `bool` - -error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) - --> $DIR/disallowed-positions.rs:325:16 - | -LL | fn outside_if_and_while_expr() { - | ------------------------------ this function should return `Result` or `Option` to accept `?` -... -LL | (let 0 = 0)?; - | ^ cannot use the `?` operator in a function that returns `()` - | - = help: the trait `FromResidual<_>` is not implemented for `()` - error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:356:10 + --> $DIR/disallowed-positions.rs:262:10 | LL | (let Range { start: _, end: _ } = true..true || false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -1888,24 +999,15 @@ LL | (let Range { start: _, end: _ } = true..true || false); = note: expected type `bool` found struct `std::ops::Range<_>` -error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:379:5 - | -LL | fn outside_if_and_while_expr() { - | - help: try adding a return type: `-> &bool` -... -LL | &let 0 = 0 - | ^^^^^^^^^^ expected `()`, found `&bool` - error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:321:17 + --> $DIR/disallowed-positions.rs:237:17 | LL | let 0 = 0?; | ^^ the `?` operator cannot be applied to type `{integer}` | = help: the trait `Try` is not implemented for `{integer}` -error: aborting due to 215 previous errors +error: aborting due to 104 previous errors -Some errors have detailed explanations: E0277, E0308, E0600, E0614. +Some errors have detailed explanations: E0277, E0308. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs index 2a6c144350a..3c572054e3f 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs @@ -14,7 +14,6 @@ fn main() { }; let Some(n) = opt && let another = n else { //~^ ERROR a `&&` expression cannot be directly assigned in `let...else` - //~| ERROR `let` expressions are not supported here //~| ERROR mismatched types //~| ERROR mismatched types //~| ERROR expected expression, found `let` statement diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr index 9bc3e754126..0442f1218b1 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr @@ -14,6 +14,8 @@ error: expected expression, found `let` statement | LL | let Some(n) = opt && let another = n else { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: a `&&` expression cannot be directly assigned in `let...else` --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19 @@ -27,13 +29,13 @@ LL | let Some(n) = (opt && let another = n) else { | + + error: this `if` expression is missing a block after the condition - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:24:5 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:23:5 | LL | if let Some(n) = opt else { | ^^ | help: add a block here - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:24:25 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:23:25 | LL | if let Some(n) = opt else { | ^ @@ -44,31 +46,31 @@ LL + let Some(n) = opt else { | error: this `if` expression is missing a block after the condition - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:28:5 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:27:5 | LL | if let Some(n) = opt && n == 1 else { | ^^ | help: add a block here - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:28:35 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:27:35 | LL | if let Some(n) = opt && n == 1 else { | ^ error: this `if` expression is missing a block after the condition - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:32:5 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:31:5 | LL | if let Some(n) = opt && let another = n else { | ^^ | help: add a block here - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:32:44 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:31:44 | LL | if let Some(n) = opt && let another = n else { | ^ error: expected `{`, found keyword `else` - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:38:33 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:37:33 | LL | while let Some(n) = opt else { | ----- ----------------- ^^^^ expected `{` @@ -77,7 +79,7 @@ LL | while let Some(n) = opt else { | while parsing the body of this `while` expression error: expected `{`, found keyword `else` - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:44:43 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:43:43 | LL | while let Some(n) = opt && n == 1 else { | ----- --------------------------- ^^^^ expected `{` @@ -86,7 +88,7 @@ LL | while let Some(n) = opt && n == 1 else { | while parsing the body of this `while` expression error: expected `{`, found keyword `else` - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:50:52 + --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:49:52 | LL | while let Some(n) = opt && let another = n else { | ----- ------------------------------------ ^^^^ expected `{` @@ -94,14 +96,6 @@ LL | while let Some(n) = opt && let another = n else { | | this `while` condition successfully parsed | while parsing the body of this `while` expression -error: `let` expressions are not supported here - --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:26 - | -LL | let Some(n) = opt && let another = n else { - | ^^^^^^^^^^^^^^^ - | - = note: only supported directly in conditions of `if` and `while` expressions - error[E0308]: mismatched types --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:19 | @@ -142,6 +136,6 @@ LL | let Some(n) = opt && let another = n else { = note: expected type `bool` found enum `Option<_>` -error: aborting due to 14 previous errors +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.rs index 2b407ef510c..bca7564efd8 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.rs @@ -43,8 +43,7 @@ fn _macros() { macro_rules! noop_expr { ($e:expr) => {}; } noop_expr!((let 0 = 1)); - //~^ ERROR `let` expressions in this position are unstable [E0658] - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement macro_rules! use_expr { ($e:expr) => { @@ -53,8 +52,7 @@ fn _macros() { } } #[cfg(FALSE)] (let 0 = 1); - //~^ ERROR `let` expressions in this position are unstable [E0658] - //~| ERROR expected expression, found `let` statement + //~^ ERROR expected expression, found `let` statement use_expr!(let 0 = 1); //~^ ERROR no rules expected the token `let` } diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr index 7a43b71fc8b..6f74736755e 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/feature-gate.stderr @@ -1,17 +1,21 @@ error: expected expression, found `let` statement - --> $DIR/feature-gate.rs:55:20 + --> $DIR/feature-gate.rs:54:20 | LL | #[cfg(FALSE)] (let 0 = 1); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/feature-gate.rs:45:17 | LL | noop_expr!((let 0 = 1)); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: no rules expected the token `let` - --> $DIR/feature-gate.rs:58:15 + --> $DIR/feature-gate.rs:56:15 | LL | macro_rules! use_expr { | --------------------- when calling this macro @@ -20,7 +24,7 @@ LL | use_expr!(let 0 = 1); | ^^^ no rules expected this token in macro call | note: while trying to match meta-variable `$e:expr` - --> $DIR/feature-gate.rs:50:10 + --> $DIR/feature-gate.rs:49:10 | LL | ($e:expr) => { | ^^^^^^^ @@ -97,24 +101,6 @@ LL | while let Range { start: _, end: _ } = (true..true) && false {} = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information = help: add `#![feature(let_chains)]` to the crate attributes to enable -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:55:20 - | -LL | #[cfg(FALSE)] (let 0 = 1); - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error[E0658]: `let` expressions in this position are unstable - --> $DIR/feature-gate.rs:45:17 - | -LL | noop_expr!((let 0 = 1)); - | ^^^^^^^^^ - | - = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information - = help: add `#![feature(let_chains)]` to the crate attributes to enable - -error: aborting due to 13 previous errors +error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.rs index a942d1f4caf..dce1c19ff33 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.rs @@ -13,6 +13,7 @@ fn main() { if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { //~^ ERROR expected expression, found `let` statement //~| ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement true } } @@ -31,6 +32,7 @@ fn main() { { if let Some(elem) = _opt && [1, 2, 3][let _ = ()] = 1 { //~^ ERROR expected expression, found `let` statement + //~| ERROR expected expression, found `let` statement true } } diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr index d1ce83c7233..247fad2e992 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/invalid-let-in-a-valid-let-context.stderr @@ -3,36 +3,64 @@ error: expected expression, found `let` statement | LL | let _ = &&let Some(x) = Some(42); | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:13:47 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement --> $DIR/invalid-let-in-a-valid-let-context.rs:13:57 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/invalid-let-in-a-valid-let-context.rs:13:12 + | +LL | if let Some(elem) = _opt && [1, 2, 3][let _ = &&let Some(x) = Some(42)] = 1 { + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement - --> $DIR/invalid-let-in-a-valid-let-context.rs:23:23 + --> $DIR/invalid-let-in-a-valid-let-context.rs:24:23 | LL | [1, 2, 3][let _ = ()]; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement - --> $DIR/invalid-let-in-a-valid-let-context.rs:32:47 + --> $DIR/invalid-let-in-a-valid-let-context.rs:33:47 | LL | if let Some(elem) = _opt && [1, 2, 3][let _ = ()] = 1 { | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions + +error: expected expression, found `let` statement + --> $DIR/invalid-let-in-a-valid-let-context.rs:33:12 + | +LL | if let Some(elem) = _opt && [1, 2, 3][let _ = ()] = 1 { + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions error: expected expression, found `let` statement - --> $DIR/invalid-let-in-a-valid-let-context.rs:40:21 + --> $DIR/invalid-let-in-a-valid-let-context.rs:42:21 | LL | let x = let y = 1; | ^^^ + | + = note: only supported directly in conditions of `if` and `while` expressions -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/fallback.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/fallback.rs new file mode 100644 index 00000000000..da2778f6101 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/fallback.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(effects)] + +pub const fn owo() {} + +fn main() { + // make sure falling back ty/int vars doesn't cause const fallback to be skipped... + // See issue: 115791. + let _ = 1; + if false { + let x = panic!(); + } + + let _ = owo; +} diff --git a/tests/ui/rmeta/auxiliary/rmeta-meta.rs b/tests/ui/rmeta/auxiliary/rmeta-meta.rs index 6d8ed95bd38..6d435049527 100644 --- a/tests/ui/rmeta/auxiliary/rmeta-meta.rs +++ b/tests/ui/rmeta/auxiliary/rmeta-meta.rs @@ -6,3 +6,7 @@ pub struct Foo { pub field: i32, } + +pub fn missing_optimized_mir() { + println!("indeed"); +} diff --git a/tests/ui/rmeta/no_optitimized_mir.rs b/tests/ui/rmeta/no_optitimized_mir.rs new file mode 100644 index 00000000000..c503005f16b --- /dev/null +++ b/tests/ui/rmeta/no_optitimized_mir.rs @@ -0,0 +1,11 @@ +// aux-build:rmeta-meta.rs +// no-prefer-dynamic +// build-fail + +// Check that we do not ICE when we need optimized MIR but it is missing. + +extern crate rmeta_meta; + +fn main() { + rmeta_meta::missing_optimized_mir(); +} diff --git a/tests/ui/rmeta/no_optitimized_mir.stderr b/tests/ui/rmeta/no_optitimized_mir.stderr new file mode 100644 index 00000000000..a17024c5310 --- /dev/null +++ b/tests/ui/rmeta/no_optitimized_mir.stderr @@ -0,0 +1,10 @@ +error: missing optimized MIR for an item in the crate `rmeta_meta` + | +note: missing optimized MIR for this item (was the crate `rmeta_meta` compiled with `--emit=metadata`?) + --> $DIR/auxiliary/rmeta-meta.rs:10:1 + | +LL | pub fn missing_optimized_mir() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/sanitize/cfg.rs b/tests/ui/sanitize/cfg.rs index c0f08a6d1e5..523de1ceaee 100644 --- a/tests/ui/sanitize/cfg.rs +++ b/tests/ui/sanitize/cfg.rs @@ -2,19 +2,19 @@ // the `#[cfg(sanitize = "option")]` attribute is configured. // needs-sanitizer-support -// needs-sanitizer-address -// needs-sanitizer-cfi -// needs-sanitizer-kcfi -// needs-sanitizer-leak -// needs-sanitizer-memory -// needs-sanitizer-thread // check-pass -// revisions: address leak memory thread +// revisions: address cfi kcfi leak memory thread +//[address]needs-sanitizer-address //[address]compile-flags: -Zsanitizer=address --cfg address -//[cfi]compile-flags: -Zsanitizer=cfi --cfg cfi +//[cfi]needs-sanitizer-cfi +//[cfi]compile-flags: -Zsanitizer=cfi --cfg cfi -Clto +//[kcfi]needs-sanitizer-kcfi //[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi +//[leak]needs-sanitizer-leak //[leak]compile-flags: -Zsanitizer=leak --cfg leak +//[memory]needs-sanitizer-memory //[memory]compile-flags: -Zsanitizer=memory --cfg memory +//[thread]needs-sanitizer-thread //[thread]compile-flags: -Zsanitizer=thread --cfg thread #![feature(cfg_sanitize)] diff --git a/tests/ui/span/issue-29595.stderr b/tests/ui/span/issue-29595.stderr index 92445e40731..7d603cdbfe5 100644 --- a/tests/ui/span/issue-29595.stderr +++ b/tests/ui/span/issue-29595.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `u8: Tr` is not satisfied | LL | let a: u8 = Tr::C; | ^^^^^ the trait `Tr` is not implemented for `u8` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-29595.rs:1:1 + | +LL | trait Tr { + | ^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/span/send-is-not-static-std-sync.rs b/tests/ui/span/send-is-not-static-std-sync.rs index f8ab5243c22..9c1ee287154 100644 --- a/tests/ui/span/send-is-not-static-std-sync.rs +++ b/tests/ui/span/send-is-not-static-std-sync.rs @@ -46,7 +46,7 @@ fn channel() { tx.send(&z).unwrap(); } //~^^ ERROR `z` does not live long enough - // (channels lack #[may_dangle], thus their dtors are implicit uses of `z`) + tx.use_ref(); // (channel drop glue does not use `z` => needs explicit use) } fn main() {} diff --git a/tests/ui/span/send-is-not-static-std-sync.stderr b/tests/ui/span/send-is-not-static-std-sync.stderr index eaba415adaa..46534b39168 100644 --- a/tests/ui/span/send-is-not-static-std-sync.stderr +++ b/tests/ui/span/send-is-not-static-std-sync.stderr @@ -75,11 +75,9 @@ LL | tx.send(&z).unwrap(); | ^^ borrowed value does not live long enough LL | } | - `z` dropped here while still borrowed -... -LL | } - | - borrow might be used here, when `tx` is dropped and runs the `Drop` code for type `Sender` - | - = note: values in a scope are dropped in the opposite order they are defined +LL | +LL | tx.use_ref(); // (channel drop glue does not use `z` => needs explicit use) + | -- borrow later used here error: aborting due to 6 previous errors diff --git a/tests/ui/specialization/issue-38091.stderr b/tests/ui/specialization/issue-38091.stderr index f2210a40719..4d840482b46 100644 --- a/tests/ui/specialization/issue-38091.stderr +++ b/tests/ui/specialization/issue-38091.stderr @@ -14,6 +14,11 @@ error[E0277]: the trait bound `(): Valid` is not satisfied LL | default type Ty = (); | ^^ the trait `Valid` is not implemented for `()` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-38091.rs:20:1 + | +LL | trait Valid {} + | ^^^^^^^^^^^ note: required by a bound in `Iterate::Ty` --> $DIR/issue-38091.rs:5:14 | diff --git a/tests/ui/static/static-reference-to-fn-1.stderr b/tests/ui/static/static-reference-to-fn-1.stderr index b68352b5183..86c4eaa7eb4 100644 --- a/tests/ui/static/static-reference-to-fn-1.stderr +++ b/tests/ui/static/static-reference-to-fn-1.stderr @@ -7,7 +7,6 @@ LL | func: &foo, = note: expected reference `&fn() -> Option<isize>` found reference `&fn() -> Option<isize> {foo}` = note: fn items are distinct from fn pointers - = note: when the arguments and return types match, functions can be coerced to function pointers help: consider casting to a fn pointer | LL | func: &(foo as fn() -> Option<isize>), diff --git a/tests/ui/suggestions/issue-89333.stderr b/tests/ui/suggestions/issue-89333.stderr index f73f1147d5d..4739f11ddad 100644 --- a/tests/ui/suggestions/issue-89333.stderr +++ b/tests/ui/suggestions/issue-89333.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<'a> &'a _: Trait` is not satisfied LL | test(&|| 0); | ^^^^ the trait `for<'a> Trait` is not implemented for `&'a _` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-89333.rs:9:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `test` --> $DIR/issue-89333.rs:11:55 | diff --git a/tests/ui/test-attrs/issue-36768.rs b/tests/ui/test-attrs/issue-36768.rs index f671cbc8205..7531f3621f5 100644 --- a/tests/ui/test-attrs/issue-36768.rs +++ b/tests/ui/test-attrs/issue-36768.rs @@ -1,6 +1,6 @@ // run-pass // compile-flags:--test -#![deny(private_in_public)] +#![deny(private_interfaces)] #[test] fn foo() {} mod foo {} diff --git a/tests/ui/thir-print/thir-flat-const-variant.stdout b/tests/ui/thir-print/thir-flat-const-variant.stdout index 7bddc925996..af7f2b67152 100644 --- a/tests/ui/thir-print/thir-flat-const-variant.stdout +++ b/tests/ui/thir-print/thir-flat-const-variant.stdout @@ -1,7 +1,11 @@ DefId(0:8 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR1): Thir { body_type: Const( - Foo, + Adt( + Foo, + [ + ], + ), ), arms: [], blocks: [], @@ -46,7 +50,11 @@ Thir { base: None, }, ), - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -60,7 +68,11 @@ Thir { ), value: e2, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -72,7 +84,11 @@ Thir { lint_level: Inherited, value: e3, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -86,7 +102,11 @@ Thir { DefId(0:9 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR2): Thir { body_type: Const( - Foo, + Adt( + Foo, + [ + ], + ), ), arms: [], blocks: [], @@ -131,7 +151,11 @@ Thir { base: None, }, ), - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -145,7 +169,11 @@ Thir { ), value: e2, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -157,7 +185,11 @@ Thir { lint_level: Inherited, value: e3, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -171,7 +203,11 @@ Thir { DefId(0:10 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR3): Thir { body_type: Const( - Foo, + Adt( + Foo, + [ + ], + ), ), arms: [], blocks: [], @@ -216,7 +252,11 @@ Thir { base: None, }, ), - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -230,7 +270,11 @@ Thir { ), value: e2, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -242,7 +286,11 @@ Thir { lint_level: Inherited, value: e3, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -256,7 +304,11 @@ Thir { DefId(0:11 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR4): Thir { body_type: Const( - Foo, + Adt( + Foo, + [ + ], + ), ), arms: [], blocks: [], @@ -301,7 +353,11 @@ Thir { base: None, }, ), - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -315,7 +371,11 @@ Thir { ), value: e2, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), @@ -327,7 +387,11 @@ Thir { lint_level: Inherited, value: e3, }, - ty: Foo, + ty: Adt( + Foo, + [ + ], + ), temp_lifetime: Some( Node(3), ), diff --git a/tests/ui/thir-print/thir-tree-match.stdout b/tests/ui/thir-print/thir-tree-match.stdout index 3fc130f0176..0e21b98307b 100644 --- a/tests/ui/thir-print/thir-tree-match.stdout +++ b/tests/ui/thir-print/thir-tree-match.stdout @@ -1,13 +1,13 @@ DefId(0:16 ~ thir_tree_match[fcf8]::has_match): params: [ Param { - ty: Foo + ty: Adt(Foo, []) ty_span: Some($DIR/thir-tree-match.rs:15:19: 15:22 (#0)) self_kind: None hir_id: Some(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).1)) param: Some( Pat: { - ty: Foo + ty: Adt(Foo, []) span: $DIR/thir-tree-match.rs:15:14: 15:17 (#0) kind: PatKind { Binding { @@ -15,7 +15,7 @@ params: [ name: "foo" mode: ByValue var: LocalVarId(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).2)) - ty: Foo + ty: Adt(Foo, []) is_primary: true subpattern: None } @@ -73,7 +73,7 @@ body: Match { scrutinee: Expr { - ty: Foo + ty: Adt(Foo, []) temp_lifetime: Some(Node(26)) span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0) kind: @@ -82,7 +82,7 @@ body: lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).4)) value: Expr { - ty: Foo + ty: Adt(Foo, []) temp_lifetime: Some(Node(26)) span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0) kind: @@ -96,7 +96,7 @@ body: Arm { pattern: Pat: { - ty: Foo + ty: Adt(Foo, []) span: $DIR/thir-tree-match.rs:17:9: 17:32 (#0) kind: PatKind { Variant { @@ -110,7 +110,7 @@ body: variant_index: 0 subpatterns: [ Pat: { - ty: Bar + ty: Adt(Bar, []) span: $DIR/thir-tree-match.rs:17:21: 17:31 (#0) kind: PatKind { Variant { @@ -169,7 +169,7 @@ body: Arm { pattern: Pat: { - ty: Foo + ty: Adt(Foo, []) span: $DIR/thir-tree-match.rs:18:9: 18:23 (#0) kind: PatKind { Variant { @@ -183,7 +183,7 @@ body: variant_index: 0 subpatterns: [ Pat: { - ty: Bar + ty: Adt(Bar, []) span: $DIR/thir-tree-match.rs:18:21: 18:22 (#0) kind: PatKind { Wild @@ -232,7 +232,7 @@ body: Arm { pattern: Pat: { - ty: Foo + ty: Adt(Foo, []) span: $DIR/thir-tree-match.rs:19:9: 19:20 (#0) kind: PatKind { Variant { diff --git a/tests/ui/trait-bounds/issue-82038.rs b/tests/ui/trait-bounds/issue-82038.rs new file mode 100644 index 00000000000..11de714faf0 --- /dev/null +++ b/tests/ui/trait-bounds/issue-82038.rs @@ -0,0 +1,9 @@ +// Failed bound `bool: Foo` must not point at the `Self: Clone` line + +trait Foo { + fn my_method() where Self: Clone; +} + +fn main() { + <bool as Foo>::my_method(); //~ERROR [E0277] +} diff --git a/tests/ui/trait-bounds/issue-82038.stderr b/tests/ui/trait-bounds/issue-82038.stderr new file mode 100644 index 00000000000..30bb4a0a850 --- /dev/null +++ b/tests/ui/trait-bounds/issue-82038.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `bool: Foo` is not satisfied + --> $DIR/issue-82038.rs:8:6 + | +LL | <bool as Foo>::my_method(); + | ^^^^ the trait `Foo` is not implemented for `bool` + | +help: this trait has no implementations, consider adding one + --> $DIR/issue-82038.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/bound/on-structs-and-enums-in-fns.stderr b/tests/ui/traits/bound/on-structs-and-enums-in-fns.stderr index 61237a63e32..530264b344a 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-in-fns.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-in-fns.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `u32: Trait` is not satisfied LL | fn explode(x: Foo<u32>) {} | ^^^^^^^^ the trait `Trait` is not implemented for `u32` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums-in-fns.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums-in-fns.rs:3:14 | @@ -16,6 +21,11 @@ error[E0277]: the trait bound `f32: Trait` is not satisfied LL | fn kaboom(y: Bar<f32>) {} | ^^^^^^^^ the trait `Trait` is not implemented for `f32` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums-in-fns.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Bar` --> $DIR/on-structs-and-enums-in-fns.rs:7:12 | diff --git a/tests/ui/traits/bound/on-structs-and-enums-in-impls.stderr b/tests/ui/traits/bound/on-structs-and-enums-in-impls.stderr index 8a43742260b..372bbabbd86 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-in-impls.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-in-impls.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `u16: Trait` is not satisfied LL | impl PolyTrait<Foo<u16>> for Struct { | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `u16` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums-in-impls.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums-in-impls.rs:3:14 | diff --git a/tests/ui/traits/bound/on-structs-and-enums-locals.stderr b/tests/ui/traits/bound/on-structs-and-enums-locals.stderr index 20bbe69c059..01cf76c62d5 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-locals.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-locals.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `usize: Trait` is not satisfied LL | let baz: Foo<usize> = loop { }; | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums-locals.rs:1:1 + | +LL | trait Trait { + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums-locals.rs:5:14 | @@ -16,6 +21,11 @@ error[E0277]: the trait bound `{integer}: Trait` is not satisfied LL | x: 3 | ^ the trait `Trait` is not implemented for `{integer}` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums-locals.rs:1:1 + | +LL | trait Trait { + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums-locals.rs:5:14 | diff --git a/tests/ui/traits/bound/on-structs-and-enums-static.stderr b/tests/ui/traits/bound/on-structs-and-enums-static.stderr index fda734e8571..fa14aff684d 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-static.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-static.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `usize: Trait` is not satisfied LL | static X: Foo<usize> = Foo { | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums-static.rs:1:1 + | +LL | trait Trait { + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums-static.rs:5:14 | diff --git a/tests/ui/traits/bound/on-structs-and-enums.stderr b/tests/ui/traits/bound/on-structs-and-enums.stderr index fe05b86344b..606f764852f 100644 --- a/tests/ui/traits/bound/on-structs-and-enums.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums.stderr @@ -20,6 +20,11 @@ error[E0277]: the trait bound `isize: Trait` is not satisfied LL | a: Foo<isize>, | ^^^^^^^^^^ the trait `Trait` is not implemented for `isize` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums.rs:3:14 | @@ -32,6 +37,11 @@ error[E0277]: the trait bound `usize: Trait` is not satisfied LL | Quux(Bar<usize>), | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Bar` --> $DIR/on-structs-and-enums.rs:7:12 | @@ -76,6 +86,11 @@ error[E0277]: the trait bound `i32: Trait` is not satisfied LL | Foo<i32>, | ^^^^^^^^ the trait `Trait` is not implemented for `i32` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Foo` --> $DIR/on-structs-and-enums.rs:3:14 | @@ -88,6 +103,11 @@ error[E0277]: the trait bound `u8: Trait` is not satisfied LL | DictionaryLike { field: Bar<u8> }, | ^^^^^^^ the trait `Trait` is not implemented for `u8` | +help: this trait has no implementations, consider adding one + --> $DIR/on-structs-and-enums.rs:1:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `Bar` --> $DIR/on-structs-and-enums.rs:7:12 | diff --git a/tests/ui/traits/deny-builtin-object-impl.current.stderr b/tests/ui/traits/deny-builtin-object-impl.current.stderr index 5c1987426f7..8ca3d3a057f 100644 --- a/tests/ui/traits/deny-builtin-object-impl.current.stderr +++ b/tests/ui/traits/deny-builtin-object-impl.current.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `dyn NotObject: NotObject` is not satisfied LL | test_not_object::<dyn NotObject>(); | ^^^^^^^^^^^^^ the trait `NotObject` is not implemented for `dyn NotObject` | +help: this trait has no implementations, consider adding one + --> $DIR/deny-builtin-object-impl.rs:10:1 + | +LL | trait NotObject {} + | ^^^^^^^^^^^^^^^ note: required by a bound in `test_not_object` --> $DIR/deny-builtin-object-impl.rs:14:23 | diff --git a/tests/ui/traits/deny-builtin-object-impl.next.stderr b/tests/ui/traits/deny-builtin-object-impl.next.stderr index 5c1987426f7..8ca3d3a057f 100644 --- a/tests/ui/traits/deny-builtin-object-impl.next.stderr +++ b/tests/ui/traits/deny-builtin-object-impl.next.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `dyn NotObject: NotObject` is not satisfied LL | test_not_object::<dyn NotObject>(); | ^^^^^^^^^^^^^ the trait `NotObject` is not implemented for `dyn NotObject` | +help: this trait has no implementations, consider adding one + --> $DIR/deny-builtin-object-impl.rs:10:1 + | +LL | trait NotObject {} + | ^^^^^^^^^^^^^^^ note: required by a bound in `test_not_object` --> $DIR/deny-builtin-object-impl.rs:14:23 | diff --git a/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr b/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr index 263c59ee327..a5d0e6ab095 100644 --- a/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr +++ b/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr @@ -10,6 +10,11 @@ error[E0277]: the trait bound `for<'a> &'a mut Vec<&'a u32>: Foo<'static, i32>` LL | <i32 as RefFoo<i32>>::ref_foo(unknown); | ^^^ the trait `for<'a> Foo<'static, i32>` is not implemented for `&'a mut Vec<&'a u32>` | +help: this trait has no implementations, consider adding one + --> $DIR/dont-autoderef-ty-with-escaping-var.rs:3:1 + | +LL | trait Foo<'x, T> {} + | ^^^^^^^^^^^^^^^^ note: required for `i32` to implement `RefFoo<i32>` --> $DIR/dont-autoderef-ty-with-escaping-var.rs:9:9 | diff --git a/tests/ui/traits/impl-bounds-checking.stderr b/tests/ui/traits/impl-bounds-checking.stderr index 1f969efe114..bfa8213abe7 100644 --- a/tests/ui/traits/impl-bounds-checking.stderr +++ b/tests/ui/traits/impl-bounds-checking.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `isize: Clone2` is not satisfied LL | impl Getter<isize> for isize { | ^^^^^ the trait `Clone2` is not implemented for `isize` | +help: this trait has no implementations, consider adding one + --> $DIR/impl-bounds-checking.rs:1:1 + | +LL | pub trait Clone2 { + | ^^^^^^^^^^^^^^^^ note: required by a bound in `Getter` --> $DIR/impl-bounds-checking.rs:6:17 | diff --git a/tests/ui/traits/issue-105231.rs b/tests/ui/traits/issue-105231.rs index bb2b13664ba..74c7afd6b9e 100644 --- a/tests/ui/traits/issue-105231.rs +++ b/tests/ui/traits/issue-105231.rs @@ -1,9 +1,9 @@ +//~ ERROR overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send` struct A<T>(B<T>); //~^ ERROR recursive types `A` and `B` have infinite size struct B<T>(A<A<T>>); trait Foo {} impl<T> Foo for T where T: Send {} -//~^ ERROR overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send` impl Foo for B<u8> {} fn main() {} diff --git a/tests/ui/traits/issue-105231.stderr b/tests/ui/traits/issue-105231.stderr index 76a71067353..fe20c47c57a 100644 --- a/tests/ui/traits/issue-105231.stderr +++ b/tests/ui/traits/issue-105231.stderr @@ -1,5 +1,5 @@ error[E0072]: recursive types `A` and `B` have infinite size - --> $DIR/issue-105231.rs:1:1 + --> $DIR/issue-105231.rs:2:1 | LL | struct A<T>(B<T>); | ^^^^^^^^^^^ ---- recursive without indirection @@ -15,14 +15,10 @@ LL ~ struct B<T>(Box<A<A<T>>>); | error[E0275]: overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send` - --> $DIR/issue-105231.rs:5:28 - | -LL | impl<T> Foo for T where T: Send {} - | ^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_105231`) note: required because it appears within the type `B<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<u8>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` - --> $DIR/issue-105231.rs:3:8 + --> $DIR/issue-105231.rs:4:8 | LL | struct B<T>(A<A<T>>); | ^ diff --git a/tests/ui/traits/new-solver/canonicalize-effect-var.rs b/tests/ui/traits/new-solver/canonicalize-effect-var.rs new file mode 100644 index 00000000000..35b69ed1a6b --- /dev/null +++ b/tests/ui/traits/new-solver/canonicalize-effect-var.rs @@ -0,0 +1,22 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(effects)] +#![feature(const_trait_impl)] + +#[const_trait] +trait Foo { + fn foo(); +} + +trait Bar {} + +impl const Foo for i32 { + fn foo() {} +} + +impl<T> const Foo for T where T: Bar { + fn foo() {} +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/dont-ice-on-assoc-projection.rs b/tests/ui/traits/new-solver/dont-ice-on-assoc-projection.rs new file mode 100644 index 00000000000..b9798c79d5e --- /dev/null +++ b/tests/ui/traits/new-solver/dont-ice-on-assoc-projection.rs @@ -0,0 +1,19 @@ +// compile-flags: -Ztrait-solver=next-coherence + +// Makes sure we don't ICE on associated const projection when the feature gate +// is not enabled, since we should avoid encountering ICEs on stable if possible. + +trait Bar { + const ASSOC: usize; +} +impl Bar for () { + const ASSOC: usize = 1; +} + +trait Foo {} +impl Foo for () {} +impl<T> Foo for T where T: Bar<ASSOC = 0> {} +//~^ ERROR associated const equality is incomplete +//~| ERROR conflicting implementations of trait `Foo` for type `()` + +fn main() {} diff --git a/tests/ui/traits/new-solver/dont-ice-on-assoc-projection.stderr b/tests/ui/traits/new-solver/dont-ice-on-assoc-projection.stderr new file mode 100644 index 00000000000..7ad495a35e0 --- /dev/null +++ b/tests/ui/traits/new-solver/dont-ice-on-assoc-projection.stderr @@ -0,0 +1,21 @@ +error[E0658]: associated const equality is incomplete + --> $DIR/dont-ice-on-assoc-projection.rs:15:32 + | +LL | impl<T> Foo for T where T: Bar<ASSOC = 0> {} + | ^^^^^^^^^ + | + = note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information + = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable + +error[E0119]: conflicting implementations of trait `Foo` for type `()` + --> $DIR/dont-ice-on-assoc-projection.rs:15:1 + | +LL | impl Foo for () {} + | --------------- first implementation here +LL | impl<T> Foo for T where T: Bar<ASSOC = 0> {} + | ^^^^^^^^^^^^^^^^^ conflicting implementation for `()` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0119, E0658. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs new file mode 100644 index 00000000000..539c9614e82 --- /dev/null +++ b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs @@ -0,0 +1,12 @@ +//~ ERROR overflow evaluating the requirement `Self well-formed` +//~| ERROR overflow evaluating the requirement `Self: Trait` + +// This is a non-regression test for issue #115351, where a recursion limit of 0 caused an ICE. +// compile-flags: -Ztrait-solver=next --crate-type=lib +// check-fail + +#![recursion_limit = "0"] +trait Trait {} +impl Trait for u32 {} +//~^ ERROR overflow evaluating the requirement `u32: Trait` +//~| ERROR overflow evaluating the requirement `u32 well-formed` diff --git a/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr new file mode 100644 index 00000000000..16b25d90ace --- /dev/null +++ b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr @@ -0,0 +1,27 @@ +error[E0275]: overflow evaluating the requirement `Self: Trait` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error[E0275]: overflow evaluating the requirement `Self well-formed` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error[E0275]: overflow evaluating the requirement `u32: Trait` + --> $DIR/recursion-limit-zero-issue-115351.rs:10:16 + | +LL | impl Trait for u32 {} + | ^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error[E0275]: overflow evaluating the requirement `u32 well-formed` + --> $DIR/recursion-limit-zero-issue-115351.rs:10:16 + | +LL | impl Trait for u32 {} + | ^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/new-solver/projection-discr-kind.stderr b/tests/ui/traits/new-solver/projection-discr-kind.stderr index 03e28f993e2..e14953f19ff 100644 --- a/tests/ui/traits/new-solver/projection-discr-kind.stderr +++ b/tests/ui/traits/new-solver/projection-discr-kind.stderr @@ -6,6 +6,11 @@ LL | needs_bar(std::mem::discriminant(&x)); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/projection-discr-kind.rs:10:1 + | +LL | trait Bar {} + | ^^^^^^^^^ note: required by a bound in `needs_bar` --> $DIR/projection-discr-kind.rs:11:22 | diff --git a/tests/ui/traits/non_lifetime_binders/fail.stderr b/tests/ui/traits/non_lifetime_binders/fail.stderr index 7bd02550fb3..240bcef7df5 100644 --- a/tests/ui/traits/non_lifetime_binders/fail.stderr +++ b/tests/ui/traits/non_lifetime_binders/fail.stderr @@ -13,6 +13,11 @@ error[E0277]: the trait bound `T: Trait` is not satisfied LL | fail(); | ^^^^ the trait `Trait` is not implemented for `T` | +help: this trait has no implementations, consider adding one + --> $DIR/fail.rs:6:1 + | +LL | trait Trait {} + | ^^^^^^^^^^^ note: required by a bound in `fail` --> $DIR/fail.rs:10:15 | diff --git a/tests/ui/traits/object-does-not-impl-trait.stderr b/tests/ui/traits/object-does-not-impl-trait.stderr index f1dd508a467..81d67255a0b 100644 --- a/tests/ui/traits/object-does-not-impl-trait.stderr +++ b/tests/ui/traits/object-does-not-impl-trait.stderr @@ -6,6 +6,11 @@ LL | fn take_object(f: Box<dyn Foo>) { take_foo(f); } | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/object-does-not-impl-trait.rs:4:1 + | +LL | trait Foo {} + | ^^^^^^^^^ note: required by a bound in `take_foo` --> $DIR/object-does-not-impl-trait.rs:5:15 | diff --git a/tests/ui/traits/object/enforce-supertrait-projection.rs b/tests/ui/traits/object/enforce-supertrait-projection.rs index 2c9b41eea2a..0ea944ec2df 100644 --- a/tests/ui/traits/object/enforce-supertrait-projection.rs +++ b/tests/ui/traits/object/enforce-supertrait-projection.rs @@ -7,7 +7,7 @@ trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {} fn transmute<A, B>(x: A) -> B { foo::<A, B, dyn Trait<A = A, B = B>>(x) - //~^ ERROR type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B` + //~^ ERROR type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B` } fn foo<A, B, T: ?Sized>(x: T::A) -> B diff --git a/tests/ui/traits/object/enforce-supertrait-projection.stderr b/tests/ui/traits/object/enforce-supertrait-projection.stderr index 848b4e69a4b..2fb94d34896 100644 --- a/tests/ui/traits/object/enforce-supertrait-projection.stderr +++ b/tests/ui/traits/object/enforce-supertrait-projection.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B` +error[E0271]: type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B` --> $DIR/enforce-supertrait-projection.rs:9:17 | LL | fn transmute<A, B>(x: A) -> B { diff --git a/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs index 206ab07898b..d37943b929a 100644 --- a/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs +++ b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs @@ -1,3 +1,4 @@ +//~ ERROR overflow // A regression test for #111729 checking that we correctly // track recursion depth for obligations returned by confirmation. use std::panic::RefUnwindSafe; @@ -14,7 +15,6 @@ struct RootDatabase { } impl<T: RefUnwindSafe> Database for T { - //~^ ERROR overflow type Storage = SalsaStorage; } impl Database for RootDatabase { diff --git a/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr index 4123a8199a0..8f9ce3ef1e9 100644 --- a/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr +++ b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr @@ -1,17 +1,13 @@ error[E0275]: overflow evaluating the requirement `Runtime<RootDatabase>: RefUnwindSafe` - --> $DIR/cycle-via-builtin-auto-trait-impl.rs:16:9 - | -LL | impl<T: RefUnwindSafe> Database for T { - | ^^^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`cycle_via_builtin_auto_trait_impl`) note: required because it appears within the type `RootDatabase` - --> $DIR/cycle-via-builtin-auto-trait-impl.rs:12:8 + --> $DIR/cycle-via-builtin-auto-trait-impl.rs:13:8 | LL | struct RootDatabase { | ^^^^^^^^^^^^ note: required for `RootDatabase` to implement `Database` - --> $DIR/cycle-via-builtin-auto-trait-impl.rs:16:24 + --> $DIR/cycle-via-builtin-auto-trait-impl.rs:17:24 | LL | impl<T: RefUnwindSafe> Database for T { | ------------- ^^^^^^^^ ^ diff --git a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs new file mode 100644 index 00000000000..c6f9e345618 --- /dev/null +++ b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs @@ -0,0 +1,15 @@ +fn use_iterator<I>(itr: I) +where + I: IntoIterator<Item = i32>, +{ +} + +fn pass_iterator<I>(i: &dyn IntoIterator<Item = i32, IntoIter = I>) +where + I: Iterator<Item = i32>, +{ + use_iterator(i); + //~^ ERROR `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator +} + +fn main() {} diff --git a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr new file mode 100644 index 00000000000..bd0e7ca2c02 --- /dev/null +++ b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr @@ -0,0 +1,22 @@ +error[E0277]: `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator + --> $DIR/dont-suggest-unsize-deref.rs:11:18 + | +LL | use_iterator(i); + | ------------ ^ `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator + | | + | required by a bound introduced by this call + | + = help: the trait `Iterator` is not implemented for `&dyn IntoIterator<IntoIter = I, Item = i32>` + = note: required for `&dyn IntoIterator<IntoIter = I, Item = i32>` to implement `IntoIterator` +note: required by a bound in `use_iterator` + --> $DIR/dont-suggest-unsize-deref.rs:3:8 + | +LL | fn use_iterator<I>(itr: I) + | ------------ required by a bound in this function +LL | where +LL | I: IntoIterator<Item = i32>, + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `use_iterator` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/suggest-deferences/issue-39029.fixed b/tests/ui/traits/suggest-dereferences/issue-39029.fixed index a1abf668b8b..a1abf668b8b 100644 --- a/tests/ui/traits/suggest-deferences/issue-39029.fixed +++ b/tests/ui/traits/suggest-dereferences/issue-39029.fixed diff --git a/tests/ui/traits/suggest-deferences/issue-39029.rs b/tests/ui/traits/suggest-dereferences/issue-39029.rs index 90d097105ed..90d097105ed 100644 --- a/tests/ui/traits/suggest-deferences/issue-39029.rs +++ b/tests/ui/traits/suggest-dereferences/issue-39029.rs diff --git a/tests/ui/traits/suggest-deferences/issue-39029.stderr b/tests/ui/traits/suggest-dereferences/issue-39029.stderr index 49105de3d69..49105de3d69 100644 --- a/tests/ui/traits/suggest-deferences/issue-39029.stderr +++ b/tests/ui/traits/suggest-dereferences/issue-39029.stderr diff --git a/tests/ui/traits/suggest-deferences/issue-62530.fixed b/tests/ui/traits/suggest-dereferences/issue-62530.fixed index 406caaa007f..406caaa007f 100644 --- a/tests/ui/traits/suggest-deferences/issue-62530.fixed +++ b/tests/ui/traits/suggest-dereferences/issue-62530.fixed diff --git a/tests/ui/traits/suggest-deferences/issue-62530.rs b/tests/ui/traits/suggest-dereferences/issue-62530.rs index 53846be7306..53846be7306 100644 --- a/tests/ui/traits/suggest-deferences/issue-62530.rs +++ b/tests/ui/traits/suggest-dereferences/issue-62530.rs diff --git a/tests/ui/traits/suggest-deferences/issue-62530.stderr b/tests/ui/traits/suggest-dereferences/issue-62530.stderr index e47ae0b65af..e47ae0b65af 100644 --- a/tests/ui/traits/suggest-deferences/issue-62530.stderr +++ b/tests/ui/traits/suggest-dereferences/issue-62530.stderr diff --git a/tests/ui/traits/suggest-deferences/multiple-0.fixed b/tests/ui/traits/suggest-dereferences/multiple-0.fixed index b7160b75c60..b7160b75c60 100644 --- a/tests/ui/traits/suggest-deferences/multiple-0.fixed +++ b/tests/ui/traits/suggest-dereferences/multiple-0.fixed diff --git a/tests/ui/traits/suggest-deferences/multiple-0.rs b/tests/ui/traits/suggest-dereferences/multiple-0.rs index 9ac55177ffa..9ac55177ffa 100644 --- a/tests/ui/traits/suggest-deferences/multiple-0.rs +++ b/tests/ui/traits/suggest-dereferences/multiple-0.rs diff --git a/tests/ui/traits/suggest-deferences/multiple-0.stderr b/tests/ui/traits/suggest-dereferences/multiple-0.stderr index 6a4d4b8d521..6a4d4b8d521 100644 --- a/tests/ui/traits/suggest-deferences/multiple-0.stderr +++ b/tests/ui/traits/suggest-dereferences/multiple-0.stderr diff --git a/tests/ui/traits/suggest-deferences/multiple-1.rs b/tests/ui/traits/suggest-dereferences/multiple-1.rs index 91c6c7924a4..91c6c7924a4 100644 --- a/tests/ui/traits/suggest-deferences/multiple-1.rs +++ b/tests/ui/traits/suggest-dereferences/multiple-1.rs diff --git a/tests/ui/traits/suggest-deferences/multiple-1.stderr b/tests/ui/traits/suggest-dereferences/multiple-1.stderr index 6e12321c233..6e12321c233 100644 --- a/tests/ui/traits/suggest-deferences/multiple-1.stderr +++ b/tests/ui/traits/suggest-dereferences/multiple-1.stderr diff --git a/tests/ui/traits/suggest-deferences/root-obligation.fixed b/tests/ui/traits/suggest-dereferences/root-obligation.fixed index 7a8433f9057..7a8433f9057 100644 --- a/tests/ui/traits/suggest-deferences/root-obligation.fixed +++ b/tests/ui/traits/suggest-dereferences/root-obligation.fixed diff --git a/tests/ui/traits/suggest-deferences/root-obligation.rs b/tests/ui/traits/suggest-dereferences/root-obligation.rs index 51bac2107e3..51bac2107e3 100644 --- a/tests/ui/traits/suggest-deferences/root-obligation.rs +++ b/tests/ui/traits/suggest-dereferences/root-obligation.rs diff --git a/tests/ui/traits/suggest-deferences/root-obligation.stderr b/tests/ui/traits/suggest-dereferences/root-obligation.stderr index 1363fb8c47a..1363fb8c47a 100644 --- a/tests/ui/traits/suggest-deferences/root-obligation.stderr +++ b/tests/ui/traits/suggest-dereferences/root-obligation.stderr diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.fixed index ea3d1bf853a..ea3d1bf853a 100644 --- a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed +++ b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.fixed diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs index 9eda68027b2..9eda68027b2 100644 --- a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs +++ b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.stderr index ede31a2c7bc..ede31a2c7bc 100644 --- a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr +++ b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.stderr diff --git a/tests/ui/traits/vtable-res-trait-param.stderr b/tests/ui/traits/vtable-res-trait-param.stderr index 2b3e3de9b1a..4cfceefb24c 100644 --- a/tests/ui/traits/vtable-res-trait-param.stderr +++ b/tests/ui/traits/vtable-res-trait-param.stderr @@ -6,6 +6,11 @@ LL | b.gimme_an_a(y) | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/vtable-res-trait-param.rs:1:1 + | +LL | trait TraitA { + | ^^^^^^^^^^^^ note: required by a bound in `TraitB::gimme_an_a` --> $DIR/vtable-res-trait-param.rs:6:21 | diff --git a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs index 546fcbaa3de..b6129163333 100644 --- a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs +++ b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs @@ -1,3 +1,5 @@ +// check-pass + //! If visibility is assumed, a transmutation should be accepted even if the //! destination type contains an unreachable field (e.g., a public field with a //! private type). (This rule is distinct from type privacy, which still may @@ -29,7 +31,7 @@ mod dst { #[repr(C)] pub(self) struct Zst; // <- unreachable type #[repr(C)] pub(in super) struct Dst { - pub(in super) field: Zst, //~ ERROR private type + pub(in super) field: Zst, //~ WARNING type `dst::Zst` is more private than the item `Dst::field` } } diff --git a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr index be83b7ce33f..80099388d63 100644 --- a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr +++ b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr @@ -1,12 +1,15 @@ -error[E0446]: private type `dst::Zst` in public interface - --> $DIR/should_accept_if_dst_has_unreachable_field.rs:32:9 +warning: type `dst::Zst` is more private than the item `Dst::field` + --> $DIR/should_accept_if_dst_has_unreachable_field.rs:34:9 | -LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type - | -------------------- `dst::Zst` declared as private -... LL | pub(in super) field: Zst, - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^ field `Dst::field` is reachable at visibility `pub(crate)` + | +note: but type `dst::Zst` is only usable at visibility `pub(self)` + --> $DIR/should_accept_if_dst_has_unreachable_field.rs:31:16 + | +LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type + | ^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default -error: aborting due to previous error +warning: 1 warning emitted -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs index 9c8345a8e91..e7742058c57 100644 --- a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs +++ b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs @@ -1,3 +1,5 @@ +// check-pass + //! The presence of an unreachable field in the source type (e.g., a public //! field with a private type does not affect transmutability. (This rule is //! distinct from type privacy, which still may forbid naming such types.) @@ -19,7 +21,7 @@ mod src { #[repr(C)] pub(self) struct Zst; // <- unreachable type #[repr(C)] pub(in super) struct Src { - pub(in super) field: Zst, //~ ERROR private type + pub(in super) field: Zst, //~ WARNING type `src::Zst` is more private than the item `Src::field` } } diff --git a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr index 39b73302e36..55fb3392305 100644 --- a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr +++ b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr @@ -1,12 +1,15 @@ -error[E0446]: private type `src::Zst` in public interface - --> $DIR/should_accept_if_src_has_unreachable_field.rs:22:9 +warning: type `src::Zst` is more private than the item `Src::field` + --> $DIR/should_accept_if_src_has_unreachable_field.rs:24:9 | -LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type - | -------------------- `src::Zst` declared as private -... LL | pub(in super) field: Zst, - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^ field `Src::field` is reachable at visibility `pub(crate)` + | +note: but type `src::Zst` is only usable at visibility `pub(self)` + --> $DIR/should_accept_if_src_has_unreachable_field.rs:21:16 + | +LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type + | ^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default -error: aborting due to previous error +warning: 1 warning emitted -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/transmute/issue-115402-overflow-size.rs b/tests/ui/transmute/issue-115402-overflow-size.rs new file mode 100644 index 00000000000..91168041ed6 --- /dev/null +++ b/tests/ui/transmute/issue-115402-overflow-size.rs @@ -0,0 +1,27 @@ +#![crate_type = "lib"] +#![feature(transmutability)] +mod assert { + use std::mem::BikeshedIntrinsicFrom; + struct Context; + + pub fn is_maybe_transmutable<Src, Dst>() + where + Dst: BikeshedIntrinsicFrom<Src, Context>, + { + } +} + +fn main() { + pub union Uninit { + a: [u8; usize::MAX], + } + + #[repr(C)] + struct ExplicitlyPadded(Uninit); + + assert::is_maybe_transmutable::<(), ExplicitlyPadded>(); + //~^ ERROR `()` cannot be safely transmuted into `ExplicitlyPadded` + + assert::is_maybe_transmutable::<ExplicitlyPadded, ()>(); + //~^ ERROR `ExplicitlyPadded` cannot be safely transmuted into `()` +} diff --git a/tests/ui/transmute/issue-115402-overflow-size.stderr b/tests/ui/transmute/issue-115402-overflow-size.stderr new file mode 100644 index 00000000000..08d180f6427 --- /dev/null +++ b/tests/ui/transmute/issue-115402-overflow-size.stderr @@ -0,0 +1,33 @@ +error[E0277]: `()` cannot be safely transmuted into `ExplicitlyPadded` in the defining scope of `assert::Context` + --> $DIR/issue-115402-overflow-size.rs:22:41 + | +LL | assert::is_maybe_transmutable::<(), ExplicitlyPadded>(); + | ^^^^^^^^^^^^^^^^ values of the type `ExplicitlyPadded` are too big for the current architecture + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/issue-115402-overflow-size.rs:9:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +LL | where +LL | Dst: BikeshedIntrinsicFrom<Src, Context>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable` + +error[E0277]: `ExplicitlyPadded` cannot be safely transmuted into `()` in the defining scope of `assert::Context` + --> $DIR/issue-115402-overflow-size.rs:25:55 + | +LL | assert::is_maybe_transmutable::<ExplicitlyPadded, ()>(); + | ^^ values of the type `ExplicitlyPadded` are too big for the current architecture + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/issue-115402-overflow-size.rs:9:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +LL | where +LL | Dst: BikeshedIntrinsicFrom<Src, Context>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/trivial-bounds/trivial-bounds-leak.stderr b/tests/ui/trivial-bounds/trivial-bounds-leak.stderr index 02c5d5d2484..be472a50769 100644 --- a/tests/ui/trivial-bounds/trivial-bounds-leak.stderr +++ b/tests/ui/trivial-bounds/trivial-bounds-leak.stderr @@ -27,6 +27,12 @@ LL | Foo::test(&4i32); | --------- ^^^^^ the trait `Foo` is not implemented for `i32` | | | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/trivial-bounds-leak.rs:4:1 + | +LL | pub trait Foo { + | ^^^^^^^^^^^^^ error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/trivial-bounds-leak.rs:26:22 @@ -36,6 +42,11 @@ LL | generic_function(5i32); | | | required by a bound introduced by this call | +help: this trait has no implementations, consider adding one + --> $DIR/trivial-bounds-leak.rs:4:1 + | +LL | pub trait Foo { + | ^^^^^^^^^^^^^ note: required by a bound in `generic_function` --> $DIR/trivial-bounds-leak.rs:29:24 | diff --git a/tests/ui/issues/issue-32709.rs b/tests/ui/try-trait/issue-32709.rs index c05bfdc4cfd..c05bfdc4cfd 100644 --- a/tests/ui/issues/issue-32709.rs +++ b/tests/ui/try-trait/issue-32709.rs diff --git a/tests/ui/issues/issue-32709.stderr b/tests/ui/try-trait/issue-32709.stderr index 94e8f9295fd..94e8f9295fd 100644 --- a/tests/ui/issues/issue-32709.stderr +++ b/tests/ui/try-trait/issue-32709.stderr diff --git a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs index 5f75fdc716e..4f424b8c665 100644 --- a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs +++ b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs @@ -1,11 +1,7 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type OneLifetime<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type OneLifetime<'a, 'b> = impl std::fmt::Debug; fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> { a diff --git a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr index 546598e8a5c..0c50a84e894 100644 --- a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr +++ b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_lifetimes_defining_uses.rs:15:5 + --> $DIR/different_lifetimes_defining_uses.rs:11:5 | LL | b | ^ expected `&'a u32`, got `&'b u32` | note: previous use here - --> $DIR/different_lifetimes_defining_uses.rs:11:5 + --> $DIR/different_lifetimes_defining_uses.rs:7:5 | LL | a | ^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs index 14ced341854..169d4f8d509 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs @@ -2,11 +2,7 @@ fn main() {} -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type Two<'a, 'b> = impl std::fmt::Debug; fn one<'a>(t: &'a ()) -> Two<'a, 'a> { //~^ ERROR non-defining opaque type use diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr index 4da69a705c0..b03bf2466e6 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr @@ -1,25 +1,25 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:11:26 + --> $DIR/generic_duplicate_lifetime_param.rs:7:26 | LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> { | ^^^^^^^^^^^ generic argument `'a` used twice | note: for this opaque type - --> $DIR/generic_duplicate_lifetime_param.rs:9:20 + --> $DIR/generic_duplicate_lifetime_param.rs:5:20 | -LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type Two<'a, 'b> = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:13:5 + --> $DIR/generic_duplicate_lifetime_param.rs:9:5 | LL | t | ^ | note: lifetime used multiple times - --> $DIR/generic_duplicate_lifetime_param.rs:9:10 + --> $DIR/generic_duplicate_lifetime_param.rs:5:10 | -LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +LL | type Two<'a, 'b> = impl std::fmt::Debug; | ^^ ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs index 1e391b55a4f..e3c6f4d874b 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs @@ -14,11 +14,7 @@ fn main() {} // test that unused generic parameters are ok type TwoTys<T, U> = impl Debug; -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; +type TwoLifetimes<'a, 'b> = impl Debug; type TwoConsts<const X: usize, const Y: usize> = impl Debug; diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr index d8330771d30..495308a6cac 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -1,5 +1,5 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:25:30 + --> $DIR/generic_duplicate_param_use.rs:21:30 | LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> { | ^^^^^^^^^^^^ generic argument `T` used twice @@ -11,7 +11,7 @@ LL | type TwoTys<T, U> = impl Debug; | ^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:27:5 + --> $DIR/generic_duplicate_param_use.rs:23:5 | LL | t | ^ @@ -23,49 +23,49 @@ LL | type TwoTys<T, U> = impl Debug; | ^ ^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:31:36 + --> $DIR/generic_duplicate_param_use.rs:27:36 | LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { | ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice | note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:21:29 + --> $DIR/generic_duplicate_param_use.rs:17:29 | -LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type TwoLifetimes<'a, 'b> = impl Debug; + | ^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:33:5 + --> $DIR/generic_duplicate_param_use.rs:29:5 | LL | t | ^ | note: lifetime used multiple times - --> $DIR/generic_duplicate_param_use.rs:21:19 + --> $DIR/generic_duplicate_param_use.rs:17:19 | -LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; +LL | type TwoLifetimes<'a, 'b> = impl Debug; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:37:50 + --> $DIR/generic_duplicate_param_use.rs:33:50 | LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> { | ^^^^^^^^^^^^^^^ generic argument `N` used twice | note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:23:50 + --> $DIR/generic_duplicate_param_use.rs:19:50 | LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug; | ^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:39:5 + --> $DIR/generic_duplicate_param_use.rs:35:5 | LL | t | ^ | note: constant used multiple times - --> $DIR/generic_duplicate_param_use.rs:23:16 + --> $DIR/generic_duplicate_param_use.rs:19:16 | LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug; | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs index 106efefbaf2..e109c38c986 100644 --- a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs @@ -1,11 +1,10 @@ -// check-pass +// build-pass (FIXME(62277): could be check-pass?) #![feature(type_alias_impl_trait)] fn main() {} -type Region<'a> = impl std::fmt::Debug + 'a; - +type Region<'a> = impl std::fmt::Debug; fn region<'b>(a: &'b ()) -> Region<'b> { a diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs index 6f9434255a8..469a493b0b3 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs @@ -1,7 +1,7 @@ #![feature(type_alias_impl_trait)] mod test_lifetime_param { - type Ty<'a> = impl Sized + 'a; + type Ty<'a> = impl Sized; fn defining(a: &str) -> Ty<'_> { a } fn assert_static<'a: 'static>() {} fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } @@ -9,7 +9,7 @@ mod test_lifetime_param { } mod test_higher_kinded_lifetime_param { - type Ty<'a> = impl Sized + 'a; + type Ty<'a> = impl Sized; fn defining(a: &str) -> Ty<'_> { a } fn assert_static<'a: 'static>() {} fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } diff --git a/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs b/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs index 4f99236f4ea..06c119287d7 100644 --- a/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs +++ b/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs @@ -1,16 +1,20 @@ // check-pass -#![feature(impl_trait_in_assoc_type)] +#![feature(impl_trait_in_assoc_type, type_alias_impl_trait)] -trait Callable { - type Output; - fn call() -> Self::Output; -} +mod foo { + pub trait Callable { + type Output; + fn call() -> Self::Output; + } -impl<'a> Callable for &'a () { - type Output = impl Sized; - fn call() -> Self::Output {} + pub type OutputHelper = impl Sized; + impl<'a> Callable for &'a () { + type Output = OutputHelper; + fn call() -> Self::Output {} + } } +use foo::*; fn test<'a>() -> impl Sized { <&'a () as Callable>::call() diff --git a/tests/ui/type-alias-impl-trait/issue-89686.rs b/tests/ui/type-alias-impl-trait/issue-89686.rs index 058417bdb80..de070fc9deb 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.rs +++ b/tests/ui/type-alias-impl-trait/issue-89686.rs @@ -4,7 +4,7 @@ use std::future::Future; -type G<'a, T> = impl Future<Output = ()> + 'a; +type G<'a, T> = impl Future<Output = ()>; trait Trait { type F: Future<Output = ()>; diff --git a/tests/ui/type-alias-impl-trait/issue-89686.stderr b/tests/ui/type-alias-impl-trait/issue-89686.stderr index 3b95a575ac2..b636ada8b75 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.stderr +++ b/tests/ui/type-alias-impl-trait/issue-89686.stderr @@ -6,7 +6,7 @@ LL | async move { self.f().await } | help: consider restricting type parameter `T` | -LL | type G<'a, T: Trait> = impl Future<Output = ()> + 'a; +LL | type G<'a, T: Trait> = impl Future<Output = ()>; | +++++++ error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs index 01d1f5db132..c584a58cb32 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs @@ -1,7 +1,8 @@ #![feature(type_alias_impl_trait)] -type Opaque<'a, T> = impl Sized; +type Opaque2<T> = impl Sized; +type Opaque<'a, T> = Opaque2<T>; fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x } -//~^ ERROR: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds +//~^ ERROR: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds fn main() {} diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr index d666e668d36..6bcae6e5316 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr @@ -1,8 +1,9 @@ -error[E0700]: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds - --> $DIR/missing_lifetime_bound.rs:4:47 +error[E0700]: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds + --> $DIR/missing_lifetime_bound.rs:5:47 | -LL | type Opaque<'a, T> = impl Sized; - | ---------- opaque type defined here +LL | type Opaque2<T> = impl Sized; + | ---------- opaque type defined here +LL | type Opaque<'a, T> = Opaque2<T>; LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x } | -- ^ | | diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs index 65eb2952e0f..3f122f10609 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs @@ -1,10 +1,6 @@ #![feature(type_alias_impl_trait)] -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type Foo<'a, 'b> = impl std::fmt::Debug; fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, i) //~ ERROR concrete type differs from previous diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr index d7676b8e9b1..81e603e2355 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr @@ -1,5 +1,5 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:10:5 + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | LL | (i, i) | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs index 21fca047a3c..83fd9a1da45 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs @@ -7,11 +7,7 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) (a.clone(), a) } -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type Foo<'a, 'b> = impl std::fmt::Debug; fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, j) diff --git a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs index 4a9631a7208..ba705d6f85a 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs @@ -8,7 +8,7 @@ fn without_lt() -> impl for<'a> Trait<'a, Assoc = WithoutLt> {} //~^ ERROR captures lifetime that does not appear in bounds type WithLt<'a> = impl Sized + 'a; -//~^ ERROR concrete type differs from previous defining opaque type use + fn with_lt() -> impl for<'a> Trait<'a, Assoc = WithLt<'a>> {} //~^ ERROR expected generic lifetime parameter, found `'a` diff --git a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr index 9a783a6d92a..f208730552d 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr @@ -17,19 +17,7 @@ LL | LL | fn with_lt() -> impl for<'a> Trait<'a, Assoc = WithLt<'a>> {} | ^^ -error: concrete type differs from previous defining opaque type use - --> $DIR/nested-tait-hrtb.rs:10:19 - | -LL | type WithLt<'a> = impl Sized + 'a; - | ^^^^^^^^^^^^^^^ expected `&'a str`, got `{type error}` - | -note: previous use here - --> $DIR/nested-tait-hrtb.rs:12:17 - | -LL | fn with_lt() -> impl for<'a> Trait<'a, Assoc = WithLt<'a>> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0700, E0792. For more information about an error, try `rustc --explain E0700`. diff --git a/tests/ui/type-alias-impl-trait/privacy.rs b/tests/ui/type-alias-impl-trait/privacy.rs index aa092f6f8ec..3efbfaf0916 100644 --- a/tests/ui/type-alias-impl-trait/privacy.rs +++ b/tests/ui/type-alias-impl-trait/privacy.rs @@ -1,8 +1,10 @@ +// check-pass + #![feature(type_alias_impl_trait)] type Foo = (impl Sized, u8); pub fn foo() -> Foo { - //~^ ERROR private type alias `Foo` in public interface + //~^ WARNING type alias `Foo` is more private than the item `foo` (42, 42) } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/privacy.stderr b/tests/ui/type-alias-impl-trait/privacy.stderr index e8c6039cdc8..50870905c30 100644 --- a/tests/ui/type-alias-impl-trait/privacy.stderr +++ b/tests/ui/type-alias-impl-trait/privacy.stderr @@ -1,11 +1,15 @@ -error[E0446]: private type alias `Foo` in public interface - --> $DIR/privacy.rs:4:1 +warning: type alias `Foo` is more private than the item `foo` + --> $DIR/privacy.rs:6:1 | -LL | type Foo = (impl Sized, u8); - | -------- `Foo` declared as private LL | pub fn foo() -> Foo { - | ^^^^^^^^^^^^^^^^^^^ can't leak private type alias + | ^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub` + | +note: but type alias `Foo` is only usable at visibility `pub(crate)` + --> $DIR/privacy.rs:5:1 + | +LL | type Foo = (impl Sized, u8); + | ^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default -error: aborting due to previous error +warning: 1 warning emitted -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs new file mode 100644 index 00000000000..eefe333da45 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs @@ -0,0 +1,25 @@ +//! This tries to prove the APIT's bounds in a canonical query, +//! which doesn't know anything about the defining scope of either +//! opaque type and thus makes a random choice as to which opaque type +//! becomes the hidden type of the other. When we leave the canonical +//! query, we attempt to actually check the defining anchor, but now we +//! have a situation where the RPIT gets constrained outside its anchor. + +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(type_alias_impl_trait)] + +type Opaque = impl Sized; + +fn get_rpit() -> impl Clone {} + +fn query(_: impl FnOnce() -> Opaque) {} + +fn test() -> Opaque { + query(get_rpit); + get_rpit() +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/self_implication.rs b/tests/ui/type-alias-impl-trait/self_implication.rs index 4e805ee308f..65659a0f3b1 100644 --- a/tests/ui/type-alias-impl-trait/self_implication.rs +++ b/tests/ui/type-alias-impl-trait/self_implication.rs @@ -22,9 +22,9 @@ fn bar() { } // desugared - type FooX<'a> = impl Sized; + type FooX = impl Sized; impl<'a> Foo<'a> { - fn foo(&self) -> FooX<'a> {} + fn foo(&self) -> FooX {} } // use site diff --git a/tests/ui/type-alias-impl-trait/variance.rs b/tests/ui/type-alias-impl-trait/variance.rs new file mode 100644 index 00000000000..eba4816003b --- /dev/null +++ b/tests/ui/type-alias-impl-trait/variance.rs @@ -0,0 +1,50 @@ +#![feature(rustc_attrs, type_alias_impl_trait, impl_trait_in_assoc_type)] +#![allow(internal_features)] +#![rustc_variance_of_opaques] + +trait Captures<'a> {} +impl<T> Captures<'_> for T {} + +type NotCapturedEarly<'a> = impl Sized; //~ [o] + +type CapturedEarly<'a> = impl Sized + Captures<'a>; //~ [o] + +type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>; //~ [o] + +type CapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'b>>; //~ [o] + +type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a> + Captures<'b>>; //~ [o] + +type Bar<'a, 'b: 'b, T> = impl Sized; //~ ERROR [o, o, o] + +trait Foo<'i> { + type ImplicitCapturedEarly<'a>; + + type ExplicitCaptureEarly<'a>; + + type ImplicitCaptureLate<'a>; + + type ExplicitCaptureLate<'a>; +} + +impl<'i> Foo<'i> for &'i () { + type ImplicitCapturedEarly<'a> = impl Sized; //~ [o, o] + + type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; //~ [o, o] + + type ImplicitCaptureLate<'a> = impl Sized; //~ [o, o] + + type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; //~ [o, o] +} + +impl<'i> Foo<'i> for () { + type ImplicitCapturedEarly<'a> = impl Sized; //~ [o, o] + + type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; //~ [o, o] + + type ImplicitCaptureLate<'a> = impl Sized; //~ [o, o] + + type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; //~ [o, o] +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/variance.stderr b/tests/ui/type-alias-impl-trait/variance.stderr new file mode 100644 index 00000000000..f73cf617a4c --- /dev/null +++ b/tests/ui/type-alias-impl-trait/variance.stderr @@ -0,0 +1,86 @@ +error: [o] + --> $DIR/variance.rs:8:29 + | +LL | type NotCapturedEarly<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:10:26 + | +LL | type CapturedEarly<'a> = impl Sized + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:12:56 + | +LL | type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>; + | ^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:14:53 + | +LL | type CapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'b>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:16:49 + | +LL | type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a> + Captures<'b>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o, o] + --> $DIR/variance.rs:18:27 + | +LL | type Bar<'a, 'b: 'b, T> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:31:38 + | +LL | type ImplicitCapturedEarly<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:33:37 + | +LL | type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:35:36 + | +LL | type ImplicitCaptureLate<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:37:36 + | +LL | type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:41:38 + | +LL | type ImplicitCapturedEarly<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:43:37 + | +LL | type ExplicitCaptureEarly<'a> = impl Sized + Captures<'i>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:45:36 + | +LL | type ImplicitCaptureLate<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:47:36 + | +LL | type ExplicitCaptureLate<'a> = impl Sized + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 14 previous errors + diff --git a/tests/ui/type/type-arg-out-of-scope.rs b/tests/ui/type/type-arg-out-of-scope.rs index 02aad007707..c36f9904e5d 100644 --- a/tests/ui/type/type-arg-out-of-scope.rs +++ b/tests/ui/type/type-arg-out-of-scope.rs @@ -1,4 +1,4 @@ -// error-pattern:can't use generic parameters from outer function +// error-pattern:can't use generic parameters from outer item fn foo<T>(x: T) { fn bar(f: Box<dyn FnMut(T) -> T>) { } } diff --git a/tests/ui/type/type-arg-out-of-scope.stderr b/tests/ui/type/type-arg-out-of-scope.stderr index 7f18b4510f4..8665001e243 100644 --- a/tests/ui/type/type-arg-out-of-scope.stderr +++ b/tests/ui/type/type-arg-out-of-scope.stderr @@ -1,22 +1,22 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/type-arg-out-of-scope.rs:3:29 | LL | fn foo<T>(x: T) { - | - type parameter from outer function + | - type parameter from outer item LL | fn bar(f: Box<dyn FnMut(T) -> T>) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<T>` + | help: try introducing a local generic parameter here: `<T>` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/type-arg-out-of-scope.rs:3:35 | LL | fn foo<T>(x: T) { - | - type parameter from outer function + | - type parameter from outer item LL | fn bar(f: Box<dyn FnMut(T) -> T>) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `<T>` + | help: try introducing a local generic parameter here: `<T>` error: aborting due to 2 previous errors diff --git a/tests/ui/typeck/issue-114918/const-in-fn-return-type.rs b/tests/ui/typeck/issue-114918/const-in-fn-return-type.rs new file mode 100644 index 00000000000..d939633290e --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-fn-return-type.rs @@ -0,0 +1,10 @@ +// Regression test for #114918 +// Test that a const generic enclosed in a block within a return type +// produces a type mismatch error instead of triggering a const eval cycle + +#[allow(unused_braces)] +fn func() -> [u8; { () } ] { //~ ERROR mismatched types + loop {} +} + +fn main() {} diff --git a/tests/ui/typeck/issue-114918/const-in-fn-return-type.stderr b/tests/ui/typeck/issue-114918/const-in-fn-return-type.stderr new file mode 100644 index 00000000000..88ed96e148c --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-fn-return-type.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/const-in-fn-return-type.rs:6:21 + | +LL | fn func() -> [u8; { () } ] { + | ^^ expected `usize`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs new file mode 100644 index 00000000000..a1b9a7eba4d --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs @@ -0,0 +1,20 @@ +// Regression test for #114918 +// Test that a const generic enclosed in a block within the return type +// of an impl fn produces a type mismatch error instead of triggering +// a const eval cycle + + +trait Trait { + fn func<const N: u32>() -> [ (); N ]; +} + +struct S {} + +#[allow(unused_braces)] +impl Trait for S { + fn func<const N: u32>() -> [ (); { () }] { //~ ERROR mismatched types + N + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.stderr b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.stderr new file mode 100644 index 00000000000..9843651b1e6 --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/const-in-impl-fn-return-type.rs:15:40 + | +LL | fn func<const N: u32>() -> [ (); { () }] { + | ^^ expected `usize`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-114918/const-in-struct-type-arg.rs b/tests/ui/typeck/issue-114918/const-in-struct-type-arg.rs new file mode 100644 index 00000000000..9eee4ab3d4c --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-struct-type-arg.rs @@ -0,0 +1,12 @@ +// Regression test for #114918 +// Test that a const generic enclosed in a block in a struct's type arg +// produces a type mismatch error instead of triggering a const eval cycle + +#[allow(unused_braces)] +struct S<const N: usize> { + arr: [u8; N] +} + +fn main() { + let s = S::<{ () }> { arr: [5, 6, 7]}; //~ ERROR mismatched types +} diff --git a/tests/ui/typeck/issue-114918/const-in-struct-type-arg.stderr b/tests/ui/typeck/issue-114918/const-in-struct-type-arg.stderr new file mode 100644 index 00000000000..3307e76d957 --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-struct-type-arg.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/const-in-struct-type-arg.rs:11:19 + | +LL | let s = S::<{ () }> { arr: [5, 6, 7]}; + | ^^ expected `usize`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-114918/const-in-trait-fn-return-type.rs b/tests/ui/typeck/issue-114918/const-in-trait-fn-return-type.rs new file mode 100644 index 00000000000..8e2eec34911 --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-trait-fn-return-type.rs @@ -0,0 +1,13 @@ +// Regression test for #114918 +// Test that a const generic enclosed in a block within the return type +// of a trait method produces a type mismatch error instead of triggering +// a const eval cycle + +#[allow(unused_braces)] +trait Trait { + fn func<const N: u32>() -> [ (); { () }] { //~ ERROR mismatched types + N + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-114918/const-in-trait-fn-return-type.stderr b/tests/ui/typeck/issue-114918/const-in-trait-fn-return-type.stderr new file mode 100644 index 00000000000..6bc0de77a62 --- /dev/null +++ b/tests/ui/typeck/issue-114918/const-in-trait-fn-return-type.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/const-in-trait-fn-return-type.rs:8:40 + | +LL | fn func<const N: u32>() -> [ (); { () }] { + | ^^ expected `usize`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/union/projection-as-union-type-error-2.stderr b/tests/ui/union/projection-as-union-type-error-2.stderr index bab226f271d..21f4ea103ad 100644 --- a/tests/ui/union/projection-as-union-type-error-2.stderr +++ b/tests/ui/union/projection-as-union-type-error-2.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `u8: NotImplemented` is not satisfied LL | a: <Foo as Identity>::Identity, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotImplemented` is not implemented for `u8` | +help: this trait has no implementations, consider adding one + --> $DIR/projection-as-union-type-error-2.rs:9:1 + | +LL | trait NotImplemented {} + | ^^^^^^^^^^^^^^^^^^^^ note: required for `u8` to implement `Identity` --> $DIR/projection-as-union-type-error-2.rs:11:25 | diff --git a/tests/ui/union/projection-as-union-type-error.stderr b/tests/ui/union/projection-as-union-type-error.stderr index e4fbe9603ad..2b0241caf98 100644 --- a/tests/ui/union/projection-as-union-type-error.stderr +++ b/tests/ui/union/projection-as-union-type-error.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `u8: Identity` is not satisfied | LL | a: <Foo as Identity>::Identity, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Identity` is not implemented for `u8` + | +help: this trait has no implementations, consider adding one + --> $DIR/projection-as-union-type-error.rs:6:1 + | +LL | pub trait Identity { + | ^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.rs b/tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.rs new file mode 100644 index 00000000000..a192f3445f7 --- /dev/null +++ b/tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.rs @@ -0,0 +1,17 @@ +// edition: 2024 +// compile-flags: -Zunstable-options +// check-pass + +#![crate_type = "lib"] + +#![deny(unused_unsafe)] + +unsafe fn unsf() {} + +unsafe fn foo() { + unsf(); + //~^ WARN call to unsafe function is unsafe and requires unsafe block + + // no unused_unsafe + unsafe { unsf(); } +} diff --git a/tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.stderr b/tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.stderr new file mode 100644 index 00000000000..fbc621f4d0e --- /dev/null +++ b/tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.stderr @@ -0,0 +1,16 @@ +warning: call to unsafe function is unsafe and requires unsafe block (error E0133) + --> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:12:5 + | +LL | unsf(); + | ^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on how to avoid undefined behavior +note: an unsafe function restricts its caller, but its body is safe by default + --> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:11:1 + | +LL | unsafe fn foo() { + | ^^^^^^^^^^^^^^^ + = note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/unsafe/initializing-ranged-via-ctor.rs b/tests/ui/unsafe/initializing-ranged-via-ctor.rs new file mode 100644 index 00000000000..ca44fa7e4e7 --- /dev/null +++ b/tests/ui/unsafe/initializing-ranged-via-ctor.rs @@ -0,0 +1,11 @@ +#![feature(rustc_attrs)] +#![allow(internal_features)] + +#[derive(Debug)] +#[rustc_layout_scalar_valid_range_start(2)] +struct NonZeroAndOneU8(u8); + +fn main() { + println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); + //~^ ERROR found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` +} diff --git a/tests/ui/unsafe/initializing-ranged-via-ctor.stderr b/tests/ui/unsafe/initializing-ranged-via-ctor.stderr new file mode 100644 index 00000000000..d34554c6641 --- /dev/null +++ b/tests/ui/unsafe/initializing-ranged-via-ctor.stderr @@ -0,0 +1,16 @@ +error[E0277]: expected a `FnOnce<({integer},)>` closure, found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` + --> $DIR/initializing-ranged-via-ctor.rs:9:34 + | +LL | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); + | --- ^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` + | | + | required by a bound introduced by this call + | + = help: the trait `FnOnce<({integer},)>` is not implemented for fn item `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` + = note: unsafe function cannot be called generically without an unsafe block +note: required by a bound in `Option::<T>::map` + --> $SRC_DIR/core/src/option.rs:LL:COL + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/unsafe/issue-115348-false-positive-warning-of-unnecessary-unsafe.rs b/tests/ui/unsafe/issue-115348-false-positive-warning-of-unnecessary-unsafe.rs new file mode 100644 index 00000000000..68559338d49 --- /dev/null +++ b/tests/ui/unsafe/issue-115348-false-positive-warning-of-unnecessary-unsafe.rs @@ -0,0 +1,16 @@ +// Regression test for #115348. + +unsafe fn uwu() {} + +// Tests that the false-positive warning "unnecessary `unsafe` block" +// should not be reported, when the error "non-exhaustive patterns" +// appears. + +fn foo(x: Option<u32>) { + match x { + //~^ ERROR non-exhaustive patterns: `None` not covered + Some(_) => unsafe { uwu() }, + } +} + +fn main() {} diff --git a/tests/ui/unsafe/issue-115348-false-positive-warning-of-unnecessary-unsafe.stderr b/tests/ui/unsafe/issue-115348-false-positive-warning-of-unnecessary-unsafe.stderr new file mode 100644 index 00000000000..7384899b978 --- /dev/null +++ b/tests/ui/unsafe/issue-115348-false-positive-warning-of-unnecessary-unsafe.stderr @@ -0,0 +1,21 @@ +error[E0004]: non-exhaustive patterns: `None` not covered + --> $DIR/issue-115348-false-positive-warning-of-unnecessary-unsafe.rs:10:11 + | +LL | match x { + | ^ pattern `None` not covered + | +note: `Option<u32>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<u32>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Some(_) => unsafe { uwu() }, +LL ~ None => todo!(), + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/unsafe/ranged-ctor-as-fn-ptr.rs b/tests/ui/unsafe/ranged-ctor-as-fn-ptr.rs new file mode 100644 index 00000000000..a91e579510d --- /dev/null +++ b/tests/ui/unsafe/ranged-ctor-as-fn-ptr.rs @@ -0,0 +1,10 @@ +#![feature(rustc_attrs)] + +#[derive(Debug)] +#[rustc_layout_scalar_valid_range_start(2)] +struct NonZeroAndOneU8(u8); + +fn main() { + let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; + //~^ ERROR mismatched types +} diff --git a/tests/ui/unsafe/ranged-ctor-as-fn-ptr.stderr b/tests/ui/unsafe/ranged-ctor-as-fn-ptr.stderr new file mode 100644 index 00000000000..660c4070451 --- /dev/null +++ b/tests/ui/unsafe/ranged-ctor-as-fn-ptr.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/ranged-ctor-as-fn-ptr.rs:8:40 + | +LL | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; + | ------------------------- ^^^^^^^^^^^^^^^ expected normal fn, found unsafe fn + | | + | expected due to this + | + = note: expected fn pointer `fn(_) -> NonZeroAndOneU8` + found struct constructor `unsafe fn(_) -> NonZeroAndOneU8 {NonZeroAndOneU8}` + = note: unsafe functions cannot be coerced into safe function pointers + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/unsized/issue-115203.rs b/tests/ui/unsized/issue-115203.rs new file mode 100644 index 00000000000..5fe7bd64288 --- /dev/null +++ b/tests/ui/unsized/issue-115203.rs @@ -0,0 +1,11 @@ +// compile-flags: --emit link + +fn main() { + let a: [i32; 0] = []; + match [a[..]] { + //~^ ERROR cannot move a value of type `[i32] + //~| ERROR cannot move out of type `[i32]`, a non-copy slice + [[]] => (), + _ => (), + } +} diff --git a/tests/ui/unsized/issue-115203.stderr b/tests/ui/unsized/issue-115203.stderr new file mode 100644 index 00000000000..3ee734988c5 --- /dev/null +++ b/tests/ui/unsized/issue-115203.stderr @@ -0,0 +1,19 @@ +error[E0161]: cannot move a value of type `[i32]` + --> $DIR/issue-115203.rs:5:12 + | +LL | match [a[..]] { + | ^^^^^ the size of `[i32]` cannot be statically determined + +error[E0508]: cannot move out of type `[i32]`, a non-copy slice + --> $DIR/issue-115203.rs:5:12 + | +LL | match [a[..]] { + | ^^^^^ + | | + | cannot move out of here + | move occurs because value has type `[i32]`, which does not implement the `Copy` trait + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0161, E0508. +For more information about an error, try `rustc --explain E0161`. diff --git a/tests/ui/unsized/issue-115809.rs b/tests/ui/unsized/issue-115809.rs new file mode 100644 index 00000000000..ff25365ea50 --- /dev/null +++ b/tests/ui/unsized/issue-115809.rs @@ -0,0 +1,13 @@ +// compile-flags: --emit=link -Zmir-opt-level=2 -Zpolymorphize=on + +fn foo<T>() { + let a: [i32; 0] = []; + match [a[..]] { + //~^ ERROR cannot move a value of type `[i32] + //~| ERROR cannot move out of type `[i32]`, a non-copy slice + [[x]] => {} + _ => (), + } +} + +fn main() {} diff --git a/tests/ui/unsized/issue-115809.stderr b/tests/ui/unsized/issue-115809.stderr new file mode 100644 index 00000000000..a92554b79b9 --- /dev/null +++ b/tests/ui/unsized/issue-115809.stderr @@ -0,0 +1,19 @@ +error[E0161]: cannot move a value of type `[i32]` + --> $DIR/issue-115809.rs:5:12 + | +LL | match [a[..]] { + | ^^^^^ the size of `[i32]` cannot be statically determined + +error[E0508]: cannot move out of type `[i32]`, a non-copy slice + --> $DIR/issue-115809.rs:5:12 + | +LL | match [a[..]] { + | ^^^^^ + | | + | cannot move out of here + | move occurs because value has type `[i32]`, which does not implement the `Copy` trait + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0161, E0508. +For more information about an error, try `rustc --explain E0161`. diff --git a/tests/ui/unsized/issue-75707.stderr b/tests/ui/unsized/issue-75707.stderr index 97618ed05ed..aa7f9c78fa8 100644 --- a/tests/ui/unsized/issue-75707.stderr +++ b/tests/ui/unsized/issue-75707.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `MyCall: Callback` is not satisfied LL | f::<dyn Processing<Call = MyCall>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Callback` is not implemented for `MyCall` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-75707.rs:1:1 + | +LL | pub trait Callback { + | ^^^^^^^^^^^^^^^^^^ note: required by a bound in `f` --> $DIR/issue-75707.rs:9:9 | diff --git a/tests/ui/wf/hir-wf-canonicalized.stderr b/tests/ui/wf/hir-wf-canonicalized.stderr index 9fd0f9c81eb..21122e37da5 100644 --- a/tests/ui/wf/hir-wf-canonicalized.stderr +++ b/tests/ui/wf/hir-wf-canonicalized.stderr @@ -3,12 +3,24 @@ error[E0277]: the trait bound `Bar<'a, T>: Foo` is not satisfied | LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<'a, T>` + | +help: this trait has no implementations, consider adding one + --> $DIR/hir-wf-canonicalized.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ error[E0277]: the trait bound `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied --> $DIR/hir-wf-canonicalized.rs:10:15 | LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)` + | +help: this trait has no implementations, consider adding one + --> $DIR/hir-wf-canonicalized.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ error[E0277]: the size for values of type `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time --> $DIR/hir-wf-canonicalized.rs:10:15 diff --git a/tests/ui/wf/issue-95665.stderr b/tests/ui/wf/issue-95665.stderr index b1cda59a916..f80cd41a4c2 100644 --- a/tests/ui/wf/issue-95665.stderr +++ b/tests/ui/wf/issue-95665.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `u8: Trait` is not satisfied LL | static VAR: Struct<u8>; | ^^^^^^^^^^ the trait `Trait` is not implemented for `u8` | +help: this trait has no implementations, consider adding one + --> $DIR/issue-95665.rs:4:1 + | +LL | pub trait Trait: {} + | ^^^^^^^^^^^^^^^ note: required by a bound in `Struct` --> $DIR/issue-95665.rs:6:22 | diff --git a/tests/ui/wf/wf-complex-assoc-type.stderr b/tests/ui/wf/wf-complex-assoc-type.stderr index ef613e3132d..6a623bec815 100644 --- a/tests/ui/wf/wf-complex-assoc-type.stderr +++ b/tests/ui/wf/wf-complex-assoc-type.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `bool: MyTrait` is not satisfied LL | type MyItem = Option<((AssertMyTrait<bool>, u8))>; | ^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `bool` | +help: this trait has no implementations, consider adding one + --> $DIR/wf-complex-assoc-type.rs:1:1 + | +LL | trait MyTrait {} + | ^^^^^^^^^^^^^ note: required by a bound in `AssertMyTrait` --> $DIR/wf-complex-assoc-type.rs:2:25 | diff --git a/tests/ui/wf/wf-foreign-fn-decl-ret.stderr b/tests/ui/wf/wf-foreign-fn-decl-ret.stderr index b03023b5fd1..0e93601043a 100644 --- a/tests/ui/wf/wf-foreign-fn-decl-ret.stderr +++ b/tests/ui/wf/wf-foreign-fn-decl-ret.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `(): Foo` is not satisfied | LL | pub fn lint_me() -> <() as Foo>::Assoc; | ^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/wf-foreign-fn-decl-ret.rs:6:1 + | +LL | pub trait Foo { + | ^^^^^^^^^^^^^ error[E0277]: the trait bound `u32: Unsatisfied` is not satisfied --> $DIR/wf-foreign-fn-decl-ret.rs:14:32 @@ -10,6 +16,11 @@ error[E0277]: the trait bound `u32: Unsatisfied` is not satisfied LL | pub fn lint_me_aswell() -> Bar<u32>; | ^^^^^^^^ the trait `Unsatisfied` is not implemented for `u32` | +help: this trait has no implementations, consider adding one + --> $DIR/wf-foreign-fn-decl-ret.rs:1:1 + | +LL | pub trait Unsatisfied {} + | ^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `Bar` --> $DIR/wf-foreign-fn-decl-ret.rs:4:19 | diff --git a/tests/ui/wf/wf-packed-on-proj-of-type-as-unimpl-trait.stderr b/tests/ui/wf/wf-packed-on-proj-of-type-as-unimpl-trait.stderr index e460cdcd3f3..52f46562c37 100644 --- a/tests/ui/wf/wf-packed-on-proj-of-type-as-unimpl-trait.stderr +++ b/tests/ui/wf/wf-packed-on-proj-of-type-as-unimpl-trait.stderr @@ -3,6 +3,12 @@ error[E0277]: the trait bound `DefaultAllocator: Allocator` is not satisfied | LL | struct Foo(Matrix<<DefaultAllocator as Allocator>::Buffer>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Allocator` is not implemented for `DefaultAllocator` + | +help: this trait has no implementations, consider adding one + --> $DIR/wf-packed-on-proj-of-type-as-unimpl-trait.rs:23:1 + | +LL | pub trait Allocator { type Buffer; } + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/where-clauses/higher-ranked-fn-type.quiet.stderr b/tests/ui/where-clauses/higher-ranked-fn-type.quiet.stderr index 191a8ca8ebc..29b36f44a4d 100644 --- a/tests/ui/where-clauses/higher-ranked-fn-type.quiet.stderr +++ b/tests/ui/where-clauses/higher-ranked-fn-type.quiet.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<'b> fn(&'b ()): Foo` is not satisfied LL | called() | ^^^^^^ the trait `for<'b> Foo` is not implemented for `fn(&'b ())` | +help: this trait has no implementations, consider adding one + --> $DIR/higher-ranked-fn-type.rs:6:1 + | +LL | trait Foo { + | ^^^^^^^^^ note: required by a bound in `called` --> $DIR/higher-ranked-fn-type.rs:12:25 | diff --git a/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr b/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr index ce409f627be..54afeaa7eda 100644 --- a/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr +++ b/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_t LL | called() | ^^^^^^ the trait `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> Foo` is not implemented for `fn(&ReLateBound(DebruijnIndex(1), BoundRegion { var: 0, kind: BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b) }) ())` | +help: this trait has no implementations, consider adding one + --> $DIR/higher-ranked-fn-type.rs:6:1 + | +LL | trait Foo { + | ^^^^^^^^^ note: required by a bound in `called` --> $DIR/higher-ranked-fn-type.rs:12:25 | diff --git a/tests/ui/where-clauses/where-clause-method-substituion.stderr b/tests/ui/where-clauses/where-clause-method-substituion.stderr index 8c47ed6d431..2f3b615a13b 100644 --- a/tests/ui/where-clauses/where-clause-method-substituion.stderr +++ b/tests/ui/where-clauses/where-clause-method-substituion.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `X: Foo<X>` is not satisfied LL | 1.method::<X>(); | ^ the trait `Foo<X>` is not implemented for `X` | +help: this trait has no implementations, consider adding one + --> $DIR/where-clause-method-substituion.rs:1:1 + | +LL | trait Foo<T> { + | ^^^^^^^^^^^^ note: required by a bound in `Bar::method` --> $DIR/where-clause-method-substituion.rs:6:34 | |
