@@ -294,15 +294,36 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
294294 let prefix_span = self . mk_sp ( start, ident_start) ;
295295
296296 if prefix_span. at_least_rust_2021 ( ) {
297+ // If the raw lifetime is followed by \' then treat it just like we do with
298+ if self . cursor . as_str ( ) . starts_with ( '\'' ) {
299+ let lit_span = self . mk_sp ( start, self . pos + BytePos ( 1 ) ) ;
300+ let contents = self . str_from_to ( start + BytePos ( 1 ) , self . pos ) ;
301+ emit_unescape_error (
302+ self . dcx ( ) ,
303+ contents,
304+ lit_span,
305+ lit_span,
306+ Mode :: Char ,
307+ 0 ..contents. len ( ) ,
308+ EscapeError :: MoreThanOneChar ,
309+ )
310+ . expect ( "expected error" ) ;
311+ }
312+
297313 let span = self . mk_sp ( start, self . pos ) ;
298314
299- let lifetime_name_without_tick = Symbol :: intern ( & self . str_from ( ident_start) ) ;
315+ let lifetime_name_without_tick =
316+ Symbol :: intern ( & self . str_from ( ident_start) ) ;
300317 if !lifetime_name_without_tick. can_be_raw ( ) {
301- self . dcx ( ) . emit_err ( errors:: CannotBeRawLifetime { span, ident : lifetime_name_without_tick } ) ;
318+ self . dcx ( ) . emit_err ( errors:: CannotBeRawLifetime {
319+ span,
320+ ident : lifetime_name_without_tick,
321+ } ) ;
302322 }
303323
304324 // Put the `'` back onto the lifetime name.
305- let mut lifetime_name = String :: with_capacity ( lifetime_name_without_tick. as_str ( ) . len ( ) + 1 ) ;
325+ let mut lifetime_name =
326+ String :: with_capacity ( lifetime_name_without_tick. as_str ( ) . len ( ) + 1 ) ;
306327 lifetime_name. push ( '\'' ) ;
307328 lifetime_name += lifetime_name_without_tick. as_str ( ) ;
308329 let sym = Symbol :: intern ( & lifetime_name) ;
@@ -358,8 +379,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
358379 rustc_lexer:: TokenKind :: Caret => token:: BinOp ( token:: Caret ) ,
359380 rustc_lexer:: TokenKind :: Percent => token:: BinOp ( token:: Percent ) ,
360381
361- rustc_lexer:: TokenKind :: Unknown
362- | rustc_lexer:: TokenKind :: InvalidIdent => {
382+ rustc_lexer:: TokenKind :: Unknown | rustc_lexer:: TokenKind :: InvalidIdent => {
363383 // Don't emit diagnostics for sequences of the same invalid token
364384 if swallow_next_invalid > 0 {
365385 swallow_next_invalid -= 1 ;
0 commit comments