Skip to content

Commit 2a98b51

Browse files
committed
Add nested bool to DefKind::Static.
Will be used in the next commit
1 parent da6ea31 commit 2a98b51

File tree

10 files changed

+19
-13
lines changed

10 files changed

+19
-13
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
467467
assert!(self.ecx.tcx.is_static(did));
468468
let is_mut = matches!(
469469
self.ecx.tcx.def_kind(did),
470-
DefKind::Static { mt: Mutability::Mut }
470+
DefKind::Static { mt: Mutability::Mut, .. }
471471
) || !self
472472
.ecx
473473
.tcx

compiler/rustc_hir/src/def.rs

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub enum DefKind {
7878
Static {
7979
/// Whether it's a `static mut` or just a `static`.
8080
mt: ast::Mutability,
81+
/// Whether it's an anonymous static generated for nested allocations.
82+
nested: bool,
8183
},
8284
/// Refers to the struct or enum variant's constructor.
8385
///

compiler/rustc_hir_analysis/src/check/errs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn is_path_static_mut(expr: hir::Expr<'_>) -> Option<String> {
4949
if let hir::ExprKind::Path(qpath) = expr.kind
5050
&& let hir::QPath::Resolved(_, path) = qpath
5151
&& let hir::def::Res::Def(def_kind, _) = path.res
52-
&& let hir::def::DefKind::Static { mt } = def_kind
52+
&& let hir::def::DefKind::Static { mt, nested: false } = def_kind
5353
&& matches!(mt, Mutability::Mut)
5454
{
5555
return Some(qpath_to_string(&qpath));

compiler/rustc_metadata/src/rmeta/table.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ fixed_size_enum! {
155155
( Impl { of_trait: false } )
156156
( Impl { of_trait: true } )
157157
( Closure )
158-
( Static{mt:ast::Mutability::Not} )
159-
( Static{mt:ast::Mutability::Mut} )
158+
( Static{mt:ast::Mutability::Not, nested: false})
159+
( Static{mt:ast::Mutability::Mut, nested: false})
160+
( Static{mt:ast::Mutability::Not, nested: true})
161+
( Static{mt:ast::Mutability::Mut, nested: true})
160162
( Ctor(CtorOf::Struct, CtorKind::Fn) )
161163
( Ctor(CtorOf::Struct, CtorKind::Const) )
162164
( Ctor(CtorOf::Variant, CtorKind::Fn) )

compiler/rustc_middle/src/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'hir> Map<'hir> {
344344
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
345345
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
346346
DefKind::Closure => BodyOwnerKind::Closure,
347-
DefKind::Static { mt } => BodyOwnerKind::Static(mt),
347+
DefKind::Static { mt, nested: false } => BodyOwnerKind::Static(mt),
348348
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
349349
}
350350
}

compiler/rustc_middle/src/mir/pretty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,10 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
498498
match (kind, body.source.promoted) {
499499
(_, Some(i)) => write!(w, "{i:?} in ")?,
500500
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
501-
(DefKind::Static { mt: hir::Mutability::Not }, _) => write!(w, "static ")?,
502-
(DefKind::Static { mt: hir::Mutability::Mut }, _) => write!(w, "static mut ")?,
501+
(DefKind::Static { mt: hir::Mutability::Not, nested: false }, _) => write!(w, "static ")?,
502+
(DefKind::Static { mt: hir::Mutability::Mut, nested: false }, _) => {
503+
write!(w, "static mut ")?
504+
}
503505
(_, _) if is_function => write!(w, "fn ")?,
504506
(DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item
505507
_ => bug!("Unexpected def kind {:?}", kind),

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'tcx> TyCtxt<'tcx> {
621621

622622
#[inline]
623623
pub fn static_mutability(self, def_id: DefId) -> Option<hir::Mutability> {
624-
if let DefKind::Static { mt } = self.def_kind(def_id) { Some(mt) } else { None }
624+
if let DefKind::Static { mt, .. } = self.def_kind(def_id) { Some(mt) } else { None }
625625
}
626626

627627
/// Returns `true` if this is a `static` item with the `#[thread_local]` attribute.

compiler/rustc_resolve/src/def_collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
125125
ItemKind::Union(..) => DefKind::Union,
126126
ItemKind::ExternCrate(..) => DefKind::ExternCrate,
127127
ItemKind::TyAlias(..) => DefKind::TyAlias,
128-
ItemKind::Static(s) => DefKind::Static { mt: s.mutability },
128+
ItemKind::Static(s) => DefKind::Static { mt: s.mutability, nested: false },
129129
ItemKind::Const(..) => DefKind::Const,
130130
ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
131131
ItemKind::MacroDef(..) => {
@@ -212,7 +212,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
212212

213213
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
214214
let def_kind = match fi.kind {
215-
ForeignItemKind::Static(_, mt, _) => DefKind::Static { mt },
215+
ForeignItemKind::Static(_, mt, _) => DefKind::Static { mt, nested: false },
216216
ForeignItemKind::Fn(_) => DefKind::Fn,
217217
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
218218
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ impl Disambiguator {
15151515
"union" => Kind(DefKind::Union),
15161516
"module" | "mod" => Kind(DefKind::Mod),
15171517
"const" | "constant" => Kind(DefKind::Const),
1518-
"static" => Kind(DefKind::Static { mt: Mutability::Not }),
1518+
"static" => Kind(DefKind::Static { mt: Mutability::Not, nested: false }),
15191519
"function" | "fn" | "method" => Kind(DefKind::Fn),
15201520
"derive" => Kind(DefKind::Macro(MacroKind::Derive)),
15211521
"type" => NS(Namespace::TypeNS),

src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs

+2-2
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{mt:Mutability::Mut}, _),
112+
res: Res::Def(DefKind::Static{mt: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{mt:Mutability::Mut}, _),
152+
res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _),
153153
..
154154
}
155155
))

0 commit comments

Comments
 (0)