Skip to content

Commit 0b3c980

Browse files
committed
Remove TyCtxt::get_attrs_unchecked.
It's identical to `TyCtxt::get_all_attrs` except it takes `DefId` instead of `impl Into<DefIf>`.
1 parent a949c47 commit 0b3c980

File tree

6 files changed

+8
-19
lines changed

6 files changed

+8
-19
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,15 +1706,6 @@ impl<'tcx> TyCtxt<'tcx> {
17061706
}
17071707
}
17081708

1709-
// FIXME(@lcnr): Remove this function.
1710-
pub fn get_attrs_unchecked(self, did: DefId) -> &'tcx [hir::Attribute] {
1711-
if let Some(did) = did.as_local() {
1712-
self.hir_attrs(self.local_def_id_to_hir_id(did))
1713-
} else {
1714-
self.attrs_for_def(did)
1715-
}
1716-
}
1717-
17181709
/// Gets all attributes with the given name.
17191710
pub fn get_attrs(
17201711
self,
@@ -1726,7 +1717,8 @@ impl<'tcx> TyCtxt<'tcx> {
17261717

17271718
/// Gets all attributes.
17281719
///
1729-
/// To see if an item has a specific attribute, you should use [`rustc_attr_data_structures::find_attr!`] so you can use matching.
1720+
/// To see if an item has a specific attribute, you should use
1721+
/// [`rustc_attr_data_structures::find_attr!`] so you can use matching.
17301722
pub fn get_all_attrs(self, did: impl Into<DefId>) -> &'tcx [hir::Attribute] {
17311723
let did: DefId = did.into();
17321724
if let Some(did) = did.as_local() {

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub(crate) fn try_inline_glob(
217217
}
218218

219219
pub(crate) fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> &'hir [hir::Attribute] {
220-
cx.tcx.get_attrs_unchecked(did)
220+
cx.tcx.get_all_attrs(did)
221221
}
222222

223223
pub(crate) fn item_relative_path(tcx: TyCtxt<'_>, def_id: DefId) -> Vec<Symbol> {

src/librustdoc/clean/types.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,7 @@ impl Item {
404404
}
405405

406406
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
407-
self.item_id
408-
.as_def_id()
409-
.map(|did| inner_docs(tcx.get_attrs_unchecked(did)))
410-
.unwrap_or(false)
407+
self.item_id.as_def_id().map(|did| inner_docs(tcx.get_all_attrs(did))).unwrap_or(false)
411408
}
412409

413410
pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
@@ -452,7 +449,7 @@ impl Item {
452449
kind: ItemKind,
453450
cx: &mut DocContext<'_>,
454451
) -> Item {
455-
let hir_attrs = cx.tcx.get_attrs_unchecked(def_id);
452+
let hir_attrs = cx.tcx.get_all_attrs(def_id);
456453

457454
Self::from_def_id_and_attrs_and_parts(
458455
def_id,

src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
185185
if let Some(adt) = ty.ty_adt_def()
186186
&& get_attr(
187187
self.cx.sess(),
188-
self.cx.tcx.get_attrs_unchecked(adt.did()),
188+
self.cx.tcx.get_all_attrs(adt.did()),
189189
sym::has_significant_drop,
190190
)
191191
.count()

src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
168168
if let Some(adt) = ty.ty_adt_def() {
169169
let mut iter = get_attr(
170170
self.cx.sess(),
171-
self.cx.tcx.get_attrs_unchecked(adt.did()),
171+
self.cx.tcx.get_all_attrs(adt.did()),
172172
sym::has_significant_drop,
173173
);
174174
if iter.next().is_some() {

src/tools/clippy/clippy_utils/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn is_format_macro(cx: &LateContext<'_>, macro_def_id: DefId) -> bool {
4242
} else {
4343
// Allow users to tag any macro as being format!-like
4444
// TODO: consider deleting FORMAT_MACRO_DIAG_ITEMS and using just this method
45-
get_unique_attr(cx.sess(), cx.tcx.get_attrs_unchecked(macro_def_id), sym::format_args).is_some()
45+
get_unique_attr(cx.sess(), cx.tcx.get_all_attrs(macro_def_id), sym::format_args).is_some()
4646
}
4747
}
4848

0 commit comments

Comments
 (0)