Skip to content

Commit 6d70858

Browse files
committed
Allow impl selection and confirmation to define opaque types
1 parent 10b0d52 commit 6d70858

27 files changed

+109
-152
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25642564
let InferOk { obligations, .. } = self
25652565
.infcx
25662566
.at(&cause, obligation.param_env)
2567-
.eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2567+
.eq(DefineOpaqueTypes::Yes, placeholder_obligation_trait_ref, impl_trait_ref)
25682568
.map_err(|e| {
25692569
debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
25702570
})?;

tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed for `&_`
2-
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:14:13
2+
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:15:13
33
|
44
LL | let x = &my_foo();
55
| ^

tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ revisions: current next
22
//@[next] compile-flags: -Znext-solver
3+
//@[current] check-pass
34

45
trait MyDebug {
56
fn my_debug(&self);
@@ -14,7 +15,6 @@ fn my_foo() -> impl std::fmt::Debug {
1415
let x = &my_foo();
1516
//[next]~^ ERROR: type annotations needed
1617
x.my_debug();
17-
//[current]~^ ERROR: no method named `my_debug`
1818
}
1919
()
2020
}

tests/ui/impl-trait/equality.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn sum_to(n: u32) -> impl Foo {
2222
0
2323
} else {
2424
n + sum_to(n - 1)
25-
//~^ ERROR cannot add `impl Foo` to `u32`
25+
//~^ ERROR cannot satisfy `<u32 as Add<impl Foo>>::Output == i32`
2626
}
2727
}
2828

@@ -32,12 +32,15 @@ trait Leak: Sized {
3232
}
3333
impl<T> Leak for T {
3434
default type T = ();
35-
default fn leak(self) -> Self::T { panic!() }
35+
default fn leak(self) -> Self::T {
36+
panic!()
37+
}
3638
}
3739
impl Leak for i32 {
3840
type T = i32;
39-
fn leak(self) -> i32 { self }
41+
fn leak(self) -> i32 {
42+
self
43+
}
4044
}
4145

42-
fn main() {
43-
}
46+
fn main() {}

tests/ui/impl-trait/equality.stderr

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ help: change the type of the numeric literal from `u32` to `i32`
2222
LL | 0_i32
2323
| ~~~
2424

25-
error[E0277]: cannot add `impl Foo` to `u32`
25+
error[E0284]: type annotations needed: cannot satisfy `<u32 as Add<impl Foo>>::Output == i32`
2626
--> $DIR/equality.rs:24:11
2727
|
2828
LL | n + sum_to(n - 1)
29-
| ^ no implementation for `u32 + impl Foo`
30-
|
31-
= help: the trait `Add<impl Foo>` is not implemented for `u32`
32-
= help: the following other types implement trait `Add<Rhs>`:
33-
`&'a u32` implements `Add<u32>`
34-
`&u32` implements `Add<&u32>`
35-
`u32` implements `Add<&u32>`
36-
`u32` implements `Add`
29+
| ^ cannot satisfy `<u32 as Add<impl Foo>>::Output == i32`
3730

3831
error: aborting due to 2 previous errors; 1 warning emitted
3932

40-
Some errors have detailed explanations: E0277, E0308.
41-
For more information about an error, try `rustc --explain E0277`.
33+
Some errors have detailed explanations: E0284, E0308.
34+
For more information about an error, try `rustc --explain E0284`.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/recursive-bound-eval.rs:19:28
3+
|
4+
LL | move || recursive_fn().parse()
5+
| ^^^^^ cannot infer type
6+
7+
error[E0599]: no method named `parse` found for opaque type `impl Parser<_>` in the current scope
8+
--> $DIR/recursive-bound-eval.rs:19:28
9+
|
10+
LL | move || recursive_fn().parse()
11+
| ^^^^^ method not found in `impl Parser<_>`
12+
|
13+
= help: items from traits can only be used if the trait is implemented and in scope
14+
help: trait `Parser` which provides `parse` is implemented but not in scope; perhaps you want to import it
15+
|
16+
LL + use Parser;
17+
|
18+
19+
error[E0391]: cycle detected when computing type of opaque `recursive_fn::{opaque#0}`
20+
--> $DIR/recursive-bound-eval.rs:17:29
21+
|
22+
LL | pub fn recursive_fn<E>() -> impl Parser<E> {
23+
| ^^^^^^^^^^^^^^
24+
|
25+
note: ...which requires type-checking `recursive_fn`...
26+
--> $DIR/recursive-bound-eval.rs:19:13
27+
|
28+
LL | move || recursive_fn().parse()
29+
| ^^^^^^^^^^^^^^
30+
= note: ...which requires evaluating trait selection obligation `recursive_fn::{opaque#0}: core::marker::Unpin`...
31+
= note: ...which again requires computing type of opaque `recursive_fn::{opaque#0}`, completing the cycle
32+
note: cycle used when computing type of `recursive_fn::{opaque#0}`
33+
--> $DIR/recursive-bound-eval.rs:17:29
34+
|
35+
LL | pub fn recursive_fn<E>() -> impl Parser<E> {
36+
| ^^^^^^^^^^^^^^
37+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
38+
39+
error: aborting due to 3 previous errors
40+
41+
Some errors have detailed explanations: E0282, E0391, E0599.
42+
For more information about an error, try `rustc --explain E0282`.

tests/ui/impl-trait/recursive-bound-eval.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/recursive-bound-eval.rs:20:13
2+
--> $DIR/recursive-bound-eval.rs:19:13
33
|
44
LL | move || recursive_fn().parse()
55
| ^^^^^^^^^^^^^^ cannot infer type

tests/ui/impl-trait/recursive-bound-eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//@revisions: next current
55
//@[next] compile-flags: -Znext-solver
66

7-
//@[current] check-pass
8-
97
pub trait Parser<E> {
108
fn parse(&self) -> E;
119
}
@@ -17,8 +15,10 @@ impl<E, T: Fn() -> E> Parser<E> for T {
1715
}
1816

1917
pub fn recursive_fn<E>() -> impl Parser<E> {
18+
//[current]~^ ERROR: cycle
2019
move || recursive_fn().parse()
21-
//[next]~^ ERROR: type annotations needed
20+
//~^ ERROR: type annotations needed
21+
//[current]~| ERROR: no method named `parse`
2222
}
2323

2424
fn main() {}

tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl PartialEq<(Bar, i32)> for Bar {
1111
}
1212

1313
fn foo() -> Foo {
14-
//~^ ERROR can't compare `Bar` with `(Foo, i32)`
14+
//~^ ERROR overflow evaluating the requirement `Bar: PartialEq<(Foo, i32)>`
1515
Bar
1616
}
1717

0 commit comments

Comments
 (0)