Skip to content

Commit 5134a04

Browse files
committed
Remove ordinalize.
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.
1 parent 7cbb736 commit 5134a04

9 files changed

+19
-77
lines changed

compiler/rustc_resolve/src/diagnostics.rs

-14
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ use crate::{LexicalScopeBinding, NameBinding, NameBindingKind, PrivacyError, Vis
4444
use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet};
4545
use crate::{Segment, UseError};
4646

47-
#[cfg(test)]
48-
mod tests;
49-
5047
type Res = def::Res<ast::NodeId>;
5148

5249
/// A vector of spans and replacements, a message and applicability.
@@ -3027,14 +3024,3 @@ fn is_span_suitable_for_use_injection(s: Span) -> bool {
30273024
// import or other generated ones
30283025
!s.from_expansion()
30293026
}
3030-
3031-
/// Convert the given number into the corresponding ordinal
3032-
pub(crate) fn ordinalize(v: usize) -> String {
3033-
let suffix = match ((11..=13).contains(&(v % 100)), v % 10) {
3034-
(false, 1) => "st",
3035-
(false, 2) => "nd",
3036-
(false, 3) => "rd",
3037-
_ => "th",
3038-
};
3039-
format!("{v}{suffix}")
3040-
}

compiler/rustc_resolve/src/diagnostics/tests.rs

-40
This file was deleted.

compiler/rustc_resolve/src/macros.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
327327
UNUSED_MACRO_RULES,
328328
node_id,
329329
rule_span,
330-
format!(
331-
"{} rule of macro `{}` is never used",
332-
crate::diagnostics::ordinalize(arm_i + 1),
333-
ident.name
334-
),
330+
format!("rule #{} of macro `{}` is never used", arm_i + 1, ident.name),
335331
);
336332
}
337333
}

tests/ui/lint/unused/unused-macro-rules-compile-error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ macro_rules! num {
99
// Some nested use
1010
(two_) => { foo(compile_error!("foo")); };
1111
(three) => { 3 };
12-
(four) => { 4 }; //~ ERROR: rule of macro
12+
(four) => { 4 }; //~ ERROR: rule #5 of macro
1313
}
1414
const _NUM: u8 = num!(one) + num!(three);
1515

1616
// compile_error not used as a macro invocation
1717
macro_rules! num2 {
1818
(one) => { 1 };
1919
// Only identifier present
20-
(two) => { fn compile_error() {} }; //~ ERROR: rule of macro
20+
(two) => { fn compile_error() {} }; //~ ERROR: rule #2 of macro
2121
// Only identifier and bang present
22-
(two_) => { compile_error! }; //~ ERROR: rule of macro
22+
(two_) => { compile_error! }; //~ ERROR: rule #3 of macro
2323
(three) => { 3 };
2424
}
2525
const _NUM2: u8 = num2!(one) + num2!(three);

tests/ui/lint/unused/unused-macro-rules-compile-error.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: 5th rule of macro `num` is never used
1+
error: rule #5 of macro `num` is never used
22
--> $DIR/unused-macro-rules-compile-error.rs:12:5
33
|
44
LL | (four) => { 4 };
@@ -10,13 +10,13 @@ note: the lint level is defined here
1010
LL | #![deny(unused_macro_rules)]
1111
| ^^^^^^^^^^^^^^^^^^
1212

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

19-
error: 2nd rule of macro `num2` is never used
19+
error: rule #2 of macro `num2` is never used
2020
--> $DIR/unused-macro-rules-compile-error.rs:20:5
2121
|
2222
LL | (two) => { fn compile_error() {} };

tests/ui/lint/unused/unused-macro-rules-decl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Most simple case
77
macro num {
88
(one) => { 1 },
9-
(two) => { 2 }, //~ ERROR: 2nd rule of macro
9+
(two) => { 2 }, //~ ERROR: rule #2 of macro
1010
(three) => { 3 },
11-
(four) => { 4 }, //~ ERROR: 4th rule of macro
11+
(four) => { 4 }, //~ ERROR: rule #4 of macro
1212
}
1313
const _NUM: u8 = num!(one) + num!(three);
1414

@@ -28,7 +28,7 @@ macro num_rec {
2828
(two) => {
2929
num_rec!(one) + num_rec!(one)
3030
},
31-
(three) => { //~ ERROR: 3rd rule of macro
31+
(three) => { //~ ERROR: rule #3 of macro
3232
num_rec!(one) + num_rec!(two)
3333
},
3434
(four) => {

tests/ui/lint/unused/unused-macro-rules-decl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: 4th rule of macro `num` is never used
1+
error: rule #4 of macro `num` is never used
22
--> $DIR/unused-macro-rules-decl.rs:11:5
33
|
44
LL | (four) => { 4 },
@@ -10,13 +10,13 @@ note: the lint level is defined here
1010
LL | #![deny(unused_macro_rules)]
1111
| ^^^^^^^^^^^^^^^^^^
1212

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

19-
error: 3rd rule of macro `num_rec` is never used
19+
error: rule #3 of macro `num_rec` is never used
2020
--> $DIR/unused-macro-rules-decl.rs:31:5
2121
|
2222
LL | (three) => {

tests/ui/lint/unused/unused-macro-rules.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Most simple case
66
macro_rules! num {
77
(one) => { 1 };
8-
(two) => { 2 }; //~ ERROR: 2nd rule of macro
8+
(two) => { 2 }; //~ ERROR: rule #2 of macro
99
(three) => { 3 };
10-
(four) => { 4 }; //~ ERROR: 4th rule of macro
10+
(four) => { 4 }; //~ ERROR: rule #4 of macro
1111
}
1212
const _NUM: u8 = num!(one) + num!(three);
1313

@@ -27,7 +27,7 @@ macro_rules! num_rec {
2727
(two) => {
2828
num_rec!(one) + num_rec!(one)
2929
};
30-
(three) => { //~ ERROR: 3rd rule of macro
30+
(three) => { //~ ERROR: rule #3 of macro
3131
num_rec!(one) + num_rec!(two)
3232
};
3333
(four) => { num_rec!(two) + num_rec!(two) };

tests/ui/lint/unused/unused-macro-rules.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: 4th rule of macro `num` is never used
1+
error: rule #4 of macro `num` is never used
22
--> $DIR/unused-macro-rules.rs:10:5
33
|
44
LL | (four) => { 4 };
@@ -10,13 +10,13 @@ note: the lint level is defined here
1010
LL | #![deny(unused_macro_rules)]
1111
| ^^^^^^^^^^^^^^^^^^
1212

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

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

0 commit comments

Comments
 (0)