Remove AngleBracketedArgs impl
This commit is contained in:
parent
e1d888c722
commit
c65454850f
5 changed files with 39 additions and 40 deletions
|
@ -1754,12 +1754,16 @@ impl<'a> LoweringContext<'a> {
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
) -> (hir::GenericArgs, bool) {
|
) -> (hir::GenericArgs, bool) {
|
||||||
let &AngleBracketedArgs { ref args, ref bindings, .. } = data;
|
let &AngleBracketedArgs { ref args, ref bindings, .. } = data;
|
||||||
|
let has_types = args.iter().any(|arg| match arg {
|
||||||
|
GenericArgAST::Type(_) => true,
|
||||||
|
_ => false,
|
||||||
|
});
|
||||||
(hir::GenericArgs {
|
(hir::GenericArgs {
|
||||||
args: args.iter().map(|a| self.lower_generic_arg(a, itctx)).collect(),
|
args: args.iter().map(|a| self.lower_generic_arg(a, itctx)).collect(),
|
||||||
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
|
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
|
||||||
parenthesized: false,
|
parenthesized: false,
|
||||||
},
|
},
|
||||||
data.types().count() == 0 && param_mode == ParamMode::Optional)
|
has_types && param_mode == ParamMode::Optional)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_parenthesized_parameter_data(
|
fn lower_parenthesized_parameter_data(
|
||||||
|
|
|
@ -679,12 +679,18 @@ impl<'a> ReplaceBodyWithLoop<'a> {
|
||||||
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| {
|
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| {
|
||||||
match seg.args.as_ref().map(|generic_arg| &**generic_arg) {
|
match seg.args.as_ref().map(|generic_arg| &**generic_arg) {
|
||||||
None => false,
|
None => false,
|
||||||
Some(&ast::GenericArgs::AngleBracketed(ref data)) =>
|
Some(&ast::GenericArgs::AngleBracketed(ref data)) => {
|
||||||
any_involves_impl_trait(data.types().into_iter()) ||
|
let types = data.args.iter().filter_map(|arg| match arg {
|
||||||
any_involves_impl_trait(data.bindings.iter().map(|b| &b.ty)),
|
ast::GenericArgAST::Type(ty) => Some(ty),
|
||||||
Some(&ast::GenericArgs::Parenthesized(ref data)) =>
|
_ => None,
|
||||||
|
});
|
||||||
|
any_involves_impl_trait(types.into_iter()) ||
|
||||||
|
any_involves_impl_trait(data.bindings.iter().map(|b| &b.ty))
|
||||||
|
},
|
||||||
|
Some(&ast::GenericArgs::Parenthesized(ref data)) => {
|
||||||
any_involves_impl_trait(data.inputs.iter()) ||
|
any_involves_impl_trait(data.inputs.iter()) ||
|
||||||
any_involves_impl_trait(data.output.iter()),
|
any_involves_impl_trait(data.output.iter())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -515,21 +515,24 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> {
|
||||||
}
|
}
|
||||||
fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
|
fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
|
||||||
match *generic_args {
|
match *generic_args {
|
||||||
GenericArgs::AngleBracketed(ref generic_args) => {
|
GenericArgs::AngleBracketed(ref data) => {
|
||||||
for type_ in generic_args.types() {
|
for arg in &data.args {
|
||||||
self.visit_ty(type_);
|
match arg {
|
||||||
|
GenericArgAST::Type(ty) => self.visit_ty(ty),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for type_binding in &generic_args.bindings {
|
for type_binding in &data.bindings {
|
||||||
// Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
|
// Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
|
||||||
// are allowed to contain nested `impl Trait`.
|
// are allowed to contain nested `impl Trait`.
|
||||||
self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty));
|
self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericArgs::Parenthesized(ref generic_args) => {
|
GenericArgs::Parenthesized(ref data) => {
|
||||||
for type_ in &generic_args.inputs {
|
for type_ in &data.inputs {
|
||||||
self.visit_ty(type_);
|
self.visit_ty(type_);
|
||||||
}
|
}
|
||||||
if let Some(ref type_) = generic_args.output {
|
if let Some(ref type_) = data.output {
|
||||||
// `-> Foo` syntax is essentially an associated type binding,
|
// `-> Foo` syntax is essentially an associated type binding,
|
||||||
// so it is also allowed to contain nested `impl Trait`.
|
// so it is also allowed to contain nested `impl Trait`.
|
||||||
self.with_impl_trait(None, |this| visit::walk_ty(this, type_));
|
self.with_impl_trait(None, |this| visit::walk_ty(this, type_));
|
||||||
|
|
|
@ -825,9 +825,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
|
||||||
for seg in &path.segments {
|
for seg in &path.segments {
|
||||||
if let Some(ref generic_args) = seg.args {
|
if let Some(ref generic_args) = seg.args {
|
||||||
match **generic_args {
|
match **generic_args {
|
||||||
ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() {
|
ast::GenericArgs::AngleBracketed(ref data) => {
|
||||||
self.visit_ty(t);
|
for arg in &data.args {
|
||||||
},
|
match arg {
|
||||||
|
ast::GenericArgAST::Type(ty) => self.visit_ty(ty),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
ast::GenericArgs::Parenthesized(ref data) => {
|
ast::GenericArgs::Parenthesized(ref data) => {
|
||||||
for t in &data.inputs {
|
for t in &data.inputs {
|
||||||
self.visit_ty(t);
|
self.visit_ty(t);
|
||||||
|
@ -910,8 +915,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
|
||||||
// Explicit types in the turbo-fish.
|
// Explicit types in the turbo-fish.
|
||||||
if let Some(ref generic_args) = seg.args {
|
if let Some(ref generic_args) = seg.args {
|
||||||
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
|
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
|
||||||
for t in data.types() {
|
for arg in &data.args {
|
||||||
self.visit_ty(t);
|
match arg {
|
||||||
|
ast::GenericArgAST::Type(ty) => self.visit_ty(ty),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,28 +178,6 @@ pub struct AngleBracketedArgs {
|
||||||
pub bindings: Vec<TypeBinding>,
|
pub bindings: Vec<TypeBinding>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AngleBracketedArgs {
|
|
||||||
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
|
|
||||||
self.args.iter().filter_map(|arg| {
|
|
||||||
if let GenericArgAST::Lifetime(lt) = arg {
|
|
||||||
Some(lt)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
|
|
||||||
self.args.iter().filter_map(|arg| {
|
|
||||||
if let GenericArgAST::Type(ty) = arg {
|
|
||||||
Some(ty)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs {
|
impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs {
|
||||||
fn into(self) -> Option<P<GenericArgs>> {
|
fn into(self) -> Option<P<GenericArgs>> {
|
||||||
Some(P(GenericArgs::AngleBracketed(self)))
|
Some(P(GenericArgs::AngleBracketed(self)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue