Skip to content
Permalink
Browse files

Remove mutability from `Def::Static`

  • Loading branch information...
petrochenkov committed Apr 19, 2019
1 parent 6c187cc commit 53ffcd96b7588669029467e5f23b699ff3283173
@@ -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
@@ -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) |
@@ -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),
@@ -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())),
@@ -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)),
}
}
@@ -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)[..]
@@ -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
})
@@ -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;
@@ -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);
@@ -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(_) |
@@ -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),

@@ -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),
@@ -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)[..] {
@@ -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;
@@ -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(..) => {
@@ -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)
@@ -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));
}

@@ -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);
@@ -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 {

0 comments on commit 53ffcd9

Please sign in to comment.
You can’t perform that action at this time.