diff options
Diffstat (limited to 'tests')
21 files changed, 233 insertions, 61 deletions
diff --git a/tests/ui/async-await/feature-self-return-type.stderr b/tests/ui/async-await/feature-self-return-type.stderr index 8924683684f..747c54b6694 100644 --- a/tests/ui/async-await/feature-self-return-type.stderr +++ b/tests/ui/async-await/feature-self-return-type.stderr @@ -4,6 +4,7 @@ error[E0597]: `bar` does not live long enough LL | let x = { | - borrow later stored here LL | let bar = 22; + | --- binding `bar` declared here LL | Foo::new(&bar).await | ^^^^ borrowed value does not live long enough LL | diff --git a/tests/ui/async-await/issue-61949-self-return-type.stderr b/tests/ui/async-await/issue-61949-self-return-type.stderr index 638b197bc02..ac85ed2887a 100644 --- a/tests/ui/async-await/issue-61949-self-return-type.stderr +++ b/tests/ui/async-await/issue-61949-self-return-type.stderr @@ -13,6 +13,7 @@ error[E0597]: `bar` does not live long enough LL | let x = { | - borrow later stored here LL | let bar = 22; + | --- binding `bar` declared here LL | Foo::new(&bar).await | ^^^^ borrowed value does not live long enough LL | diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed b/tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed new file mode 100644 index 00000000000..4a8831dab95 --- /dev/null +++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed @@ -0,0 +1,39 @@ +// run-rustfix +#![allow(unused)] +struct S; + +impl S { + fn call(&mut self, f: impl FnOnce((), &mut Self)) { + // change state or something ... + f((), self); + // change state or something ... + } + + fn get(&self) {} + fn set(&mut self) {} +} + +fn main() { + let mut v = S; + + v.call(|(), this: &mut S| this.get()); + //~^ error: cannot borrow `v` as mutable because it is also borrowed as immutable + v.call(|(), this: &mut S| this.set()); + //~^ error: cannot borrow `v` as mutable more than once at a time + //~| error: cannot borrow `v` as mutable more than once at a time + + v.call(|(), this: &mut S| { + //~^ error: cannot borrow `v` as mutable more than once at a time + //~| error: cannot borrow `v` as mutable more than once at a time + + _ = this; + this.set(); + this.get(); + S::get(&this); + + use std::ops::Add; + let v = 0u32; + _ = v + v; + _ = v.add(3); + }); +} diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.rs b/tests/ui/borrowck/issue-109271-pass-self-into-closure.rs new file mode 100644 index 00000000000..fcd855f862d --- /dev/null +++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.rs @@ -0,0 +1,39 @@ +// run-rustfix +#![allow(unused)] +struct S; + +impl S { + fn call(&mut self, f: impl FnOnce((), &mut Self)) { + // change state or something ... + f((), self); + // change state or something ... + } + + fn get(&self) {} + fn set(&mut self) {} +} + +fn main() { + let mut v = S; + + v.call(|(), this: &mut S| v.get()); + //~^ error: cannot borrow `v` as mutable because it is also borrowed as immutable + v.call(|(), this: &mut S| v.set()); + //~^ error: cannot borrow `v` as mutable more than once at a time + //~| error: cannot borrow `v` as mutable more than once at a time + + v.call(|(), this: &mut S| { + //~^ error: cannot borrow `v` as mutable more than once at a time + //~| error: cannot borrow `v` as mutable more than once at a time + + _ = v; + v.set(); + v.get(); + S::get(&v); + + use std::ops::Add; + let v = 0u32; + _ = v + v; + _ = v.add(3); + }); +} diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr new file mode 100644 index 00000000000..25974e0d008 --- /dev/null +++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr @@ -0,0 +1,85 @@ +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable + --> $DIR/issue-109271-pass-self-into-closure.rs:19:5 + | +LL | v.call(|(), this: &mut S| v.get()); + | ^^----^------------------^-^^^^^^^ + | | | | | + | | | | first borrow occurs due to use of `v` in closure + | | | | help: try using the closure argument: `this` + | | | immutable borrow occurs here + | | immutable borrow later used by call + | mutable borrow occurs here + +error[E0499]: cannot borrow `v` as mutable more than once at a time + --> $DIR/issue-109271-pass-self-into-closure.rs:21:5 + | +LL | v.call(|(), this: &mut S| v.set()); + | ^^----^------------------^-^^^^^^^ + | | | | | + | | | | first borrow occurs due to use of `v` in closure + | | | | help: try using the closure argument: `this` + | | | first mutable borrow occurs here + | | first borrow later used by call + | second mutable borrow occurs here + +error[E0499]: cannot borrow `v` as mutable more than once at a time + --> $DIR/issue-109271-pass-self-into-closure.rs:21:12 + | +LL | v.call(|(), this: &mut S| v.set()); + | -------^^^^^^^^^^^^^^^^^^--------- + | | | | | + | | | | second borrow occurs due to use of `v` in closure + | | | second mutable borrow occurs here + | | first borrow later used by call + | first mutable borrow occurs here + +error[E0499]: cannot borrow `v` as mutable more than once at a time + --> $DIR/issue-109271-pass-self-into-closure.rs:25:5 + | +LL | v.call(|(), this: &mut S| { + | ^ ---- ------------------ first mutable borrow occurs here + | | | + | _____| first borrow later used by call + | | +LL | | +LL | | +LL | | +LL | | _ = v; +LL | | v.set(); + | | - first borrow occurs due to use of `v` in closure +... | +LL | | _ = v.add(3); +LL | | }); + | |______^ second mutable borrow occurs here + | +help: try using the closure argument + | +LL ~ _ = this; +LL ~ this.set(); +LL ~ this.get(); +LL ~ S::get(&this); + | + +error[E0499]: cannot borrow `v` as mutable more than once at a time + --> $DIR/issue-109271-pass-self-into-closure.rs:25:12 + | +LL | v.call(|(), this: &mut S| { + | - ---- ^^^^^^^^^^^^^^^^^^ second mutable borrow occurs here + | | | + | _____| first borrow later used by call + | | +LL | | +LL | | +LL | | +LL | | _ = v; +LL | | v.set(); + | | - second borrow occurs due to use of `v` in closure +... | +LL | | _ = v.add(3); +LL | | }); + | |______- first mutable borrow occurs here + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0499, E0502. +For more information about an error, try `rustc --explain E0499`. diff --git a/tests/ui/consts/const-eval/generic-slice.stderr b/tests/ui/consts/const-eval/generic-slice.stderr index c38088df4d8..ff1dc29ccfd 100644 --- a/tests/ui/consts/const-eval/generic-slice.stderr +++ b/tests/ui/consts/const-eval/generic-slice.stderr @@ -4,6 +4,8 @@ error[E0597]: `x` does not live long enough LL | impl<'a, T: 'static> Generic<'a, T> { | -- lifetime `'a` defined here ... +LL | let x: &'static [T] = &[]; + | - binding `x` declared here LL | &x | ^^ | | @@ -16,6 +18,8 @@ LL | }; error[E0597]: `x` does not live long enough --> $DIR/generic-slice.rs:27:5 | +LL | let x: &[_] = &[]; + | - binding `x` declared here LL | &x | ^^ | | diff --git a/tests/ui/generator/auto-trait-regions.drop_tracking.stderr b/tests/ui/generator/auto-trait-regions.drop_tracking.stderr index 165748d4430..b2a5b92ed0f 100644 --- a/tests/ui/generator/auto-trait-regions.drop_tracking.stderr +++ b/tests/ui/generator/auto-trait-regions.drop_tracking.stderr @@ -9,7 +9,11 @@ LL | let a = A(&mut true, &mut true, No); LL | assert_foo(a); | - borrow later used here | - = note: consider using a `let` binding to create a longer lived value +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = true; +LL ~ let a = A(&mut binding, &mut true, No); + | error[E0716]: temporary value dropped while borrowed --> $DIR/auto-trait-regions.rs:48:35 @@ -22,7 +26,11 @@ LL | let a = A(&mut true, &mut true, No); LL | assert_foo(a); | - borrow later used here | - = note: consider using a `let` binding to create a longer lived value +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = true; +LL ~ let a = A(&mut true, &mut binding, No); + | error: implementation of `Foo` is not general enough --> $DIR/auto-trait-regions.rs:34:5 diff --git a/tests/ui/generator/auto-trait-regions.drop_tracking_mir.stderr b/tests/ui/generator/auto-trait-regions.drop_tracking_mir.stderr index 165748d4430..b2a5b92ed0f 100644 --- a/tests/ui/generator/auto-trait-regions.drop_tracking_mir.stderr +++ b/tests/ui/generator/auto-trait-regions.drop_tracking_mir.stderr @@ -9,7 +9,11 @@ LL | let a = A(&mut true, &mut true, No); LL | assert_foo(a); | - borrow later used here | - = note: consider using a `let` binding to create a longer lived value +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = true; +LL ~ let a = A(&mut binding, &mut true, No); + | error[E0716]: temporary value dropped while borrowed --> $DIR/auto-trait-regions.rs:48:35 @@ -22,7 +26,11 @@ LL | let a = A(&mut true, &mut true, No); LL | assert_foo(a); | - borrow later used here | - = note: consider using a `let` binding to create a longer lived value +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = true; +LL ~ let a = A(&mut true, &mut binding, No); + | error: implementation of `Foo` is not general enough --> $DIR/auto-trait-regions.rs:34:5 diff --git a/tests/ui/generator/auto-trait-regions.no_drop_tracking.stderr b/tests/ui/generator/auto-trait-regions.no_drop_tracking.stderr index 165748d4430..b2a5b92ed0f 100644 --- a/tests/ui/generator/auto-trait-regions.no_drop_tracking.stderr +++ b/tests/ui/generator/auto-trait-regions.no_drop_tracking.stderr @@ -9,7 +9,11 @@ LL | let a = A(&mut true, &mut true, No); LL | assert_foo(a); | - borrow later used here | - = note: consider using a `let` binding to create a longer lived value +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = true; +LL ~ let a = A(&mut binding, &mut true, No); + | error[E0716]: temporary value dropped while borrowed --> $DIR/auto-trait-regions.rs:48:35 @@ -22,7 +26,11 @@ LL | let a = A(&mut true, &mut true, No); LL | assert_foo(a); | - borrow later used here | - = note: consider using a `let` binding to create a longer lived value +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = true; +LL ~ let a = A(&mut true, &mut binding, No); + | error: implementation of `Foo` is not general enough --> $DIR/auto-trait-regions.rs:34:5 diff --git a/tests/ui/generator/auto-trait-regions.stderr b/tests/ui/generator/auto-trait-regions.stderr deleted file mode 100644 index 165748d4430..00000000000 --- a/tests/ui/generator/auto-trait-regions.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error[E0716]: temporary value dropped while borrowed - --> $DIR/auto-trait-regions.rs:48:24 - | -LL | let a = A(&mut true, &mut true, No); - | ^^^^ - temporary value is freed at the end of this statement - | | - | creates a temporary value which is freed while still in use -... -LL | assert_foo(a); - | - borrow later used here - | - = note: consider using a `let` binding to create a longer lived value - -error[E0716]: temporary value dropped while borrowed - --> $DIR/auto-trait-regions.rs:48:35 - | -LL | let a = A(&mut true, &mut true, No); - | ^^^^ - temporary value is freed at the end of this statement - | | - | creates a temporary value which is freed while still in use -... -LL | assert_foo(a); - | - borrow later used here - | - = note: consider using a `let` binding to create a longer lived value - -error: implementation of `Foo` is not general enough - --> $DIR/auto-trait-regions.rs:34:5 - | -LL | assert_foo(gen); - | ^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough - | - = note: `&'0 OnlyFooIfStaticRef` must implement `Foo`, for any lifetime `'0`... - = note: ...but `Foo` is actually implemented for the type `&'static OnlyFooIfStaticRef` - -error: implementation of `Foo` is not general enough - --> $DIR/auto-trait-regions.rs:54:5 - | -LL | assert_foo(gen); - | ^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough - | - = note: `Foo` would have to be implemented for the type `A<'0, '1>`, for any two lifetimes `'0` and `'1`... - = note: ...but `Foo` is actually implemented for the type `A<'_, '2>`, for some specific lifetime `'2` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/lifetimes/issue-69314.stderr b/tests/ui/lifetimes/issue-69314.stderr index 7ae6789285b..3879f35505c 100644 --- a/tests/ui/lifetimes/issue-69314.stderr +++ b/tests/ui/lifetimes/issue-69314.stderr @@ -12,6 +12,8 @@ LL | async fn f2(m: Msg<'_>) {} error[E0597]: `buf` does not live long enough --> $DIR/issue-69314.rs:14:19 | +LL | let mut buf = [0; 512]; + | ------- binding `buf` declared here LL | let m2 = &buf[..]; | ^^^ borrowed value does not live long enough LL | let m = Self::g(m2).await; diff --git a/tests/ui/nll/user-annotations/adt-brace-enums.stderr b/tests/ui/nll/user-annotations/adt-brace-enums.stderr index 9e94fd5a782..900e7e25390 100644 --- a/tests/ui/nll/user-annotations/adt-brace-enums.stderr +++ b/tests/ui/nll/user-annotations/adt-brace-enums.stderr @@ -31,7 +31,9 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; | ^^ | | diff --git a/tests/ui/nll/user-annotations/adt-brace-structs.stderr b/tests/ui/nll/user-annotations/adt-brace-structs.stderr index cbb7f6a55a9..d61643dc6ed 100644 --- a/tests/ui/nll/user-annotations/adt-brace-structs.stderr +++ b/tests/ui/nll/user-annotations/adt-brace-structs.stderr @@ -31,7 +31,9 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here LL | SomeStruct::<&'a u32> { t: &c }; | ^^ | | diff --git a/tests/ui/nll/user-annotations/adt-nullary-enums.stderr b/tests/ui/nll/user-annotations/adt-nullary-enums.stderr index bca85a90d19..5b385feeedc 100644 --- a/tests/ui/nll/user-annotations/adt-nullary-enums.stderr +++ b/tests/ui/nll/user-annotations/adt-nullary-enums.stderr @@ -34,7 +34,10 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here +LL | combine( LL | SomeEnum::SomeVariant(Cell::new(&c)), | ----------^^- | | | diff --git a/tests/ui/nll/user-annotations/adt-tuple-enums.stderr b/tests/ui/nll/user-annotations/adt-tuple-enums.stderr index d2d85ec2b9b..766da9ec00c 100644 --- a/tests/ui/nll/user-annotations/adt-tuple-enums.stderr +++ b/tests/ui/nll/user-annotations/adt-tuple-enums.stderr @@ -31,7 +31,9 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here LL | SomeEnum::SomeVariant::<&'a u32>(&c); | ^^ | | diff --git a/tests/ui/nll/user-annotations/adt-tuple-struct-calls.stderr b/tests/ui/nll/user-annotations/adt-tuple-struct-calls.stderr index b7bc2a10b70..2084697e7e2 100644 --- a/tests/ui/nll/user-annotations/adt-tuple-struct-calls.stderr +++ b/tests/ui/nll/user-annotations/adt-tuple-struct-calls.stderr @@ -33,7 +33,10 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here +LL | let f = SomeStruct::<&'a u32>; LL | f(&c); | --^^- | | | @@ -47,7 +50,9 @@ error[E0597]: `c` does not live long enough | LL | let f = SomeStruct::<&'a u32>; | - lifetime `'1` appears in the type of `f` -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here LL | f(&c); | --^^- | | | diff --git a/tests/ui/nll/user-annotations/adt-tuple-struct.stderr b/tests/ui/nll/user-annotations/adt-tuple-struct.stderr index 97d39da265f..c7480f52963 100644 --- a/tests/ui/nll/user-annotations/adt-tuple-struct.stderr +++ b/tests/ui/nll/user-annotations/adt-tuple-struct.stderr @@ -31,7 +31,9 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here LL | SomeStruct::<&'a u32>(&c); | ^^ | | diff --git a/tests/ui/nll/user-annotations/fns.stderr b/tests/ui/nll/user-annotations/fns.stderr index 8b53e138d9b..abaa35e9516 100644 --- a/tests/ui/nll/user-annotations/fns.stderr +++ b/tests/ui/nll/user-annotations/fns.stderr @@ -31,7 +31,9 @@ error[E0597]: `c` does not live long enough | LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here -... +LL | let _closure = || { +LL | let c = 66; + | - binding `c` declared here LL | some_fn::<&'a u32>(&c); | -------------------^^- | | | diff --git a/tests/ui/nll/user-annotations/method-call.stderr b/tests/ui/nll/user-annotations/method-call.stderr index 3803cbf776b..b4d1ac042a2 100644 --- a/tests/ui/nll/user-annotations/method-call.stderr +++ b/tests/ui/nll/user-annotations/method-call.stderr @@ -33,6 +33,8 @@ error[E0597]: `c` does not live long enough LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here ... +LL | let c = 66; + | - binding `c` declared here LL | a.method::<&'a u32>(b, &c); | ------------------------^^- | | | diff --git a/tests/ui/nll/user-annotations/method-ufcs-3.stderr b/tests/ui/nll/user-annotations/method-ufcs-3.stderr index 8cb995a03ce..4dd39e10827 100644 --- a/tests/ui/nll/user-annotations/method-ufcs-3.stderr +++ b/tests/ui/nll/user-annotations/method-ufcs-3.stderr @@ -33,6 +33,8 @@ error[E0597]: `c` does not live long enough LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { | -- lifetime `'a` defined here ... +LL | let c = 66; + | - binding `c` declared here LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); | -------------------------------------------^^- | | | diff --git a/tests/ui/static/issue-18118.stderr b/tests/ui/static/issue-18118.stderr index 49798a148de..035be2b1202 100644 --- a/tests/ui/static/issue-18118.stderr +++ b/tests/ui/static/issue-18118.stderr @@ -1,6 +1,8 @@ error[E0597]: `p` does not live long enough --> $DIR/issue-18118.rs:4:9 | +LL | let p = 3; + | - binding `p` declared here LL | &p | ^^ | | |
