Changed APIT with explicit generic args span to specific arg spans

This commit is contained in:
Sydney Acksman 2019-10-24 09:46:19 -05:00
parent 4a8c5b20c7
commit 4cfcb77084
4 changed files with 29 additions and 14 deletions

View File

@ -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`. /// Report error if there is an explicit type parameter when using `impl Trait`.
fn check_impl_trait( fn check_impl_trait(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
span: Span,
seg: &hir::PathSegment, seg: &hir::PathSegment,
generics: &ty::Generics, generics: &ty::Generics,
) -> bool { ) -> bool {
@ -228,14 +227,28 @@ fn check_impl_trait(
}); });
if explicit && 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::<Vec<_>>();
let mut err = struct_span_err! { let mut err = struct_span_err! {
tcx.sess, tcx.sess,
span, spans.clone(),
E0632, E0632,
"cannot provide explicit generic arguments when `impl Trait` is \ "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(); err.emit();
} }
@ -254,7 +267,7 @@ pub fn check_generic_arg_count_for_call(
let empty_args = P(hir::GenericArgs { let empty_args = P(hir::GenericArgs {
args: HirVec::new(), bindings: HirVec::new(), parenthesized: false, 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( Self::check_generic_arg_count(
tcx, tcx,
span, span,

View File

@ -1,8 +1,8 @@
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position 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::<String>('a'); LL | foo::<String>('a');
| ^^^^^^^^^^^^^ | ^^^^^^ explicit generic argument not allowed
error: aborting due to previous error error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position 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::<TestEvent, fn(TestEvent)>(|_evt| { LL | evt.handle_event::<TestEvent, fn(TestEvent)>(|_evt| {
| ^^^^^^^^^^^^ | ^^^^^^^^^ ^^^^^^^^^^^^^ explicit generic argument not allowed
| |
| explicit generic argument not allowed
error: aborting due to previous error error: aborting due to previous error

View File

@ -1,20 +1,20 @@
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position 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::<u8>(42); LL | func::<u8>(42);
| ^^^^^^^^^^ | ^^ explicit generic argument not allowed
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position 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::<u8>(42); LL | Foo::func::<u8>(42);
| ^^^^^^^^^^^^^^^ | ^^ explicit generic argument not allowed
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position 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::<i8>::func::<u8>(42); LL | Bar::<i8>::func::<u8>(42);
| ^^^^^^^^^^^^^^^^^^^^^ | ^^ explicit generic argument not allowed
error: aborting due to 3 previous errors error: aborting due to 3 previous errors