mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
Reduce arbitrary self type suggestions
This commit is contained in:
parent
8c8af6cf99
commit
dce7e87b16
@ -2019,7 +2019,7 @@ impl<'a> Parser<'a> {
|
|||||||
{
|
{
|
||||||
let rfc_note = "anonymous parameters are removed in the 2018 edition (see RFC 1685)";
|
let rfc_note = "anonymous parameters are removed in the 2018 edition (see RFC 1685)";
|
||||||
|
|
||||||
let (ident, self_sugg, param_sugg, type_sugg, self_span, param_span, type_span, maybe_name) =
|
let (ident, self_sugg, param_sugg, type_sugg, self_span, param_span, type_span) =
|
||||||
match pat.kind {
|
match pat.kind {
|
||||||
PatKind::Ident(_, ident, _) => (
|
PatKind::Ident(_, ident, _) => (
|
||||||
ident,
|
ident,
|
||||||
@ -2029,7 +2029,6 @@ impl<'a> Parser<'a> {
|
|||||||
pat.span.shrink_to_lo(),
|
pat.span.shrink_to_lo(),
|
||||||
pat.span.shrink_to_hi(),
|
pat.span.shrink_to_hi(),
|
||||||
pat.span.shrink_to_lo(),
|
pat.span.shrink_to_lo(),
|
||||||
true,
|
|
||||||
),
|
),
|
||||||
// Also catches `fn foo(&a)`.
|
// Also catches `fn foo(&a)`.
|
||||||
PatKind::Ref(ref inner_pat, mutab)
|
PatKind::Ref(ref inner_pat, mutab)
|
||||||
@ -2046,22 +2045,11 @@ impl<'a> Parser<'a> {
|
|||||||
pat.span.shrink_to_lo(),
|
pat.span.shrink_to_lo(),
|
||||||
pat.span,
|
pat.span,
|
||||||
pat.span.shrink_to_lo(),
|
pat.span.shrink_to_lo(),
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
PatKind::Path(_, ref path) if let Some(segment) = path.segments.last() => (
|
|
||||||
segment.ident,
|
|
||||||
"self: ",
|
|
||||||
": TypeName".to_string(),
|
|
||||||
"_: ",
|
|
||||||
pat.span.shrink_to_lo(),
|
|
||||||
pat.span.shrink_to_hi(),
|
|
||||||
pat.span.shrink_to_lo(),
|
|
||||||
path.segments.len() == 1, // Avoid suggesting that `fn foo(a::b)` is fixed with a change to `fn foo(a::b: TypeName)`.
|
|
||||||
),
|
|
||||||
_ => {
|
_ => {
|
||||||
// Otherwise, try to get a type and emit a suggestion.
|
// Otherwise, try to get a type and emit a suggestion.
|
||||||
if let Some(ty) = pat.to_ty() {
|
if let Some(ty) = pat.to_ty() {
|
||||||
@ -2089,7 +2077,7 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
// Avoid suggesting that `fn foo(HashMap<u32>)` is fixed with a change to
|
// Avoid suggesting that `fn foo(HashMap<u32>)` is fixed with a change to
|
||||||
// `fn foo(HashMap: TypeName<u32>)`.
|
// `fn foo(HashMap: TypeName<u32>)`.
|
||||||
if self.token != token::Lt && maybe_name {
|
if self.token != token::Lt {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
param_span,
|
param_span,
|
||||||
"if this is a parameter name, give it a type",
|
"if this is a parameter name, give it a type",
|
||||||
|
@ -45,14 +45,10 @@ LL | fn foo_with_qualified_path(<Bar as T>::Baz);
|
|||||||
| ^ expected one of 8 possible tokens
|
| ^ expected one of 8 possible tokens
|
||||||
|
|
|
|
||||||
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
||||||
help: if this is a `self` type, give it a parameter name
|
help: explicitly ignore the parameter name
|
||||||
|
|
|
||||||
LL | fn foo_with_qualified_path(self: <Bar as T>::Baz);
|
|
||||||
| +++++
|
|
||||||
help: if this is a type, explicitly ignore the parameter name
|
|
||||||
|
|
|
|
||||||
LL | fn foo_with_qualified_path(_: <Bar as T>::Baz);
|
LL | fn foo_with_qualified_path(_: <Bar as T>::Baz);
|
||||||
| ++
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
|
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
|
||||||
--> $DIR/anon-params-denied-2018.rs:15:56
|
--> $DIR/anon-params-denied-2018.rs:15:56
|
||||||
@ -73,14 +69,10 @@ LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
|
|||||||
| ^ expected one of 8 possible tokens
|
| ^ expected one of 8 possible tokens
|
||||||
|
|
|
|
||||||
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
||||||
help: if this is a `self` type, give it a parameter name
|
help: explicitly ignore the parameter name
|
||||||
|
|
|
||||||
LL | fn foo_with_multiple_qualified_paths(self: <Bar as T>::Baz, <Bar as T>::Baz);
|
|
||||||
| +++++
|
|
||||||
help: if this is a type, explicitly ignore the parameter name
|
|
||||||
|
|
|
|
||||||
LL | fn foo_with_multiple_qualified_paths(_: <Bar as T>::Baz, <Bar as T>::Baz);
|
LL | fn foo_with_multiple_qualified_paths(_: <Bar as T>::Baz, <Bar as T>::Baz);
|
||||||
| ++
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
|
error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
|
||||||
--> $DIR/anon-params-denied-2018.rs:18:74
|
--> $DIR/anon-params-denied-2018.rs:18:74
|
||||||
@ -89,10 +81,10 @@ LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz);
|
|||||||
| ^ expected one of 8 possible tokens
|
| ^ expected one of 8 possible tokens
|
||||||
|
|
|
|
||||||
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
||||||
help: if this is a type, explicitly ignore the parameter name
|
help: explicitly ignore the parameter name
|
||||||
|
|
|
|
||||||
LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, _: <Bar as T>::Baz);
|
LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, _: <Bar as T>::Baz);
|
||||||
| ++
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: expected one of `:`, `@`, or `|`, found `,`
|
error: expected one of `:`, `@`, or `|`, found `,`
|
||||||
--> $DIR/anon-params-denied-2018.rs:22:36
|
--> $DIR/anon-params-denied-2018.rs:22:36
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
// This test checks that a suggestion to add a `self: ` parameter name is provided
|
// This test checks that a suggestion to add a `self: ` parameter name is provided
|
||||||
// to functions where this is applicable.
|
// to functions where this is applicable.
|
||||||
|
|
||||||
pub fn foo(Box<Self>) { } //~ ERROR expected one of
|
pub fn foo(Box<Self>) { }
|
||||||
|
//~^ ERROR expected one of `:`, `@`, or `|`, found `<`
|
||||||
|
|
||||||
struct Bar;
|
struct Bar;
|
||||||
|
|
||||||
impl Bar {
|
impl Bar {
|
||||||
fn bar(Box<Self>) { } //~ ERROR expected one of
|
fn bar(Box<Self>) { }
|
||||||
|
//~^ ERROR expected one of `:`, `@`, or `|`, found `<`
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
@ -15,7 +15,7 @@ LL | pub fn foo(_: Box<Self>) { }
|
|||||||
| ++
|
| ++
|
||||||
|
|
||||||
error: expected one of `:`, `@`, or `|`, found `<`
|
error: expected one of `:`, `@`, or `|`, found `<`
|
||||||
--> $DIR/issue-64252-self-type.rs:8:15
|
--> $DIR/issue-64252-self-type.rs:10:15
|
||||||
|
|
|
|
||||||
LL | fn bar(Box<Self>) { }
|
LL | fn bar(Box<Self>) { }
|
||||||
| ^ expected one of `:`, `@`, or `|`
|
| ^ expected one of `:`, `@`, or `|`
|
||||||
|
Loading…
Reference in New Issue
Block a user