Store the laziness of type aliases in the DefKind
This commit is contained in:
parent
34ccd04859
commit
5468336d6b
49 changed files with 208 additions and 93 deletions
|
@ -196,7 +196,9 @@ impl<'hir> Map<'hir> {
|
|||
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
|
||||
ItemKind::Mod(..) => DefKind::Mod,
|
||||
ItemKind::OpaqueTy(..) => DefKind::OpaqueTy,
|
||||
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
||||
ItemKind::TyAlias(..) => {
|
||||
DefKind::TyAlias { lazy: self.tcx.features().lazy_type_alias }
|
||||
}
|
||||
ItemKind::Enum(..) => DefKind::Enum,
|
||||
ItemKind::Struct(..) => DefKind::Struct,
|
||||
ItemKind::Union(..) => DefKind::Union,
|
||||
|
|
|
@ -231,7 +231,7 @@ rustc_queries! {
|
|||
action = {
|
||||
use rustc_hir::def::DefKind;
|
||||
match tcx.def_kind(key) {
|
||||
DefKind::TyAlias => "expanding type alias",
|
||||
DefKind::TyAlias { .. } => "expanding type alias",
|
||||
DefKind::TraitAlias => "expanding trait alias",
|
||||
_ => "computing type of",
|
||||
}
|
||||
|
|
|
@ -448,7 +448,7 @@ impl<'tcx> AdtDef<'tcx> {
|
|||
Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
|
||||
Res::Def(DefKind::Struct, _)
|
||||
| Res::Def(DefKind::Union, _)
|
||||
| Res::Def(DefKind::TyAlias, _)
|
||||
| Res::Def(DefKind::TyAlias { .. }, _)
|
||||
| Res::Def(DefKind::AssocTy, _)
|
||||
| Res::SelfTyParam { .. }
|
||||
| Res::SelfTyAlias { .. }
|
||||
|
|
|
@ -1062,7 +1062,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
if let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id)
|
||||
&& let hir::TyKind::Path(hir::QPath::Resolved(
|
||||
None,
|
||||
hir::Path { res: hir::def::Res::Def(DefKind::TyAlias, def_id), .. }, )) = hir_output.kind
|
||||
hir::Path { res: hir::def::Res::Def(DefKind::TyAlias { .. }, def_id), .. }, )) = hir_output.kind
|
||||
&& let Some(local_id) = def_id.as_local()
|
||||
&& let Some(alias_ty) = self.hir().get_by_def_id(local_id).alias_ty() // it is type alias
|
||||
&& let Some(alias_generics) = self.hir().get_by_def_id(local_id).generics()
|
||||
|
|
|
@ -492,7 +492,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
|
|||
Alias(Opaque, AliasTy { def_id, .. }) => {
|
||||
let parent = self.tcx.parent(def_id);
|
||||
let parent_ty = self.tcx.type_of(parent).instantiate_identity();
|
||||
if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||
if let DefKind::TyAlias { .. } | DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
|
||||
&& parent_opaque_def_id == def_id
|
||||
{
|
||||
|
@ -576,7 +576,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
|
|||
Alias(Opaque, AliasTy { def_id, .. }) => {
|
||||
let parent = self.tcx.parent(def_id);
|
||||
let parent_ty = self.tcx.type_of(parent).instantiate_identity();
|
||||
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||
if let hir::def::DefKind::TyAlias { .. } | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
|
||||
&& parent_opaque_def_id == def_id
|
||||
{
|
||||
|
|
|
@ -364,7 +364,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||
self.write_str(get_local_name(&self, symbol, parent, parent_key).as_str())?;
|
||||
self.write_str("::")?;
|
||||
} else if let DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait
|
||||
| DefKind::TyAlias | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind
|
||||
| DefKind::TyAlias { .. } | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind
|
||||
{
|
||||
} else {
|
||||
// If not covered above, like for example items out of `impl` blocks, fallback.
|
||||
|
@ -766,7 +766,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||
|
||||
let parent = self.tcx().parent(def_id);
|
||||
match self.tcx().def_kind(parent) {
|
||||
DefKind::TyAlias | DefKind::AssocTy => {
|
||||
DefKind::TyAlias { .. } | DefKind::AssocTy => {
|
||||
// NOTE: I know we should check for NO_QUERIES here, but it's alright.
|
||||
// `type_of` on a type alias or assoc type should never cause a cycle.
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) =
|
||||
|
@ -2982,7 +2982,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
|
|||
|
||||
match child.res {
|
||||
def::Res::Def(DefKind::AssocTy, _) => {}
|
||||
def::Res::Def(DefKind::TyAlias, _) => {}
|
||||
def::Res::Def(DefKind::TyAlias { .. }, _) => {}
|
||||
def::Res::Def(defkind, def_id) => {
|
||||
if let Some(ns) = defkind.ns() {
|
||||
collect_fn(&child.ident, ns, def_id);
|
||||
|
|
|
@ -1223,7 +1223,7 @@ impl<'tcx> AliasTy<'tcx> {
|
|||
DefKind::AssocTy if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) => ty::Inherent,
|
||||
DefKind::AssocTy => ty::Projection,
|
||||
DefKind::OpaqueTy => ty::Opaque,
|
||||
DefKind::TyAlias => ty::Weak,
|
||||
DefKind::TyAlias { .. } => ty::Weak,
|
||||
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
|
||||
}
|
||||
}
|
||||
|
@ -1945,7 +1945,7 @@ impl<'tcx> Ty<'tcx> {
|
|||
(kind, tcx.def_kind(alias_ty.def_id)),
|
||||
(ty::Opaque, DefKind::OpaqueTy)
|
||||
| (ty::Projection | ty::Inherent, DefKind::AssocTy)
|
||||
| (ty::Weak, DefKind::TyAlias)
|
||||
| (ty::Weak, DefKind::TyAlias { .. })
|
||||
);
|
||||
Ty::new(tcx, Alias(kind, alias_ty))
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
| DefKind::Enum
|
||||
| DefKind::Trait
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::TyAlias
|
||||
| DefKind::TyAlias { .. }
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
|
|
|
@ -209,7 +209,7 @@ fn find_item_ty_spans(
|
|||
match ty.kind {
|
||||
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
|
||||
if let Res::Def(kind, def_id) = path.res
|
||||
&& kind != DefKind::TyAlias {
|
||||
&& !matches!(kind, DefKind::TyAlias { .. }) {
|
||||
let check_params = def_id.as_local().map_or(true, |def_id| {
|
||||
if def_id == needle {
|
||||
spans.push(ty.span);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue