@@ -8,11 +8,12 @@ use rustc_borrowck as mir_borrowck;
88use rustc_codegen_ssa:: traits:: CodegenBackend ;
99use rustc_data_structures:: parallel;
1010use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
11- use rustc_errors:: { Applicability , ErrorGuaranteed , MultiSpan , PResult } ;
11+ use rustc_errors:: { ErrorGuaranteed , PResult } ;
1212use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
1313use rustc_hir:: def_id:: StableCrateId ;
1414use rustc_hir:: definitions:: Definitions ;
1515use rustc_lint:: { BufferedEarlyLint , EarlyCheckNode , LintStore } ;
16+ use rustc_macros:: SessionDiagnostic ;
1617use rustc_metadata:: creader:: CStore ;
1718use rustc_middle:: arena:: Arena ;
1819use rustc_middle:: dep_graph:: DepGraph ;
@@ -30,7 +31,7 @@ use rustc_session::output::filename_for_input;
3031use rustc_session:: search_paths:: PathKind ;
3132use rustc_session:: { Limit , Session } ;
3233use rustc_span:: symbol:: { sym, Symbol } ;
33- use rustc_span:: FileName ;
34+ use rustc_span:: { FileName , Span } ;
3435use rustc_trait_selection:: traits;
3536use rustc_typeck as typeck;
3637use tracing:: { info, warn} ;
@@ -263,6 +264,23 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
263264 }
264265}
265266
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+
266284/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
267285/// syntax expansion, secondary `cfg` expansion, synthesis of a test
268286/// harness if one is to be provided, injection of a dependency on the
@@ -443,23 +461,9 @@ pub fn configure_and_expand(
443461 spans. sort ( ) ;
444462 if ident == sym:: ferris {
445463 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 } ) ;
458465 } 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 } ) ;
463467 }
464468 }
465469 } ) ;
0 commit comments