diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 218126e64de9..5b31c421bf34 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -7,7 +7,6 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::msg; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::definitions::DefPathData; use rustc_hir::{HirId, Target, find_attr}; @@ -805,7 +804,7 @@ pub(super) fn maybe_forward_track_caller( ) { if self.tcx.features().async_fn_track_caller() && let Some(attrs) = self.attrs.get(&outer_hir_id.local_id) - && find_attr!(*attrs, AttributeKind::TrackCaller(_)) + && find_attr!(*attrs, TrackCaller(_)) { let unstable_span = self.mark_span_with_reason( DesugaringKind::Async, @@ -1072,7 +1071,7 @@ fn lower_expr_closure( let (binder_clause, generic_params) = self.lower_closure_binder(binder); let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| { - let mut coroutine_kind = find_attr!(attrs, AttributeKind::Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable)); + let mut coroutine_kind = find_attr!(attrs, Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable)); // FIXME(contracts): Support contracts on closures? let body_id = this.lower_fn_body(decl, None, |this| { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 8ae117f62786..4f58fef2d24c 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -243,7 +243,7 @@ fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> { vis_span, span: self.lower_span(i.span), has_delayed_lints: !self.delayed_lints.is_empty(), - eii: find_attr!(attrs, AttributeKind::EiiImpls(..) | AttributeKind::EiiDeclaration(..)), + eii: find_attr!(attrs, EiiImpls(..) | EiiDeclaration(..)), }; self.arena.alloc(item) } @@ -707,10 +707,7 @@ fn lower_use_tree( vis_span, span: this.lower_span(use_tree.span), has_delayed_lints: !this.delayed_lints.is_empty(), - eii: find_attr!( - attrs, - AttributeKind::EiiImpls(..) | AttributeKind::EiiDeclaration(..) - ), + eii: find_attr!(attrs, EiiImpls(..) | EiiDeclaration(..)), }; hir::OwnerNode::Item(this.arena.alloc(item)) }); @@ -1415,9 +1412,7 @@ fn lower_maybe_coroutine_body( // create a fake body so that the entire rest of the compiler doesn't have to deal with // this as a special case. return self.lower_fn_body(decl, contract, |this| { - if find_attr!(attrs, AttributeKind::RustcIntrinsic) - || this.tcx.is_sdylib_interface_build() - { + if find_attr!(attrs, RustcIntrinsic) || this.tcx.is_sdylib_interface_build() { let span = this.lower_span(span); let empty_block = hir::Block { hir_id: this.next_id(), @@ -1695,7 +1690,7 @@ pub(super) fn lower_fn_header( let safety = self.lower_safety(h.safety, default_safety); // Treat safe `#[target_feature]` functions as unsafe, but also remember that we did so. - let safety = if find_attr!(attrs, AttributeKind::TargetFeature { was_forced: false, .. }) + let safety = if find_attr!(attrs, TargetFeature { was_forced: false, .. }) && safety.is_safe() && !self.tcx.sess.target.is_like_wasm { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index db9f27e4603a..24a7215ddb38 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -47,7 +47,6 @@ use rustc_data_structures::sync::spawn; use rustc_data_structures::tagged_ptr::TaggedRef; use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId}; use rustc_hir::definitions::{DefPathData, DisambiguatorState}; @@ -255,10 +254,10 @@ fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'_>) -> Option fn_indexes + RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes ) .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect()) } diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index 0d1925f138c7..dd6eb1794757 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -7,7 +7,6 @@ use polonius_engine::{Algorithm, AllFacts, Output}; use rustc_data_structures::frozen::Frozen; -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_index::IndexSlice; use rustc_middle::mir::pretty::PrettyPrintMirOptions; @@ -296,7 +295,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>( ) { let tcx = infcx.tcx; let base_def_id = tcx.typeck_root_def_id(body.source.def_id()); - if !find_attr!(tcx, base_def_id, AttributeKind::RustcRegions) { + if !find_attr!(tcx, base_def_id, RustcRegions) { return; } diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index e66df3691377..546fa87ff561 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -460,7 +460,8 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( { to_add.push(create_alloc_family_attr(cx.llcx)); if let Some(instance) = instance - && let Some(name) = find_attr!(tcx, instance.def_id(), rustc_hir::attrs::AttributeKind::RustcAllocatorZeroedVariant {name} => name) + && let Some(name) = + find_attr!(tcx, instance.def_id(), RustcAllocatorZeroedVariant {name} => name) { to_add.push(llvm::CreateAttrStringValue( cx.llcx, diff --git a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs index 081fe0aa91aa..9858d9335dc6 100644 --- a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs +++ b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs @@ -28,7 +28,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::{DiagArgValue, IntoDiagArg}; -use rustc_hir::attrs::{AttributeKind, CguFields, CguKind}; +use rustc_hir::attrs::{CguFields, CguKind}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{self as hir, find_attr}; use rustc_middle::mir::mono::CodegenUnitNameBuilder; @@ -89,7 +89,7 @@ struct AssertModuleSource<'tcx> { impl<'tcx> AssertModuleSource<'tcx> { fn check_attrs(&mut self, attrs: &[hir::Attribute]) { for &(span, cgu_fields) in find_attr!(attrs, - AttributeKind::RustcCguTestAttr(e) => e) + RustcCguTestAttr(e) => e) .into_iter() .flatten() { diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 1448ae674a90..8ffab7a4d8f7 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -18,7 +18,6 @@ Level, MultiSpan, Style, Suggestions, catch_fatal_errors, }; use rustc_fs_util::link_or_copy; -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_incremental::{ copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess, @@ -454,7 +453,7 @@ pub(crate) fn start_async_codegen( ) -> OngoingCodegen { let (coordinator_send, coordinator_receive) = channel(); - let no_builtins = find_attr!(tcx, crate, AttributeKind::NoBuiltins); + let no_builtins = find_attr!(tcx, crate, NoBuiltins); let crate_info = CrateInfo::new(tcx, target_cpu); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index b8bc585d16a3..0d3fc63a69bd 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -13,7 +13,7 @@ use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; use rustc_data_structures::unord::UnordMap; -use rustc_hir::attrs::{AttributeKind, DebuggerVisualizerType, OptimizeAttr}; +use rustc_hir::attrs::{DebuggerVisualizerType, OptimizeAttr}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_hir::{ItemId, Target, find_attr}; @@ -894,8 +894,7 @@ pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo { let linked_symbols = crate_types.iter().map(|&c| (c, crate::back::linker::linked_symbols(tcx, c))).collect(); let local_crate_name = tcx.crate_name(LOCAL_CRATE); - let windows_subsystem = - find_attr!(tcx, crate, AttributeKind::WindowsSubsystem(kind, _) => *kind); + let windows_subsystem = find_attr!(tcx, crate, WindowsSubsystem(kind, _) => *kind); // This list is used when generating the command line to pass through to // system linker. The linker expects undefined symbols on the left of the diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index fbed5c96e1c4..6b0d46f5dc5d 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -230,7 +230,7 @@ fn process_builtin_attrs( for i in impls { let foreign_item = match i.resolution { EiiImplResolution::Macro(def_id) => { - let Some(extern_item) = find_attr!(tcx, def_id, AttributeKind::EiiDeclaration(target) => target.foreign_item + let Some(extern_item) = find_attr!(tcx, def_id, EiiDeclaration(target) => target.foreign_item ) else { tcx.dcx().span_delayed_bug( i.span, @@ -350,7 +350,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code // When `no_builtins` is applied at the crate level, we should add the // `no-builtins` attribute to each function to ensure it takes effect in LTO. - let no_builtins = find_attr!(tcx, crate, AttributeKind::NoBuiltins); + let no_builtins = find_attr!(tcx, crate, NoBuiltins); if no_builtins { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS; } @@ -480,7 +480,7 @@ fn check_result( .map(|features| (features.name.as_str(), true)) .collect(), ) { - let span = find_attr!(tcx, did, AttributeKind::TargetFeature{attr_span: span, ..} => *span) + let span = find_attr!(tcx, did, TargetFeature{attr_span: span, ..} => *span) .unwrap_or_else(|| tcx.def_span(did)); tcx.dcx() @@ -500,7 +500,7 @@ fn handle_lang_items( attrs: &[Attribute], codegen_fn_attrs: &mut CodegenFnAttrs, ) { - let lang_item = find_attr!(attrs, AttributeKind::Lang(lang, _) => lang); + let lang_item = find_attr!(attrs, Lang(lang, _) => lang); // Weak lang items have the same semantics as "std internal" symbols in the // sense that they're preserved through all our LTO passes and only @@ -579,7 +579,8 @@ fn sanitizer_settings_for(tcx: TyCtxt<'_>, did: LocalDefId) -> SanitizerFnAttrs }; // Check for a sanitize annotation directly on this def. - if let Some((on_set, off_set, rtsan)) = find_attr!(tcx, did, AttributeKind::Sanitize {on_set, off_set, rtsan, ..} => (on_set, off_set, rtsan)) + if let Some((on_set, off_set, rtsan)) = + find_attr!(tcx, did, Sanitize {on_set, off_set, rtsan, ..} => (on_set, off_set, rtsan)) { // the on set is the set of sanitizers explicitly enabled. // we mask those out since we want the set of disabled sanitizers here diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index b1a93acdfc6b..e4f99be339df 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -7,7 +7,6 @@ use rustc_data_structures::assert_matches; use rustc_errors::{Diag, ErrorGuaranteed}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, LangItem, find_attr}; @@ -216,7 +215,7 @@ pub fn check_body(&mut self) { return; } - if !find_attr!(tcx, def_id, AttributeKind::RustcDoNotConstCheck) { + if !find_attr!(tcx, def_id, RustcDoNotConstCheck) { self.visit_body(body); } diff --git a/compiler/rustc_const_eval/src/check_consts/mod.rs b/compiler/rustc_const_eval/src/check_consts/mod.rs index ed4bbe467f94..3f4527a8750b 100644 --- a/compiler/rustc_const_eval/src/check_consts/mod.rs +++ b/compiler/rustc_const_eval/src/check_consts/mod.rs @@ -5,7 +5,6 @@ //! it finds operations that are invalid in a certain context. use rustc_errors::DiagCtxtHandle; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, find_attr}; use rustc_middle::ty::{self, PolyFnSig, TyCtxt}; @@ -81,7 +80,7 @@ pub fn rustc_allow_const_fn_unstable( def_id: LocalDefId, feature_gate: Symbol, ) -> bool { - find_attr!(tcx, def_id, AttributeKind::RustcAllowConstFnUnstable(syms, _) if syms.contains(&feature_gate)) + find_attr!(tcx, def_id, RustcAllowConstFnUnstable(syms, _) if syms.contains(&feature_gate)) } /// Returns `true` if the given `def_id` (trait or function) is "safe to expose on stable". diff --git a/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs index d27d66a9de28..34d4ce9f9f2c 100644 --- a/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs +++ b/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs @@ -1,4 +1,3 @@ -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{self, BasicBlock, Location}; @@ -36,7 +35,7 @@ pub fn check_live_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) { return; } - if find_attr!(tcx, body.source.def_id(), AttributeKind::RustcDoNotConstCheck) { + if find_attr!(tcx, body.source.def_id(), RustcDoNotConstCheck) { return; } diff --git a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs index 46cdca53ba8c..ad4c9aa5ff9b 100644 --- a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs @@ -1,4 +1,3 @@ -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{ Constness, ExprKind, ForeignItemKind, ImplItem, ImplItemImplKind, ImplItemKind, Item, ItemKind, @@ -38,7 +37,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Constness { } } Node::TraitItem(ti @ TraitItem { kind: TraitItemKind::Fn(..), .. }) => { - if find_attr!(tcx.hir_attrs(ti.hir_id()), AttributeKind::RustcNonConstTraitMethod) { + if find_attr!(tcx.hir_attrs(ti.hir_id()), RustcNonConstTraitMethod) { Constness::NotConst } else { tcx.trait_def(tcx.local_parent(def_id)).constness diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 4a215f277cf7..025c59747eaf 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -6,7 +6,6 @@ use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry}; use rustc_errors::msg; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem, find_attr}; use rustc_middle::mir::AssertMessage; @@ -441,9 +440,7 @@ fn find_mir_or_eval_fn( // sensitive check here. But we can at least rule out functions that are not const at // all. That said, we have to allow calling functions inside a `const trait`. These // *are* const-checked! - if !ecx.tcx.is_const_fn(def) - || find_attr!(ecx.tcx, def, AttributeKind::RustcDoNotConstCheck) - { + if !ecx.tcx.is_const_fn(def) || find_attr!(ecx.tcx, def, RustcDoNotConstCheck) { // We certainly do *not* want to actually call the fn // though, so be sure we return here. throw_unsup_format!("calling non-const function `{}`", instance) diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index ff9b177ac1e2..b8205bda6852 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -7,7 +7,6 @@ use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx}; use rustc_data_structures::assert_matches; use rustc_errors::msg; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::DefId; use rustc_hir::find_attr; use rustc_middle::ty::layout::{IntegerExt, TyAndLayout}; @@ -142,9 +141,8 @@ fn unfold_npo(&self, layout: TyAndLayout<'tcx>) -> InterpResult<'tcx, TyAndLayou // Check if the inner type is one of the NPO-guaranteed ones. // For that we first unpeel transparent *structs* (but not unions). - let is_npo = |def: AdtDef<'tcx>| { - find_attr!(self.tcx, def.did(), AttributeKind::RustcNonnullOptimizationGuaranteed) - }; + let is_npo = + |def: AdtDef<'tcx>| find_attr!(self.tcx, def.did(), RustcNonnullOptimizationGuaranteed); let inner = self.unfold_transparent(inner, /* may_unfold */ |def| { // Stop at NPO types so that we don't miss that attribute in the check below! def.is_struct() && !is_npo(def) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 476be94efd9e..ae3022b83e56 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -15,7 +15,7 @@ use rustc_errors::{BufferedEarlyLint, DiagCtxtHandle, ErrorGuaranteed, PResult}; use rustc_feature::Features; use rustc_hir as hir; -use rustc_hir::attrs::{AttributeKind, CfgEntry, CollapseMacroDebuginfo, Deprecation}; +use rustc_hir::attrs::{CfgEntry, CollapseMacroDebuginfo, Deprecation}; use rustc_hir::def::MacroKinds; use rustc_hir::limit::Limit; use rustc_hir::{Stability, find_attr}; @@ -896,14 +896,13 @@ pub fn default(kind: SyntaxExtensionKind, edition: Edition) -> SyntaxExtension { /// | yes | yes | yes | yes | yes | fn get_collapse_debuginfo(sess: &Session, attrs: &[hir::Attribute], ext: bool) -> bool { let flag = sess.opts.cg.collapse_macro_debuginfo; - let attr = - if let Some(info) = find_attr!(attrs, AttributeKind::CollapseDebugInfo(info) => info) { - info.clone() - } else if find_attr!(attrs, AttributeKind::RustcBuiltinMacro { .. }) { - CollapseMacroDebuginfo::Yes - } else { - CollapseMacroDebuginfo::Unspecified - }; + let attr = if let Some(info) = find_attr!(attrs, CollapseDebugInfo(info) => info) { + info.clone() + } else if find_attr!(attrs, RustcBuiltinMacro { .. }) { + CollapseMacroDebuginfo::Yes + } else { + CollapseMacroDebuginfo::Unspecified + }; #[rustfmt::skip] let collapse_table = [ @@ -918,7 +917,7 @@ fn get_collapse_debuginfo(sess: &Session, attrs: &[hir::Attribute], ext: bool) - fn get_hide_backtrace(attrs: &[hir::Attribute]) -> bool { // FIXME(estebank): instead of reusing `#[rustc_diagnostic_item]` as a proxy, introduce a // new attribute purely for this under the `#[diagnostic]` namespace. - find_attr!(attrs, AttributeKind::RustcDiagnosticItem(..)) + find_attr!(attrs, RustcDiagnosticItem(..)) } /// Constructs a syntax extension with the given properties @@ -933,19 +932,17 @@ pub fn new( attrs: &[hir::Attribute], is_local: bool, ) -> SyntaxExtension { - let allow_internal_unstable = - find_attr!(attrs, AttributeKind::AllowInternalUnstable(i, _) => i) - .map(|i| i.as_slice()) - .unwrap_or_default(); - let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe(_)); + let allow_internal_unstable = find_attr!(attrs, AllowInternalUnstable(i, _) => i) + .map(|i| i.as_slice()) + .unwrap_or_default(); + let allow_internal_unsafe = find_attr!(attrs, AllowInternalUnsafe(_)); let local_inner_macros = - *find_attr!(attrs, AttributeKind::MacroExport {local_inner_macros: l, ..} => l) - .unwrap_or(&false); + *find_attr!(attrs, MacroExport {local_inner_macros: l, ..} => l).unwrap_or(&false); let collapse_debuginfo = Self::get_collapse_debuginfo(sess, attrs, !is_local); tracing::debug!(?name, ?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe); - let (builtin_name, helper_attrs) = match find_attr!(attrs, AttributeKind::RustcBuiltinMacro { builtin_name, helper_attrs, .. } => (builtin_name, helper_attrs)) + let (builtin_name, helper_attrs) = match find_attr!(attrs, RustcBuiltinMacro { builtin_name, helper_attrs, .. } => (builtin_name, helper_attrs)) { // Override `helper_attrs` passed above if it's a built-in macro, // marking `proc_macro_derive` macros as built-in is not a realistic use case. @@ -959,10 +956,9 @@ pub fn new( }; let hide_backtrace = builtin_name.is_some() || Self::get_hide_backtrace(attrs); - let stability = find_attr!(attrs, AttributeKind::Stability { stability, .. } => *stability); + let stability = find_attr!(attrs, Stability { stability, .. } => *stability); - if let Some(sp) = find_attr!(attrs, AttributeKind::RustcBodyStability{ span, .. } => *span) - { + if let Some(sp) = find_attr!(attrs, RustcBodyStability{ span, .. } => *span) { sess.dcx().emit_err(errors::MacroBodyStability { span: sp, head_span: sess.source_map().guess_head_span(span), @@ -978,7 +974,7 @@ pub fn new( stability, deprecation: find_attr!( attrs, - AttributeKind::Deprecation { deprecation, .. } => *deprecation + Deprecation { deprecation, .. } => *deprecation ), helper_attrs, edition, diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 7cd96211de50..7ff49e040f6f 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -14,7 +14,6 @@ use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan}; use rustc_feature::Features; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::MacroKinds; use rustc_hir::find_attr; use rustc_lint_defs::builtin::{ @@ -819,7 +818,7 @@ pub fn compile_declarative_macro( } assert!(!kinds.is_empty()); - let transparency = find_attr!(attrs, AttributeKind::RustcMacroTransparency(x) => *x) + let transparency = find_attr!(attrs, RustcMacroTransparency(x) => *x) .unwrap_or(Transparency::fallback(macro_rules)); if let Some(guar) = guar { diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index d057630bac33..04773ad3f8bc 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -6,10 +6,9 @@ use rustc_errors::codes::*; use rustc_errors::{EmissionGuarantee, MultiSpan}; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::attrs::ReprAttr::ReprPacked; use rustc_hir::def::{CtorKind, DefKind}; -use rustc_hir::{LangItem, Node, attrs, find_attr, intravisit}; +use rustc_hir::{LangItem, Node, find_attr, intravisit}; use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt}; use rustc_infer::traits::{Obligation, ObligationCauseCode, WellFormedLoc}; use rustc_lint_defs::builtin::{REPR_TRANSPARENT_NON_ZST_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS}; @@ -79,7 +78,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi pub fn check_custom_abi(tcx: TyCtxt<'_>, def_id: LocalDefId, fn_sig: FnSig<'_>, fn_sig_span: Span) { if fn_sig.abi == ExternAbi::Custom { // Function definitions that use `extern "custom"` must be naked functions. - if !find_attr!(tcx, def_id, AttributeKind::Naked(_)) { + if !find_attr!(tcx, def_id, Naked(_)) { tcx.dcx().emit_err(crate::errors::AbiCustomClothedFunction { span: fn_sig_span, naked_span: tcx.def_span(def_id).shrink_to_lo(), @@ -981,7 +980,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), (0, _) => ("const", "consts", None), _ => ("type or const", "types or consts", None), }; - let name = if find_attr!(tcx, def_id, AttributeKind::EiiForeignItem) { + let name = if find_attr!(tcx, def_id, EiiForeignItem) { "externally implementable items" } else { "foreign items" @@ -1372,7 +1371,7 @@ fn check_impl_items_against_trait<'tcx>( } if let Some(missing_items) = must_implement_one_of { - let attr_span = find_attr!(tcx, trait_ref.def_id, AttributeKind::RustcMustImplementOneOf {attr_span, ..} => *attr_span); + let attr_span = find_attr!(tcx, trait_ref.def_id, RustcMustImplementOneOf {attr_span, ..} => *attr_span); missing_items_must_implement_one_of_err( tcx, @@ -1555,8 +1554,7 @@ fn check_scalable_vector(tcx: TyCtxt<'_>, span: Span, def_id: LocalDefId, scalab pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) { let repr = def.repr(); if repr.packed() { - if let Some(reprs) = find_attr!(tcx, def.did(), AttributeKind::Repr { reprs, .. } => reprs) - { + if let Some(reprs) = find_attr!(tcx, def.did(), Repr { reprs, .. } => reprs) { for (r, _) in reprs { if let ReprPacked(pack) = r && let Some(repr_pack) = repr.pack @@ -1723,9 +1721,7 @@ fn check_unsuited<'tcx>( ty::Tuple(list) => list.iter().try_for_each(|t| check_unsuited(tcx, typing_env, t)), ty::Array(ty, _) => check_unsuited(tcx, typing_env, *ty), ty::Adt(def, args) => { - if !def.did().is_local() - && !find_attr!(tcx, def.did(), AttributeKind::RustcPubTransparent(_)) - { + if !def.did().is_local() && !find_attr!(tcx, def.did(), RustcPubTransparent(_)) { let non_exhaustive = def.is_variant_list_non_exhaustive() || def.variants().iter().any(ty::VariantDef::is_field_list_non_exhaustive); let has_priv = def.all_fields().any(|f| !f.vis.is_public()); @@ -1796,7 +1792,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) { def.destructor(tcx); // force the destructor to be evaluated if def.variants().is_empty() { - find_attr!(tcx, def_id, attrs::AttributeKind::Repr { reprs, first_span } => { + find_attr!(tcx, def_id, Repr { reprs, first_span } => { struct_span_code_err!( tcx.dcx(), reprs.first().map(|repr| repr.1).unwrap_or(*first_span), diff --git a/compiler/rustc_hir_analysis/src/check/compare_eii.rs b/compiler/rustc_hir_analysis/src/check/compare_eii.rs index 43fbcb492160..9443aaac2258 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_eii.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_eii.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{Applicability, E0806, struct_span_code_err}; -use rustc_hir::attrs::{AttributeKind, EiiImplResolution}; +use rustc_hir::attrs::EiiImplResolution; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, FnSig, HirId, ItemKind, find_attr}; use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt}; @@ -177,7 +177,7 @@ fn check_no_generics<'tcx>( // since in that case it looks like a duplicate error: the declaration of the EII already can't contain generics. // So, we check here if at least one of the eii impls has ImplResolution::Macro, which indicates it's // not generated as part of the declaration. - && find_attr!(tcx, external_impl, AttributeKind::EiiImpls(impls) if impls.iter().any(|i| matches!(i.resolution, EiiImplResolution::Macro(_))) + && find_attr!(tcx, external_impl, EiiImpls(impls) if impls.iter().any(|i| matches!(i.resolution, EiiImplResolution::Macro(_))) ) { tcx.dcx().emit_err(EiiWithGenerics { diff --git a/compiler/rustc_hir_analysis/src/check/entry.rs b/compiler/rustc_hir_analysis/src/check/entry.rs index 25eef5e9bde3..a6dae521db88 100644 --- a/compiler/rustc_hir_analysis/src/check/entry.rs +++ b/compiler/rustc_hir_analysis/src/check/entry.rs @@ -2,7 +2,6 @@ use rustc_abi::ExternAbi; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{Node, find_attr}; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::span_bug; @@ -99,8 +98,7 @@ fn main_fn_return_type_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option { error = true; } - if let Some(attr_span) = find_attr!(tcx, main_def_id, AttributeKind::TrackCaller(span) => *span) - { + if let Some(attr_span) = find_attr!(tcx, main_def_id, TrackCaller(span) => *span) { tcx.dcx().emit_err(errors::TrackCallerOnMain { span: attr_span, annotated: main_span }); error = true; } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 1e6bdddf11d6..ed951015a4f1 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::codes::*; use rustc_errors::{Applicability, ErrorGuaranteed, msg, pluralize, struct_span_code_err}; -use rustc_hir::attrs::{AttributeKind, EiiDecl, EiiImpl, EiiImplResolution}; +use rustc_hir::attrs::{EiiDecl, EiiImpl, EiiImplResolution}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; @@ -1197,13 +1197,14 @@ fn check_eiis(tcx: TyCtxt<'_>, def_id: LocalDefId) { // does the function have an EiiImpl attribute? that contains the defid of a *macro* // that was used to mark the implementation. This is a two step process. for EiiImpl { resolution, span, .. } in - find_attr!(tcx, def_id, AttributeKind::EiiImpls(impls) => impls).into_iter().flatten() + find_attr!(tcx, def_id, EiiImpls(impls) => impls).into_iter().flatten() { let (foreign_item, name) = match resolution { EiiImplResolution::Macro(def_id) => { // we expect this macro to have the `EiiMacroFor` attribute, that points to a function // signature that we'd like to compare the function we're currently checking with - if let Some(foreign_item) = find_attr!(tcx, *def_id, AttributeKind::EiiDeclaration(EiiDecl {foreign_item: t, ..}) => *t) + if let Some(foreign_item) = + find_attr!(tcx, *def_id, EiiDeclaration(EiiDecl {foreign_item: t, ..}) => *t) { (foreign_item, tcx.item_name(*def_id)) } else { diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index 1c37d06d5541..0050fea988f8 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -8,7 +8,6 @@ //! is computed by selecting an idea from this table. use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::find_attr; @@ -79,14 +78,14 @@ fn check_def_id( } if self.tcx.features().rustc_attrs() { - if !find_attr!(self.tcx, ty_def_id, AttributeKind::RustcHasIncoherentInherentImpls) { + if !find_attr!(self.tcx, ty_def_id, RustcHasIncoherentInherentImpls) { let impl_span = self.tcx.def_span(impl_def_id); return Err(self.tcx.dcx().emit_err(errors::InherentTyOutside { span: impl_span })); } let items = self.tcx.associated_item_def_ids(impl_def_id); for &impl_item in items { - if !find_attr!(self.tcx, impl_item, AttributeKind::RustcAllowIncoherentImpl(_)) { + if !find_attr!(self.tcx, impl_item, RustcAllowIncoherentImpl(_)) { let impl_span = self.tcx.def_span(impl_def_id); return Err(self.tcx.dcx().emit_err(errors::InherentTyOutsideRelevant { span: impl_span, @@ -132,8 +131,7 @@ fn check_primitive_impl( if !self.tcx.hir_rustc_coherence_is_core() { if self.tcx.features().rustc_attrs() { for &impl_item in items { - if !find_attr!(self.tcx, impl_item, AttributeKind::RustcAllowIncoherentImpl(_)) - { + if !find_attr!(self.tcx, impl_item, RustcAllowIncoherentImpl(_)) { let span = self.tcx.def_span(impl_def_id); return Err(self.tcx.dcx().emit_err(errors::InherentTyOutsidePrimitive { span, diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 9fa936d87ffd..276bc697eaa9 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -23,7 +23,6 @@ use rustc_data_structures::assert_matches; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, E0228, ErrorGuaranteed, StashKey}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{self, InferKind, Visitor, VisitorExt}; @@ -816,11 +815,9 @@ fn lower_variant<'tcx>( fields, parent_did.to_def_id(), recovered, - adt_kind == AdtKind::Struct - && find_attr!(tcx, parent_did, AttributeKind::NonExhaustive(..)) - || variant_did.is_some_and(|variant_did| { - find_attr!(tcx, variant_did, AttributeKind::NonExhaustive(..)) - }), + adt_kind == AdtKind::Struct && find_attr!(tcx, parent_did, NonExhaustive(..)) + || variant_did + .is_some_and(|variant_did| find_attr!(tcx, variant_did, NonExhaustive(..))), ) } @@ -899,44 +896,42 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { #[allow(deprecated)] let attrs = tcx.get_all_attrs(def_id); - let paren_sugar = find_attr!(attrs, AttributeKind::RustcParenSugar(_)); + let paren_sugar = find_attr!(attrs, RustcParenSugar(_)); if paren_sugar && !tcx.features().unboxed_closures() { tcx.dcx().emit_err(errors::ParenSugarAttribute { span: item.span }); } // Only regular traits can be marker. - let is_marker = !is_alias && find_attr!(attrs, AttributeKind::Marker(_)); + let is_marker = !is_alias && find_attr!(attrs, Marker(_)); - let rustc_coinductive = find_attr!(attrs, AttributeKind::RustcCoinductive(_)); - let is_fundamental = find_attr!(attrs, AttributeKind::Fundamental); + let rustc_coinductive = find_attr!(attrs, RustcCoinductive(_)); + let is_fundamental = find_attr!(attrs, Fundamental); let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!( attrs, - AttributeKind::RustcSkipDuringMethodDispatch { array, boxed_slice, span: _ } => [*array, *boxed_slice] + RustcSkipDuringMethodDispatch { array, boxed_slice, span: _ } => [*array, *boxed_slice] ) .unwrap_or([false; 2]); - let specialization_kind = - if find_attr!(attrs, AttributeKind::RustcUnsafeSpecializationMarker(_)) { - ty::trait_def::TraitSpecializationKind::Marker - } else if find_attr!(attrs, AttributeKind::RustcSpecializationTrait(_)) { - ty::trait_def::TraitSpecializationKind::AlwaysApplicable - } else { - ty::trait_def::TraitSpecializationKind::None - }; + let specialization_kind = if find_attr!(attrs, RustcUnsafeSpecializationMarker(_)) { + ty::trait_def::TraitSpecializationKind::Marker + } else if find_attr!(attrs, RustcSpecializationTrait(_)) { + ty::trait_def::TraitSpecializationKind::AlwaysApplicable + } else { + ty::trait_def::TraitSpecializationKind::None + }; let must_implement_one_of = find_attr!( attrs, - AttributeKind::RustcMustImplementOneOf { fn_names, .. } => + RustcMustImplementOneOf { fn_names, .. } => fn_names .iter() .cloned() .collect::>() ); - let deny_explicit_impl = find_attr!(attrs, AttributeKind::RustcDenyExplicitImpl(_)); - let force_dyn_incompatible = - find_attr!(attrs, AttributeKind::RustcDynIncompatibleTrait(span) => *span); + let deny_explicit_impl = find_attr!(attrs, RustcDenyExplicitImpl(_)); + let force_dyn_incompatible = find_attr!(attrs, RustcDynIncompatibleTrait(span) => *span); ty::TraitDef { def_id: def_id.to_def_id(), @@ -1357,7 +1352,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader .of_trait .unwrap_or_else(|| panic!("expected impl trait, found inherent impl on {def_id:?}")); let selfty = tcx.type_of(def_id).instantiate_identity(); - let is_rustc_reservation = find_attr!(tcx, def_id, AttributeKind::RustcReservationImpl(..)); + let is_rustc_reservation = find_attr!(tcx, def_id, RustcReservationImpl(..)); check_impl_constness(tcx, impl_.constness, &of_trait.trait_ref); diff --git a/compiler/rustc_hir_analysis/src/collect/dump.rs b/compiler/rustc_hir_analysis/src/collect/dump.rs index ad73ea50323d..8534cc26fd94 100644 --- a/compiler/rustc_hir_analysis/src/collect/dump.rs +++ b/compiler/rustc_hir_analysis/src/collect/dump.rs @@ -1,5 +1,4 @@ use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::{find_attr, intravisit}; use rustc_middle::hir::nested_filter; @@ -7,7 +6,7 @@ use rustc_span::sym; pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) { - if !find_attr!(tcx, crate, AttributeKind::RustcHiddenTypeOfOpaques) { + if !find_attr!(tcx, crate, RustcHiddenTypeOfOpaques) { return; } for id in tcx.hir_crate_items(()).opaques() { @@ -28,7 +27,7 @@ pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) { pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) { for id in tcx.hir_crate_items(()).owners() { - if find_attr!(tcx, id, AttributeKind::RustcDumpPredicates) { + if find_attr!(tcx, id, RustcDumpPredicates) { let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates; let span = tcx.def_span(id); @@ -38,7 +37,7 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) { } diag.emit(); } - if find_attr!(tcx, id, AttributeKind::RustcDumpItemBounds) { + if find_attr!(tcx, id, RustcDumpItemBounds) { let bounds = tcx.item_bounds(id).instantiate_identity(); let span = tcx.def_span(id); @@ -54,7 +53,7 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) { pub(crate) fn def_parents(tcx: TyCtxt<'_>) { for iid in tcx.hir_free_items() { let did = iid.owner_id.def_id; - if find_attr!(tcx, did, AttributeKind::RustcDumpDefParents) { + if find_attr!(tcx, did, RustcDumpDefParents) { struct AnonConstFinder<'tcx> { tcx: TyCtxt<'tcx>, anon_consts: Vec, @@ -102,9 +101,7 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) { for id in tcx.hir_free_items() { let def_id = id.owner_id.def_id; - let Some(&attr_span) = - find_attr!(tcx, def_id, AttributeKind::RustcDumpVtable(span) => span) - else { + let Some(&attr_span) = find_attr!(tcx, def_id, RustcDumpVtable(span) => span) else { continue; }; diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index a2236b426305..777610402893 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -2,7 +2,6 @@ use rustc_data_structures::assert_matches; use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::find_attr; @@ -331,9 +330,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // first we would need a way to let std/core use APIs with unstable feature bounds from // within stable APIs. let allow_unstable_feature_attr = - find_attr!(attrs, AttributeKind::UnstableFeatureBound(i) => i) - .map(|i| i.as_slice()) - .unwrap_or_default(); + find_attr!(attrs, UnstableFeatureBound(i) => i).map(|i| i.as_slice()).unwrap_or_default(); for (feat_name, span) in allow_unstable_feature_attr { predicates.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span)); diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index a73009838b0f..ca399964fdd9 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -4,7 +4,6 @@ use rustc_errors::codes::*; use rustc_errors::struct_span_code_err; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{PolyTraitRef, find_attr}; @@ -171,7 +170,7 @@ pub(crate) fn add_implicit_sizedness_bounds( let tcx = self.tcx(); // Skip adding any default bounds if `#![rustc_no_implicit_bounds]` - if find_attr!(tcx, crate, AttributeKind::RustcNoImplicitBounds) { + if find_attr!(tcx, crate, RustcNoImplicitBounds) { return; } @@ -285,7 +284,7 @@ fn should_add_default_traits<'a>( context: ImpliedBoundsContext<'tcx>, ) -> bool { let collected = collect_bounds(hir_bounds, context, trait_def_id); - !find_attr!(self.tcx(), crate, AttributeKind::RustcNoImplicitBounds) && !collected.any() + !find_attr!(self.tcx(), crate, RustcNoImplicitBounds) && !collected.any() } fn reject_duplicate_relaxed_bounds(&self, relaxed_bounds: SmallVec<[&PolyTraitRef<'_>; 1]>) { diff --git a/compiler/rustc_hir_analysis/src/outlives/dump.rs b/compiler/rustc_hir_analysis/src/outlives/dump.rs index 52a0543e27bf..671846a35b26 100644 --- a/compiler/rustc_hir_analysis/src/outlives/dump.rs +++ b/compiler/rustc_hir_analysis/src/outlives/dump.rs @@ -1,4 +1,3 @@ -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_middle::bug; use rustc_middle::ty::{self, TyCtxt}; @@ -6,7 +5,7 @@ pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) { for id in tcx.hir_free_items() { - if !find_attr!(tcx, id.owner_id, AttributeKind::RustcOutlives) { + if !find_attr!(tcx, id.owner_id, RustcOutlives) { continue; } diff --git a/compiler/rustc_hir_analysis/src/variance/dump.rs b/compiler/rustc_hir_analysis/src/variance/dump.rs index 1771f6295fba..db17aaf8de1f 100644 --- a/compiler/rustc_hir_analysis/src/variance/dump.rs +++ b/compiler/rustc_hir_analysis/src/variance/dump.rs @@ -1,6 +1,5 @@ use std::fmt::Write; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; use rustc_middle::ty::{GenericArgs, TyCtxt}; @@ -26,7 +25,7 @@ fn format_variances(tcx: TyCtxt<'_>, def_id: LocalDefId) -> String { pub(crate) fn variances(tcx: TyCtxt<'_>) { let crate_items = tcx.hir_crate_items(()); - if find_attr!(tcx, crate, AttributeKind::RustcVarianceOfOpaques) { + if find_attr!(tcx, crate, RustcVarianceOfOpaques) { for id in crate_items.opaques() { tcx.dcx().emit_err(crate::errors::VariancesOf { span: tcx.def_span(id), @@ -36,7 +35,7 @@ pub(crate) fn variances(tcx: TyCtxt<'_>) { } for id in crate_items.free_items() { - if !find_attr!(tcx, id.owner_id, AttributeKind::RustcVariance) { + if !find_attr!(tcx, id.owner_id, RustcVariance) { continue; } diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index a363cee5a1f1..471aa4384984 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -3,7 +3,6 @@ use rustc_abi::{CanonAbi, ExternAbi}; use rustc_ast::util::parser::ExprPrecedence; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey, msg}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{self, CtorKind, Namespace, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, HirId, LangItem, find_attr}; @@ -526,9 +525,7 @@ fn confirm_builtin_call( // Unit testing: function items annotated with // `#[rustc_evaluate_where_clauses]` trigger special output // to let us test the trait evaluation system. - if self.has_rustc_attrs - && find_attr!(self.tcx, def_id, AttributeKind::RustcEvaluateWhereClauses) - { + if self.has_rustc_attrs && find_attr!(self.tcx, def_id, RustcEvaluateWhereClauses) { let predicates = self.tcx.predicates_of(def_id); let predicates = predicates.instantiate(self.tcx, args); for (predicate, predicate_span) in predicates { @@ -903,9 +900,7 @@ pub(super) fn enforce_context_effects( callee_args: GenericArgsRef<'tcx>, ) { // If we have `rustc_do_not_const_check`, do not check `[const]` bounds. - if self.has_rustc_attrs - && find_attr!(self.tcx, self.body_id, AttributeKind::RustcDoNotConstCheck) - { + if self.has_rustc_attrs && find_attr!(self.tcx, self.body_id, RustcDoNotConstCheck) { return; } diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 6d6de0d3d90d..d9604ceedb15 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1,5 +1,4 @@ use rustc_errors::{Applicability, Diag, MultiSpan, listify}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::Res; use rustc_hir::intravisit::Visitor; use rustc_hir::{self as hir, find_attr}; @@ -1092,7 +1091,7 @@ pub(crate) fn get_conversion_methods_for_diagnostic( // // FIXME? Other potential candidate methods: `as_ref` and // `as_mut`? - && find_attr!(self.tcx, m.def_id, AttributeKind::RustcConversionSuggestion) + && find_attr!(self.tcx, m.def_id, RustcConversionSuggestion) }, ); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index b0b56c869449..8baa67197213 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -15,7 +15,6 @@ Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey, Subdiagnostic, listify, pluralize, struct_span_code_err, }; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; @@ -3676,7 +3675,7 @@ fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) { fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) -> Ty<'tcx> { if let rustc_ast::AsmMacro::NakedAsm = asm.asm_macro { - if !find_attr!(self.tcx, self.body_id, AttributeKind::Naked(..)) { + if !find_attr!(self.tcx, self.body_id, Naked(..)) { self.tcx.dcx().emit_err(NakedAsmOutsideNakedFn { span }); } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 2724e2302009..873e95f13bb9 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -9,7 +9,7 @@ use std::ops::Deref; use rustc_errors::DiagCtxtHandle; -use rustc_hir::attrs::{AttributeKind, DivergingBlockBehavior, DivergingFallbackBehavior}; +use rustc_hir::attrs::{DivergingBlockBehavior, DivergingFallbackBehavior}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, HirId, ItemLocalMap, find_attr}; use rustc_hir_analysis::hir_ty_lowering::{ @@ -515,5 +515,5 @@ fn parse_never_type_options_attr( // Error handling is dubious here (unwraps), but that's probably fine for an internal attribute. // Just don't write incorrect attributes <3 - find_attr!(tcx, crate, AttributeKind::RustcNeverTypeOptions {fallback, diverging_block_default} => (*fallback, *diverging_block_default)).unwrap_or_default() + find_attr!(tcx, crate, RustcNeverTypeOptions {fallback, diverging_block_default} => (*fallback, *diverging_block_default)).unwrap_or_default() } diff --git a/compiler/rustc_hir_typeck/src/loops.rs b/compiler/rustc_hir_typeck/src/loops.rs index 799e82ec13b8..e77c93641e1a 100644 --- a/compiler/rustc_hir_typeck/src/loops.rs +++ b/compiler/rustc_hir_typeck/src/loops.rs @@ -3,7 +3,6 @@ use Context::*; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, Visitor}; @@ -208,7 +207,7 @@ fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) { }; // A `#[const_continue]` must break to a block in a `#[loop_match]`. - if find_attr!(self.tcx.hir_attrs(e.hir_id), AttributeKind::ConstContinue(_)) { + if find_attr!(self.tcx.hir_attrs(e.hir_id), ConstContinue(_)) { let Some(label) = break_destination.label else { let span = e.span; self.tcx.dcx().emit_fatal(ConstContinueBadLabel { span }); @@ -421,7 +420,7 @@ fn is_loop_match( e: &'hir hir::Expr<'hir>, body: &'hir hir::Block<'hir>, ) -> Option { - if !find_attr!(self.tcx.hir_attrs(e.hir_id), AttributeKind::LoopMatch(_)) { + if !find_attr!(self.tcx.hir_attrs(e.hir_id), LoopMatch(_)) { return None; } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 5c1bc20bdbec..b98c9de92ca9 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -6,7 +6,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sso::SsoHashSet; use rustc_errors::Applicability; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::{self as hir, ExprKind, HirId, Node, find_attr}; use rustc_hir_analysis::autoderef::{self, Autoderef}; @@ -2591,7 +2590,7 @@ fn matches_by_doc_alias(&self, def_id: DefId) -> bool { let hir_id = self.fcx.tcx.local_def_id_to_hir_id(local_def_id); let attrs = self.fcx.tcx.hir_attrs(hir_id); - if let Some(d) = find_attr!(attrs, AttributeKind::Doc(d) => d) + if let Some(d) = find_attr!(attrs, Doc(d) => d) && d.aliases.contains_key(&method.name) { return true; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index c0e83f922293..c5e055e68aea 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -16,7 +16,6 @@ use rustc_errors::{ Applicability, Diag, MultiSpan, StashKey, listify, pluralize, struct_span_code_err, }; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, Visitor}; @@ -2261,7 +2260,7 @@ pub(crate) fn confusable_method_name( for inherent_method in self.tcx.associated_items(inherent_impl_did).in_definition_order() { - if let Some(candidates) = find_attr!(self.tcx, inherent_method.def_id, AttributeKind::RustcConfusables{symbols, ..} => symbols) + if let Some(candidates) = find_attr!(self.tcx, inherent_method.def_id, RustcConfusables{symbols, ..} => symbols) && candidates.contains(&item_name.name) && inherent_method.is_fn() { diff --git a/compiler/rustc_hir_typeck/src/naked_functions.rs b/compiler/rustc_hir_typeck/src/naked_functions.rs index 49e4b1feb4d6..c118f49dca6d 100644 --- a/compiler/rustc_hir_typeck/src/naked_functions.rs +++ b/compiler/rustc_hir_typeck/src/naked_functions.rs @@ -1,7 +1,6 @@ //! Checks validity of naked functions. use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::Visitor; use rustc_hir::{ExprKind, HirIdSet, StmtKind, find_attr}; @@ -21,7 +20,7 @@ pub(crate) fn typeck_naked_fn<'tcx>( def_id: LocalDefId, body: &'tcx hir::Body<'tcx>, ) { - debug_assert!(find_attr!(tcx, def_id, AttributeKind::Naked(..))); + debug_assert!(find_attr!(tcx, def_id, Naked(..))); check_no_patterns(tcx, body.params); check_no_parameters_use(tcx, body); check_asm(tcx, def_id, body); diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 49a8dd29dce6..8cc2be9c45e4 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -36,7 +36,6 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::unord::{ExtendUnord, UnordSet}; use rustc_errors::{Applicability, MultiSpan}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{self as hir, HirId, find_attr}; @@ -1743,8 +1742,7 @@ fn place_for_root_variable( } fn should_log_capture_analysis(&self, closure_def_id: LocalDefId) -> bool { - self.has_rustc_attrs - && find_attr!(self.tcx, closure_def_id, AttributeKind::RustcCaptureAnalysis) + self.has_rustc_attrs && find_attr!(self.tcx, closure_def_id, RustcCaptureAnalysis) } fn log_capture_analysis_first_pass( diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 3962b748714e..afb20b3c7cd0 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -14,7 +14,6 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::unord::ExtendUnord; use rustc_errors::{E0720, ErrorGuaranteed}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, InferKind, Visitor}; use rustc_hir::{self as hir, AmbigArg, HirId, find_attr}; @@ -46,8 +45,8 @@ pub(crate) fn resolve_type_vars_in_body( // This attribute causes us to dump some writeback information // in the form of errors, which is used for unit tests. - let rustc_dump_user_args = self.has_rustc_attrs - && find_attr!(self.tcx, item_def_id, AttributeKind::RustcDumpUserArgs); + let rustc_dump_user_args = + self.has_rustc_attrs && find_attr!(self.tcx, item_def_id, RustcDumpUserArgs); let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_args); for param in body.params { diff --git a/compiler/rustc_incremental/src/persist/clean.rs b/compiler/rustc_incremental/src/persist/clean.rs index 47cef5ac2d11..296915284898 100644 --- a/compiler/rustc_incremental/src/persist/clean.rs +++ b/compiler/rustc_incremental/src/persist/clean.rs @@ -352,9 +352,7 @@ fn check_item(&mut self, item_id: LocalDefId) { let item_span = self.tcx.def_span(item_id.to_def_id()); let def_path_hash = self.tcx.def_path_hash(item_id.to_def_id()); - let Some(clean_attrs) = - find_attr!(self.tcx, item_id, AttributeKind::RustcClean(attr) => attr) - else { + let Some(clean_attrs) = find_attr!(self.tcx, item_id, RustcClean(attr) => attr) else { return; }; diff --git a/compiler/rustc_interface/src/limits.rs b/compiler/rustc_interface/src/limits.rs index 10e58f32256f..e0fc91f3b723 100644 --- a/compiler/rustc_interface/src/limits.rs +++ b/compiler/rustc_interface/src/limits.rs @@ -8,7 +8,6 @@ //! Users can override these limits via an attribute on the crate like //! `#![recursion_limit="22"]`. This pass just looks for those attributes. -use rustc_hir::attrs::AttributeKind; use rustc_hir::limit::Limit; use rustc_hir::{Attribute, find_attr}; use rustc_middle::query::Providers; @@ -19,14 +18,12 @@ pub(crate) fn provide(providers: &mut Providers) { let attrs = tcx.hir_krate_attrs(); Limits { recursion_limit: get_recursion_limit(tcx.hir_krate_attrs()), - move_size_limit: - find_attr!(attrs, AttributeKind::MoveSizeLimit { limit, .. } => *limit) - .unwrap_or(Limit::new(tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0))), - type_length_limit: - find_attr!(attrs, AttributeKind::TypeLengthLimit { limit, .. } => *limit) - .unwrap_or(Limit::new(2usize.pow(24))), + move_size_limit: find_attr!(attrs, MoveSizeLimit { limit, .. } => *limit) + .unwrap_or(Limit::new(tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0))), + type_length_limit: find_attr!(attrs, TypeLengthLimit { limit, .. } => *limit) + .unwrap_or(Limit::new(2usize.pow(24))), pattern_complexity_limit: - find_attr!(attrs, AttributeKind::PatternComplexityLimit { limit, .. } => *limit) + find_attr!(attrs, PatternComplexityLimit { limit, .. } => *limit) .unwrap_or(Limit::unlimited()), } } @@ -34,6 +31,5 @@ pub(crate) fn provide(providers: &mut Providers) { // This one is separate because it must be read prior to macro expansion. pub(crate) fn get_recursion_limit(attrs: &[Attribute]) -> Limit { - find_attr!(attrs, AttributeKind::RecursionLimit { limit, .. } => *limit) - .unwrap_or(Limit::new(128)) + find_attr!(attrs, RecursionLimit { limit, .. } => *limit).unwrap_or(Limit::new(128)) } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index f33084afe257..15addd240785 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1199,7 +1199,7 @@ pub(crate) fn start_codegen<'tcx>( // Hook for tests. if let Some((def_id, _)) = tcx.entry_fn(()) - && find_attr!(tcx, def_id, AttributeKind::RustcDelayedBugFromInsideQuery) + && find_attr!(tcx, def_id, RustcDelayedBugFromInsideQuery) { tcx.ensure_ok().trigger_delayed_bug(def_id); } diff --git a/compiler/rustc_interface/src/proc_macro_decls.rs b/compiler/rustc_interface/src/proc_macro_decls.rs index bd08faa1ed3a..63fed51b020a 100644 --- a/compiler/rustc_interface/src/proc_macro_decls.rs +++ b/compiler/rustc_interface/src/proc_macro_decls.rs @@ -1,4 +1,3 @@ -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; use rustc_middle::query::Providers; @@ -8,7 +7,7 @@ fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option { let mut decls = None; for id in tcx.hir_free_items() { - if find_attr!(tcx.hir_attrs(id.hir_id()), AttributeKind::RustcProcMacroDecls) { + if find_attr!(tcx.hir_attrs(id.hir_id()), RustcProcMacroDecls) { decls = Some(id.owner_id.def_id); } } diff --git a/compiler/rustc_lint/src/autorefs.rs b/compiler/rustc_lint/src/autorefs.rs index ecaadad9dfc3..34049288ea80 100644 --- a/compiler/rustc_lint/src/autorefs.rs +++ b/compiler/rustc_lint/src/autorefs.rs @@ -1,5 +1,4 @@ use rustc_ast::{BorrowKind, UnOp}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{Expr, ExprKind, Mutability, find_attr}; use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AutoBorrow, DerefAdjustKind, OverloadedDeref, @@ -108,7 +107,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(expr.hir_id), _ => None, } - && method_did.map(|did| find_attr!(cx.tcx, did, AttributeKind::RustcNoImplicitAutorefs)).unwrap_or(true) + && method_did.map(|did| find_attr!(cx.tcx, did, RustcNoImplicitAutorefs)).unwrap_or(true) { cx.emit_span_lint( DANGEROUS_IMPLICIT_AUTOREFS, diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index c389fd26dbb2..c83de3b38eb5 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -980,15 +980,14 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { let attrs = cx.tcx.hir_attrs(it.hir_id()); match it.kind { hir::ItemKind::Fn { .. } => { - if let Some(attr_span) = - find_attr!(attrs, AttributeKind::ExportName {span, ..} => *span) - .or_else(|| find_attr!(attrs, AttributeKind::NoMangle(span) => *span)) + if let Some(attr_span) = find_attr!(attrs, ExportName {span, ..} => *span) + .or_else(|| find_attr!(attrs, NoMangle(span) => *span)) { self.check_no_mangle_on_generic_fn(cx, attr_span, it.owner_id.def_id); } } hir::ItemKind::Const(ident, generics, ..) => { - if find_attr!(attrs, AttributeKind::NoMangle(..)) { + if find_attr!(attrs, NoMangle(..)) { let suggestion = if generics.params.is_empty() && generics.where_clause_span.is_empty() { // account for "pub const" (#45562) @@ -1014,9 +1013,8 @@ fn check_impl_item(&mut self, cx: &LateContext<'_>, it: &hir::ImplItem<'_>) { let attrs = cx.tcx.hir_attrs(it.hir_id()); match it.kind { hir::ImplItemKind::Fn { .. } => { - if let Some(attr_span) = - find_attr!(attrs, AttributeKind::ExportName {span, ..} => *span) - .or_else(|| find_attr!(attrs, AttributeKind::NoMangle(span) => *span)) + if let Some(attr_span) = find_attr!(attrs, ExportName {span, ..} => *span) + .or_else(|| find_attr!(attrs, NoMangle(span) => *span)) { self.check_no_mangle_on_generic_fn(cx, attr_span, it.owner_id.def_id); } @@ -1178,7 +1176,7 @@ fn check_fn( if fn_kind.asyncness().is_async() && !cx.tcx.features().async_fn_track_caller() // Now, check if the function has the `#[track_caller]` attribute - && let Some(attr_span) = find_attr!(cx.tcx, def_id, AttributeKind::TrackCaller(span) => *span) + && let Some(attr_span) = find_attr!(cx.tcx, def_id, TrackCaller(span) => *span) { cx.emit_span_lint( UNGATED_ASYNC_FN_TRACK_CALLER, diff --git a/compiler/rustc_lint/src/dangling.rs b/compiler/rustc_lint/src/dangling.rs index 16533722d8c0..448c0ded637c 100644 --- a/compiler/rustc_lint/src/dangling.rs +++ b/compiler/rustc_lint/src/dangling.rs @@ -1,5 +1,4 @@ use rustc_ast::visit::{visit_opt, walk_list}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::Res; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{FnKind, Visitor, walk_expr}; @@ -268,7 +267,7 @@ fn lint_expr(cx: &LateContext<'_>, expr: &Expr<'_>) { && let ty = cx.typeck_results().expr_ty(receiver) && owns_allocation(cx.tcx, ty) && let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) - && find_attr!(cx.tcx, fn_id, AttributeKind::RustcAsPtr(_)) + && find_attr!(cx.tcx, fn_id, RustcAsPtr(_)) { // FIXME: use `emit_node_lint` when `#[primary_span]` is added. cx.tcx.emit_node_span_lint( diff --git a/compiler/rustc_lint/src/foreign_modules.rs b/compiler/rustc_lint/src/foreign_modules.rs index f775a7eb163b..d234c6863103 100644 --- a/compiler/rustc_lint/src/foreign_modules.rs +++ b/compiler/rustc_lint/src/foreign_modules.rs @@ -2,7 +2,6 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::find_attr; use rustc_middle::query::Providers; @@ -183,10 +182,7 @@ fn name_of_extern_decl(tcx: TyCtxt<'_>, fi: hir::OwnerId) -> SymbolName { // information, we could have codegen_fn_attrs also give span information back for // where the attribute was defined. However, until this is found to be a // bottleneck, this does just fine. - ( - overridden_link_name, - find_attr!(tcx, fi, AttributeKind::LinkName {span, ..} => *span).unwrap(), - ) + (overridden_link_name, find_attr!(tcx, fi, LinkName {span, ..} => *span).unwrap()) }) { SymbolName::Link(overridden_link_name, overridden_link_name_span) diff --git a/compiler/rustc_lint/src/gpukernel_abi.rs b/compiler/rustc_lint/src/gpukernel_abi.rs index b3a061afd9d0..4fb26739cd28 100644 --- a/compiler/rustc_lint/src/gpukernel_abi.rs +++ b/compiler/rustc_lint/src/gpukernel_abi.rs @@ -1,7 +1,6 @@ use std::iter; use rustc_abi::ExternAbi; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{self as hir, find_attr}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_session::{declare_lint, declare_lint_pass}; @@ -184,7 +183,7 @@ fn check_fn( } // Check for no_mangle/export_name, so the kernel can be found when querying the compiled object for the kernel function by name - if !find_attr!(cx.tcx, id, AttributeKind::NoMangle(..) | AttributeKind::ExportName { .. }) { + if !find_attr!(cx.tcx, id, NoMangle(..) | ExportName { .. }) { cx.emit_span_lint(MISSING_GPU_KERNEL_EXPORT_NAME, span, MissingGpuKernelExportName); } } diff --git a/compiler/rustc_lint/src/interior_mutable_consts.rs b/compiler/rustc_lint/src/interior_mutable_consts.rs index 2ad1dc43bae7..807a121abd9e 100644 --- a/compiler/rustc_lint/src/interior_mutable_consts.rs +++ b/compiler/rustc_lint/src/interior_mutable_consts.rs @@ -1,4 +1,3 @@ -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, ItemKind, Node, find_attr}; use rustc_middle::ty::adjustment::Adjust; @@ -88,7 +87,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { // Let's do the attribute check after the other checks for perf reasons && find_attr!( cx.tcx, method_did, - AttributeKind::RustcShouldNotBeCalledOnConstItems(_) + RustcShouldNotBeCalledOnConstItems(_) ) && let Some(method_name) = cx.tcx.opt_item_ident(method_did) && let Some(const_name) = cx.tcx.opt_item_ident(const_did) diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 7b97ff92e008..87c36f41afab 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -2,7 +2,6 @@ //! Clippy. use rustc_ast::{Pat, PatKind, Path}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::Res; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, HirId, find_attr}; @@ -91,7 +90,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { ty::Instance::try_resolve(cx.tcx, cx.typing_env(), callee_def_id, generic_args) { let def_id = instance.def_id(); - if find_attr!(cx.tcx, def_id, AttributeKind::RustcLintQueryInstability) { + if find_attr!(cx.tcx, def_id, RustcLintQueryInstability) { cx.emit_span_lint( POTENTIAL_QUERY_INSTABILITY, span, @@ -106,7 +105,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { ); } - if find_attr!(cx.tcx, def_id, AttributeKind::RustcLintUntrackedQueryInformation) { + if find_attr!(cx.tcx, def_id, RustcLintUntrackedQueryInformation) { cx.emit_span_lint( UNTRACKED_QUERY_INFORMATION, span, @@ -151,7 +150,7 @@ fn has_unstable_into_iter_predicate<'tcx>( }; // Does the input type's `IntoIterator` implementation have the // `rustc_lint_query_instability` attribute on its `into_iter` method? - if find_attr!(cx.tcx, instance.def_id(), AttributeKind::RustcLintQueryInstability) { + if find_attr!(cx.tcx, instance.def_id(), RustcLintQueryInstability) { return true; } } @@ -503,13 +502,13 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { let Some(adt_def) = cx.typeck_results().expr_ty(base).ty_adt_def() else { return }; // Skip types without `#[rustc_lint_opt_ty]` - only so that the rest of the lint can be // avoided. - if !find_attr!(cx.tcx, adt_def.did(), AttributeKind::RustcLintOptTy) { + if !find_attr!(cx.tcx, adt_def.did(), RustcLintOptTy) { return; } for field in adt_def.all_fields() { if field.name == target.name - && let Some(lint_message) = find_attr!(cx.tcx, field.did, AttributeKind::RustcLintOptDenyFieldAccess { lint_message, } => lint_message) + && let Some(lint_message) = find_attr!(cx.tcx, field.did, RustcLintOptDenyFieldAccess { lint_message, } => lint_message) { cx.emit_span_lint( BAD_OPT_ACCESS, diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 8da452861163..2b9a65f84a02 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -1,5 +1,4 @@ use rustc_errors::{MultiSpan, msg}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{self, Visitor, VisitorExt}; use rustc_hir::{Body, HirId, Item, ItemKind, Node, Path, TyKind, find_attr}; @@ -243,7 +242,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { ) } ItemKind::Macro(_, _macro, _kinds) - if find_attr!(cx.tcx, item.owner_id.def_id, AttributeKind::MacroExport { .. }) => + if find_attr!(cx.tcx, item.owner_id.def_id, MacroExport { .. }) => { cx.emit_span_lint( NON_LOCAL_DEFINITIONS, diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 85d08acb4cf5..1496e3974bd7 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -322,7 +322,7 @@ fn check_mod(&mut self, cx: &LateContext<'_>, _: &'tcx hir::Mod<'tcx>, id: hir:: let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name { Some(Ident::from_str(name)) } else { - find_attr!(cx.tcx, crate, AttributeKind::CrateName{name, name_span,..} => (name, name_span)).map( + find_attr!(cx.tcx, crate, CrateName{name, name_span,..} => (name, name_span)).map( |(&name, &span)| { // Discard the double quotes surrounding the literal. let sp = cx @@ -335,8 +335,7 @@ fn check_mod(&mut self, cx: &LateContext<'_>, _: &'tcx hir::Mod<'tcx>, id: hir:: let right = snippet.rfind('"').map(|pos| snippet.len() - pos)?; Some( - span - .with_lo(span.lo() + BytePos(left as u32 + 1)) + span.with_lo(span.lo() + BytePos(left as u32 + 1)) .with_hi(span.hi() - BytePos(right as u32)), ) }) @@ -370,9 +369,7 @@ fn check_fn( match &fk { FnKind::Method(ident, sig, ..) => match cx.tcx.associated_item(id).container { AssocContainer::InherentImpl => { - if sig.header.abi != ExternAbi::Rust - && find_attr!(cx.tcx, id, AttributeKind::NoMangle(..)) - { + if sig.header.abi != ExternAbi::Rust && find_attr!(cx.tcx, id, NoMangle(..)) { return; } self.check_snake_case(cx, "method", ident); @@ -384,9 +381,7 @@ fn check_fn( }, FnKind::ItemFn(ident, _, header) => { // Skip foreign-ABI #[no_mangle] functions (Issue #31924) - if header.abi != ExternAbi::Rust - && find_attr!(cx.tcx, id, AttributeKind::NoMangle(..)) - { + if header.abi != ExternAbi::Rust && find_attr!(cx.tcx, id, NoMangle(..)) { return; } self.check_snake_case(cx, "function", ident); @@ -551,9 +546,7 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals { fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { let attrs = cx.tcx.hir_attrs(it.hir_id()); match it.kind { - hir::ItemKind::Static(_, ident, ..) - if !find_attr!(attrs, AttributeKind::NoMangle(..)) => - { + hir::ItemKind::Static(_, ident, ..) if !find_attr!(attrs, NoMangle(..)) => { NonUpperCaseGlobals::check_upper_case( cx, "static variable", diff --git a/compiler/rustc_lint/src/pass_by_value.rs b/compiler/rustc_lint/src/pass_by_value.rs index 69c49519144c..5a4eb2943381 100644 --- a/compiler/rustc_lint/src/pass_by_value.rs +++ b/compiler/rustc_lint/src/pass_by_value.rs @@ -1,4 +1,3 @@ -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::Res; use rustc_hir::{self as hir, AmbigArg, GenericArg, PathSegment, QPath, TyKind, find_attr}; use rustc_middle::ty; @@ -43,16 +42,14 @@ fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx, AmbigArg>) fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option { if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind { match path.res { - Res::Def(_, def_id) - if find_attr!(cx.tcx, def_id, AttributeKind::RustcPassByValue(_)) => - { + Res::Def(_, def_id) if find_attr!(cx.tcx, def_id, RustcPassByValue(_)) => { let name = cx.tcx.item_ident(def_id); let path_segment = path.segments.last().unwrap(); return Some(format!("{}{}", name, gen_args(cx, path_segment))); } Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => { if let ty::Adt(adt, args) = cx.tcx.type_of(did).instantiate_identity().kind() { - if find_attr!(cx.tcx, adt.did(), AttributeKind::RustcPassByValue(_)) { + if find_attr!(cx.tcx, adt.did(), RustcPassByValue(_)) { return Some(cx.tcx.def_path_str_with_args(adt.did(), args)); } } diff --git a/compiler/rustc_lint/src/ptr_nulls.rs b/compiler/rustc_lint/src/ptr_nulls.rs index cfc36436a50d..18a80684fa44 100644 --- a/compiler/rustc_lint/src/ptr_nulls.rs +++ b/compiler/rustc_lint/src/ptr_nulls.rs @@ -1,5 +1,4 @@ use rustc_ast::LitKind; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind, find_attr}; use rustc_middle::ty::RawPtr; use rustc_session::{declare_lint, declare_lint_pass}; @@ -73,14 +72,14 @@ fn useless_check<'a, 'tcx: 'a>( e = e.peel_blocks(); if let ExprKind::MethodCall(_, _expr, [], _) = e.kind && let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) - && find_attr!(cx.tcx, def_id, AttributeKind::RustcNeverReturnsNullPointer) + && find_attr!(cx.tcx, def_id, RustcNeverReturnsNullPointer) && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) { return Some(UselessPtrNullChecksDiag::FnRet { fn_name }); } else if let ExprKind::Call(path, _args) = e.kind && let ExprKind::Path(ref qpath) = path.kind && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() - && find_attr!(cx.tcx, def_id, AttributeKind::RustcNeverReturnsNullPointer) + && find_attr!(cx.tcx, def_id, RustcNeverReturnsNullPointer) && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) { return Some(UselessPtrNullChecksDiag::FnRet { fn_name }); diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index ca9a74f822c8..a2427d9ca588 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1,7 +1,6 @@ use std::iter; use rustc_abi::{BackendRepr, TagEncoding, Variants, WrappingRange}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{Expr, ExprKind, HirId, LangItem, find_attr}; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, SizeSkeleton}; @@ -687,7 +686,7 @@ pub(crate) fn nonnull_optimization_guaranteed<'tcx>( tcx: TyCtxt<'tcx>, def: ty::AdtDef<'tcx>, ) -> bool { - find_attr!(tcx, def.did(), AttributeKind::RustcNonnullOptimizationGuaranteed) + find_attr!(tcx, def.did(), RustcNonnullOptimizationGuaranteed) } /// `repr(transparent)` structs can have a single non-1-ZST field, this function returns that diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index ef78fa05e89e..4b3a49af0836 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -4,7 +4,6 @@ use rustc_ast::{self as ast, ExprKind, FnRetTy, HasAttrs as _, StmtKind}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{MultiSpan, pluralize}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, LangItem, find_attr}; @@ -402,7 +401,7 @@ fn is_ty_must_use<'tcx>( fn is_def_must_use(cx: &LateContext<'_>, def_id: DefId, span: Span) -> Option { if let Some(reason) = find_attr!( cx.tcx, def_id, - AttributeKind::MustUse { reason, .. } => reason + MustUse { reason, .. } => reason ) { // check for #[must_use = "..."] Some(MustUsePath::Def(span, def_id, *reason)) diff --git a/compiler/rustc_metadata/src/eii.rs b/compiler/rustc_metadata/src/eii.rs index 7bc63b157814..f3ce07aa75a1 100644 --- a/compiler/rustc_metadata/src/eii.rs +++ b/compiler/rustc_metadata/src/eii.rs @@ -1,5 +1,5 @@ use rustc_data_structures::fx::FxIndexMap; -use rustc_hir::attrs::{AttributeKind, EiiDecl, EiiImpl, EiiImplResolution}; +use rustc_hir::attrs::{EiiDecl, EiiImpl, EiiImplResolution}; use rustc_hir::def_id::DefId; use rustc_hir::find_attr; use rustc_middle::query::LocalCrate; @@ -25,13 +25,11 @@ pub(crate) fn collect<'tcx>(tcx: TyCtxt<'tcx>, LocalCrate: LocalCrate) -> EiiMap // iterate over all items in the current crate for id in tcx.hir_crate_items(()).eiis() { - for i in find_attr!(tcx, id, AttributeKind::EiiImpls(e) => e).into_iter().flatten() { + for i in find_attr!(tcx, id, EiiImpls(e) => e).into_iter().flatten() { let decl = match i.resolution { EiiImplResolution::Macro(macro_defid) => { // find the decl for this one if it wasn't in yet (maybe it's from the local crate? not very useful but not illegal) - let Some(decl) = - find_attr!(tcx, macro_defid, AttributeKind::EiiDeclaration(d) => *d) - else { + let Some(decl) = find_attr!(tcx, macro_defid, EiiDeclaration(d) => *d) else { // skip if it doesn't have eii_declaration (if we resolved to another macro that's not an EII) tcx.dcx() .span_delayed_bug(i.span, "resolved to something that's not an EII"); @@ -51,7 +49,7 @@ pub(crate) fn collect<'tcx>(tcx: TyCtxt<'tcx>, LocalCrate: LocalCrate) -> EiiMap } // if we find a new declaration, add it to the list without a known implementation - if let Some(decl) = find_attr!(tcx, id, AttributeKind::EiiDeclaration(d) => *d) { + if let Some(decl) = find_attr!(tcx, id, EiiDeclaration(d) => *d) { eiis.entry(decl.foreign_item).or_insert((decl, Default::default())); } } diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index e61ef3de9ccb..52b11615c76f 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -4,7 +4,7 @@ use rustc_abi::ExternAbi; use rustc_attr_parsing::eval_config_entry; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::attrs::{AttributeKind, NativeLibKind, PeImportNameType}; +use rustc_hir::attrs::{NativeLibKind, PeImportNameType}; use rustc_hir::find_attr; use rustc_middle::query::LocalCrate; use rustc_middle::ty::{self, List, Ty, TyCtxt}; @@ -213,10 +213,8 @@ fn process_module(&mut self, module: &ForeignModule) { return; } - for attr in find_attr!(self.tcx, def_id, AttributeKind::Link(links, _) => links) - .iter() - .map(|v| v.iter()) - .flatten() + for attr in + find_attr!(self.tcx, def_id, Link(links, _) => links).iter().map(|v| v.iter()).flatten() { let dll_imports = match attr.kind { NativeLibKind::RawDylib { .. } => foreign_items @@ -231,7 +229,8 @@ fn process_module(&mut self, module: &ForeignModule) { .collect(), _ => { for &child_item in foreign_items { - if let Some(span) = find_attr!(self.tcx, child_item, AttributeKind::LinkOrdinal {span, ..} => *span) + if let Some(span) = + find_attr!(self.tcx, child_item, LinkOrdinal {span, ..} => *span) { sess.dcx().emit_err(errors::LinkOrdinalRawDylib { span }); } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index a3d8b07fb1d9..e9ae43b78d54 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -734,16 +734,16 @@ macro_rules! stat { has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE), has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE), has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE), - has_default_lib_allocator: find_attr!(attrs, AttributeKind::DefaultLibAllocator), + has_default_lib_allocator: find_attr!(attrs, DefaultLibAllocator), externally_implementable_items, proc_macro_data, debugger_visualizers, - compiler_builtins: find_attr!(attrs, AttributeKind::CompilerBuiltins), - needs_allocator: find_attr!(attrs, AttributeKind::NeedsAllocator), - needs_panic_runtime: find_attr!(attrs, AttributeKind::NeedsPanicRuntime), - no_builtins: find_attr!(attrs, AttributeKind::NoBuiltins), - panic_runtime: find_attr!(attrs, AttributeKind::PanicRuntime), - profiler_runtime: find_attr!(attrs, AttributeKind::ProfilerRuntime), + compiler_builtins: find_attr!(attrs, CompilerBuiltins), + needs_allocator: find_attr!(attrs, NeedsAllocator), + needs_panic_runtime: find_attr!(attrs, NeedsPanicRuntime), + no_builtins: find_attr!(attrs, NoBuiltins), + panic_runtime: find_attr!(attrs, PanicRuntime), + profiler_runtime: find_attr!(attrs, ProfilerRuntime), symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(), crate_deps, @@ -2012,11 +2012,12 @@ fn encode_proc_macros(&mut self) -> Option { // Proc-macros may have attributes like `#[allow_internal_unstable]`, // so downstream crates need access to them. let attrs = tcx.hir_attrs(proc_macro); - let macro_kind = if find_attr!(attrs, AttributeKind::ProcMacro(..)) { + let macro_kind = if find_attr!(attrs, ProcMacro(..)) { MacroKind::Bang - } else if find_attr!(attrs, AttributeKind::ProcMacroAttribute(..)) { + } else if find_attr!(attrs, ProcMacroAttribute(..)) { MacroKind::Attr - } else if let Some(trait_name) = find_attr!(attrs, AttributeKind::ProcMacroDerive { trait_name, ..} => trait_name) + } else if let Some(trait_name) = + find_attr!(attrs, ProcMacroDerive { trait_name, ..} => trait_name) { name = *trait_name; MacroKind::Derive diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index ca783311586f..67dd26c8a7d3 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -8,7 +8,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::{DynSend, DynSync, par_for_each_in, try_par_for_each_in}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; @@ -369,7 +368,7 @@ pub fn hir_krate_attrs(self) -> &'tcx [Attribute] { } pub fn hir_rustc_coherence_is_core(self) -> bool { - find_attr!(self.hir_krate_attrs(), AttributeKind::RustcCoherenceIsCore(..)) + find_attr!(self.hir_krate_attrs(), RustcCoherenceIsCore(..)) } pub fn hir_get_module(self, module: LocalModDefId) -> (&'tcx Mod<'tcx>, Span, HirId) { diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index 3dc8a1d07609..6367c87b1aa9 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -1,6 +1,5 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::ErrorGuaranteed; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{DefId, DefIdMap}; use rustc_hir::find_attr; use rustc_macros::{HashStable, TyDecodable, TyEncodable}; @@ -62,8 +61,7 @@ pub enum OverlapMode { impl OverlapMode { pub fn get(tcx: TyCtxt<'_>, trait_id: DefId) -> OverlapMode { let with_negative_coherence = tcx.features().with_negative_coherence(); - let strict_coherence = - find_attr!(tcx, trait_id, AttributeKind::RustcStrictCoherence(span) => *span); + let strict_coherence = find_attr!(tcx, trait_id, RustcStrictCoherence(span) => *span); if with_negative_coherence { if strict_coherence.is_some() { OverlapMode::Strict } else { OverlapMode::WithNegative } diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 448be791c9eb..020669588ac5 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -9,7 +9,6 @@ use rustc_data_structures::intern::Interned; use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher}; use rustc_errors::ErrorGuaranteed; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, LangItem, find_attr}; @@ -282,11 +281,11 @@ pub(super) fn new( debug!("AdtDef::new({:?}, {:?}, {:?}, {:?})", did, kind, variants, repr); let mut flags = AdtFlags::NO_ADT_FLAGS; - if kind == AdtKind::Enum && find_attr!(tcx, did, AttributeKind::NonExhaustive(..)) { + if kind == AdtKind::Enum && find_attr!(tcx, did, NonExhaustive(..)) { debug!("found non-exhaustive variant list for {:?}", did); flags = flags | AdtFlags::IS_VARIANT_LIST_NON_EXHAUSTIVE; } - if find_attr!(tcx, did, AttributeKind::PinV2(..)) { + if find_attr!(tcx, did, PinV2(..)) { debug!("found pin-project type {:?}", did); flags |= AdtFlags::IS_PIN_PROJECT; } @@ -301,7 +300,7 @@ pub(super) fn new( flags |= AdtFlags::HAS_CTOR; } - if find_attr!(tcx, did, AttributeKind::Fundamental) { + if find_attr!(tcx, did, Fundamental) { flags |= AdtFlags::IS_FUNDAMENTAL; } if tcx.is_lang_item(did, LangItem::PhantomData) { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 363e429df4e3..47843a260440 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -30,7 +30,6 @@ self, DynSend, DynSync, FreezeReadGuard, Lock, RwLock, WorkerLocal, }; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, LintDiagnostic, MultiSpan}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::definitions::{DefPathData, Definitions, DisambiguatorState}; @@ -994,8 +993,10 @@ pub fn is_sizedness_trait(self, def_id: DefId) -> bool { /// `rustc_layout_scalar_valid_range` attribute. // FIXME(eddyb) this is an awkward spot for this method, maybe move it? pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound, Bound) { - let start = find_attr!(self, def_id, AttributeKind::RustcLayoutScalarValidRangeStart(n, _) => Bound::Included(**n)).unwrap_or(Bound::Unbounded); - let end = find_attr!(self, def_id, AttributeKind::RustcLayoutScalarValidRangeEnd(n, _) => Bound::Included(**n)).unwrap_or(Bound::Unbounded); + let start = find_attr!(self, def_id, RustcLayoutScalarValidRangeStart(n, _) => Bound::Included(**n)).unwrap_or(Bound::Unbounded); + let end = + find_attr!(self, def_id, RustcLayoutScalarValidRangeEnd(n, _) => Bound::Included(**n)) + .unwrap_or(Bound::Unbounded); (start, end) } @@ -2768,7 +2769,7 @@ pub fn needs_coroutine_by_move_body_def_id(self, def_id: DefId) -> bool { /// Whether this is a trait implementation that has `#[diagnostic::do_not_recommend]` pub fn do_not_recommend_impl(self, def_id: DefId) -> bool { - find_attr!(self, def_id, AttributeKind::DoNotRecommend { .. }) + find_attr!(self, def_id, DoNotRecommend { .. }) } pub fn is_trivial_const

(self, def_id: P) -> bool @@ -2794,10 +2795,8 @@ pub fn is_entrypoint(self, def_id: DefId) -> bool { } pub fn provide(providers: &mut Providers) { - providers.is_panic_runtime = - |tcx, LocalCrate| find_attr!(tcx, crate, AttributeKind::PanicRuntime); - providers.is_compiler_builtins = - |tcx, LocalCrate| find_attr!(tcx, crate, AttributeKind::CompilerBuiltins); + providers.is_panic_runtime = |tcx, LocalCrate| find_attr!(tcx, crate, PanicRuntime); + providers.is_compiler_builtins = |tcx, LocalCrate| find_attr!(tcx, crate, CompilerBuiltins); providers.has_panic_handler = |tcx, LocalCrate| { // We want to check if the panic handler was defined in this crate tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 7cdd48b9bf35..8511f227c669 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -37,7 +37,7 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer}; -use rustc_hir::attrs::{AttributeKind, StrippedCfgItem}; +use rustc_hir::attrs::StrippedCfgItem; use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap}; use rustc_hir::{LangItem, attrs as attr, find_attr}; @@ -1442,7 +1442,7 @@ pub fn repr_options_of_def(self, did: LocalDefId) -> ReprOptions { field_shuffle_seed ^= user_seed; } - let elt = find_attr!(self, did, AttributeKind::RustcScalableVector { element_count, .. } => element_count + let elt = find_attr!(self, did, RustcScalableVector { element_count, .. } => element_count ) .map(|elt| match elt { Some(n) => ScalableElt::ElementCount(*n), @@ -1451,7 +1451,7 @@ pub fn repr_options_of_def(self, did: LocalDefId) -> ReprOptions { if elt.is_some() { flags.insert(ReprFlags::IS_SCALABLE); } - if let Some(reprs) = find_attr!(self, did, AttributeKind::Repr { reprs, .. } => reprs) { + if let Some(reprs) = find_attr!(self, did, Repr { reprs, .. } => reprs) { for (r, _) in reprs { flags.insert(match *r { attr::ReprRust => ReprFlags::empty(), @@ -1511,7 +1511,7 @@ pub fn repr_options_of_def(self, did: LocalDefId) -> ReprOptions { } // See `TyAndLayout::pass_indirectly_in_non_rustic_abis` for details. - if find_attr!(self, did, AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)) { + if find_attr!(self, did, RustcPassIndirectlyInNonRusticAbis(..)) { flags.insert(ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS); } @@ -1991,11 +1991,7 @@ pub fn is_builtin_derived(self, def_id: DefId) -> bool { && let Some(def_id) = def_id.as_local() && let outer = self.def_span(def_id).ctxt().outer_expn_data() && matches!(outer.kind, ExpnKind::Macro(MacroKind::Derive, _)) - && find_attr!( - self, - outer.macro_def_id.unwrap(), - AttributeKind::RustcBuiltinMacro { .. } - ) + && find_attr!(self, outer.macro_def_id.unwrap(), RustcBuiltinMacro { .. }) { true } else { @@ -2005,7 +2001,7 @@ pub fn is_builtin_derived(self, def_id: DefId) -> bool { /// Check if the given `DefId` is `#\[automatically_derived\]`. pub fn is_automatically_derived(self, def_id: DefId) -> bool { - find_attr!(self, def_id, AttributeKind::AutomaticallyDerived(..)) + find_attr!(self, def_id, AutomaticallyDerived(..)) } /// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err` diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 22fd22f2bba7..3e69eda11ca6 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -2,7 +2,6 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::ErrorGuaranteed; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::{self as hir, find_attr}; @@ -241,7 +240,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait /// Query provider for `incoherent_impls`. pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] { if let Some(def_id) = simp.def() - && !find_attr!(tcx, def_id, AttributeKind::RustcHasIncoherentInherentImpls) + && !find_attr!(tcx, def_id, RustcHasIncoherentInherentImpls) { return &[]; } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 60ac1e13e849..c3be0b630d6e 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -9,7 +9,6 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorGuaranteed; use rustc_hashes::Hash128; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::limit::Limit; @@ -1671,12 +1670,12 @@ pub fn reveal_opaque_types_in_bounds<'tcx>( /// Determines whether an item is directly annotated with `doc(hidden)`. fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { - find_attr!(tcx, def_id, AttributeKind::Doc(doc) if doc.hidden.is_some()) + find_attr!(tcx, def_id, Doc(doc) if doc.hidden.is_some()) } /// Determines whether an item is annotated with `doc(notable_trait)`. pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool { - find_attr!(tcx, def_id, AttributeKind::Doc(doc) if doc.notable_trait.is_some()) + find_attr!(tcx, def_id, Doc(doc) if doc.notable_trait.is_some()) } /// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute). @@ -1685,7 +1684,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool { /// the compiler to make some assumptions about its shape; if the user doesn't use a feature gate, they may /// cause an ICE that we otherwise may want to prevent. pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { - if tcx.features().intrinsics() && find_attr!(tcx, def_id, AttributeKind::RustcIntrinsic) { + if tcx.features().intrinsics() && find_attr!(tcx, def_id, RustcIntrinsic) { let must_be_overridden = match tcx.hir_node_by_def_id(def_id) { hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { has_body, .. }, .. }) => { !has_body @@ -1695,7 +1694,7 @@ pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option( ty => span_bug!(span_with_body, "unexpected type of body: {ty:?}"), }; - if let Some((dialect, phase)) = find_attr!(tcx.hir_attrs(fn_id), AttributeKind::CustomMir(dialect, phase, _) => (dialect, phase)) + if let Some((dialect, phase)) = + find_attr!(tcx.hir_attrs(fn_id), CustomMir(dialect, phase, _) => (dialect, phase)) { return custom::build_custom_mir( tcx, diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 64bec3ae3818..001c4338ad0e 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -5,7 +5,6 @@ use rustc_ast::AsmMacro; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::DiagArgValue; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, find_attr}; use rustc_middle::middle::codegen_fn_attrs::{TargetFeature, TargetFeatureKind}; @@ -98,7 +97,7 @@ fn emit_deprecated_safe_fn_call(&self, span: Span, kind: &UnsafeOpKind) -> bool // from an edition before 2024. &UnsafeOpKind::CallToUnsafeFunction(Some(id)) if !span.at_least_rust_2024() - && let Some(suggestion) = find_attr!(self.tcx, id, AttributeKind::RustcDeprecatedSafe2024{suggestion} => suggestion) => + && let Some(suggestion) = find_attr!(self.tcx, id, RustcDeprecatedSafe2024{suggestion} => suggestion) => { let sm = self.tcx.sess.source_map(); let guarantee = format!("that {}", suggestion); @@ -1146,7 +1145,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) { // Closures and inline consts are handled by their owner, if it has a body assert!(!tcx.is_typeck_child(def.to_def_id())); // Also, don't safety check custom MIR - if find_attr!(tcx, def, AttributeKind::CustomMir(..) => ()).is_some() { + if find_attr!(tcx, def, CustomMir(..) => ()).is_some() { return; } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index fa3f89dfc4fc..3d94ee701f56 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -3,7 +3,6 @@ use rustc_ast::UnsafeBinderCastKind; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::{LangItem, find_attr}; use rustc_index::Idx; @@ -865,7 +864,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> hir::ExprKind::Ret(v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) }, hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) }, hir::ExprKind::Break(dest, ref value) => { - if find_attr!(self.tcx.hir_attrs(expr.hir_id), AttributeKind::ConstContinue(_)) { + if find_attr!(self.tcx.hir_attrs(expr.hir_id), ConstContinue(_)) { match dest.target_id { Ok(target_id) => { let (Some(value), Some(_)) = (value, dest.label) else { @@ -930,7 +929,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> match_source, }, hir::ExprKind::Loop(body, ..) => { - if find_attr!(self.tcx.hir_attrs(expr.hir_id), AttributeKind::LoopMatch(_)) { + if find_attr!(self.tcx.hir_attrs(expr.hir_id), LoopMatch(_)) { let dcx = self.tcx.dcx(); // Accept either `state = expr` or `state = expr;`. diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index b08d1d4bcf27..60cb509ee9dd 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -4,7 +4,6 @@ use rustc_data_structures::steal::Steal; use rustc_errors::ErrorGuaranteed; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; @@ -105,8 +104,7 @@ fn new(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Self { typing_env: ty::TypingEnv::non_body_analysis(tcx, def), typeck_results, body_owner: def.to_def_id(), - apply_adjustments: - !find_attr!(tcx.hir_attrs(hir_id), AttributeKind::CustomMir(..) => ()).is_some(), + apply_adjustments: !find_attr!(tcx.hir_attrs(hir_id), CustomMir(..) => ()).is_some(), } } diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 424ac99a4b31..ae24605c39b4 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Diag, msg}; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_index::Idx; use rustc_infer::infer::TyCtxtInferExt; @@ -488,7 +487,7 @@ fn type_has_partial_eq_impl<'tcx>( let mut structural_peq = false; let mut impl_def_id = None; for def_id in tcx.non_blanket_impls_for_ty(partial_eq_trait_id, ty) { - automatically_derived = find_attr!(tcx, def_id, AttributeKind::AutomaticallyDerived(..)); + automatically_derived = find_attr!(tcx, def_id, AutomaticallyDerived(..)); impl_def_id = Some(def_id); } for _ in tcx.non_blanket_impls_for_ty(structural_partial_eq_trait_id, ty) { diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs index 9a8aea824429..6c0f2e8d7305 100644 --- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -8,7 +8,7 @@ use regex::Regex; use rustc_graphviz as dot; -use rustc_hir::attrs::{AttributeKind, BorrowckGraphvizFormatKind, RustcMirKind}; +use rustc_hir::attrs::{BorrowckGraphvizFormatKind, RustcMirKind}; use rustc_hir::find_attr; use rustc_index::bit_set::DenseBitSet; use rustc_middle::mir::{ @@ -97,9 +97,7 @@ impl RustcMirAttrs { fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Self { let mut ret = RustcMirAttrs::default(); - if let Some(rustc_mir_attrs) = - find_attr!(tcx, def_id, AttributeKind::RustcMir(kind) => kind) - { + if let Some(rustc_mir_attrs) = find_attr!(tcx, def_id, RustcMir(kind) => kind) { for attr in rustc_mir_attrs { match attr { RustcMirKind::BorrowckGraphvizPostflow { path } => { diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index 6cdf8b39df21..5b5afd7ecc7d 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -1,4 +1,4 @@ -use rustc_hir::attrs::{AttributeKind, RustcMirKind}; +use rustc_hir::attrs::RustcMirKind; use rustc_hir::find_attr; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -16,7 +16,7 @@ pub fn sanity_check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) { let def_id = body.source.def_id(); - if let Some(kind) = find_attr!(tcx, def_id, AttributeKind::RustcMir(kind) => kind) { + if let Some(kind) = find_attr!(tcx, def_id, RustcMir(kind) => kind) { let move_data = MoveData::gather_moves(body, tcx, |_| true); debug!("running rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id)); if kind.contains(&RustcMirKind::PeekMaybeInit) { diff --git a/compiler/rustc_mir_transform/src/check_inline.rs b/compiler/rustc_mir_transform/src/check_inline.rs index d084460ab84d..aa945266413d 100644 --- a/compiler/rustc_mir_transform/src/check_inline.rs +++ b/compiler/rustc_mir_transform/src/check_inline.rs @@ -1,7 +1,7 @@ //! Check that a body annotated with `#[rustc_force_inline]` will not fail to inline based on its //! definition alone (irrespective of any specific caller). -use rustc_hir::attrs::{AttributeKind, InlineAttr}; +use rustc_hir::attrs::InlineAttr; use rustc_hir::def_id::DefId; use rustc_hir::find_attr; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -42,7 +42,7 @@ pub(super) fn is_inline_valid_on_fn<'tcx>( ) -> Result<(), &'static str> { let codegen_attrs = tcx.codegen_fn_attrs(def_id); - if find_attr!(tcx, def_id, AttributeKind::RustcNoMirInline) { + if find_attr!(tcx, def_id, RustcNoMirInline) { return Err("#[rustc_no_mir_inline]"); } @@ -63,7 +63,7 @@ pub(super) fn is_inline_valid_on_fn<'tcx>( // but at this stage we don't know whether codegen knows the intrinsic, // so just conservatively don't inline it. This also ensures that we do not // accidentally inline the body of an intrinsic that *must* be overridden. - if find_attr!(tcx, def_id, AttributeKind::RustcIntrinsic) { + if find_attr!(tcx, def_id, RustcIntrinsic) { return Err("callee is an intrinsic"); } diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index bc65499a96a2..c83b10a5e583 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -64,7 +64,6 @@ use rustc_abi::{FieldIdx, VariantIdx}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::pluralize; -use rustc_hir::attrs::AttributeKind; use rustc_hir::lang_items::LangItem; use rustc_hir::{self as hir, CoroutineDesugaring, CoroutineKind, find_attr}; use rustc_index::bit_set::{BitMatrix, DenseBitSet, GrowableBitSet}; @@ -1988,9 +1987,7 @@ fn check_must_not_suspend_def( hir_id: hir::HirId, data: SuspendCheckData<'_>, ) -> bool { - if let Some(reason_str) = - find_attr!(tcx, def_id, AttributeKind::MustNotSupend {reason} => reason) - { + if let Some(reason_str) = find_attr!(tcx, def_id, MustNotSupend {reason} => reason) { let reason = reason_str.map(|s| errors::MustNotSuspendReason { span: data.source_span, reason: s }); tcx.emit_node_span_lint( diff --git a/compiler/rustc_mir_transform/src/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs index 74f4131258e4..85870be912b5 100644 --- a/compiler/rustc_mir_transform/src/coverage/query.rs +++ b/compiler/rustc_mir_transform/src/coverage/query.rs @@ -1,4 +1,4 @@ -use rustc_hir::attrs::{AttributeKind, CoverageAttrKind}; +use rustc_hir::attrs::CoverageAttrKind; use rustc_hir::find_attr; use rustc_index::bit_set::DenseBitSet; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -49,7 +49,7 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { /// Query implementation for `coverage_attr_on`. fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { // Check for a `#[coverage(..)]` attribute on this def. - if let Some(kind) = find_attr!(tcx, def_id, AttributeKind::Coverage(_sp, kind) => kind) { + if let Some(kind) = find_attr!(tcx, def_id, Coverage(_sp, kind) => kind) { match kind { CoverageAttrKind::On => return true, CoverageAttrKind::Off => return false, diff --git a/compiler/rustc_mir_transform/src/cross_crate_inline.rs b/compiler/rustc_mir_transform/src/cross_crate_inline.rs index 30ad713d201e..7435fbe8d38a 100644 --- a/compiler/rustc_mir_transform/src/cross_crate_inline.rs +++ b/compiler/rustc_mir_transform/src/cross_crate_inline.rs @@ -1,4 +1,4 @@ -use rustc_hir::attrs::{AttributeKind, InlineAttr}; +use rustc_hir::attrs::InlineAttr; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; @@ -45,7 +45,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { return true; } - if find_attr!(tcx, def_id, AttributeKind::RustcIntrinsic) { + if find_attr!(tcx, def_id, RustcIntrinsic) { // Intrinsic fallback bodies are always cross-crate inlineable. // To ensure that the MIR inliner doesn't cluelessly try to inline fallback // bodies even when the backend would implement something better, we stop @@ -159,7 +159,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, _: Location) { // But intrinsics don't have a body that gets assigned to a CGU, so they are // ignored. if let Some((fn_def_id, _)) = func.const_fn_def() - && find_attr!(tcx, fn_def_id, AttributeKind::RustcIntrinsic) + && find_attr!(tcx, fn_def_id, RustcIntrinsic) { return; } diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index b92938c7094e..b97901f075bc 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -1,7 +1,6 @@ //! Performs various peephole optimizations. use rustc_abi::ExternAbi; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{LangItem, find_attr}; use rustc_middle::bug; use rustc_middle::mir::visit::MutVisitor; @@ -30,8 +29,7 @@ fn is_enabled(&self, sess: &rustc_session::Session) -> bool { } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let preserve_ub_checks = - find_attr!(tcx.hir_krate_attrs(), AttributeKind::RustcPreserveUbChecks); + let preserve_ub_checks = find_attr!(tcx.hir_krate_attrs(), RustcPreserveUbChecks); if !preserve_ub_checks { SimplifyUbCheck { tcx }.visit_body(body); } diff --git a/compiler/rustc_mir_transform/src/liveness.rs b/compiler/rustc_mir_transform/src/liveness.rs index bb746e490c8a..3fbe1e398a18 100644 --- a/compiler/rustc_mir_transform/src/liveness.rs +++ b/compiler/rustc_mir_transform/src/liveness.rs @@ -1,6 +1,5 @@ use rustc_abi::FieldIdx; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorKind, DefKind}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::find_attr; @@ -63,14 +62,14 @@ pub(crate) fn check_liveness<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Den } // Don't run unused pass for #[naked] - if find_attr!(tcx, def_id.to_def_id(), AttributeKind::Naked(..)) { + if find_attr!(tcx, def_id.to_def_id(), Naked(..)) { return DenseBitSet::new_empty(0); } // Don't run unused pass for #[derive] let parent = tcx.parent(tcx.typeck_root_def_id(def_id.to_def_id())); if let DefKind::Impl { of_trait: true } = tcx.def_kind(parent) - && find_attr!(tcx, parent, AttributeKind::AutomaticallyDerived(..)) + && find_attr!(tcx, parent, AutomaticallyDerived(..)) { return DenseBitSet::new_empty(0); } diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index dac5684dc0ec..3da0978e5ff8 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -1,4 +1,4 @@ -use rustc_hir::attrs::{AttributeKind, RustcAbiAttrKind}; +use rustc_hir::attrs::RustcAbiAttrKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; @@ -19,7 +19,7 @@ pub fn test_abi(tcx: TyCtxt<'_>) { } for id in tcx.hir_crate_items(()).definitions() { let Some((attr_span, attr_kind)) = - find_attr!(tcx, id, AttributeKind::RustcAbi{ attr_span, kind } => (*attr_span, *kind)) + find_attr!(tcx, id, RustcAbi{ attr_span, kind } => (*attr_span, *kind)) else { continue; }; diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d6a171857ece..9af9398d78b9 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -567,7 +567,7 @@ fn check_eii_impl(&self, impls: &[EiiImpl], target: Target) { } if let EiiImplResolution::Macro(eii_macro) = resolution - && find_attr!(self.tcx, *eii_macro, AttributeKind::EiiDeclaration(EiiDecl { impl_unsafe, .. }) if *impl_unsafe) + && find_attr!(self.tcx, *eii_macro, EiiDeclaration(EiiDecl { impl_unsafe, .. }) if *impl_unsafe) && !impl_marked_unsafe { self.dcx().emit_err(errors::EiiImplRequiresUnsafe { @@ -782,7 +782,7 @@ fn check_track_caller( Target::Fn => { // `#[track_caller]` is not valid on weak lang items because they are called via // `extern` declarations and `#[track_caller]` would alter their ABI. - if let Some(item) = find_attr!(attrs, AttributeKind::Lang(item, _) => item) + if let Some(item) = find_attr!(attrs, Lang(item, _) => item) && item.is_weak() { let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); @@ -794,7 +794,7 @@ fn check_track_caller( }); } - if let Some(impls) = find_attr!(attrs, AttributeKind::EiiImpls(impls) => impls) { + if let Some(impls) = find_attr!(attrs, EiiImpls(impls) => impls) { let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); for i in impls { let name = match i.resolution { @@ -853,7 +853,7 @@ fn check_target_feature( Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) | Target::Fn => { // `#[target_feature]` is not allowed in lang items. - if let Some(lang_item) = find_attr!(attrs, AttributeKind::Lang(lang, _) => lang) + if let Some(lang_item) = find_attr!(attrs, Lang(lang, _) => lang) // Calling functions with `#[target_feature]` is // not unsafe on WASM, see #84988 && !self.tcx.sess.target.is_like_wasm @@ -1161,7 +1161,7 @@ fn check_doc_attrs(&self, attr: &DocAttribute, hir_id: HirId, target: Target) { } fn check_ffi_pure(&self, attr_span: Span, attrs: &[Attribute]) { - if find_attr!(attrs, AttributeKind::FfiConst(_)) { + if find_attr!(attrs, FfiConst(_)) { // `#[ffi_const]` functions cannot be `#[ffi_pure]` self.dcx().emit_err(errors::BothFfiConstAndPure { attr_span }); } @@ -1268,7 +1268,9 @@ fn check_repr( // #[repr(foo)] // #[repr(bar, align(8))] // ``` - let (reprs, first_attr_span) = find_attr!(attrs, AttributeKind::Repr { reprs, first_span } => (reprs.as_slice(), Some(*first_span))).unwrap_or((&[], None)); + let (reprs, first_attr_span) = + find_attr!(attrs, Repr { reprs, first_span } => (reprs.as_slice(), Some(*first_span))) + .unwrap_or((&[], None)); let mut int_reprs = 0; let mut is_explicit_rust = false; @@ -1413,7 +1415,7 @@ fn check_repr( // `#[rustc_pass_indirectly_in_non_rustic_abis]` if is_transparent && let Some(&pass_indirectly_span) = - find_attr!(attrs, AttributeKind::RustcPassIndirectlyInNonRusticAbis(span) => span) + find_attr!(attrs, RustcPassIndirectlyInNonRusticAbis(span) => span) { self.dcx().emit_err(errors::TransparentIncompatible { hint_spans: vec![span, pass_indirectly_span], @@ -1751,7 +1753,7 @@ fn check_proc_macro(&self, hir_id: HirId, target: Target, kind: ProcMacroKind) { } fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) { - if !find_attr!(attrs, AttributeKind::Repr { reprs, .. } => reprs.iter().any(|(r, _)| r == &ReprAttr::ReprTransparent)) + if !find_attr!(attrs, Repr { reprs, .. } => reprs.iter().any(|(r, _)| r == &ReprAttr::ReprTransparent)) .unwrap_or(false) { self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span }); @@ -1761,7 +1763,7 @@ fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attr fn check_rustc_force_inline(&self, hir_id: HirId, attrs: &[Attribute], target: Target) { if let (Target::Closure, None) = ( target, - find_attr!(attrs, AttributeKind::Inline(InlineAttr::Force { attr_span, .. }, _) => *attr_span), + find_attr!(attrs, Inline(InlineAttr::Force { attr_span, .. }, _) => *attr_span), ) { let is_coro = matches!( self.tcx.hir_expect_expr(hir_id).kind, @@ -1775,7 +1777,7 @@ fn check_rustc_force_inline(&self, hir_id: HirId, attrs: &[Attribute], target: T if let Some(attr_span) = find_attr!( self.tcx, parent_did, - AttributeKind::Inline(InlineAttr::Force { attr_span, .. }, _) => *attr_span + Inline(InlineAttr::Force { attr_span, .. }, _) => *attr_span ) && is_coro { self.dcx().emit_err(errors::RustcForceInlineCoro { attr_span, span: parent_span }); @@ -1784,9 +1786,10 @@ fn check_rustc_force_inline(&self, hir_id: HirId, attrs: &[Attribute], target: T } fn check_mix_no_mangle_export(&self, hir_id: HirId, attrs: &[Attribute]) { - if let Some(export_name_span) = find_attr!(attrs, AttributeKind::ExportName { span: export_name_span, .. } => *export_name_span) + if let Some(export_name_span) = + find_attr!(attrs, ExportName { span: export_name_span, .. } => *export_name_span) && let Some(no_mangle_span) = - find_attr!(attrs, AttributeKind::NoMangle(no_mangle_span) => *no_mangle_span) + find_attr!(attrs, NoMangle(no_mangle_span) => *no_mangle_span) { let no_mangle_attr = if no_mangle_span.edition() >= Edition::Edition2024 { "#[unsafe(no_mangle)]" @@ -1905,9 +1908,7 @@ fn visit_item(&mut self, item: &'tcx Item<'tcx>) { // In the long run, the checks should be harmonized. if let ItemKind::Macro(_, macro_def, _) = item.kind { let def_id = item.owner_id.to_def_id(); - if macro_def.macro_rules - && !find_attr!(self.tcx, def_id, AttributeKind::MacroExport { .. }) - { + if macro_def.macro_rules && !find_attr!(self.tcx, def_id, MacroExport { .. }) { check_non_exported_macro_for_invalid_attrs(self.tcx, item); } } @@ -2097,7 +2098,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>) { let attrs = tcx.hir_attrs(item.hir_id()); - if let Some(attr_span) = find_attr!(attrs, AttributeKind::Inline(i, span) if !matches!(i, InlineAttr::Force{..}) => *span) + if let Some(attr_span) = + find_attr!(attrs, Inline(i, span) if !matches!(i, InlineAttr::Force{..}) => *span) { tcx.dcx().emit_err(errors::NonExportedMacroInvalidAttrs { attr_span }); } diff --git a/compiler/rustc_passes/src/check_export.rs b/compiler/rustc_passes/src/check_export.rs index 1e6f6d459813..f1c89face6a0 100644 --- a/compiler/rustc_passes/src/check_export.rs +++ b/compiler/rustc_passes/src/check_export.rs @@ -4,7 +4,6 @@ use rustc_abi::ExternAbi; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::find_attr; @@ -46,7 +45,7 @@ fn report_wrong_site(&self, def_id: LocalDefId) { } fn item_is_exportable(&self, def_id: LocalDefId) -> bool { - let has_attr = find_attr!(self.tcx, def_id, AttributeKind::ExportStable); + let has_attr = find_attr!(self.tcx, def_id, ExportStable); if !self.in_exportable_mod && !has_attr { return false; } @@ -82,7 +81,7 @@ fn add_exportable(&mut self, def_id: LocalDefId) { fn walk_item_with_mod(&mut self, item: &'tcx hir::Item<'tcx>) { let def_id = item.hir_id().owner.def_id; let old_exportable_mod = self.in_exportable_mod; - if find_attr!(self.tcx, def_id, AttributeKind::ExportStable) { + if find_attr!(self.tcx, def_id, ExportStable) { self.in_exportable_mod = true; } let old_seen_exportable_in_mod = std::mem::replace(&mut self.seen_exportable_in_mod, false); diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index a2cbdd23e379..f6d00f5342f2 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -10,7 +10,6 @@ use rustc_abi::FieldIdx; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{ErrorGuaranteed, MultiSpan}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; use rustc_hir::intravisit::{self, Visitor}; @@ -381,7 +380,7 @@ fn should_ignore_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) -> bool { && let impl_of = self.tcx.parent(impl_item.owner_id.to_def_id()) && self.tcx.is_automatically_derived(impl_of) && let trait_ref = self.tcx.impl_trait_ref(impl_of).instantiate_identity() - && find_attr!(self.tcx, trait_ref.def_id, AttributeKind::RustcTrivialFieldReads) + && find_attr!(self.tcx, trait_ref.def_id, RustcTrivialFieldReads) { if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind() && let Some(adt_def_id) = adt_def.did().as_local() @@ -723,7 +722,7 @@ fn has_used_like_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { if has_allow_expect_dead_code(tcx, def_id) { Some(ComesFromAllowExpect::Yes) - } else if has_used_like_attr(tcx, def_id) || find_attr!(tcx, def_id, AttributeKind::Lang(..)) { + } else if has_used_like_attr(tcx, def_id) || find_attr!(tcx, def_id, Lang(..)) { Some(ComesFromAllowExpect::No) } else { None diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index c7b1dcb95e33..be7ae5b97f55 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -9,7 +9,6 @@ //! //! * Compiler internal types like `Ty` and `TyCtxt` -use rustc_hir::attrs::AttributeKind; use rustc_hir::diagnostic_items::DiagnosticItems; use rustc_hir::{CRATE_OWNER_ID, OwnerId, find_attr}; use rustc_middle::query::{LocalCrate, Providers}; @@ -21,7 +20,7 @@ fn observe_item<'tcx>(tcx: TyCtxt<'tcx>, diagnostic_items: &mut DiagnosticItems, owner: OwnerId) { let attrs = tcx.hir_attrs(owner.into()); - if let Some(name) = find_attr!(attrs, AttributeKind::RustcDiagnosticItem(name) => name) { + if let Some(name) = find_attr!(attrs, RustcDiagnosticItem(name) => name) { // insert into our table collect_item(tcx, diagnostic_items, *name, owner.to_def_id()); } diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index a5ebf7e5fee9..9fc9df7604c5 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -1,6 +1,5 @@ use rustc_ast::entry::EntryPointType; use rustc_errors::codes::*; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::{ItemId, Node, find_attr}; use rustc_middle::query::Providers; @@ -29,7 +28,7 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { } // If the user wants no main function at all, then stop here. - if find_attr!(tcx, crate, AttributeKind::NoMain) { + if find_attr!(tcx, crate, NoMain) { return None; } @@ -47,7 +46,7 @@ fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) { let attrs = ctxt.tcx.hir_attrs(id.hir_id()); let entry_point_type = rustc_ast::entry::entry_point_type( - find_attr!(attrs, AttributeKind::RustcMain), + find_attr!(attrs, RustcMain), at_root, ctxt.tcx.opt_item_name(id.owner_id.to_def_id()), ); diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 89766d84377c..68834cf7d55a 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -1,5 +1,5 @@ use rustc_abi::{HasDataLayout, TargetDataLayout}; -use rustc_hir::attrs::{AttributeKind, RustcLayoutType}; +use rustc_hir::attrs::RustcLayoutType; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; @@ -20,7 +20,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) { return; } for id in tcx.hir_crate_items(()).definitions() { - if let Some(attrs) = find_attr!(tcx, id, AttributeKind::RustcLayout(attrs) => attrs) { + if let Some(attrs) = find_attr!(tcx, id, RustcLayout(attrs) => attrs) { // Attribute parsing handles error reporting if matches!( tcx.def_kind(id), diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index ec38a334be28..6fd28c78740c 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -97,7 +97,7 @@ fn annotation_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> AnnotationKind { fn lookup_deprecation_entry(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { let depr = find_attr!(tcx, def_id, - AttributeKind::Deprecation { deprecation, span: _ } => *deprecation + Deprecation { deprecation, span: _ } => *deprecation ); let Some(depr) = depr else { @@ -160,8 +160,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { } // # Regular stability - let stab = - find_attr!(tcx, def_id, AttributeKind::Stability { stability, span: _ } => *stability); + let stab = find_attr!(tcx, def_id, Stability { stability, span: _ } => *stability); if let Some(stab) = stab { return Some(stab); @@ -195,7 +194,7 @@ fn lookup_default_body_stability( } // FIXME: check that this item can have body stability - find_attr!(tcx, def_id, AttributeKind::RustcBodyStability { stability, .. } => *stability) + find_attr!(tcx, def_id, RustcBodyStability { stability, .. } => *stability) } #[instrument(level = "debug", skip(tcx))] @@ -210,8 +209,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option, def_id: LocalDefId) -> Option *stability); + let const_stability_indirect = find_attr!(tcx, def_id, RustcConstStabilityIndirect); + let const_stab = + find_attr!(tcx, def_id, RustcConstStability { stability, span: _ } => *stability); // After checking the immediate attributes, get rid of the span and compute implied // const stability: inherit feature gate from regular stability. @@ -595,15 +593,15 @@ fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { let features = self.tcx.features(); if features.staged_api() { let attrs = self.tcx.hir_attrs(item.hir_id()); - let stab = find_attr!(attrs, AttributeKind::Stability{stability, span} => (*stability, *span)); + let stab = find_attr!(attrs, Stability{stability, span} => (*stability, *span)); // FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem - let const_stab = find_attr!(attrs, AttributeKind::RustcConstStability{stability, ..} => *stability); + let const_stab = + find_attr!(attrs, RustcConstStability{stability, ..} => *stability); - let unstable_feature_stab = - find_attr!(attrs, AttributeKind::UnstableFeatureBound(i) => i) - .map(|i| i.as_slice()) - .unwrap_or_default(); + let unstable_feature_stab = find_attr!(attrs, UnstableFeatureBound(i) => i) + .map(|i| i.as_slice()) + .unwrap_or_default(); // If this impl block has an #[unstable] attribute, give an // error if all involved types and traits are stable, because diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index d84797f2fab6..59fd908756b0 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -21,7 +21,6 @@ use rustc_data_structures::intern::Interned; use rustc_errors::{MultiSpan, listify}; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; use rustc_hir::intravisit::{self, InferKind, Visitor}; @@ -508,7 +507,7 @@ fn update_reachability_from_macro( let hir_id = self.tcx.local_def_id_to_hir_id(local_def_id); let attrs = self.tcx.hir_attrs(hir_id); - if find_attr!(attrs, AttributeKind::RustcMacroTransparency(x) => *x) + if find_attr!(attrs, RustcMacroTransparency(x) => *x) .unwrap_or(Transparency::fallback(md.macro_rules)) != Transparency::Opaque { @@ -876,7 +875,7 @@ pub struct TestReachabilityVisitor<'a, 'tcx> { impl<'a, 'tcx> TestReachabilityVisitor<'a, 'tcx> { fn effective_visibility_diagnostic(&self, def_id: LocalDefId) { - if find_attr!(self.tcx, def_id, AttributeKind::RustcEffectiveVisibility) { + if find_attr!(self.tcx, def_id, RustcEffectiveVisibility) { let mut error_msg = String::new(); let span = self.tcx.def_span(def_id.to_def_id()); if let Some(effective_vis) = self.effective_visibilities.effective_vis(def_id) { diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 5eb1f73eb750..78fd9c1e21a0 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -14,7 +14,7 @@ struct_span_code_err, }; use rustc_feature::BUILTIN_ATTRIBUTES; -use rustc_hir::attrs::{AttributeKind, CfgEntry, StrippedCfgItem}; +use rustc_hir::attrs::{CfgEntry, StrippedCfgItem}; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, MacroKinds, NonMacroAttrKind, PerNS}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; @@ -1432,7 +1432,7 @@ fn lookup_import_candidates_from_module( && find_attr!( this.tcx, did, - AttributeKind::RustcDiagnosticItem( + RustcDiagnosticItem( sym::TryInto | sym::TryFrom | sym::FromIterator ) ); @@ -2171,8 +2171,7 @@ fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'ra>) { // Otherwise, point out if the struct has any private fields. if let Some(def_id) = res.opt_def_id() && !def_id.is_local() - && let Some(attr_span) = - find_attr!(self.tcx, def_id, AttributeKind::NonExhaustive(span) => *span) + && let Some(attr_span) = find_attr!(self.tcx, def_id, NonExhaustive(span) => *span) { non_exhaustive = Some(attr_span); } else if let Some(span) = ctor_fields_span { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 7c20b006c00b..b1d6e3526d9c 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -17,7 +17,6 @@ struct_span_code_err, }; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, MacroKinds}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; @@ -1115,7 +1114,7 @@ fn lookup_doc_alias_name(&mut self, path: &[Segment], ns: Namespace) -> Option<( // confused by them. continue; } - if let Some(d) = hir::find_attr!(r.tcx, did, AttributeKind::Doc(d) => d) + if let Some(d) = hir::find_attr!(r.tcx, did, Doc(d) => d) && d.aliases.contains_key(&item_name) { return Some(did); @@ -2664,9 +2663,7 @@ fn suggest_alternative_construction_methods( ) .iter() .filter_map(|candidate| candidate.did) - .find(|did| { - find_attr!(self.r.tcx, *did, AttributeKind::RustcDiagnosticItem(sym::Default)) - }); + .find(|did| find_attr!(self.r.tcx, *did, RustcDiagnosticItem(sym::Default))); let Some(default_trait) = default_trait else { return; }; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 476bd146e46a..74e313bb4269 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -53,7 +53,7 @@ use rustc_errors::{Applicability, Diag, ErrCode, ErrorGuaranteed, LintBuffer}; use rustc_expand::base::{DeriveResolution, SyntaxExtension, SyntaxExtensionKind}; use rustc_feature::BUILTIN_ATTRIBUTES; -use rustc_hir::attrs::{AttributeKind, StrippedCfgItem}; +use rustc_hir::attrs::StrippedCfgItem; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{ self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, MacroKinds, NonMacroAttrKind, PartialRes, @@ -2476,7 +2476,7 @@ fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option> { find_attr!( // we can use parsed attrs here since for other crates they're already available self.tcx, def_id, - AttributeKind::RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes + RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes ) .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect()) } diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs index 3c50a993465b..26979c24bdb6 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs @@ -11,7 +11,6 @@ use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, CASE_INSENSITIVE, ToBaseN}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_middle::bug; use rustc_middle::ty::layout::IntegerExt; @@ -447,9 +446,7 @@ pub(crate) fn encode_ty<'tcx>( ty::Adt(adt_def, args) => { let mut s = String::new(); let def_id = adt_def.did(); - if let Some(encoding) = - find_attr!(tcx, def_id, AttributeKind::CfiEncoding { encoding } => encoding) - { + if let Some(encoding) = find_attr!(tcx, def_id, CfiEncoding { encoding } => encoding) { let encoding = encoding.as_str().trim(); // Use user-defined CFI encoding for type s.push_str(&encoding); @@ -495,9 +492,7 @@ pub(crate) fn encode_ty<'tcx>( // , where is let mut s = String::new(); - if let Some(encoding) = - find_attr!(tcx, *def_id, AttributeKind::CfiEncoding {encoding} => encoding) - { + if let Some(encoding) = find_attr!(tcx, *def_id, CfiEncoding {encoding} => encoding) { // Use user-defined CFI encoding for type s.push_str(encoding.as_str().trim()); } else { diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index b4f8e8201f44..90b489258360 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -6,7 +6,6 @@ use std::iter; -use rustc_hir::attrs::AttributeKind; use rustc_hir::{self as hir, LangItem, find_attr}; use rustc_middle::bug; use rustc_middle::ty::{ @@ -138,7 +137,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { { // Don't transform repr(transparent) types with an user-defined CFI encoding to // preserve the user-defined CFI encoding. - if find_attr!(self.tcx, adt_def.did(), AttributeKind::CfiEncoding { .. }) { + if find_attr!(self.tcx, adt_def.did(), CfiEncoding { .. }) { return t; } let variant = adt_def.non_enum_variant(); diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs index 6a550c132876..b4d9031469dd 100644 --- a/compiler/rustc_symbol_mangling/src/test.rs +++ b/compiler/rustc_symbol_mangling/src/test.rs @@ -4,7 +4,6 @@ //! def-path. This is used for unit testing the code that generates //! paths etc in all kinds of annoying scenarios. -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; use rustc_middle::ty::print::with_no_trimmed_paths; @@ -53,9 +52,7 @@ fn process_attrs(&mut self, def_id: LocalDefId) { // to test the entirety of the string, if they choose, or else just // some subset. - if let Some(attr_span) = - find_attr!(tcx, def_id,AttributeKind::RustcSymbolName(span) => span) - { + if let Some(attr_span) = find_attr!(tcx, def_id, RustcSymbolName(span) => span) { let def_id = def_id.to_def_id(); let instance = Instance::new_raw( def_id, @@ -83,7 +80,7 @@ fn process_attrs(&mut self, def_id: LocalDefId) { if let Some(attr_span) = find_attr!( tcx, def_id, - AttributeKind::RustcDefPath(span) => span + RustcDefPath(span) => span ) { tcx.dcx().emit_err(TestOutput { span: *attr_span, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index df88b26d811c..ab19df5620cd 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -1,7 +1,6 @@ use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; use rustc_errors::{Diag, MultiSpan, pluralize}; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::find_attr; use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; @@ -533,7 +532,7 @@ fn foo(&self, x: T) -> T { x } } } TypeError::TargetFeatureCast(def_id) => { - let target_spans = find_attr!(tcx, def_id, AttributeKind::TargetFeature{attr_span: span, was_forced: false, ..} => *span); + let target_spans = find_attr!(tcx, def_id, TargetFeature{attr_span: span, was_forced: false, ..} => *span); diag.note( "functions with `#[target_feature]` can only be coerced to `unsafe` function pointers" ); diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index eaa767f1496e..4e37871d28a2 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -8,7 +8,6 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_errors::{Diag, EmissionGuarantee}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; use rustc_hir::find_attr; @@ -760,7 +759,8 @@ fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) { } = cand.kind() && let ty::ImplPolarity::Reservation = infcx.tcx.impl_polarity(def_id) { - if let Some(message) = find_attr!(infcx.tcx, def_id, AttributeKind::RustcReservationImpl(_, message) => *message) + if let Some(message) = + find_attr!(infcx.tcx, def_id, RustcReservationImpl(_, message) => *message) { self.causes.insert(IntercrateAmbiguityCause::ReservationImpl { message }); } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 4620fe9b475d..d6657ea392dc 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -12,7 +12,6 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{Diag, EmissionGuarantee}; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, LangItem, find_attr}; use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType}; @@ -1445,7 +1444,7 @@ fn filter_reservation_impls( && let ty::ImplPolarity::Reservation = tcx.impl_polarity(def_id) { if let Some(intercrate_ambiguity_clauses) = &mut self.intercrate_ambiguity_causes { - let message = find_attr!(tcx, def_id, AttributeKind::RustcReservationImpl(_, message) => *message); + let message = find_attr!(tcx, def_id, RustcReservationImpl(_, message) => *message); if let Some(message) = message { debug!( "filter_reservation_impls: \ diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 5b5fa82517ed..a095ee7cbbba 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -7,7 +7,6 @@ TagEncoding, VariantIdx, Variants, WrappingRange, }; use rustc_hashes::Hash64; -use rustc_hir::attrs::AttributeKind; use rustc_hir::find_attr; use rustc_index::{Idx as _, IndexVec}; use rustc_middle::bug; @@ -625,7 +624,7 @@ fn layout_of_uncached<'tcx>( // Check for the rustc_simd_monomorphize_lane_limit attribute and check the lane limit if let Some(limit) = find_attr!( tcx, def.did(), - AttributeKind::RustcSimdMonomorphizeLaneLimit(limit) => limit + RustcSimdMonomorphizeLaneLimit(limit) => limit ) { if !limit.value_within_limit(e_len as usize) { return Err(map_error( diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index c5dedd51af85..2cff60de9d1c 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -1,7 +1,6 @@ //! Check whether a type has (potentially) non-trivial drop glue. use rustc_data_structures::fx::FxHashSet; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::DefId; use rustc_hir::find_attr; use rustc_hir::limit::Limit; @@ -397,7 +396,7 @@ fn adt_consider_insignificant_dtor<'tcx>( tcx: TyCtxt<'tcx>, ) -> impl Fn(ty::AdtDef<'tcx>) -> Option { move |adt_def: ty::AdtDef<'tcx>| { - if find_attr!(tcx, adt_def.did(), AttributeKind::RustcInsignificantDtor) { + if find_attr!(tcx, adt_def.did(), RustcInsignificantDtor) { // In some cases like `std::collections::HashMap` where the struct is a wrapper around // a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies // outside stdlib, we might choose to still annotate the wrapper (std HashMap) with