Skip to content

Commit 831b5c0

Browse files
committed
Take advantage of the lifetime refactoring
1 parent 6015edf commit 831b5c0

File tree

8 files changed

+50
-66
lines changed

8 files changed

+50
-66
lines changed

src/librustc/hir/intravisit.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,20 +743,19 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBou
743743
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) {
744744
visitor.visit_id(param.id);
745745
match param.kind {
746-
GenericParamKind::Lifetime { ref bounds, ref lifetime, .. } => {
747-
match lifetime.name {
746+
GenericParamKind::Lifetime { ref lt_name, .. } => {
747+
match lt_name {
748748
LifetimeName::Name(name) => {
749-
visitor.visit_name(param.span, name);
749+
visitor.visit_name(param.span, *name);
750750
}
751751
LifetimeName::Fresh(_) |
752752
LifetimeName::Static |
753753
LifetimeName::Implicit |
754754
LifetimeName::Underscore => {}
755755
}
756-
walk_list!(visitor, visit_lifetime, bounds);
757756
}
758-
GenericParamKind::Type { name, ref bounds, ref default, ref attrs, .. } => {
759-
visitor.visit_name(param.span, name);
757+
GenericParamKind::Type { ref default, ref attrs, .. } => {
758+
visitor.visit_name(param.span, param.name);
760759
walk_list!(visitor, visit_ty, default);
761760
walk_list!(visitor, visit_attribute, attrs.iter());
762761
}

src/librustc/hir/lowering.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ impl<'a> LoweringContext<'a> {
17471747

17481748
fn lower_parenthesized_parameter_data(
17491749
&mut self,
1750-
data: &ParenthesizedParameterData,
1751-
) -> (hir::PathParameters, bool) {
1750+
data: &ParenthesizedArgData,
1751+
) -> (hir::GenericArgs, bool) {
17521752
// Switch to `PassThrough` mode for anonymous lifetimes: this
17531753
// means that we permit things like `&Ref<T>`, where `Ref` has
17541754
// a hidden lifetime parameter. This is needed for backwards
@@ -1758,7 +1758,7 @@ impl<'a> LoweringContext<'a> {
17581758
AnonymousLifetimeMode::PassThrough,
17591759
|this| {
17601760
const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed;
1761-
let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
1761+
let &ParenthesizedArgData { ref inputs, ref output, span } = data;
17621762
let inputs = inputs.iter().map(|ty| this.lower_ty(ty, DISALLOWED)).collect();
17631763
let mk_tup = |this: &mut Self, tys, span| {
17641764
let LoweredNodeId { node_id, hir_id } = this.next_id();
@@ -1767,7 +1767,7 @@ impl<'a> LoweringContext<'a> {
17671767

17681768
(
17691769
hir::GenericArgs {
1770-
parameters: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
1770+
args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
17711771
bindings: hir_vec![
17721772
hir::TypeBinding {
17731773
id: this.next_id().node_id,

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
347347
}
348348

349349
fn visit_generic_param(&mut self, param: &'hir GenericParam) {
350-
match param.kind {
351-
GenericParamKind::Lifetime { ref lifetime_deprecated, .. } => {
352-
self.insert(param.id, NodeLifetime(lifetime_deprecated));
353-
}
354-
GenericParamKind::Type { .. } => {
355-
self.insert(param.id, NodeGenericParam(param));
356-
}
357-
}
350+
self.insert(param.id, NodeGenericParam(param));
358351
intravisit::walk_generic_param(self, param);
359352
}
360353

src/librustc/middle/resolve_lifetime.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl Region {
110110
let depth = ty::INNERMOST;
111111
let (name, def_id, origin) = new_region(hir_map, param);
112112
debug!(
113-
"Region::late: def={:?} depth={:?} def_id={:?} origin={:?}",
114-
def,
113+
"Region::late: param={:?} depth={:?} def_id={:?} origin={:?}",
114+
param,
115115
depth,
116116
def_id,
117117
origin,
@@ -2243,8 +2243,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22432243
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
22442244
match lifetime_i_name {
22452245
hir::LifetimeName::Static | hir::LifetimeName::Underscore => {
2246-
let lifetime = lifetime_i.lifetime;
2247-
let name = lifetime_i.name();
2246+
let name = lifetime_i.name;
22482247
let mut err = struct_span_err!(
22492248
self.tcx.sess,
22502249
lifetime_i.span,
@@ -2518,10 +2517,10 @@ fn insert_late_bound_lifetimes(
25182517

25192518
for param in &generics.params {
25202519
match param.kind {
2521-
hir::GenericParamKind::Lifetime { .. } => {
2520+
hir::GenericParamKind::Lifetime { lt_name, .. } => {
25222521
if !param.bounds.is_empty() {
25232522
// `'a: 'b` means both `'a` and `'b` are referenced
2524-
appears_in_where_clause.regions.insert(lifetime_def.lifetime.name);
2523+
appears_in_where_clause.regions.insert(lt_name);
25252524
}
25262525
}
25272526
hir::GenericParamKind::Type { .. } => {}

src/librustc_passes/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
431431
}
432432

433433
fn visit_generic_param(&mut self, param: &'a GenericParam) {
434-
if let GenericParam::Lifetime(ref ld) = *param {
435-
self.check_lifetime(ld.lifetime.ident);
434+
if let GenericParamKind::Lifetime { .. } = param.kind {
435+
self.check_lifetime(param.ident);
436436
}
437437
visit::walk_generic_param(self, param);
438438
}

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ pub enum GenericParamKind {
309309

310310
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
311311
pub struct GenericParam {
312-
pub ident: Ident,
313312
pub id: NodeId,
313+
pub ident: Ident,
314314
pub attrs: ThinVec<Attribute>,
315315
pub bounds: ParamBounds,
316316

src/libsyntax/fold.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ pub trait Folder : Sized {
143143
noop_fold_ty(t, self)
144144
}
145145

146+
fn fold_lifetime(&mut self, l: Lifetime) -> Lifetime {
147+
noop_fold_lifetime(l, self)
148+
}
149+
146150
fn fold_ty_binding(&mut self, t: TypeBinding) -> TypeBinding {
147151
noop_fold_ty_binding(t, self)
148152
}
@@ -240,10 +244,6 @@ pub trait Folder : Sized {
240244
noop_fold_variant_data(vdata, self)
241245
}
242246

243-
fn fold_ty_param(&mut self, tp: TyParam) -> TyParam {
244-
noop_fold_ty_param(tp, self)
245-
}
246-
247247
fn fold_generic_param(&mut self, param: GenericParam) -> GenericParam {
248248
noop_fold_generic_param(param, self)
249249
}
@@ -268,17 +268,16 @@ pub trait Folder : Sized {
268268
noop_fold_interpolated(nt, self)
269269
}
270270

271-
fn fold_opt_bounds(&mut self, b: Option<TyParamBounds>) -> Option<TyParamBounds> {
271+
fn fold_opt_bounds(&mut self, b: Option<ParamBounds>) -> Option<ParamBounds> {
272272
noop_fold_opt_bounds(b, self)
273273
}
274274

275-
fn fold_bounds(&mut self, b: ParamBounds)
276-
-> ParamBounds {
275+
fn fold_bounds(&mut self, b: ParamBounds) -> ParamBounds {
277276
noop_fold_bounds(b, self)
278277
}
279278

280-
fn fold_ty_param_bound(&mut self, tpb: ParamBound) -> ParamBound {
281-
noop_fold_ty_param_bound(tpb, self)
279+
fn fold_param_bound(&mut self, tpb: ParamBound) -> ParamBound {
280+
noop_fold_param_bound(tpb, self)
282281
}
283282

284283
fn fold_mt(&mut self, mt: MutTy) -> MutTy {
@@ -391,10 +390,10 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
391390
TyKind::Typeof(fld.fold_anon_const(expr))
392391
}
393392
TyKind::TraitObject(bounds, syntax) => {
394-
TyKind::TraitObject(bounds.move_map(|b| fld.fold_ty_param_bound(b)), syntax)
393+
TyKind::TraitObject(bounds.move_map(|b| fld.fold_param_bound(b)), syntax)
395394
}
396395
TyKind::ImplTrait(bounds) => {
397-
TyKind::ImplTrait(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
396+
TyKind::ImplTrait(bounds.move_map(|b| fld.fold_param_bound(b)))
398397
}
399398
TyKind::Mac(mac) => {
400399
TyKind::Mac(fld.fold_mac(mac))
@@ -677,32 +676,31 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
677676
})
678677
}
679678

680-
pub fn noop_fold_ty_param_bound<T>(tpb: ParamBound, fld: &mut T)
681-
-> ParamBound
682-
where T: Folder {
683-
match tpb {
684-
TraitTyParamBound(ty, modifier) => TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier),
679+
pub fn noop_fold_param_bound<T>(pb: ParamBound, fld: &mut T) -> ParamBound where T: Folder {
680+
match pb {
681+
TraitTyParamBound(ty, modifier) => {
682+
TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier)
683+
}
685684
Outlives(lifetime) => Outlives(noop_fold_lifetime(lifetime, fld)),
686685
}
687686
}
688687

689688
pub fn noop_fold_generic_param<T: Folder>(param: GenericParam, fld: &mut T) -> GenericParam {
690-
match param.kind {
691-
GenericParamKind::Lifetime { bounds, lifetime } => {
692-
let attrs: Vec<_> = param.attrs.into();
693-
GenericParamKind::Lifetime(LifetimeDef {
694-
attrs: attrs.into_iter()
689+
let attrs: Vec<_> = param.attrs.into();
690+
GenericParam {
691+
ident: fld.fold_ident(param.ident),
692+
id: fld.new_id(param.id),
693+
attrs: attrs.into_iter()
695694
.flat_map(|x| fld.fold_attribute(x).into_iter())
696695
.collect::<Vec<_>>()
697696
.into(),
698-
lifetime: Lifetime {
699-
id: fld.new_id(param.id),
700-
ident: fld.fold_ident(param.ident),
701-
},
702-
bounds: bounds.move_map(|l| noop_fold_lifetime(l, fld)),
703-
})
697+
bounds: param.bounds.move_map(|l| noop_fold_param_bound(l, fld)),
698+
kind: match param.kind {
699+
GenericParamKind::Lifetime => GenericParamKind::Lifetime,
700+
GenericParamKind::Type { default } => GenericParamKind::Type {
701+
default: default.map(|ty| fld.fold_ty(ty))
702+
}
704703
}
705-
GenericParamKind::Type { .. } => GenericParamKind::Type(fld.fold_ty_param(param)),
706704
}
707705
}
708706

@@ -760,7 +758,7 @@ pub fn noop_fold_where_predicate<T: Folder>(
760758
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
761759
bound_generic_params: fld.fold_generic_params(bound_generic_params),
762760
bounded_ty: fld.fold_ty(bounded_ty),
763-
bounds: bounds.move_map(|x| fld.fold_ty_param_bound(x)),
761+
bounds: bounds.move_map(|x| fld.fold_param_bound(x)),
764762
span: fld.new_span(span)
765763
})
766764
}
@@ -770,7 +768,7 @@ pub fn noop_fold_where_predicate<T: Folder>(
770768
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
771769
span: fld.new_span(span),
772770
lifetime: noop_fold_lifetime(lifetime, fld),
773-
bounds: bounds.move_map(|bound| noop_fold_lifetime(bound, fld))
771+
bounds: bounds.move_map(|bound| noop_fold_param_bound(bound, fld))
774772
})
775773
}
776774
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{id,
@@ -856,7 +854,7 @@ pub fn noop_fold_opt_bounds<T: Folder>(b: Option<ParamBounds>, folder: &mut T)
856854

857855
fn noop_fold_bounds<T: Folder>(bounds: ParamBounds, folder: &mut T)
858856
-> ParamBounds {
859-
bounds.move_map(|bound| folder.fold_ty_param_bound(bound))
857+
bounds.move_map(|bound| folder.fold_param_bound(bound))
860858
}
861859

862860
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> {

src/libsyntax/visit.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,10 @@ pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a ParamBou
492492

493493
pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) {
494494
visitor.visit_ident(param.ident);
495+
walk_list!(visitor, visit_param_bound, &param.bounds);
495496
match param.kind {
496-
GenericParamKind::Lifetime { ref bounds, ref lifetime } => {
497-
walk_list!(visitor, visit_lifetime, bounds);
498-
}
499-
GenericParamKind::Type { ref bounds, ref default } => {
500-
visitor.visit_ident(t.ident);
501-
walk_list!(visitor, visit_ty_param_bound, bounds);
502-
walk_list!(visitor, visit_ty, default);
503-
}
497+
GenericParamKind::Lifetime => {}
498+
GenericParamKind::Type { ref default } => walk_list!(visitor, visit_ty, default),
504499
}
505500
walk_list!(visitor, visit_attribute, param.attrs.iter());
506501
}

0 commit comments

Comments
 (0)