Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77e5bbf

Browse files
Rollup merge of #127889 - estebank:anon-arg-sugg, r=compiler-errors
More accurate span for anonymous argument suggestion Use smaller span for suggesting adding `_:` ahead of a type: ``` error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` --> $DIR/anon-params-denied-2018.rs:12:47 | LL | fn foo_with_qualified_path(<Bar as T>::Baz); | ^ expected one of 8 possible tokens | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: explicitly ignore the parameter name | LL | fn foo_with_qualified_path(_: <Bar as T>::Baz); | ++ ```
2 parents d78be31 + f6c4679 commit 77e5bbf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ LL | fn foo_with_qualified_path(<Bar as T>::Baz);
4848
help: explicitly ignore the parameter name
4949
|
5050
LL | fn foo_with_qualified_path(_: <Bar as T>::Baz);
51-
| ~~~~~~~~~~~~~~~~~~
51+
| ++
5252

5353
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
5454
--> $DIR/anon-params-denied-2018.rs:15:56
@@ -60,7 +60,7 @@ LL | fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz);
6060
help: explicitly ignore the parameter name
6161
|
6262
LL | fn foo_with_qualified_path_and_ref(_: &<Bar as T>::Baz);
63-
| ~~~~~~~~~~~~~~~~~~~
63+
| ++
6464

6565
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `,`
6666
--> $DIR/anon-params-denied-2018.rs:18:57
@@ -72,7 +72,7 @@ LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
7272
help: explicitly ignore the parameter name
7373
|
7474
LL | fn foo_with_multiple_qualified_paths(_: <Bar as T>::Baz, <Bar as T>::Baz);
75-
| ~~~~~~~~~~~~~~~~~~
75+
| ++
7676

7777
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
7878
--> $DIR/anon-params-denied-2018.rs:18:74
@@ -84,7 +84,7 @@ LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
8484
help: explicitly ignore the parameter name
8585
|
8686
LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, _: <Bar as T>::Baz);
87-
| ~~~~~~~~~~~~~~~~~~
87+
| ++
8888

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /