Skip to content

Commit

Permalink
Rollup merge of #65763 - ObsidianMinor:diag/65642, r=varkor
Browse files Browse the repository at this point in the history
Changed APIT with explicit generic args span to specific arg spans

Fixes #65642.
  • Loading branch information
Centril authored Oct 25, 2019
2 parents 8b9661b + 4cfcb77 commit 2b7cc64
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
21 changes: 17 additions & 4 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// 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 {
Expand All @@ -228,14 +227,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
});

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! {
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();
}

Expand All @@ -254,7 +267,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/impl-trait/issues/universal-issue-48703.stderr
Original file line number Diff line number Diff line change
@@ -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::<String>('a');
| ^^^^^^^^^^^^^
| ^^^^^^ explicit generic argument not allowed

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -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::<TestEvent, fn(TestEvent)>(|_evt| {
| ^^^^^^^^^^^^
| ^^^^^^^^^ ^^^^^^^^^^^^^ explicit generic argument not allowed
| |
| explicit generic argument not allowed

error: aborting due to previous error

12 changes: 6 additions & 6 deletions src/test/ui/synthetic-param.stderr
Original file line number Diff line number Diff line change
@@ -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::<u8>(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::<u8>(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::<i8>::func::<u8>(42);
| ^^^^^^^^^^^^^^^^^^^^^
| ^^ explicit generic argument not allowed

error: aborting due to 3 previous errors

0 comments on commit 2b7cc64

Please sign in to comment.