diff options
Diffstat (limited to 'tests/ui/borrowck')
29 files changed, 394 insertions, 358 deletions
diff --git a/tests/ui/borrowck/alias-liveness/escaping-bounds-2.rs b/tests/ui/borrowck/alias-liveness/escaping-bounds-2.rs new file mode 100644 index 000000000..05884f674 --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/escaping-bounds-2.rs @@ -0,0 +1,14 @@ +trait Trait { + type Gat<'a: 'b, 'b: 'c, 'c>: 'c; +} + +fn get_func<'a, T: Trait>(_: &'a str) -> fn(T::Gat<'a, '_, 'static>) { + loop {} +} + +fn test<T: Trait>() { + let func = get_func::<T>(&String::new()); //~ ERROR temporary value dropped + drop(func); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/escaping-bounds-2.stderr b/tests/ui/borrowck/alias-liveness/escaping-bounds-2.stderr new file mode 100644 index 000000000..7fd0cb9bb --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/escaping-bounds-2.stderr @@ -0,0 +1,19 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/escaping-bounds-2.rs:10:31 + | +LL | let func = get_func::<T>(&String::new()); + | ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | + | creates a temporary value which is freed while still in use +LL | drop(func); + | ---- borrow later used here + | +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = String::new(); +LL ~ let func = get_func::<T>(&binding); + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/borrowck/alias-liveness/escaping-bounds.rs b/tests/ui/borrowck/alias-liveness/escaping-bounds.rs new file mode 100644 index 000000000..3ccdc78e6 --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/escaping-bounds.rs @@ -0,0 +1,22 @@ +// check-pass + +// Ensure that we don't ICE when an alias that has escaping bound vars is +// required to be live. This is because the code that allows us to deduce an +// appropriate outlives bound for a given alias type (in this test, a +// projection) does not handle aliases with escaping bound vars. +// See <https://github.com/rust-lang/rust/issues/117455>. + +trait Foo { + type Assoc<'a, 'b>: 'static; +} + +struct MentionsLifetimeAndType<'a, T>(&'a (), T); + +fn foo<'a, 'b, T: Foo>(_: <T as Foo>::Assoc<'a, 'b>) {} + +fn test<'b, T: Foo>() { + let y: MentionsLifetimeAndType<'_, for<'a> fn(<T as Foo>::Assoc<'a, 'b>)> = + MentionsLifetimeAndType(&(), foo); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/gat-static.rs b/tests/ui/borrowck/alias-liveness/gat-static.rs new file mode 100644 index 000000000..92153124a --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/gat-static.rs @@ -0,0 +1,29 @@ +// check-pass + +trait Foo { + type Assoc<'a> + where + Self: 'a; + + fn assoc(&mut self) -> Self::Assoc<'_>; +} + +fn overlapping_mut<T>(mut t: T) +where + T: Foo, + for<'a> T::Assoc<'a>: 'static, +{ + let a = t.assoc(); + let b = t.assoc(); +} + +fn live_past_borrow<T>(mut t: T) +where + T: Foo, + for<'a> T::Assoc<'a>: 'static { + let x = t.assoc(); + drop(t); + drop(x); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.rs b/tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.rs new file mode 100644 index 000000000..1f26c7bab --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.rs @@ -0,0 +1,16 @@ +// known-bug: #42940 + +trait Captures<'a> {} +impl<T> Captures<'_> for T {} + +trait Outlives<'a>: 'a {} +impl<'a, T: 'a> Outlives<'a> for T {} + +// Test that we treat `for<'a> Opaque: 'a` as `Opaque: 'static` +fn test<'o>(v: &'o Vec<i32>) -> impl Captures<'o> + for<'a> Outlives<'a> {} + +fn statik() -> impl Sized { + test(&vec![]) +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.stderr b/tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.stderr new file mode 100644 index 000000000..58a42d8af --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.stderr @@ -0,0 +1,16 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/higher-ranked-outlives-for-capture.rs:13:11 + | +LL | test(&vec![]) + | ------^^^^^^- + | | | + | | creates a temporary value which is freed while still in use + | argument requires that borrow lasts for `'static` +LL | } + | - temporary value is freed at the end of this statement + | + = note: this error originates in the macro `vec` (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 E0716`. diff --git a/tests/ui/borrowck/alias-liveness/higher-ranked.rs b/tests/ui/borrowck/alias-liveness/higher-ranked.rs new file mode 100644 index 000000000..afd0d3b31 --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/higher-ranked.rs @@ -0,0 +1,16 @@ +// check-pass + +trait Captures<'a> {} +impl<T> Captures<'_> for T {} + +trait Outlives<'a>: 'a {} +impl<'a, T: 'a> Outlives<'a> for T {} + +// Test that we treat `for<'a> Opaque: 'a` as `Opaque: 'static` +fn test<'o>(v: &'o Vec<i32>) -> impl Captures<'o> + for<'a> Outlives<'a> {} + +fn opaque_doesnt_use_temporary() { + let a = test(&vec![]); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/opaque-capture.rs b/tests/ui/borrowck/alias-liveness/opaque-capture.rs new file mode 100644 index 000000000..f4ca2728b --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/opaque-capture.rs @@ -0,0 +1,17 @@ +// check-pass + +// Check that opaques capturing early and late-bound vars correctly mark +// regions required to be live using the item bounds. + +trait Captures<'a> {} +impl<T> Captures<'_> for T {} + +fn captures_temp_late<'a>(x: &'a Vec<i32>) -> impl Sized + Captures<'a> + 'static {} +fn captures_temp_early<'a: 'a>(x: &'a Vec<i32>) -> impl Sized + Captures<'a> + 'static {} + +fn test() { + let x = captures_temp_early(&vec![]); + let y = captures_temp_late(&vec![]); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/opaque-type-param.rs b/tests/ui/borrowck/alias-liveness/opaque-type-param.rs new file mode 100644 index 000000000..a292463b2 --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/opaque-type-param.rs @@ -0,0 +1,14 @@ +// known-bug: #42940 + +trait Trait {} +impl Trait for () {} + +fn foo<'a>(s: &'a str) -> impl Trait + 'static { + bar(s) +} + +fn bar<P: AsRef<str>>(s: P) -> impl Trait + 'static { + () +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/opaque-type-param.stderr b/tests/ui/borrowck/alias-liveness/opaque-type-param.stderr new file mode 100644 index 000000000..e1fbbc14f --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/opaque-type-param.stderr @@ -0,0 +1,13 @@ +error[E0700]: hidden type for `impl Trait + 'static` captures lifetime that does not appear in bounds + --> $DIR/opaque-type-param.rs:7:5 + | +LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static { + | -- -------------------- opaque type defined here + | | + | hidden type `impl Trait + 'static` captures the lifetime `'a` as defined here +LL | bar(s) + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0700`. diff --git a/tests/ui/borrowck/alias-liveness/rpit-static.rs b/tests/ui/borrowck/alias-liveness/rpit-static.rs new file mode 100644 index 000000000..45da3edb8 --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/rpit-static.rs @@ -0,0 +1,22 @@ +// check-pass + +trait Captures<'a> {} +impl<T> Captures<'_> for T {} + +fn foo(x: &mut i32) -> impl Sized + Captures<'_> + 'static {} + +fn overlapping_mut() { + let i = &mut 1; + let x = foo(i); + let y = foo(i); +} + +fn live_past_borrow() { + let y; + { + let x = &mut 1; + y = foo(x); + } +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/rpitit-static.rs b/tests/ui/borrowck/alias-liveness/rpitit-static.rs new file mode 100644 index 000000000..2cc68d2bf --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/rpitit-static.rs @@ -0,0 +1,18 @@ +// check-pass + +trait Foo { + fn rpitit(&mut self) -> impl Sized + 'static; +} + +fn live_past_borrow<T: Foo>(mut t: T) { + let x = t.rpitit(); + drop(t); + drop(x); +} + +fn overlapping_mut<T: Foo>(mut t: T) { + let a = t.rpitit(); + let b = t.rpitit(); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/rtn-static.rs b/tests/ui/borrowck/alias-liveness/rtn-static.rs new file mode 100644 index 000000000..1f136b8b9 --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/rtn-static.rs @@ -0,0 +1,23 @@ +// check-pass + +#![feature(return_type_notation)] +//~^ WARN the feature `return_type_notation` is incomplete + +trait Foo { + fn borrow(&mut self) -> impl Sized + '_; +} + +fn live_past_borrow<T: Foo<borrow(): 'static>>(mut t: T) { + let x = t.borrow(); + drop(t); + drop(x); +} + +// Test that the `'_` item bound in `borrow` does not cause us to +// overlook the `'static` RTN bound. +fn overlapping_mut<T: Foo<borrow(): 'static>>(mut t: T) { + let x = t.borrow(); + let x = t.borrow(); +} + +fn main() {} diff --git a/tests/ui/borrowck/alias-liveness/rtn-static.stderr b/tests/ui/borrowck/alias-liveness/rtn-static.stderr new file mode 100644 index 000000000..e9202db2c --- /dev/null +++ b/tests/ui/borrowck/alias-liveness/rtn-static.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/rtn-static.rs:3: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/borrowck/borrowck-move-out-from-array-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-match.rs index ced4d002b..d2a5da66d 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-match.rs @@ -42,8 +42,8 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _, _] => {} + //~^ ERROR use of partially moved value } } @@ -53,8 +53,8 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR use of partially moved value [_, _, _y @ ..] => {} + //~^ ERROR use of partially moved value } } @@ -64,8 +64,8 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _, _] => {} + //~^ ERROR use of partially moved value } } @@ -75,8 +75,8 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [_, _, _y @ ..] => {} + //~^ ERROR use of partially moved value } } @@ -108,8 +108,8 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} + //~^ ERROR use of partially moved value } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr index 67b00c1dd..d82777684 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr +++ b/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr @@ -44,13 +44,13 @@ LL | [_, _, (ref _x, _)] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:44:11 + --> $DIR/borrowck-move-out-from-array-match.rs:45:10 | LL | [_x, _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_y @ .., _, _] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -59,13 +59,13 @@ LL | [ref _x, _, _] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:55:11 + --> $DIR/borrowck-move-out-from-array-match.rs:56:16 | LL | [.., _x] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, _y @ ..] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -74,13 +74,13 @@ LL | [.., ref _x] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:66:11 + --> $DIR/borrowck-move-out-from-array-match.rs:67:10 | LL | [(_x, _), _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_y @ .., _, _] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -89,13 +89,13 @@ LL | [(ref _x, _), _, _] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:77:11 + --> $DIR/borrowck-move-out-from-array-match.rs:78:16 | LL | [.., (_x, _)] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, _y @ ..] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -134,13 +134,13 @@ LL | [_, _, ref _y @ ..] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:110:11 + --> $DIR/borrowck-move-out-from-array-match.rs:111:13 | LL | [x @ .., _] => {} | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _y @ ..] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs index 97db70f34..1e401b7e9 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs @@ -1,3 +1,4 @@ +// check-pass // Due to #53114, which causes a "read" of the `_` patterns, // the borrow-checker refuses this code, while it should probably be allowed. // Once the bug is fixed, the test, which is derived from a @@ -15,7 +16,6 @@ fn move_out_from_begin_and_one_from_end() { [_, _, _x] => {} } match a { - //~^ ERROR use of partially moved value [.., _y, _] => {} } } @@ -26,7 +26,6 @@ fn move_out_from_begin_field_and_end_field() { [_, _, (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [.., (_, _y)] => {} } } @@ -39,7 +38,6 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} } } @@ -50,7 +48,6 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _] => {} } } @@ -61,7 +58,6 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} } } @@ -72,7 +68,6 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _] => {} } } @@ -83,7 +78,6 @@ fn move_out_by_const_subslice_and_index_field() { [_, _y @ ..] => {} } match a { - //~^ ERROR use of partially moved value [(_x, _), _, _] => {} } } @@ -94,7 +88,6 @@ fn move_out_by_const_subslice_and_end_index_field() { [_y @ .., _] => {} } match a { - //~^ ERROR use of partially moved value [.., (_x, _)] => {} } } @@ -107,7 +100,6 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr deleted file mode 100644 index 47429ea3e..000000000 --- a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:17:11 - | -LL | [_, _, _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:28:11 - | -LL | [_, _, (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:41:11 - | -LL | [_x, _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _x, _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:52:11 - | -LL | [.., _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:63:11 - | -LL | [(_x, _), _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [(ref _x, _), _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:74:11 - | -LL | [.., (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:85:11 - | -LL | [_, _y @ ..] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, ref _y @ ..] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:96:11 - | -LL | [_y @ .., _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _y @ .., _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:109:11 - | -LL | [x @ .., _, _] => {} - | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref x @ .., _, _] => {} - | +++ - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs index 604a25cdc..fbcf126f3 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs @@ -42,8 +42,8 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR [E0382] [ref _y @ .., _, _] => {} + //~^ ERROR [E0382] } } @@ -53,8 +53,8 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR [E0382] [_, _, ref _y @ ..] => {} + //~^ ERROR [E0382] } } @@ -64,8 +64,8 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR [E0382] [ref _y @ .., _, _] => {} + //~^ ERROR [E0382] } } @@ -75,8 +75,8 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR [E0382] [_, _, ref _y @ ..] => {} + //~^ ERROR [E0382] } } @@ -108,8 +108,8 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _] => {} } match a { - //~^ ERROR [E0382] [_, ref _y @ ..] => {} + //~^ ERROR [E0382] } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr index bfab13d42..da76b5c4a 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr +++ b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr @@ -43,14 +43,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [_, _, (ref _x, _)] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:44:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:45:10 | LL | [_x, _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [ref _y @ .., _, _] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -58,14 +58,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [ref _x, _, _] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:55:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:56:16 | LL | [.., _x] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, ref _y @ ..] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -73,14 +73,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [.., ref _x] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:66:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:67:10 | LL | [(_x, _), _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [ref _y @ .., _, _] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -88,14 +88,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [(ref _x, _), _, _] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:77:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:78:16 | LL | [.., (_x, _)] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, ref _y @ ..] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -133,14 +133,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [_, _, ref _y @ ..] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:110:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:111:13 | LL | [x @ .., _] => {} | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, ref _y @ ..] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs index 017ca90b8..2f6ce430b 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs @@ -1,3 +1,4 @@ +// check-pass // Due to #53114, which causes a "read" of the `_` patterns, // the borrow-checker refuses this code, while it should probably be allowed. // Once the bug is fixed, the test, which is derived from a @@ -15,7 +16,6 @@ fn move_out_from_begin_and_one_from_end() { [_, _, _x] => {} } match a { - //~^ ERROR use of partially moved value [.., ref _y, _] => {} } } @@ -26,7 +26,6 @@ fn move_out_from_begin_field_and_end_field() { [_, _, (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [.., (_, ref _y)] => {} } } @@ -39,7 +38,6 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, ref _y @ ..] => {} } } @@ -50,7 +48,6 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR use of partially moved value [ref _y @ .., _] => {} } } @@ -61,7 +58,6 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, ref _y @ ..] => {} } } @@ -72,7 +68,6 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [ref _y @ .., _] => {} } } @@ -83,7 +78,6 @@ fn move_out_by_const_subslice_and_index_field() { [_, _y @ ..] => {} } match a { - //~^ ERROR use of partially moved value [(ref _x, _), _, _] => {} } } @@ -94,7 +88,6 @@ fn move_out_by_const_subslice_and_end_index_field() { [_y @ .., _] => {} } match a { - //~^ ERROR use of partially moved value [.., (ref _x, _)] => {} } } @@ -107,7 +100,6 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, ref _y @ ..] => {} } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr deleted file mode 100644 index 8412c24fe..000000000 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:17:11 - | -LL | [_, _, _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:28:11 - | -LL | [_, _, (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:41:11 - | -LL | [_x, _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _x, _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:52:11 - | -LL | [.., _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:63:11 - | -LL | [(_x, _), _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [(ref _x, _), _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:74:11 - | -LL | [.., (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:85:11 - | -LL | [_, _y @ ..] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, ref _y @ ..] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:96:11 - | -LL | [_y @ .., _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _y @ .., _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:109:11 - | -LL | [x @ .., _, _] => {} - | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref x @ .., _, _] => {} - | +++ - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/borrowck/issue-62107-match-arm-scopes.rs b/tests/ui/borrowck/issue-62107-match-arm-scopes.rs index 93ce34d2f..7dbcad9d3 100644 --- a/tests/ui/borrowck/issue-62107-match-arm-scopes.rs +++ b/tests/ui/borrowck/issue-62107-match-arm-scopes.rs @@ -1,8 +1,8 @@ fn main() { let e: i32; match e { - //~^ ERROR E0381 ref u if true => {} + //~^ ERROR E0381 ref v if true => { let tx = 0; &tx; diff --git a/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr b/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr index 9683da919..8fe8fa710 100644 --- a/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr +++ b/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr @@ -1,10 +1,11 @@ error[E0381]: used binding `e` isn't initialized - --> $DIR/issue-62107-match-arm-scopes.rs:3:11 + --> $DIR/issue-62107-match-arm-scopes.rs:4:9 | LL | let e: i32; | - binding declared here but left uninitialized LL | match e { - | ^ `e` used here but it isn't initialized +LL | ref u if true => {} + | ^^^^^ `e` used here but it isn't initialized | help: consider assigning a value | diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs index d067ff447..b52939ffc 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs @@ -13,10 +13,10 @@ impl MarketMultiplier { } } -async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { +async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument was supplied //~^^ ERROR struct takes 1 generic argument but 0 generic arguments were supplied - LockedMarket(generator.lock().unwrap().buy()) + LockedMarket(coroutine.lock().unwrap().buy()) } struct LockedMarket<T>(T); diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index 73e0aaf1e..516c1d065 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -1,7 +1,7 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | -LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { +LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { | ^^^^^^^^^^^^---- help: remove these generics | | | expected 0 lifetime arguments @@ -15,7 +15,7 @@ LL | struct LockedMarket<T>(T); error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | -LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { +LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { | ^^^^^^^^^^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` @@ -25,7 +25,7 @@ LL | struct LockedMarket<T>(T); | ^^^^^^^^^^^^ - help: add missing generic argument | -LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_, T> { +LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_, T> { | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/borrowck/let_underscore_temporary.rs b/tests/ui/borrowck/let_underscore_temporary.rs index 835cd2079..a5ea3b3a7 100644 --- a/tests/ui/borrowck/let_underscore_temporary.rs +++ b/tests/ui/borrowck/let_underscore_temporary.rs @@ -52,4 +52,42 @@ fn let_ascribe(string: &Option<&str>, mut num: Option<i32>) { }; } +fn matched(string: &Option<&str>, mut num: Option<i32>) { + match if let Some(s) = *string { s.len() } else { 0 } { + _ => {} + }; + match if let Some(s) = &num { s } else { &0 } { + _ => {} + }; + match if let Some(s) = &mut num { + *s += 1; + s + } else { + &mut 0 + //~^ ERROR temporary value dropped while borrowed + } { + _ => {} + }; + match if let Some(ref s) = num { s } else { &0 } { + _ => {} + }; + match if let Some(mut s) = num { + s += 1; + s + } else { + 0 + } { + _ => {} + }; + match if let Some(ref mut s) = num { + *s += 1; + s + } else { + &mut 0 + //~^ ERROR temporary value dropped while borrowed + } { + _ => {} + }; +} + fn main() {} diff --git a/tests/ui/borrowck/let_underscore_temporary.stderr b/tests/ui/borrowck/let_underscore_temporary.stderr index 74f3598c4..6bccf3291 100644 --- a/tests/ui/borrowck/let_underscore_temporary.stderr +++ b/tests/ui/borrowck/let_underscore_temporary.stderr @@ -74,6 +74,44 @@ LL | | }; | = note: consider using a `let` binding to create a longer lived value -error: aborting due to 4 previous errors +error[E0716]: temporary value dropped while borrowed + --> $DIR/let_underscore_temporary.rs:66:14 + | +LL | match if let Some(s) = &mut num { + | ___________- +LL | | *s += 1; +LL | | s +LL | | } else { +LL | | &mut 0 + | | ^ creates a temporary value which is freed while still in use +LL | | +LL | | } { + | | - + | | | + | |_____temporary value is freed at the end of this statement + | borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error[E0716]: temporary value dropped while borrowed + --> $DIR/let_underscore_temporary.rs:86:14 + | +LL | match if let Some(ref mut s) = num { + | ___________- +LL | | *s += 1; +LL | | s +LL | | } else { +LL | | &mut 0 + | | ^ creates a temporary value which is freed while still in use +LL | | +LL | | } { + | | - + | | | + | |_____temporary value is freed at the end of this statement + | borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/borrowck/regions-bound-missing-bound-in-impl.stderr b/tests/ui/borrowck/regions-bound-missing-bound-in-impl.stderr index 930fea915..7ebea3c03 100644 --- a/tests/ui/borrowck/regions-bound-missing-bound-in-impl.stderr +++ b/tests/ui/borrowck/regions-bound-missing-bound-in-impl.stderr @@ -53,6 +53,7 @@ note: ...does not necessarily outlive the lifetime `'c` as defined here | LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { | ^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration --> $DIR/regions-bound-missing-bound-in-impl.rs:42:20 |