@@ -8,11 +8,12 @@ use rustc_borrowck as mir_borrowck;
8
8
use rustc_codegen_ssa:: traits:: CodegenBackend ;
9
9
use rustc_data_structures:: parallel;
10
10
use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
11
- use rustc_errors:: { Applicability , ErrorGuaranteed , MultiSpan , PResult } ;
11
+ use rustc_errors:: { ErrorGuaranteed , PResult } ;
12
12
use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
13
13
use rustc_hir:: def_id:: StableCrateId ;
14
14
use rustc_hir:: definitions:: Definitions ;
15
15
use rustc_lint:: { BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16
+ use rustc_macros:: SessionDiagnostic ;
16
17
use rustc_metadata:: creader:: CStore ;
17
18
use rustc_middle:: arena:: Arena ;
18
19
use rustc_middle:: dep_graph:: DepGraph ;
@@ -30,7 +31,7 @@ use rustc_session::output::filename_for_input;
30
31
use rustc_session:: search_paths:: PathKind ;
31
32
use rustc_session:: { Limit , Session } ;
32
33
use rustc_span:: symbol:: { sym, Symbol } ;
33
- use rustc_span:: FileName ;
34
+ use rustc_span:: { FileName , Span } ;
34
35
use rustc_trait_selection:: traits;
35
36
use rustc_typeck as typeck;
36
37
use tracing:: { info, warn} ;
@@ -263,6 +264,23 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
263
264
}
264
265
}
265
266
267
+ #[ derive( SessionDiagnostic ) ]
268
+ #[ error( interface:: ferris_identifier) ]
269
+ struct FerrisIdentifier {
270
+ #[ primary_span]
271
+ spans : Vec < Span > ,
272
+ #[ suggestion( code = "ferris" , applicability = "maybe-incorrect" ) ]
273
+ first_span : Span ,
274
+ }
275
+
276
+ #[ derive( SessionDiagnostic ) ]
277
+ #[ error( interface:: emoji_identifier) ]
278
+ struct EmojiIdentifier {
279
+ #[ primary_span]
280
+ spans : Vec < Span > ,
281
+ ident : Symbol ,
282
+ }
283
+
266
284
/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
267
285
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
268
286
/// harness if one is to be provided, injection of a dependency on the
@@ -443,23 +461,9 @@ pub fn configure_and_expand(
443
461
spans. sort ( ) ;
444
462
if ident == sym:: ferris {
445
463
let first_span = spans[ 0 ] ;
446
- sess. diagnostic ( )
447
- . struct_span_err (
448
- MultiSpan :: from ( spans) ,
449
- "Ferris cannot be used as an identifier" ,
450
- )
451
- . span_suggestion (
452
- first_span,
453
- "try using their name instead" ,
454
- "ferris" ,
455
- Applicability :: MaybeIncorrect ,
456
- )
457
- . emit ( ) ;
464
+ sess. emit_err ( FerrisIdentifier { spans, first_span } ) ;
458
465
} else {
459
- sess. diagnostic ( ) . span_err (
460
- MultiSpan :: from ( spans) ,
461
- & format ! ( "identifiers cannot contain emoji: `{}`" , ident) ,
462
- ) ;
466
+ sess. emit_err ( EmojiIdentifier { spans, ident } ) ;
463
467
}
464
468
}
465
469
} ) ;
0 commit comments