Skip to content

Commit 80b381e

Browse files
committed
Remove all traces of lifetimes() and types() methods
1 parent 10229fd commit 80b381e

File tree

16 files changed

+419
-346
lines changed

16 files changed

+419
-346
lines changed

src/librustc/hir/lowering.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,11 @@ impl<'a> LoweringContext<'a> {
17311731
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
17321732
};
17331733

1734-
if !generic_args.parenthesized && generic_args.lifetimes().count() == 0 {
1734+
let has_lifetimes = generic_args.args.iter().any(|arg| match arg {
1735+
GenericArg::Lifetime(_) => true,
1736+
_ => false,
1737+
});
1738+
if !generic_args.parenthesized && !has_lifetimes {
17351739
generic_args.args =
17361740
self.elided_path_lifetimes(path_span, expected_lifetimes)
17371741
.into_iter()
@@ -1763,7 +1767,7 @@ impl<'a> LoweringContext<'a> {
17631767
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
17641768
parenthesized: false,
17651769
},
1766-
has_types && param_mode == ParamMode::Optional)
1770+
!has_types && param_mode == ParamMode::Optional)
17671771
}
17681772

17691773
fn lower_parenthesized_parameter_data(

src/librustc/hir/mod.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -400,34 +400,20 @@ impl GenericArgs {
400400

401401
pub fn inputs(&self) -> &[P<Ty>] {
402402
if self.parenthesized {
403-
if let Some(ref ty) = self.types().next() {
404-
if let TyTup(ref tys) = ty.node {
405-
return tys;
403+
for arg in &self.args {
404+
match arg {
405+
GenericArg::Lifetime(_) => {}
406+
GenericArg::Type(ref ty) => {
407+
if let TyTup(ref tys) = ty.node {
408+
return tys;
409+
}
410+
break;
411+
}
406412
}
407413
}
408414
}
409415
bug!("GenericArgs::inputs: not a `Fn(T) -> U`");
410416
}
411-
412-
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
413-
self.args.iter().filter_map(|p| {
414-
if let GenericArg::Lifetime(lt) = p {
415-
Some(lt)
416-
} else {
417-
None
418-
}
419-
})
420-
}
421-
422-
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
423-
self.args.iter().filter_map(|p| {
424-
if let GenericArg::Type(ty) = p {
425-
Some(ty)
426-
} else {
427-
None
428-
}
429-
})
430-
}
431417
}
432418

433419
/// The AST represents all type param bounds as types.

src/librustc/hir/print.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,20 +1731,31 @@ impl<'a> State<'a> {
17311731
}
17321732
};
17331733

1734-
let elide_lifetimes = generic_args.lifetimes().all(|lt| lt.is_elided());
1734+
let mut types = vec![];
1735+
let mut elide_lifetimes = true;
1736+
for arg in &generic_args.args {
1737+
match arg {
1738+
GenericArg::Lifetime(lt) => {
1739+
if !lt.is_elided() {
1740+
elide_lifetimes = false;
1741+
}
1742+
}
1743+
GenericArg::Type(ty) => {
1744+
types.push(ty);
1745+
}
1746+
}
1747+
}
17351748
if !elide_lifetimes {
17361749
start_or_comma(self)?;
17371750
self.commasep(Inconsistent, &generic_args.args, |s, generic_arg| {
17381751
match generic_arg {
17391752
GenericArg::Lifetime(lt) => s.print_lifetime(lt),
17401753
GenericArg::Type(ty) => s.print_type(ty),
1741-
}
1754+
}
17421755
})?;
1743-
} else if generic_args.types().count() != 0 {
1756+
} else if !types.is_empty() {
17441757
start_or_comma(self)?;
1745-
self.commasep(Inconsistent,
1746-
&generic_args.types().collect::<Vec<_>>(),
1747-
|s, ty| s.print_type(&ty))?;
1758+
self.commasep(Inconsistent, &types, |s, ty| s.print_type(&ty))?;
17481759
}
17491760

17501761
// FIXME(eddyb) This would leak into error messages, e.g.:

0 commit comments

Comments
 (0)