-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27e38f8
commit 251b6da
Showing
5 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::{mem, sync::OnceLock}; | ||
|
||
use rustc_ast::{Attribute, Crate}; | ||
use rustc_lint::{EarlyContext, EarlyLintPass}; | ||
use rustc_session::impl_lint_pass; | ||
use rustc_span::Span; | ||
use rustc_data_structures::sync::Lrc; | ||
|
||
#[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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub mod author; | ||
pub mod dump_hir; | ||
pub mod format_args_collector; | ||
pub mod attr_collector; | ||
|
||
#[cfg(feature = "internal")] | ||
pub mod internal_lints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters