Skip to content

Commit

Permalink
Remove ordinalize.
Browse files Browse the repository at this point in the history
Some minor (English only) heroics are performed to print error messages
like "5th rule of macro `m` is never used". The form "rule #5 of macro
`m` is never used" is just as good and much simpler to implement.
  • Loading branch information
nnethercote committed May 10, 2024
1 parent 7cbb736 commit 5134a04
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 77 deletions.
14 changes: 0 additions & 14 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ use crate::{LexicalScopeBinding, NameBinding, NameBindingKind, PrivacyError, Vis
use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet};
use crate::{Segment, UseError};

#[cfg(test)]
mod tests;

type Res = def::Res<ast::NodeId>;

/// A vector of spans and replacements, a message and applicability.
Expand Down Expand Up @@ -3027,14 +3024,3 @@ fn is_span_suitable_for_use_injection(s: Span) -> bool {
// import or other generated ones
!s.from_expansion()
}

/// Convert the given number into the corresponding ordinal
pub(crate) fn ordinalize(v: usize) -> String {
let suffix = match ((11..=13).contains(&(v % 100)), v % 10) {
(false, 1) => "st",
(false, 2) => "nd",
(false, 3) => "rd",
_ => "th",
};
format!("{v}{suffix}")
}
40 changes: 0 additions & 40 deletions compiler/rustc_resolve/src/diagnostics/tests.rs

This file was deleted.

6 changes: 1 addition & 5 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
UNUSED_MACRO_RULES,
node_id,
rule_span,
format!(
"{} rule of macro `{}` is never used",
crate::diagnostics::ordinalize(arm_i + 1),
ident.name
),
format!("rule #{} of macro `{}` is never used", arm_i + 1, ident.name),
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-compile-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ macro_rules! num {
// Some nested use
(two_) => { foo(compile_error!("foo")); };
(three) => { 3 };
(four) => { 4 }; //~ ERROR: rule of macro
(four) => { 4 }; //~ ERROR: rule #5 of macro
}
const _NUM: u8 = num!(one) + num!(three);

// compile_error not used as a macro invocation
macro_rules! num2 {
(one) => { 1 };
// Only identifier present
(two) => { fn compile_error() {} }; //~ ERROR: rule of macro
(two) => { fn compile_error() {} }; //~ ERROR: rule #2 of macro
// Only identifier and bang present
(two_) => { compile_error! }; //~ ERROR: rule of macro
(two_) => { compile_error! }; //~ ERROR: rule #3 of macro
(three) => { 3 };
}
const _NUM2: u8 = num2!(one) + num2!(three);
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-compile-error.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: 5th rule of macro `num` is never used
error: rule #5 of macro `num` is never used
--> $DIR/unused-macro-rules-compile-error.rs:12:5
|
LL | (four) => { 4 };
Expand All @@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^

error: 3rd rule of macro `num2` is never used
error: rule #3 of macro `num2` is never used
--> $DIR/unused-macro-rules-compile-error.rs:22:5
|
LL | (two_) => { compile_error! };
| ^^^^^^

error: 2nd rule of macro `num2` is never used
error: rule #2 of macro `num2` is never used
--> $DIR/unused-macro-rules-compile-error.rs:20:5
|
LL | (two) => { fn compile_error() {} };
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Most simple case
macro num {
(one) => { 1 },
(two) => { 2 }, //~ ERROR: 2nd rule of macro
(two) => { 2 }, //~ ERROR: rule #2 of macro
(three) => { 3 },
(four) => { 4 }, //~ ERROR: 4th rule of macro
(four) => { 4 }, //~ ERROR: rule #4 of macro
}
const _NUM: u8 = num!(one) + num!(three);

Expand All @@ -28,7 +28,7 @@ macro num_rec {
(two) => {
num_rec!(one) + num_rec!(one)
},
(three) => { //~ ERROR: 3rd rule of macro
(three) => { //~ ERROR: rule #3 of macro
num_rec!(one) + num_rec!(two)
},
(four) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-decl.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: 4th rule of macro `num` is never used
error: rule #4 of macro `num` is never used
--> $DIR/unused-macro-rules-decl.rs:11:5
|
LL | (four) => { 4 },
Expand All @@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^

error: 2nd rule of macro `num` is never used
error: rule #2 of macro `num` is never used
--> $DIR/unused-macro-rules-decl.rs:9:5
|
LL | (two) => { 2 },
| ^^^^^

error: 3rd rule of macro `num_rec` is never used
error: rule #3 of macro `num_rec` is never used
--> $DIR/unused-macro-rules-decl.rs:31:5
|
LL | (three) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Most simple case
macro_rules! num {
(one) => { 1 };
(two) => { 2 }; //~ ERROR: 2nd rule of macro
(two) => { 2 }; //~ ERROR: rule #2 of macro
(three) => { 3 };
(four) => { 4 }; //~ ERROR: 4th rule of macro
(four) => { 4 }; //~ ERROR: rule #4 of macro
}
const _NUM: u8 = num!(one) + num!(three);

Expand All @@ -27,7 +27,7 @@ macro_rules! num_rec {
(two) => {
num_rec!(one) + num_rec!(one)
};
(three) => { //~ ERROR: 3rd rule of macro
(three) => { //~ ERROR: rule #3 of macro
num_rec!(one) + num_rec!(two)
};
(four) => { num_rec!(two) + num_rec!(two) };
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: 4th rule of macro `num` is never used
error: rule #4 of macro `num` is never used
--> $DIR/unused-macro-rules.rs:10:5
|
LL | (four) => { 4 };
Expand All @@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^

error: 2nd rule of macro `num` is never used
error: rule #2 of macro `num` is never used
--> $DIR/unused-macro-rules.rs:8:5
|
LL | (two) => { 2 };
| ^^^^^

error: 3rd rule of macro `num_rec` is never used
error: rule #3 of macro `num_rec` is never used
--> $DIR/unused-macro-rules.rs:30:5
|
LL | (three) => {
Expand Down

0 comments on commit 5134a04

Please sign in to comment.