@@ -300,17 +300,35 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
300
300
let prefix_span = self . mk_sp ( start, ident_start) ;
301
301
302
302
if prefix_span. at_least_rust_2021 ( ) {
303
+ // If the raw lifetime is followed by \' then treat it a normal
304
+ // lifetime followed by a \', which is to interpret it as a character
305
+ // literal. In this case, it's always an invalid character literal
306
+ // since the literal must necessarily have >3 characters (r#...) inside
307
+ // of it, which is invalid.
308
+ if self . cursor . as_str ( ) . starts_with ( '\'' ) {
309
+ let lit_span = self . mk_sp ( start, self . pos + BytePos ( 1 ) ) ;
310
+ let contents = self . str_from_to ( start + BytePos ( 1 ) , self . pos ) ;
311
+ emit_unescape_error (
312
+ self . dcx ( ) ,
313
+ contents,
314
+ lit_span,
315
+ lit_span,
316
+ Mode :: Char ,
317
+ 0 ..contents. len ( ) ,
318
+ EscapeError :: MoreThanOneChar ,
319
+ )
320
+ . expect ( "expected error" ) ;
321
+ }
322
+
303
323
let span = self . mk_sp ( start, self . pos ) ;
304
324
305
325
let lifetime_name_without_tick =
306
326
Symbol :: intern ( & self . str_from ( ident_start) ) ;
307
327
if !lifetime_name_without_tick. can_be_raw ( ) {
308
- self . dcx ( ) . emit_err (
309
- errors:: CannotBeRawLifetime {
310
- span,
311
- ident : lifetime_name_without_tick
312
- }
313
- ) ;
328
+ self . dcx ( ) . emit_err ( errors:: CannotBeRawLifetime {
329
+ span,
330
+ ident : lifetime_name_without_tick,
331
+ } ) ;
314
332
}
315
333
316
334
// Put the `'` back onto the lifetime name.
@@ -371,8 +389,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
371
389
rustc_lexer:: TokenKind :: Caret => token:: BinOp ( token:: Caret ) ,
372
390
rustc_lexer:: TokenKind :: Percent => token:: BinOp ( token:: Percent ) ,
373
391
374
- rustc_lexer:: TokenKind :: Unknown
375
- | rustc_lexer:: TokenKind :: InvalidIdent => {
392
+ rustc_lexer:: TokenKind :: Unknown | rustc_lexer:: TokenKind :: InvalidIdent => {
376
393
// Don't emit diagnostics for sequences of the same invalid token
377
394
if swallow_next_invalid > 0 {
378
395
swallow_next_invalid -= 1 ;
0 commit comments