Skip to content

Commit da6ea31

Browse files
committed
Change DefKind::Static to a struct variant
1 parent 67a2192 commit da6ea31

File tree

47 files changed

+90
-86
lines changed

Some content is hidden

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

47 files changed

+90
-86
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
195195
.get_partial_res(sym.id)
196196
.and_then(|res| res.full_res())
197197
.and_then(|res| match res {
198-
Res::Def(DefKind::Static(_), def_id) => Some(def_id),
198+
Res::Def(DefKind::Static { .. }, def_id) => Some(def_id),
199199
_ => None,
200200
});
201201

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
8383

8484
// Only consider nodes that actually have exported symbols.
8585
match tcx.def_kind(def_id) {
86-
DefKind::Fn | DefKind::Static(_) => {}
86+
DefKind::Fn | DefKind::Static { .. } => {}
8787
DefKind::AssocFn if tcx.impl_of_method(def_id.to_def_id()).is_some() => {}
8888
_ => return None,
8989
};
@@ -479,7 +479,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
479479
let target = &tcx.sess.target.llvm_target;
480480
// WebAssembly cannot export data symbols, so reduce their export level
481481
if target.contains("emscripten") {
482-
if let DefKind::Static(_) = tcx.def_kind(sym_def_id) {
482+
if let DefKind::Static { .. } = tcx.def_kind(sym_def_id) {
483483
return SymbolExportLevel::Rust;
484484
}
485485
}

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
3737
|| matches!(
3838
ecx.tcx.def_kind(cid.instance.def_id()),
3939
DefKind::Const
40-
| DefKind::Static(_)
40+
| DefKind::Static { .. }
4141
| DefKind::ConstParam
4242
| DefKind::AnonConst
4343
| DefKind::InlineConst

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,16 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
465465
// Special handling for pointers to statics (irrespective of their type).
466466
assert!(!self.ecx.tcx.is_thread_local_static(did));
467467
assert!(self.ecx.tcx.is_static(did));
468-
let is_mut =
469-
matches!(self.ecx.tcx.def_kind(did), DefKind::Static(Mutability::Mut))
470-
|| !self
471-
.ecx
472-
.tcx
473-
.type_of(did)
474-
.no_bound_vars()
475-
.expect("statics should not have generic parameters")
476-
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all());
468+
let is_mut = matches!(
469+
self.ecx.tcx.def_kind(did),
470+
DefKind::Static { mt: Mutability::Mut }
471+
) || !self
472+
.ecx
473+
.tcx
474+
.type_of(did)
475+
.no_bound_vars()
476+
.expect("statics should not have generic parameters")
477+
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all());
477478
// Mode-specific checks
478479
match self.ctfe_mode {
479480
Some(

compiler/rustc_hir/src/def.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ pub enum DefKind {
7575
Const,
7676
/// Constant generic parameter: `struct Foo<const N: usize> { ... }`
7777
ConstParam,
78-
Static(ast::Mutability),
78+
Static {
79+
/// Whether it's a `static mut` or just a `static`.
80+
mt: ast::Mutability,
81+
},
7982
/// Refers to the struct or enum variant's constructor.
8083
///
8184
/// The reason `Ctor` exists in addition to [`DefKind::Struct`] and
@@ -136,7 +139,7 @@ impl DefKind {
136139
DefKind::Fn => "function",
137140
DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
138141
DefKind::Mod => "module",
139-
DefKind::Static(..) => "static",
142+
DefKind::Static { .. } => "static",
140143
DefKind::Enum => "enum",
141144
DefKind::Variant => "variant",
142145
DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
@@ -209,7 +212,7 @@ impl DefKind {
209212
DefKind::Fn
210213
| DefKind::Const
211214
| DefKind::ConstParam
212-
| DefKind::Static(..)
215+
| DefKind::Static { .. }
213216
| DefKind::Ctor(..)
214217
| DefKind::AssocFn
215218
| DefKind::AssocConst => Some(Namespace::ValueNS),
@@ -248,7 +251,7 @@ impl DefKind {
248251
DefKind::Fn
249252
| DefKind::Const
250253
| DefKind::ConstParam
251-
| DefKind::Static(..)
254+
| DefKind::Static { .. }
252255
| DefKind::AssocFn
253256
| DefKind::AssocConst
254257
| DefKind::Field => DefPathData::ValueNs(name),
@@ -278,7 +281,7 @@ impl DefKind {
278281
| DefKind::AssocFn
279282
| DefKind::Ctor(..)
280283
| DefKind::Closure
281-
| DefKind::Static(_) => true,
284+
| DefKind::Static { .. } => true,
282285
DefKind::Mod
283286
| DefKind::Struct
284287
| DefKind::Union

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ impl Expr<'_> {
16161616
pub fn is_place_expr(&self, mut allow_projections_from: impl FnMut(&Self) -> bool) -> bool {
16171617
match self.kind {
16181618
ExprKind::Path(QPath::Resolved(_, ref path)) => {
1619-
matches!(path.res, Res::Local(..) | Res::Def(DefKind::Static(_), _) | Res::Err)
1619+
matches!(path.res, Res::Local(..) | Res::Def(DefKind::Static { .. }, _) | Res::Err)
16201620
}
16211621

16221622
// Type ascription inherits its place expression kind from its

compiler/rustc_hir/src/target.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Target {
107107
match item.kind {
108108
ItemKind::ExternCrate(..) => Target::ExternCrate,
109109
ItemKind::Use(..) => Target::Use,
110-
ItemKind::Static(..) => Target::Static,
110+
ItemKind::Static { .. } => Target::Static,
111111
ItemKind::Const(..) => Target::Const,
112112
ItemKind::Fn(..) => Target::Fn,
113113
ItemKind::Macro(..) => Target::MacroDef,
@@ -130,7 +130,7 @@ impl Target {
130130
match def_kind {
131131
DefKind::ExternCrate => Target::ExternCrate,
132132
DefKind::Use => Target::Use,
133-
DefKind::Static(..) => Target::Static,
133+
DefKind::Static { .. } => Target::Static,
134134
DefKind::Const => Target::Const,
135135
DefKind::Fn => Target::Fn,
136136
DefKind::Macro(..) => Target::MacroDef,

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19371937
}
19381938

19391939
// Case 3. Reference to a top-level value.
1940-
DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static(_) => {
1940+
DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
19411941
path_segs.push(PathSeg(def_id, last));
19421942
}
19431943

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
226226
Ok(l) => l,
227227
// Foreign statics that overflow their allowed size should emit an error
228228
Err(LayoutError::SizeOverflow(_))
229-
if matches!(tcx.def_kind(def_id), DefKind::Static(_)
229+
if matches!(tcx.def_kind(def_id), DefKind::Static{..}
230230
if tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod) =>
231231
{
232232
tcx.dcx().emit_err(errors::TooLargeStatic { span });
@@ -514,7 +514,7 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
514514
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
515515
let _indenter = indenter();
516516
match tcx.def_kind(def_id) {
517-
DefKind::Static(..) => {
517+
DefKind::Static { .. } => {
518518
tcx.ensure().typeck(def_id);
519519
maybe_check_static_with_link_section(tcx, def_id);
520520
check_static_inhabited(tcx, def_id);

compiler/rustc_hir_analysis/src/check/errs.rs

Lines changed: 1 addition & 1 deletion
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 } = def_kind
5353
&& matches!(mt, Mutability::Mut)
5454
{
5555
return Some(qpath_to_string(&qpath));

0 commit comments

Comments
 (0)