Skip to content

Commit b323f58

Browse files
committed
Handle weak type aliases by immediately resolving them to their aliased type
1 parent b0b4a07 commit b323f58

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
107107
}
108108
}
109109
}
110+
ty::Alias(ty::Weak, alias_ty) if alias_ty.def_id.is_local() => {
111+
self.tcx
112+
.type_of(alias_ty.def_id)
113+
.subst(self.tcx, alias_ty.substs)
114+
.visit_with(self)?;
115+
}
110116
ty::Alias(ty::Projection, alias_ty) => {
111117
// This avoids having to do normalization of `Self::AssocTy` by only
112118
// supporting the case of a method defining opaque types from assoc types
@@ -136,24 +142,23 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
136142
ty::InternalSubsts::identity_for_item(self.tcx, parent),
137143
);
138144

139-
if !check_substs_compatible(self.tcx, assoc, impl_substs) {
145+
if check_substs_compatible(self.tcx, assoc, impl_substs) {
146+
return self
147+
.tcx
148+
.type_of(assoc.def_id)
149+
.subst(self.tcx, impl_substs)
150+
.visit_with(self);
151+
} else {
140152
self.tcx.sess.delay_span_bug(
141153
self.tcx.def_span(assoc.def_id),
142154
"item had incorrect substs",
143155
);
144-
return ControlFlow::Continue(());
145156
}
146-
147-
return self
148-
.tcx
149-
.type_of(assoc.def_id)
150-
.subst(self.tcx, impl_substs)
151-
.visit_with(self);
152157
}
153158
}
154159
}
155160
}
156-
_ => {}
161+
_ => trace!(kind=?t.kind()),
157162
}
158163
ControlFlow::Continue(())
159164
}

tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ LL | fn eq(&self, _other: &(Foo, i32)) -> bool {
2020
|
2121
= note: expected signature `fn(&a::Bar, &(a::Bar, i32)) -> _`
2222
found signature `fn(&a::Bar, &(a::Foo, i32)) -> _`
23-
note: this item must have the opaque type in its signature in order to be able to register hidden types
24-
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:10:12
25-
|
26-
LL | fn eq(&self, _other: &(Foo, i32)) -> bool {
27-
| ^^
2823

2924
error: unconstrained opaque type
3025
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:18:16

tests/ui/type-alias-impl-trait/unnameable_type.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ LL | fn dont_define_this(_private: Private) {}
2525
| ^^^^^^^
2626
= note: expected signature `fn(Private)`
2727
found signature `fn(MyPrivate)`
28-
note: this item must have the opaque type in its signature in order to be able to register hidden types
29-
--> $DIR/unnameable_type.rs:20:8
30-
|
31-
LL | fn dont_define_this(_private: MyPrivate) {}
32-
| ^^^^^^^^^^^^^^^^
3328

3429
error: aborting due to 2 previous errors
3530

0 commit comments

Comments
 (0)