Skip to content

Commit 138c6df

Browse files
committed
Revert "Revert "When checking whether an impl applies, constrain hidden types of opaque types.""
This reverts commit ad00868.
1 parent d2ad293 commit 138c6df

25 files changed

+117
-141
lines changed

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

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

tests/ui/impl-trait/equality.rs

+8-5
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

+4-11
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 as Add<u32>>
34-
<&u32 as Add<&u32>>
35-
<u32 as Add<&u32>>
36-
<u32 as 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`.

tests/ui/impl-trait/nested_impl_trait.stderr

+10-6
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfie
4646
--> $DIR/nested_impl_trait.rs:6:46
4747
|
4848
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
49-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`, which is required by `impl Into<u32>: Into<impl Debug>`
49+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
5050
|
51-
= help: the trait `Into<U>` is implemented for `T`
52-
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
51+
help: consider further restricting this bound
52+
|
53+
LL | fn bad_in_ret_position(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
54+
| +++++++++++++++++
5355

5456
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
5557
--> $DIR/nested_impl_trait.rs:19:34
5658
|
5759
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
58-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`, which is required by `impl Into<u32>: Into<impl Debug>`
60+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
61+
|
62+
help: consider further restricting this bound
5963
|
60-
= help: the trait `Into<U>` is implemented for `T`
61-
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
64+
LL | fn bad(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
65+
| +++++++++++++++++
6266

6367
error: aborting due to 7 previous errors
6468

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

+1-1
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

+3-3
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 detected
2019
move || recursive_fn().parse()
21-
//[next]~^ ERROR: type annotations needed
20+
//~^ ERROR: type annotations needed
21+
//[current]~^^ ERROR: no method named `parse` found for opaque type
2222
}
2323

2424
fn main() {}

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

+1-1
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

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
error[E0277]: can't compare `Bar` with `(Foo, i32)`
1+
error[E0275]: overflow evaluating the requirement `Bar: PartialEq<(Foo, i32)>`
22
--> $DIR/recursive-type-alias-impl-trait-declaration.rs:13:13
33
|
44
LL | fn foo() -> Foo {
5-
| ^^^ no implementation for `Bar == (Foo, i32)`
6-
LL |
7-
LL | Bar
8-
| --- return type was inferred to be `Bar` here
9-
|
10-
= help: the trait `PartialEq<(Foo, i32)>` is not implemented for `Bar`
11-
= help: the trait `PartialEq<(Bar, i32)>` is implemented for `Bar`
5+
| ^^^
126

137
error: aborting due to 1 previous error
148

15-
For more information about this error, try `rustc --explain E0277`.
9+
For more information about this error, try `rustc --explain E0275`.

tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr

-11
This file was deleted.

tests/ui/type-alias-impl-trait/constrain_in_projection.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ revisions: current next
55
//@ ignore-compare-mode-next-solver (explicit revisions)
66
//@[next] compile-flags: -Znext-solver
7-
//@[next]check-pass
7+
//@check-pass
88

99
#![feature(type_alias_impl_trait)]
1010

@@ -22,7 +22,6 @@ impl Trait<()> for Foo {
2222

2323
fn bop(_: Bar) {
2424
let x = <Foo as Trait<Bar>>::Assoc::default();
25-
//[current]~^ `Foo: Trait<Bar>` is not satisfied
2625
}
2726

2827
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
error[E0277]: the trait bound `Foo: Trait<Bar>` is not satisfied
1+
error[E0283]: type annotations needed: cannot satisfy `Foo: Trait<Bar>`
22
--> $DIR/constrain_in_projection2.rs:27:14
33
|
44
LL | let x = <Foo as Trait<Bar>>::Assoc::default();
5-
| ^^^ the trait `Trait<Bar>` is not implemented for `Foo`
5+
| ^^^ help: use the fully qualified path to an implementation: `<Type as Trait>::Assoc`
66
|
7-
= help: the following other types implement trait `Trait<T>`:
8-
<Foo as Trait<()>>
9-
<Foo as Trait<u32>>
7+
note: multiple `impl`s satisfying `Foo: Trait<Bar>` found
8+
--> $DIR/constrain_in_projection2.rs:18:1
9+
|
10+
LL | impl Trait<()> for Foo {
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
...
13+
LL | impl Trait<u32> for Foo {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^
15+
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
1016

1117
error: aborting due to 1 previous error
1218

13-
For more information about this error, try `rustc --explain E0277`.
19+
For more information about this error, try `rustc --explain E0283`.

tests/ui/type-alias-impl-trait/constrain_in_projection2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ impl Trait<u32> for Foo {
2525

2626
fn bop(_: Bar) {
2727
let x = <Foo as Trait<Bar>>::Assoc::default();
28-
//[next]~^ ERROR: cannot satisfy `Foo: Trait<Bar>`
29-
//[current]~^^ ERROR: `Foo: Trait<Bar>` is not satisfied
28+
//~^ ERROR: cannot satisfy `Foo: Trait<Bar>`
3029
}
3130

3231
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
error: item does not constrain `Bar::{opaque#0}`, but has it in its signature
2-
--> $DIR/issue-84660-unsoundness.rs:22:8
3-
|
4-
LL | fn convert(_i: In) -> Self::Out {
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/issue-84660-unsoundness.rs:12:12
10-
|
11-
LL | type Bar = impl Foo;
12-
| ^^^^^^^^
13-
141
error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
15-
--> $DIR/issue-84660-unsoundness.rs:29:1
2+
--> $DIR/issue-84660-unsoundness.rs:28:1
163
|
174
LL | impl<In, Out> Trait<Bar, In> for Out {
185
| ------------------------------------ first implementation here
196
...
207
LL | impl<In, Out> Trait<(), In> for Out {
218
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
229

23-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2411

2512
For more information about this error, try `rustc --explain E0119`.

tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ error[E0284]: type annotations needed: cannot satisfy `Bar == _`
44
LL | fn convert(_i: In) -> Self::Out {
55
| _____________________________________^
66
LL | |
7-
LL | |
87
LL | | unreachable!();
98
LL | | }
109
| |_____^ cannot satisfy `Bar == _`
1110

1211
error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
13-
--> $DIR/issue-84660-unsoundness.rs:29:1
12+
--> $DIR/issue-84660-unsoundness.rs:28:1
1413
|
1514
LL | impl<In, Out> Trait<Bar, In> for Out {
1615
| ------------------------------------ first implementation here

tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ impl<In, Out> Trait<Bar, In> for Out {
2121
type Out = Out;
2222
fn convert(_i: In) -> Self::Out {
2323
//[next]~^ ERROR: cannot satisfy `Bar == _`
24-
//[current]~^^ ERROR: item does not constrain `Bar::{opaque#0}`, but has it in its signature
2524
unreachable!();
2625
}
2726
}

tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr

-14
This file was deleted.

tests/ui/type-alias-impl-trait/nested-tait-inference.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ revisions: current next
55
//@ ignore-compare-mode-next-solver (explicit revisions)
66
//@[next] compile-flags: -Znext-solver
7-
//@[next] check-pass
7+
//@check-pass
88

99
use std::fmt::Debug;
1010

@@ -15,8 +15,6 @@ trait Foo<A> {}
1515
impl Foo<()> for () {}
1616

1717
fn foo() -> impl Foo<FooX> {
18-
//[current]~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
19-
// FIXME(type-alias-impl-trait): We could probably make this work.
2018
()
2119
}
2220

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
error[E0277]: the trait bound `(): Foo<FooX>` is not satisfied
1+
error[E0283]: type annotations needed: cannot satisfy `(): Foo<FooX>`
22
--> $DIR/nested-tait-inference2.rs:17:13
33
|
44
LL | fn foo() -> impl Foo<FooX> {
5-
| ^^^^^^^^^^^^^^ the trait `Foo<FooX>` is not implemented for `()`
6-
LL |
7-
LL | ()
8-
| -- return type was inferred to be `()` here
5+
| ^^^^^^^^^^^^^^
96
|
10-
= help: the following other types implement trait `Foo<A>`:
11-
<() as Foo<()>>
12-
<() as Foo<u32>>
7+
note: multiple `impl`s satisfying `(): Foo<FooX>` found
8+
--> $DIR/nested-tait-inference2.rs:14:1
9+
|
10+
LL | impl Foo<()> for () {}
11+
| ^^^^^^^^^^^^^^^^^^^
12+
LL | impl Foo<u32> for () {}
13+
| ^^^^^^^^^^^^^^^^^^^^
1314

1415
error: aborting due to 1 previous error
1516

16-
For more information about this error, try `rustc --explain E0277`.
17+
For more information about this error, try `rustc --explain E0283`.

tests/ui/type-alias-impl-trait/nested-tait-inference2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Foo<()> for () {}
1515
impl Foo<u32> for () {}
1616

1717
fn foo() -> impl Foo<FooX> {
18-
//[current]~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
18+
//[current]~^ ERROR: cannot satisfy `(): Foo<FooX>`
1919
()
2020
//[next]~^ ERROR: cannot satisfy `impl Foo<FooX> == ()`
2121
}

0 commit comments

Comments
 (0)