Skip to content

Commit 53f10b9

Browse files
committed
Add opaque type test
1 parent 1208edd commit 53f10b9

4 files changed

+81
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0284]: type annotations needed: cannot satisfy `Foo == _`
2+
--> $DIR/norm-before-method-resolution-opaque-type.rs:16:19
3+
|
4+
LL | fn weird_bound<X>(x: &<X as Trait<'static>>::Out<Foo>) -> X
5+
| ^ cannot satisfy `Foo == _`
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0284`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error: item does not constrain `Foo::{opaque#0}`, but has it in its signature
2+
--> $DIR/norm-before-method-resolution-opaque-type.rs:16:4
3+
|
4+
LL | fn weird_bound<X>(x: &<X as Trait<'static>>::Out<Foo>) -> X
5+
| ^^^^^^^^^^^
6+
|
7+
= note: consider moving the opaque type's declaration and defining uses into a separate module
8+
note: this opaque type is in the signature
9+
--> $DIR/norm-before-method-resolution-opaque-type.rs:13:12
10+
|
11+
LL | type Foo = impl Sized;
12+
| ^^^^^^^^^^
13+
14+
error: unconstrained opaque type
15+
--> $DIR/norm-before-method-resolution-opaque-type.rs:13:12
16+
|
17+
LL | type Foo = impl Sized;
18+
| ^^^^^^^^^^
19+
|
20+
= note: `Foo` must be used in combination with a concrete type within the same module
21+
22+
error[E0507]: cannot move out of `*x` which is behind a shared reference
23+
--> $DIR/norm-before-method-resolution-opaque-type.rs:23:13
24+
|
25+
LL | let x = *x;
26+
| ^^ move occurs because `*x` has type `<X as Trait<'_>>::Out<Foo>`, which does not implement the `Copy` trait
27+
|
28+
help: consider removing the dereference here
29+
|
30+
LL - let x = *x;
31+
LL + let x = x;
32+
|
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0507`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ revisions: old next
2+
//@[next] compile-flags: -Znext-solver
3+
4+
#![feature(type_alias_impl_trait)]
5+
trait Trait<'a> {
6+
type Out<U>;
7+
}
8+
9+
impl<'a, T> Trait<'a> for T {
10+
type Out<U> = T;
11+
}
12+
13+
type Foo = impl Sized;
14+
//[old]~^ ERROR: unconstrained opaque type
15+
16+
fn weird_bound<X>(x: &<X as Trait<'static>>::Out<Foo>) -> X
17+
//[old]~^ ERROR: item does not constrain
18+
//[next]~^^ ERROR: cannot satisfy `Foo == _`
19+
where
20+
for<'a> X: Trait<'a>,
21+
for<'a> <X as Trait<'a>>::Out<()>: Copy,
22+
{
23+
let x = *x; //[old]~ ERROR: cannot move out of `*x`
24+
todo!();
25+
}
26+
27+
fn main() {
28+
let _: () = weird_bound(&());
29+
}

Diff for: tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ check-pass
22

3-
// Should pass, but we normalize and check bounds before we resolve the generics
3+
// We normalize and check bounds before we resolve the generics
44
// of the function (which we know because of the return type).
55

66
trait Trait<'a> {
@@ -12,10 +12,12 @@ impl<'a, T> Trait<'a> for T {
1212
}
1313

1414
fn weird_bound<X>() -> X
15-
where
16-
for<'a> X: Trait<'a>,
17-
for<'a> <X as Trait<'a>>::Out: Copy
18-
{ todo!() }
15+
where
16+
for<'a> X: Trait<'a>,
17+
for<'a> <X as Trait<'a>>::Out: Copy,
18+
{
19+
todo!()
20+
}
1921

2022
fn main() {
2123
let _: () = weird_bound();

0 commit comments

Comments
 (0)