Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4203e9c

Browse files
committed
depend more on attr_data_structures and move find_attr! there
1 parent 03eb454 commit 4203e9c

File tree

15 files changed

+73
-68
lines changed

15 files changed

+73
-68
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,6 +3286,7 @@ dependencies = [
32863286
"rustc_hir",
32873287
"rustc_lexer",
32883288
"rustc_macros",
3289+
"rustc_middle",
32893290
"rustc_serialize",
32903291
"rustc_session",
32913292
"rustc_span",
@@ -3741,7 +3742,7 @@ dependencies = [
37413742
"rustc_abi",
37423743
"rustc_ast",
37433744
"rustc_ast_pretty",
3744-
"rustc_attr_parsing",
3745+
"rustc_attr_data_structures",
37453746
"rustc_hir",
37463747
"rustc_span",
37473748
]
@@ -4009,7 +4010,8 @@ dependencies = [
40094010
"rustc_apfloat",
40104011
"rustc_arena",
40114012
"rustc_ast",
4012-
"rustc_attr_parsing",
4013+
"rustc_ast_ir",
4014+
"rustc_attr_data_structures",
40134015
"rustc_data_structures",
40144016
"rustc_error_messages",
40154017
"rustc_errors",

compiler/rustc_attr_data_structures/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,47 @@ print_tup!(A B C D E F G H);
149149
print_skip!(Span, ());
150150
print_disp!(Symbol, u16, bool, NonZero<u32>);
151151
print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency);
152+
153+
/// Finds attributes in sequences of attributes by pattern matching.
154+
///
155+
/// A little like `matches` but for attributes.
156+
///
157+
/// ```rust,ignore (illustrative)
158+
/// // finds the repr attribute
159+
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
160+
///
161+
/// }
162+
///
163+
/// // checks if one has matched
164+
/// if find_attr!(attrs, AttributeKind::Repr(_)) {
165+
///
166+
/// }
167+
/// ```
168+
///
169+
/// Often this requires you to first end up with a list of attributes.
170+
/// A common way to get those is through `tcx.get_all_attrs(did)`
171+
#[macro_export]
172+
macro_rules! find_attr {
173+
($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
174+
$crate::find_attr!($attributes_list, $pattern $(if $guard)? => ()).is_some()
175+
}};
176+
177+
($attributes_list: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
178+
fn check_attribute_iterator<'a>(_: &'_ impl IntoIterator<Item = &'a rustc_hir::Attribute>) {}
179+
check_attribute_iterator(&$attributes_list);
180+
181+
let find_attribute = |iter| {
182+
for i in $attributes_list {
183+
match i {
184+
rustc_hir::Attribute::Parsed($pattern) $(if $guard)? => {
185+
return Some($e);
186+
}
187+
_ => {}
188+
}
189+
}
190+
191+
None
192+
};
193+
find_attribute($attributes_list)
194+
}};
195+
}

compiler/rustc_attr_parsing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1616
rustc_hir = { path = "../rustc_hir" }
1717
rustc_lexer = { path = "../rustc_lexer" }
1818
rustc_macros = { path = "../rustc_macros" }
19+
rustc_middle = { path = "../rustc_middle" }
1920
rustc_serialize = { path = "../rustc_serialize" }
2021
rustc_session = { path = "../rustc_session" }
2122
rustc_span = { path = "../rustc_span" }

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -95,47 +95,3 @@ pub use context::{AttributeParser, OmitDoc};
9595
pub use rustc_attr_data_structures::*;
9696

9797
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
98-
99-
/// Finds attributes in sequences of attributes by pattern matching.
100-
///
101-
/// A little like `matches` but for attributes.
102-
///
103-
/// ```rust,ignore (illustrative)
104-
/// // finds the repr attribute
105-
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
106-
///
107-
/// }
108-
///
109-
/// // checks if one has matched
110-
/// if find_attr!(attrs, AttributeKind::Repr(_)) {
111-
///
112-
/// }
113-
/// ```
114-
///
115-
/// Often this requires you to first end up with a list of attributes.
116-
/// A common way to get those is through `tcx.get_all_attrs(did)`
117-
#[macro_export]
118-
macro_rules! find_attr {
119-
($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
120-
$crate::find_attr!($attributes_list, $pattern $(if $guard)? => ()).is_some()
121-
}};
122-
123-
($attributes_list: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
124-
fn check_attribute_iterator<'a>(_: &'_ impl IntoIterator<Item = &'a rustc_hir::Attribute>) {}
125-
check_attribute_iterator(&$attributes_list);
126-
127-
let find_attribute = |iter| {
128-
for i in $attributes_list {
129-
match i {
130-
rustc_hir::Attribute::Parsed($pattern) $(if $guard)? => {
131-
return Some($e);
132-
}
133-
_ => {}
134-
}
135-
}
136-
137-
None
138-
};
139-
find_attribute($attributes_list)
140-
}};
141-
}

compiler/rustc_hir_pretty/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2024"
88
rustc_abi = { path = "../rustc_abi" }
99
rustc_ast = { path = "../rustc_ast" }
1010
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
11-
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
11+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
1212
rustc_hir = { path = "../rustc_hir" }
1313
rustc_span = { path = "../rustc_span" }
1414
# tidy-alphabetical-end

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
1616
use rustc_ast_pretty::pp::{self, Breaks};
1717
use rustc_ast_pretty::pprust::state::MacHeader;
1818
use rustc_ast_pretty::pprust::{Comments, PrintState};
19-
use rustc_attr_parsing::{AttributeKind, PrintAttribute};
19+
use rustc_attr_data_structures::{AttributeKind, PrintAttribute};
2020
use rustc_hir::{
2121
BindingMode, ByRef, ConstArgKind, GenericArg, GenericBound, GenericParam, GenericParamKind,
2222
HirId, ImplicitSelfKind, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term,

compiler/rustc_middle/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ rustc_abi = { path = "../rustc_abi" }
1414
rustc_apfloat = "0.2.0"
1515
rustc_arena = { path = "../rustc_arena" }
1616
rustc_ast = { path = "../rustc_ast" }
17-
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
17+
rustc_ast_ir = { path = "../rustc_ast_ir" }
18+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
1819
rustc_data_structures = { path = "../rustc_data_structures" }
1920
rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links
2021
rustc_errors = { path = "../rustc_errors" }

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_abi::Align;
22
use rustc_ast::expand::autodiff_attrs::AutoDiffAttrs;
3-
use rustc_attr_parsing::{InlineAttr, InstructionSetAttr, OptimizeAttr};
3+
use rustc_attr_data_structures::{InlineAttr, InstructionSetAttr, OptimizeAttr};
44
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
55
use rustc_span::Symbol;
66
use rustc_target::spec::SanitizerSet;

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::num::NonZero;
55

66
use rustc_ast::NodeId;
7-
use rustc_attr_parsing::{
7+
use rustc_attr_data_structures::{
88
self as attr, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability,
99
};
1010
use rustc_data_structures::unord::UnordMap;

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::hash::Hash;
33

44
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
5-
use rustc_attr_parsing::InlineAttr;
5+
use rustc_attr_data_structures::InlineAttr;
66
use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN};
77
use rustc_data_structures::fingerprint::Fingerprint;
88
use rustc_data_structures::fx::FxIndexMap;

0 commit comments

Comments
 (0)