about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-03-29 17:11:12 +0200
committerCamille GILLOT <gillot.camille@gmail.com>2022-03-29 18:50:52 +0200
commite01897edcbcf89952b1823125c199a4ce8ec628d (patch)
tree45c3888db7b14e1b2044e652b15b35aa1f866eea
parenta7da8a601903eb3bd70523644dd0ce936359c13a (diff)
downloadrust-e01897edcbcf89952b1823125c199a4ce8ec628d.tar.gz
rust-e01897edcbcf89952b1823125c199a4ce8ec628d.zip
Remember mutability in `DefKind::Static`.
This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.
-rw-r--r--clippy_lints/src/arithmetic.rs4
-rw-r--r--clippy_lints/src/loops/needless_range_loop.rs2
-rw-r--r--clippy_lints/src/loops/while_immutable_condition.rs2
-rw-r--r--clippy_lints/src/methods/expect_fun_call.rs2
-rw-r--r--clippy_lints/src/shadow.rs10
5 files changed, 13 insertions, 7 deletions
diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs
index e0c1d6ab6e1..c5948707c81 100644
--- a/clippy_lints/src/arithmetic.rs
+++ b/clippy_lints/src/arithmetic.rs
@@ -139,11 +139,11 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
     }
 
     fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
-        let body_owner = cx.tcx.hir().body_owner(body.id());
+        let body_owner = cx.tcx.hir().body_owner_def_id(body.id());
 
         match cx.tcx.hir().body_owner_kind(body_owner) {
             hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => {
-                let body_span = cx.tcx.hir().span(body_owner);
+                let body_span = cx.tcx.def_span(body_owner);
 
                 if let Some(span) = self.const_span {
                     if span.contains(body_span) {
diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs
index 9d335073e4f..72e86804ed2 100644
--- a/clippy_lints/src/loops/needless_range_loop.rs
+++ b/clippy_lints/src/loops/needless_range_loop.rs
@@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
                         }
                         return false;  // no need to walk further *on the variable*
                     }
-                    Res::Def(DefKind::Static | DefKind::Const, ..) => {
+                    Res::Def(DefKind::Static (_)| DefKind::Const, ..) => {
                         if index_used_directly {
                             self.indexed_directly.insert(
                                 seqvar.segments[0].ident.name,
diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs
index 5dcfed65c78..a63422d2a36 100644
--- a/clippy_lints/src/loops/while_immutable_condition.rs
+++ b/clippy_lints/src/loops/while_immutable_condition.rs
@@ -104,7 +104,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
                     Res::Local(hir_id) => {
                         self.ids.insert(hir_id);
                     },
-                    Res::Def(DefKind::Static, def_id) => {
+                    Res::Def(DefKind::Static(_), def_id) => {
                         let mutable = self.cx.tcx.is_mutable_static(def_id);
                         self.def_ids.insert(def_id, mutable);
                     },
diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs
index c3cb02329a1..6f2307d8f18 100644
--- a/clippy_lints/src/methods/expect_fun_call.rs
+++ b/clippy_lints/src/methods/expect_fun_call.rs
@@ -93,7 +93,7 @@ pub(super) fn check<'tcx>(
             },
             hir::ExprKind::Path(ref p) => matches!(
                 cx.qpath_res(p, arg.hir_id),
-                hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _)
+                hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _)
             ),
             _ => false,
         }
diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs
index ce05c5a6164..11882585044 100644
--- a/clippy_lints/src/shadow.rs
+++ b/clippy_lints/src/shadow.rs
@@ -139,14 +139,20 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
 
     fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
         let hir = cx.tcx.hir();
-        if !matches!(hir.body_owner_kind(hir.body_owner(body.id())), BodyOwnerKind::Closure) {
+        if !matches!(
+            hir.body_owner_kind(hir.body_owner_def_id(body.id())),
+            BodyOwnerKind::Closure
+        ) {
             self.bindings.push(FxHashMap::default());
         }
     }
 
     fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
         let hir = cx.tcx.hir();
-        if !matches!(hir.body_owner_kind(hir.body_owner(body.id())), BodyOwnerKind::Closure) {
+        if !matches!(
+            hir.body_owner_kind(hir.body_owner_def_id(body.id())),
+            BodyOwnerKind::Closure
+        ) {
             self.bindings.pop();
         }
     }