1
Fork 0

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.
This commit is contained in:
Nicholas Nethercote 2024-05-10 15:34:12 +10:00
parent 7cbb736a60
commit 5134a04eaa
9 changed files with 19 additions and 77 deletions

View file

@ -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.
@ -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}")
}

View file

@ -1,40 +0,0 @@
use super::ordinalize;
#[test]
fn test_ordinalize() {
assert_eq!(ordinalize(1), "1st");
assert_eq!(ordinalize(2), "2nd");
assert_eq!(ordinalize(3), "3rd");
assert_eq!(ordinalize(4), "4th");
assert_eq!(ordinalize(5), "5th");
// ...
assert_eq!(ordinalize(10), "10th");
assert_eq!(ordinalize(11), "11th");
assert_eq!(ordinalize(12), "12th");
assert_eq!(ordinalize(13), "13th");
assert_eq!(ordinalize(14), "14th");
// ...
assert_eq!(ordinalize(20), "20th");
assert_eq!(ordinalize(21), "21st");
assert_eq!(ordinalize(22), "22nd");
assert_eq!(ordinalize(23), "23rd");
assert_eq!(ordinalize(24), "24th");
// ...
assert_eq!(ordinalize(30), "30th");
assert_eq!(ordinalize(31), "31st");
assert_eq!(ordinalize(32), "32nd");
assert_eq!(ordinalize(33), "33rd");
assert_eq!(ordinalize(34), "34th");
// ...
assert_eq!(ordinalize(7010), "7010th");
assert_eq!(ordinalize(7011), "7011th");
assert_eq!(ordinalize(7012), "7012th");
assert_eq!(ordinalize(7013), "7013th");
assert_eq!(ordinalize(7014), "7014th");
// ...
assert_eq!(ordinalize(7020), "7020th");
assert_eq!(ordinalize(7021), "7021st");
assert_eq!(ordinalize(7022), "7022nd");
assert_eq!(ordinalize(7023), "7023rd");
assert_eq!(ordinalize(7024), "7024th");
}

View file

@ -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),
);
}
}