Skip to content

Commit 2b7cc64

Browse files
authored
Rollup merge of #65763 - ObsidianMinor:diag/65642, r=varkor
Changed APIT with explicit generic args span to specific arg spans Fixes #65642.
2 parents 8b9661b + 4cfcb77 commit 2b7cc64

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

src/librustc_typeck/astconv.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
215215
/// Report error if there is an explicit type parameter when using `impl Trait`.
216216
fn check_impl_trait(
217217
tcx: TyCtxt<'_>,
218-
span: Span,
219218
seg: &hir::PathSegment,
220219
generics: &ty::Generics,
221220
) -> bool {
@@ -228,14 +227,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
228227
});
229228

230229
if explicit && impl_trait {
230+
let spans =
231+
seg.generic_args().args
232+
.iter()
233+
.filter_map(|arg|
234+
match arg {
235+
GenericArg::Type(_) => Some(arg.span()),
236+
_ => None
237+
})
238+
.collect::<Vec<_>>();
239+
231240
let mut err = struct_span_err! {
232241
tcx.sess,
233-
span,
242+
spans.clone(),
234243
E0632,
235244
"cannot provide explicit generic arguments when `impl Trait` is \
236-
used in argument position"
245+
used in argument position"
237246
};
238247

248+
for span in spans {
249+
err.span_label(span, "explicit generic argument not allowed");
250+
}
251+
239252
err.emit();
240253
}
241254

@@ -254,7 +267,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
254267
let empty_args = P(hir::GenericArgs {
255268
args: HirVec::new(), bindings: HirVec::new(), parenthesized: false,
256269
});
257-
let suppress_mismatch = Self::check_impl_trait(tcx, span, seg, &def);
270+
let suppress_mismatch = Self::check_impl_trait(tcx, seg, &def);
258271
Self::check_generic_arg_count(
259272
tcx,
260273
span,
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
2-
--> $DIR/universal-issue-48703.rs:8:5
2+
--> $DIR/universal-issue-48703.rs:8:11
33
|
44
LL | foo::<String>('a');
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^ explicit generic argument not allowed
66

77
error: aborting due to previous error
88

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
2-
--> $DIR/universal-turbofish-in-method-issue-50950.rs:14:9
2+
--> $DIR/universal-turbofish-in-method-issue-50950.rs:14:24
33
|
44
LL | evt.handle_event::<TestEvent, fn(TestEvent)>(|_evt| {
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^^^^ ^^^^^^^^^^^^^ explicit generic argument not allowed
6+
| |
7+
| explicit generic argument not allowed
68

79
error: aborting due to previous error
810

src/test/ui/synthetic-param.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
2-
--> $DIR/synthetic-param.rs:20:5
2+
--> $DIR/synthetic-param.rs:20:12
33
|
44
LL | func::<u8>(42);
5-
| ^^^^^^^^^^
5+
| ^^ explicit generic argument not allowed
66

77
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
8-
--> $DIR/synthetic-param.rs:23:5
8+
--> $DIR/synthetic-param.rs:23:17
99
|
1010
LL | Foo::func::<u8>(42);
11-
| ^^^^^^^^^^^^^^^
11+
| ^^ explicit generic argument not allowed
1212

1313
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
14-
--> $DIR/synthetic-param.rs:26:5
14+
--> $DIR/synthetic-param.rs:26:23
1515
|
1616
LL | Bar::<i8>::func::<u8>(42);
17-
| ^^^^^^^^^^^^^^^^^^^^^
17+
| ^^ explicit generic argument not allowed
1818

1919
error: aborting due to 3 previous errors
2020

0 commit comments

Comments
 (0)