Shrink hir::def::Res
.
`Res::SelfTy` currently has two `Option`s. When the second one is `Some` the first one is never consulted. So we can split it into two variants, `Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res` from 24 bytes to 12. This then shrinks `hir::Path` and `hir::PathSegment`, which are the HIR types that take up the most space.
This commit is contained in:
parent
5f29a13a5b
commit
f07d4efc45
28 changed files with 224 additions and 185 deletions
|
@ -314,45 +314,54 @@ pub enum Res<Id = hir::HirId> {
|
||||||
/// **Belongs to the type namespace.**
|
/// **Belongs to the type namespace.**
|
||||||
PrimTy(hir::PrimTy),
|
PrimTy(hir::PrimTy),
|
||||||
|
|
||||||
/// The `Self` type, optionally with the [`DefId`] of the trait it belongs to and
|
/// The `Self` type, as used within a trait.
|
||||||
/// optionally with the [`DefId`] of the item introducing the `Self` type alias.
|
///
|
||||||
|
/// **Belongs to the type namespace.**
|
||||||
|
///
|
||||||
|
/// See the examples on [`Res::SelfTyAlias`] for details.
|
||||||
|
SelfTyParam {
|
||||||
|
/// The trait this `Self` is a generic parameter for.
|
||||||
|
trait_: DefId,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// The `Self` type, as used somewhere other than within a trait.
|
||||||
///
|
///
|
||||||
/// **Belongs to the type namespace.**
|
/// **Belongs to the type namespace.**
|
||||||
///
|
///
|
||||||
/// Examples:
|
/// Examples:
|
||||||
/// ```
|
/// ```
|
||||||
/// struct Bar(Box<Self>);
|
/// struct Bar(Box<Self>); // SelfTyAlias
|
||||||
/// // `Res::SelfTy { trait_: None, alias_of: Some(Bar) }`
|
|
||||||
///
|
///
|
||||||
/// trait Foo {
|
/// trait Foo {
|
||||||
/// fn foo() -> Box<Self>;
|
/// fn foo() -> Box<Self>; // SelfTyParam
|
||||||
/// // `Res::SelfTy { trait_: Some(Foo), alias_of: None }`
|
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Bar {
|
/// impl Bar {
|
||||||
/// fn blah() {
|
/// fn blah() {
|
||||||
/// let _: Self;
|
/// let _: Self; // SelfTyAlias
|
||||||
/// // `Res::SelfTy { trait_: None, alias_of: Some(::{impl#0}) }`
|
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Foo for Bar {
|
/// impl Foo for Bar {
|
||||||
/// fn foo() -> Box<Self> {
|
/// fn foo() -> Box<Self> { // SelfTyAlias
|
||||||
/// // `Res::SelfTy { trait_: Some(Foo), alias_of: Some(::{impl#1}) }`
|
/// let _: Self; // SelfTyAlias
|
||||||
/// let _: Self;
|
|
||||||
/// // `Res::SelfTy { trait_: Some(Foo), alias_of: Some(::{impl#1}) }`
|
|
||||||
///
|
///
|
||||||
/// todo!()
|
/// todo!()
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// *See also [`Res::SelfCtor`].*
|
/// *See also [`Res::SelfCtor`].*
|
||||||
///
|
///
|
||||||
/// -----
|
SelfTyAlias {
|
||||||
|
/// The item introducing the `Self` type alias. Can be used in the `type_of` query
|
||||||
|
/// to get the underlying type.
|
||||||
|
alias_to: DefId,
|
||||||
|
|
||||||
|
/// Whether the `Self` type is disallowed from mentioning generics (i.e. when used in an
|
||||||
|
/// anonymous constant).
|
||||||
///
|
///
|
||||||
/// HACK(min_const_generics): self types also have an optional requirement to **not** mention
|
/// HACK(min_const_generics): self types also have an optional requirement to **not**
|
||||||
/// any generic parameters to allow the following with `min_const_generics`:
|
/// mention any generic parameters to allow the following with `min_const_generics`:
|
||||||
/// ```
|
/// ```
|
||||||
/// # struct Foo;
|
/// # struct Foo;
|
||||||
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
|
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
|
||||||
|
@ -361,27 +370,19 @@ pub enum Res<Id = hir::HirId> {
|
||||||
/// const fn baz<T>() -> usize { 10 }
|
/// const fn baz<T>() -> usize { 10 }
|
||||||
/// ```
|
/// ```
|
||||||
/// We do however allow `Self` in repeat expression even if it is generic to not break code
|
/// We do however allow `Self` in repeat expression even if it is generic to not break code
|
||||||
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat
|
/// which already works on stable while causing the `const_evaluatable_unchecked` future
|
||||||
/// lint:
|
/// compat lint:
|
||||||
/// ```
|
/// ```
|
||||||
/// fn foo<T>() {
|
/// fn foo<T>() {
|
||||||
/// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
|
/// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
|
// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
|
||||||
SelfTy {
|
forbid_generic: bool,
|
||||||
/// The trait this `Self` is a generic arg for.
|
|
||||||
trait_: Option<DefId>,
|
|
||||||
/// The item introducing the `Self` type alias. Can be used in the `type_of` query
|
|
||||||
/// to get the underlying type. Additionally whether the `Self` type is disallowed
|
|
||||||
/// from mentioning generics (i.e. when used in an anonymous constant).
|
|
||||||
alias_to: Option<(DefId, bool)>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
|
/// Is this within an `impl Foo for bar`?
|
||||||
///
|
is_trait_impl: bool,
|
||||||
/// **Belongs to the type namespace.**
|
},
|
||||||
ToolMod,
|
|
||||||
|
|
||||||
// Value namespace
|
// Value namespace
|
||||||
/// The `Self` constructor, along with the [`DefId`]
|
/// The `Self` constructor, along with the [`DefId`]
|
||||||
|
@ -389,7 +390,7 @@ pub enum Res<Id = hir::HirId> {
|
||||||
///
|
///
|
||||||
/// **Belongs to the value namespace.**
|
/// **Belongs to the value namespace.**
|
||||||
///
|
///
|
||||||
/// *See also [`Res::SelfTy`].*
|
/// *See also [`Res::SelfTyParam`] and [`Res::SelfTyAlias`].*
|
||||||
SelfCtor(DefId),
|
SelfCtor(DefId),
|
||||||
|
|
||||||
/// A local variable or function parameter.
|
/// A local variable or function parameter.
|
||||||
|
@ -397,6 +398,11 @@ pub enum Res<Id = hir::HirId> {
|
||||||
/// **Belongs to the value namespace.**
|
/// **Belongs to the value namespace.**
|
||||||
Local(Id),
|
Local(Id),
|
||||||
|
|
||||||
|
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
|
||||||
|
///
|
||||||
|
/// **Belongs to the type namespace.**
|
||||||
|
ToolMod,
|
||||||
|
|
||||||
// Macro namespace
|
// Macro namespace
|
||||||
/// An attribute that is *not* implemented via macro.
|
/// An attribute that is *not* implemented via macro.
|
||||||
/// E.g., `#[inline]` and `#[rustfmt::skip]`, which are essentially directives,
|
/// E.g., `#[inline]` and `#[rustfmt::skip]`, which are essentially directives,
|
||||||
|
@ -606,7 +612,8 @@ impl<Id> Res<Id> {
|
||||||
|
|
||||||
Res::Local(..)
|
Res::Local(..)
|
||||||
| Res::PrimTy(..)
|
| Res::PrimTy(..)
|
||||||
| Res::SelfTy { .. }
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
| Res::ToolMod
|
| Res::ToolMod
|
||||||
| Res::NonMacroAttr(..)
|
| Res::NonMacroAttr(..)
|
||||||
|
@ -629,7 +636,7 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(..) => "self constructor",
|
Res::SelfCtor(..) => "self constructor",
|
||||||
Res::PrimTy(..) => "builtin type",
|
Res::PrimTy(..) => "builtin type",
|
||||||
Res::Local(..) => "local variable",
|
Res::Local(..) => "local variable",
|
||||||
Res::SelfTy { .. } => "self type",
|
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => "self type",
|
||||||
Res::ToolMod => "tool module",
|
Res::ToolMod => "tool module",
|
||||||
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
||||||
Res::Err => "unresolved item",
|
Res::Err => "unresolved item",
|
||||||
|
@ -652,7 +659,10 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(id) => Res::SelfCtor(id),
|
Res::SelfCtor(id) => Res::SelfCtor(id),
|
||||||
Res::PrimTy(id) => Res::PrimTy(id),
|
Res::PrimTy(id) => Res::PrimTy(id),
|
||||||
Res::Local(id) => Res::Local(map(id)),
|
Res::Local(id) => Res::Local(map(id)),
|
||||||
Res::SelfTy { trait_, alias_to } => Res::SelfTy { trait_, alias_to },
|
Res::SelfTyParam { trait_ } => Res::SelfTyParam { trait_ },
|
||||||
|
Res::SelfTyAlias { alias_to, forbid_generic, is_trait_impl } => {
|
||||||
|
Res::SelfTyAlias { alias_to, forbid_generic, is_trait_impl }
|
||||||
|
}
|
||||||
Res::ToolMod => Res::ToolMod,
|
Res::ToolMod => Res::ToolMod,
|
||||||
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
||||||
Res::Err => Res::Err,
|
Res::Err => Res::Err,
|
||||||
|
@ -665,7 +675,10 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(id) => Res::SelfCtor(id),
|
Res::SelfCtor(id) => Res::SelfCtor(id),
|
||||||
Res::PrimTy(id) => Res::PrimTy(id),
|
Res::PrimTy(id) => Res::PrimTy(id),
|
||||||
Res::Local(id) => Res::Local(map(id)?),
|
Res::Local(id) => Res::Local(map(id)?),
|
||||||
Res::SelfTy { trait_, alias_to } => Res::SelfTy { trait_, alias_to },
|
Res::SelfTyParam { trait_ } => Res::SelfTyParam { trait_ },
|
||||||
|
Res::SelfTyAlias { alias_to, forbid_generic, is_trait_impl } => {
|
||||||
|
Res::SelfTyAlias { alias_to, forbid_generic, is_trait_impl }
|
||||||
|
}
|
||||||
Res::ToolMod => Res::ToolMod,
|
Res::ToolMod => Res::ToolMod,
|
||||||
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
||||||
Res::Err => Res::Err,
|
Res::Err => Res::Err,
|
||||||
|
@ -692,7 +705,9 @@ impl<Id> Res<Id> {
|
||||||
pub fn ns(&self) -> Option<Namespace> {
|
pub fn ns(&self) -> Option<Namespace> {
|
||||||
match self {
|
match self {
|
||||||
Res::Def(kind, ..) => kind.ns(),
|
Res::Def(kind, ..) => kind.ns(),
|
||||||
Res::PrimTy(..) | Res::SelfTy { .. } | Res::ToolMod => Some(Namespace::TypeNS),
|
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::ToolMod => {
|
||||||
|
Some(Namespace::TypeNS)
|
||||||
|
}
|
||||||
Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
|
Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
|
||||||
Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
|
Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
|
||||||
Res::Err => None,
|
Res::Err => None,
|
||||||
|
|
|
@ -2404,8 +2404,9 @@ impl<'hir> Ty<'hir> {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::Def(DefKind::TyParam, def_id)
|
Res::Def(DefKind::TyParam, def_id) | Res::SelfTyParam { trait_: def_id } => {
|
||||||
| Res::SelfTy { trait_: Some(def_id), alias_to: None } => Some((def_id, segment.ident)),
|
Some((def_id, segment.ident))
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3533,9 +3534,10 @@ mod size_asserts {
|
||||||
static_assert_size!(Param<'_>, 32);
|
static_assert_size!(Param<'_>, 32);
|
||||||
static_assert_size!(Pat<'_>, 72);
|
static_assert_size!(Pat<'_>, 72);
|
||||||
static_assert_size!(PatKind<'_>, 48);
|
static_assert_size!(PatKind<'_>, 48);
|
||||||
static_assert_size!(Path<'_>, 48);
|
static_assert_size!(Path<'_>, 40);
|
||||||
static_assert_size!(PathSegment<'_>, 56);
|
static_assert_size!(PathSegment<'_>, 48);
|
||||||
static_assert_size!(QPath<'_>, 24);
|
static_assert_size!(QPath<'_>, 24);
|
||||||
|
static_assert_size!(Res, 12);
|
||||||
static_assert_size!(Stmt<'_>, 32);
|
static_assert_size!(Stmt<'_>, 32);
|
||||||
static_assert_size!(StmtKind<'_>, 16);
|
static_assert_size!(StmtKind<'_>, 16);
|
||||||
static_assert_size!(TraitItem<'_>, 88);
|
static_assert_size!(TraitItem<'_>, 88);
|
||||||
|
|
|
@ -1902,7 +1902,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
// Find the type of the associated item, and the trait where the associated
|
// Find the type of the associated item, and the trait where the associated
|
||||||
// item is declared.
|
// item is declared.
|
||||||
let bound = match (&qself_ty.kind(), qself_res) {
|
let bound = match (&qself_ty.kind(), qself_res) {
|
||||||
(_, Res::SelfTy { trait_: Some(_), alias_to: Some((impl_def_id, _)) }) => {
|
(_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => {
|
||||||
// `Self` in an impl of a trait -- we have a concrete self type and a
|
// `Self` in an impl of a trait -- we have a concrete self type and a
|
||||||
// trait reference.
|
// trait reference.
|
||||||
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
|
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
|
||||||
|
@ -1921,8 +1921,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
&ty::Param(_),
|
&ty::Param(_),
|
||||||
Res::SelfTy { trait_: Some(param_did), alias_to: None }
|
Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did),
|
||||||
| Res::Def(DefKind::TyParam, param_did),
|
|
||||||
) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?,
|
) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?,
|
||||||
_ => {
|
_ => {
|
||||||
let reported = if variant_resolution.is_some() {
|
let reported = if variant_resolution.is_some() {
|
||||||
|
@ -2417,7 +2416,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||||
tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id))
|
tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id))
|
||||||
}
|
}
|
||||||
Res::SelfTy { trait_: Some(_), alias_to: None } => {
|
Res::SelfTyParam { .. } => {
|
||||||
// `Self` in trait or type alias.
|
// `Self` in trait or type alias.
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments.iter(), |err| {
|
self.prohibit_generics(path.segments.iter(), |err| {
|
||||||
|
@ -2432,7 +2431,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
});
|
});
|
||||||
tcx.types.self_param
|
tcx.types.self_param
|
||||||
}
|
}
|
||||||
Res::SelfTy { trait_: _, alias_to: Some((def_id, forbid_generic)) } => {
|
Res::SelfTyAlias { alias_to: def_id, forbid_generic, .. } => {
|
||||||
// `Self` in impl (we know the concrete type).
|
// `Self` in impl (we know the concrete type).
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
// Try to evaluate any array length constants.
|
// Try to evaluate any array length constants.
|
||||||
|
|
|
@ -609,9 +609,12 @@ pub(super) fn check_opaque_for_inheriting_lifetimes<'tcx>(
|
||||||
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
|
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
|
||||||
match arg.kind {
|
match arg.kind {
|
||||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => match &path.segments {
|
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => match &path.segments {
|
||||||
[PathSegment { res: Res::SelfTy { trait_: _, alias_to: impl_ref }, .. }] => {
|
[PathSegment { res: Res::SelfTyParam { .. }, .. }] => {
|
||||||
let impl_ty_name =
|
let impl_ty_name = None;
|
||||||
impl_ref.map(|(def_id, _)| self.tcx.def_path_str(def_id));
|
self.selftys.push((path.span, impl_ty_name));
|
||||||
|
}
|
||||||
|
[PathSegment { res: Res::SelfTyAlias { alias_to: def_id, .. }, .. }] => {
|
||||||
|
let impl_ty_name = Some(self.tcx.def_path_str(*def_id));
|
||||||
self.selftys.push((path.span, impl_ty_name));
|
self.selftys.push((path.span, impl_ty_name));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -1199,7 +1199,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
_ => bug!("unexpected type: {:?}", ty),
|
_ => bug!("unexpected type: {:?}", ty),
|
||||||
},
|
},
|
||||||
Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
||||||
| Res::SelfTy { .. } => match ty.kind() {
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. } => match ty.kind() {
|
||||||
ty::Adt(adt, substs) if !adt.is_enum() => {
|
ty::Adt(adt, substs) if !adt.is_enum() => {
|
||||||
Some((adt.non_enum_variant(), adt.did(), substs))
|
Some((adt.non_enum_variant(), adt.did(), substs))
|
||||||
}
|
}
|
||||||
|
|
|
@ -560,7 +560,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
||||||
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _)
|
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _)
|
||||||
| Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
| Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
| Res::SelfTy { .. } => {
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. } => {
|
||||||
// Structs and Unions have only have one variant.
|
// Structs and Unions have only have one variant.
|
||||||
Ok(VariantIdx::new(0))
|
Ok(VariantIdx::new(0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1021,7 +1021,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
// There cannot be inference variables in the self type,
|
// There cannot be inference variables in the self type,
|
||||||
// so there's nothing for us to do here.
|
// so there's nothing for us to do here.
|
||||||
Res::SelfTy { .. } => {}
|
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {}
|
||||||
_ => warn!(
|
_ => warn!(
|
||||||
"unexpected path: def={:?} substs={:?} path={:?}",
|
"unexpected path: def={:?} substs={:?} path={:?}",
|
||||||
def, substs, path,
|
def, substs, path,
|
||||||
|
|
|
@ -156,7 +156,8 @@ impl<'tcx> Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
|
||||||
[segment]
|
[segment]
|
||||||
if matches!(
|
if matches!(
|
||||||
segment.res,
|
segment.res,
|
||||||
Res::SelfTy { trait_: _, alias_to: _ }
|
Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
| Res::Def(hir::def::DefKind::TyParam, _)
|
| Res::Def(hir::def::DefKind::TyParam, _)
|
||||||
) =>
|
) =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -244,7 +244,7 @@ fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, path: &Path<'_>) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
|
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
|
||||||
Res::SelfTy { trait_: None, alias_to: Some((did, _)) } => {
|
Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => {
|
||||||
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
||||||
if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(adt.did())
|
if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(adt.did())
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
|
||||||
let path_segment = path.segments.last().unwrap();
|
let path_segment = path.segments.last().unwrap();
|
||||||
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
|
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
|
||||||
}
|
}
|
||||||
Res::SelfTy { trait_: None, alias_to: Some((did, _)) } => {
|
Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => {
|
||||||
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
||||||
if cx.tcx.has_attr(adt.did(), sym::rustc_pass_by_value) {
|
if cx.tcx.has_attr(adt.did(), sym::rustc_pass_by_value) {
|
||||||
return Some(cx.tcx.def_path_str_with_substs(adt.did(), substs));
|
return Some(cx.tcx.def_path_str_with_substs(adt.did(), substs));
|
||||||
|
|
|
@ -438,7 +438,8 @@ impl<'tcx> AdtDef<'tcx> {
|
||||||
| 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::SelfTy { .. }
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
| Res::SelfCtor(..) => self.non_enum_variant(),
|
| Res::SelfCtor(..) => self.non_enum_variant(),
|
||||||
_ => bug!("unexpected res {:?} in variant_of_res", res),
|
_ => bug!("unexpected res {:?} in variant_of_res", res),
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,7 +433,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
| DefKind::AssocTy,
|
| DefKind::AssocTy,
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::SelfTy { .. }
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
| Res::SelfCtor(..) => PatKind::Leaf { subpatterns },
|
| Res::SelfCtor(..) => PatKind::Leaf { subpatterns },
|
||||||
_ => {
|
_ => {
|
||||||
let pattern_error = match res {
|
let pattern_error = match res {
|
||||||
|
|
|
@ -102,14 +102,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Res::Def(_, def_id) => self.check_def_id(def_id),
|
Res::Def(_, def_id) => self.check_def_id(def_id),
|
||||||
Res::SelfTy { trait_: t, alias_to: i } => {
|
Res::SelfTyParam { trait_: t } => self.check_def_id(t),
|
||||||
if let Some(t) = t {
|
Res::SelfTyAlias { alias_to: i, .. } => self.check_def_id(i),
|
||||||
self.check_def_id(t);
|
|
||||||
}
|
|
||||||
if let Some((i, _)) = i {
|
|
||||||
self.check_def_id(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Res::ToolMod | Res::NonMacroAttr(..) | Res::Err => {}
|
Res::ToolMod | Res::NonMacroAttr(..) | Res::Err => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1422,7 +1422,9 @@ struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
|
||||||
impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||||
fn path_is_private_type(&self, path: &hir::Path<'_>) -> bool {
|
fn path_is_private_type(&self, path: &hir::Path<'_>) -> bool {
|
||||||
let did = match path.res {
|
let did = match path.res {
|
||||||
Res::PrimTy(..) | Res::SelfTy { .. } | Res::Err => return false,
|
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Err => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
res => res.def_id(),
|
res => res.def_id(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1010,7 +1010,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::Local(..)
|
| Res::Local(..)
|
||||||
| Res::SelfTy { .. }
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
| Res::Err => bug!("unexpected resolution: {:?}", res),
|
| Res::Err => bug!("unexpected resolution: {:?}", res),
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,24 +511,18 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
let sm = self.session.source_map();
|
let sm = self.session.source_map();
|
||||||
let def_id = match outer_res {
|
let def_id = match outer_res {
|
||||||
Res::SelfTy { trait_: maybe_trait_defid, alias_to: maybe_impl_defid } => {
|
Res::SelfTyParam { .. } => {
|
||||||
if let Some(impl_span) =
|
err.span_label(span, "can't use `Self` here");
|
||||||
maybe_impl_defid.and_then(|(def_id, _)| self.opt_span(def_id))
|
return err;
|
||||||
{
|
}
|
||||||
|
Res::SelfTyAlias { alias_to: def_id, .. } => {
|
||||||
|
if let Some(impl_span) = self.opt_span(def_id) {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
reduce_impl_span_to_impl_keyword(sm, impl_span),
|
reduce_impl_span_to_impl_keyword(sm, impl_span),
|
||||||
"`Self` type implicitly declared here, by this `impl`",
|
"`Self` type implicitly declared here, by this `impl`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
match (maybe_trait_defid, maybe_impl_defid) {
|
|
||||||
(Some(_), None) => {
|
|
||||||
err.span_label(span, "can't use `Self` here");
|
|
||||||
}
|
|
||||||
(_, Some(_)) => {
|
|
||||||
err.span_label(span, "use a type here instead");
|
err.span_label(span, "use a type here instead");
|
||||||
}
|
|
||||||
(None, None) => bug!("`impl` without trait nor type?"),
|
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, def_id) => {
|
Res::Def(DefKind::TyParam, def_id) => {
|
||||||
|
@ -545,8 +539,9 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
bug!(
|
bug!(
|
||||||
"GenericParamsFromOuterFunction should only be used with Res::SelfTy, \
|
"GenericParamsFromOuterFunction should only be used with \
|
||||||
DefKind::TyParam or DefKind::ConstParam"
|
Res::SelfTyParam, Res::SelfTyAlias, DefKind::TyParam or \
|
||||||
|
DefKind::ConstParam"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1162,7 +1162,7 @@ impl<'a> Resolver<'a> {
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) | Res::SelfTy { .. } => {
|
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
|
||||||
for rib in ribs {
|
for rib in ribs {
|
||||||
let has_generic_params: HasGenericParams = match rib.kind {
|
let has_generic_params: HasGenericParams = match rib.kind {
|
||||||
NormalRibKind
|
NormalRibKind
|
||||||
|
@ -1182,11 +1182,21 @@ impl<'a> Resolver<'a> {
|
||||||
if !(trivial == ConstantHasGenerics::Yes
|
if !(trivial == ConstantHasGenerics::Yes
|
||||||
|| features.generic_const_exprs)
|
|| features.generic_const_exprs)
|
||||||
{
|
{
|
||||||
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
|
// HACK(min_const_generics): If we encounter `Self` in an anonymous
|
||||||
// we can't easily tell if it's generic at this stage, so we instead remember
|
// constant we can't easily tell if it's generic at this stage, so
|
||||||
// this and then enforce the self type to be concrete later on.
|
// we instead remember this and then enforce the self type to be
|
||||||
if let Res::SelfTy { trait_, alias_to: Some((def, _)) } = res {
|
// concrete later on.
|
||||||
res = Res::SelfTy { trait_, alias_to: Some((def, true)) }
|
if let Res::SelfTyAlias {
|
||||||
|
alias_to: def,
|
||||||
|
forbid_generic: _,
|
||||||
|
is_trait_impl,
|
||||||
|
} = res
|
||||||
|
{
|
||||||
|
res = Res::SelfTyAlias {
|
||||||
|
alias_to: def,
|
||||||
|
forbid_generic: true,
|
||||||
|
is_trait_impl,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
|
|
|
@ -414,7 +414,8 @@ impl<'a> PathSource<'a> {
|
||||||
| DefKind::ForeignTy,
|
| DefKind::ForeignTy,
|
||||||
_,
|
_,
|
||||||
) | Res::PrimTy(..)
|
) | Res::PrimTy(..)
|
||||||
| Res::SelfTy { .. }
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
),
|
),
|
||||||
PathSource::Trait(AliasPossibility::No) => matches!(res, Res::Def(DefKind::Trait, _)),
|
PathSource::Trait(AliasPossibility::No) => matches!(res, Res::Def(DefKind::Trait, _)),
|
||||||
PathSource::Trait(AliasPossibility::Maybe) => {
|
PathSource::Trait(AliasPossibility::Maybe) => {
|
||||||
|
@ -448,7 +449,8 @@ impl<'a> PathSource<'a> {
|
||||||
| DefKind::TyAlias
|
| DefKind::TyAlias
|
||||||
| DefKind::AssocTy,
|
| DefKind::AssocTy,
|
||||||
_,
|
_,
|
||||||
) | Res::SelfTy { .. }
|
) | Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
),
|
),
|
||||||
PathSource::TraitItem(ns) => match res {
|
PathSource::TraitItem(ns) => match res {
|
||||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
|
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
|
||||||
|
@ -1929,7 +1931,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
TyKind::ImplicitSelf => true,
|
TyKind::ImplicitSelf => true,
|
||||||
TyKind::Path(None, _) => {
|
TyKind::Path(None, _) => {
|
||||||
let path_res = self.r.partial_res_map[&ty.id].base_res();
|
let path_res = self.r.partial_res_map[&ty.id].base_res();
|
||||||
if let Res::SelfTy { .. } = path_res {
|
if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path_res {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Some(path_res) == self.impl_self
|
Some(path_res) == self.impl_self
|
||||||
|
@ -2050,7 +2052,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
|this| {
|
|this| {
|
||||||
let item_def_id = this.r.local_def_id(item.id).to_def_id();
|
let item_def_id = this.r.local_def_id(item.id).to_def_id();
|
||||||
this.with_self_rib(
|
this.with_self_rib(
|
||||||
Res::SelfTy { trait_: None, alias_to: Some((item_def_id, false)) },
|
Res::SelfTyAlias {
|
||||||
|
alias_to: item_def_id,
|
||||||
|
forbid_generic: false,
|
||||||
|
is_trait_impl: false,
|
||||||
|
},
|
||||||
|this| {
|
|this| {
|
||||||
visit::walk_item(this, item);
|
visit::walk_item(this, item);
|
||||||
},
|
},
|
||||||
|
@ -2164,14 +2170,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
},
|
},
|
||||||
|this| {
|
|this| {
|
||||||
let local_def_id = this.r.local_def_id(item.id).to_def_id();
|
let local_def_id = this.r.local_def_id(item.id).to_def_id();
|
||||||
this.with_self_rib(
|
this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
|
||||||
Res::SelfTy { trait_: Some(local_def_id), alias_to: None },
|
|
||||||
|this| {
|
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits);
|
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits);
|
||||||
this.resolve_trait_items(items);
|
this.resolve_trait_items(items);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2188,13 +2191,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
},
|
},
|
||||||
|this| {
|
|this| {
|
||||||
let local_def_id = this.r.local_def_id(item.id).to_def_id();
|
let local_def_id = this.r.local_def_id(item.id).to_def_id();
|
||||||
this.with_self_rib(
|
this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
|
||||||
Res::SelfTy { trait_: Some(local_def_id), alias_to: None },
|
|
||||||
|this| {
|
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
walk_list!(this, visit_param_bound, bounds, BoundKind::Bound);
|
walk_list!(this, visit_param_bound, bounds, BoundKind::Bound);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2576,7 +2576,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
},
|
},
|
||||||
|this| {
|
|this| {
|
||||||
// Dummy self type for better errors if `Self` is used in the trait path.
|
// Dummy self type for better errors if `Self` is used in the trait path.
|
||||||
this.with_self_rib(Res::SelfTy { trait_: Some(LOCAL_CRATE.as_def_id()), alias_to: None }, |this| {
|
this.with_self_rib(Res::SelfTyParam { trait_: LOCAL_CRATE.as_def_id() }, |this| {
|
||||||
this.with_lifetime_rib(
|
this.with_lifetime_rib(
|
||||||
LifetimeRibKind::AnonymousCreateParameter {
|
LifetimeRibKind::AnonymousCreateParameter {
|
||||||
binder: item_id,
|
binder: item_id,
|
||||||
|
@ -2600,9 +2600,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let item_def_id = item_def_id.to_def_id();
|
let item_def_id = item_def_id.to_def_id();
|
||||||
let res = Res::SelfTy {
|
let res = Res::SelfTyAlias {
|
||||||
trait_: trait_id,
|
alias_to: item_def_id,
|
||||||
alias_to: Some((item_def_id, false)),
|
forbid_generic: false,
|
||||||
|
is_trait_impl: trait_id.is_some()
|
||||||
};
|
};
|
||||||
this.with_self_rib(res, |this| {
|
this.with_self_rib(res, |this| {
|
||||||
if let Some(trait_ref) = opt_trait_reference.as_ref() {
|
if let Some(trait_ref) = opt_trait_reference.as_ref() {
|
||||||
|
|
|
@ -1330,7 +1330,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
Applicability::HasPlaceholders,
|
Applicability::HasPlaceholders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(Res::SelfTy { .. }, _) if ns == ValueNS => {
|
(Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }, _) if ns == ValueNS => {
|
||||||
err.span_label(span, fallback_label);
|
err.span_label(span, fallback_label);
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -913,7 +913,8 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
| HirDefKind::AssocTy,
|
| HirDefKind::AssocTy,
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::SelfTy { .. } => {
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. } => {
|
||||||
self.dump_path_segment_ref(
|
self.dump_path_segment_ref(
|
||||||
id,
|
id,
|
||||||
&hir::PathSegment::new(ident, hir::HirId::INVALID, Res::Err),
|
&hir::PathSegment::new(ident, hir::HirId::INVALID, Res::Err),
|
||||||
|
|
|
@ -740,7 +740,8 @@ impl<'tcx> SaveContext<'tcx> {
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::PrimTy(..)
|
| Res::PrimTy(..)
|
||||||
| Res::SelfTy { .. }
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
| Res::ToolMod
|
| Res::ToolMod
|
||||||
| Res::NonMacroAttr(..)
|
| Res::NonMacroAttr(..)
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
|
@ -805,7 +806,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||||
|
|
||||||
fn lookup_def_id(&self, ref_id: hir::HirId) -> Option<DefId> {
|
fn lookup_def_id(&self, ref_id: hir::HirId) -> Option<DefId> {
|
||||||
match self.get_path_res(ref_id) {
|
match self.get_path_res(ref_id) {
|
||||||
Res::PrimTy(_) | Res::SelfTy { .. } | Res::Err => None,
|
Res::PrimTy(_) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Err => None,
|
||||||
def => def.opt_def_id(),
|
def => def.opt_def_id(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -579,7 +579,7 @@ impl<'hir> Sig for hir::Path<'hir> {
|
||||||
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
||||||
|
|
||||||
let (name, start, end) = match res {
|
let (name, start, end) = match res {
|
||||||
Res::PrimTy(..) | Res::SelfTy { .. } | Res::Err => {
|
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Err => {
|
||||||
return Ok(Signature { text: path_to_string(self), defs: vec![], refs: vec![] });
|
return Ok(Signature { text: path_to_string(self), defs: vec![], refs: vec![] });
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::AssocConst | DefKind::Variant | DefKind::Ctor(..), _) => {
|
Res::Def(DefKind::AssocConst | DefKind::Variant | DefKind::Ctor(..), _) => {
|
||||||
|
|
|
@ -2201,8 +2201,11 @@ impl Path {
|
||||||
/// Checks if this is a `T::Name` path for an associated type.
|
/// Checks if this is a `T::Name` path for an associated type.
|
||||||
pub(crate) fn is_assoc_ty(&self) -> bool {
|
pub(crate) fn is_assoc_ty(&self) -> bool {
|
||||||
match self.res {
|
match self.res {
|
||||||
Res::SelfTy { .. } if self.segments.len() != 1 => true,
|
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Def(DefKind::TyParam, _)
|
||||||
Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true,
|
if self.segments.len() != 1 =>
|
||||||
|
{
|
||||||
|
true
|
||||||
|
}
|
||||||
Res::Def(DefKind::AssocTy, _) => true,
|
Res::Def(DefKind::AssocTy, _) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -2535,11 +2538,11 @@ mod size_asserts {
|
||||||
// These are in alphabetical order, which is easy to maintain.
|
// These are in alphabetical order, which is easy to maintain.
|
||||||
static_assert_size!(Crate, 72); // frequently moved by-value
|
static_assert_size!(Crate, 72); // frequently moved by-value
|
||||||
static_assert_size!(DocFragment, 32);
|
static_assert_size!(DocFragment, 32);
|
||||||
static_assert_size!(GenericArg, 56);
|
static_assert_size!(GenericArg, 48);
|
||||||
static_assert_size!(GenericArgs, 32);
|
static_assert_size!(GenericArgs, 32);
|
||||||
static_assert_size!(GenericParamDef, 56);
|
static_assert_size!(GenericParamDef, 56);
|
||||||
static_assert_size!(Item, 56);
|
static_assert_size!(Item, 56);
|
||||||
static_assert_size!(ItemKind, 96);
|
static_assert_size!(ItemKind, 88);
|
||||||
static_assert_size!(PathSegment, 40);
|
static_assert_size!(PathSegment, 40);
|
||||||
static_assert_size!(Type, 56);
|
static_assert_size!(Type, 48);
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,7 +454,9 @@ pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
|
||||||
|
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
|
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
|
||||||
Res::SelfTy { .. } if path.segments.len() == 1 => Generic(kw::SelfUpper),
|
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } if path.segments.len() == 1 => {
|
||||||
|
Generic(kw::SelfUpper)
|
||||||
|
}
|
||||||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
||||||
_ => {
|
_ => {
|
||||||
let _ = register_res(cx, path.res);
|
let _ = register_res(cx, path.res);
|
||||||
|
|
|
@ -118,61 +118,61 @@ ast-stats-2
|
||||||
hir-stats HIR STATS
|
hir-stats HIR STATS
|
||||||
hir-stats Name Accumulated Size Count Item Size
|
hir-stats Name Accumulated Size Count Item Size
|
||||||
hir-stats ----------------------------------------------------------------
|
hir-stats ----------------------------------------------------------------
|
||||||
hir-stats ForeignItemRef 24 ( 0.2%) 1 24
|
hir-stats ForeignItemRef 24 ( 0.3%) 1 24
|
||||||
hir-stats Lifetime 32 ( 0.3%) 1 32
|
hir-stats Lifetime 32 ( 0.4%) 1 32
|
||||||
hir-stats Mod 32 ( 0.3%) 1 32
|
hir-stats Mod 32 ( 0.4%) 1 32
|
||||||
hir-stats ExprField 40 ( 0.4%) 1 40
|
hir-stats ExprField 40 ( 0.4%) 1 40
|
||||||
hir-stats TraitItemRef 56 ( 0.6%) 2 28
|
hir-stats TraitItemRef 56 ( 0.6%) 2 28
|
||||||
hir-stats Local 64 ( 0.7%) 1 64
|
hir-stats Local 64 ( 0.7%) 1 64
|
||||||
hir-stats Param 64 ( 0.7%) 2 32
|
hir-stats Param 64 ( 0.7%) 2 32
|
||||||
hir-stats InlineAsm 72 ( 0.7%) 1 72
|
hir-stats InlineAsm 72 ( 0.8%) 1 72
|
||||||
hir-stats ImplItemRef 72 ( 0.7%) 2 36
|
hir-stats ImplItemRef 72 ( 0.8%) 2 36
|
||||||
hir-stats Body 96 ( 1.0%) 3 32
|
hir-stats Body 96 ( 1.1%) 3 32
|
||||||
hir-stats GenericArg 96 ( 1.0%) 4 24
|
hir-stats GenericArg 96 ( 1.1%) 4 24
|
||||||
hir-stats - Type 24 ( 0.2%) 1
|
hir-stats - Type 24 ( 0.3%) 1
|
||||||
hir-stats - Lifetime 72 ( 0.7%) 3
|
hir-stats - Lifetime 72 ( 0.8%) 3
|
||||||
hir-stats FieldDef 96 ( 1.0%) 2 48
|
hir-stats FieldDef 96 ( 1.1%) 2 48
|
||||||
hir-stats Arm 96 ( 1.0%) 2 48
|
hir-stats Arm 96 ( 1.1%) 2 48
|
||||||
hir-stats Stmt 96 ( 1.0%) 3 32
|
hir-stats Stmt 96 ( 1.1%) 3 32
|
||||||
hir-stats - Local 32 ( 0.3%) 1
|
hir-stats - Local 32 ( 0.4%) 1
|
||||||
hir-stats - Semi 32 ( 0.3%) 1
|
hir-stats - Semi 32 ( 0.4%) 1
|
||||||
hir-stats - Expr 32 ( 0.3%) 1
|
hir-stats - Expr 32 ( 0.4%) 1
|
||||||
hir-stats FnDecl 120 ( 1.2%) 3 40
|
hir-stats FnDecl 120 ( 1.3%) 3 40
|
||||||
hir-stats Attribute 128 ( 1.3%) 4 32
|
hir-stats Attribute 128 ( 1.4%) 4 32
|
||||||
hir-stats GenericArgs 144 ( 1.5%) 3 48
|
hir-stats GenericArgs 144 ( 1.6%) 3 48
|
||||||
hir-stats Variant 160 ( 1.6%) 2 80
|
hir-stats Variant 160 ( 1.8%) 2 80
|
||||||
hir-stats GenericBound 192 ( 2.0%) 4 48
|
hir-stats GenericBound 192 ( 2.1%) 4 48
|
||||||
hir-stats - Trait 192 ( 2.0%) 4
|
hir-stats - Trait 192 ( 2.1%) 4
|
||||||
hir-stats WherePredicate 192 ( 2.0%) 3 64
|
hir-stats WherePredicate 192 ( 2.1%) 3 64
|
||||||
hir-stats - BoundPredicate 192 ( 2.0%) 3
|
hir-stats - BoundPredicate 192 ( 2.1%) 3
|
||||||
hir-stats Block 288 ( 3.0%) 6 48
|
hir-stats Block 288 ( 3.2%) 6 48
|
||||||
hir-stats Pat 360 ( 3.7%) 5 72
|
hir-stats Pat 360 ( 3.9%) 5 72
|
||||||
hir-stats - Wild 72 ( 0.7%) 1
|
hir-stats - Wild 72 ( 0.8%) 1
|
||||||
hir-stats - Struct 72 ( 0.7%) 1
|
hir-stats - Struct 72 ( 0.8%) 1
|
||||||
hir-stats - Binding 216 ( 2.2%) 3
|
hir-stats - Binding 216 ( 2.4%) 3
|
||||||
hir-stats GenericParam 400 ( 4.1%) 5 80
|
hir-stats GenericParam 400 ( 4.4%) 5 80
|
||||||
hir-stats Generics 560 ( 5.8%) 10 56
|
hir-stats Generics 560 ( 6.1%) 10 56
|
||||||
hir-stats Ty 720 ( 7.4%) 15 48
|
hir-stats Ty 720 ( 7.9%) 15 48
|
||||||
hir-stats - Ptr 48 ( 0.5%) 1
|
hir-stats - Ptr 48 ( 0.5%) 1
|
||||||
hir-stats - Rptr 48 ( 0.5%) 1
|
hir-stats - Rptr 48 ( 0.5%) 1
|
||||||
hir-stats - Path 624 ( 6.4%) 13
|
hir-stats - Path 624 ( 6.8%) 13
|
||||||
hir-stats Expr 768 ( 7.9%) 12 64
|
hir-stats Expr 768 ( 8.4%) 12 64
|
||||||
hir-stats - Path 64 ( 0.7%) 1
|
hir-stats - Path 64 ( 0.7%) 1
|
||||||
hir-stats - Struct 64 ( 0.7%) 1
|
hir-stats - Struct 64 ( 0.7%) 1
|
||||||
hir-stats - Match 64 ( 0.7%) 1
|
hir-stats - Match 64 ( 0.7%) 1
|
||||||
hir-stats - InlineAsm 64 ( 0.7%) 1
|
hir-stats - InlineAsm 64 ( 0.7%) 1
|
||||||
hir-stats - Lit 128 ( 1.3%) 2
|
hir-stats - Lit 128 ( 1.4%) 2
|
||||||
hir-stats - Block 384 ( 4.0%) 6
|
hir-stats - Block 384 ( 4.2%) 6
|
||||||
hir-stats Item 960 ( 9.9%) 12 80
|
hir-stats Item 960 (10.5%) 12 80
|
||||||
hir-stats - Trait 80 ( 0.8%) 1
|
hir-stats - Trait 80 ( 0.9%) 1
|
||||||
hir-stats - Enum 80 ( 0.8%) 1
|
hir-stats - Enum 80 ( 0.9%) 1
|
||||||
hir-stats - ExternCrate 80 ( 0.8%) 1
|
hir-stats - ExternCrate 80 ( 0.9%) 1
|
||||||
hir-stats - ForeignMod 80 ( 0.8%) 1
|
hir-stats - ForeignMod 80 ( 0.9%) 1
|
||||||
hir-stats - Impl 80 ( 0.8%) 1
|
hir-stats - Impl 80 ( 0.9%) 1
|
||||||
hir-stats - Fn 160 ( 1.6%) 2
|
hir-stats - Fn 160 ( 1.8%) 2
|
||||||
hir-stats - Use 400 ( 4.1%) 5
|
hir-stats - Use 400 ( 4.4%) 5
|
||||||
hir-stats Path 1_536 (15.8%) 32 48
|
hir-stats Path 1_280 (14.0%) 32 40
|
||||||
hir-stats PathSegment 2_240 (23.1%) 40 56
|
hir-stats PathSegment 1_920 (21.0%) 40 48
|
||||||
hir-stats ----------------------------------------------------------------
|
hir-stats ----------------------------------------------------------------
|
||||||
hir-stats Total 9_704
|
hir-stats Total 9_128
|
||||||
hir-stats
|
hir-stats
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
|
||||||
if !bound_predicate.span.from_expansion();
|
if !bound_predicate.span.from_expansion();
|
||||||
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
|
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
|
||||||
if let Some(PathSegment {
|
if let Some(PathSegment {
|
||||||
res: Res::SelfTy{ trait_: Some(def_id), alias_to: _ }, ..
|
res: Res::SelfTyParam { trait_: def_id }, ..
|
||||||
}) = segments.first();
|
}) = segments.first();
|
||||||
if let Some(
|
if let Some(
|
||||||
Node::Item(
|
Node::Item(
|
||||||
|
|
|
@ -206,7 +206,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
ref types_to_skip,
|
ref types_to_skip,
|
||||||
}) = self.stack.last();
|
}) = self.stack.last();
|
||||||
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
|
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
|
||||||
if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _));
|
if !matches!(
|
||||||
|
path.res,
|
||||||
|
Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
|
| Res::Def(DefKind::TyParam, _)
|
||||||
|
);
|
||||||
if !types_to_skip.contains(&hir_ty.hir_id);
|
if !types_to_skip.contains(&hir_ty.hir_id);
|
||||||
let ty = if in_body > 0 {
|
let ty = if in_body > 0 {
|
||||||
cx.typeck_results().node_type(hir_ty.hir_id)
|
cx.typeck_results().node_type(hir_ty.hir_id)
|
||||||
|
@ -230,7 +235,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
}
|
}
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
|
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
|
||||||
Res::SelfTy { .. } => (),
|
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => (),
|
||||||
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
|
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
|
||||||
_ => span_lint(cx, path.span),
|
_ => span_lint(cx, path.span),
|
||||||
},
|
},
|
||||||
|
|
|
@ -1535,7 +1535,7 @@ pub fn is_self(slf: &Param<'_>) -> bool {
|
||||||
|
|
||||||
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
|
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
|
||||||
if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
|
if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
|
||||||
if let Res::SelfTy { .. } = path.res {
|
if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path.res {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue