Skip to content

Commit 28dd5d1

Browse files
authored
Unrolled build for #142716
Rollup merge of #142716 - nnethercote:adjust-with_generic_param_rib, r=petrochenkov Adjust `with_generic_param_rib`. Currently all of its call sites construct a `LifetimeRibKind::Generics` value, which `with_generic_param_rib` then deconstructs (and panics if it's a different `LifetimeRibKind` variant). This commit makes the code simpler and shorter: the call sites just pass in the three values and `with_generic_param_rib` constructs the `LifetimeRibKind::Generics` value from them. r? `@petrochenkov`
2 parents 15c701f + 41ca0cb commit 28dd5d1

File tree

1 file changed

+77
-119
lines changed

1 file changed

+77
-119
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 77 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,9 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
869869
self.with_generic_param_rib(
870870
&[],
871871
RibKind::Normal,
872-
LifetimeRibKind::Generics {
873-
binder: ty.id,
874-
kind: LifetimeBinderKind::PolyTrait,
875-
span,
876-
},
872+
ty.id,
873+
LifetimeBinderKind::PolyTrait,
874+
span,
877875
|this| this.visit_path(path),
878876
);
879877
} else {
@@ -907,11 +905,9 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
907905
self.with_generic_param_rib(
908906
&bare_fn.generic_params,
909907
RibKind::Normal,
910-
LifetimeRibKind::Generics {
911-
binder: ty.id,
912-
kind: LifetimeBinderKind::BareFnType,
913-
span,
914-
},
908+
ty.id,
909+
LifetimeBinderKind::BareFnType,
910+
span,
915911
|this| {
916912
this.visit_generic_params(&bare_fn.generic_params, false);
917913
this.with_lifetime_rib(
@@ -942,11 +938,9 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
942938
self.with_generic_param_rib(
943939
&unsafe_binder.generic_params,
944940
RibKind::Normal,
945-
LifetimeRibKind::Generics {
946-
binder: ty.id,
947-
kind: LifetimeBinderKind::BareFnType,
948-
span,
949-
},
941+
ty.id,
942+
LifetimeBinderKind::BareFnType,
943+
span,
950944
|this| {
951945
this.visit_generic_params(&unsafe_binder.generic_params, false);
952946
this.with_lifetime_rib(
@@ -995,11 +989,9 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
995989
self.with_generic_param_rib(
996990
&tref.bound_generic_params,
997991
RibKind::Normal,
998-
LifetimeRibKind::Generics {
999-
binder: tref.trait_ref.ref_id,
1000-
kind: LifetimeBinderKind::PolyTrait,
1001-
span,
1002-
},
992+
tref.trait_ref.ref_id,
993+
LifetimeBinderKind::PolyTrait,
994+
span,
1003995
|this| {
1004996
this.visit_generic_params(&tref.bound_generic_params, false);
1005997
this.smart_resolve_path(
@@ -1020,23 +1012,19 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
10201012
self.with_generic_param_rib(
10211013
&generics.params,
10221014
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
1023-
LifetimeRibKind::Generics {
1024-
binder: foreign_item.id,
1025-
kind: LifetimeBinderKind::Item,
1026-
span: generics.span,
1027-
},
1015+
foreign_item.id,
1016+
LifetimeBinderKind::Item,
1017+
generics.span,
10281018
|this| visit::walk_item(this, foreign_item),
10291019
);
10301020
}
10311021
ForeignItemKind::Fn(box Fn { ref generics, .. }) => {
10321022
self.with_generic_param_rib(
10331023
&generics.params,
10341024
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
1035-
LifetimeRibKind::Generics {
1036-
binder: foreign_item.id,
1037-
kind: LifetimeBinderKind::Function,
1038-
span: generics.span,
1039-
},
1025+
foreign_item.id,
1026+
LifetimeBinderKind::Function,
1027+
generics.span,
10401028
|this| visit::walk_item(this, foreign_item),
10411029
);
10421030
}
@@ -1374,11 +1362,9 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
13741362
this.with_generic_param_rib(
13751363
bound_generic_params,
13761364
RibKind::Normal,
1377-
LifetimeRibKind::Generics {
1378-
binder: bounded_ty.id,
1379-
kind: LifetimeBinderKind::WhereBound,
1380-
span,
1381-
},
1365+
bounded_ty.id,
1366+
LifetimeBinderKind::WhereBound,
1367+
span,
13821368
|this| {
13831369
this.visit_generic_params(bound_generic_params, false);
13841370
this.visit_ty(bounded_ty);
@@ -2555,11 +2541,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
25552541
this.with_generic_param_rib(
25562542
&generics.params,
25572543
RibKind::Item(HasGenericParams::Yes(generics.span), kind),
2558-
LifetimeRibKind::Generics {
2559-
binder: item.id,
2560-
kind: LifetimeBinderKind::Item,
2561-
span: generics.span,
2562-
},
2544+
item.id,
2545+
LifetimeBinderKind::Item,
2546+
generics.span,
25632547
|this| {
25642548
let item_def_id = this.r.local_def_id(item.id).to_def_id();
25652549
this.with_self_rib(
@@ -2632,11 +2616,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
26322616
self.with_generic_param_rib(
26332617
&generics.params,
26342618
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2635-
LifetimeRibKind::Generics {
2636-
binder: item.id,
2637-
kind: LifetimeBinderKind::Item,
2638-
span: generics.span,
2639-
},
2619+
item.id,
2620+
LifetimeBinderKind::Item,
2621+
generics.span,
26402622
|this| visit::walk_item(this, item),
26412623
);
26422624
}
@@ -2645,11 +2627,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
26452627
self.with_generic_param_rib(
26462628
&generics.params,
26472629
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2648-
LifetimeRibKind::Generics {
2649-
binder: item.id,
2650-
kind: LifetimeBinderKind::Function,
2651-
span: generics.span,
2652-
},
2630+
item.id,
2631+
LifetimeBinderKind::Function,
2632+
generics.span,
26532633
|this| visit::walk_item(this, item),
26542634
);
26552635
self.resolve_define_opaques(define_opaque);
@@ -2685,11 +2665,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
26852665
self.with_generic_param_rib(
26862666
&generics.params,
26872667
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2688-
LifetimeRibKind::Generics {
2689-
binder: item.id,
2690-
kind: LifetimeBinderKind::Item,
2691-
span: generics.span,
2692-
},
2668+
item.id,
2669+
LifetimeBinderKind::Item,
2670+
generics.span,
26932671
|this| {
26942672
let local_def_id = this.r.local_def_id(item.id).to_def_id();
26952673
this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
@@ -2706,11 +2684,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27062684
self.with_generic_param_rib(
27072685
&generics.params,
27082686
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
2709-
LifetimeRibKind::Generics {
2710-
binder: item.id,
2711-
kind: LifetimeBinderKind::Item,
2712-
span: generics.span,
2713-
},
2687+
item.id,
2688+
LifetimeBinderKind::Item,
2689+
generics.span,
27142690
|this| {
27152691
let local_def_id = this.r.local_def_id(item.id).to_def_id();
27162692
this.with_self_rib(Res::SelfTyParam { trait_: local_def_id }, |this| {
@@ -2776,11 +2752,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27762752
},
27772753
def_kind,
27782754
),
2779-
LifetimeRibKind::Generics {
2780-
binder: item.id,
2781-
kind: LifetimeBinderKind::ConstItem,
2782-
span: generics.span,
2783-
},
2755+
item.id,
2756+
LifetimeBinderKind::ConstItem,
2757+
generics.span,
27842758
|this| {
27852759
this.visit_generics(generics);
27862760

@@ -2825,11 +2799,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28252799
self.with_generic_param_rib(
28262800
&[],
28272801
RibKind::Item(HasGenericParams::Yes(span), def_kind),
2828-
LifetimeRibKind::Generics {
2829-
binder: item.id,
2830-
kind: LifetimeBinderKind::Function,
2831-
span,
2832-
},
2802+
item.id,
2803+
LifetimeBinderKind::Function,
2804+
span,
28332805
|this| this.resolve_delegation(delegation),
28342806
);
28352807
}
@@ -2846,17 +2818,16 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28462818
&'c mut self,
28472819
params: &'c [GenericParam],
28482820
kind: RibKind<'ra>,
2849-
lifetime_kind: LifetimeRibKind,
2821+
binder: NodeId,
2822+
generics_kind: LifetimeBinderKind,
2823+
generics_span: Span,
28502824
f: F,
28512825
) where
28522826
F: FnOnce(&mut Self),
28532827
{
28542828
debug!("with_generic_param_rib");
2855-
let LifetimeRibKind::Generics { binder, span: generics_span, kind: generics_kind, .. } =
2856-
lifetime_kind
2857-
else {
2858-
panic!()
2859-
};
2829+
let lifetime_kind =
2830+
LifetimeRibKind::Generics { binder, span: generics_span, kind: generics_kind };
28602831

28612832
let mut function_type_rib = Rib::new(kind);
28622833
let mut function_value_rib = Rib::new(kind);
@@ -3086,7 +3057,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
30863057
this.with_generic_param_rib(
30873058
&generics.params,
30883059
RibKind::AssocItem,
3089-
LifetimeRibKind::Generics { binder: item.id, span: generics.span, kind },
3060+
item.id,
3061+
kind,
3062+
generics.span,
30903063
|this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
30913064
);
30923065
};
@@ -3104,11 +3077,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
31043077
self.with_generic_param_rib(
31053078
&generics.params,
31063079
RibKind::AssocItem,
3107-
LifetimeRibKind::Generics {
3108-
binder: item.id,
3109-
span: generics.span,
3110-
kind: LifetimeBinderKind::ConstItem,
3111-
},
3080+
item.id,
3081+
LifetimeBinderKind::ConstItem,
3082+
generics.span,
31123083
|this| {
31133084
this.with_lifetime_rib(
31143085
LifetimeRibKind::StaticIfNoLifetimeInScope {
@@ -3145,11 +3116,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
31453116
self.with_generic_param_rib(
31463117
&[],
31473118
RibKind::AssocItem,
3148-
LifetimeRibKind::Generics {
3149-
binder: item.id,
3150-
kind: LifetimeBinderKind::Function,
3151-
span: delegation.path.segments.last().unwrap().ident.span,
3152-
},
3119+
item.id,
3120+
LifetimeBinderKind::Function,
3121+
delegation.path.segments.last().unwrap().ident.span,
31533122
|this| this.resolve_delegation(delegation),
31543123
);
31553124
}
@@ -3227,11 +3196,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32273196
self.with_generic_param_rib(
32283197
&generics.params,
32293198
RibKind::Item(HasGenericParams::Yes(generics.span), self.r.local_def_kind(item_id)),
3230-
LifetimeRibKind::Generics {
3231-
span: generics.span,
3232-
binder: item_id,
3233-
kind: LifetimeBinderKind::ImplBlock,
3234-
},
3199+
item_id,
3200+
LifetimeBinderKind::ImplBlock,
3201+
generics.span,
32353202
|this| {
32363203
// Dummy self type for better errors if `Self` is used in the trait path.
32373204
this.with_self_rib(Res::SelfTyParam { trait_: LOCAL_CRATE.as_def_id() }, |this| {
@@ -3316,15 +3283,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
33163283
self.with_generic_param_rib(
33173284
&generics.params,
33183285
RibKind::AssocItem,
3319-
LifetimeRibKind::Generics {
3320-
binder: item.id,
3321-
span: generics.span,
3322-
kind: LifetimeBinderKind::ConstItem,
3323-
},
3286+
item.id,
3287+
LifetimeBinderKind::ConstItem,
3288+
generics.span,
33243289
|this| {
33253290
this.with_lifetime_rib(
3326-
// Until these are a hard error, we need to create them within the correct binder,
3327-
// Otherwise the lifetimes of this assoc const think they are lifetimes of the trait.
3291+
// Until these are a hard error, we need to create them within the
3292+
// correct binder, Otherwise the lifetimes of this assoc const think
3293+
// they are lifetimes of the trait.
33283294
LifetimeRibKind::AnonymousCreateParameter {
33293295
binder: item.id,
33303296
report_in_path: true,
@@ -3373,11 +3339,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
33733339
self.with_generic_param_rib(
33743340
&generics.params,
33753341
RibKind::AssocItem,
3376-
LifetimeRibKind::Generics {
3377-
binder: item.id,
3378-
span: generics.span,
3379-
kind: LifetimeBinderKind::Function,
3380-
},
3342+
item.id,
3343+
LifetimeBinderKind::Function,
3344+
generics.span,
33813345
|this| {
33823346
// If this is a trait impl, ensure the method
33833347
// exists in trait
@@ -3404,11 +3368,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34043368
self.with_generic_param_rib(
34053369
&generics.params,
34063370
RibKind::AssocItem,
3407-
LifetimeRibKind::Generics {
3408-
binder: item.id,
3409-
span: generics.span,
3410-
kind: LifetimeBinderKind::Item,
3411-
},
3371+
item.id,
3372+
LifetimeBinderKind::Item,
3373+
generics.span,
34123374
|this| {
34133375
this.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
34143376
// If this is a trait impl, ensure the type
@@ -3434,11 +3396,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34343396
self.with_generic_param_rib(
34353397
&[],
34363398
RibKind::AssocItem,
3437-
LifetimeRibKind::Generics {
3438-
binder: item.id,
3439-
kind: LifetimeBinderKind::Function,
3440-
span: delegation.path.segments.last().unwrap().ident.span,
3441-
},
3399+
item.id,
3400+
LifetimeBinderKind::Function,
3401+
delegation.path.segments.last().unwrap().ident.span,
34423402
|this| {
34433403
this.check_trait_item(
34443404
item.id,
@@ -4951,11 +4911,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
49514911
self.with_generic_param_rib(
49524912
generic_params,
49534913
RibKind::Normal,
4954-
LifetimeRibKind::Generics {
4955-
binder: expr.id,
4956-
kind: LifetimeBinderKind::Closure,
4957-
span,
4958-
},
4914+
expr.id,
4915+
LifetimeBinderKind::Closure,
4916+
span,
49594917
|this| visit::walk_expr(this, expr),
49604918
);
49614919
}

0 commit comments

Comments
 (0)