Merge pull request #13657 from jdonszelmann/disallowed-macros-to-early
collect attribute spans early for disallowed macros
This commit is contained in:
commit
f712eb5cdc
5 changed files with 98 additions and 38 deletions
40
clippy_lints/src/utils/attr_collector.rs
Normal file
40
clippy_lints/src/utils/attr_collector.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use std::mem;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use rustc_ast::{Attribute, Crate};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::Span;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct AttrStorage(pub Lrc<OnceLock<Vec<Span>>>);
|
||||
|
||||
pub struct AttrCollector {
|
||||
storage: AttrStorage,
|
||||
attrs: Vec<Span>,
|
||||
}
|
||||
|
||||
impl AttrCollector {
|
||||
pub fn new(storage: AttrStorage) -> Self {
|
||||
Self {
|
||||
storage,
|
||||
attrs: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_lint_pass!(AttrCollector => []);
|
||||
|
||||
impl EarlyLintPass for AttrCollector {
|
||||
fn check_attribute(&mut self, _cx: &EarlyContext<'_>, attr: &Attribute) {
|
||||
self.attrs.push(attr.span);
|
||||
}
|
||||
|
||||
fn check_crate_post(&mut self, _: &EarlyContext<'_>, _: &Crate) {
|
||||
self.storage
|
||||
.0
|
||||
.set(mem::take(&mut self.attrs))
|
||||
.expect("should only be called once");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
pub mod attr_collector;
|
||||
pub mod author;
|
||||
pub mod dump_hir;
|
||||
pub mod format_args_collector;
|
||||
|
||||
#[cfg(feature = "internal")]
|
||||
pub mod internal_lints;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue