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() {}

0 commit comments

Comments
 (0)