Skip to content

Commit 3c2175b

Browse files
authored
Rollup merge of #99356 - compiler-errors:tait-in-assoc-ty-supertraits, r=oli-obk
Do not constraint TAITs when checking impl/trait item compatibility Check out the UI test for the example. Open to other approaches to fix this issue -- ideally we _would_ be able to collect this opaque type constraint in a way to use it in `find_opaque_ty_constraints`, so we can report a better mismatch error in the incompatible case, and just allow it in the compatible case. But that seems like a bigger refactor, so I wouldn't want to start it unless someone else thought it was a good idea. cc #99348 r? ``@oli-obk``
2 parents cc35c78 + 23cb89e commit 3c2175b

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

compiler/rustc_typeck/src/check/compare_method.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,21 @@ pub fn check_type_bounds<'tcx>(
15051505
&outlives_environment,
15061506
);
15071507

1508+
let constraints = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
1509+
for (key, value) in constraints {
1510+
infcx
1511+
.report_mismatched_types(
1512+
&ObligationCause::misc(
1513+
value.hidden_type.span,
1514+
tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()),
1515+
),
1516+
tcx.mk_opaque(key.def_id, key.substs),
1517+
value.hidden_type.ty,
1518+
TypeError::Mismatch,
1519+
)
1520+
.emit();
1521+
}
1522+
15081523
Ok(())
15091524
})
15101525
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
struct Concrete;
4+
5+
type Tait = impl Sized;
6+
7+
impl Foo for Concrete {
8+
type Item = Concrete;
9+
//~^ mismatched types
10+
}
11+
12+
impl Bar for Concrete {
13+
type Other = Tait;
14+
}
15+
16+
trait Foo {
17+
type Item: Bar<Other = Self>;
18+
}
19+
20+
trait Bar {
21+
type Other;
22+
}
23+
24+
fn tait() -> Tait {}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-99348-impl-compatibility.rs:8:17
3+
|
4+
LL | type Tait = impl Sized;
5+
| ---------- the expected opaque type
6+
...
7+
LL | type Item = Concrete;
8+
| ^^^^^^^^ types differ
9+
|
10+
= note: expected opaque type `Tait`
11+
found struct `Concrete`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)