deprecate functions

This commit is contained in:
Jana Dönszelmann
2026-02-05 13:24:24 +01:00
parent 7477a5b48e
commit 54d673dd69
4 changed files with 15 additions and 13 deletions
+5 -3
View File
@@ -57,9 +57,11 @@ macro_rules! find_attr {
($tcx: expr, $def_id: expr, $pattern: pat $(if $guard: expr)?) => {
$crate::find_attr!($tcx, $def_id, $pattern $(if $guard)? => ()).is_some()
};
($tcx: expr, $def_id: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {
$crate::find_attr!($tcx.get_all_attrs($def_id), $pattern $(if $guard)? => $e)
};
($tcx: expr, $def_id: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
#[allow(deprecated)] {
$crate::find_attr!($tcx.get_all_attrs($def_id), $pattern $(if $guard)? => $e)
}
}};
($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
@@ -895,6 +895,8 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
};
// we do a bunch of find_attr calls here, probably faster to get them from the tcx just once.
#[allow(deprecated)]
let attrs = tcx.get_all_attrs(def_id);
let paren_sugar = find_attr!(attrs, AttributeKind::RustcParenSugar(_));
+1 -10
View File
@@ -10,7 +10,7 @@
use rustc_index::bit_set::FiniteBitSet;
use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable};
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_span::{DUMMY_SP, Span};
use tracing::{debug, instrument};
use crate::error;
@@ -286,15 +286,6 @@ pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
}
}
#[inline]
pub fn get_attrs(
&self,
tcx: TyCtxt<'tcx>,
attr: Symbol,
) -> impl Iterator<Item = &'tcx hir::Attribute> {
tcx.get_attrs(self.def_id(), attr)
}
/// Returns `true` if the LLVM version of this instance is unconditionally
/// marked with `inline`. This implies that a copy of this instance is
/// generated in every codegen unit.
+7
View File
@@ -1708,11 +1708,13 @@ pub fn instance_mir(self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx>
}
/// Gets all attributes with the given name.
#[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
pub fn get_attrs(
self,
did: impl Into<DefId>,
attr: Symbol,
) -> impl Iterator<Item = &'tcx hir::Attribute> {
#[allow(deprecated)]
self.get_all_attrs(did).iter().filter(move |a: &&hir::Attribute| a.has_name(attr))
}
@@ -1720,6 +1722,7 @@ pub fn get_attrs(
///
/// To see if an item has a specific attribute, you should use
/// [`rustc_hir::find_attr!`] so you can use matching.
#[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
pub fn get_all_attrs(self, did: impl Into<DefId>) -> &'tcx [hir::Attribute] {
let did: DefId = did.into();
if let Some(did) = did.as_local() {
@@ -1742,17 +1745,21 @@ pub fn get_attrs_by_path(
}
}
#[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
pub fn get_attr(self, did: impl Into<DefId>, attr: Symbol) -> Option<&'tcx hir::Attribute> {
if cfg!(debug_assertions) && !rustc_feature::is_valid_for_get_attr(attr) {
let did: DefId = did.into();
bug!("get_attr: unexpected called with DefId `{:?}`, attr `{:?}`", did, attr);
} else {
#[allow(deprecated)]
self.get_attrs(did, attr).next()
}
}
/// Determines whether an item is annotated with an attribute.
#[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
pub fn has_attr(self, did: impl Into<DefId>, attr: Symbol) -> bool {
#[allow(deprecated)]
self.get_attrs(did, attr).next().is_some()
}