Skip to content

Commit bfbc036

Browse files
committed
More accurate span for anonymous argument suggestion
1 parent 7585cc1 commit bfbc036

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2249,11 +2249,11 @@ impl<'a> Parser<'a> {
22492249
}
22502250
_ => {
22512251
// Otherwise, try to get a type and emit a suggestion.
2252-
if let Some(ty) = pat.to_ty() {
2252+
if let Some(_) = pat.to_ty() {
22532253
err.span_suggestion_verbose(
2254-
pat.span,
2254+
pat.span.shrink_to_lo(),
22552255
"explicitly ignore the parameter name",
2256-
format!("_: {}", pprust::ty_to_string(&ty)),
2256+
"_: ".to_string(),
22572257
Applicability::MachineApplicable,
22582258
);
22592259
err.note(rfc_note);
@@ -2265,7 +2265,7 @@ impl<'a> Parser<'a> {
22652265

22662266
// `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}`
22672267
if first_param {
2268-
err.span_suggestion(
2268+
err.span_suggestion_verbose(
22692269
self_span,
22702270
"if this is a `self` type, give it a parameter name",
22712271
self_sugg,
@@ -2275,14 +2275,14 @@ impl<'a> Parser<'a> {
22752275
// Avoid suggesting that `fn foo(HashMap<u32>)` is fixed with a change to
22762276
// `fn foo(HashMap: TypeName<u32>)`.
22772277
if self.token != token::Lt {
2278-
err.span_suggestion(
2278+
err.span_suggestion_verbose(
22792279
param_span,
22802280
"if this is a parameter name, give it a type",
22812281
param_sugg,
22822282
Applicability::HasPlaceholders,
22832283
);
22842284
}
2285-
err.span_suggestion(
2285+
err.span_suggestion_verbose(
22862286
type_span,
22872287
"if this is a type, explicitly ignore the parameter name",
22882288
type_sugg,

tests/ui/anon-params/anon-params-denied-2018.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ LL | fn foo_with_qualified_path(<Bar as T>::Baz);
4848
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
4949
help: explicitly ignore the parameter name
5050
|
51-
LL - fn foo_with_qualified_path(<Bar as T>::Baz);
52-
LL + fn foo_with_qualified_path(_: <Bar as T>::Baz);
53-
|
51+
LL | fn foo_with_qualified_path(_: <Bar as T>::Baz);
52+
| ++
5453

5554
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
5655
--> $DIR/anon-params-denied-2018.rs:15:56
@@ -61,9 +60,8 @@ LL | fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz);
6160
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
6261
help: explicitly ignore the parameter name
6362
|
64-
LL - fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz);
65-
LL + fn foo_with_qualified_path_and_ref(_: &<Bar as T>::Baz);
66-
|
63+
LL | fn foo_with_qualified_path_and_ref(_: &<Bar as T>::Baz);
64+
| ++
6765

6866
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `,`
6967
--> $DIR/anon-params-denied-2018.rs:18:57
@@ -74,9 +72,8 @@ LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
7472
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
7573
help: explicitly ignore the parameter name
7674
|
77-
LL - fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
78-
LL + fn foo_with_multiple_qualified_paths(_: <Bar as T>::Baz, <Bar as T>::Baz);
79-
|
75+
LL | fn foo_with_multiple_qualified_paths(_: <Bar as T>::Baz, <Bar as T>::Baz);
76+
| ++
8077

8178
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
8279
--> $DIR/anon-params-denied-2018.rs:18:74
@@ -87,9 +84,8 @@ LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
8784
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
8885
help: explicitly ignore the parameter name
8986
|
90-
LL - fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
91-
LL + fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, _: <Bar as T>::Baz);
92-
|
87+
LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, _: <Bar as T>::Baz);
88+
| ++
9389

9490
error: expected one of `:`, `@`, or `|`, found `,`
9591
--> $DIR/anon-params-denied-2018.rs:22:36

0 commit comments

Comments
 (0)