mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
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
e5ce6d18df
commit
8b59fe4981
3 changed files with 9 additions and 4 deletions
|
@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
|
|||
if !bound_predicate.span.from_expansion();
|
||||
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
|
||||
if let Some(PathSegment {
|
||||
res: Res::SelfTy{ trait_: Some(def_id), alias_to: _ }, ..
|
||||
res: Res::SelfTyParam { trait_: def_id }, ..
|
||||
}) = segments.first();
|
||||
if let Some(
|
||||
Node::Item(
|
||||
|
|
|
@ -206,7 +206,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
|||
ref types_to_skip,
|
||||
}) = self.stack.last();
|
||||
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);
|
||||
let ty = if in_body > 0 {
|
||||
cx.typeck_results().node_type(hir_ty.hir_id)
|
||||
|
@ -230,7 +235,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
|||
}
|
||||
match expr.kind {
|
||||
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
|
||||
Res::SelfTy { .. } => (),
|
||||
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => (),
|
||||
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
|
||||
_ => 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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue