Special case type aliases from impl trait in const/static types

This commit is contained in:
Oli Scherer 2021-03-12 11:27:08 +00:00
parent 3abdb08351
commit cdbb0ff8ca
5 changed files with 13 additions and 6 deletions

View File

@ -342,7 +342,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty,
ImplTraitContext::OtherOpaqueTy {
capturable_lifetimes: &mut FxHashSet::default(),
origin: hir::OpaqueTyOrigin::Misc,
origin: hir::OpaqueTyOrigin::TyAlias,
},
);
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
@ -918,7 +918,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty,
ImplTraitContext::OtherOpaqueTy {
capturable_lifetimes: &mut FxHashSet::default(),
origin: hir::OpaqueTyOrigin::Misc,
origin: hir::OpaqueTyOrigin::TyAlias,
},
);
hir::ImplItemKind::TyAlias(ty)

View File

@ -2291,7 +2291,9 @@ pub enum OpaqueTyOrigin {
AsyncFn,
/// `let _: impl Trait = ...`
Binding,
/// Impl trait in type aliases, consts, statics, bounds.
/// type aliases: `type Foo = impl Trait;`
TyAlias,
/// Impl trait consts, statics, bounds.
Misc,
}

View File

@ -422,7 +422,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
// These opaque type inherit all lifetime parameters from their
// parent, so we have to check them all.
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc => 0,
hir::OpaqueTyOrigin::Binding
| hir::OpaqueTyOrigin::TyAlias
| hir::OpaqueTyOrigin::Misc => 0,
};
let span = tcx.def_span(def_id);
@ -581,6 +583,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Otherwise, generate the label we'll use in the error message.
hir::OpaqueTyOrigin::Binding
| hir::OpaqueTyOrigin::FnReturn
| hir::OpaqueTyOrigin::TyAlias
| hir::OpaqueTyOrigin::Misc => "impl Trait",
};
let msg = format!("ambiguous lifetime bound in `{}`", context_name);

View File

@ -659,7 +659,8 @@ fn check_opaque_meets_bounds<'tcx>(
// Checked when type checking the function containing them.
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => return,
// Can have different predicates to their defining use
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc => {}
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias => {
}
}
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

View File

@ -497,7 +497,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let mut skip_add = false;
if let ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() {
if let hir::OpaqueTyOrigin::Misc = opaque_defn.origin {
if let hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias = opaque_defn.origin
{
if def_id == defin_ty_def_id {
debug!(
"skipping adding concrete definition for opaque type {:?} {:?}",