Skip to content

Commit

Permalink
Remove mutability from Def::Static
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 21, 2019
1 parent 6c187cc commit 53ffcd9
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/def.rs
Expand Up @@ -73,7 +73,7 @@ pub enum Def<Id = hir::HirId> {
Fn(DefId),
Const(DefId),
ConstParam(DefId),
Static(DefId, bool /* is_mutbl */),
Static(DefId),
/// `DefId` refers to the struct or enum variant's constructor.
Ctor(DefId, CtorOf, CtorKind),
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<Id> Def<Id> {
/// Return `Some(..)` with the `DefId` of this `Def` if it has a id, else `None`.
pub fn opt_def_id(&self) -> Option<DefId> {
match *self {
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
Def::Fn(id) | Def::Mod(id) | Def::Static(id) |
Def::Variant(id) | Def::Ctor(id, ..) | Def::Enum(id) |
Def::TyAlias(id) | Def::TraitAlias(id) |
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
Expand Down Expand Up @@ -379,7 +379,7 @@ impl<Id> Def<Id> {
match self {
Def::Fn(id) => Def::Fn(id),
Def::Mod(id) => Def::Mod(id),
Def::Static(id, is_mutbl) => Def::Static(id, is_mutbl),
Def::Static(id) => Def::Static(id),
Def::Enum(id) => Def::Enum(id),
Def::Variant(id) => Def::Variant(id),
Def::Ctor(a, b, c) => Def::Ctor(a, b, c),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -322,7 +322,7 @@ impl<'hir> Map<'hir> {
let def_id = || self.local_def_id_from_hir_id(item.hir_id);

match item.node {
ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)),
ItemKind::Static(..) => Some(Def::Static(def_id())),
ItemKind::Const(..) => Some(Def::Const(def_id())),
ItemKind::Fn(..) => Some(Def::Fn(def_id())),
ItemKind::Mod(..) => Some(Def::Mod(def_id())),
Expand All @@ -344,7 +344,7 @@ impl<'hir> Map<'hir> {
let def_id = self.local_def_id_from_hir_id(item.hir_id);
match item.node {
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)),
ForeignItemKind::Static(..) => Some(Def::Static(def_id)),
ForeignItemKind::Type => Some(Def::ForeignTy(def_id)),
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -705,7 +705,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
Ok(self.cat_rvalue_node(hir_id, span, expr_ty))
}

Def::Static(def_id, mutbl) => {
Def::Static(def_id) => {
// `#[thread_local]` statics may not outlive the current function, but
// they also cannot be moved out of.
let is_thread_local = self.tcx.get_attrs(def_id)[..]
Expand All @@ -723,7 +723,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
hir_id,
span,
cat,
mutbl: if mutbl { McDeclared } else { McImmutable},
mutbl: match self.tcx.static_mutability(def_id).unwrap() {
hir::MutImmutable => McImmutable,
hir::MutMutable => McDeclared,
},
ty:expr_ty,
note: NoteNone
})
Expand Down
13 changes: 1 addition & 12 deletions src/librustc_codegen_ssa/mono_item.rs
@@ -1,5 +1,4 @@
use rustc::hir;
use rustc::hir::def::Def;
use rustc::mir::mono::{Linkage, Visibility};
use rustc::ty::layout::HasTyCtxt;
use std::fmt;
Expand All @@ -19,17 +18,7 @@ pub trait MonoItemExt<'a, 'tcx: 'a>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {

match *self.as_mono_item() {
MonoItem::Static(def_id) => {
let tcx = cx.tcx();
let is_mutable = match tcx.describe_def(def_id) {
Some(Def::Static(_, is_mutable)) => is_mutable,
Some(other) => {
bug!("Expected Def::Static, found {:?}", other)
}
None => {
bug!("Expected Def::Static for {:?}, found nothing", def_id)
}
};
cx.codegen_static(def_id, is_mutable);
cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
}
MonoItem::GlobalAsm(hir_id) => {
let item = cx.tcx().hir().expect_item_by_hir_id(hir_id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -404,9 +404,9 @@ impl<'tcx> EntryKind<'tcx> {
EntryKind::Const(..) => Def::Const(did),
EntryKind::AssociatedConst(..) => Def::AssociatedConst(did),
EntryKind::ImmStatic |
EntryKind::ForeignImmStatic => Def::Static(did, false),
EntryKind::MutStatic |
EntryKind::ForeignMutStatic => Def::Static(did, true),
EntryKind::ForeignImmStatic |
EntryKind::ForeignMutStatic => Def::Static(did),
EntryKind::Struct(_, _) => Def::Struct(did),
EntryKind::Union(_, _) => Def::Union(did),
EntryKind::Fn(_) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -960,7 +960,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
}
}

Def::Static(node_id, _) => ExprKind::StaticRef { id: node_id },
Def::Static(id) => ExprKind::StaticRef { id },

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

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/util/pretty.rs
Expand Up @@ -592,8 +592,8 @@ fn write_mir_sig(
match (descr, src.promoted) {
(_, Some(i)) => write!(w, "{:?} in ", i)?,
(Some(Def::Const(_)), _) | (Some(Def::AssociatedConst(_)), _) => write!(w, "const ")?,
(Some(Def::Static(_, /*is_mutbl*/false)), _) => write!(w, "static ")?,
(Some(Def::Static(_, /*is_mutbl*/true)), _) => write!(w, "static mut ")?,
(Some(Def::Static(def_id)), _) =>
write!(w, "static {}", if tcx.is_mutable_static(def_id) { "mut " } else { "" })?,
(_, _) if is_function => write!(w, "fn ")?,
(None, _) => {}, // things like anon const, not an item
_ => bug!("Unexpected def description {:?}", descr),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/rvalue_promotion.rs
Expand Up @@ -329,7 +329,7 @@ fn check_expr_kind<'a, 'tcx>(
// are inherently promotable with the exception
// of "#[thread_local]" statics, which may not
// outlive the current function
Def::Static(did, _) => {
Def::Static(did) => {

if v.in_static {
for attr in &v.tcx.get_attrs(did)[..] {
Expand Down
11 changes: 5 additions & 6 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -28,7 +28,7 @@ use syntax::ast::{Name, Ident};
use syntax::attr;

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

// These items live in the value namespace.
ItemKind::Static(_, m, _) => {
let mutbl = m == Mutability::Mutable;
let def = Def::Static(self.definitions.local_def_id(item.id), mutbl);
ItemKind::Static(..) => {
let def = Def::Static(self.definitions.local_def_id(item.id));
self.define(parent, ident, ValueNS, (def, vis, sp, expansion));
}
ItemKind::Const(..) => {
Expand Down Expand Up @@ -616,8 +615,8 @@ impl<'a> Resolver<'a> {
ForeignItemKind::Fn(..) => {
(Def::Fn(self.definitions.local_def_id(item.id)), ValueNS)
}
ForeignItemKind::Static(_, m) => {
(Def::Static(self.definitions.local_def_id(item.id), m), ValueNS)
ForeignItemKind::Static(..) => {
(Def::Static(self.definitions.local_def_id(item.id)), ValueNS)
}
ForeignItemKind::Ty => {
(Def::ForeignTy(self.definitions.local_def_id(item.id)), TypeNS)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Expand Up @@ -1665,7 +1665,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
Def::Fn(def_id) |
Def::Const(def_id) |
Def::ConstParam(def_id) |
Def::Static(def_id, _) => {
Def::Static(def_id) => {
path_segs.push(PathSeg(def_id, last));
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -93,9 +93,9 @@ pub fn try_inline(
record_extern_fqn(cx, did, clean::TypeKind::Module);
clean::ModuleItem(build_module(cx, did, visited))
}
Def::Static(did, mtbl) => {
Def::Static(did) => {
record_extern_fqn(cx, did, clean::TypeKind::Static);
clean::StaticItem(build_static(cx, did, mtbl))
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
}
Def::Const(did) => {
record_extern_fqn(cx, did, clean::TypeKind::Const);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -4204,7 +4204,7 @@ pub fn register_def(cx: &DocContext<'_>, def: Def) -> DefId {
Def::Mod(i) => (i, TypeKind::Module),
Def::ForeignTy(i) => (i, TypeKind::Foreign),
Def::Const(i) => (i, TypeKind::Const),
Def::Static(i, _) => (i, TypeKind::Static),
Def::Static(i) => (i, TypeKind::Static),
Def::Variant(i) => (cx.tcx.parent(i).expect("cannot get parent def id"),
TypeKind::Enum),
Def::Macro(i, mac_kind) => match mac_kind {
Expand Down

0 comments on commit 53ffcd9

Please sign in to comment.