diff options
| author | r0cky <mu001999@outlook.com> | 2023-08-03 10:34:57 +0000 |
|---|---|---|
| committer | r0cky <mu001999@outlook.com> | 2023-08-03 10:34:57 +0000 |
| commit | dce7e87b1646fd5f4f7908fcd0aa1060c5189d44 (patch) | |
| tree | a6e4363e176bb98ab7628c090e3446de18cb5c5a /compiler/rustc_parse/src/parser | |
| parent | 8c8af6cf99d6a54ece11d21c15e909aef2b60552 (diff) | |
| download | rust-dce7e87b1646fd5f4f7908fcd0aa1060c5189d44.tar.gz rust-dce7e87b1646fd5f4f7908fcd0aa1060c5189d44.zip | |
Reduce arbitrary self type suggestions
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 5fa4f7902d6..00ffa7de2ff 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2019,7 +2019,7 @@ impl<'a> Parser<'a> { { 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 { PatKind::Ident(_, ident, _) => ( ident, @@ -2029,7 +2029,6 @@ impl<'a> Parser<'a> { pat.span.shrink_to_lo(), pat.span.shrink_to_hi(), pat.span.shrink_to_lo(), - true, ), // Also catches `fn foo(&a)`. PatKind::Ref(ref inner_pat, mutab) @@ -2046,22 +2045,11 @@ impl<'a> Parser<'a> { pat.span.shrink_to_lo(), pat.span, pat.span.shrink_to_lo(), - true, ) } _ => 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. 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 // `fn foo(HashMap: TypeName<u32>)`. - if self.token != token::Lt && maybe_name { + if self.token != token::Lt { err.span_suggestion( param_span, "if this is a parameter name, give it a type", |
