Skip to content

Commit d88752a

Browse files
authored
Rollup merge of #138160 - jdonszelmann:move-find-attr2, r=oli-obk
depend more on attr_data_structures and move find_attr! there r? ``@oli-obk`` This should be an easy one. It just moves some imports around. This is necessary for other changes that I'm working on not to have import cycles. However, it's an easy one to just merge on its own.
2 parents bfa1a62 + 4203e9c commit d88752a

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
@@ -3297,6 +3297,7 @@ dependencies = [
32973297
"rustc_hir",
32983298
"rustc_lexer",
32993299
"rustc_macros",
3300+
"rustc_middle",
33003301
"rustc_serialize",
33013302
"rustc_session",
33023303
"rustc_span",
@@ -3752,7 +3753,7 @@ dependencies = [
37523753
"rustc_abi",
37533754
"rustc_ast",
37543755
"rustc_ast_pretty",
3755-
"rustc_attr_parsing",
3756+
"rustc_attr_data_structures",
37563757
"rustc_hir",
37573758
"rustc_span",
37583759
]
@@ -4020,7 +4021,8 @@ dependencies = [
40204021
"rustc_apfloat",
40214022
"rustc_arena",
40224023
"rustc_ast",
4023-
"rustc_attr_parsing",
4024+
"rustc_ast_ir",
4025+
"rustc_attr_data_structures",
40244026
"rustc_data_structures",
40254027
"rustc_error_messages",
40264028
"rustc_errors",

compiler/rustc_attr_data_structures/src/lib.rs

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

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
@@ -94,47 +94,3 @@ pub use context::{AttributeParser, OmitDoc};
9494
pub use rustc_attr_data_structures::*;
9595

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

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
@@ -15,7 +15,7 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
1515
use rustc_ast_pretty::pp::{self, Breaks};
1616
use rustc_ast_pretty::pprust::state::MacHeader;
1717
use rustc_ast_pretty::pprust::{Comments, PrintState};
18-
use rustc_attr_parsing::{AttributeKind, PrintAttribute};
18+
use rustc_attr_data_structures::{AttributeKind, PrintAttribute};
1919
use rustc_hir::{
2020
BindingMode, ByRef, ConstArgKind, GenericArg, GenericBound, GenericParam, GenericParamKind,
2121
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)