diff options
| author | Chris Simpkins <git.simpkins@gmail.com> | 2020-05-27 14:09:54 -0400 |
|---|---|---|
| committer | Chris Simpkins <git.simpkins@gmail.com> | 2020-05-27 14:10:41 -0400 |
| commit | 593d1eed8216c4ab33500b323fbd1b3de4ecb34d (patch) | |
| tree | a94f52110b0575b30aa85e77351d1b11ec194c38 /src/librustc_parse | |
| parent | acfc5584018de3a9a431a17f0cc34e0bfaf4cdeb (diff) | |
| download | rust-593d1eed8216c4ab33500b323fbd1b3de4ecb34d.tar.gz rust-593d1eed8216c4ab33500b323fbd1b3de4ecb34d.zip | |
improve diagnostics suggestion for missing `@` in slice id binding to rest pattern
add issue 72373 tests fmt test fix suggestion format Replacement, not insertion of suggested string implement review changes refactor to span_suggestion_verbose, improve suggestion message, change id @ pattern space formatting fmt fix diagnostics spacing between ident and @ refactor reference
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/parser/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index b21524cb9bd..c00b6084829 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -672,6 +672,26 @@ impl<'a> Parser<'a> { } } + // If this was a missing `@` in a binding pattern + // bail with a suggestion + // https://github.com/rust-lang/rust/issues/72373 + if self.prev_token.is_ident() && &self.token.kind == &token::DotDot { + let msg = format!( + "if you meant to bind the contents of \ + the rest of the array pattern into `{}`, use `@`", + pprust::token_to_string(&self.prev_token) + ); + expect_err + .span_suggestion_verbose( + self.prev_token.span.shrink_to_hi().until(self.token.span), + &msg, + " @ ".to_string(), + Applicability::MaybeIncorrect, + ) + .emit(); + break; + } + // Attempt to keep parsing if it was an omitted separator. match f(self) { Ok(t) => { |
