diff options
| author | Hirochika Matsumoto <hirochika.k.matsumoto@gmail.com> | 2023-11-27 18:28:51 +0900 |
|---|---|---|
| committer | Hirochika Matsumoto <hirochika.k.matsumoto@gmail.com> | 2023-11-27 21:38:19 +0900 |
| commit | f4c2bdeec9d53c6a7221ebfdb2d995932dff9648 (patch) | |
| tree | 81bf624c30ae20d0decbd2d91805404b8e4c75f4 /compiler/rustc_parse/src/parser | |
| parent | b29a1e00f850e548f3021ea523d0e143724fa9b7 (diff) | |
| download | rust-f4c2bdeec9d53c6a7221ebfdb2d995932dff9648.tar.gz rust-f4c2bdeec9d53c6a7221ebfdb2d995932dff9648.zip | |
Suggest swapping the order of `ref` and `box`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 15491cac56a..8f5f4459d64 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -5,8 +5,8 @@ use crate::errors::{ ExpectedCommaAfterPatternField, GenericArgsInPatRequireTurbofishSyntax, InclusiveRangeExtraEquals, InclusiveRangeMatchArrow, InclusiveRangeNoEnd, InvalidMutInPattern, PatternOnWrongSideOfAt, RefMutOrderIncorrect, RemoveLet, RepeatedMutInPattern, - TopLevelOrPatternNotAllowed, TopLevelOrPatternNotAllowedSugg, TrailingVertNotAllowed, - UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam, + SwitchRefBoxOrder, TopLevelOrPatternNotAllowed, TopLevelOrPatternNotAllowedSugg, + TrailingVertNotAllowed, UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam, UnexpectedVertVertInPattern, }; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; @@ -374,6 +374,12 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(kw::Mut) { self.parse_pat_ident_mut(syntax_loc)? } else if self.eat_keyword(kw::Ref) { + if self.check_keyword(kw::Box) { + // Suggest `box ref` and quit parsing pattern to prevent series of + // misguided diagnostics from later stages of the compiler. + let span = self.prev_token.span.to(self.token.span); + return Err(self.sess.create_err(SwitchRefBoxOrder { span })); + } // Parse ref ident @ pat / ref mut ident @ pat let mutbl = self.parse_mutability(); self.parse_pat_ident(BindingAnnotation(ByRef::Yes, mutbl), syntax_loc)? |
