Skip to content

Commit bc9019f

Browse files
committed
Special case type aliases from impl trait in const/static types
1 parent ed4c2d1 commit bc9019f

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
342342
ty,
343343
ImplTraitContext::OtherOpaqueTy {
344344
capturable_lifetimes: &mut FxHashSet::default(),
345-
origin: hir::OpaqueTyOrigin::Misc,
345+
origin: hir::OpaqueTyOrigin::TyAlias,
346346
},
347347
);
348348
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
@@ -918,7 +918,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
918918
ty,
919919
ImplTraitContext::OtherOpaqueTy {
920920
capturable_lifetimes: &mut FxHashSet::default(),
921-
origin: hir::OpaqueTyOrigin::Misc,
921+
origin: hir::OpaqueTyOrigin::TyAlias,
922922
},
923923
);
924924
hir::ImplItemKind::TyAlias(ty)

compiler/rustc_hir/src/hir.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,9 @@ pub enum OpaqueTyOrigin {
22912291
AsyncFn,
22922292
/// `let _: impl Trait = ...`
22932293
Binding,
2294-
/// Impl trait in type aliases, consts, statics, bounds.
2294+
/// type aliases: `type Foo = impl Trait;`
2295+
TyAlias,
2296+
/// Impl trait consts, statics, bounds.
22952297
Misc,
22962298
}
22972299

compiler/rustc_trait_selection/src/opaque_types.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
422422
}
423423
// These opaque type inherit all lifetime parameters from their
424424
// parent, so we have to check them all.
425-
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc => 0,
425+
hir::OpaqueTyOrigin::Binding
426+
| hir::OpaqueTyOrigin::TyAlias
427+
| hir::OpaqueTyOrigin::Misc => 0,
426428
};
427429

428430
let span = tcx.def_span(def_id);
@@ -581,6 +583,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
581583
// Otherwise, generate the label we'll use in the error message.
582584
hir::OpaqueTyOrigin::Binding
583585
| hir::OpaqueTyOrigin::FnReturn
586+
| hir::OpaqueTyOrigin::TyAlias
584587
| hir::OpaqueTyOrigin::Misc => "impl Trait",
585588
};
586589
let msg = format!("ambiguous lifetime bound in `{}`", context_name);

compiler/rustc_typeck/src/check/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ fn check_opaque_meets_bounds<'tcx>(
659659
// Checked when type checking the function containing them.
660660
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => return,
661661
// Can have different predicates to their defining use
662-
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc => {}
662+
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias => {
663+
}
663664
}
664665

665666
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

compiler/rustc_typeck/src/check/writeback.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
497497
let mut skip_add = false;
498498

499499
if let ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() {
500-
if let hir::OpaqueTyOrigin::Misc = opaque_defn.origin {
500+
if let hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias = opaque_defn.origin
501+
{
501502
if def_id == defin_ty_def_id {
502503
debug!(
503504
"skipping adding concrete definition for opaque type {:?} {:?}",

0 commit comments

Comments
 (0)