Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,11 +2240,11 @@ impl<'a> Parser<'a> {
}
_ => {
// Otherwise, try to get a type and emit a suggestion.
if let Some(ty) = pat.to_ty() {
if let Some(_) = pat.to_ty() {
err.span_suggestion_verbose(
pat.span,
pat.span.shrink_to_lo(),
"explicitly ignore the parameter name",
format!("_: {}", pprust::ty_to_string(&ty)),
"_: ".to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"_: ".to_string(),
"_: ",

Applicability::MachineApplicable,
);
err.note(rfc_note);
Expand All @@ -2256,7 +2256,7 @@ impl<'a> Parser<'a> {

// `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}`
if first_param {
err.span_suggestion(
err.span_suggestion_verbose(
self_span,
"if this is a `self` type, give it a parameter name",
self_sugg,
Expand All @@ -2266,14 +2266,14 @@ impl<'a> Parser<'a> {
// Avoid suggesting that `fn foo(HashMap<u32>)` is fixed with a change to
// `fn foo(HashMap: TypeName<u32>)`.
if self.token != token::Lt {
err.span_suggestion(
err.span_suggestion_verbose(
param_span,
"if this is a parameter name, give it a type",
param_sugg,
Applicability::HasPlaceholders,
);
}
err.span_suggestion(
err.span_suggestion_verbose(
type_span,
"if this is a type, explicitly ignore the parameter name",
type_sugg,
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/anon-params/anon-params-denied-2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ LL | fn foo_with_qualified_path(<Bar as T>::Baz);
help: explicitly ignore the parameter name
|
LL | fn foo_with_qualified_path(_: <Bar as T>::Baz);
| ~~~~~~~~~~~~~~~~~~
| ++

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

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

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

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