Skip to content

Commit 7059c7c

Browse files
committed
Auto merge of #121644 - oli-obk:unique_static_innards2, r=RalfJung,nnethercote
Ensure nested allocations in statics neither get deduplicated nor duplicated This PR generates new `DefId`s for nested allocations in static items and feeds all the right queries to make the compiler believe these are regular `static` items. I chose this design, because all other designs are fragile and make the compiler horribly complex for such a niche use case. At present this wrecks incremental compilation performance *in case nested allocations exist* (because any query creating a `DefId` will be recomputed and never loaded from the cache). This will be resolved later in rust-lang/rust#115613 . All other statics are unaffected by this change and will not have performance regressions (heh, famous last words) This PR contains various smaller refactorings that can be pulled out into separate PRs. It is best reviewed commit-by-commit. The last commit is where the actual magic happens. r? `@RalfJung` on the const interner and engine changes fixes rust-lang/rust#79738
2 parents f5fadcb + b159896 commit 7059c7c

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
101101
Res::Local(hir_id) => {
102102
self.ids.insert(hir_id);
103103
},
104-
Res::Def(DefKind::Static(_), def_id) => {
104+
Res::Def(DefKind::Static{..}, def_id) => {
105105
let mutable = self.cx.tcx.is_mutable_static(def_id);
106106
self.def_ids.insert(def_id, mutable);
107107
},

clippy_lints/src/methods/expect_fun_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(super) fn check<'tcx>(
9191
},
9292
hir::ExprKind::Path(ref p) => matches!(
9393
cx.qpath_res(p, arg.hir_id),
94-
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _)
94+
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static{..}, _)
9595
),
9696
_ => false,
9797
}

clippy_lints/src/multiple_unsafe_ops_per_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>(
109109
ExprKind::Path(QPath::Resolved(
110110
_,
111111
hir::Path {
112-
res: Res::Def(DefKind::Static(Mutability::Mut), _),
112+
res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _),
113113
..
114114
},
115115
)) => {
@@ -149,7 +149,7 @@ fn collect_unsafe_exprs<'tcx>(
149149
ExprKind::Path(QPath::Resolved(
150150
_,
151151
hir::Path {
152-
res: Res::Def(DefKind::Static(Mutability::Mut), _),
152+
res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _),
153153
..
154154
}
155155
))

0 commit comments

Comments
 (0)