Skip to content

Commit c654548

Browse files
committed
Remove AngleBracketedArgs impl
1 parent e1d888c commit c654548

File tree

5 files changed

+39
-40
lines changed

5 files changed

+39
-40
lines changed

src/librustc/hir/lowering.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,12 +1754,16 @@ impl<'a> LoweringContext<'a> {
17541754
itctx: ImplTraitContext,
17551755
) -> (hir::GenericArgs, bool) {
17561756
let &AngleBracketedArgs { ref args, ref bindings, .. } = data;
1757+
let has_types = args.iter().any(|arg| match arg {
1758+
GenericArgAST::Type(_) => true,
1759+
_ => false,
1760+
});
17571761
(hir::GenericArgs {
17581762
args: args.iter().map(|a| self.lower_generic_arg(a, itctx)).collect(),
17591763
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
17601764
parenthesized: false,
17611765
},
1762-
data.types().count() == 0 && param_mode == ParamMode::Optional)
1766+
has_types && param_mode == ParamMode::Optional)
17631767
}
17641768

17651769
fn lower_parenthesized_parameter_data(

src/librustc_driver/pretty.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,18 @@ impl<'a> ReplaceBodyWithLoop<'a> {
679679
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| {
680680
match seg.args.as_ref().map(|generic_arg| &**generic_arg) {
681681
None => false,
682-
Some(&ast::GenericArgs::AngleBracketed(ref data)) =>
683-
any_involves_impl_trait(data.types().into_iter()) ||
684-
any_involves_impl_trait(data.bindings.iter().map(|b| &b.ty)),
685-
Some(&ast::GenericArgs::Parenthesized(ref data)) =>
682+
Some(&ast::GenericArgs::AngleBracketed(ref data)) => {
683+
let types = data.args.iter().filter_map(|arg| match arg {
684+
ast::GenericArgAST::Type(ty) => Some(ty),
685+
_ => None,
686+
});
687+
any_involves_impl_trait(types.into_iter()) ||
688+
any_involves_impl_trait(data.bindings.iter().map(|b| &b.ty))
689+
},
690+
Some(&ast::GenericArgs::Parenthesized(ref data)) => {
686691
any_involves_impl_trait(data.inputs.iter()) ||
687-
any_involves_impl_trait(data.output.iter()),
692+
any_involves_impl_trait(data.output.iter())
693+
}
688694
}
689695
}),
690696
_ => false,

src/librustc_passes/ast_validation.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,21 +515,24 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> {
515515
}
516516
fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
517517
match *generic_args {
518-
GenericArgs::AngleBracketed(ref generic_args) => {
519-
for type_ in generic_args.types() {
520-
self.visit_ty(type_);
518+
GenericArgs::AngleBracketed(ref data) => {
519+
for arg in &data.args {
520+
match arg {
521+
GenericArgAST::Type(ty) => self.visit_ty(ty),
522+
_ => {}
523+
}
521524
}
522-
for type_binding in &generic_args.bindings {
525+
for type_binding in &data.bindings {
523526
// Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
524527
// are allowed to contain nested `impl Trait`.
525528
self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty));
526529
}
527530
}
528-
GenericArgs::Parenthesized(ref generic_args) => {
529-
for type_ in &generic_args.inputs {
531+
GenericArgs::Parenthesized(ref data) => {
532+
for type_ in &data.inputs {
530533
self.visit_ty(type_);
531534
}
532-
if let Some(ref type_) = generic_args.output {
535+
if let Some(ref type_) = data.output {
533536
// `-> Foo` syntax is essentially an associated type binding,
534537
// so it is also allowed to contain nested `impl Trait`.
535538
self.with_impl_trait(None, |this| visit::walk_ty(this, type_));

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
825825
for seg in &path.segments {
826826
if let Some(ref generic_args) = seg.args {
827827
match **generic_args {
828-
ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() {
829-
self.visit_ty(t);
830-
},
828+
ast::GenericArgs::AngleBracketed(ref data) => {
829+
for arg in &data.args {
830+
match arg {
831+
ast::GenericArgAST::Type(ty) => self.visit_ty(ty),
832+
_ => {}
833+
}
834+
}
835+
}
831836
ast::GenericArgs::Parenthesized(ref data) => {
832837
for t in &data.inputs {
833838
self.visit_ty(t);
@@ -910,8 +915,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
910915
// Explicit types in the turbo-fish.
911916
if let Some(ref generic_args) = seg.args {
912917
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
913-
for t in data.types() {
914-
self.visit_ty(t);
918+
for arg in &data.args {
919+
match arg {
920+
ast::GenericArgAST::Type(ty) => self.visit_ty(ty),
921+
_ => {}
922+
}
915923
}
916924
}
917925
}

src/libsyntax/ast.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,28 +178,6 @@ pub struct AngleBracketedArgs {
178178
pub bindings: Vec<TypeBinding>,
179179
}
180180

181-
impl AngleBracketedArgs {
182-
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
183-
self.args.iter().filter_map(|arg| {
184-
if let GenericArgAST::Lifetime(lt) = arg {
185-
Some(lt)
186-
} else {
187-
None
188-
}
189-
})
190-
}
191-
192-
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
193-
self.args.iter().filter_map(|arg| {
194-
if let GenericArgAST::Type(ty) = arg {
195-
Some(ty)
196-
} else {
197-
None
198-
}
199-
})
200-
}
201-
}
202-
203181
impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs {
204182
fn into(self) -> Option<P<GenericArgs>> {
205183
Some(P(GenericArgs::AngleBracketed(self)))

0 commit comments

Comments
 (0)