Skip to content

Commit 71c1e87

Browse files
committed
Auto merge of rust-lang#95436 - cjgillot:static-mut, r=oli-obk
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.
2 parents 104ba47 + e01897e commit 71c1e87

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

clippy_lints/src/arithmetic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
139139
}
140140

141141
fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
142-
let body_owner = cx.tcx.hir().body_owner(body.id());
142+
let body_owner = cx.tcx.hir().body_owner_def_id(body.id());
143143

144144
match cx.tcx.hir().body_owner_kind(body_owner) {
145145
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => {
146-
let body_span = cx.tcx.hir().span(body_owner);
146+
let body_span = cx.tcx.def_span(body_owner);
147147

148148
if let Some(span) = self.const_span {
149149
if span.contains(body_span) {

clippy_lints/src/loops/needless_range_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
273273
}
274274
return false; // no need to walk further *on the variable*
275275
}
276-
Res::Def(DefKind::Static | DefKind::Const, ..) => {
276+
Res::Def(DefKind::Static (_)| DefKind::Const, ..) => {
277277
if index_used_directly {
278278
self.indexed_directly.insert(
279279
seqvar.segments[0].ident.name,

clippy_lints/src/loops/while_immutable_condition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
104104
Res::Local(hir_id) => {
105105
self.ids.insert(hir_id);
106106
},
107-
Res::Def(DefKind::Static, def_id) => {
107+
Res::Def(DefKind::Static(_), def_id) => {
108108
let mutable = self.cx.tcx.is_mutable_static(def_id);
109109
self.def_ids.insert(def_id, mutable);
110110
},

clippy_lints/src/methods/expect_fun_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub(super) fn check<'tcx>(
9393
},
9494
hir::ExprKind::Path(ref p) => matches!(
9595
cx.qpath_res(p, arg.hir_id),
96-
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _)
96+
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _)
9797
),
9898
_ => false,
9999
}

clippy_lints/src/shadow.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,20 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
139139

140140
fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
141141
let hir = cx.tcx.hir();
142-
if !matches!(hir.body_owner_kind(hir.body_owner(body.id())), BodyOwnerKind::Closure) {
142+
if !matches!(
143+
hir.body_owner_kind(hir.body_owner_def_id(body.id())),
144+
BodyOwnerKind::Closure
145+
) {
143146
self.bindings.push(FxHashMap::default());
144147
}
145148
}
146149

147150
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
148151
let hir = cx.tcx.hir();
149-
if !matches!(hir.body_owner_kind(hir.body_owner(body.id())), BodyOwnerKind::Closure) {
152+
if !matches!(
153+
hir.body_owner_kind(hir.body_owner_def_id(body.id())),
154+
BodyOwnerKind::Closure
155+
) {
150156
self.bindings.pop();
151157
}
152158
}

0 commit comments

Comments
 (0)