@@ -138,19 +138,7 @@ impl<'a> Parser<'a> {
138
138
self . parse_item_const ( Some ( m) ) ?
139
139
} else if let Const :: Yes ( const_span) = self . parse_constness ( ) {
140
140
// CONST ITEM
141
- if self . eat_keyword ( kw:: Mut ) {
142
- let prev_span = self . prev_span ;
143
- self . struct_span_err ( prev_span, "const globals cannot be mutable" )
144
- . span_label ( prev_span, "cannot be mutable" )
145
- . span_suggestion (
146
- const_span,
147
- "you might want to declare a static instead" ,
148
- "static" . to_owned ( ) ,
149
- Applicability :: MaybeIncorrect ,
150
- )
151
- . emit ( ) ;
152
- }
153
-
141
+ self . recover_const_mut ( const_span) ;
154
142
self . parse_item_const ( None ) ?
155
143
} else if self . check_keyword ( kw:: Trait ) || self . check_auto_or_unsafe_trait_item ( ) {
156
144
// TRAIT ITEM
@@ -987,6 +975,22 @@ impl<'a> Parser<'a> {
987
975
}
988
976
}
989
977
978
+ /// Recover on `const mut` with `const` already eaten.
979
+ fn recover_const_mut ( & mut self , const_span : Span ) {
980
+ if self . eat_keyword ( kw:: Mut ) {
981
+ let span = self . prev_span ;
982
+ self . struct_span_err ( span, "const globals cannot be mutable" )
983
+ . span_label ( span, "cannot be mutable" )
984
+ . span_suggestion (
985
+ const_span,
986
+ "you might want to declare a static instead" ,
987
+ "static" . to_owned ( ) ,
988
+ Applicability :: MaybeIncorrect ,
989
+ )
990
+ . emit ( ) ;
991
+ }
992
+ }
993
+
990
994
/// Parse `["const" | ("static" "mut"?)] $ident ":" $ty = $expr` with
991
995
/// `["const" | ("static" "mut"?)]` already parsed and stored in `m`.
992
996
///
0 commit comments