summaryrefslogtreecommitdiffstats
path: root/src/test/ui/fn
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
commit17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch)
tree3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /src/test/ui/fn
parentAdding upstream version 1.64.0+dfsg1. (diff)
downloadrustc-upstream/1.65.0+dfsg1.tar.xz
rustc-upstream/1.65.0+dfsg1.zip
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/fn')
-rw-r--r--src/test/ui/fn/fn-compare-mismatch.stderr10
-rw-r--r--src/test/ui/fn/fn-item-type.stderr10
-rw-r--r--src/test/ui/fn/fn-trait-formatting.stderr8
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-2.rs3
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-2.stderr17
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs5
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr14
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-4.rs24
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-4.stderr14
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-5.rs23
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type-5.stderr19
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type.rs6
-rw-r--r--src/test/ui/fn/implied-bounds-unnorm-associated-type.stderr20
13 files changed, 129 insertions, 44 deletions
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<T>(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<T>(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<T>(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<T>(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<T>(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<dyn FnOnce(isize)>;
|
= note: expected unit type `()`
found struct `Box<dyn FnOnce(isize)>`
+help: use parentheses to call this trait object
+ |
+LL | let _: () = (Box::new(|_: isize| {}) as Box<dyn FnOnce(isize)>)(/* isize */);
+ | + ++++++++++++++
error[E0308]: mismatched types
--> $DIR/fn-trait-formatting.rs:10:17
@@ -19,6 +23,10 @@ LL | let _: () = Box::new(|_: isize, isize| {}) as Box<dyn Fn(isize, isize)>
|
= note: expected unit type `()`
found struct `Box<dyn Fn(isize, isize)>`
+help: use parentheses to call this trait object
+ |
+LL | let _: () = (Box::new(|_: isize, isize| {}) as Box<dyn Fn(isize, isize)>)(/* 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 <https://doc.rust-lang.org/nomicon/subtyping.html> 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<C: ?Sized>: for<'a> Yokeable<'a> {
impl<T> 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<T: 'static> 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<T> 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<T> 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`.