Skip to content

Commit e0faa7b

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

34 files changed

+148
-171
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
@@ -2532,7 +2532,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25322532
let InferOk { obligations, .. } = self
25332533
.infcx
25342534
.at(&cause, obligation.param_env)
2535-
.eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2535+
.eq(DefineOpaqueTypes::Yes, placeholder_obligation_trait_ref, impl_trait_ref)
25362536
.map_err(|e| {
25372537
debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
25382538
})?;

tests/ui/auto-traits/opaque_type_candidate_selection.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
//! used to ICE: #119272
22
3-
//@ check-pass
4-
53
#![feature(type_alias_impl_trait)]
64
mod defining_scope {
75
use super::*;
86
pub type Alias<T> = impl Sized;
97

108
pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
9+
//~^ ERROR: type annotations needed
1110
x
1211
}
1312
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0284]: type annotations needed
2+
--> $DIR/opaque_type_candidate_selection.rs:8:20
3+
|
4+
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
5+
| ^ cannot infer type
6+
|
7+
= note: cannot satisfy `<Alias<T> as Trait<T>>::Assoc == _`
8+
note: required because it appears within the type `Container<Alias<T>, T>`
9+
--> $DIR/opaque_type_candidate_selection.rs:14:8
10+
|
11+
LL | struct Container<T: Trait<U>, U> {
12+
| ^^^^^^^^^
13+
= help: unsized fn params are gated as an unstable feature
14+
help: function arguments must have a statically known size, borrowed types always have a known size
15+
|
16+
LL | pub fn cast<T>(x: &Container<Alias<T>, T>) -> Container<T, T> {
17+
| +
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0284`.

tests/ui/coherence/occurs-check/opaques.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0119]: conflicting implementations of trait `Trait<_>`
2-
--> $DIR/opaques.rs:30:1
2+
--> $DIR/opaques.rs:29:1
33
|
44
LL | impl<T> Trait<T> for T {
55
| ---------------------- first implementation here
@@ -8,7 +8,7 @@ LL | impl<T> Trait<T> for defining_scope::Alias<T> {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
99

1010
error[E0282]: type annotations needed
11-
--> $DIR/opaques.rs:13:20
11+
--> $DIR/opaques.rs:12:20
1212
|
1313
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
1414
| ^ cannot infer type
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0284]: type annotations needed
2+
--> $DIR/opaques.rs:12:20
3+
|
4+
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
5+
| ^ cannot infer type
6+
|
7+
= note: cannot satisfy `<Alias<T> as Trait<T>>::Assoc == _`
8+
note: required because it appears within the type `Container<Alias<T>, T>`
9+
--> $DIR/opaques.rs:18:8
10+
|
11+
LL | struct Container<T: Trait<U>, U> {
12+
| ^^^^^^^^^
13+
= help: unsized fn params are gated as an unstable feature
14+
help: function arguments must have a statically known size, borrowed types always have a known size
15+
|
16+
LL | pub fn cast<T>(x: &Container<Alias<T>, T>) -> Container<T, T> {
17+
| +
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0284`.

tests/ui/coherence/occurs-check/opaques.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// A regression test for #105787
55

66
//@[old] known-bug: #105787
7-
//@[old] check-pass
87
#![feature(type_alias_impl_trait)]
98
mod defining_scope {
109
use super::*;

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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
| ^
6-
LL |
76
LL | x.my_debug();
87
| -------- type must be known at this point
98
|

tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs

Lines changed: 2 additions & 3 deletions
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);
@@ -11,10 +12,8 @@ impl MyDebug for &() {
1112

1213
fn my_foo() -> impl std::fmt::Debug {
1314
if false {
14-
let x = &my_foo();
15-
//[next]~^ ERROR: type annotations needed
15+
let x = &my_foo(); //[next]~ ERROR: type annotations needed
1616
x.my_debug();
17-
//[current]~^ ERROR: no method named `my_debug`
1817
}
1918
()
2019
}

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`.

tests/ui/impl-trait/nested_impl_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn fine(x: impl Into<u32>) -> impl Into<u32> { x }
55

66
fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
77
//~^ ERROR nested `impl Trait` is not allowed
8-
//~| ERROR the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
8+
//~| ERROR the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfie
99

1010
fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
1111
//~^ ERROR nested `impl Trait` is not allowed
@@ -18,7 +18,7 @@ struct X;
1818
impl X {
1919
fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
2020
//~^ ERROR nested `impl Trait` is not allowed
21-
//~| ERROR the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
21+
//~| ERROR the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfie
2222
}
2323

2424
fn allowed_in_assoc_type() -> impl Iterator<Item=impl Fn()> {

tests/ui/impl-trait/nested_impl_trait.stderr

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,27 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
4242
|
4343
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
4444

45-
error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
45+
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
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

54-
error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
56+
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/recursive-bound-eval.rs:18: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:18: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: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0282, E0599.
22+
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:18:13
33
|
44
LL | move || recursive_fn().parse()
55
| ^^^^^^^^^^^^^^ cannot infer type

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

Lines changed: 2 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
}
@@ -18,7 +16,8 @@ impl<E, T: Fn() -> E> Parser<E> for T {
1816

1917
pub fn recursive_fn<E>() -> impl Parser<E> {
2018
move || recursive_fn().parse()
21-
//[next]~^ ERROR: type annotations needed
19+
//~^ ERROR: type annotations needed
20+
//[current]~^^ ERROR: no method named `parse` found for opaque type
2221
}
2322

2423
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

Lines changed: 3 additions & 9 deletions
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

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

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

Lines changed: 1 addition & 2 deletions
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() {}
Lines changed: 12 additions & 6 deletions
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` implements `Trait<()>`
9-
`Foo` implements `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

Lines changed: 1 addition & 2 deletions
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() {}

0 commit comments

Comments
 (0)