From 94a0819fe3a0d679c3042a77bfe6a2afc505daea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:28 +0200 Subject: Adding upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/fn/fn-compare-mismatch.stderr | 10 +++------ src/test/ui/fn/fn-item-type.stderr | 10 ++++----- src/test/ui/fn/fn-trait-formatting.stderr | 8 ++++++++ .../fn/implied-bounds-unnorm-associated-type-2.rs | 3 ++- .../implied-bounds-unnorm-associated-type-2.stderr | 17 +++++++++++++++ .../fn/implied-bounds-unnorm-associated-type-3.rs | 5 +---- .../implied-bounds-unnorm-associated-type-3.stderr | 14 ------------- .../fn/implied-bounds-unnorm-associated-type-4.rs | 24 ++++++++++++++++++++++ .../implied-bounds-unnorm-associated-type-4.stderr | 14 +++++++++++++ .../fn/implied-bounds-unnorm-associated-type-5.rs | 23 +++++++++++++++++++++ .../implied-bounds-unnorm-associated-type-5.stderr | 19 +++++++++++++++++ .../ui/fn/implied-bounds-unnorm-associated-type.rs | 6 +++--- .../implied-bounds-unnorm-associated-type.stderr | 20 +++++++++--------- 13 files changed, 129 insertions(+), 44 deletions(-) create mode 100644 src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr delete mode 100644 src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr create mode 100644 src/test/ui/fn/implied-bounds-unnorm-associated-type-4.rs create mode 100644 src/test/ui/fn/implied-bounds-unnorm-associated-type-4.stderr create mode 100644 src/test/ui/fn/implied-bounds-unnorm-associated-type-5.rs create mode 100644 src/test/ui/fn/implied-bounds-unnorm-associated-type-5.stderr (limited to 'src/test/ui/fn') diff --git a/src/test/ui/fn/fn-compare-mismatch.stderr b/src/test/ui/fn/fn-compare-mismatch.stderr index 096440225..df838cb11 100644 --- a/src/test/ui/fn/fn-compare-mismatch.stderr +++ b/src/test/ui/fn/fn-compare-mismatch.stderr @@ -6,14 +6,10 @@ LL | let x = f == g; | | | fn() {f} | -help: you might have forgotten to call this function +help: use parentheses to call these | -LL | let x = f() == g; - | ++ -help: you might have forgotten to call this function - | -LL | let x = f == g(); - | ++ +LL | let x = f() == g(); + | ++ ++ error[E0308]: mismatched types --> $DIR/fn-compare-mismatch.rs:4:18 diff --git a/src/test/ui/fn/fn-item-type.stderr b/src/test/ui/fn/fn-item-type.stderr index ecc6485d6..f03a47d5c 100644 --- a/src/test/ui/fn/fn-item-type.stderr +++ b/src/test/ui/fn/fn-item-type.stderr @@ -15,7 +15,7 @@ note: function defined here --> $DIR/fn-item-type.rs:7:4 | LL | fn eq(x: T, y: T) { } - | ^^ ---- ---- + | ^^ ---- error[E0308]: mismatched types --> $DIR/fn-item-type.rs:22:19 @@ -34,7 +34,7 @@ note: function defined here --> $DIR/fn-item-type.rs:7:4 | LL | fn eq(x: T, y: T) { } - | ^^ ---- ---- + | ^^ ---- error[E0308]: mismatched types --> $DIR/fn-item-type.rs:29:23 @@ -53,7 +53,7 @@ note: function defined here --> $DIR/fn-item-type.rs:7:4 | LL | fn eq(x: T, y: T) { } - | ^^ ---- ---- + | ^^ ---- error[E0308]: mismatched types --> $DIR/fn-item-type.rs:38:26 @@ -72,7 +72,7 @@ note: function defined here --> $DIR/fn-item-type.rs:7:4 | LL | fn eq(x: T, y: T) { } - | ^^ ---- ---- + | ^^ ---- error[E0308]: mismatched types --> $DIR/fn-item-type.rs:45:19 @@ -90,7 +90,7 @@ note: function defined here --> $DIR/fn-item-type.rs:7:4 | LL | fn eq(x: T, y: T) { } - | ^^ ---- ---- + | ^^ ---- error: aborting due to 5 previous errors diff --git a/src/test/ui/fn/fn-trait-formatting.stderr b/src/test/ui/fn/fn-trait-formatting.stderr index ea88e401b..2a674d3c1 100644 --- a/src/test/ui/fn/fn-trait-formatting.stderr +++ b/src/test/ui/fn/fn-trait-formatting.stderr @@ -8,6 +8,10 @@ LL | let _: () = Box::new(|_: isize| {}) as Box; | = note: expected unit type `()` found struct `Box` +help: use parentheses to call this trait object + | +LL | let _: () = (Box::new(|_: isize| {}) as Box)(/* isize */); + | + ++++++++++++++ error[E0308]: mismatched types --> $DIR/fn-trait-formatting.rs:10:17 @@ -19,6 +23,10 @@ LL | let _: () = Box::new(|_: isize, isize| {}) as Box | = note: expected unit type `()` found struct `Box` +help: use parentheses to call this trait object + | +LL | let _: () = (Box::new(|_: isize, isize| {}) as Box)(/* isize */, /* isize */); + | + +++++++++++++++++++++++++++ error[E0308]: mismatched types --> $DIR/fn-trait-formatting.rs:14:17 diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.rs b/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.rs index 5a92bcd37..5d9245556 100644 --- a/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.rs +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.rs @@ -1,4 +1,4 @@ -// check-pass +// check-fail trait Trait { type Type; @@ -17,6 +17,7 @@ where fn g<'a, 'b>() { f::<'a, 'b>(()); + //~^ ERROR lifetime may not live long enough } fn main() {} diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr new file mode 100644 index 000000000..0c3df04ea --- /dev/null +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr @@ -0,0 +1,17 @@ +error: lifetime may not live long enough + --> $DIR/implied-bounds-unnorm-associated-type-2.rs:19:5 + | +LL | fn g<'a, 'b>() { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | f::<'a, 'b>(()); + | ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of a function pointer to `f` + = note: the function `f` is invariant over the parameter `'a` + = help: see for more information about variance + +error: aborting due to previous error + diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs b/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs index dc25ac086..888f74cf6 100644 --- a/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs @@ -1,6 +1,4 @@ -// check-fail -// See issue #91899. If we treat unnormalized args as WF, `Self` can also be a -// source of unsoundness. +// check-pass pub trait Yokeable<'a>: 'static { type Output: 'a; @@ -17,7 +15,6 @@ pub trait ZeroCopyFrom: for<'a> Yokeable<'a> { impl ZeroCopyFrom<[T]> for &'static [T] { fn zero_copy_from<'b>(cart: &'b [T]) -> &'b [T] { - //~^ the parameter cart } } diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr deleted file mode 100644 index 95cf4fb16..000000000 --- a/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0310]: the parameter type `T` may not live long enough - --> $DIR/implied-bounds-unnorm-associated-type-3.rs:19:5 - | -LL | fn zero_copy_from<'b>(cart: &'b [T]) -> &'b [T] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `[T]` will meet its required lifetime bounds - | -help: consider adding an explicit lifetime bound... - | -LL | impl ZeroCopyFrom<[T]> for &'static [T] { - | +++++++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0310`. diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-4.rs b/src/test/ui/fn/implied-bounds-unnorm-associated-type-4.rs new file mode 100644 index 000000000..12859252c --- /dev/null +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-4.rs @@ -0,0 +1,24 @@ +// A regression test for #98543 + +trait Trait { + type Type; +} + +impl Trait for T { + type Type = (); +} + +fn f<'a, 'b>(s: &'b str, _: <&'a &'b () as Trait>::Type) -> &'a str +where + &'a &'b (): Trait, // <- adding this bound is the change from #91068 +{ + s +} + +fn main() { + let x = String::from("Hello World!"); + let y = f(&x, ()); + drop(x); + //~^ ERROR cannot move out of `x` because it is borrowed + println!("{}", y); +} diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-4.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type-4.stderr new file mode 100644 index 000000000..fcbaa91d1 --- /dev/null +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-4.stderr @@ -0,0 +1,14 @@ +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/implied-bounds-unnorm-associated-type-4.rs:21:10 + | +LL | let y = f(&x, ()); + | -- borrow of `x` occurs here +LL | drop(x); + | ^ move out of `x` occurs here +LL | +LL | println!("{}", y); + | - borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0505`. diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-5.rs b/src/test/ui/fn/implied-bounds-unnorm-associated-type-5.rs new file mode 100644 index 000000000..2a9a6a8cc --- /dev/null +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-5.rs @@ -0,0 +1,23 @@ +trait Trait<'a>: 'a { + type Type; +} + +// if the `T: 'a` bound gets implied we would probably get ub here again +impl<'a, T> Trait<'a> for T { + //~^ ERROR the parameter type `T` may not live long enough + type Type = (); +} + +fn f<'a, 'b>(s: &'b str, _: <&'b () as Trait<'a>>::Type) -> &'a str +where + &'b (): Trait<'a>, +{ + s +} + +fn main() { + let x = String::from("Hello World!"); + let y = f(&x, ()); + drop(x); + println!("{}", y); +} diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-5.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type-5.stderr new file mode 100644 index 000000000..458756a3d --- /dev/null +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type-5.stderr @@ -0,0 +1,19 @@ +error[E0309]: the parameter type `T` may not live long enough + --> $DIR/implied-bounds-unnorm-associated-type-5.rs:6:13 + | +LL | impl<'a, T> Trait<'a> for T { + | ^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds... + | +note: ...that is required by this bound + --> $DIR/implied-bounds-unnorm-associated-type-5.rs:1:18 + | +LL | trait Trait<'a>: 'a { + | ^^ +help: consider adding an explicit lifetime bound... + | +LL | impl<'a, T: 'a> Trait<'a> for T { + | ++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0309`. diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type.rs b/src/test/ui/fn/implied-bounds-unnorm-associated-type.rs index 04b6f4dd8..d58d25036 100644 --- a/src/test/ui/fn/implied-bounds-unnorm-associated-type.rs +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type.rs @@ -1,6 +1,6 @@ // check-fail -// See issue #91068. Types in the substs of an associated type can't be implied -// to be WF, since they don't actually have to be constructed. +// See issue #91068. We check that the unnormalized associated types in +// function signatures are implied trait Trait { type Type; @@ -12,12 +12,12 @@ impl Trait for T { fn f<'a, 'b>(s: &'b str, _: <&'a &'b () as Trait>::Type) -> &'a str { s - //~^ ERROR lifetime may not live long enough } fn main() { let x = String::from("Hello World!"); let y = f(&x, ()); drop(x); + //~^ ERROR cannot move out of `x` because it is borrowed println!("{}", y); } diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type.stderr index 8096f0838..e35f46e44 100644 --- a/src/test/ui/fn/implied-bounds-unnorm-associated-type.stderr +++ b/src/test/ui/fn/implied-bounds-unnorm-associated-type.stderr @@ -1,14 +1,14 @@ -error: lifetime may not live long enough - --> $DIR/implied-bounds-unnorm-associated-type.rs:14:5 +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/implied-bounds-unnorm-associated-type.rs:20:10 | -LL | fn f<'a, 'b>(s: &'b str, _: <&'a &'b () as Trait>::Type) -> &'a str { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -LL | s - | ^ 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` +LL | let y = f(&x, ()); + | -- borrow of `x` occurs here +LL | drop(x); + | ^ move out of `x` occurs here +LL | +LL | println!("{}", y); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0505`. -- cgit v1.2.3