@@ -798,18 +798,19 @@ impl<'a> Parser<'a> {
798798 let mut err = self . struct_span_err ( self . span ,
799799 & format ! ( "expected identifier, found {}" ,
800800 self . this_token_descr( ) ) ) ;
801- if let ( true , token:: Ident ( ref s, false ) , true ) = (
802- self . span . rust_2018 ( ) ,
803- & self . token ,
804- self . token . is_used_keyword ( ) || self . token . is_unused_keyword ( ) ,
805- ) {
806- err. span_suggestion_with_applicability (
807- self . span ,
808- "you can escape reserved keywords to use them as identifiers" ,
809- format ! ( "r#{}" , s. to_string( ) ) ,
810- Applicability :: MaybeIncorrect ,
811- ) ;
812- } else if let Some ( token_descr) = self . token_descr ( ) {
801+ if let token:: Ident ( ident, false ) = & self . token {
802+ if ident. is_reserved ( ) && !ident. is_path_segment_keyword ( ) &&
803+ ident. name != keywords:: Underscore . name ( )
804+ {
805+ err. span_suggestion_with_applicability (
806+ self . span ,
807+ "you can escape reserved keywords to use them as identifiers" ,
808+ format ! ( "r#{}" , ident) ,
809+ Applicability :: MaybeIncorrect ,
810+ ) ;
811+ }
812+ }
813+ if let Some ( token_descr) = self . token_descr ( ) {
813814 err. span_label ( self . span , format ! ( "expected identifier, found {}" , token_descr) ) ;
814815 } else {
815816 err. span_label ( self . span , "expected identifier" ) ;
0 commit comments