From 53f10b936bc7052b7616f5a9e7f7f81c78f79f88 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 20 Jun 2024 09:20:45 +0000 Subject: [PATCH] Add opaque type test --- ...-method-resolution-opaque-type.next.stderr | 9 +++++ ...e-method-resolution-opaque-type.old.stderr | 36 +++++++++++++++++++ ...rm-before-method-resolution-opaque-type.rs | 29 +++++++++++++++ .../norm-before-method-resolution.rs | 12 ++++--- 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr create mode 100644 tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr create mode 100644 tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr new file mode 100644 index 00000000000..72646b7bc76 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr @@ -0,0 +1,9 @@ +error[E0284]: type annotations needed: cannot satisfy `Foo == _` + --> $DIR/norm-before-method-resolution-opaque-type.rs:16:19 + | +LL | fn weird_bound(x: &>::Out) -> X + | ^ cannot satisfy `Foo == _` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr new file mode 100644 index 00000000000..dbd0d5dc733 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr @@ -0,0 +1,36 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/norm-before-method-resolution-opaque-type.rs:16:4 + | +LL | fn weird_bound(x: &>::Out) -> X + | ^^^^^^^^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/norm-before-method-resolution-opaque-type.rs:13:12 + | +LL | type Foo = impl Sized; + | ^^^^^^^^^^ + +error: unconstrained opaque type + --> $DIR/norm-before-method-resolution-opaque-type.rs:13:12 + | +LL | type Foo = impl Sized; + | ^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same module + +error[E0507]: cannot move out of `*x` which is behind a shared reference + --> $DIR/norm-before-method-resolution-opaque-type.rs:23:13 + | +LL | let x = *x; + | ^^ move occurs because `*x` has type `>::Out`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = *x; +LL + let x = x; + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs new file mode 100644 index 00000000000..cf752f814c9 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs @@ -0,0 +1,29 @@ +//@ revisions: old next +//@[next] compile-flags: -Znext-solver + +#![feature(type_alias_impl_trait)] +trait Trait<'a> { + type Out; +} + +impl<'a, T> Trait<'a> for T { + type Out = T; +} + +type Foo = impl Sized; +//[old]~^ ERROR: unconstrained opaque type + +fn weird_bound(x: &>::Out) -> X +//[old]~^ ERROR: item does not constrain +//[next]~^^ ERROR: cannot satisfy `Foo == _` +where + for<'a> X: Trait<'a>, + for<'a> >::Out<()>: Copy, +{ + let x = *x; //[old]~ ERROR: cannot move out of `*x` + todo!(); +} + +fn main() { + let _: () = weird_bound(&()); +} diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution.rs b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution.rs index e1aa1babdbb..f0e13a74b2c 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution.rs +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution.rs @@ -1,6 +1,6 @@ //@ check-pass -// Should pass, but we normalize and check bounds before we resolve the generics +// We normalize and check bounds before we resolve the generics // of the function (which we know because of the return type). trait Trait<'a> { @@ -12,10 +12,12 @@ impl<'a, T> Trait<'a> for T { } fn weird_bound() -> X - where - for<'a> X: Trait<'a>, - for<'a> >::Out: Copy -{ todo!() } +where + for<'a> X: Trait<'a>, + for<'a> >::Out: Copy, +{ + todo!() +} fn main() { let _: () = weird_bound();