From 4cfcb770844333a6c7e1ebddc8d30770098bdfd7 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Thu, 24 Oct 2019 09:46:19 -0500 Subject: [PATCH] Changed APIT with explicit generic args span to specific arg spans --- src/librustc_typeck/astconv.rs | 21 +++++++++++++++---- .../issues/universal-issue-48703.stderr | 4 ++-- ...sal-turbofish-in-method-issue-50950.stderr | 6 ++++-- src/test/ui/synthetic-param.stderr | 12 +++++------ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a052ad95ed5..97f7c6a2c8a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -215,7 +215,6 @@ pub fn ast_path_substs_for_ty(&self, /// Report error if there is an explicit type parameter when using `impl Trait`. fn check_impl_trait( tcx: TyCtxt<'_>, - span: Span, seg: &hir::PathSegment, generics: &ty::Generics, ) -> bool { @@ -228,14 +227,28 @@ fn check_impl_trait( }); if explicit && impl_trait { + let spans = + seg.generic_args().args + .iter() + .filter_map(|arg| + match arg { + GenericArg::Type(_) => Some(arg.span()), + _ => None + }) + .collect::>(); + let mut err = struct_span_err! { tcx.sess, - span, + spans.clone(), E0632, "cannot provide explicit generic arguments when `impl Trait` is \ - used in argument position" + used in argument position" }; + for span in spans { + err.span_label(span, "explicit generic argument not allowed"); + } + err.emit(); } @@ -254,7 +267,7 @@ pub fn check_generic_arg_count_for_call( let empty_args = P(hir::GenericArgs { args: HirVec::new(), bindings: HirVec::new(), parenthesized: false, }); - let suppress_mismatch = Self::check_impl_trait(tcx, span, seg, &def); + let suppress_mismatch = Self::check_impl_trait(tcx, seg, &def); Self::check_generic_arg_count( tcx, span, diff --git a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr index a51302dce29..8f05ab3c494 100644 --- a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr +++ b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr @@ -1,8 +1,8 @@ error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/universal-issue-48703.rs:8:5 + --> $DIR/universal-issue-48703.rs:8:11 | LL | foo::('a'); - | ^^^^^^^^^^^^^ + | ^^^^^^ explicit generic argument not allowed error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr index f09aa166ef5..c980e9463e4 100644 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr +++ b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr @@ -1,8 +1,10 @@ error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/universal-turbofish-in-method-issue-50950.rs:14:9 + --> $DIR/universal-turbofish-in-method-issue-50950.rs:14:24 | LL | evt.handle_event::(|_evt| { - | ^^^^^^^^^^^^ + | ^^^^^^^^^ ^^^^^^^^^^^^^ explicit generic argument not allowed + | | + | explicit generic argument not allowed error: aborting due to previous error diff --git a/src/test/ui/synthetic-param.stderr b/src/test/ui/synthetic-param.stderr index f8d14f26f32..951d7edb7f5 100644 --- a/src/test/ui/synthetic-param.stderr +++ b/src/test/ui/synthetic-param.stderr @@ -1,20 +1,20 @@ error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/synthetic-param.rs:20:5 + --> $DIR/synthetic-param.rs:20:12 | LL | func::(42); - | ^^^^^^^^^^ + | ^^ explicit generic argument not allowed error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/synthetic-param.rs:23:5 + --> $DIR/synthetic-param.rs:23:17 | LL | Foo::func::(42); - | ^^^^^^^^^^^^^^^ + | ^^ explicit generic argument not allowed error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/synthetic-param.rs:26:5 + --> $DIR/synthetic-param.rs:26:23 | LL | Bar::::func::(42); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^ explicit generic argument not allowed error: aborting due to 3 previous errors