File tree Expand file tree Collapse file tree 5 files changed +14
-19
lines changed Expand file tree Collapse file tree 5 files changed +14
-19
lines changed Original file line number Diff line number Diff line change @@ -468,9 +468,6 @@ parse_invalid_dyn_keyword = invalid `dyn` keyword
468468parse_invalid_expression_in_let_else = a `{ $operator } ` expression cannot be directly assigned in `let...else`
469469parse_invalid_identifier_with_leading_number = identifiers cannot start with a number
470470
471- parse_invalid_label =
472- invalid label name `{ $name } `
473-
474471parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
475472 .label = invalid suffix `{ $suffix } `
476473 .tuple_exception_line_1 = `{ $suffix } ` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
@@ -500,6 +497,8 @@ parse_invalid_unicode_escape = invalid unicode character escape
500497parse_invalid_variable_declaration =
501498 invalid variable declaration
502499
500+ parse_invalid_label = labels cannot use keyword names
501+
503502parse_keyword_lifetime =
504503 lifetimes cannot use keyword names
505504
Original file line number Diff line number Diff line change @@ -2228,11 +2228,10 @@ pub(crate) struct KeywordLifetime {
22282228}
22292229
22302230#[ derive( Diagnostic ) ]
2231- #[ diag( parse_invalid_label ) ]
2232- pub ( crate ) struct InvalidLabel {
2231+ #[ diag( parse_keyword_label ) ]
2232+ pub ( crate ) struct KeywordLabel {
22332233 #[ primary_span]
22342234 pub span : Span ,
2235- pub name : String ,
22362235}
22372236
22382237#[ derive( Diagnostic ) ]
Original file line number Diff line number Diff line change @@ -3094,13 +3094,7 @@ impl<'a> Parser<'a> {
30943094 if let Some ( ( ident, is_raw) ) = self . token . lifetime ( ) {
30953095 // Disallow `'fn`, but with a better error message than `expect_lifetime`.
30963096 if matches ! ( is_raw, IdentIsRaw :: No ) && ident. without_first_quote ( ) . is_reserved ( ) {
3097- self . dcx ( ) . emit_err ( errors:: InvalidLabel {
3098- span : ident. span ,
3099- // `IntoDiagArg` prints the symbol as if it was an ident,
3100- // so `'break` is printed as `r#break`. We don't want that
3101- // here so convert to string eagerly.
3102- name : ident. without_first_quote ( ) . name . to_string ( ) ,
3103- } ) ;
3097+ self . dcx ( ) . emit_err ( errors:: KeywordLabel { span : ident. span } ) ;
31043098 }
31053099
31063100 self . bump ( ) ;
Original file line number Diff line number Diff line change @@ -1479,8 +1479,7 @@ impl<'a> Parser<'a> {
14791479 pub ( super ) fn expect_lifetime ( & mut self ) -> Lifetime {
14801480 if let Some ( ( ident, is_raw) ) = self . token . lifetime ( ) {
14811481 if matches ! ( is_raw, IdentIsRaw :: No )
1482- && ident. without_first_quote ( ) . is_reserved ( )
1483- && ![ kw:: UnderscoreLifetime , kw:: StaticLifetime ] . contains ( & ident. name )
1482+ && ident. without_first_quote ( ) . is_reserved_lifetime ( )
14841483 {
14851484 self . dcx ( ) . emit_err ( errors:: KeywordLifetime { span : ident. span } ) ;
14861485 }
Original file line number Diff line number Diff line change @@ -3045,13 +3045,17 @@ impl Ident {
30453045 self . name . can_be_raw ( ) && self . is_reserved ( )
30463046 }
30473047
3048+ /// Given the name of a lifetime without the first quote (`'`),
3049+ /// returns whether the lifetime name is reserved (therefore invalid)
3050+ pub fn is_reserved_lifetime ( self ) -> bool {
3051+ self . is_reserved ( ) && ![ kw:: Underscore , kw:: Static ] . contains ( & self . name )
3052+ }
3053+
30483054 pub fn is_raw_lifetime_guess ( self ) -> bool {
3049- // this should be kept consistent with `Parser::expect_lifetime` found under
3050- // compiler/rustc_parse/src/parser/ty.rs
30513055 let name_without_apostrophe = self . without_first_quote ( ) ;
30523056 name_without_apostrophe. name != self . name
3053- && ! [ kw :: UnderscoreLifetime , kw :: StaticLifetime ] . contains ( & self . name )
3054- && name_without_apostrophe. is_raw_guess ( )
3057+ && name_without_apostrophe . name . can_be_raw ( )
3058+ && name_without_apostrophe. is_reserved_lifetime ( )
30553059 }
30563060
30573061 pub fn guess_print_mode ( self ) -> IdentPrintMode {
You can’t perform that action at this time.
0 commit comments