Skip to content

Commit 0baacd7

Browse files
committed
Revert "Revert "When checking whether an impl applies, constrain hidden types of opaque types.""
This reverts commit ad00868.
1 parent 2633e01 commit 0baacd7

31 files changed

+122
-162
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
@@ -2543,7 +2543,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25432543
let InferOk { obligations, .. } = self
25442544
.infcx
25452545
.at(&cause, obligation.param_env)
2546-
.eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2546+
.eq(DefineOpaqueTypes::Yes, placeholder_obligation_trait_ref, impl_trait_ref)
25472547
.map_err(|e| {
25482548
debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
25492549
})?;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! used to ICE: #119272
2+
3+
#![feature(type_alias_impl_trait)]
4+
mod defining_scope {
5+
use super::*;
6+
pub type Alias<T> = impl Sized;
7+
8+
pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
9+
x
10+
}
11+
}
12+
13+
struct Container<T: Trait<U>, U> {
14+
x: <T as Trait<U>>::Assoc,
15+
}
16+
17+
trait Trait<T> {
18+
type Assoc;
19+
}
20+
21+
impl<T> Trait<T> for T {
22+
type Assoc = Box<u32>;
23+
}
24+
impl<T> Trait<T> for defining_scope::Alias<T> {
25+
//~^ ERROR: conflicting implementations
26+
type Assoc = usize;
27+
}
28+
29+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `Trait<_>`
2+
--> $DIR/opaque_type_candidate_selection.rs:24:1
3+
|
4+
LL | impl<T> Trait<T> for T {
5+
| ---------------------- first implementation here
6+
...
7+
LL | impl<T> Trait<T> for defining_scope::Alias<T> {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.

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: 1 addition & 1 deletion
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

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-
`&u32` implements `Add<u32>`
34-
`&u32` implements `Add`
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 satisfied
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 satisfied
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +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-
| ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into<u32>` here
50-
| |
51-
| the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
49+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
5250
|
53-
= help: the trait `Into<U>` is implemented for `T`
54-
= 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+
| +++++++++++++++++
5555

56-
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
5757
--> $DIR/nested_impl_trait.rs:19:34
5858
|
5959
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
60-
| ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into<u32>` here
61-
| |
62-
| the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
60+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
61+
|
62+
help: consider further restricting this bound
6363
|
64-
= help: the trait `Into<U>` is implemented for `T`
65-
= 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+
| +++++++++++++++++
6666

6767
error: aborting due to 7 previous errors
6868

0 commit comments

Comments
 (0)