Skip to content

Commit 6cbf87c

Browse files
Querify hir attr fetching again
1 parent 33a2c24 commit 6cbf87c

File tree

7 files changed

+7
-18
lines changed

7 files changed

+7
-18
lines changed

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub fn provide(providers: &mut Providers) {
153153
providers.hir_attrs = |tcx, id| {
154154
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
155155
};
156+
providers.item_attrs = |tcx, def_id| tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(def_id));
156157
providers.def_span = |tcx, def_id| {
157158
let def_id = def_id;
158159
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,15 +2491,6 @@ impl<'tcx> TyCtxt<'tcx> {
24912491
}
24922492
}
24932493

2494-
// FIXME(@lcnr): Remove this function.
2495-
pub fn get_attrs_unchecked(self, did: DefId) -> &'tcx [ast::Attribute] {
2496-
if let Some(did) = did.as_local() {
2497-
self.hir().attrs(self.hir().local_def_id_to_hir_id(did))
2498-
} else {
2499-
self.item_attrs(did)
2500-
}
2501-
}
2502-
25032494
/// Gets all attributes with the given name.
25042495
pub fn get_attrs(
25052496
self,

src/librustdoc/clean/inline.rs

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

177177
pub(crate) fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> &'hir [ast::Attribute] {
178-
cx.tcx.get_attrs_unchecked(did)
178+
cx.tcx.item_attrs(did)
179179
}
180180

181181
/// Record an external fully qualified name in the external_paths cache.

src/librustdoc/clean/types.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,7 @@ impl Item {
370370
}
371371

372372
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
373-
self.item_id
374-
.as_def_id()
375-
.map(|did| inner_docs(tcx.get_attrs_unchecked(did)))
376-
.unwrap_or(false)
373+
self.item_id.as_def_id().map(|did| inner_docs(tcx.item_attrs(did))).unwrap_or(false)
377374
}
378375

379376
pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
@@ -418,7 +415,7 @@ impl Item {
418415
kind: ItemKind,
419416
cx: &mut DocContext<'_>,
420417
) -> Item {
421-
let ast_attrs = cx.tcx.get_attrs_unchecked(def_id);
418+
let ast_attrs = cx.tcx.item_attrs(def_id);
422419

423420
Self::from_def_id_and_attrs_and_parts(
424421
def_id,

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
465465

466466
clean::ImportItem(ref import) => {
467467
let stab_tags = if let Some(import_def_id) = import.source.did {
468-
let ast_attrs = tcx.get_attrs_unchecked(import_def_id);
468+
let ast_attrs = tcx.item_attrs(import_def_id);
469469
let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs));
470470

471471
// Just need an item with the correct def_id and attrs

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
@@ -126,7 +126,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
126126

127127
fn has_sig_drop_attr(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
128128
if let Some(adt) = ty.ty_adt_def() {
129-
if get_attr(cx.sess(), cx.tcx.get_attrs_unchecked(adt.did()), "has_significant_drop").count() > 0 {
129+
if get_attr(cx.sess(), cx.tcx.item_attrs(adt.did()), "has_significant_drop").count() > 0 {
130130
return true;
131131
}
132132
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
176176
if let Some(adt) = ty.ty_adt_def() {
177177
let mut iter = get_attr(
178178
self.cx.sess(),
179-
self.cx.tcx.get_attrs_unchecked(adt.did()),
179+
self.cx.tcx.item_attrs(adt.did()),
180180
"has_significant_drop",
181181
);
182182
if iter.next().is_some() {

0 commit comments

Comments
 (0)