diff options
| author | bors <bors@rust-lang.org> | 2022-09-08 13:11:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-08 13:11:57 +0000 |
| commit | 24d69920201563f0ee7b530f1cda0f171b205cc2 (patch) | |
| tree | 2071fdf41cd4126e7e1c4ed82e5c37f7fd0f17cd /src | |
| parent | ccb5595df2ed412eda6444edc7eaf06f709fa79d (diff) | |
| parent | e67f39f8bcb12dc4c985abe922d78c0daad7e5cd (diff) | |
Auto merge of #101467 - nnethercote:shrink-hir-Ty-Pat, r=spastorino
Shrink `hir::Ty` and `hir::Pat` r? `@ghost`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/stats/hir-stats.stderr | 77 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/equatable_if_let.rs | 4 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs | 4 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/matches/single_match.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/question_mark.rs | 3 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs | 6 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_utils/src/hir_utils.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_utils/src/lib.rs | 3 |
9 files changed, 58 insertions, 49 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c2baea839f6..66f766bfbe8 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -190,7 +190,7 @@ fn clean_poly_trait_ref_with_bindings<'tcx>( ) } -fn clean_lifetime<'tcx>(lifetime: hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime { +fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime { let def = cx.tcx.named_region(lifetime.hir_id); if let Some( rl::Region::EarlyBound(node_id) @@ -495,7 +495,7 @@ fn clean_generic_param<'tcx>( .filter(|bp| !bp.in_where_clause) .flat_map(|bp| bp.bounds) .map(|bound| match bound { - hir::GenericBound::Outlives(lt) => clean_lifetime(*lt, cx), + hir::GenericBound::Outlives(lt) => clean_lifetime(lt, cx), _ => panic!(), }) .collect() @@ -1392,7 +1392,7 @@ fn maybe_expand_private_type_alias<'tcx>( } _ => None, }); - if let Some(lt) = lifetime.cloned() { + if let Some(lt) = lifetime { let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id); let cleaned = if !lt.is_elided() { clean_lifetime(lt, cx) } else { Lifetime::elided() }; diff --git a/src/test/ui/stats/hir-stats.stderr b/src/test/ui/stats/hir-stats.stderr index c8ceb6ff22d..8d977606530 100644 --- a/src/test/ui/stats/hir-stats.stderr +++ b/src/test/ui/stats/hir-stats.stderr @@ -119,59 +119,60 @@ hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size hir-stats ---------------------------------------------------------------- hir-stats ForeignItemRef 24 ( 0.2%) 1 24 +hir-stats Lifetime 32 ( 0.3%) 1 32 hir-stats Mod 32 ( 0.3%) 1 32 hir-stats ExprField 40 ( 0.4%) 1 40 hir-stats TraitItemRef 56 ( 0.6%) 2 28 -hir-stats Param 64 ( 0.6%) 2 32 -hir-stats Local 64 ( 0.6%) 1 64 +hir-stats Local 64 ( 0.7%) 1 64 +hir-stats Param 64 ( 0.7%) 2 32 hir-stats InlineAsm 72 ( 0.7%) 1 72 hir-stats ImplItemRef 72 ( 0.7%) 2 36 -hir-stats FieldDef 96 ( 0.9%) 2 48 -hir-stats Arm 96 ( 0.9%) 2 48 -hir-stats Body 96 ( 0.9%) 3 32 -hir-stats Stmt 96 ( 0.9%) 3 32 +hir-stats Body 96 ( 1.0%) 3 32 +hir-stats GenericArg 96 ( 1.0%) 4 24 +hir-stats - Type 24 ( 0.2%) 1 +hir-stats - Lifetime 72 ( 0.7%) 3 +hir-stats FieldDef 96 ( 1.0%) 2 48 +hir-stats Arm 96 ( 1.0%) 2 48 +hir-stats Stmt 96 ( 1.0%) 3 32 hir-stats - Local 32 ( 0.3%) 1 hir-stats - Semi 32 ( 0.3%) 1 hir-stats - Expr 32 ( 0.3%) 1 hir-stats FnDecl 120 ( 1.2%) 3 40 hir-stats Attribute 128 ( 1.3%) 4 32 -hir-stats GenericArg 128 ( 1.3%) 4 32 -hir-stats - Type 32 ( 0.3%) 1 -hir-stats - Lifetime 96 ( 0.9%) 3 -hir-stats GenericArgs 144 ( 1.4%) 3 48 -hir-stats Variant 160 ( 1.6%) 2 80 -hir-stats GenericBound 192 ( 1.9%) 4 48 -hir-stats - Trait 192 ( 1.9%) 4 -hir-stats WherePredicate 216 ( 2.1%) 3 72 -hir-stats - BoundPredicate 216 ( 2.1%) 3 -hir-stats Block 288 ( 2.8%) 6 48 -hir-stats GenericParam 400 ( 3.9%) 5 80 -hir-stats Pat 440 ( 4.3%) 5 88 -hir-stats - Wild 88 ( 0.9%) 1 -hir-stats - Struct 88 ( 0.9%) 1 -hir-stats - Binding 264 ( 2.6%) 3 -hir-stats Generics 560 ( 5.5%) 10 56 -hir-stats Expr 768 ( 7.6%) 12 64 -hir-stats - Path 64 ( 0.6%) 1 -hir-stats - Struct 64 ( 0.6%) 1 -hir-stats - Match 64 ( 0.6%) 1 -hir-stats - InlineAsm 64 ( 0.6%) 1 +hir-stats GenericArgs 144 ( 1.5%) 3 48 +hir-stats Variant 160 ( 1.7%) 2 80 +hir-stats WherePredicate 168 ( 1.7%) 3 56 +hir-stats - BoundPredicate 168 ( 1.7%) 3 +hir-stats GenericBound 192 ( 2.0%) 4 48 +hir-stats - Trait 192 ( 2.0%) 4 +hir-stats Block 288 ( 3.0%) 6 48 +hir-stats Pat 360 ( 3.7%) 5 72 +hir-stats - Wild 72 ( 0.7%) 1 +hir-stats - Struct 72 ( 0.7%) 1 +hir-stats - Binding 216 ( 2.2%) 3 +hir-stats GenericParam 400 ( 4.1%) 5 80 +hir-stats Generics 560 ( 5.8%) 10 56 +hir-stats Ty 720 ( 7.4%) 15 48 +hir-stats - Ptr 48 ( 0.5%) 1 +hir-stats - Rptr 48 ( 0.5%) 1 +hir-stats - Path 624 ( 6.4%) 13 +hir-stats Expr 768 ( 7.9%) 12 64 +hir-stats - Path 64 ( 0.7%) 1 +hir-stats - Struct 64 ( 0.7%) 1 +hir-stats - Match 64 ( 0.7%) 1 +hir-stats - InlineAsm 64 ( 0.7%) 1 hir-stats - Lit 128 ( 1.3%) 2 -hir-stats - Block 384 ( 3.8%) 6 -hir-stats Item 960 ( 9.4%) 12 80 +hir-stats - Block 384 ( 4.0%) 6 +hir-stats Item 960 ( 9.9%) 12 80 hir-stats - Trait 80 ( 0.8%) 1 hir-stats - Enum 80 ( 0.8%) 1 hir-stats - ExternCrate 80 ( 0.8%) 1 hir-stats - ForeignMod 80 ( 0.8%) 1 hir-stats - Impl 80 ( 0.8%) 1 -hir-stats - Fn 160 ( 1.6%) 2 -hir-stats - Use 400 ( 3.9%) 5 -hir-stats Ty 1_080 (10.6%) 15 72 -hir-stats - Ptr 72 ( 0.7%) 1 -hir-stats - Rptr 72 ( 0.7%) 1 -hir-stats - Path 936 ( 9.2%) 13 -hir-stats Path 1_536 (15.1%) 32 48 -hir-stats PathSegment 2_240 (22.0%) 40 56 +hir-stats - Fn 160 ( 1.7%) 2 +hir-stats - Use 400 ( 4.1%) 5 +hir-stats Path 1_536 (15.9%) 32 48 +hir-stats PathSegment 2_240 (23.1%) 40 56 hir-stats ---------------------------------------------------------------- -hir-stats Total 10_168 +hir-stats Total 9_680 hir-stats diff --git a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs index fdfb821ac78..bce49165e5b 100644 --- a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs +++ b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs @@ -51,7 +51,9 @@ fn unary_pattern(pat: &Pat<'_>) -> bool { false }, PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), - PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => !etc.is_some() && array_rec(a), + PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => { + !etc.as_opt_usize().is_some() && array_rec(a) + } PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x), PatKind::Path(_) | PatKind::Lit(_) => true, } diff --git a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs index e32ef9933af..93874b103b4 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs @@ -248,7 +248,7 @@ impl<'a> NormalizedPat<'a> { } else { (None, adt.non_enum_variant()) }; - let (front, back) = match wild_idx { + let (front, back) = match wild_idx.as_opt_usize() { Some(i) => pats.split_at(i), None => (pats, [].as_slice()), }; @@ -268,7 +268,7 @@ impl<'a> NormalizedPat<'a> { ty::Tuple(subs) => subs.len(), _ => return Self::Wild, }; - let (front, back) = match wild_idx { + let (front, back) = match wild_idx.as_opt_usize() { Some(i) => pats.split_at(i), None => (pats, [].as_slice()), }; diff --git a/src/tools/clippy/clippy_lints/src/matches/single_match.rs b/src/tools/clippy/clippy_lints/src/matches/single_match.rs index 95478af45b4..1bf1c4d1078 100644 --- a/src/tools/clippy/clippy_lints/src/matches/single_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/single_match.rs @@ -200,6 +200,8 @@ fn form_exhaustive_matches<'a>(cx: &LateContext<'a>, ty: Ty<'a>, left: &Pat<'_>, // We don't actually know the position and the presence of the `..` (dotdot) operator // in the arms, so we need to evaluate the correct offsets here in order to iterate in // both arms at the same time. + let left_pos = left_pos.as_opt_usize(); + let right_pos = right_pos.as_opt_usize(); let len = max( left_in.len() + { if left_pos.is_some() { 1 } else { 0 } diff --git a/src/tools/clippy/clippy_lints/src/question_mark.rs b/src/tools/clippy/clippy_lints/src/question_mark.rs index f4f1fd336df..569870ab2b7 100644 --- a/src/tools/clippy/clippy_lints/src/question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/question_mark.rs @@ -122,7 +122,8 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: if_chain! { if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr); if !is_else_clause(cx.tcx, expr); - if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind; + if let PatKind::TupleStruct(ref path1, [field], ddpos) = let_pat.kind; + if ddpos.as_opt_usize().is_none(); if let PatKind::Binding(BindingAnnotation(by_ref, _), bind_id, ident, None) = field.kind; let caller_ty = cx.typeck_results().expr_ty(let_expr); let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else); diff --git a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs index 35824b03170..ce9ebad8c89 100644 --- a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs +++ b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs @@ -19,10 +19,12 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { && cx.typeck_results().pat_ty(local.pat).is_unit() { if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer)) - || matches!(local.pat.kind, PatKind::Tuple([], None))) + || matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none())) && expr_needs_inferred_result(cx, init) { - if !matches!(local.pat.kind, PatKind::Wild | PatKind::Tuple([], None)) { + if !matches!(local.pat.kind, PatKind::Wild) + && !matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none()) + { span_lint_and_then( cx, LET_UNIT_VALUE, diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index 57448f716d4..ff23ed5fffa 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -929,7 +929,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_lifetime(&mut self, lifetime: Lifetime) { + pub fn hash_lifetime(&mut self, lifetime: &Lifetime) { std::mem::discriminant(&lifetime.name).hash(&mut self.s); if let LifetimeName::Param(param_id, ref name) = lifetime.name { std::mem::discriminant(name).hash(&mut self.s); diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index b27439cbec2..3cf043f22df 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1552,7 +1552,8 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl<'_>, body: &'tcx Body<'_>) -> impl It pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { fn is_ok(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { if_chain! { - if let PatKind::TupleStruct(ref path, pat, None) = arm.pat.kind; + if let PatKind::TupleStruct(ref path, pat, ddpos) = arm.pat.kind; + if ddpos.as_opt_usize().is_none(); if is_lang_ctor(cx, path, ResultOk); if let PatKind::Binding(_, hir_id, _, None) = pat[0].kind; if path_to_local_id(arm.body, hir_id); |
