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
468
468
parse_invalid_expression_in_let_else = a `{ $operator } ` expression cannot be directly assigned in `let...else`
469
469
parse_invalid_identifier_with_leading_number = identifiers cannot start with a number
470
470
471
- parse_invalid_label =
472
- invalid label name `{ $name } `
473
-
474
471
parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
475
472
.label = invalid suffix `{ $suffix } `
476
473
.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
500
497
parse_invalid_variable_declaration =
501
498
invalid variable declaration
502
499
500
+ parse_invalid_label = labels cannot use keyword names
501
+
503
502
parse_keyword_lifetime =
504
503
lifetimes cannot use keyword names
505
504
Original file line number Diff line number Diff line change @@ -2228,11 +2228,10 @@ pub(crate) struct KeywordLifetime {
2228
2228
}
2229
2229
2230
2230
#[ derive( Diagnostic ) ]
2231
- #[ diag( parse_invalid_label ) ]
2232
- pub ( crate ) struct InvalidLabel {
2231
+ #[ diag( parse_keyword_label ) ]
2232
+ pub ( crate ) struct KeywordLabel {
2233
2233
#[ primary_span]
2234
2234
pub span : Span ,
2235
- pub name : String ,
2236
2235
}
2237
2236
2238
2237
#[ derive( Diagnostic ) ]
Original file line number Diff line number Diff line change @@ -3094,13 +3094,7 @@ impl<'a> Parser<'a> {
3094
3094
if let Some ( ( ident, is_raw) ) = self . token . lifetime ( ) {
3095
3095
// Disallow `'fn`, but with a better error message than `expect_lifetime`.
3096
3096
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 } ) ;
3104
3098
}
3105
3099
3106
3100
self . bump ( ) ;
Original file line number Diff line number Diff line change @@ -1479,8 +1479,7 @@ impl<'a> Parser<'a> {
1479
1479
pub ( super ) fn expect_lifetime ( & mut self ) -> Lifetime {
1480
1480
if let Some ( ( ident, is_raw) ) = self . token . lifetime ( ) {
1481
1481
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 ( )
1484
1483
{
1485
1484
self . dcx ( ) . emit_err ( errors:: KeywordLifetime { span : ident. span } ) ;
1486
1485
}
Original file line number Diff line number Diff line change @@ -3045,13 +3045,17 @@ impl Ident {
3045
3045
self . name . can_be_raw ( ) && self . is_reserved ( )
3046
3046
}
3047
3047
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
+
3048
3054
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
3051
3055
let name_without_apostrophe = self . without_first_quote ( ) ;
3052
3056
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 ( )
3055
3059
}
3056
3060
3057
3061
pub fn guess_print_mode ( self ) -> IdentPrintMode {
You can’t perform that action at this time.
0 commit comments