diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /tests/ui/impl-trait/rpit | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/impl-trait/rpit')
-rw-r--r-- | tests/ui/impl-trait/rpit/equal-lifetime-params-ok.rs | 19 | ||||
-rw-r--r-- | tests/ui/impl-trait/rpit/non-defining-use.rs | 14 | ||||
-rw-r--r-- | tests/ui/impl-trait/rpit/non-defining-use.stderr | 31 |
3 files changed, 64 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/rpit/equal-lifetime-params-ok.rs b/tests/ui/impl-trait/rpit/equal-lifetime-params-ok.rs new file mode 100644 index 000000000..6207381c7 --- /dev/null +++ b/tests/ui/impl-trait/rpit/equal-lifetime-params-ok.rs @@ -0,0 +1,19 @@ +// check-pass + +// related to #113916, check that using RPITs in functions with lifetime params +// which are constrained to be equal compiles. + +trait Trait<'a, 'b> {} +impl Trait<'_, '_> for () {} +fn pass<'a: 'b, 'b: 'a>() -> impl Trait<'a, 'b> { + (|| {})() +} + +struct Foo<'a>(&'a ()); +impl<'a> Foo<'a> { + fn bar<'b: 'a>(&'b self) -> impl Trait<'a, 'b> { + let _: &'a &'b &'a (); + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/rpit/non-defining-use.rs b/tests/ui/impl-trait/rpit/non-defining-use.rs new file mode 100644 index 000000000..255a8929a --- /dev/null +++ b/tests/ui/impl-trait/rpit/non-defining-use.rs @@ -0,0 +1,14 @@ +// Regression test for #111935 that non-defining uses of RPIT result in errors +#![allow(unconditional_recursion)] +fn foo<T>() -> impl Sized { + let _: () = foo::<u8>(); //~ ERROR expected generic type parameter, found `u8` +} + +fn bar<T>(val: T) -> impl Sized { + let _: u8 = bar(0u8); + //~^ ERROR concrete type differs from previous defining opaque type use + //~| ERROR expected generic type parameter, found `u8` + val +} + +fn main() {} diff --git a/tests/ui/impl-trait/rpit/non-defining-use.stderr b/tests/ui/impl-trait/rpit/non-defining-use.stderr new file mode 100644 index 000000000..19987d476 --- /dev/null +++ b/tests/ui/impl-trait/rpit/non-defining-use.stderr @@ -0,0 +1,31 @@ +error[E0792]: expected generic type parameter, found `u8` + --> $DIR/non-defining-use.rs:4:12 + | +LL | fn foo<T>() -> impl Sized { + | - this generic parameter must be used with a generic type parameter +LL | let _: () = foo::<u8>(); + | ^^ + +error[E0792]: expected generic type parameter, found `u8` + --> $DIR/non-defining-use.rs:8:12 + | +LL | fn bar<T>(val: T) -> impl Sized { + | - this generic parameter must be used with a generic type parameter +LL | let _: u8 = bar(0u8); + | ^^ + +error: concrete type differs from previous defining opaque type use + --> $DIR/non-defining-use.rs:8:17 + | +LL | let _: u8 = bar(0u8); + | ^^^^^^^^ expected `T`, got `u8` + | +note: previous use here + --> $DIR/non-defining-use.rs:7:22 + | +LL | fn bar<T>(val: T) -> impl Sized { + | ^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0792`. |