Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkov
Implement a lint to warn about unused macro rules This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros. ```rust macro_rules! unused_empty { (hello) => { println!("Hello, world!") }; () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used } fn main() { unused_empty!(hello); } ``` Builds upon #96149 and #96156. Fixes #73576
This commit is contained in:
@@ -35,6 +35,9 @@ 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.
|
||||
@@ -2675,3 +2678,14 @@ 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
|
||||
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}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user