Skip to content

Commit d43683f

Browse files
Treat TAIT equation as always ambiguous in coherence
1 parent 9397862 commit d43683f

File tree

6 files changed

+74
-21
lines changed

6 files changed

+74
-21
lines changed

compiler/rustc_infer/src/infer/combine.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,10 @@ impl<'tcx> InferCtxt<'tcx> {
124124
}
125125

126126
// During coherence, opaque types should be treated as *possibly*
127-
// equal to each other, even if their generic params differ, as
128-
// they could resolve to the same hidden type, even for different
129-
// generic params.
130-
(
131-
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
132-
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
133-
) if self.intercrate && a_def_id == b_def_id => {
127+
// equal to any other type (except for possibly itself). This is an
128+
// extremely heavy hammer, but can be relaxed in a fowards-compatible
129+
// way later.
130+
(&ty::Alias(ty::Opaque, _), _) | (_, &ty::Alias(ty::Opaque, _)) if self.intercrate => {
134131
relation.register_predicates([ty::Binder::dummy(ty::PredicateKind::Ambiguous)]);
135132
Ok(a)
136133
}

src/tools/clippy/tests/ui/from_over_into_unfixable.rs

-6
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,4 @@ impl Into<u8> for ContainsVal {
3232
}
3333
}
3434

35-
type Opaque = impl Sized;
36-
struct IntoOpaque;
37-
impl Into<Opaque> for IntoOpaque {
38-
fn into(self) -> Opaque {}
39-
}
40-
4135
fn main() {}

src/tools/clippy/tests/ui/from_over_into_unfixable.stderr

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
error[E0658]: `impl Trait` in type aliases is unstable
2-
--> $DIR/from_over_into_unfixable.rs:35:15
1+
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
2+
--> $DIR/from_over_into_unfixable.rs:11:1
33
|
4-
LL | type Opaque = impl Sized;
5-
| ^^^^^^^^^^
4+
LL | impl Into<InMacro> for String {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
8-
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
7+
= help: replace the `Into` implementation with `From<std::string::String>`
8+
= note: `-D clippy::from-over-into` implied by `-D warnings`
99

10-
error: aborting due to previous error
10+
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
11+
--> $DIR/from_over_into_unfixable.rs:19:1
12+
|
13+
LL | impl Into<WeirdUpperSelf> for &'static [u8] {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: replace the `Into` implementation with `From<&'static [u8]>`
17+
18+
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
19+
--> $DIR/from_over_into_unfixable.rs:28:1
20+
|
21+
LL | impl Into<u8> for ContainsVal {
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
25+
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
26+
= help: replace the `Into` implementation with `From<ContainsVal>`
27+
28+
error: aborting due to 3 previous errors
1129

12-
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0119]: conflicting implementations of trait `Into<T>` for type `Foo`
2+
--> $DIR/coherence-treats-tait-ambig.rs:10:1
3+
|
4+
LL | impl Into<T> for Foo {
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: conflicting implementation in crate `core`:
8+
- impl<T, U> Into<U> for T
9+
where U: From<T>;
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0119]: conflicting implementations of trait `Into<T>` for type `Foo`
2+
--> $DIR/coherence-treats-tait-ambig.rs:10:1
3+
|
4+
LL | impl Into<T> for Foo {
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: conflicting implementation in crate `core`:
8+
- impl<T, U> Into<U> for T
9+
where U: From<T>;
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
4+
#![feature(type_alias_impl_trait)]
5+
6+
type T = impl Sized;
7+
8+
struct Foo;
9+
10+
impl Into<T> for Foo {
11+
//~^ ERROR conflicting implementations of trait `Into<T>` for type `Foo`
12+
fn into(self) -> T {
13+
Foo
14+
}
15+
}
16+
17+
fn main() {
18+
let _: T = Foo.into();
19+
}

0 commit comments

Comments
 (0)