s/mt/mutability/
This commit is contained in:
parent
d3514a036d
commit
926bfe5078
11 changed files with 28 additions and 21 deletions
|
@ -102,7 +102,7 @@ fn intern_as_new_static<'tcx>(
|
||||||
let feed = tcx.create_def(
|
let feed = tcx.create_def(
|
||||||
static_id,
|
static_id,
|
||||||
sym::nested,
|
sym::nested,
|
||||||
DefKind::Static { mt: alloc.0.mutability, nested: true },
|
DefKind::Static { mutability: alloc.0.mutability, nested: true },
|
||||||
);
|
);
|
||||||
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
|
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
|
||||||
feed.codegen_fn_attrs(tcx.codegen_fn_attrs(static_id).clone());
|
feed.codegen_fn_attrs(tcx.codegen_fn_attrs(static_id).clone());
|
||||||
|
|
|
@ -484,11 +484,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||||
// Return alloc mutability. For "root" statics we look at the type to account for interior
|
// Return alloc mutability. For "root" statics we look at the type to account for interior
|
||||||
// mutability; for nested statics we have no type and directly use the annotated mutability.
|
// mutability; for nested statics we have no type and directly use the annotated mutability.
|
||||||
match self.ecx.tcx.def_kind(did) {
|
match self.ecx.tcx.def_kind(did) {
|
||||||
DefKind::Static { mt: Mutability::Mut, .. } => Mutability::Mut,
|
DefKind::Static { mutability: Mutability::Mut, .. } => Mutability::Mut,
|
||||||
DefKind::Static { mt: Mutability::Not, nested: true } => {
|
DefKind::Static { mutability: Mutability::Not, nested: true } => {
|
||||||
Mutability::Not
|
Mutability::Not
|
||||||
}
|
}
|
||||||
DefKind::Static { mt: Mutability::Not, nested: false }
|
DefKind::Static { mutability: Mutability::Not, nested: false }
|
||||||
if !self
|
if !self
|
||||||
.ecx
|
.ecx
|
||||||
.tcx
|
.tcx
|
||||||
|
|
|
@ -77,7 +77,7 @@ pub enum DefKind {
|
||||||
ConstParam,
|
ConstParam,
|
||||||
Static {
|
Static {
|
||||||
/// Whether it's a `static mut` or just a `static`.
|
/// Whether it's a `static mut` or just a `static`.
|
||||||
mt: ast::Mutability,
|
mutability: ast::Mutability,
|
||||||
/// Whether it's an anonymous static generated for nested allocations.
|
/// Whether it's an anonymous static generated for nested allocations.
|
||||||
nested: bool,
|
nested: bool,
|
||||||
},
|
},
|
||||||
|
|
|
@ -48,8 +48,7 @@ fn is_path_static_mut(expr: hir::Expr<'_>) -> Option<String> {
|
||||||
if let hir::ExprKind::Path(qpath) = expr.kind
|
if let hir::ExprKind::Path(qpath) = expr.kind
|
||||||
&& let hir::QPath::Resolved(_, path) = qpath
|
&& let hir::QPath::Resolved(_, path) = qpath
|
||||||
&& let hir::def::Res::Def(def_kind, _) = path.res
|
&& let hir::def::Res::Def(def_kind, _) = path.res
|
||||||
&& let hir::def::DefKind::Static { mt, nested: false } = def_kind
|
&& let hir::def::DefKind::Static { mutability: Mutability::Mut, nested: false } = def_kind
|
||||||
&& matches!(mt, Mutability::Mut)
|
|
||||||
{
|
{
|
||||||
return Some(qpath_to_string(&qpath));
|
return Some(qpath_to_string(&qpath));
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,10 +155,10 @@ fixed_size_enum! {
|
||||||
( Impl { of_trait: false } )
|
( Impl { of_trait: false } )
|
||||||
( Impl { of_trait: true } )
|
( Impl { of_trait: true } )
|
||||||
( Closure )
|
( Closure )
|
||||||
( Static{mt:ast::Mutability::Not, nested: false})
|
( Static { mutability: ast::Mutability::Not, nested: false } )
|
||||||
( Static{mt:ast::Mutability::Mut, nested: false})
|
( Static { mutability: ast::Mutability::Mut, nested: false } )
|
||||||
( Static{mt:ast::Mutability::Not, nested: true})
|
( Static { mutability: ast::Mutability::Not, nested: true } )
|
||||||
( Static{mt:ast::Mutability::Mut, nested: true})
|
( Static { mutability: ast::Mutability::Mut, nested: true } )
|
||||||
( Ctor(CtorOf::Struct, CtorKind::Fn) )
|
( Ctor(CtorOf::Struct, CtorKind::Fn) )
|
||||||
( Ctor(CtorOf::Struct, CtorKind::Const) )
|
( Ctor(CtorOf::Struct, CtorKind::Const) )
|
||||||
( Ctor(CtorOf::Variant, CtorKind::Fn) )
|
( Ctor(CtorOf::Variant, CtorKind::Fn) )
|
||||||
|
|
|
@ -343,7 +343,7 @@ impl<'hir> Map<'hir> {
|
||||||
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
|
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
|
||||||
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
|
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
|
||||||
DefKind::Closure => BodyOwnerKind::Closure,
|
DefKind::Closure => BodyOwnerKind::Closure,
|
||||||
DefKind::Static { mt, nested: false } => BodyOwnerKind::Static(mt),
|
DefKind::Static { mutability, nested: false } => BodyOwnerKind::Static(mutability),
|
||||||
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
|
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,7 @@ impl<'hir> Map<'hir> {
|
||||||
let def_id = def_id.into();
|
let def_id = def_id.into();
|
||||||
let ccx = match self.body_owner_kind(def_id) {
|
let ccx = match self.body_owner_kind(def_id) {
|
||||||
BodyOwnerKind::Const { inline } => ConstContext::Const { inline },
|
BodyOwnerKind::Const { inline } => ConstContext::Const { inline },
|
||||||
BodyOwnerKind::Static(mt) => ConstContext::Static(mt),
|
BodyOwnerKind::Static(mutability) => ConstContext::Static(mutability),
|
||||||
|
|
||||||
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id) => return None,
|
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id) => return None,
|
||||||
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn_raw(def_id) => {
|
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn_raw(def_id) => {
|
||||||
|
|
|
@ -498,8 +498,10 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
|
||||||
match (kind, body.source.promoted) {
|
match (kind, body.source.promoted) {
|
||||||
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
|
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
|
||||||
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
|
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
|
||||||
(DefKind::Static { mt: hir::Mutability::Not, nested: false }, _) => write!(w, "static ")?,
|
(DefKind::Static { mutability: hir::Mutability::Not, nested: false }, _) => {
|
||||||
(DefKind::Static { mt: hir::Mutability::Mut, nested: false }, _) => {
|
write!(w, "static ")?
|
||||||
|
}
|
||||||
|
(DefKind::Static { mutability: hir::Mutability::Mut, nested: false }, _) => {
|
||||||
write!(w, "static mut ")?
|
write!(w, "static mut ")?
|
||||||
}
|
}
|
||||||
(_, _) if is_function => write!(w, "fn ")?,
|
(_, _) if is_function => write!(w, "fn ")?,
|
||||||
|
|
|
@ -621,7 +621,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn static_mutability(self, def_id: DefId) -> Option<hir::Mutability> {
|
pub fn static_mutability(self, def_id: DefId) -> Option<hir::Mutability> {
|
||||||
if let DefKind::Static { mt, .. } = self.def_kind(def_id) { Some(mt) } else { None }
|
if let DefKind::Static { mutability, .. } = self.def_kind(def_id) {
|
||||||
|
Some(mutability)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this is a `static` item with the `#[thread_local]` attribute.
|
/// Returns `true` if this is a `static` item with the `#[thread_local]` attribute.
|
||||||
|
|
|
@ -127,7 +127,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
ItemKind::Union(..) => DefKind::Union,
|
ItemKind::Union(..) => DefKind::Union,
|
||||||
ItemKind::ExternCrate(..) => DefKind::ExternCrate,
|
ItemKind::ExternCrate(..) => DefKind::ExternCrate,
|
||||||
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
||||||
ItemKind::Static(s) => DefKind::Static { mt: s.mutability, nested: false },
|
ItemKind::Static(s) => DefKind::Static { mutability: s.mutability, nested: false },
|
||||||
ItemKind::Const(..) => DefKind::Const,
|
ItemKind::Const(..) => DefKind::Const,
|
||||||
ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
|
ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
|
||||||
ItemKind::MacroDef(..) => {
|
ItemKind::MacroDef(..) => {
|
||||||
|
@ -214,7 +214,9 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||||
let def_kind = match fi.kind {
|
let def_kind = match fi.kind {
|
||||||
ForeignItemKind::Static(_, mt, _) => DefKind::Static { mt, nested: false },
|
ForeignItemKind::Static(_, mutability, _) => {
|
||||||
|
DefKind::Static { mutability, nested: false }
|
||||||
|
}
|
||||||
ForeignItemKind::Fn(_) => DefKind::Fn,
|
ForeignItemKind::Fn(_) => DefKind::Fn,
|
||||||
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
|
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
|
||||||
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
||||||
|
|
|
@ -1514,7 +1514,7 @@ impl Disambiguator {
|
||||||
"union" => Kind(DefKind::Union),
|
"union" => Kind(DefKind::Union),
|
||||||
"module" | "mod" => Kind(DefKind::Mod),
|
"module" | "mod" => Kind(DefKind::Mod),
|
||||||
"const" | "constant" => Kind(DefKind::Const),
|
"const" | "constant" => Kind(DefKind::Const),
|
||||||
"static" => Kind(DefKind::Static { mt: Mutability::Not, nested: false }),
|
"static" => Kind(DefKind::Static { mutability: Mutability::Not, nested: false }),
|
||||||
"function" | "fn" | "method" => Kind(DefKind::Fn),
|
"function" | "fn" | "method" => Kind(DefKind::Fn),
|
||||||
"derive" => Kind(DefKind::Macro(MacroKind::Derive)),
|
"derive" => Kind(DefKind::Macro(MacroKind::Derive)),
|
||||||
"type" => NS(Namespace::TypeNS),
|
"type" => NS(Namespace::TypeNS),
|
||||||
|
|
|
@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||||
ExprKind::Path(QPath::Resolved(
|
ExprKind::Path(QPath::Resolved(
|
||||||
_,
|
_,
|
||||||
hir::Path {
|
hir::Path {
|
||||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _),
|
res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _),
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
)) => {
|
)) => {
|
||||||
|
@ -149,7 +149,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||||
ExprKind::Path(QPath::Resolved(
|
ExprKind::Path(QPath::Resolved(
|
||||||
_,
|
_,
|
||||||
hir::Path {
|
hir::Path {
|
||||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _),
|
res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _),
|
||||||
..
|
..
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue