Skip to content

Commit 53ffcd9

Browse files
committed
Remove mutability from Def::Static
1 parent 6c187cc commit 53ffcd9

File tree

12 files changed

+26
-35
lines changed

12 files changed

+26
-35
lines changed

src/librustc/hir/def.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum Def<Id = hir::HirId> {
7373
Fn(DefId),
7474
Const(DefId),
7575
ConstParam(DefId),
76-
Static(DefId, bool /* is_mutbl */),
76+
Static(DefId),
7777
/// `DefId` refers to the struct or enum variant's constructor.
7878
Ctor(DefId, CtorOf, CtorKind),
7979
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
@@ -291,7 +291,7 @@ impl<Id> Def<Id> {
291291
/// Return `Some(..)` with the `DefId` of this `Def` if it has a id, else `None`.
292292
pub fn opt_def_id(&self) -> Option<DefId> {
293293
match *self {
294-
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
294+
Def::Fn(id) | Def::Mod(id) | Def::Static(id) |
295295
Def::Variant(id) | Def::Ctor(id, ..) | Def::Enum(id) |
296296
Def::TyAlias(id) | Def::TraitAlias(id) |
297297
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
@@ -379,7 +379,7 @@ impl<Id> Def<Id> {
379379
match self {
380380
Def::Fn(id) => Def::Fn(id),
381381
Def::Mod(id) => Def::Mod(id),
382-
Def::Static(id, is_mutbl) => Def::Static(id, is_mutbl),
382+
Def::Static(id) => Def::Static(id),
383383
Def::Enum(id) => Def::Enum(id),
384384
Def::Variant(id) => Def::Variant(id),
385385
Def::Ctor(a, b, c) => Def::Ctor(a, b, c),

src/librustc/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'hir> Map<'hir> {
322322
let def_id = || self.local_def_id_from_hir_id(item.hir_id);
323323

324324
match item.node {
325-
ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)),
325+
ItemKind::Static(..) => Some(Def::Static(def_id())),
326326
ItemKind::Const(..) => Some(Def::Const(def_id())),
327327
ItemKind::Fn(..) => Some(Def::Fn(def_id())),
328328
ItemKind::Mod(..) => Some(Def::Mod(def_id())),
@@ -344,7 +344,7 @@ impl<'hir> Map<'hir> {
344344
let def_id = self.local_def_id_from_hir_id(item.hir_id);
345345
match item.node {
346346
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
347-
ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)),
347+
ForeignItemKind::Static(..) => Some(Def::Static(def_id)),
348348
ForeignItemKind::Type => Some(Def::ForeignTy(def_id)),
349349
}
350350
}

src/librustc/middle/mem_categorization.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
705705
Ok(self.cat_rvalue_node(hir_id, span, expr_ty))
706706
}
707707

708-
Def::Static(def_id, mutbl) => {
708+
Def::Static(def_id) => {
709709
// `#[thread_local]` statics may not outlive the current function, but
710710
// they also cannot be moved out of.
711711
let is_thread_local = self.tcx.get_attrs(def_id)[..]
@@ -723,7 +723,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
723723
hir_id,
724724
span,
725725
cat,
726-
mutbl: if mutbl { McDeclared } else { McImmutable},
726+
mutbl: match self.tcx.static_mutability(def_id).unwrap() {
727+
hir::MutImmutable => McImmutable,
728+
hir::MutMutable => McDeclared,
729+
},
727730
ty:expr_ty,
728731
note: NoteNone
729732
})

src/librustc_codegen_ssa/mono_item.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc::hir;
2-
use rustc::hir::def::Def;
32
use rustc::mir::mono::{Linkage, Visibility};
43
use rustc::ty::layout::HasTyCtxt;
54
use std::fmt;
@@ -19,17 +18,7 @@ pub trait MonoItemExt<'a, 'tcx: 'a>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
1918

2019
match *self.as_mono_item() {
2120
MonoItem::Static(def_id) => {
22-
let tcx = cx.tcx();
23-
let is_mutable = match tcx.describe_def(def_id) {
24-
Some(Def::Static(_, is_mutable)) => is_mutable,
25-
Some(other) => {
26-
bug!("Expected Def::Static, found {:?}", other)
27-
}
28-
None => {
29-
bug!("Expected Def::Static for {:?}, found nothing", def_id)
30-
}
31-
};
32-
cx.codegen_static(def_id, is_mutable);
21+
cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
3322
}
3423
MonoItem::GlobalAsm(hir_id) => {
3524
let item = cx.tcx().hir().expect_item_by_hir_id(hir_id);

src/librustc_metadata/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ impl<'tcx> EntryKind<'tcx> {
404404
EntryKind::Const(..) => Def::Const(did),
405405
EntryKind::AssociatedConst(..) => Def::AssociatedConst(did),
406406
EntryKind::ImmStatic |
407-
EntryKind::ForeignImmStatic => Def::Static(did, false),
408407
EntryKind::MutStatic |
409-
EntryKind::ForeignMutStatic => Def::Static(did, true),
408+
EntryKind::ForeignImmStatic |
409+
EntryKind::ForeignMutStatic => Def::Static(did),
410410
EntryKind::Struct(_, _) => Def::Struct(did),
411411
EntryKind::Union(_, _) => Def::Union(did),
412412
EntryKind::Fn(_) |

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
960960
}
961961
}
962962

963-
Def::Static(node_id, _) => ExprKind::StaticRef { id: node_id },
963+
Def::Static(id) => ExprKind::StaticRef { id },
964964

965965
Def::Local(..) | Def::Upvar(..) => convert_var(cx, expr, def),
966966

src/librustc_mir/util/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ fn write_mir_sig(
592592
match (descr, src.promoted) {
593593
(_, Some(i)) => write!(w, "{:?} in ", i)?,
594594
(Some(Def::Const(_)), _) | (Some(Def::AssociatedConst(_)), _) => write!(w, "const ")?,
595-
(Some(Def::Static(_, /*is_mutbl*/false)), _) => write!(w, "static ")?,
596-
(Some(Def::Static(_, /*is_mutbl*/true)), _) => write!(w, "static mut ")?,
595+
(Some(Def::Static(def_id)), _) =>
596+
write!(w, "static {}", if tcx.is_mutable_static(def_id) { "mut " } else { "" })?,
597597
(_, _) if is_function => write!(w, "fn ")?,
598598
(None, _) => {}, // things like anon const, not an item
599599
_ => bug!("Unexpected def description {:?}", descr),

src/librustc_passes/rvalue_promotion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn check_expr_kind<'a, 'tcx>(
329329
// are inherently promotable with the exception
330330
// of "#[thread_local]" statics, which may not
331331
// outlive the current function
332-
Def::Static(did, _) => {
332+
Def::Static(did) => {
333333

334334
if v.in_static {
335335
for attr in &v.tcx.get_attrs(did)[..] {

src/librustc_resolve/build_reduced_graph.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use syntax::ast::{Name, Ident};
2828
use syntax::attr;
2929

3030
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
31-
use syntax::ast::{MetaItemKind, Mutability, StmtKind, TraitItem, TraitItemKind, Variant};
31+
use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant};
3232
use syntax::ext::base::{MacroKind, SyntaxExtension};
3333
use syntax::ext::base::Determinacy::Undetermined;
3434
use syntax::ext::hygiene::Mark;
@@ -442,9 +442,8 @@ impl<'a> Resolver<'a> {
442442
ItemKind::ForeignMod(..) => {}
443443

444444
// These items live in the value namespace.
445-
ItemKind::Static(_, m, _) => {
446-
let mutbl = m == Mutability::Mutable;
447-
let def = Def::Static(self.definitions.local_def_id(item.id), mutbl);
445+
ItemKind::Static(..) => {
446+
let def = Def::Static(self.definitions.local_def_id(item.id));
448447
self.define(parent, ident, ValueNS, (def, vis, sp, expansion));
449448
}
450449
ItemKind::Const(..) => {
@@ -616,8 +615,8 @@ impl<'a> Resolver<'a> {
616615
ForeignItemKind::Fn(..) => {
617616
(Def::Fn(self.definitions.local_def_id(item.id)), ValueNS)
618617
}
619-
ForeignItemKind::Static(_, m) => {
620-
(Def::Static(self.definitions.local_def_id(item.id), m), ValueNS)
618+
ForeignItemKind::Static(..) => {
619+
(Def::Static(self.definitions.local_def_id(item.id)), ValueNS)
621620
}
622621
ForeignItemKind::Ty => {
623622
(Def::ForeignTy(self.definitions.local_def_id(item.id)), TypeNS)

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
16651665
Def::Fn(def_id) |
16661666
Def::Const(def_id) |
16671667
Def::ConstParam(def_id) |
1668-
Def::Static(def_id, _) => {
1668+
Def::Static(def_id) => {
16691669
path_segs.push(PathSeg(def_id, last));
16701670
}
16711671

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ pub fn try_inline(
9393
record_extern_fqn(cx, did, clean::TypeKind::Module);
9494
clean::ModuleItem(build_module(cx, did, visited))
9595
}
96-
Def::Static(did, mtbl) => {
96+
Def::Static(did) => {
9797
record_extern_fqn(cx, did, clean::TypeKind::Static);
98-
clean::StaticItem(build_static(cx, did, mtbl))
98+
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
9999
}
100100
Def::Const(did) => {
101101
record_extern_fqn(cx, did, clean::TypeKind::Const);

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4204,7 +4204,7 @@ pub fn register_def(cx: &DocContext<'_>, def: Def) -> DefId {
42044204
Def::Mod(i) => (i, TypeKind::Module),
42054205
Def::ForeignTy(i) => (i, TypeKind::Foreign),
42064206
Def::Const(i) => (i, TypeKind::Const),
4207-
Def::Static(i, _) => (i, TypeKind::Static),
4207+
Def::Static(i) => (i, TypeKind::Static),
42084208
Def::Variant(i) => (cx.tcx.parent(i).expect("cannot get parent def id"),
42094209
TypeKind::Enum),
42104210
Def::Macro(i, mac_kind) => match mac_kind {

0 commit comments

Comments
 (0)