depend more on attr_data_structures and move find_attr! there
This commit is contained in:
parent
03eb454523
commit
4203e9c56d
15 changed files with 73 additions and 68 deletions
|
@ -3286,6 +3286,7 @@ dependencies = [
|
|||
"rustc_hir",
|
||||
"rustc_lexer",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
|
@ -3741,7 +3742,7 @@ dependencies = [
|
|||
"rustc_abi",
|
||||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
"rustc_attr_parsing",
|
||||
"rustc_attr_data_structures",
|
||||
"rustc_hir",
|
||||
"rustc_span",
|
||||
]
|
||||
|
@ -4009,7 +4010,8 @@ dependencies = [
|
|||
"rustc_apfloat",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
"rustc_attr_parsing",
|
||||
"rustc_ast_ir",
|
||||
"rustc_attr_data_structures",
|
||||
"rustc_data_structures",
|
||||
"rustc_error_messages",
|
||||
"rustc_errors",
|
||||
|
|
|
@ -149,3 +149,47 @@ print_tup!(A B C D E F G H);
|
|||
print_skip!(Span, ());
|
||||
print_disp!(Symbol, u16, bool, NonZero<u32>);
|
||||
print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency);
|
||||
|
||||
/// Finds attributes in sequences of attributes by pattern matching.
|
||||
///
|
||||
/// A little like `matches` but for attributes.
|
||||
///
|
||||
/// ```rust,ignore (illustrative)
|
||||
/// // finds the repr attribute
|
||||
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
|
||||
///
|
||||
/// }
|
||||
///
|
||||
/// // checks if one has matched
|
||||
/// if find_attr!(attrs, AttributeKind::Repr(_)) {
|
||||
///
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Often this requires you to first end up with a list of attributes.
|
||||
/// A common way to get those is through `tcx.get_all_attrs(did)`
|
||||
#[macro_export]
|
||||
macro_rules! find_attr {
|
||||
($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
|
||||
$crate::find_attr!($attributes_list, $pattern $(if $guard)? => ()).is_some()
|
||||
}};
|
||||
|
||||
($attributes_list: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
|
||||
fn check_attribute_iterator<'a>(_: &'_ impl IntoIterator<Item = &'a rustc_hir::Attribute>) {}
|
||||
check_attribute_iterator(&$attributes_list);
|
||||
|
||||
let find_attribute = |iter| {
|
||||
for i in $attributes_list {
|
||||
match i {
|
||||
rustc_hir::Attribute::Parsed($pattern) $(if $guard)? => {
|
||||
return Some($e);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
};
|
||||
find_attribute($attributes_list)
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ rustc_fluent_macro = { path = "../rustc_fluent_macro" }
|
|||
rustc_hir = { path = "../rustc_hir" }
|
||||
rustc_lexer = { path = "../rustc_lexer" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_middle = { path = "../rustc_middle" }
|
||||
rustc_serialize = { path = "../rustc_serialize" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
|
|
|
@ -95,47 +95,3 @@ pub use context::{AttributeParser, OmitDoc};
|
|||
pub use rustc_attr_data_structures::*;
|
||||
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
|
||||
/// Finds attributes in sequences of attributes by pattern matching.
|
||||
///
|
||||
/// A little like `matches` but for attributes.
|
||||
///
|
||||
/// ```rust,ignore (illustrative)
|
||||
/// // finds the repr attribute
|
||||
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
|
||||
///
|
||||
/// }
|
||||
///
|
||||
/// // checks if one has matched
|
||||
/// if find_attr!(attrs, AttributeKind::Repr(_)) {
|
||||
///
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Often this requires you to first end up with a list of attributes.
|
||||
/// A common way to get those is through `tcx.get_all_attrs(did)`
|
||||
#[macro_export]
|
||||
macro_rules! find_attr {
|
||||
($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
|
||||
$crate::find_attr!($attributes_list, $pattern $(if $guard)? => ()).is_some()
|
||||
}};
|
||||
|
||||
($attributes_list: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
|
||||
fn check_attribute_iterator<'a>(_: &'_ impl IntoIterator<Item = &'a rustc_hir::Attribute>) {}
|
||||
check_attribute_iterator(&$attributes_list);
|
||||
|
||||
let find_attribute = |iter| {
|
||||
for i in $attributes_list {
|
||||
match i {
|
||||
rustc_hir::Attribute::Parsed($pattern) $(if $guard)? => {
|
||||
return Some($e);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
};
|
||||
find_attribute($attributes_list)
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ edition = "2024"
|
|||
rustc_abi = { path = "../rustc_abi" }
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
||||
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
|
||||
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
|
||||
rustc_hir = { path = "../rustc_hir" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -16,7 +16,7 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
|
|||
use rustc_ast_pretty::pp::{self, Breaks};
|
||||
use rustc_ast_pretty::pprust::state::MacHeader;
|
||||
use rustc_ast_pretty::pprust::{Comments, PrintState};
|
||||
use rustc_attr_parsing::{AttributeKind, PrintAttribute};
|
||||
use rustc_attr_data_structures::{AttributeKind, PrintAttribute};
|
||||
use rustc_hir::{
|
||||
BindingMode, ByRef, ConstArgKind, GenericArg, GenericBound, GenericParam, GenericParamKind,
|
||||
HirId, ImplicitSelfKind, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term,
|
||||
|
|
|
@ -14,7 +14,8 @@ rustc_abi = { path = "../rustc_abi" }
|
|||
rustc_apfloat = "0.2.0"
|
||||
rustc_arena = { path = "../rustc_arena" }
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
|
||||
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links
|
||||
rustc_errors = { path = "../rustc_errors" }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_abi::Align;
|
||||
use rustc_ast::expand::autodiff_attrs::AutoDiffAttrs;
|
||||
use rustc_attr_parsing::{InlineAttr, InstructionSetAttr, OptimizeAttr};
|
||||
use rustc_attr_data_structures::{InlineAttr, InstructionSetAttr, OptimizeAttr};
|
||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
|
||||
use rustc_span::Symbol;
|
||||
use rustc_target::spec::SanitizerSet;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use std::num::NonZero;
|
||||
|
||||
use rustc_ast::NodeId;
|
||||
use rustc_attr_parsing::{
|
||||
use rustc_attr_data_structures::{
|
||||
self as attr, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability,
|
||||
};
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::fmt;
|
|||
use std::hash::Hash;
|
||||
|
||||
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
|
||||
use rustc_attr_parsing::InlineAttr;
|
||||
use rustc_attr_data_structures::InlineAttr;
|
||||
use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN};
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
|
|
|
@ -231,9 +231,9 @@ trivial! {
|
|||
bool,
|
||||
Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>,
|
||||
Option<rustc_ast::expand::allocator::AllocatorKind>,
|
||||
Option<rustc_attr_parsing::ConstStability>,
|
||||
Option<rustc_attr_parsing::DefaultBodyStability>,
|
||||
Option<rustc_attr_parsing::Stability>,
|
||||
Option<rustc_attr_data_structures::ConstStability>,
|
||||
Option<rustc_attr_data_structures::DefaultBodyStability>,
|
||||
Option<rustc_attr_data_structures::Stability>,
|
||||
Option<rustc_data_structures::svh::Svh>,
|
||||
Option<rustc_hir::def::DefKind>,
|
||||
Option<rustc_hir::CoroutineKind>,
|
||||
|
@ -256,10 +256,10 @@ trivial! {
|
|||
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
|
||||
rustc_abi::ReprOptions,
|
||||
rustc_ast::expand::allocator::AllocatorKind,
|
||||
rustc_attr_parsing::ConstStability,
|
||||
rustc_attr_parsing::DefaultBodyStability,
|
||||
rustc_attr_parsing::Deprecation,
|
||||
rustc_attr_parsing::Stability,
|
||||
rustc_attr_data_structures::ConstStability,
|
||||
rustc_attr_data_structures::DefaultBodyStability,
|
||||
rustc_attr_data_structures::Deprecation,
|
||||
rustc_attr_data_structures::Stability,
|
||||
rustc_data_structures::svh::Svh,
|
||||
rustc_errors::ErrorGuaranteed,
|
||||
rustc_hir::Constness,
|
||||
|
|
|
@ -41,7 +41,7 @@ use rustc_span::def_id::LOCAL_CRATE;
|
|||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::{DUMMY_SP, Span, Symbol};
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
use {rustc_abi as abi, rustc_ast as ast, rustc_attr_parsing as attr, rustc_hir as hir};
|
||||
use {rustc_abi as abi, rustc_ast as ast, rustc_attr_data_structures as attr, rustc_hir as hir};
|
||||
|
||||
use crate::infer::canonical::{self, Canonical};
|
||||
use crate::lint::LintExpectation;
|
||||
|
|
|
@ -203,7 +203,7 @@ impl<'tcx> Instance<'tcx> {
|
|||
if !tcx.sess.opts.share_generics()
|
||||
// However, if the def_id is marked inline(never), then it's fine to just reuse the
|
||||
// upstream monomorphization.
|
||||
&& tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_parsing::InlineAttr::Never
|
||||
&& tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_data_structures::InlineAttr::Never
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ pub use intrinsic::IntrinsicDef;
|
|||
use rustc_abi::{Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, VariantIdx};
|
||||
use rustc_ast::expand::StrippedCfgItem;
|
||||
use rustc_ast::node_id::NodeMap;
|
||||
use rustc_attr_parsing::AttributeKind;
|
||||
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
|
||||
use rustc_attr_data_structures::AttributeKind;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
|
@ -51,7 +52,7 @@ pub use rustc_type_ir::relate::VarianceDiagInfo;
|
|||
pub use rustc_type_ir::*;
|
||||
use tracing::{debug, instrument};
|
||||
pub use vtable::*;
|
||||
use {rustc_ast as ast, rustc_attr_parsing as attr, rustc_hir as hir};
|
||||
use {rustc_ast as ast, rustc_attr_data_structures as attr, rustc_hir as hir};
|
||||
|
||||
pub use self::closure::{
|
||||
BorrowKind, CAPTURE_STRUCT_LOCAL, CaptureInfo, CapturedPlace, ClosureTypeInfo,
|
||||
|
@ -1757,7 +1758,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
/// Gets all attributes.
|
||||
///
|
||||
/// To see if an item has a specific attribute, you should use [`rustc_attr_parsing::find_attr!`] so you can use matching.
|
||||
/// To see if an item has a specific attribute, you should use [`rustc_attr_data_structures::find_attr!`] so you can use matching.
|
||||
pub fn get_all_attrs(
|
||||
self,
|
||||
did: impl Into<DefId>,
|
||||
|
|
|
@ -80,10 +80,10 @@ trivially_parameterized_over_tcx! {
|
|||
rustc_ast::Attribute,
|
||||
rustc_ast::DelimArgs,
|
||||
rustc_ast::expand::StrippedCfgItem<rustc_hir::def_id::DefIndex>,
|
||||
rustc_attr_parsing::ConstStability,
|
||||
rustc_attr_parsing::DefaultBodyStability,
|
||||
rustc_attr_parsing::Deprecation,
|
||||
rustc_attr_parsing::Stability,
|
||||
rustc_attr_data_structures::ConstStability,
|
||||
rustc_attr_data_structures::DefaultBodyStability,
|
||||
rustc_attr_data_structures::Deprecation,
|
||||
rustc_attr_data_structures::Stability,
|
||||
rustc_hir::Constness,
|
||||
rustc_hir::Defaultness,
|
||||
rustc_hir::Safety,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue