@@ -5,8 +5,8 @@ use crate::errors::{
55 ExpectedCommaAfterPatternField , GenericArgsInPatRequireTurbofishSyntax ,
66 InclusiveRangeExtraEquals , InclusiveRangeMatchArrow , InclusiveRangeNoEnd , InvalidMutInPattern ,
77 PatternOnWrongSideOfAt , RefMutOrderIncorrect , RemoveLet , RepeatedMutInPattern ,
8- TopLevelOrPatternNotAllowed , TopLevelOrPatternNotAllowedSugg , TrailingVertNotAllowed ,
9- UnexpectedLifetimeInPattern , UnexpectedVertVertBeforeFunctionParam ,
8+ SwitchRefBoxOrder , TopLevelOrPatternNotAllowed , TopLevelOrPatternNotAllowedSugg ,
9+ TrailingVertNotAllowed , UnexpectedLifetimeInPattern , UnexpectedVertVertBeforeFunctionParam ,
1010 UnexpectedVertVertInPattern ,
1111} ;
1212use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole} ;
@@ -374,6 +374,12 @@ impl<'a> Parser<'a> {
374374 } else if self . eat_keyword ( kw:: Mut ) {
375375 self . parse_pat_ident_mut ( syntax_loc) ?
376376 } else if self . eat_keyword ( kw:: Ref ) {
377+ if self . check_keyword ( kw:: Box ) {
378+ // Suggest `box ref` and quit parsing pattern to prevent series of
379+ // misguided diagnostics from later stages of the compiler.
380+ let span = self . prev_token . span . to ( self . token . span ) ;
381+ return Err ( self . sess . create_err ( SwitchRefBoxOrder { span } ) ) ;
382+ }
377383 // Parse ref ident @ pat / ref mut ident @ pat
378384 let mutbl = self . parse_mutability ( ) ;
379385 self . parse_pat_ident ( BindingAnnotation ( ByRef :: Yes , mutbl) , syntax_loc) ?
0 commit comments