Skip to content

Commit 41b1bcb

Browse files
committed
Improve 'cannot contain emoji' error.
1 parent acbe444 commit 41b1bcb

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

compiler/rustc_interface/src/passes.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
1010
use rustc_data_structures::parallel;
1111
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
1212
use rustc_data_structures::temp_dir::MaybeTempDir;
13-
use rustc_errors::{ErrorReported, PResult};
13+
use rustc_errors::{Applicability, ErrorReported, PResult};
1414
use rustc_expand::base::ExtCtxt;
1515
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
1616
use rustc_hir::Crate;
@@ -456,10 +456,26 @@ pub fn configure_and_expand(
456456
identifiers.sort_by_key(|&(key, _)| key);
457457
for (ident, mut spans) in identifiers.into_iter() {
458458
spans.sort();
459-
sess.diagnostic().span_err(
460-
MultiSpan::from(spans),
461-
&format!("identifiers cannot contain emoji: `{}`", ident),
462-
);
459+
if ident == sym::ferris {
460+
let first_span = spans[0];
461+
sess.diagnostic()
462+
.struct_span_err(
463+
MultiSpan::from(spans),
464+
"Ferris cannot be used as an identifier",
465+
)
466+
.span_suggestion(
467+
first_span,
468+
"try using their name instead",
469+
"ferris".to_string(),
470+
Applicability::MaybeIncorrect,
471+
)
472+
.emit();
473+
} else {
474+
sess.diagnostic().span_err(
475+
MultiSpan::from(spans),
476+
&format!("identifiers cannot contain emoji: `{}`", ident),
477+
);
478+
}
463479
}
464480
});
465481

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ symbols! {
627627
fdiv_fast,
628628
feature,
629629
fence,
630+
ferris: "🦀",
630631
fetch_update,
631632
ffi,
632633
ffi_const,

0 commit comments

Comments
 (0)