Skip to content

Commit 0042afe

Browse files
authored
Unrolled build for #138160
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 4f52199 + 4203e9c commit 0042afe

File tree

15 files changed

+73
-68
lines changed

15 files changed

+73
-68
lines changed

Cargo.lock

+4-2
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

+44
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

+1
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

-44
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

+1-1
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

+1-1
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

+2-1
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

+1-1
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

+1-1
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

+1-1
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;

compiler/rustc_middle/src/query/erase.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ trivial! {
231231
bool,
232232
Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>,
233233
Option<rustc_ast::expand::allocator::AllocatorKind>,
234-
Option<rustc_attr_parsing::ConstStability>,
235-
Option<rustc_attr_parsing::DefaultBodyStability>,
236-
Option<rustc_attr_parsing::Stability>,
234+
Option<rustc_attr_data_structures::ConstStability>,
235+
Option<rustc_attr_data_structures::DefaultBodyStability>,
236+
Option<rustc_attr_data_structures::Stability>,
237237
Option<rustc_data_structures::svh::Svh>,
238238
Option<rustc_hir::def::DefKind>,
239239
Option<rustc_hir::CoroutineKind>,
@@ -256,10 +256,10 @@ trivial! {
256256
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
257257
rustc_abi::ReprOptions,
258258
rustc_ast::expand::allocator::AllocatorKind,
259-
rustc_attr_parsing::ConstStability,
260-
rustc_attr_parsing::DefaultBodyStability,
261-
rustc_attr_parsing::Deprecation,
262-
rustc_attr_parsing::Stability,
259+
rustc_attr_data_structures::ConstStability,
260+
rustc_attr_data_structures::DefaultBodyStability,
261+
rustc_attr_data_structures::Deprecation,
262+
rustc_attr_data_structures::Stability,
263263
rustc_data_structures::svh::Svh,
264264
rustc_errors::ErrorGuaranteed,
265265
rustc_hir::Constness,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_span::def_id::LOCAL_CRATE;
4141
use rustc_span::source_map::Spanned;
4242
use rustc_span::{DUMMY_SP, Span, Symbol};
4343
use rustc_target::spec::PanicStrategy;
44-
use {rustc_abi as abi, rustc_ast as ast, rustc_attr_parsing as attr, rustc_hir as hir};
44+
use {rustc_abi as abi, rustc_ast as ast, rustc_attr_data_structures as attr, rustc_hir as hir};
4545

4646
use crate::infer::canonical::{self, Canonical};
4747
use crate::lint::LintExpectation;

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'tcx> Instance<'tcx> {
203203
if !tcx.sess.opts.share_generics()
204204
// However, if the def_id is marked inline(never), then it's fine to just reuse the
205205
// upstream monomorphization.
206-
&& tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_parsing::InlineAttr::Never
206+
&& tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_data_structures::InlineAttr::Never
207207
{
208208
return None;
209209
}

compiler/rustc_middle/src/ty/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ pub use intrinsic::IntrinsicDef;
2727
use rustc_abi::{Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, VariantIdx};
2828
use rustc_ast::expand::StrippedCfgItem;
2929
use rustc_ast::node_id::NodeMap;
30-
use rustc_attr_parsing::AttributeKind;
30+
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
31+
use rustc_attr_data_structures::AttributeKind;
3132
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3233
use rustc_data_structures::intern::Interned;
3334
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -51,7 +52,7 @@ pub use rustc_type_ir::relate::VarianceDiagInfo;
5152
pub use rustc_type_ir::*;
5253
use tracing::{debug, instrument};
5354
pub use vtable::*;
54-
use {rustc_ast as ast, rustc_attr_parsing as attr, rustc_hir as hir};
55+
use {rustc_ast as ast, rustc_attr_data_structures as attr, rustc_hir as hir};
5556

5657
pub use self::closure::{
5758
BorrowKind, CAPTURE_STRUCT_LOCAL, CaptureInfo, CapturedPlace, ClosureTypeInfo,
@@ -1757,7 +1758,7 @@ impl<'tcx> TyCtxt<'tcx> {
17571758

17581759
/// Gets all attributes.
17591760
///
1760-
/// To see if an item has a specific attribute, you should use [`rustc_attr_parsing::find_attr!`] so you can use matching.
1761+
/// To see if an item has a specific attribute, you should use [`rustc_attr_data_structures::find_attr!`] so you can use matching.
17611762
pub fn get_all_attrs(
17621763
self,
17631764
did: impl Into<DefId>,

compiler/rustc_middle/src/ty/parameterized.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ trivially_parameterized_over_tcx! {
8080
rustc_ast::Attribute,
8181
rustc_ast::DelimArgs,
8282
rustc_ast::expand::StrippedCfgItem<rustc_hir::def_id::DefIndex>,
83-
rustc_attr_parsing::ConstStability,
84-
rustc_attr_parsing::DefaultBodyStability,
85-
rustc_attr_parsing::Deprecation,
86-
rustc_attr_parsing::Stability,
83+
rustc_attr_data_structures::ConstStability,
84+
rustc_attr_data_structures::DefaultBodyStability,
85+
rustc_attr_data_structures::Deprecation,
86+
rustc_attr_data_structures::Stability,
8787
rustc_hir::Constness,
8888
rustc_hir::Defaultness,
8989
rustc_hir::Safety,

0 commit comments

Comments
 (0)