diff options
| author | bors <bors@rust-lang.org> | 2025-08-10 14:17:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-10 14:17:41 +0000 |
| commit | 18eeac04fc5c2a4c4a8020dbdf1c652077ad0e4e (patch) | |
| tree | 3bb0db94131d71006af1bfd0151bb9d530cf1315 /tests | |
| parent | 7f7b8ef27d86c865a7ab20c7c42f50811c6a914d (diff) | |
| parent | 934cb10f1b21be3a855951fb9b1f38094946aac8 (diff) | |
| download | rust-18eeac04fc5c2a4c4a8020dbdf1c652077ad0e4e.tar.gz rust-18eeac04fc5c2a4c4a8020dbdf1c652077ad0e4e.zip | |
Auto merge of #145210 - Zalathar:rollup-dm4reb2, r=Zalathar
Rollup of 17 pull requests
Successful merges:
- rust-lang/rust#141624 (unstable-book: Add stubs for environment variables; document some of the important ones)
- rust-lang/rust#143093 (Simplify polonius location-sensitive analysis)
- rust-lang/rust#144402 (Stabilize loongarch32 inline asm)
- rust-lang/rust#144403 (`tests/ui/issues/`: The Issues Strike Back [4/N])
- rust-lang/rust#144739 (Use new public libtest `ERROR_EXIT_CODE` constant in rustdoc)
- rust-lang/rust#145089 (Improve error output when a command fails in bootstrap)
- rust-lang/rust#145112 ([win][arm64ec] Partial fix for raw-dylib-link-ordinal on Arm64EC)
- rust-lang/rust#145129 ([win][arm64ec] Add `/machine:arm64ec` when linking LLVM as Arm64EC)
- rust-lang/rust#145130 (improve "Documentation problem" issue template.)
- rust-lang/rust#145135 (Stabilize `duration_constructors_lite` feature)
- rust-lang/rust#145145 (some `derive_more` refactors)
- rust-lang/rust#145147 (rename `TraitRef::from_method` to `from_assoc`)
- rust-lang/rust#145156 (Override custom Cargo `build-dir` in bootstrap)
- rust-lang/rust#145160 (Change days-threshold to 28 in [behind-upstream])
- rust-lang/rust#145162 (`{BTree,Hash}Map`: add "`Entry` API" section heading)
- rust-lang/rust#145187 (Fix an unstable feature comment that wasn't a doc comment)
- rust-lang/rust#145191 (`suggest_borrow_generic_arg`: use the correct generic args)
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests')
88 files changed, 937 insertions, 118 deletions
diff --git a/tests/assembly-llvm/asm/loongarch-type.rs b/tests/assembly-llvm/asm/loongarch-type.rs index c782be19f1d..95d811a6bd0 100644 --- a/tests/assembly-llvm/asm/loongarch-type.rs +++ b/tests/assembly-llvm/asm/loongarch-type.rs @@ -1,8 +1,15 @@ //@ add-core-stubs +//@ revisions: loongarch32 loongarch64 + //@ assembly-output: emit-asm -//@ compile-flags: --target loongarch64-unknown-linux-gnu + +//@[loongarch32] compile-flags: --target loongarch32-unknown-none +//@[loongarch32] needs-llvm-components: loongarch + +//@[loongarch64] compile-flags: --target loongarch64-unknown-none +//@[loongarch64] needs-llvm-components: loongarch + //@ compile-flags: -Zmerge-functions=disabled -//@ needs-llvm-components: loongarch #![feature(no_core, f16)] #![crate_type = "rlib"] @@ -22,7 +29,7 @@ extern "C" { // CHECK-LABEL: sym_fn: // CHECK: #APP // CHECK: pcalau12i $t0, %got_pc_hi20(extern_func) -// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_func) +// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_func) // CHECK: #NO_APP #[no_mangle] pub unsafe fn sym_fn() { @@ -32,7 +39,7 @@ pub unsafe fn sym_fn() { // CHECK-LABEL: sym_static: // CHECK: #APP // CHECK: pcalau12i $t0, %got_pc_hi20(extern_static) -// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_static) +// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_static) // CHECK: #NO_APP #[no_mangle] pub unsafe fn sym_static() { @@ -87,16 +94,18 @@ check!(reg_i32, i32, reg, "move"); // CHECK: #NO_APP check!(reg_f32, f32, reg, "move"); -// CHECK-LABEL: reg_i64: -// CHECK: #APP -// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} -// CHECK: #NO_APP +// loongarch64-LABEL: reg_i64: +// loongarch64: #APP +// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} +// loongarch64: #NO_APP +#[cfg(loongarch64)] check!(reg_i64, i64, reg, "move"); -// CHECK-LABEL: reg_f64: -// CHECK: #APP -// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} -// CHECK: #NO_APP +// loongarch64-LABEL: reg_f64: +// loongarch64: #APP +// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} +// loongarch64: #NO_APP +#[cfg(loongarch64)] check!(reg_f64, f64, reg, "move"); // CHECK-LABEL: reg_ptr: @@ -153,16 +162,18 @@ check_reg!(r4_i32, i32, "$r4", "move"); // CHECK: #NO_APP check_reg!(r4_f32, f32, "$r4", "move"); -// CHECK-LABEL: r4_i64: -// CHECK: #APP -// CHECK: move $a0, $a0 -// CHECK: #NO_APP +// loongarch64-LABEL: r4_i64: +// loongarch64: #APP +// loongarch64: move $a0, $a0 +// loongarch64: #NO_APP +#[cfg(loongarch64)] check_reg!(r4_i64, i64, "$r4", "move"); -// CHECK-LABEL: r4_f64: -// CHECK: #APP -// CHECK: move $a0, $a0 -// CHECK: #NO_APP +// loongarch64-LABEL: r4_f64: +// loongarch64: #APP +// loongarch64: move $a0, $a0 +// loongarch64: #NO_APP +#[cfg(loongarch64)] check_reg!(r4_f64, f64, "$r4", "move"); // CHECK-LABEL: r4_ptr: diff --git a/tests/crashes/135646.rs b/tests/crashes/135646.rs deleted file mode 100644 index 841ea5b81b4..00000000000 --- a/tests/crashes/135646.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ known-bug: #135646 -//@ compile-flags: -Zpolonius=next -//@ edition: 2024 - -fn main() { - &{ [1, 2, 3][4] }; -} diff --git a/tests/run-make/raw-dylib-link-ordinal/exporter.def b/tests/run-make/raw-dylib-link-ordinal/exporter.def index 5d87c580a54..0544e9f1803 100644 --- a/tests/run-make/raw-dylib-link-ordinal/exporter.def +++ b/tests/run-make/raw-dylib-link-ordinal/exporter.def @@ -1,5 +1,5 @@ LIBRARY exporter EXPORTS exported_function @13 NONAME - exported_variable @5 NONAME + exported_variable @5 NONAME DATA print_exported_variable @9 NONAME diff --git a/tests/run-make/raw-dylib-link-ordinal/rmake.rs b/tests/run-make/raw-dylib-link-ordinal/rmake.rs index 43274b9765b..b9254b16753 100644 --- a/tests/run-make/raw-dylib-link-ordinal/rmake.rs +++ b/tests/run-make/raw-dylib-link-ordinal/rmake.rs @@ -11,7 +11,7 @@ //@ only-windows -use run_make_support::{cc, diff, is_windows_msvc, run, rustc}; +use run_make_support::{cc, diff, extra_c_flags, is_windows_msvc, run, rustc}; // NOTE: build_native_dynamic lib is not used, as the special `def` files // must be passed to the CC compiler. @@ -24,6 +24,7 @@ fn main() { cc().input("exporter.obj") .arg("exporter.def") .args(&["-link", "-dll", "-noimplib", "-out:exporter.dll"]) + .args(extra_c_flags()) .run(); } else { cc().arg("-v").arg("-c").out_exe("exporter.obj").input("exporter.c").run(); diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr new file mode 100644 index 00000000000..8742d4bd82c --- /dev/null +++ b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr @@ -0,0 +1,38 @@ +error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:27:18 + | +LL | asm!("", out("$r0") _); + | ^^^^^^^^^^^^ + +error: invalid register `$tp`: reserved for TLS + --> $DIR/bad-reg.rs:29:18 + | +LL | asm!("", out("$tp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:31:18 + | +LL | asm!("", out("$sp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r21`: reserved by the ABI + --> $DIR/bad-reg.rs:33:18 + | +LL | asm!("", out("$r21") _); + | ^^^^^^^^^^^^^ + +error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:35:18 + | +LL | asm!("", out("$fp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:37:18 + | +LL | asm!("", out("$r31") _); + | ^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors + diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr new file mode 100644 index 00000000000..e6cb6e40c70 --- /dev/null +++ b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr @@ -0,0 +1,62 @@ +error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:27:18 + | +LL | asm!("", out("$r0") _); + | ^^^^^^^^^^^^ + +error: invalid register `$tp`: reserved for TLS + --> $DIR/bad-reg.rs:29:18 + | +LL | asm!("", out("$tp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:31:18 + | +LL | asm!("", out("$sp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r21`: reserved by the ABI + --> $DIR/bad-reg.rs:33:18 + | +LL | asm!("", out("$r21") _); + | ^^^^^^^^^^^^^ + +error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:35:18 + | +LL | asm!("", out("$fp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:37:18 + | +LL | asm!("", out("$r31") _); + | ^^^^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:41:26 + | +LL | asm!("/* {} */", in(freg) f); + | ^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:43:26 + | +LL | asm!("/* {} */", out(freg) _); + | ^^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:45:26 + | +LL | asm!("/* {} */", in(freg) d); + | ^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:47:26 + | +LL | asm!("/* {} */", out(freg) d); + | ^^^^^^^^^^^ + +error: aborting due to 10 previous errors + diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr index 0e544119650..8742d4bd82c 100644 --- a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr +++ b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr @@ -1,35 +1,35 @@ error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:22:18 + --> $DIR/bad-reg.rs:27:18 | LL | asm!("", out("$r0") _); | ^^^^^^^^^^^^ error: invalid register `$tp`: reserved for TLS - --> $DIR/bad-reg.rs:24:18 + --> $DIR/bad-reg.rs:29:18 | LL | asm!("", out("$tp") _); | ^^^^^^^^^^^^ error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:26:18 + --> $DIR/bad-reg.rs:31:18 | LL | asm!("", out("$sp") _); | ^^^^^^^^^^^^ error: invalid register `$r21`: reserved by the ABI - --> $DIR/bad-reg.rs:28:18 + --> $DIR/bad-reg.rs:33:18 | LL | asm!("", out("$r21") _); | ^^^^^^^^^^^^^ error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:30:18 + --> $DIR/bad-reg.rs:35:18 | LL | asm!("", out("$fp") _); | ^^^^^^^^^^^^ error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:32:18 + --> $DIR/bad-reg.rs:37:18 | LL | asm!("", out("$r31") _); | ^^^^^^^^^^^^^ diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr index 6d0410dc6a1..e6cb6e40c70 100644 --- a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr +++ b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr @@ -1,59 +1,59 @@ error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:22:18 + --> $DIR/bad-reg.rs:27:18 | LL | asm!("", out("$r0") _); | ^^^^^^^^^^^^ error: invalid register `$tp`: reserved for TLS - --> $DIR/bad-reg.rs:24:18 + --> $DIR/bad-reg.rs:29:18 | LL | asm!("", out("$tp") _); | ^^^^^^^^^^^^ error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:26:18 + --> $DIR/bad-reg.rs:31:18 | LL | asm!("", out("$sp") _); | ^^^^^^^^^^^^ error: invalid register `$r21`: reserved by the ABI - --> $DIR/bad-reg.rs:28:18 + --> $DIR/bad-reg.rs:33:18 | LL | asm!("", out("$r21") _); | ^^^^^^^^^^^^^ error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:30:18 + --> $DIR/bad-reg.rs:35:18 | LL | asm!("", out("$fp") _); | ^^^^^^^^^^^^ error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:32:18 + --> $DIR/bad-reg.rs:37:18 | LL | asm!("", out("$r31") _); | ^^^^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:36:26 + --> $DIR/bad-reg.rs:41:26 | LL | asm!("/* {} */", in(freg) f); | ^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:38:26 + --> $DIR/bad-reg.rs:43:26 | LL | asm!("/* {} */", out(freg) _); | ^^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:40:26 + --> $DIR/bad-reg.rs:45:26 | LL | asm!("/* {} */", in(freg) d); | ^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:42:26 + --> $DIR/bad-reg.rs:47:26 | LL | asm!("/* {} */", out(freg) d); | ^^^^^^^^^^^ diff --git a/tests/ui/asm/loongarch/bad-reg.rs b/tests/ui/asm/loongarch/bad-reg.rs index 685b460bc92..0d3eba07f14 100644 --- a/tests/ui/asm/loongarch/bad-reg.rs +++ b/tests/ui/asm/loongarch/bad-reg.rs @@ -1,6 +1,11 @@ //@ add-core-stubs //@ needs-asm-support -//@ revisions: loongarch64_lp64d loongarch64_lp64s +//@ revisions: loongarch32_ilp32d loongarch32_ilp32s loongarch64_lp64d loongarch64_lp64s +//@ min-llvm-version: 20 +//@[loongarch32_ilp32d] compile-flags: --target loongarch32-unknown-none +//@[loongarch32_ilp32d] needs-llvm-components: loongarch +//@[loongarch32_ilp32s] compile-flags: --target loongarch32-unknown-none-softfloat +//@[loongarch32_ilp32s] needs-llvm-components: loongarch //@[loongarch64_lp64d] compile-flags: --target loongarch64-unknown-linux-gnu //@[loongarch64_lp64d] needs-llvm-components: loongarch //@[loongarch64_lp64s] compile-flags: --target loongarch64-unknown-none-softfloat @@ -34,12 +39,12 @@ fn f() { asm!("", out("$f0") _); // ok asm!("/* {} */", in(freg) f); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f asm!("/* {} */", out(freg) _); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f asm!("/* {} */", in(freg) d); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f asm!("/* {} */", out(freg) d); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f } } diff --git a/tests/ui/issues/issue-15783.rs b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.rs index ef948a1a88c..3322ed71c60 100644 --- a/tests/ui/issues/issue-15783.rs +++ b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15783 + //@ dont-require-annotations: NOTE pub fn foo(params: Option<&[&str]>) -> usize { diff --git a/tests/ui/issues/issue-15783.stderr b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.stderr index c9c9a723a86..050eb4baa41 100644 --- a/tests/ui/issues/issue-15783.stderr +++ b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-15783.rs:10:19 + --> $DIR/array-slice-coercion-mismatch-15783.rs:12:19 | LL | let msg = foo(x); | --- ^ expected `Option<&[&str]>`, found `Option<&[&str; 1]>` @@ -9,7 +9,7 @@ LL | let msg = foo(x); = note: expected enum `Option<&[&str]>` found enum `Option<&[&str; 1]>` note: function defined here - --> $DIR/issue-15783.rs:3:8 + --> $DIR/array-slice-coercion-mismatch-15783.rs:5:8 | LL | pub fn foo(params: Option<&[&str]>) -> usize { | ^^^ ----------------------- diff --git a/tests/ui/issues/issue-16256.rs b/tests/ui/closures/unused-closure-ice-16256.rs index 1024e4511d6..fd569dd8a0a 100644 --- a/tests/ui/issues/issue-16256.rs +++ b/tests/ui/closures/unused-closure-ice-16256.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16256 + //@ run-pass fn main() { diff --git a/tests/ui/issues/issue-16256.stderr b/tests/ui/closures/unused-closure-ice-16256.stderr index 75c3ec1bd1c..9df433add5d 100644 --- a/tests/ui/issues/issue-16256.stderr +++ b/tests/ui/closures/unused-closure-ice-16256.stderr @@ -1,5 +1,5 @@ warning: unused closure that must be used - --> $DIR/issue-16256.rs:5:5 + --> $DIR/unused-closure-ice-16256.rs:7:5 | LL | |c: u8| buf.push(c); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/issues/issue-15793.rs b/tests/ui/codegen/nested-enum-match-optimization-15793.rs index af92e9dfa4c..420e3ad82b2 100644 --- a/tests/ui/issues/issue-15793.rs +++ b/tests/ui/codegen/nested-enum-match-optimization-15793.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15793 + //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/issues/issue-15523-big.rs b/tests/ui/derives/derive-partial-ord-discriminant-64bit.rs index 7214a4fb1d5..5b6bf6fbf1f 100644 --- a/tests/ui/issues/issue-15523-big.rs +++ b/tests/ui/derives/derive-partial-ord-discriminant-64bit.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15523 + //@ run-pass // Issue 15523: derive(PartialOrd) should use the provided // discriminant values for the derived ordering. @@ -28,7 +30,6 @@ fn main() { assert!(Eu64::Pos2 < Eu64::PosMax); assert!(Eu64::Pos1 < Eu64::PosMax); - assert!(Ei64::Pos2 > Ei64::Pos1); assert!(Ei64::Pos2 > Ei64::Neg1); assert!(Ei64::Pos1 > Ei64::Neg1); diff --git a/tests/ui/issues/issue-15523.rs b/tests/ui/derives/derive-partial-ord-discriminant.rs index 9fc2e51c6ab..28f325ec966 100644 --- a/tests/ui/issues/issue-15523.rs +++ b/tests/ui/derives/derive-partial-ord-discriminant.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15523 + //@ run-pass // Issue 15523: derive(PartialOrd) should use the provided // discriminant values for the derived ordering. diff --git a/tests/ui/drop/dropck-normalize-errors.stderr b/tests/ui/drop/dropck-normalize-errors.nll.stderr index 2bb5909c6b2..b008daa51a3 100644 --- a/tests/ui/drop/dropck-normalize-errors.stderr +++ b/tests/ui/drop/dropck-normalize-errors.nll.stderr @@ -1,44 +1,44 @@ error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>` - --> $DIR/dropck-normalize-errors.rs:15:28 + --> $DIR/dropck-normalize-errors.rs:19:28 | LL | fn make_a_decoder<'a>() -> ADecoder<'a> { | ^^^^^^^^^^^^ within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: required because it appears within the type `BDecoder` - --> $DIR/dropck-normalize-errors.rs:26:12 + --> $DIR/dropck-normalize-errors.rs:30:12 | LL | pub struct BDecoder { | ^^^^^^^^ note: required because it appears within the type `ADecoder<'a>` - --> $DIR/dropck-normalize-errors.rs:12:12 + --> $DIR/dropck-normalize-errors.rs:16:12 | LL | pub struct ADecoder<'a> { | ^^^^^^^^ = note: the return type of a function must have a statically known size error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder` - --> $DIR/dropck-normalize-errors.rs:23:20 + --> $DIR/dropck-normalize-errors.rs:27:20 | LL | type Decoder = BDecoder; | ^^^^^^^^ within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: required because it appears within the type `BDecoder` - --> $DIR/dropck-normalize-errors.rs:26:12 + --> $DIR/dropck-normalize-errors.rs:30:12 | LL | pub struct BDecoder { | ^^^^^^^^ note: required by a bound in `Decode::Decoder` - --> $DIR/dropck-normalize-errors.rs:4:5 + --> $DIR/dropck-normalize-errors.rs:8:5 | LL | type Decoder; | ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder` @@ -48,25 +48,25 @@ LL | type Decoder: ?Sized; | ++++++++ error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied - --> $DIR/dropck-normalize-errors.rs:27:22 + --> $DIR/dropck-normalize-errors.rs:31:22 | LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied - --> $DIR/dropck-normalize-errors.rs:15:28 + --> $DIR/dropck-normalize-errors.rs:19:28 | LL | fn make_a_decoder<'a>() -> ADecoder<'a> { | ^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/drop/dropck-normalize-errors.polonius.stderr b/tests/ui/drop/dropck-normalize-errors.polonius.stderr new file mode 100644 index 00000000000..f8674b8e34a --- /dev/null +++ b/tests/ui/drop/dropck-normalize-errors.polonius.stderr @@ -0,0 +1,64 @@ +error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>` + --> $DIR/dropck-normalize-errors.rs:19:28 + | +LL | fn make_a_decoder<'a>() -> ADecoder<'a> { + | ^^^^^^^^^^^^ within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` + | +help: this trait has no implementations, consider adding one + --> $DIR/dropck-normalize-errors.rs:11:1 + | +LL | trait NonImplementedTrait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required because it appears within the type `BDecoder` + --> $DIR/dropck-normalize-errors.rs:30:12 + | +LL | pub struct BDecoder { + | ^^^^^^^^ +note: required because it appears within the type `ADecoder<'a>` + --> $DIR/dropck-normalize-errors.rs:16:12 + | +LL | pub struct ADecoder<'a> { + | ^^^^^^^^ + = note: the return type of a function must have a statically known size + +error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder` + --> $DIR/dropck-normalize-errors.rs:27:20 + | +LL | type Decoder = BDecoder; + | ^^^^^^^^ within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` + | +help: this trait has no implementations, consider adding one + --> $DIR/dropck-normalize-errors.rs:11:1 + | +LL | trait NonImplementedTrait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required because it appears within the type `BDecoder` + --> $DIR/dropck-normalize-errors.rs:30:12 + | +LL | pub struct BDecoder { + | ^^^^^^^^ +note: required by a bound in `Decode::Decoder` + --> $DIR/dropck-normalize-errors.rs:8:5 + | +LL | type Decoder; + | ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder` +help: consider relaxing the implicit `Sized` restriction + | +LL | type Decoder: ?Sized; + | ++++++++ + +error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied + --> $DIR/dropck-normalize-errors.rs:31:22 + | +LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` + | +help: this trait has no implementations, consider adding one + --> $DIR/dropck-normalize-errors.rs:11:1 + | +LL | trait NonImplementedTrait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/drop/dropck-normalize-errors.rs b/tests/ui/drop/dropck-normalize-errors.rs index 793122bd33d..2ade63f27c5 100644 --- a/tests/ui/drop/dropck-normalize-errors.rs +++ b/tests/ui/drop/dropck-normalize-errors.rs @@ -1,5 +1,9 @@ // Test that we don't ICE when computing the drop types for +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius +//@ [polonius] compile-flags: -Zpolonius=next + trait Decode<'a> { type Decoder; } @@ -14,7 +18,7 @@ pub struct ADecoder<'a> { } fn make_a_decoder<'a>() -> ADecoder<'a> { //~^ ERROR the trait bound - //~| ERROR the trait bound + //[nll]~| ERROR the trait bound panic!() } diff --git a/tests/ui/issues/issue-15063.rs b/tests/ui/drop/enum-drop-impl-15063.rs index 969dbe5fad2..a8198abafa0 100644 --- a/tests/ui/issues/issue-15063.rs +++ b/tests/ui/drop/enum-drop-impl-15063.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15063 + //@ run-pass #![allow(dead_code)] #![allow(unused_variables)] diff --git a/tests/ui/issues/issue-15858.rs b/tests/ui/drop/generic-drop-trait-bound-15858.rs index 27887d49e3e..682604d17d8 100644 --- a/tests/ui/issues/issue-15858.rs +++ b/tests/ui/drop/generic-drop-trait-bound-15858.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15858 + //@ run-pass // FIXME(static_mut_refs): this could use an atomic #![allow(static_mut_refs)] diff --git a/tests/ui/issues/issue-15858.stderr b/tests/ui/drop/generic-drop-trait-bound-15858.stderr index 0c082cc0862..86cd6cb6026 100644 --- a/tests/ui/issues/issue-15858.stderr +++ b/tests/ui/drop/generic-drop-trait-bound-15858.stderr @@ -1,5 +1,5 @@ warning: method `do_something` is never used - --> $DIR/issue-15858.rs:7:8 + --> $DIR/generic-drop-trait-bound-15858.rs:9:8 | LL | trait Bar { | --- method in this trait diff --git a/tests/ui/issues/issue-15763.rs b/tests/ui/drop/nested-return-drop-order.rs index 0ebadd80541..67ab52e6250 100644 --- a/tests/ui/issues/issue-15763.rs +++ b/tests/ui/drop/nested-return-drop-order.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15763 + //@ run-pass #![allow(unreachable_code)] diff --git a/tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs b/tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs new file mode 100644 index 00000000000..ecc862ec7be --- /dev/null +++ b/tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs @@ -0,0 +1,34 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16151 + +//@ run-pass + +// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint +#![allow(static_mut_refs)] + +use std::mem; + +static mut DROP_COUNT: usize = 0; + +struct Fragment; + +impl Drop for Fragment { + fn drop(&mut self) { + unsafe { + DROP_COUNT += 1; + } + } +} + +fn main() { + { + let mut fragments = vec![Fragment, Fragment, Fragment]; + let _new_fragments: Vec<Fragment> = mem::replace(&mut fragments, vec![]) + .into_iter() + .skip_while(|_fragment| { + true + }).collect(); + } + unsafe { + assert_eq!(DROP_COUNT, 3); + } +} diff --git a/tests/ui/issues/issue-16492.rs b/tests/ui/drop/struct-field-drop-order.rs index cfdba5fda35..80e3ea616a5 100644 --- a/tests/ui/issues/issue-16492.rs +++ b/tests/ui/drop/struct-field-drop-order.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16492 + //@ run-pass #![allow(non_snake_case)] diff --git a/tests/ui/issues/issue-16441.rs b/tests/ui/extern/empty-struct-extern-fn-16441.rs index 58cfb389297..82f2eee611d 100644 --- a/tests/ui/issues/issue-16441.rs +++ b/tests/ui/extern/empty-struct-extern-fn-16441.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16441 + //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/issues/issue-15094.rs b/tests/ui/fn/fn-traits-call-once-signature-15094.rs index 408ab82eb8c..f550bafe43d 100644 --- a/tests/ui/issues/issue-15094.rs +++ b/tests/ui/fn/fn-traits-call-once-signature-15094.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15094 + #![feature(fn_traits, unboxed_closures)] use std::{fmt, ops}; diff --git a/tests/ui/issues/issue-15094.stderr b/tests/ui/fn/fn-traits-call-once-signature-15094.stderr index 8e0fc8f1770..bb1d336e848 100644 --- a/tests/ui/issues/issue-15094.stderr +++ b/tests/ui/fn/fn-traits-call-once-signature-15094.stderr @@ -1,5 +1,5 @@ error[E0053]: method `call_once` has an incompatible type for trait - --> $DIR/issue-15094.rs:11:5 + --> $DIR/fn-traits-call-once-signature-15094.rs:13:5 | LL | fn call_once(self, _args: ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "rust-call" fn, found "Rust" fn diff --git a/tests/ui/issues/issue-15774.rs b/tests/ui/imports/enum-variant-import-path-15774.rs index dadd59cc077..583fe4da179 100644 --- a/tests/ui/issues/issue-15774.rs +++ b/tests/ui/imports/enum-variant-import-path-15774.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15774 + //@ edition: 2015 //@ run-pass diff --git a/tests/ui/inference/iterator-sum-array-15673.rs b/tests/ui/inference/iterator-sum-array-15673.rs new file mode 100644 index 00000000000..c3d94415aff --- /dev/null +++ b/tests/ui/inference/iterator-sum-array-15673.rs @@ -0,0 +1,11 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15673 + +//@ run-pass +#![allow(stable_features)] + +#![feature(iter_arith)] + +fn main() { + let x: [u64; 3] = [1, 2, 3]; + assert_eq!(6, (0..3).map(|i| x[i]).sum::<u64>()); +} diff --git a/tests/ui/issues/issue-15965.rs b/tests/ui/inference/return-block-type-inference-15965.rs index eef4900d432..50753e309e8 100644 --- a/tests/ui/issues/issue-15965.rs +++ b/tests/ui/inference/return-block-type-inference-15965.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15965 + fn main() { return { return () } diff --git a/tests/ui/issues/issue-15965.stderr b/tests/ui/inference/return-block-type-inference-15965.stderr index 14727e74334..fc4f2defe7f 100644 --- a/tests/ui/issues/issue-15965.stderr +++ b/tests/ui/inference/return-block-type-inference-15965.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/issue-15965.rs:3:9 + --> $DIR/return-block-type-inference-15965.rs:5:9 | LL | / { return () } LL | | diff --git a/tests/ui/issues/issue-15756.rs b/tests/ui/iterators/explicit-deref-non-deref-type-15756.rs index e0861dee61e..6d4a3bffcf7 100644 --- a/tests/ui/issues/issue-15756.rs +++ b/tests/ui/iterators/explicit-deref-non-deref-type-15756.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15756 + use std::slice::Chunks; use std::slice::ChunksMut; diff --git a/tests/ui/issues/issue-15756.stderr b/tests/ui/iterators/explicit-deref-non-deref-type-15756.stderr index a487d360bef..b4f9aab8496 100644 --- a/tests/ui/issues/issue-15756.stderr +++ b/tests/ui/iterators/explicit-deref-non-deref-type-15756.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `[T]` cannot be known at compilation time - --> $DIR/issue-15756.rs:7:10 + --> $DIR/explicit-deref-non-deref-type-15756.rs:9:10 | LL | &mut something | ^^^^^^^^^ doesn't have a size known at compile-time diff --git a/tests/ui/issues/issue-15034.rs b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.rs index 9ea6ed89ca2..e7f9a94231f 100644 --- a/tests/ui/issues/issue-15034.rs +++ b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15034 + pub struct Lexer<'a> { input: &'a str, } diff --git a/tests/ui/issues/issue-15034.stderr b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.stderr index 7db8ade2e48..0762714d259 100644 --- a/tests/ui/issues/issue-15034.stderr +++ b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.stderr @@ -1,5 +1,5 @@ error[E0621]: explicit lifetime required in the type of `lexer` - --> $DIR/issue-15034.rs:17:9 + --> $DIR/nondeterministic-lifetime-errors-15034.rs:19:9 | LL | Parser { lexer: lexer } | ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required diff --git a/tests/ui/lifetimes/struct-lifetime-inference-15735.rs b/tests/ui/lifetimes/struct-lifetime-inference-15735.rs new file mode 100644 index 00000000000..39e619648eb --- /dev/null +++ b/tests/ui/lifetimes/struct-lifetime-inference-15735.rs @@ -0,0 +1,19 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15735 + +//@ check-pass +#![allow(dead_code)] +struct A<'a> { + a: &'a i32, + b: &'a i32, +} + +impl <'a> A<'a> { + fn foo<'b>(&'b self) { + A { + a: self.a, + b: self.b, + }; + } +} + +fn main() { } diff --git a/tests/ui/issues/issue-15189.rs b/tests/ui/macros/for-loop-macro-rules-hygiene.rs index 4dbe2179dd9..fcebda1b9da 100644 --- a/tests/ui/issues/issue-15189.rs +++ b/tests/ui/macros/for-loop-macro-rules-hygiene.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15189 + //@ run-pass macro_rules! third { ($e:expr) => ({let x = 2; $e[x]}) diff --git a/tests/ui/issues/issue-15167.rs b/tests/ui/macros/macro-hygiene-scope-15167.rs index a2653c10ea4..6578f898a5f 100644 --- a/tests/ui/issues/issue-15167.rs +++ b/tests/ui/macros/macro-hygiene-scope-15167.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15167 + // macro f should not be able to inject a reference to 'n'. macro_rules! f { () => (n) } diff --git a/tests/ui/issues/issue-15167.stderr b/tests/ui/macros/macro-hygiene-scope-15167.stderr index 53082ea0ec6..58112c52df1 100644 --- a/tests/ui/issues/issue-15167.stderr +++ b/tests/ui/macros/macro-hygiene-scope-15167.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope @@ -10,7 +10,7 @@ LL | println!("{}", f!()); = note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope @@ -21,7 +21,7 @@ LL | println!("{}", f!()); = note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope @@ -32,7 +32,7 @@ LL | println!("{}", f!()); = note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope diff --git a/tests/ui/issues/issue-15571.rs b/tests/ui/moves/match-move-same-binding-15571.rs index cf17113a282..f6d79c6d76c 100644 --- a/tests/ui/issues/issue-15571.rs +++ b/tests/ui/moves/match-move-same-binding-15571.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15571 + //@ run-pass fn match_on_local() { diff --git a/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.rs b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.rs new file mode 100644 index 00000000000..0fb0cee2013 --- /dev/null +++ b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.rs @@ -0,0 +1,13 @@ +//! Regression test for #145164: For normal calls, make sure the suggestion to borrow generic inputs +//! uses the generic args from the callee's type rather than those attached to the callee's HIR +//! node. In cases where the callee isn't an identifier expression, its HIR node won't have its +//! generic arguments attached, which could lead to ICE when it had other generic args. In this +//! case, the callee expression is `run.clone()`, to which `clone`'s generic arguments are attached. + +fn main() { + let value = String::new(); + run.clone()(value, ()); + run(value, ()); + //~^ ERROR use of moved value: `value` +} +fn run<F, T: Clone>(value: T, f: F) {} diff --git a/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.stderr b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.stderr new file mode 100644 index 00000000000..8c29bfbd290 --- /dev/null +++ b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.stderr @@ -0,0 +1,18 @@ +error[E0382]: use of moved value: `value` + --> $DIR/use-correct-generic-args-in-borrow-suggest.rs:10:9 + | +LL | let value = String::new(); + | ----- move occurs because `value` has type `String`, which does not implement the `Copy` trait +LL | run.clone()(value, ()); + | ----- value moved here +LL | run(value, ()); + | ^^^^^ value used here after move + | +help: consider borrowing `value` + | +LL | run.clone()(&value, ()); + | + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/issues/issue-15207.rs b/tests/ui/never/never-type-method-call-15207.rs index 356e55ac912..69cdeeabb7c 100644 --- a/tests/ui/issues/issue-15207.rs +++ b/tests/ui/never/never-type-method-call-15207.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15207 + fn main() { loop { break.push(1) //~ ERROR no method named `push` found for type `!` diff --git a/tests/ui/issues/issue-15207.stderr b/tests/ui/never/never-type-method-call-15207.stderr index a1047e27ba2..265e7c8611d 100644 --- a/tests/ui/issues/issue-15207.stderr +++ b/tests/ui/never/never-type-method-call-15207.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `push` found for type `!` in the current scope - --> $DIR/issue-15207.rs:3:15 + --> $DIR/never-type-method-call-15207.rs:5:15 | LL | break.push(1) | ^^^^ method not found in `!` diff --git a/tests/ui/nll/issue-46589.nll.stderr b/tests/ui/nll/issue-46589.nll.stderr index dc80c1d08de..f2d08d1f4c8 100644 --- a/tests/ui/nll/issue-46589.nll.stderr +++ b/tests/ui/nll/issue-46589.nll.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `**other` as mutable more than once at a time - --> $DIR/issue-46589.rs:24:21 + --> $DIR/issue-46589.rs:25:21 | LL | *other = match (*other).get_self() { | -------- first mutable borrow occurs here diff --git a/tests/ui/nll/issue-46589.polonius.stderr b/tests/ui/nll/issue-46589.polonius.stderr new file mode 100644 index 00000000000..f2d08d1f4c8 --- /dev/null +++ b/tests/ui/nll/issue-46589.polonius.stderr @@ -0,0 +1,15 @@ +error[E0499]: cannot borrow `**other` as mutable more than once at a time + --> $DIR/issue-46589.rs:25:21 + | +LL | *other = match (*other).get_self() { + | -------- first mutable borrow occurs here +LL | Some(s) => s, +LL | None => (*other).new_self() + | ^^^^^^^^ + | | + | second mutable borrow occurs here + | first borrow later used here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/issue-46589.rs b/tests/ui/nll/issue-46589.rs index 10aff0d7b4e..9a23f61b8cb 100644 --- a/tests/ui/nll/issue-46589.rs +++ b/tests/ui/nll/issue-46589.rs @@ -1,9 +1,10 @@ //@ ignore-compare-mode-polonius (explicit revisions) -//@ revisions: nll polonius_next polonius -//@ [polonius_next] check-pass -//@ [polonius_next] compile-flags: -Zpolonius=next -//@ [polonius] check-pass -//@ [polonius] compile-flags: -Zpolonius +//@ revisions: nll polonius legacy +//@ [nll] known-bug: #46589 +//@ [polonius] known-bug: #46589 +//@ [polonius] compile-flags: -Zpolonius=next +//@ [legacy] check-pass +//@ [legacy] compile-flags: -Zpolonius=legacy struct Foo; @@ -22,7 +23,6 @@ impl Foo { *other = match (*other).get_self() { Some(s) => s, None => (*other).new_self() - //[nll]~^ ERROR cannot borrow `**other` as mutable more than once at a time [E0499] }; let c = other; diff --git a/tests/ui/nll/polonius/array-literal-index-oob-2024.rs b/tests/ui/nll/polonius/array-literal-index-oob-2024.rs new file mode 100644 index 00000000000..2054a32e535 --- /dev/null +++ b/tests/ui/nll/polonius/array-literal-index-oob-2024.rs @@ -0,0 +1,12 @@ +// This test used to ICE under `-Zpolonius=next` when computing loan liveness +// and taking kills into account during reachability traversal of the localized +// constraint graph. Originally from another test but on edition 2024, as +// seen in issue #135646. + +//@ compile-flags: -Zpolonius=next +//@ edition: 2024 +//@ check-pass + +fn main() { + &{ [1, 2, 3][4] }; +} diff --git a/tests/ui/nll/polonius/flow-sensitive-invariance.nll.stderr b/tests/ui/nll/polonius/flow-sensitive-invariance.nll.stderr new file mode 100644 index 00000000000..5756148f4eb --- /dev/null +++ b/tests/ui/nll/polonius/flow-sensitive-invariance.nll.stderr @@ -0,0 +1,36 @@ +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:17 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:45 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'a` and `'b` must be the same: replace one with the other + +error: aborting due to 2 previous errors + diff --git a/tests/ui/nll/polonius/flow-sensitive-invariance.polonius.stderr b/tests/ui/nll/polonius/flow-sensitive-invariance.polonius.stderr new file mode 100644 index 00000000000..5756148f4eb --- /dev/null +++ b/tests/ui/nll/polonius/flow-sensitive-invariance.polonius.stderr @@ -0,0 +1,36 @@ +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:17 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:45 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'a` and `'b` must be the same: replace one with the other + +error: aborting due to 2 previous errors + diff --git a/tests/ui/nll/polonius/flow-sensitive-invariance.rs b/tests/ui/nll/polonius/flow-sensitive-invariance.rs new file mode 100644 index 00000000000..c5571f131da --- /dev/null +++ b/tests/ui/nll/polonius/flow-sensitive-invariance.rs @@ -0,0 +1,34 @@ +// An example (from @steffahn) of reachability as an approximation of liveness where the polonius +// alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius legacy +//@ [polonius] compile-flags: -Z polonius=next +//@ [legacy] check-pass +//@ [legacy] compile-flags: -Z polonius=legacy + +use std::cell::Cell; + +struct Invariant<'l>(Cell<&'l ()>); + +fn create_invariant<'l>() -> Invariant<'l> { + Invariant(Cell::new(&())) +} + +fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + let returned_value = create_invariant(); + if choice { Ok(returned_value) } else { Err(returned_value) } + //[nll]~^ ERROR lifetime may not live long enough + //[nll]~| ERROR lifetime may not live long enough + //[polonius]~^^^ ERROR lifetime may not live long enough + //[polonius]~| ERROR lifetime may not live long enough +} + +fn use_it_but_its_the_same_region<'a: 'b, 'b: 'a>( + choice: bool, +) -> Result<Invariant<'a>, Invariant<'b>> { + let returned_value = create_invariant(); + if choice { Ok(returned_value) } else { Err(returned_value) } +} + +fn main() {} diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr index 7ac4e5de283..b768f60590c 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `*elements` as mutable more than once at a time - --> $DIR/iterating-updating-cursor-issue-108704.rs:40:26 + --> $DIR/iterating-updating-cursor-issue-108704.rs:41:26 | LL | for (idx, el) in elements.iter_mut().enumerate() { | ^^^^^^^^ diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.polonius.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.polonius.stderr new file mode 100644 index 00000000000..b768f60590c --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.polonius.stderr @@ -0,0 +1,12 @@ +error[E0499]: cannot borrow `*elements` as mutable more than once at a time + --> $DIR/iterating-updating-cursor-issue-108704.rs:41:26 + | +LL | for (idx, el) in elements.iter_mut().enumerate() { + | ^^^^^^^^ + | | + | `*elements` was mutably borrowed here in the previous iteration of the loop + | first borrow used here, in later iteration of loop + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs index 420cb73bed2..673efa8f225 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs @@ -1,11 +1,12 @@ #![crate_type = "lib"] -// An example from #108704 of the linked-list cursor-like pattern of #46859/#48001. +// An example from #108704 of the linked-list cursor-like pattern of #46859/#48001, where the +// polonius alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. //@ ignore-compare-mode-polonius (explicit revisions) //@ revisions: nll polonius legacy //@ [nll] known-bug: #108704 -//@ [polonius] check-pass +//@ [polonius] known-bug: #108704 //@ [polonius] compile-flags: -Z polonius=next //@ [legacy] check-pass //@ [legacy] compile-flags: -Z polonius=legacy @@ -32,7 +33,7 @@ fn merge_tree_ok(root: &mut Root, path: Vec<String>) { } } -// NLLs fail here +// NLLs and polonius alpha fail here fn merge_tree_ko(root: &mut Root, path: Vec<String>) { let mut elements = &mut root.children; diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr index 14e1726e158..34b04e707db 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `p.0` as mutable more than once at a time - --> $DIR/iterating-updating-cursor-issue-57165.rs:29:20 + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:20 | LL | while let Some(now) = p { | ^^^ - first borrow used here, in later iteration of loop @@ -7,7 +7,7 @@ LL | while let Some(now) = p { | `p.0` was mutably borrowed here in the previous iteration of the loop error[E0503]: cannot use `*p` because it was mutably borrowed - --> $DIR/iterating-updating-cursor-issue-57165.rs:29:27 + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:27 | LL | while let Some(now) = p { | --- ^ diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.polonius.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.polonius.stderr new file mode 100644 index 00000000000..34b04e707db --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.polonius.stderr @@ -0,0 +1,22 @@ +error[E0499]: cannot borrow `p.0` as mutable more than once at a time + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:20 + | +LL | while let Some(now) = p { + | ^^^ - first borrow used here, in later iteration of loop + | | + | `p.0` was mutably borrowed here in the previous iteration of the loop + +error[E0503]: cannot use `*p` because it was mutably borrowed + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:27 + | +LL | while let Some(now) = p { + | --- ^ + | | | + | | use of borrowed `p.0` + | | borrow later used here + | `p.0` is borrowed here + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0499, E0503. +For more information about an error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs index 63ec89146d4..9670fc77e6f 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs @@ -1,11 +1,12 @@ #![crate_type = "lib"] -// An example from #57165 of the linked-list cursor-like pattern of #46859/#48001. +// An example from #57165 of the linked-list cursor-like pattern of #46859/#48001, where the +// polonius alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. //@ ignore-compare-mode-polonius (explicit revisions) //@ revisions: nll polonius legacy //@ [nll] known-bug: #57165 -//@ [polonius] check-pass +//@ [polonius] known-bug: #57165 //@ [polonius] compile-flags: -Z polonius=next //@ [legacy] check-pass //@ [legacy] compile-flags: -Z polonius=legacy @@ -22,7 +23,7 @@ fn no_control_flow() { } } -// NLLs fail here +// NLLs and polonius alpha fail here fn conditional() { let mut b = Some(Box::new(X { next: None })); let mut p = &mut b; diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr index bf38da566c6..b76e4ff6398 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr @@ -1,5 +1,5 @@ error[E0506]: cannot assign to `*node_ref` because it is borrowed - --> $DIR/iterating-updating-cursor-issue-63908.rs:42:5 + --> $DIR/iterating-updating-cursor-issue-63908.rs:43:5 | LL | fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) { | - let's call the lifetime of this reference `'1` diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.polonius.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.polonius.stderr new file mode 100644 index 00000000000..b76e4ff6398 --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.polonius.stderr @@ -0,0 +1,18 @@ +error[E0506]: cannot assign to `*node_ref` because it is borrowed + --> $DIR/iterating-updating-cursor-issue-63908.rs:43:5 + | +LL | fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) { + | - let's call the lifetime of this reference `'1` +LL | loop { +LL | let next_ref = &mut node_ref.as_mut().unwrap().next; + | -------- `*node_ref` is borrowed here +... +LL | node_ref = next_ref; + | ------------------- assignment requires that `*node_ref` is borrowed for `'1` +... +LL | *node_ref = None; + | ^^^^^^^^^ `*node_ref` is assigned to here but it was already borrowed + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0506`. diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs index 00e48b65fed..6682926c523 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs @@ -1,11 +1,12 @@ #![crate_type = "lib"] -// An example from #63908 of the linked-list cursor-like pattern of #46859/#48001. +// An example from #63908 of the linked-list cursor-like pattern of #46859/#48001, where the +// polonius alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. //@ ignore-compare-mode-polonius (explicit revisions) //@ revisions: nll polonius legacy //@ [nll] known-bug: #63908 -//@ [polonius] check-pass +//@ [polonius] known-bug: #63908 //@ [polonius] compile-flags: -Z polonius=next //@ [legacy] check-pass //@ [legacy] compile-flags: -Z polonius=legacy @@ -27,7 +28,7 @@ fn remove_last_node_recursive<T>(node_ref: &mut List<T>) { } } -// NLLs fail here +// NLLs and polonius alpha fail here fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) { loop { let next_ref = &mut node_ref.as_mut().unwrap().next; diff --git a/tests/ui/nll/polonius/iterating-updating-mutref.nll.stderr b/tests/ui/nll/polonius/iterating-updating-mutref.nll.stderr new file mode 100644 index 00000000000..941c736d8d2 --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-mutref.nll.stderr @@ -0,0 +1,15 @@ +error[E0499]: cannot borrow `self.buf_read` as mutable more than once at a time + --> $DIR/iterating-updating-mutref.rs:61:23 + | +LL | pub fn next<'a>(&'a mut self) -> &'a str { + | -- lifetime `'a` defined here +LL | loop { +LL | let buf = self.buf_read.fill_buf(); + | ^^^^^^^^^^^^^ `self.buf_read` was mutably borrowed here in the previous iteration of the loop +LL | if let Some(s) = decode(buf) { +LL | return s; + | - returning this value requires that `self.buf_read` is borrowed for `'a` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/iterating-updating-mutref.rs b/tests/ui/nll/polonius/iterating-updating-mutref.rs new file mode 100644 index 00000000000..a315bf66279 --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-mutref.rs @@ -0,0 +1,87 @@ +// These are some examples of iterating through and updating a mutable ref, similar in spirit to the +// linked-list-like pattern of #46859/#48001 where the polonius alpha analysis shows imprecision, +// unlike the datalog implementation. +// +// They differ in that after the loans prior to the loop are either not live after the loop, or with +// control flow and outlives relationships that are simple enough for the reachability +// approximation. They're thus accepted by the alpha analysis, like NLLs did for the simplest cases +// of flow-sensitivity. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius legacy +//@ [nll] known-bug: #46859 +//@ [polonius] check-pass +//@ [polonius] compile-flags: -Z polonius=next +//@ [legacy] check-pass +//@ [legacy] compile-flags: -Z polonius=legacy + +// The #46859 OP +struct List<T> { + value: T, + next: Option<Box<List<T>>>, +} + +fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> { + let mut result = vec![]; + loop { + result.push(&mut list.value); + if let Some(n) = list.next.as_mut() { + list = n; + } else { + return result; + } + } +} + +// A similar construction, where paths in the constraint graph are also clearly terminating, so it's +// fine even for NLLs. +fn to_refs2<T>(mut list: &mut List<T>) -> Vec<&mut T> { + let mut result = vec![]; + loop { + result.push(&mut list.value); + if let Some(n) = list.next.as_mut() { + list = n; + } else { + break; + } + } + + result +} + +// Another MCVE from the same issue, but was rejected by NLLs. +pub struct Decoder { + buf_read: BufRead, +} + +impl Decoder { + // NLLs fail here + pub fn next<'a>(&'a mut self) -> &'a str { + loop { + let buf = self.buf_read.fill_buf(); + if let Some(s) = decode(buf) { + return s; + } + // loop to get more input data + + // At this point `buf` is not used anymore. + // With NLL I would expect the borrow to end here, + // such that `self.buf_read` is not borrowed anymore + // by the time we start the next loop iteration. + } + } +} + +struct BufRead; + +impl BufRead { + fn fill_buf(&mut self) -> &[u8] { + unimplemented!() + } +} + +fn decode(_: &[u8]) -> Option<&str> { + unimplemented!() +} + +fn main() {} diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.legacy.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.legacy.stderr new file mode 100644 index 00000000000..fa201b89048 --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.legacy.stderr @@ -0,0 +1,28 @@ +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:19:19 + | +LL | fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + | - let's call the lifetime of this reference `'1` +LL | let Some(i) = t.next() else { return None }; + | - first mutable borrow occurs here +LL | let Some(j) = t.next() else { return None }; + | ^ second mutable borrow occurs here +... +LL | Some((i, j)) + | ------------ returning this value requires that `*t` is borrowed for `'1` + +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:31:13 + | +LL | let i = t.next(); + | - first mutable borrow occurs here +... +LL | let j = t.next(); + | ^ second mutable borrow occurs here +LL | +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `Option<<T as LendingIterator>::Item<'_>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.nll.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.nll.stderr new file mode 100644 index 00000000000..fa201b89048 --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.nll.stderr @@ -0,0 +1,28 @@ +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:19:19 + | +LL | fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + | - let's call the lifetime of this reference `'1` +LL | let Some(i) = t.next() else { return None }; + | - first mutable borrow occurs here +LL | let Some(j) = t.next() else { return None }; + | ^ second mutable borrow occurs here +... +LL | Some((i, j)) + | ------------ returning this value requires that `*t` is borrowed for `'1` + +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:31:13 + | +LL | let i = t.next(); + | - first mutable borrow occurs here +... +LL | let j = t.next(); + | ^ second mutable borrow occurs here +LL | +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `Option<<T as LendingIterator>::Item<'_>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr new file mode 100644 index 00000000000..bf8546b63bf --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr @@ -0,0 +1,26 @@ +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:19:19 + | +LL | let Some(i) = t.next() else { return None }; + | - first mutable borrow occurs here +LL | let Some(j) = t.next() else { return None }; + | ^ second mutable borrow occurs here +... +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `<T as LendingIterator>::Item<'_>` + +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:31:13 + | +LL | let i = t.next(); + | - first mutable borrow occurs here +... +LL | let j = t.next(); + | ^ second mutable borrow occurs here +LL | +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `Option<<T as LendingIterator>::Item<'_>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.rs b/tests/ui/nll/polonius/lending-iterator-sanity-checks.rs new file mode 100644 index 00000000000..ae8cc78957f --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.rs @@ -0,0 +1,71 @@ +// Some sanity checks for lending iterators with GATs. This is just some non-regression tests +// ensuring the polonius alpha analysis, the datalog implementation, and NLLs agree in these common +// cases of overlapping yielded items. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius legacy +//@ [polonius] compile-flags: -Z polonius=next +//@ [legacy] compile-flags: -Z polonius=legacy + +trait LendingIterator { + type Item<'a> + where + Self: 'a; + fn next(&mut self) -> Option<Self::Item<'_>>; +} + +fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + let Some(i) = t.next() else { return None }; + let Some(j) = t.next() else { return None }; + //~^ ERROR cannot borrow `*t` as mutable more than once at a time + + // `i` is obviously still (use-)live here, but we called `next` again to get `j`. + Some((i, j)) +} + +fn drop_live<T: LendingIterator>(t: &mut T) { + let i = t.next(); + + // Now `i` is use-dead here, but we don't know if the iterator items have a `Drop` impl, so it's + // still drop-live. + let j = t.next(); + //~^ ERROR cannot borrow `*t` as mutable more than once at a time +} + +// But we can still manually serialize the lifetimes with scopes (or preventing the destructor from +// being called), so they're not overlapping. +fn manually_non_overlapping<T: LendingIterator>(t: &mut T) { + { + let i = t.next(); + } + + let j = t.next(); // i is dead + + drop(j); + let k = t.next(); // j is dead + + let k = std::mem::ManuallyDrop::new(k); + let l = t.next(); // we told the compiler that k is not drop-live +} + +// The cfg below is because there's a diagnostic ICE trying to explain the source of the error when +// using the datalog implementation. We're not fixing *that*, outside of removing the implementation +// in the future. +#[cfg(not(legacy))] // FIXME: remove this cfg when removing the datalog implementation +fn items_have_no_borrows<T: LendingIterator>(t: &mut T) +where + for<'a> T::Item<'a>: 'static, +{ + let i = t.next(); + let j = t.next(); +} + +fn items_are_copy<T: LendingIterator>(t: &mut T) +where + for<'a> T::Item<'a>: Copy, +{ + let i = t.next(); + let j = t.next(); +} + +fn main() {} diff --git a/tests/ui/issues/issue-15043.rs b/tests/ui/parser/generics-rangle-eq-15043.rs index a9bb46b649b..1afc334dfd8 100644 --- a/tests/ui/issues/issue-15043.rs +++ b/tests/ui/parser/generics-rangle-eq-15043.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15043 + //@ run-pass #![allow(warnings)] diff --git a/tests/ui/issues/issue-15896.rs b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.rs index d3153b516e6..9f7c5084c0e 100644 --- a/tests/ui/issues/issue-15896.rs +++ b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15896 + // Regression test for #15896. It used to ICE rustc. fn main() { diff --git a/tests/ui/issues/issue-15896.stderr b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.stderr index 381f6dc2276..8dee4c37e2f 100644 --- a/tests/ui/issues/issue-15896.stderr +++ b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-15896.rs:11:11 + --> $DIR/enum-struct-pattern-mismatch-15896.rs:13:11 | LL | let u = match e { | - this expression has type `E` diff --git a/tests/ui/issues/issue-15381.rs b/tests/ui/pattern/refutable-pattern-for-loop-15381.rs index bd5f62ddc67..3c19612c9cc 100644 --- a/tests/ui/issues/issue-15381.rs +++ b/tests/ui/pattern/refutable-pattern-for-loop-15381.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15381 + fn main() { let values: Vec<u8> = vec![1,2,3,4,5,6,7,8]; diff --git a/tests/ui/issues/issue-15381.stderr b/tests/ui/pattern/refutable-pattern-for-loop-15381.stderr index 03a0100f1bd..3c1d5fb454c 100644 --- a/tests/ui/issues/issue-15381.stderr +++ b/tests/ui/pattern/refutable-pattern-for-loop-15381.stderr @@ -1,5 +1,5 @@ error[E0005]: refutable pattern in `for` loop binding - --> $DIR/issue-15381.rs:4:9 + --> $DIR/refutable-pattern-for-loop-15381.rs:6:9 | LL | for &[x,y,z] in values.chunks(3).filter(|&xs| xs.len() == 3) { | ^^^^^^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 1 more not covered diff --git a/tests/ui/issues/issue-15104.rs b/tests/ui/pattern/slice-pattern-recursion-15104.rs index e68c94c370e..24e3fe78de0 100644 --- a/tests/ui/issues/issue-15104.rs +++ b/tests/ui/pattern/slice-pattern-recursion-15104.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15104 + //@ run-pass fn main() { diff --git a/tests/ui/issues/issue-16149.rs b/tests/ui/pattern/static-binding-shadow-16149.rs index 51b60725c5a..a46f78214c7 100644 --- a/tests/ui/issues/issue-16149.rs +++ b/tests/ui/pattern/static-binding-shadow-16149.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16149 + extern "C" { static externalValue: isize; } diff --git a/tests/ui/issues/issue-16149.stderr b/tests/ui/pattern/static-binding-shadow-16149.stderr index 9ffd0e7e645..6d8c7634acd 100644 --- a/tests/ui/issues/issue-16149.stderr +++ b/tests/ui/pattern/static-binding-shadow-16149.stderr @@ -1,5 +1,5 @@ error[E0530]: match bindings cannot shadow statics - --> $DIR/issue-16149.rs:7:9 + --> $DIR/static-binding-shadow-16149.rs:9:9 | LL | static externalValue: isize; | ---------------------------- the static `externalValue` is defined here diff --git a/tests/ui/issues/issue-15260.rs b/tests/ui/pattern/struct-field-duplicate-binding-15260.rs index 64fc3df3d23..a3617798cdf 100644 --- a/tests/ui/issues/issue-15260.rs +++ b/tests/ui/pattern/struct-field-duplicate-binding-15260.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15260 + struct Foo { a: usize, } diff --git a/tests/ui/issues/issue-15260.stderr b/tests/ui/pattern/struct-field-duplicate-binding-15260.stderr index 4a3041122b2..536904fbcb3 100644 --- a/tests/ui/issues/issue-15260.stderr +++ b/tests/ui/pattern/struct-field-duplicate-binding-15260.stderr @@ -1,5 +1,5 @@ error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:8:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:10:9 | LL | a: _, | ---- first use of `a` @@ -7,7 +7,7 @@ LL | a: _ | ^^^^ multiple uses of `a` in pattern error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:14:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:16:9 | LL | a, | - first use of `a` @@ -15,7 +15,7 @@ LL | a: _ | ^^^^ multiple uses of `a` in pattern error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:20:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:22:9 | LL | a, | - first use of `a` @@ -23,7 +23,7 @@ LL | a: _, | ^^^^ multiple uses of `a` in pattern error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:22:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:24:9 | LL | a, | - first use of `a` diff --git a/tests/ui/issues/issue-15129-rpass.rs b/tests/ui/pattern/tuple-enum-match-15129.rs index e2ddb989072..1d6192c4cb3 100644 --- a/tests/ui/issues/issue-15129-rpass.rs +++ b/tests/ui/pattern/tuple-enum-match-15129.rs @@ -1,24 +1,25 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15129 + //@ run-pass pub enum T { T1(()), - T2(()) + T2(()), } pub enum V { V1(isize), - V2(bool) + V2(bool), } fn foo(x: (T, V)) -> String { match x { - (T::T1(()), V::V1(i)) => format!("T1(()), V1({})", i), - (T::T2(()), V::V2(b)) => format!("T2(()), V2({})", b), - _ => String::new() + (T::T1(()), V::V1(i)) => format!("T1(()), V1({})", i), + (T::T2(()), V::V2(b)) => format!("T2(()), V2({})", b), + _ => String::new(), } } - fn main() { assert_eq!(foo((T::T1(()), V::V1(99))), "T1(()), V1(99)".to_string()); assert_eq!(foo((T::T2(()), V::V2(true))), "T2(()), V2(true)".to_string()); diff --git a/tests/ui/issues/issue-16401.rs b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.rs index 0985a6806d2..2eba33e177e 100644 --- a/tests/ui/issues/issue-16401.rs +++ b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16401 + struct Slice<T> { data: *const T, len: usize, diff --git a/tests/ui/issues/issue-16401.stderr b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.stderr index 6af920ca439..22c04e439c4 100644 --- a/tests/ui/issues/issue-16401.stderr +++ b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-16401.rs:8:9 + --> $DIR/unit-type-struct-pattern-mismatch-16401.rs:10:9 | LL | match () { | -- this expression has type `()` diff --git a/tests/ui/issues/issue-16452.rs b/tests/ui/statics/conditional-static-declaration-16010.rs index 4ab74f09059..0bc5b0ee86f 100644 --- a/tests/ui/issues/issue-16452.rs +++ b/tests/ui/statics/conditional-static-declaration-16010.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16010 + //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/issues/issue-15444.rs b/tests/ui/traits/fn-type-trait-impl-15444.rs index 14708c7733c..ab91e88b9cd 100644 --- a/tests/ui/issues/issue-15444.rs +++ b/tests/ui/traits/fn-type-trait-impl-15444.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15444 + //@ run-pass trait MyTrait { diff --git a/tests/ui/issues/issue-15734.rs b/tests/ui/traits/index-trait-multiple-impls-15734.rs index 26fb7061664..a2d5d7c87fc 100644 --- a/tests/ui/issues/issue-15734.rs +++ b/tests/ui/traits/index-trait-multiple-impls-15734.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15734 + //@ run-pass //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) diff --git a/tests/ui/issues/issue-16048.rs b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.rs index eaf6acff26b..9c36b231403 100644 --- a/tests/ui/issues/issue-16048.rs +++ b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16048 + trait NoLifetime { fn get<'p, T : Test<'p>>(&self) -> T; //~^ NOTE lifetimes in impl do not match this method in trait diff --git a/tests/ui/issues/issue-16048.stderr b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.stderr index f97f13152bc..08b69184b7f 100644 --- a/tests/ui/issues/issue-16048.stderr +++ b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.stderr @@ -1,5 +1,5 @@ error[E0195]: lifetime parameters or bounds on method `get` do not match the trait declaration - --> $DIR/issue-16048.rs:21:11 + --> $DIR/lifetime-mismatch-trait-impl-16048.rs:23:11 | LL | fn get<'p, T : Test<'p>>(&self) -> T; | ------------------ lifetimes in impl do not match this method in trait @@ -8,7 +8,7 @@ LL | fn get<'p, T: Test<'a> + From<Foo<'a>>>(&self) -> T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait error[E0605]: non-primitive cast: `Foo<'a>` as `T` - --> $DIR/issue-16048.rs:24:16 + --> $DIR/lifetime-mismatch-trait-impl-16048.rs:26:16 | LL | return *self as T; | ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object diff --git a/tests/ui/wf/hir-wf-check-erase-regions.stderr b/tests/ui/wf/hir-wf-check-erase-regions.nll.stderr index 07304cd448e..dcade3aa367 100644 --- a/tests/ui/wf/hir-wf-check-erase-regions.stderr +++ b/tests/ui/wf/hir-wf-check-erase-regions.nll.stderr @@ -1,5 +1,5 @@ error[E0277]: `&'a T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:7:21 + --> $DIR/hir-wf-check-erase-regions.rs:11:21 | LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'a T` is not an iterator @@ -11,7 +11,7 @@ note: required by a bound in `std::iter::IntoIterator::IntoIter` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL error[E0277]: `&'a T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:7:5 + --> $DIR/hir-wf-check-erase-regions.rs:11:5 | LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; | ^^^^^^^^^^^^^ `&'a T` is not an iterator @@ -23,7 +23,7 @@ note: required by a bound in `Flatten` --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL error[E0277]: `&'a T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:11:27 + --> $DIR/hir-wf-check-erase-regions.rs:15:27 | LL | fn into_iter(self) -> Self::IntoIter { | ^^^^^^^^^^^^^^ `&'a T` is not an iterator @@ -35,7 +35,7 @@ note: required by a bound in `Flatten` --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL error[E0277]: `&T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:11:27 + --> $DIR/hir-wf-check-erase-regions.rs:15:27 | LL | fn into_iter(self) -> Self::IntoIter { | ^^^^^^^^^^^^^^ `&T` is not an iterator diff --git a/tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr b/tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr new file mode 100644 index 00000000000..55728aa642b --- /dev/null +++ b/tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr @@ -0,0 +1,39 @@ +error[E0277]: `&'a T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:11:21 + | +LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'a T` is not an iterator + | + = help: the trait `Iterator` is not implemented for `&'a T` + = help: the trait `Iterator` is implemented for `&mut I` + = note: required for `Flatten<std::slice::Iter<'a, T>>` to implement `Iterator` +note: required by a bound in `std::iter::IntoIterator::IntoIter` + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL + +error[E0277]: `&'a T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:11:5 + | +LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; + | ^^^^^^^^^^^^^ `&'a T` is not an iterator + | + = help: the trait `Iterator` is not implemented for `&'a T` + = help: the trait `Iterator` is implemented for `&mut I` + = note: required for `&'a T` to implement `IntoIterator` +note: required by a bound in `Flatten` + --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL + +error[E0277]: `&'a T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:15:27 + | +LL | fn into_iter(self) -> Self::IntoIter { + | ^^^^^^^^^^^^^^ `&'a T` is not an iterator + | + = help: the trait `Iterator` is not implemented for `&'a T` + = help: the trait `Iterator` is implemented for `&mut I` + = note: required for `&'a T` to implement `IntoIterator` +note: required by a bound in `Flatten` + --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/wf/hir-wf-check-erase-regions.rs b/tests/ui/wf/hir-wf-check-erase-regions.rs index 20cc1cfe730..ef9132697ef 100644 --- a/tests/ui/wf/hir-wf-check-erase-regions.rs +++ b/tests/ui/wf/hir-wf-check-erase-regions.rs @@ -1,6 +1,10 @@ // Regression test for #87549. //@ incremental +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius +//@ [polonius] compile-flags: -Zpolonius=next + pub struct Table<T, const N: usize>([Option<T>; N]); impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> { @@ -10,7 +14,7 @@ impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> { fn into_iter(self) -> Self::IntoIter { //~^ ERROR `&'a T` is not an iterator - //~| ERROR `&T` is not an iterator + //[nll]~| ERROR `&T` is not an iterator unimplemented!() } } |
