Skip to content

Commit f072221

Browse files
committed
More accurate span for anonymous argument suggestion
1 parent b936db7 commit f072221

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,11 +2240,11 @@ impl<'a> Parser<'a> {
22402240
}
22412241
_ => {
22422242
// Otherwise, try to get a type and emit a suggestion.
2243-
if let Some(ty) = pat.to_ty() {
2243+
if let Some(_) = pat.to_ty() {
22442244
err.span_suggestion_verbose(
2245-
pat.span,
2245+
pat.span.shrink_to_lo(),
22462246
"explicitly ignore the parameter name",
2247-
format!("_: {}", pprust::ty_to_string(&ty)),
2247+
"_: ".to_string(),
22482248
Applicability::MachineApplicable,
22492249
);
22502250
err.note(rfc_note);
@@ -2256,7 +2256,7 @@ impl<'a> Parser<'a> {
22562256

22572257
// `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}`
22582258
if first_param {
2259-
err.span_suggestion(
2259+
err.span_suggestion_verbose(
22602260
self_span,
22612261
"if this is a `self` type, give it a parameter name",
22622262
self_sugg,
@@ -2266,14 +2266,14 @@ impl<'a> Parser<'a> {
22662266
// Avoid suggesting that `fn foo(HashMap<u32>)` is fixed with a change to
22672267
// `fn foo(HashMap: TypeName<u32>)`.
22682268
if self.token != token::Lt {
2269-
err.span_suggestion(
2269+
err.span_suggestion_verbose(
22702270
param_span,
22712271
"if this is a parameter name, give it a type",
22722272
param_sugg,
22732273
Applicability::HasPlaceholders,
22742274
);
22752275
}
2276-
err.span_suggestion(
2276+
err.span_suggestion_verbose(
22772277
type_span,
22782278
"if this is a type, explicitly ignore the parameter name",
22792279
type_sugg,

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

Lines changed: 8 additions & 12 deletions
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)