diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
commit | 4f9fe856a25ab29345b90e7725509e9ee38a37be (patch) | |
tree | e4ffd8a9374cae7b21f7cbfb352927e0e074aff6 /tests/ui/regions | |
parent | Adding upstream version 1.68.2+dfsg1. (diff) | |
download | rustc-4f9fe856a25ab29345b90e7725509e9ee38a37be.tar.xz rustc-4f9fe856a25ab29345b90e7725509e9ee38a37be.zip |
Adding upstream version 1.69.0+dfsg1.upstream/1.69.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/regions')
25 files changed, 142 insertions, 24 deletions
diff --git a/tests/ui/regions/do-not-suggest-adding-bound-to-opaque-type.stderr b/tests/ui/regions/do-not-suggest-adding-bound-to-opaque-type.stderr index 6ea238f30..d76a83b02 100644 --- a/tests/ui/regions/do-not-suggest-adding-bound-to-opaque-type.stderr +++ b/tests/ui/regions/do-not-suggest-adding-bound-to-opaque-type.stderr @@ -1,6 +1,8 @@ error[E0597]: `x` does not live long enough --> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:9:7 | +LL | let x = (); + | - binding `x` declared here LL | S(&x) | --^^- | | | diff --git a/tests/ui/regions/higher-ranked-implied.rs b/tests/ui/regions/higher-ranked-implied.rs new file mode 100644 index 000000000..103884c50 --- /dev/null +++ b/tests/ui/regions/higher-ranked-implied.rs @@ -0,0 +1,14 @@ +// FIXME: This test should pass as the first two fields add implied bounds that +// `'a` is equal to `'b` while the last one should simply use that fact. With +// the current implementation this errors. We have to be careful as implied bounds +// are only sound if they're also correctly checked. + +struct Inv<T>(*mut T); // `T` is invariant. +type A = for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>); +type B = for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>); + +fn main() { + let x: A = |_, _, _| (); + let y: B = x; //~ ERROR mismatched types + let _: A = y; //~ ERROR mismatched types +} diff --git a/tests/ui/regions/higher-ranked-implied.stderr b/tests/ui/regions/higher-ranked-implied.stderr new file mode 100644 index 000000000..9d80eacd7 --- /dev/null +++ b/tests/ui/regions/higher-ranked-implied.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/higher-ranked-implied.rs:12:16 + | +LL | let y: B = x; + | ^ one type is more general than the other + | + = note: expected fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>)` + found fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>)` + +error[E0308]: mismatched types + --> $DIR/higher-ranked-implied.rs:13:16 + | +LL | let _: A = y; + | ^ one type is more general than the other + | + = note: expected fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>)` + found fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>)` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/regions/issue-102374.stderr b/tests/ui/regions/issue-102374.stderr index 157850693..af64b6867 100644 --- a/tests/ui/regions/issue-102374.stderr +++ b/tests/ui/regions/issue-102374.stderr @@ -7,7 +7,7 @@ LL | f | ^ expected `i32`, found fn pointer | = note: expected type `i32` - found fn pointer `for<'z1, 'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, 'n, 'o, 'p, 'q, 'r, 's, 't, 'u, 'v, 'w, 'x, 'y, 'z, 'z0> fn(Cell<...>)` + found fn pointer `fn(Cell<...>)` the full type name has been written to '$TEST_BUILD_DIR/regions/issue-102374/issue-102374.long-type-hash.txt' error: aborting due to previous error diff --git a/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr b/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr index 3b62c7b61..bb5bc6f66 100644 --- a/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr +++ b/tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr @@ -6,6 +6,7 @@ LL | let _: fn(&mut &isize, &mut &isize) = a; | = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)` found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}` + = note: when the arguments and return types match, functions can be coerced to function pointers error: aborting due to previous error diff --git a/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr b/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr index 8a18a234b..dbe9e9b1a 100644 --- a/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr +++ b/tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr @@ -6,6 +6,7 @@ LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; | = note: expected fn pointer `for<'a, 'b, 'c, 'd, 'e, 'f> fn(&'a mut &'b isize, &'c mut &'d isize, &'e mut &'f isize)` found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a::<'_, '_, '_>}` + = note: when the arguments and return types match, functions can be coerced to function pointers error: aborting due to previous error diff --git a/tests/ui/regions/regions-addr-of-arg.stderr b/tests/ui/regions/regions-addr-of-arg.stderr index e77289287..99060a9c7 100644 --- a/tests/ui/regions/regions-addr-of-arg.stderr +++ b/tests/ui/regions/regions-addr-of-arg.stderr @@ -1,6 +1,8 @@ error[E0597]: `a` does not live long enough --> $DIR/regions-addr-of-arg.rs:5:30 | +LL | fn foo(a: isize) { + | - binding `a` declared here LL | let _p: &'static isize = &a; | -------------- ^^ borrowed value does not live long enough | | diff --git a/tests/ui/regions/regions-early-bound-error-method.stderr b/tests/ui/regions/regions-early-bound-error-method.stderr index 7f10c051f..a7746d898 100644 --- a/tests/ui/regions/regions-early-bound-error-method.stderr +++ b/tests/ui/regions/regions-early-bound-error-method.stderr @@ -6,7 +6,7 @@ LL | impl<'a> Box<'a> { LL | fn or<'b,G:GetRef<'b>>(&self, g2: G) -> &'a isize { | -- lifetime `'b` defined here LL | g2.get() - | ^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | ^^^^^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` | = help: consider adding the following bound: `'b: 'a` diff --git a/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr b/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr index 8d82ff958..766a3d033 100644 --- a/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr +++ b/tests/ui/regions/regions-fn-subtyping-return-static-fail.stderr @@ -8,6 +8,7 @@ LL | want_G(baz); | = note: expected fn pointer `for<'cx> fn(&'cx S) -> &'static S` found fn item `for<'a> fn(&'a S) -> &'a S {baz}` + = note: when the arguments and return types match, functions can be coerced to function pointers note: function defined here --> $DIR/regions-fn-subtyping-return-static-fail.rs:20:4 | diff --git a/tests/ui/regions/regions-free-region-ordering-caller1.stderr b/tests/ui/regions/regions-free-region-ordering-caller1.stderr index 8ef7e2253..c83cfc1c9 100644 --- a/tests/ui/regions/regions-free-region-ordering-caller1.stderr +++ b/tests/ui/regions/regions-free-region-ordering-caller1.stderr @@ -18,6 +18,8 @@ error[E0597]: `y` does not live long enough LL | fn call1<'a>(x: &'a usize) { | -- lifetime `'a` defined here ... +LL | let y: usize = 3; + | - binding `y` declared here LL | let z: &'a & usize = &(&y); | ----------- ^^^^ borrowed value does not live long enough | | diff --git a/tests/ui/regions/regions-free-region-ordering-incorrect.stderr b/tests/ui/regions/regions-free-region-ordering-incorrect.stderr index f7c75033c..d0ceaec3b 100644 --- a/tests/ui/regions/regions-free-region-ordering-incorrect.stderr +++ b/tests/ui/regions/regions-free-region-ordering-incorrect.stderr @@ -9,7 +9,7 @@ LL | / match self.next { LL | | Some(ref next) => next.get(), LL | | None => &self.val LL | | } - | |_________^ associated function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | |_________^ method was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` diff --git a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs index 7c2e1aeee..46462c432 100644 --- a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs +++ b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs @@ -8,6 +8,8 @@ // // 'a : 'b +#![warn(unused_lifetimes)] + fn test<'a,'b>(x: &'a i32) -> &'b i32 where 'a: 'static //~ WARN unnecessary lifetime parameter `'a` { diff --git a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr index 70ed418d5..9f03a6553 100644 --- a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr +++ b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr @@ -1,10 +1,15 @@ warning: unnecessary lifetime parameter `'a` - --> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:12:11 + --> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:14:11 | LL | where 'a: 'static | ^^ | = help: you can use the `'static` lifetime directly, in place of `'a` +note: the lint level is defined here + --> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:11:9 + | +LL | #![warn(unused_lifetimes)] + | ^^^^^^^^^^^^^^^^ warning: 1 warning emitted diff --git a/tests/ui/regions/regions-infer-proc-static-upvar.stderr b/tests/ui/regions/regions-infer-proc-static-upvar.stderr index 803d0d744..c8a33bbc5 100644 --- a/tests/ui/regions/regions-infer-proc-static-upvar.stderr +++ b/tests/ui/regions/regions-infer-proc-static-upvar.stderr @@ -1,6 +1,8 @@ error[E0597]: `x` does not live long enough --> $DIR/regions-infer-proc-static-upvar.rs:10:13 | +LL | let x = 3; + | - binding `x` declared here LL | let y = &x; | ^^ borrowed value does not live long enough LL | / foo(move|| { diff --git a/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr b/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr index 17a901943..df0fd069e 100644 --- a/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr +++ b/tests/ui/regions/regions-lifetime-bounds-on-fns.stderr @@ -6,6 +6,7 @@ LL | let _: fn(&mut &isize, &mut &isize) = a; | = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)` found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}` + = note: when the arguments and return types match, functions can be coerced to function pointers error: aborting due to previous error diff --git a/tests/ui/regions/regions-mock-codegen.rs b/tests/ui/regions/regions-mock-codegen.rs index 9d0ca76e4..d5c93f81f 100644 --- a/tests/ui/regions/regions-mock-codegen.rs +++ b/tests/ui/regions/regions-mock-codegen.rs @@ -22,15 +22,15 @@ struct Ccx { x: isize, } -fn allocate(_bcx: &arena) -> &Bcx<'_> { +fn allocate(_bcx: &arena) -> &mut Bcx<'_> { unsafe { let layout = Layout::new::<Bcx>(); let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout)); - &*(ptr.as_ptr() as *const _) + &mut *ptr.as_ptr().cast() } } -fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> { +fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> { return allocate(bcx.fcx.arena); } @@ -38,7 +38,7 @@ fn g(fcx: &Fcx) { let bcx = Bcx { fcx }; let bcx2 = h(&bcx); unsafe { - Global.deallocate(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>()); + Global.deallocate(NonNull::new_unchecked(bcx2 as *mut _ as *mut _), Layout::new::<Bcx>()); } } diff --git a/tests/ui/regions/regions-nested-fns.stderr b/tests/ui/regions/regions-nested-fns.stderr index bb2740310..ee43f9fa5 100644 --- a/tests/ui/regions/regions-nested-fns.stderr +++ b/tests/ui/regions/regions-nested-fns.stderr @@ -13,6 +13,8 @@ LL | ay = z; error[E0597]: `y` does not live long enough --> $DIR/regions-nested-fns.rs:5:18 | +LL | let y = 3; + | - binding `y` declared here LL | let mut ay = &y; | ^^ borrowed value does not live long enough ... diff --git a/tests/ui/regions/regions-pattern-typing-issue-19552.stderr b/tests/ui/regions/regions-pattern-typing-issue-19552.stderr index f77d94a24..18aec29ad 100644 --- a/tests/ui/regions/regions-pattern-typing-issue-19552.stderr +++ b/tests/ui/regions/regions-pattern-typing-issue-19552.stderr @@ -1,6 +1,8 @@ error[E0597]: `line` does not live long enough --> $DIR/regions-pattern-typing-issue-19552.rs:5:14 | +LL | let line = String::new(); + | ---- binding `line` declared here LL | match [&*line] { | ^^^^ borrowed value does not live long enough LL | [ word ] => { assert_static(word); } diff --git a/tests/ui/regions/regions-pattern-typing-issue-19997.stderr b/tests/ui/regions/regions-pattern-typing-issue-19997.stderr index ae60e3c0d..0abe77a86 100644 --- a/tests/ui/regions/regions-pattern-typing-issue-19997.stderr +++ b/tests/ui/regions/regions-pattern-typing-issue-19997.stderr @@ -2,10 +2,10 @@ error[E0506]: cannot assign to `a1` because it is borrowed --> $DIR/regions-pattern-typing-issue-19997.rs:7:13 | LL | match (&a1,) { - | --- borrow of `a1` occurs here + | --- `a1` is borrowed here LL | (&ref b0,) => { LL | a1 = &f; - | ^^^^^^^ assignment to borrowed `a1` occurs here + | ^^^^^^^ `a1` is assigned to here but it was already borrowed LL | drop(b0); | -- borrow later used here diff --git a/tests/ui/regions/regions-static-bound-rpass.rs b/tests/ui/regions/regions-static-bound-rpass.rs index 25232b455..e2ebb394d 100644 --- a/tests/ui/regions/regions-static-bound-rpass.rs +++ b/tests/ui/regions/regions-static-bound-rpass.rs @@ -1,5 +1,7 @@ // run-pass +#![warn(unused_lifetimes)] + fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a () where 'a: 'static { t } //~^ WARN unnecessary lifetime parameter `'a` diff --git a/tests/ui/regions/regions-static-bound-rpass.stderr b/tests/ui/regions/regions-static-bound-rpass.stderr index 9355a409d..f0f3a4c52 100644 --- a/tests/ui/regions/regions-static-bound-rpass.stderr +++ b/tests/ui/regions/regions-static-bound-rpass.stderr @@ -1,13 +1,18 @@ warning: unnecessary lifetime parameter `'a` - --> $DIR/regions-static-bound-rpass.rs:4:11 + --> $DIR/regions-static-bound-rpass.rs:6:11 | LL | where 'a: 'static { t } | ^^ | = help: you can use the `'static` lifetime directly, in place of `'a` +note: the lint level is defined here + --> $DIR/regions-static-bound-rpass.rs:3:9 + | +LL | #![warn(unused_lifetimes)] + | ^^^^^^^^^^^^^^^^ warning: unnecessary lifetime parameter `'a` - --> $DIR/regions-static-bound-rpass.rs:8:11 + --> $DIR/regions-static-bound-rpass.rs:10:11 | LL | where 'a: 'static { t } | ^^ @@ -15,7 +20,7 @@ LL | where 'a: 'static { t } = help: you can use the `'static` lifetime directly, in place of `'a` warning: unnecessary lifetime parameter `'b` - --> $DIR/regions-static-bound-rpass.rs:12:19 + --> $DIR/regions-static-bound-rpass.rs:14:19 | LL | where 'a: 'b, 'b: 'static { t } | ^^ diff --git a/tests/ui/regions/regions-static-bound.rs b/tests/ui/regions/regions-static-bound.rs index 4d2455470..e7aa8795f 100644 --- a/tests/ui/regions/regions-static-bound.rs +++ b/tests/ui/regions/regions-static-bound.rs @@ -1,6 +1,8 @@ -fn static_id<'a,'b>(t: &'a ()) -> &'static () - where 'a: 'static { t } -//~^ WARN unnecessary lifetime parameter `'a` +#![warn(unused_lifetimes)] + +fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t } +//~^ WARN lifetime parameter `'b` never used +//~| WARN unnecessary lifetime parameter `'a` fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static () where 'a: 'b, 'b: 'static { t } diff --git a/tests/ui/regions/regions-static-bound.stderr b/tests/ui/regions/regions-static-bound.stderr index 2886ec3ea..b314e9fe8 100644 --- a/tests/ui/regions/regions-static-bound.stderr +++ b/tests/ui/regions/regions-static-bound.stderr @@ -1,13 +1,27 @@ +warning: lifetime parameter `'b` never used + --> $DIR/regions-static-bound.rs:3:17 + | +LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t } + | -^^ + | | + | help: elide the unused lifetime + | +note: the lint level is defined here + --> $DIR/regions-static-bound.rs:1:9 + | +LL | #![warn(unused_lifetimes)] + | ^^^^^^^^^^^^^^^^ + warning: unnecessary lifetime parameter `'a` - --> $DIR/regions-static-bound.rs:2:11 + --> $DIR/regions-static-bound.rs:3:53 | -LL | where 'a: 'static { t } - | ^^ +LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t } + | ^^ | = help: you can use the `'static` lifetime directly, in place of `'a` warning: unnecessary lifetime parameter `'b` - --> $DIR/regions-static-bound.rs:6:19 + --> $DIR/regions-static-bound.rs:8:19 | LL | where 'a: 'b, 'b: 'static { t } | ^^ @@ -15,7 +29,7 @@ LL | where 'a: 'b, 'b: 'static { t } = help: you can use the `'static` lifetime directly, in place of `'b` error: lifetime may not live long enough - --> $DIR/regions-static-bound.rs:10:5 + --> $DIR/regions-static-bound.rs:12:5 | LL | fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a { | -- lifetime `'a` defined here @@ -23,7 +37,7 @@ LL | t | ^ returning this value requires that `'a` must outlive `'static` error[E0521]: borrowed data escapes outside of function - --> $DIR/regions-static-bound.rs:15:5 + --> $DIR/regions-static-bound.rs:17:5 | LL | fn error(u: &(), v: &()) { | - - let's call the lifetime of this reference `'1` @@ -36,7 +50,7 @@ LL | static_id(&u); | argument requires that `'1` must outlive `'static` error[E0521]: borrowed data escapes outside of function - --> $DIR/regions-static-bound.rs:17:5 + --> $DIR/regions-static-bound.rs:19:5 | LL | fn error(u: &(), v: &()) { | - - let's call the lifetime of this reference `'2` @@ -49,6 +63,6 @@ LL | static_id_indirect(&v); | `v` escapes the function body here | argument requires that `'2` must outlive `'static` -error: aborting due to 3 previous errors; 2 warnings emitted +error: aborting due to 3 previous errors; 3 warnings emitted For more information about this error, try `rustc --explain E0521`. diff --git a/tests/ui/regions/resolve-re-error-ice.rs b/tests/ui/regions/resolve-re-error-ice.rs new file mode 100644 index 000000000..f37b27a82 --- /dev/null +++ b/tests/ui/regions/resolve-re-error-ice.rs @@ -0,0 +1,22 @@ +// check-pass + +// Allow this for now, can remove this UI test when this becomes a hard error. +#![allow(implied_bounds_entailment)] + +use std::collections::hash_map::{Keys, HashMap}; +use std::marker::PhantomData; + +trait MapAssertion<'a, K, V, R> { + fn key_set(&self) -> Subject<Keys<K, V>, (), R>; +} + +struct Subject<'a, T, V, R>(PhantomData<(&'a T, V, R)>); + +impl<'a, K, V, R> MapAssertion<'a, K, V, R> for Subject<'a, HashMap<K, V>, (), R> +{ + fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> { + todo!() + } +} + +fn main() {} diff --git a/tests/ui/regions/resolve-re-error-ice.stderr b/tests/ui/regions/resolve-re-error-ice.stderr new file mode 100644 index 000000000..e7003e1c3 --- /dev/null +++ b/tests/ui/regions/resolve-re-error-ice.stderr @@ -0,0 +1,15 @@ +Future incompatibility report: Future breakage diagnostic: +warning: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/resolve-re-error-ice.rs:17:16 + | +LL | fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> { + | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this type to make the impl signature compatible: `Subject<'_, std::collections::hash_map::Keys<'_, K, V>, (), R>` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572> +note: the lint level is defined here + --> $DIR/resolve-re-error-ice.rs:4:10 + | +LL | #![allow(implied_bounds_entailment)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + |