diff options
| author | bors <bors@rust-lang.org> | 2019-10-03 02:08:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-10-03 02:08:53 +0000 |
| commit | c6293e359848c8c7275330719b33ccd168df04c3 (patch) | |
| tree | e57fb077f12e3c6f5e1991e93a873d361a814ea9 /src/libsyntax/parse | |
| parent | 2daa404e9a151a2e8262cbd6d8c209fd067aca16 (diff) | |
| parent | d5a0765f44069d3f56bb91e7b5ba09514f2acffb (diff) | |
| download | rust-c6293e359848c8c7275330719b33ccd168df04c3.tar.gz rust-c6293e359848c8c7275330719b33ccd168df04c3.zip | |
Auto merge of #65038 - Centril:rollup-m83dpfh, r=Centril
Rollup of 7 pull requests Successful merges: - #63678 (Improve HRTB error span when -Zno-leak-check is used) - #64931 (Reword E0392 slightly) - #64959 (syntax: improve parameter without type suggestions) - #64975 (Implement Clone::clone_from for LinkedList) - #64993 (BacktraceStatus: add Eq impl) - #64998 (Filter out RLS output directories on tidy runs) - #65010 (Compare `primary` with maximum of `children`s' line num instead of dropping it) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/diagnostics.rs | 32 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 1 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index e8d7b7663ed..4ad0bd06d99 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -1220,6 +1220,7 @@ impl<'a> Parser<'a> { err: &mut DiagnosticBuilder<'_>, pat: P<ast::Pat>, require_name: bool, + is_self_allowed: bool, is_trait_item: bool, ) -> Option<Ident> { // If we find a pattern followed by an identifier, it could be an (incorrect) @@ -1241,14 +1242,27 @@ impl<'a> Parser<'a> { if require_name && ( is_trait_item || self.token == token::Comma || + self.token == token::Lt || self.token == token::CloseDelim(token::Paren) - ) { // `fn foo(a, b) {}` or `fn foo(usize, usize) {}` - err.span_suggestion( - pat.span, - "if this was a parameter name, give it a type", - format!("{}: TypeName", ident), - Applicability::HasPlaceholders, - ); + ) { // `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}` + if is_self_allowed { + err.span_suggestion( + pat.span, + "if this is a `self` type, give it a parameter name", + format!("self: {}", ident), + Applicability::MaybeIncorrect, + ); + } + // 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( + pat.span, + "if this was a parameter name, give it a type", + format!("{}: TypeName", ident), + Applicability::HasPlaceholders, + ); + } err.span_suggestion( pat.span, "if this is a type, explicitly ignore the parameter name", @@ -1256,7 +1270,9 @@ impl<'a> Parser<'a> { Applicability::MachineApplicable, ); err.note("anonymous parameters are removed in the 2018 edition (see RFC 1685)"); - return Some(ident); + + // Don't attempt to recover by using the `X` in `X<Y>` as the parameter name. + return if self.token == token::Lt { None } else { Some(ident) }; } } None diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 95f84d5cb33..d4a6e9f6c6b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1212,6 +1212,7 @@ impl<'a> Parser<'a> { &mut err, pat, is_name_required, + is_self_allowed, is_trait_item, ) { err.emit(); |
