forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#13657 from jdonszelmann/disallowed-macro…
…s-to-early collect attribute spans early for disallowed macros
- Loading branch information
Showing
5 changed files
with
98 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,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"); | ||
} | ||
} |
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 attr_collector; | ||
pub mod author; | ||
pub mod dump_hir; | ||
pub mod format_args_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