Skip to content

Commit 650b7d9

Browse files
committed
Move methods from Map to TyCtxt, part 4.
Continuing the work from #137350. Removes the unused methods: `expect_variant`, `expect_field`, `expect_foreign_item`. Every method gains a `hir_` prefix.
1 parent cb044d4 commit 650b7d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+67
-78
lines changed

clippy_lints/src/attrs/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl Attributes {
465465

466466
impl<'tcx> LateLintPass<'tcx> for Attributes {
467467
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
468-
let attrs = cx.tcx.hir().attrs(item.hir_id());
468+
let attrs = cx.tcx.hir_attrs(item.hir_id());
469469
if is_relevant_item(cx, item) {
470470
inline_always::check(cx, item.span, item.ident.name, attrs);
471471
}
@@ -474,13 +474,13 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
474474

475475
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
476476
if is_relevant_impl(cx, item) {
477-
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
477+
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir_attrs(item.hir_id()));
478478
}
479479
}
480480

481481
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
482482
if is_relevant_trait(cx, item) {
483-
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
483+
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir_attrs(item.hir_id()));
484484
}
485485
}
486486
}

clippy_lints/src/default_union_representation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsR
9797
}
9898

9999
fn has_c_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool {
100-
let attrs = cx.tcx.hir().attrs(hir_id);
100+
let attrs = cx.tcx.hir_attrs(hir_id);
101101

102102
find_attr!(attrs, AttributeKind::Repr(r) if r.iter().any(|(x, _)| *x == ReprAttr::ReprC))
103103
}

clippy_lints/src/derivable_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
197197
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
198198
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
199199
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
200-
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
200+
&& let attrs = cx.tcx.hir_attrs(item.hir_id())
201201
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
202-
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
202+
&& cx.tcx.hir_attrs(impl_item_hir).is_empty()
203203
{
204204
if adt_def.is_struct() {
205205
check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b));

clippy_lints/src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ fn check_unsafe_derive_deserialize<'tcx>(
384384
.tcx
385385
.inherent_impls(def.did())
386386
.iter()
387-
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
387+
.map(|imp_did| cx.tcx.hir_expect_item(imp_did.expect_local()))
388388
.any(|imp| has_unsafe(cx, imp))
389389
{
390390
span_lint_hir_and_then(

clippy_lints/src/doc/missing_headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn check(
2525
&& cx
2626
.tcx
2727
.hir_parent_iter(owner_id.into())
28-
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
28+
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir_attrs(id)))
2929
{
3030
return;
3131
}

clippy_lints/src/escape.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ impl<'tcx> Delegate<'tcx> for EscapeDelegate<'_, 'tcx> {
163163

164164
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
165165
if cmt.place.projections.is_empty() {
166-
let map = &self.cx.tcx.hir();
167166
if is_argument(self.cx.tcx, cmt.hir_id) {
168167
// Skip closure arguments
169168
let parent_id = self.cx.tcx.parent_hir_id(cmt.hir_id);
@@ -174,7 +173,7 @@ impl<'tcx> Delegate<'tcx> for EscapeDelegate<'_, 'tcx> {
174173
// skip if there is a `self` parameter binding to a type
175174
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
176175
if let Some(trait_self_ty) = self.trait_self_ty {
177-
if map.name(cmt.hir_id) == kw::SelfLower && cmt.place.ty().contains(trait_self_ty) {
176+
if self.cx.tcx.hir_name(cmt.hir_id) == kw::SelfLower && cmt.place.ty().contains(trait_self_ty) {
178177
return;
179178
}
180179
}

clippy_lints/src/exhaustive_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
8484
_ => return,
8585
};
8686
if cx.effective_visibilities.is_exported(item.owner_id.def_id)
87-
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
87+
&& let attrs = cx.tcx.hir_attrs(item.hir_id())
8888
&& !attrs.iter().any(|a| a.has_name(sym::non_exhaustive))
8989
&& fields.iter().all(|f| cx.tcx.visibility(f.def_id).is_public())
9090
{

clippy_lints/src/format_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ impl FormatImplExpr<'_, '_> {
209209
// Handle dereference of &self -> self that is equivalent (i.e. via *self in fmt() impl)
210210
// Since the argument to fmt is itself a reference: &self
211211
let reference = peel_ref_operators(self.cx, arg);
212-
let map = self.cx.tcx.hir();
213212
// Is the reference self?
214-
if path_to_local(reference).map(|x| map.name(x)) == Some(kw::SelfLower) {
213+
if path_to_local(reference).map(|x| self.cx.tcx.hir_name(x)) == Some(kw::SelfLower) {
215214
let FormatTraitNames { name, .. } = self.format_trait_impl;
216215
span_lint(
217216
self.cx,

clippy_lints/src/four_forward_slashes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for FourForwardSlashes {
4343
let sm = cx.sess().source_map();
4444
let mut span = cx
4545
.tcx
46-
.hir()
47-
.attrs(item.hir_id())
46+
.hir_attrs(item.hir_id())
4847
.iter()
4948
.filter(|i| i.is_doc_comment())
5049
.fold(item.span.shrink_to_lo(), |span, attr| span.to(attr.span()));

clippy_lints/src/functions/must_use.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::ops::ControlFlow;
2121
use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
2222

2323
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
24-
let attrs = cx.tcx.hir().attrs(item.hir_id());
24+
let attrs = cx.tcx.hir_attrs(item.hir_id());
2525
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
2626
if let hir::ItemKind::Fn {
2727
ref sig,
@@ -51,7 +51,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
5151
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
5252
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
5353
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
54-
let attrs = cx.tcx.hir().attrs(item.hir_id());
54+
let attrs = cx.tcx.hir_attrs(item.hir_id());
5555
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
5656
if let Some(attr) = attr {
5757
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
@@ -74,7 +74,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
7474
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
7575
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
7676

77-
let attrs = cx.tcx.hir().attrs(item.hir_id());
77+
let attrs = cx.tcx.hir_attrs(item.hir_id());
7878
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
7979
if let Some(attr) = attr {
8080
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);

0 commit comments

Comments
 (0)