Special case type aliases from impl trait in const/static types
This commit is contained in:
parent
3abdb08351
commit
cdbb0ff8ca
5 changed files with 13 additions and 6 deletions
|
@ -342,7 +342,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ty,
|
ty,
|
||||||
ImplTraitContext::OtherOpaqueTy {
|
ImplTraitContext::OtherOpaqueTy {
|
||||||
capturable_lifetimes: &mut FxHashSet::default(),
|
capturable_lifetimes: &mut FxHashSet::default(),
|
||||||
origin: hir::OpaqueTyOrigin::Misc,
|
origin: hir::OpaqueTyOrigin::TyAlias,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
|
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
|
||||||
|
@ -918,7 +918,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ty,
|
ty,
|
||||||
ImplTraitContext::OtherOpaqueTy {
|
ImplTraitContext::OtherOpaqueTy {
|
||||||
capturable_lifetimes: &mut FxHashSet::default(),
|
capturable_lifetimes: &mut FxHashSet::default(),
|
||||||
origin: hir::OpaqueTyOrigin::Misc,
|
origin: hir::OpaqueTyOrigin::TyAlias,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
hir::ImplItemKind::TyAlias(ty)
|
hir::ImplItemKind::TyAlias(ty)
|
||||||
|
|
|
@ -2291,7 +2291,9 @@ pub enum OpaqueTyOrigin {
|
||||||
AsyncFn,
|
AsyncFn,
|
||||||
/// `let _: impl Trait = ...`
|
/// `let _: impl Trait = ...`
|
||||||
Binding,
|
Binding,
|
||||||
/// Impl trait in type aliases, consts, statics, bounds.
|
/// type aliases: `type Foo = impl Trait;`
|
||||||
|
TyAlias,
|
||||||
|
/// Impl trait consts, statics, bounds.
|
||||||
Misc,
|
Misc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
// These opaque type inherit all lifetime parameters from their
|
// These opaque type inherit all lifetime parameters from their
|
||||||
// parent, so we have to check them all.
|
// 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);
|
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.
|
// Otherwise, generate the label we'll use in the error message.
|
||||||
hir::OpaqueTyOrigin::Binding
|
hir::OpaqueTyOrigin::Binding
|
||||||
| hir::OpaqueTyOrigin::FnReturn
|
| hir::OpaqueTyOrigin::FnReturn
|
||||||
|
| hir::OpaqueTyOrigin::TyAlias
|
||||||
| hir::OpaqueTyOrigin::Misc => "impl Trait",
|
| hir::OpaqueTyOrigin::Misc => "impl Trait",
|
||||||
};
|
};
|
||||||
let msg = format!("ambiguous lifetime bound in `{}`", context_name);
|
let msg = format!("ambiguous lifetime bound in `{}`", context_name);
|
||||||
|
|
|
@ -659,7 +659,8 @@ fn check_opaque_meets_bounds<'tcx>(
|
||||||
// Checked when type checking the function containing them.
|
// Checked when type checking the function containing them.
|
||||||
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => return,
|
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => return,
|
||||||
// Can have different predicates to their defining use
|
// 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);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
|
|
|
@ -497,7 +497,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
let mut skip_add = false;
|
let mut skip_add = false;
|
||||||
|
|
||||||
if let ty::Opaque(defin_ty_def_id, _substs) = *definition_ty.kind() {
|
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 {
|
if def_id == defin_ty_def_id {
|
||||||
debug!(
|
debug!(
|
||||||
"skipping adding concrete definition for opaque type {:?} {:?}",
|
"skipping adding concrete definition for opaque type {:?} {:?}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue