Don't store lazyness in DefKind

This commit is contained in:
Michael Goulet 2023-09-26 02:15:32 +00:00
parent c614c17626
commit d6ce9ce115
51 changed files with 128 additions and 189 deletions

View File

@ -516,7 +516,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
// be the same as those of the ADT. // be the same as those of the ADT.
// FIXME: We should be able to do something similar to // FIXME: We should be able to do something similar to
// match_adt_and_segment in this case. // match_adt_and_segment in this case.
Res::Def(DefKind::TyAlias { .. }, _) => (), Res::Def(DefKind::TyAlias, _) => (),
_ => { _ => {
if let Some(last_segment) = path.segments.last() { if let Some(last_segment) = path.segments.last() {
if let Some(highlight) = self.match_adt_and_segment( if let Some(highlight) = self.match_adt_and_segment(

View File

@ -61,9 +61,7 @@ pub enum DefKind {
Variant, Variant,
Trait, Trait,
/// Type alias: `type Foo = Bar;` /// Type alias: `type Foo = Bar;`
TyAlias { TyAlias,
lazy: bool,
},
/// Type from an `extern` block. /// Type from an `extern` block.
ForeignTy, ForeignTy,
/// Trait alias: `trait IntIterator = Iterator<Item = i32>;` /// Trait alias: `trait IntIterator = Iterator<Item = i32>;`
@ -143,7 +141,7 @@ impl DefKind {
DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct", DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct",
DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct", DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
DefKind::OpaqueTy => "opaque type", DefKind::OpaqueTy => "opaque type",
DefKind::TyAlias { .. } => "type alias", DefKind::TyAlias => "type alias",
DefKind::TraitAlias => "trait alias", DefKind::TraitAlias => "trait alias",
DefKind::AssocTy => "associated type", DefKind::AssocTy => "associated type",
DefKind::Union => "union", DefKind::Union => "union",
@ -199,7 +197,7 @@ impl DefKind {
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy
@ -250,7 +248,7 @@ impl DefKind {
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy

View File

@ -101,7 +101,7 @@ impl Target {
DefKind::Mod => Target::Mod, DefKind::Mod => Target::Mod,
DefKind::ForeignMod => Target::ForeignMod, DefKind::ForeignMod => Target::ForeignMod,
DefKind::GlobalAsm => Target::GlobalAsm, DefKind::GlobalAsm => Target::GlobalAsm,
DefKind::TyAlias { .. } => Target::TyAlias, DefKind::TyAlias => Target::TyAlias,
DefKind::OpaqueTy => Target::OpaqueTy, DefKind::OpaqueTy => Target::OpaqueTy,
DefKind::Enum => Target::Enum, DefKind::Enum => Target::Enum,
DefKind::Struct => Target::Struct, DefKind::Struct => Target::Struct,

View File

@ -909,23 +909,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let tcx = self.tcx(); let tcx = self.tcx();
let args = self.ast_path_args_for_ty(span, did, item_segment); let args = self.ast_path_args_for_ty(span, did, item_segment);
if let DefKind::TyAlias { lazy: true } = tcx.def_kind(did) { if let DefKind::TyAlias = tcx.def_kind(did)
&& tcx.type_alias_is_lazy(did)
{
// Type aliases defined in crates that have the // Type aliases defined in crates that have the
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
// then actually instantiate the where bounds of. // then actually instantiate the where bounds of.
let alias_ty = tcx.mk_alias_ty(did, args); let alias_ty = tcx.mk_alias_ty(did, args);
Ty::new_alias(tcx, ty::Weak, alias_ty) Ty::new_alias(tcx, ty::Weak, alias_ty)
} else { } else {
let ty = tcx.at(span).type_of(did); tcx.at(span).type_of(did).instantiate(tcx, args)
if ty.skip_binder().has_opaque_types() {
// Type aliases referring to types that contain opaque types (but aren't just directly
// referencing a single opaque type) get encoded as a type alias that normalization will
// then actually instantiate the where bounds of.
let alias_ty = tcx.mk_alias_ty(did, args);
Ty::new_alias(tcx, ty::Weak, alias_ty)
} else {
ty.instantiate(tcx, args)
}
} }
} }
@ -2164,7 +2157,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
Res::Def( Res::Def(
DefKind::Enum DefKind::Enum
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::Struct | DefKind::Struct
| DefKind::Union | DefKind::Union
| DefKind::ForeignTy, | DefKind::ForeignTy,

View File

@ -640,7 +640,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
check_opaque(tcx, id); check_opaque(tcx, id);
} }
} }
DefKind::TyAlias { .. } => { DefKind::TyAlias => {
let pty_ty = tcx.type_of(id.owner_id).instantiate_identity(); let pty_ty = tcx.type_of(id.owner_id).instantiate_identity();
let generics = tcx.generics_of(id.owner_id); let generics = tcx.generics_of(id.owner_id);
check_type_params_are_used(tcx, &generics, pty_ty); check_type_params_are_used(tcx, &generics, pty_ty);

View File

@ -246,9 +246,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
// `ForeignItem`s are handled separately. // `ForeignItem`s are handled separately.
hir::ItemKind::ForeignMod { .. } => {} hir::ItemKind::ForeignMod { .. } => {}
hir::ItemKind::TyAlias(hir_ty, ast_generics) => { hir::ItemKind::TyAlias(hir_ty, ast_generics) => {
if tcx.features().lazy_type_alias if tcx.type_alias_is_lazy(item.owner_id) {
|| tcx.type_of(item.owner_id).skip_binder().has_opaque_types()
{
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected. // Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`. // E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow); check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow);
@ -1711,10 +1709,8 @@ fn check_variances_for_type_defn<'tcx>(
} }
} }
ItemKind::TyAlias(..) => { ItemKind::TyAlias(..) => {
let ty = tcx.type_of(item.owner_id).instantiate_identity(); if tcx.type_alias_is_lazy(item.owner_id) {
if tcx.type_of(item.owner_id).skip_binder().references_error() {
if tcx.features().lazy_type_alias || ty.has_opaque_types() {
if ty.references_error() {
return; return;
} }
} else { } else {

View File

@ -58,6 +58,7 @@ pub fn provide(providers: &mut Providers) {
*providers = Providers { *providers = Providers {
type_of: type_of::type_of, type_of: type_of::type_of,
type_of_opaque: type_of::type_of_opaque, type_of_opaque: type_of::type_of_opaque,
type_alias_is_lazy: type_of::type_alias_is_lazy,
item_bounds: item_bounds::item_bounds, item_bounds: item_bounds::item_bounds,
explicit_item_bounds: item_bounds::explicit_item_bounds, explicit_item_bounds: item_bounds::explicit_item_bounds,
generics_of: generics_of::generics_of, generics_of: generics_of::generics_of,

View File

@ -1519,7 +1519,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
DefKind::Struct DefKind::Struct
| DefKind::Union | DefKind::Union
| DefKind::Enum | DefKind::Enum
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::Trait, | DefKind::Trait,
def_id, def_id,
) if depth == 0 => Some(def_id), ) if depth == 0 => Some(def_id),
@ -2029,7 +2029,7 @@ fn is_late_bound_map(
hir::TyKind::Path(hir::QPath::Resolved( hir::TyKind::Path(hir::QPath::Resolved(
None, None,
hir::Path { res: Res::Def(DefKind::TyAlias { .. }, alias_def), segments, span }, hir::Path { res: Res::Def(DefKind::TyAlias, alias_def), segments, span },
)) => { )) => {
// See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider // See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider
// args to be unconstrained. // args to be unconstrained.

View File

@ -623,3 +623,25 @@ fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
.emit(); .emit();
} }
} }
pub fn type_alias_is_lazy<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool {
use hir::intravisit::Visitor;
if tcx.features().lazy_type_alias {
return true;
}
struct HasTait {
has_type_alias_impl_trait: bool,
}
impl<'tcx> Visitor<'tcx> for HasTait {
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
if let hir::TyKind::OpaqueDef(..) = t.kind {
self.has_type_alias_impl_trait = true;
} else {
hir::intravisit::walk_ty(self, t);
}
}
}
let mut has_tait = HasTait { has_type_alias_impl_trait: false };
has_tait.visit_ty(tcx.hir().expect_item(def_id).expect_ty_alias().0);
has_tait.has_type_alias_impl_trait
}

View File

@ -6,7 +6,7 @@
use hir::def_id::{DefId, LocalDefId}; use hir::def_id::{DefId, LocalDefId};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{GenericArgKind, GenericArgsRef}; use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
use super::terms::VarianceTerm::*; use super::terms::VarianceTerm::*;
@ -78,9 +78,7 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
} }
} }
DefKind::Fn | DefKind::AssocFn => constraint_cx.build_constraints_for_item(def_id), DefKind::Fn | DefKind::AssocFn => constraint_cx.build_constraints_for_item(def_id),
DefKind::TyAlias { lazy } DefKind::TyAlias if tcx.type_alias_is_lazy(def_id) => {
if lazy || tcx.type_of(def_id).instantiate_identity().has_opaque_types() =>
{
constraint_cx.build_constraints_for_item(def_id) constraint_cx.build_constraints_for_item(def_id)
} }
_ => {} _ => {}
@ -110,8 +108,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
// The type as returned by `type_of` is the underlying type and generally not a weak projection. // The type as returned by `type_of` is the underlying type and generally not a weak projection.
// Therefore we need to check the `DefKind` first. // Therefore we need to check the `DefKind` first.
if let DefKind::TyAlias { lazy } = tcx.def_kind(def_id) if let DefKind::TyAlias = tcx.def_kind(def_id)
&& (lazy || ty.has_opaque_types()) && tcx.type_alias_is_lazy(def_id)
{ {
self.add_constraints_from_ty(current_item, ty, self.covariant); self.add_constraints_from_ty(current_item, ty, self.covariant);
return; return;

View File

@ -8,7 +8,7 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::{self, CrateVariancesMap, GenericArgsRef, Ty, TyCtxt}; use rustc_middle::ty::{self, CrateVariancesMap, GenericArgsRef, Ty, TyCtxt};
use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable};
use std::ops::ControlFlow; use std::ops::ControlFlow;
/// Defines the `TermsContext` basically houses an arena where we can /// Defines the `TermsContext` basically houses an arena where we can
@ -56,9 +56,7 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
let crate_map = tcx.crate_variances(()); let crate_map = tcx.crate_variances(());
return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]); return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]);
} }
DefKind::TyAlias { lazy } DefKind::TyAlias if tcx.type_alias_is_lazy(item_def_id) => {
if lazy || tcx.type_of(item_def_id).instantiate_identity().has_opaque_types() =>
{
// These are inferred. // These are inferred.
let crate_map = tcx.crate_variances(()); let crate_map = tcx.crate_variances(());
return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]); return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]);

View File

@ -12,7 +12,7 @@
use rustc_arena::DroplessArena; use rustc_arena::DroplessArena;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap}; use rustc_hir::def_id::{LocalDefId, LocalDefIdMap};
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, TyCtxt};
use std::fmt; use std::fmt;
use self::VarianceTerm::*; use self::VarianceTerm::*;
@ -97,9 +97,7 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
} }
} }
DefKind::Fn | DefKind::AssocFn => terms_cx.add_inferreds_for_item(def_id), DefKind::Fn | DefKind::AssocFn => terms_cx.add_inferreds_for_item(def_id),
DefKind::TyAlias { lazy } DefKind::TyAlias if tcx.type_alias_is_lazy(def_id) => {
if lazy || tcx.type_of(def_id).instantiate_identity().has_opaque_types() =>
{
terms_cx.add_inferreds_for_item(def_id) terms_cx.add_inferreds_for_item(def_id)
} }
_ => {} _ => {}

View File

@ -1370,10 +1370,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
_ => bug!("unexpected type: {:?}", ty.normalized), _ => bug!("unexpected type: {:?}", ty.normalized),
}, },
Res::Def( Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
DefKind::Struct | DefKind::Union | DefKind::TyAlias { .. } | DefKind::AssocTy,
_,
)
| Res::SelfTyParam { .. } | Res::SelfTyParam { .. }
| Res::SelfTyAlias { .. } => match ty.normalized.ty_adt_def() { | Res::SelfTyAlias { .. } => match ty.normalized.ty_adt_def() {
Some(adt) if !adt.is_enum() => { Some(adt) if !adt.is_enum() => {

View File

@ -557,10 +557,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
Ok(adt_def.variant_index_with_ctor_id(variant_ctor_id)) Ok(adt_def.variant_index_with_ctor_id(variant_ctor_id))
} }
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _) Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _)
| Res::Def( | Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
DefKind::Struct | DefKind::Union | DefKind::TyAlias { .. } | DefKind::AssocTy,
_,
)
| Res::SelfCtor(..) | Res::SelfCtor(..)
| Res::SelfTyParam { .. } | Res::SelfTyParam { .. }
| Res::SelfTyAlias { .. } => { | Res::SelfTyAlias { .. } => {

View File

@ -918,7 +918,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
// //
// See the `need_type_info/issue-103053.rs` test for // See the `need_type_info/issue-103053.rs` test for
// a example. // a example.
if !matches!(path.res, Res::Def(DefKind::TyAlias { .. }, _)) => { if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
if let Some(ty) = self.opt_node_type(expr.hir_id) if let Some(ty) = self.opt_node_type(expr.hir_id)
&& let ty::Adt(_, args) = ty.kind() && let ty::Adt(_, args) = ty.kind()
{ {
@ -1047,7 +1047,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
) => { ) => {
if tcx.res_generics_def_id(path.res) != Some(def.did()) { if tcx.res_generics_def_id(path.res) != Some(def.did()) {
match path.res { match path.res {
Res::Def(DefKind::TyAlias { .. }, _) => { Res::Def(DefKind::TyAlias, _) => {
// FIXME: Ideally we should support this. For that // FIXME: Ideally we should support this. For that
// we have to map back from the self type to the // we have to map back from the self type to the
// type alias though. That's difficult. // type alias though. That's difficult.

View File

@ -1454,13 +1454,13 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
let hir::ItemKind::TyAlias(hir_ty, type_alias_generics) = &item.kind else { return }; let hir::ItemKind::TyAlias(hir_ty, type_alias_generics) = &item.kind else { return };
if cx.tcx.features().lazy_type_alias { // Bounds of lazy type aliases and TAITs are respected.
// Bounds of lazy type aliases are respected. if cx.tcx.type_alias_is_lazy(item.owner_id) {
return; return;
} }
let ty = cx.tcx.type_of(item.owner_id).skip_binder(); let ty = cx.tcx.type_of(item.owner_id).skip_binder();
if ty.has_opaque_types() || ty.has_inherent_projections() { if ty.has_inherent_projections() {
// Bounds of type aliases that contain opaque types or inherent projections are respected. // Bounds of type aliases that contain opaque types or inherent projections are respected.
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X = Type::Inherent;`. // E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X = Type::Inherent;`.
return; return;

View File

@ -210,6 +210,7 @@ provide! { tcx, def_id, other, cdata,
inferred_outlives_of => { table_defaulted_array } inferred_outlives_of => { table_defaulted_array }
super_predicates_of => { table } super_predicates_of => { table }
type_of => { table } type_of => { table }
type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) }
variances_of => { table } variances_of => { table }
fn_sig => { table } fn_sig => { table }
codegen_fn_attrs => { table } codegen_fn_attrs => { table }

View File

@ -31,7 +31,6 @@ use rustc_middle::query::Providers;
use rustc_middle::traits::specialization_graph; use rustc_middle::traits::specialization_graph;
use rustc_middle::ty::codec::TyEncoder; use rustc_middle::ty::codec::TyEncoder;
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams}; use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams};
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::{self, AssocItemContainer, SymbolName, Ty, TyCtxt}; use rustc_middle::ty::{self, AssocItemContainer, SymbolName, Ty, TyCtxt};
use rustc_middle::util::common::to_readable_str; use rustc_middle::util::common::to_readable_str;
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
@ -827,7 +826,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy
@ -862,7 +861,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy
@ -903,7 +902,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::Impl { .. } => true, | DefKind::Impl { .. } => true,
DefKind::TyAlias { .. } DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy
@ -938,7 +937,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy
@ -982,7 +981,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
| DefKind::Const | DefKind::Const
| DefKind::Fn | DefKind::Fn
| DefKind::ForeignMod | DefKind::ForeignMod
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::Enum | DefKind::Enum
| DefKind::Union | DefKind::Union
@ -1092,9 +1091,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
| DefKind::Closure | DefKind::Closure
| DefKind::Generator | DefKind::Generator
| DefKind::ExternCrate => false, | DefKind::ExternCrate => false,
DefKind::TyAlias { lazy } => { DefKind::TyAlias => tcx.type_alias_is_lazy(def_id),
lazy || tcx.type_of(def_id).instantiate_identity().has_opaque_types()
}
} }
} }
@ -1105,7 +1102,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy
@ -1145,7 +1142,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(..) | DefKind::Static(..)
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::AssocFn | DefKind::AssocFn
@ -1205,7 +1202,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
| DefKind::Const | DefKind::Const
| DefKind::Static(..) | DefKind::Static(..)
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::Impl { .. } | DefKind::Impl { .. }
@ -1246,7 +1243,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::AnonConst | DefKind::AnonConst
| DefKind::Static(..) | DefKind::Static(..)
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::Impl { of_trait: false } | DefKind::Impl { of_trait: false }
| DefKind::ForeignTy | DefKind::ForeignTy
@ -1279,7 +1276,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
| DefKind::Field | DefKind::Field
| DefKind::Fn | DefKind::Fn
| DefKind::Static(..) | DefKind::Static(..)
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::Impl { .. } | DefKind::Impl { .. }
@ -1451,6 +1448,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if let DefKind::Macro(_) = def_kind { if let DefKind::Macro(_) = def_kind {
self.encode_info_for_macro(local_id); self.encode_info_for_macro(local_id);
} }
if let DefKind::TyAlias = def_kind {
self.tables
.type_alias_is_lazy
.set(def_id.index, self.tcx.type_alias_is_lazy(def_id));
}
if let DefKind::OpaqueTy = def_kind { if let DefKind::OpaqueTy = def_kind {
self.encode_explicit_item_bounds(def_id); self.encode_explicit_item_bounds(def_id);
self.tables self.tables

View File

@ -383,6 +383,7 @@ define_tables! {
is_intrinsic: Table<DefIndex, bool>, is_intrinsic: Table<DefIndex, bool>,
is_macro_rules: Table<DefIndex, bool>, is_macro_rules: Table<DefIndex, bool>,
is_type_alias_impl_trait: Table<DefIndex, bool>, is_type_alias_impl_trait: Table<DefIndex, bool>,
type_alias_is_lazy: Table<DefIndex, bool>,
attr_flags: Table<DefIndex, AttrFlags>, attr_flags: Table<DefIndex, AttrFlags>,
def_path_hashes: Table<DefIndex, DefPathHash>, def_path_hashes: Table<DefIndex, DefPathHash>,
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,

View File

@ -145,8 +145,7 @@ fixed_size_enum! {
( Enum ) ( Enum )
( Variant ) ( Variant )
( Trait ) ( Trait )
( TyAlias { lazy: false } ) ( TyAlias )
( TyAlias { lazy: true } )
( ForeignTy ) ( ForeignTy )
( TraitAlias ) ( TraitAlias )
( AssocTy ) ( AssocTy )

View File

@ -196,9 +196,7 @@ impl<'hir> Map<'hir> {
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind), ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
ItemKind::Mod(..) => DefKind::Mod, ItemKind::Mod(..) => DefKind::Mod,
ItemKind::OpaqueTy(..) => DefKind::OpaqueTy, ItemKind::OpaqueTy(..) => DefKind::OpaqueTy,
ItemKind::TyAlias(..) => { ItemKind::TyAlias(..) => DefKind::TyAlias,
DefKind::TyAlias { lazy: self.tcx.features().lazy_type_alias }
}
ItemKind::Enum(..) => DefKind::Enum, ItemKind::Enum(..) => DefKind::Enum,
ItemKind::Struct(..) => DefKind::Struct, ItemKind::Struct(..) => DefKind::Struct,
ItemKind::Union(..) => DefKind::Union, ItemKind::Union(..) => DefKind::Union,

View File

@ -229,7 +229,7 @@ rustc_queries! {
action = { action = {
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
match tcx.def_kind(key) { match tcx.def_kind(key) {
DefKind::TyAlias { .. } => "expanding type alias", DefKind::TyAlias => "expanding type alias",
DefKind::TraitAlias => "expanding trait alias", DefKind::TraitAlias => "expanding trait alias",
_ => "computing type of", _ => "computing type of",
} }
@ -251,6 +251,14 @@ rustc_queries! {
} }
} }
query type_alias_is_lazy(key: DefId) -> bool {
desc { |tcx|
"computing whether `{path}` is a lazy type alias",
path = tcx.def_path_str(key),
}
separate_provide_extern
}
query collect_return_position_impl_trait_in_trait_tys(key: DefId) query collect_return_position_impl_trait_in_trait_tys(key: DefId)
-> Result<&'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed> -> Result<&'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed>
{ {

View File

@ -448,7 +448,7 @@ impl<'tcx> AdtDef<'tcx> {
Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid), Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
Res::Def(DefKind::Struct, _) Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _) | Res::Def(DefKind::Union, _)
| Res::Def(DefKind::TyAlias { .. }, _) | Res::Def(DefKind::TyAlias, _)
| Res::Def(DefKind::AssocTy, _) | Res::Def(DefKind::AssocTy, _)
| Res::SelfTyParam { .. } | Res::SelfTyParam { .. }
| Res::SelfTyAlias { .. } | Res::SelfTyAlias { .. }

View File

@ -1114,7 +1114,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) 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( && let hir::TyKind::Path(hir::QPath::Resolved(
None, 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(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_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() && let Some(alias_generics) = self.hir().get_by_def_id(local_id).generics()

View File

@ -493,7 +493,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => { Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id); let parent = self.tcx.parent(def_id);
let parent_ty = self.tcx.type_of(parent).instantiate_identity(); 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() && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& parent_opaque_def_id == def_id && parent_opaque_def_id == def_id
{ {
@ -577,7 +577,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => { Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id); let parent = self.tcx.parent(def_id);
let parent_ty = self.tcx.type_of(parent).instantiate_identity(); 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() && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& parent_opaque_def_id == def_id && parent_opaque_def_id == def_id
{ {

View File

@ -360,7 +360,7 @@ pub trait PrettyPrinter<'tcx>:
self.write_str(get_local_name(&self, symbol, parent, parent_key).as_str())?; self.write_str(get_local_name(&self, symbol, parent, parent_key).as_str())?;
self.write_str("::")?; self.write_str("::")?;
} else if let DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait } 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 { } else {
// If not covered above, like for example items out of `impl` blocks, fallback. // 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); let parent = self.tcx().parent(def_id);
match self.tcx().def_kind(parent) { 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. // 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. // `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, .. }) = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) =
@ -2998,7 +2998,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
match child.res { match child.res {
def::Res::Def(DefKind::AssocTy, _) => {} def::Res::Def(DefKind::AssocTy, _) => {}
def::Res::Def(DefKind::TyAlias { .. }, _) => {} def::Res::Def(DefKind::TyAlias, _) => {}
def::Res::Def(defkind, def_id) => { def::Res::Def(defkind, def_id) => {
if let Some(ns) = defkind.ns() { if let Some(ns) = defkind.ns() {
collect_fn(&child.ident, ns, def_id); collect_fn(&child.ident, ns, def_id);

View File

@ -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 if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) => ty::Inherent,
DefKind::AssocTy => ty::Projection, DefKind::AssocTy => ty::Projection,
DefKind::OpaqueTy => ty::Opaque, DefKind::OpaqueTy => ty::Opaque,
DefKind::TyAlias { .. } => ty::Weak, DefKind::TyAlias => ty::Weak,
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"), kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
} }
} }
@ -1959,7 +1959,7 @@ impl<'tcx> Ty<'tcx> {
(kind, tcx.def_kind(alias_ty.def_id)), (kind, tcx.def_kind(alias_ty.def_id)),
(ty::Opaque, DefKind::OpaqueTy) (ty::Opaque, DefKind::OpaqueTy)
| (ty::Projection | ty::Inherent, DefKind::AssocTy) | (ty::Projection | ty::Inherent, DefKind::AssocTy)
| (ty::Weak, DefKind::TyAlias { .. }) | (ty::Weak, DefKind::TyAlias)
); );
Ty::new(tcx, Alias(kind, alias_ty)) Ty::new(tcx, Alias(kind, alias_ty))
} }

View File

@ -156,7 +156,7 @@ impl<'tcx> TyCtxt<'tcx> {
| DefKind::Enum | DefKind::Enum
| DefKind::Trait | DefKind::Trait
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy

View File

@ -217,7 +217,7 @@ fn find_item_ty_spans(
match ty.kind { match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => { hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
if let Res::Def(kind, def_id) = path.res if let Res::Def(kind, def_id) = path.res
&& !matches!(kind, DefKind::TyAlias { .. }) { && !matches!(kind, DefKind::TyAlias) {
let check_params = def_id.as_local().map_or(true, |def_id| { let check_params = def_id.as_local().map_or(true, |def_id| {
if def_id == needle { if def_id == needle {
spans.push(ty.span); spans.push(ty.span);

View File

@ -439,7 +439,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
DefKind::Struct DefKind::Struct
| DefKind::Ctor(CtorOf::Struct, ..) | DefKind::Ctor(CtorOf::Struct, ..)
| DefKind::Union | DefKind::Union
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::AssocTy, | DefKind::AssocTy,
_, _,
) )

View File

@ -143,7 +143,7 @@ fn mark_used_by_default_parameters<'tcx>(
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::AssocTy | DefKind::AssocTy

View File

@ -21,7 +21,7 @@ pub fn test_abi(tcx: TyCtxt<'_>) {
DefKind::Fn | DefKind::AssocFn => { DefKind::Fn | DefKind::AssocFn => {
dump_abi_of_fn_item(tcx, id, attr); dump_abi_of_fn_item(tcx, id, attr);
} }
DefKind::TyAlias { .. } => { DefKind::TyAlias => {
dump_abi_of_fn_type(tcx, id, attr); dump_abi_of_fn_type(tcx, id, attr);
} }
_ => { _ => {

View File

@ -96,7 +96,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
fn handle_res(&mut self, res: Res) { fn handle_res(&mut self, res: Res) {
match res { match res {
Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::TyAlias { .. }, def_id) => { Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::TyAlias, def_id) => {
self.check_def_id(def_id); self.check_def_id(def_id);
} }
_ if self.in_pat => {} _ if self.in_pat => {}
@ -923,7 +923,7 @@ impl<'tcx> DeadVisitor<'tcx> {
| DefKind::Fn | DefKind::Fn
| DefKind::Static(_) | DefKind::Static(_)
| DefKind::Const | DefKind::Const
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::Enum | DefKind::Enum
| DefKind::Union | DefKind::Union
| DefKind::ForeignTy => self.warn_dead_code(def_id, "used"), | DefKind::ForeignTy => self.warn_dead_code(def_id, "used"),

View File

@ -23,7 +23,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) {
for id in tcx.hir_crate_items(()).definitions() { for id in tcx.hir_crate_items(()).definitions() {
for attr in tcx.get_attrs(id, sym::rustc_layout) { for attr in tcx.get_attrs(id, sym::rustc_layout) {
match tcx.def_kind(id) { match tcx.def_kind(id) {
DefKind::TyAlias { .. } | DefKind::Enum | DefKind::Struct | DefKind::Union => { DefKind::TyAlias | DefKind::Enum | DefKind::Struct | DefKind::Union => {
dump_layout_of(tcx, id, attr); dump_layout_of(tcx, id, attr);
} }
_ => { _ => {

View File

@ -588,7 +588,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
self.update(def_id, macro_ev, Level::Reachable); self.update(def_id, macro_ev, Level::Reachable);
match def_kind { match def_kind {
// No type privacy, so can be directly marked as reachable. // No type privacy, so can be directly marked as reachable.
DefKind::Const | DefKind::Static(_) | DefKind::TraitAlias | DefKind::TyAlias { .. } => { DefKind::Const | DefKind::Static(_) | DefKind::TraitAlias | DefKind::TyAlias => {
if vis.is_accessible_from(module, self.tcx) { if vis.is_accessible_from(module, self.tcx) {
self.update(def_id, macro_ev, Level::Reachable); self.update(def_id, macro_ev, Level::Reachable);
} }
@ -1637,8 +1637,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
let def_kind = tcx.def_kind(def_id); let def_kind = tcx.def_kind(def_id);
match def_kind { match def_kind {
DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias { .. } => { DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias => {
if let DefKind::TyAlias { .. } = def_kind { if let DefKind::TyAlias = def_kind {
self.check_unnameable(def_id, effective_vis); self.check_unnameable(def_id, effective_vis);
} }
self.check(def_id, item_visibility, effective_vis).generics().predicates().ty(); self.check(def_id, item_visibility, effective_vis).generics().predicates().ty();

View File

@ -580,9 +580,7 @@ pub(crate) fn report_cycle<'a>(
}); });
} }
let alias = if stack let alias = if stack.iter().all(|entry| matches!(entry.query.def_kind, Some(DefKind::TyAlias)))
.iter()
.all(|entry| matches!(entry.query.def_kind, Some(DefKind::TyAlias { .. })))
{ {
Some(crate::error::Alias::Ty) Some(crate::error::Alias::Ty)
} else if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TraitAlias)) { } else if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TraitAlias)) {

View File

@ -698,10 +698,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
// These items live in the type namespace. // These items live in the type namespace.
ItemKind::TyAlias(..) => { ItemKind::TyAlias(..) => {
let res = Res::Def( let res = Res::Def(DefKind::TyAlias, def_id);
DefKind::TyAlias { lazy: self.r.tcx.features().lazy_type_alias },
def_id,
);
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
} }
@ -950,7 +947,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
DefKind::Struct DefKind::Struct
| DefKind::Union | DefKind::Union
| DefKind::Variant | DefKind::Variant
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::TraitAlias | DefKind::TraitAlias

View File

@ -474,7 +474,7 @@ impl<'a> PathSource<'a> {
| DefKind::Enum | DefKind::Enum
| DefKind::Trait | DefKind::Trait
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::AssocTy | DefKind::AssocTy
| DefKind::TyParam | DefKind::TyParam
| DefKind::OpaqueTy | DefKind::OpaqueTy
@ -513,7 +513,7 @@ impl<'a> PathSource<'a> {
DefKind::Struct DefKind::Struct
| DefKind::Union | DefKind::Union
| DefKind::Variant | DefKind::Variant
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::AssocTy, | DefKind::AssocTy,
_, _,
) | Res::SelfTyParam { .. } ) | Res::SelfTyParam { .. }
@ -1766,7 +1766,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
Res::Def(DefKind::Struct, def_id) Res::Def(DefKind::Struct, def_id)
| Res::Def(DefKind::Union, def_id) | Res::Def(DefKind::Union, def_id)
| Res::Def(DefKind::Enum, def_id) | Res::Def(DefKind::Enum, def_id)
| Res::Def(DefKind::TyAlias { .. }, def_id) | Res::Def(DefKind::TyAlias, def_id)
| Res::Def(DefKind::Trait, def_id) | Res::Def(DefKind::Trait, def_id)
if i + 1 == proj_start => if i + 1 == proj_start =>
{ {

View File

@ -1429,7 +1429,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
(Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => { (Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => {
err.span_label(span, fallback_label.to_string()); err.span_label(span, fallback_label.to_string());
} }
(Res::Def(DefKind::TyAlias { .. }, def_id), PathSource::Trait(_)) => { (Res::Def(DefKind::TyAlias, def_id), PathSource::Trait(_)) => {
err.span_label(span, "type aliases cannot be used as traits"); err.span_label(span, "type aliases cannot be used as traits");
if self.r.tcx.sess.is_nightly_build() { if self.r.tcx.sess.is_nightly_build() {
let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \ let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
@ -1598,7 +1598,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err.span_label(span, fallback_label.to_string()); err.span_label(span, fallback_label.to_string());
err.note("can't use `Self` as a constructor, you must use the implemented struct"); err.note("can't use `Self` as a constructor, you must use the implemented struct");
} }
(Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, _), _) if ns == ValueNS => { (Res::Def(DefKind::TyAlias | DefKind::AssocTy, _), _) if ns == ValueNS => {
err.note("can't use a type alias as a constructor"); err.note("can't use a type alias as a constructor");
} }
_ => return false, _ => return false,

View File

@ -59,7 +59,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
} }
DefKind::AnonConst => self.normalize_anon_const(goal), DefKind::AnonConst => self.normalize_anon_const(goal),
DefKind::OpaqueTy => self.normalize_opaque_type(goal), DefKind::OpaqueTy => self.normalize_opaque_type(goal),
DefKind::TyAlias { .. } => self.normalize_weak_type(goal), DefKind::TyAlias => self.normalize_weak_type(goal),
kind => bug!("unknown DefKind {} in projection goal: {goal:#?}", kind.descr(def_id)), kind => bug!("unknown DefKind {} in projection goal: {goal:#?}", kind.descr(def_id)),
} }
} }

View File

@ -119,7 +119,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
}, },
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)), DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)),
DefKind::OpaqueTy => match tcx.def_kind(tcx.local_parent(def_id)) { DefKind::OpaqueTy => match tcx.def_kind(tcx.local_parent(def_id)) {
DefKind::TyAlias { .. } => ty::List::empty(), DefKind::TyAlias => ty::List::empty(),
DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)), DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)),
// Nested opaque types only occur in associated types: // Nested opaque types only occur in associated types:
// ` type Opaque<T> = impl Trait<&'static T, AssocTy = impl Nested>; ` // ` type Opaque<T> = impl Trait<&'static T, AssocTy = impl Nested>; `
@ -136,7 +136,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
| DefKind::Enum | DefKind::Enum
| DefKind::Variant | DefKind::Variant
| DefKind::Trait | DefKind::Trait
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::TraitAlias | DefKind::TraitAlias
| DefKind::TyParam | DefKind::TyParam

View File

@ -53,9 +53,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
fn parent(&self) -> Option<LocalDefId> { fn parent(&self) -> Option<LocalDefId> {
match self.tcx.def_kind(self.item) { match self.tcx.def_kind(self.item) {
DefKind::AnonConst | DefKind::InlineConst | DefKind::Fn | DefKind::TyAlias { .. } => { DefKind::AnonConst | DefKind::InlineConst | DefKind::Fn | DefKind::TyAlias => None,
None
}
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => { DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
Some(self.tcx.local_parent(self.item)) Some(self.tcx.local_parent(self.item))
} }
@ -118,7 +116,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
#[instrument(level = "trace", skip(self))] #[instrument(level = "trace", skip(self))]
fn visit_nested_item(&mut self, id: rustc_hir::ItemId) { fn visit_nested_item(&mut self, id: rustc_hir::ItemId) {
let id = id.owner_id.def_id; let id = id.owner_id.def_id;
if let DefKind::TyAlias { .. } = self.collector.tcx.def_kind(id) { if let DefKind::TyAlias = self.collector.tcx.def_kind(id) {
let items = self.collector.tcx.opaque_types_defined_by(id); let items = self.collector.tcx.opaque_types_defined_by(id);
self.collector.opaques.extend(items); self.collector.opaques.extend(items);
} }
@ -297,7 +295,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
collector.collect_body_and_predicate_taits(); collector.collect_body_and_predicate_taits();
} }
// We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds` // We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds`
DefKind::TyAlias { .. } | DefKind::AssocTy => { DefKind::TyAlias | DefKind::AssocTy => {
tcx.type_of(item).instantiate_identity().visit_with(&mut collector); tcx.type_of(item).instantiate_identity().visit_with(&mut collector);
} }
DefKind::OpaqueTy => { DefKind::OpaqueTy => {

View File

@ -80,7 +80,7 @@ pub(crate) fn try_inline(
build_impls(cx, did, attrs_without_docs, &mut ret); build_impls(cx, did, attrs_without_docs, &mut ret);
clean::UnionItem(build_union(cx, did)) clean::UnionItem(build_union(cx, did))
} }
Res::Def(DefKind::TyAlias { .. }, did) => { Res::Def(DefKind::TyAlias, did) => {
record_extern_fqn(cx, did, ItemType::TypeAlias); record_extern_fqn(cx, did, ItemType::TypeAlias);
build_impls(cx, did, attrs_without_docs, &mut ret); build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TypeAliasItem(build_type_alias(cx, did)) clean::TypeAliasItem(build_type_alias(cx, did))

View File

@ -1758,7 +1758,7 @@ fn maybe_expand_private_type_alias<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
path: &hir::Path<'tcx>, path: &hir::Path<'tcx>,
) -> Option<Type> { ) -> Option<Type> {
let Res::Def(DefKind::TyAlias { .. }, def_id) = path.res else { return None }; let Res::Def(DefKind::TyAlias, def_id) = path.res else { return None };
// Substitute private type aliases // Substitute private type aliases
let def_id = def_id.as_local()?; let def_id = def_id.as_local()?;
let alias = if !cx.cache.effective_visibilities.is_exported(cx.tcx, def_id.to_def_id()) let alias = if !cx.cache.effective_visibilities.is_exported(cx.tcx, def_id.to_def_id())
@ -2027,7 +2027,7 @@ impl<'tcx> ContainerTy<'tcx> {
let (DefKind::Struct let (DefKind::Struct
| DefKind::Union | DefKind::Union
| DefKind::Enum | DefKind::Enum
| DefKind::TyAlias { .. } | DefKind::TyAlias
| DefKind::Trait) = tcx.def_kind(container) | DefKind::Trait) = tcx.def_kind(container)
else { else {
return ObjectLifetimeDefault::Empty; return ObjectLifetimeDefault::Empty;
@ -2859,7 +2859,7 @@ fn clean_impl<'tcx>(
let for_ = clean_ty(impl_.self_ty, cx); let for_ = clean_ty(impl_.self_ty, cx);
let type_alias = let type_alias =
for_.def_id(&cx.cache).and_then(|alias_def_id: DefId| match tcx.def_kind(alias_def_id) { for_.def_id(&cx.cache).and_then(|alias_def_id: DefId| match tcx.def_kind(alias_def_id) {
DefKind::TyAlias { .. } => Some(clean_middle_ty( DefKind::TyAlias => Some(clean_middle_ty(
ty::Binder::dummy(tcx.type_of(def_id).instantiate_identity()), ty::Binder::dummy(tcx.type_of(def_id).instantiate_identity()),
cx, cx,
Some(def_id.to_def_id()), Some(def_id.to_def_id()),

View File

@ -115,7 +115,7 @@ impl From<DefKind> for ItemType {
DefKind::Struct => Self::Struct, DefKind::Struct => Self::Struct,
DefKind::Union => Self::Union, DefKind::Union => Self::Union,
DefKind::Trait => Self::Trait, DefKind::Trait => Self::Trait,
DefKind::TyAlias { .. } => Self::TypeAlias, DefKind::TyAlias => Self::TypeAlias,
DefKind::TraitAlias => Self::TraitAlias, DefKind::TraitAlias => Self::TraitAlias,
DefKind::Macro(kind) => match kind { DefKind::Macro(kind) => match kind {
MacroKind::Bang => ItemType::Macro, MacroKind::Bang => ItemType::Macro,

View File

@ -593,7 +593,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
.unwrap_or(Vec::new()) .unwrap_or(Vec::new())
} }
} }
Res::Def(DefKind::TyAlias { .. }, did) => { Res::Def(DefKind::TyAlias, did) => {
// Resolve the link on the type the alias points to. // Resolve the link on the type the alias points to.
// FIXME: if the associated item is defined directly on the type alias, // FIXME: if the associated item is defined directly on the type alias,
// it will show up on its documentation page, we should link there instead. // it will show up on its documentation page, we should link there instead.

View File

@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
&& fields && fields
.iter() .iter()
.all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit)) .all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit))
&& !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias { .. }, ..)) && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..))
{ {
let expr_spans = fields let expr_spans = fields
.iter() .iter()

View File

@ -288,7 +288,7 @@ pub fn is_wild(pat: &Pat<'_>) -> bool {
/// Checks if the given `QPath` belongs to a type alias. /// Checks if the given `QPath` belongs to a type alias.
pub fn is_ty_alias(qpath: &QPath<'_>) -> bool { pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
match *qpath { match *qpath {
QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, ..)), QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias | DefKind::AssocTy, ..)),
QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) }, QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) },
_ => false, _ => false,
} }

View File

@ -220,7 +220,7 @@ fn path_segment_certainty(
// See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value. // See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value.
let certainty = lhs.join_clearing_def_ids(rhs); let certainty = lhs.join_clearing_def_ids(rhs);
if resolves_to_type { if resolves_to_type {
if let DefKind::TyAlias { .. } = cx.tcx.def_kind(def_id) { if let DefKind::TyAlias = cx.tcx.def_kind(def_id) {
adt_def_id(cx.tcx.type_of(def_id).instantiate_identity()) adt_def_id(cx.tcx.type_of(def_id).instantiate_identity())
.map_or(certainty, |def_id| certainty.with_def_id(def_id)) .map_or(certainty, |def_id| certainty.with_def_id(def_id))
} else { } else {

View File

@ -1,6 +1,5 @@
// FIXME(inherent_associated_types): This should be `check-pass`
// known-bug: #108491
// compile-flags: --crate-type=lib // compile-flags: --crate-type=lib
// check-pass
#![feature(inherent_associated_types)] #![feature(inherent_associated_types)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
@ -8,11 +7,6 @@
// Bounds on the self type play a major role in the resolution of inherent associated types (*). // Bounds on the self type play a major role in the resolution of inherent associated types (*).
// As a result of that, if a type alias contains any then its bounds have to be respected and the // As a result of that, if a type alias contains any then its bounds have to be respected and the
// lint `type_alias_bounds` should not fire. // lint `type_alias_bounds` should not fire.
//
// FIXME(inherent_associated_types): In the current implementation that is. We might move the
// selection phase of IATs from hir_typeck to trait_selection resulting in us not requiring the
// ParamEnv that early allowing us to ignore bounds on type aliases again.
// Triage this before stabilization.
#![deny(type_alias_bounds)] #![deny(type_alias_bounds)]

View File

@ -1,55 +0,0 @@
error[E0391]: cycle detected when expanding type alias `Alias`
--> $DIR/type-alias-bounds-are-enforced.rs:19:1
|
LL | pub type Alias<T: Bound> = (Source<T>::Assoc,);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing the variances of `Source`...
--> $DIR/type-alias-bounds-are-enforced.rs:21:1
|
LL | pub struct Source<T>(T);
| ^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires expanding type alias `Alias`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/type-alias-bounds-are-enforced.rs:5:1
|
LL | / #![feature(inherent_associated_types)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | // Bounds on the self type play a major role in the resolution of inherent associated types (*).
... |
LL | | pub type Assoc = ();
LL | | }
| |_^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0391]: cycle detected when expanding type alias `Alias`
--> $DIR/type-alias-bounds-are-enforced.rs:19:1
|
LL | pub type Alias<T: Bound> = (Source<T>::Assoc,);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing the variances of `Source`...
--> $DIR/type-alias-bounds-are-enforced.rs:21:1
|
LL | pub struct Source<T>(T);
| ^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires expanding type alias `Alias`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/type-alias-bounds-are-enforced.rs:5:1
|
LL | / #![feature(inherent_associated_types)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | // Bounds on the self type play a major role in the resolution of inherent associated types (*).
... |
LL | | pub type Assoc = ();
LL | | }
| |_^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0391`.