diff options
| author | Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> | 2025-02-21 01:00:19 +0000 |
|---|---|---|
| committer | Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> | 2025-02-21 20:44:35 +0000 |
| commit | ec88bc2e00985e99923ff3de966a947daa63c567 (patch) | |
| tree | 2fae71a7a1eee01d0cfe188684f8b12cb6f5f7cc /compiler/rustc_interface/src/passes.rs | |
| parent | 28b83ee59698ae069f5355b8e03f976406f410f5 (diff) | |
| download | rust-ec88bc2e00985e99923ff3de966a947daa63c567.tar.gz rust-ec88bc2e00985e99923ff3de966a947daa63c567.zip | |
fix: naming convention "ferris" suggestion for idents named 🦀
test: add tests for correct ferris capitalization fix: add "struct" style: use rustfmt style: remove newline fix: _ _ _ _ _
Diffstat (limited to 'compiler/rustc_interface/src/passes.rs')
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index d70d9d344b9..c4b0e244c56 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -301,8 +301,41 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { for (ident, mut spans) in identifiers.drain(..) { spans.sort(); if ident == sym::ferris { + enum FerrisFix { + SnakeCase, + ScreamingSnakeCase, + PascalCase, + } + + impl FerrisFix { + const fn as_str(self) -> &'static str { + match self { + FerrisFix::SnakeCase => "ferris", + FerrisFix::ScreamingSnakeCase => "FERRIS", + FerrisFix::PascalCase => "Ferris", + } + } + } + let first_span = spans[0]; - sess.dcx().emit_err(errors::FerrisIdentifier { spans, first_span }); + let prev_source = sess.psess.source_map().span_to_prev_source(first_span); + let ferris_fix = prev_source + .map_or(FerrisFix::SnakeCase, |source| { + let mut source_before_ferris = source.trim_end().split_whitespace().rev(); + match source_before_ferris.next() { + Some("struct" | "trait" | "mod" | "union" | "type" | "enum") => { + FerrisFix::PascalCase + } + Some("const" | "static") => FerrisFix::ScreamingSnakeCase, + Some("mut") if source_before_ferris.next() == Some("static") => { + FerrisFix::ScreamingSnakeCase + } + _ => FerrisFix::SnakeCase, + } + }) + .as_str(); + + sess.dcx().emit_err(errors::FerrisIdentifier { spans, first_span, ferris_fix }); } else { sess.dcx().emit_err(errors::EmojiIdentifier { spans, ident }); } |
