Skip to content

Commit 8b59fe4

Browse files
committed
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.
1 parent e5ce6d1 commit 8b59fe4

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

clippy_lints/src/trait_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
128128
if !bound_predicate.span.from_expansion();
129129
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
130130
if let Some(PathSegment {
131-
res: Res::SelfTy{ trait_: Some(def_id), alias_to: _ }, ..
131+
res: Res::SelfTyParam { trait_: def_id }, ..
132132
}) = segments.first();
133133
if let Some(
134134
Node::Item(

clippy_lints/src/use_self.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
206206
ref types_to_skip,
207207
}) = self.stack.last();
208208
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
209-
if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _));
209+
if !matches!(
210+
path.res,
211+
Res::SelfTyParam { .. }
212+
| Res::SelfTyAlias { .. }
213+
| Res::Def(DefKind::TyParam, _)
214+
);
210215
if !types_to_skip.contains(&hir_ty.hir_id);
211216
let ty = if in_body > 0 {
212217
cx.typeck_results().node_type(hir_ty.hir_id)
@@ -230,7 +235,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
230235
}
231236
match expr.kind {
232237
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
233-
Res::SelfTy { .. } => (),
238+
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => (),
234239
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
235240
_ => span_lint(cx, path.span),
236241
},

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ pub fn is_self(slf: &Param<'_>) -> bool {
15351535

15361536
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
15371537
if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
1538-
if let Res::SelfTy { .. } = path.res {
1538+
if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path.res {
15391539
return true;
15401540
}
15411541
}

0 commit comments

Comments
 (0)