mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Add nested
bool to DefKind::Static
.
Will be used in the next commit
This commit is contained in:
parent
9816915954
commit
0b4cbee660
@ -459,7 +459,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
assert!(self.ecx.tcx.is_static(did));
|
||||
let is_mut = matches!(
|
||||
self.ecx.tcx.def_kind(did),
|
||||
DefKind::Static { mt: Mutability::Mut }
|
||||
DefKind::Static { mt: Mutability::Mut, .. }
|
||||
) || !self
|
||||
.ecx
|
||||
.tcx
|
||||
|
@ -78,6 +78,8 @@ pub enum DefKind {
|
||||
Static {
|
||||
/// Whether it's a `static mut` or just a `static`.
|
||||
mt: ast::Mutability,
|
||||
/// Whether it's an anonymous static generated for nested allocations.
|
||||
nested: bool,
|
||||
},
|
||||
/// Refers to the struct or enum variant's constructor.
|
||||
///
|
||||
|
@ -48,7 +48,7 @@ fn is_path_static_mut(expr: hir::Expr<'_>) -> Option<String> {
|
||||
if let hir::ExprKind::Path(qpath) = expr.kind
|
||||
&& let hir::QPath::Resolved(_, path) = qpath
|
||||
&& let hir::def::Res::Def(def_kind, _) = path.res
|
||||
&& let hir::def::DefKind::Static { mt } = def_kind
|
||||
&& let hir::def::DefKind::Static { mt, nested: false } = def_kind
|
||||
&& matches!(mt, Mutability::Mut)
|
||||
{
|
||||
return Some(qpath_to_string(&qpath));
|
||||
|
@ -155,8 +155,10 @@ fixed_size_enum! {
|
||||
( Impl { of_trait: false } )
|
||||
( Impl { of_trait: true } )
|
||||
( Closure )
|
||||
( Static{mt:ast::Mutability::Not} )
|
||||
( Static{mt:ast::Mutability::Mut} )
|
||||
( Static{mt:ast::Mutability::Not, nested: false})
|
||||
( Static{mt:ast::Mutability::Mut, nested: false})
|
||||
( Static{mt:ast::Mutability::Not, nested: true})
|
||||
( Static{mt:ast::Mutability::Mut, nested: true})
|
||||
( Ctor(CtorOf::Struct, CtorKind::Fn) )
|
||||
( Ctor(CtorOf::Struct, CtorKind::Const) )
|
||||
( Ctor(CtorOf::Variant, CtorKind::Fn) )
|
||||
|
@ -343,7 +343,7 @@ impl<'hir> Map<'hir> {
|
||||
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
|
||||
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
|
||||
DefKind::Closure => BodyOwnerKind::Closure,
|
||||
DefKind::Static { mt } => BodyOwnerKind::Static(mt),
|
||||
DefKind::Static { mt, nested: false } => BodyOwnerKind::Static(mt),
|
||||
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
|
||||
}
|
||||
}
|
||||
|
@ -498,8 +498,10 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
|
||||
match (kind, body.source.promoted) {
|
||||
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
|
||||
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
|
||||
(DefKind::Static { mt: hir::Mutability::Not }, _) => write!(w, "static ")?,
|
||||
(DefKind::Static { mt: hir::Mutability::Mut }, _) => write!(w, "static mut ")?,
|
||||
(DefKind::Static { mt: hir::Mutability::Not, nested: false }, _) => write!(w, "static ")?,
|
||||
(DefKind::Static { mt: hir::Mutability::Mut, nested: false }, _) => {
|
||||
write!(w, "static mut ")?
|
||||
}
|
||||
(_, _) if is_function => write!(w, "fn ")?,
|
||||
(DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item
|
||||
_ => bug!("Unexpected def kind {:?}", kind),
|
||||
|
@ -621,7 +621,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
#[inline]
|
||||
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 { mt, .. } = self.def_kind(def_id) { Some(mt) } else { None }
|
||||
}
|
||||
|
||||
/// 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::ExternCrate(..) => DefKind::ExternCrate,
|
||||
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
||||
ItemKind::Static(s) => DefKind::Static { mt: s.mutability },
|
||||
ItemKind::Static(s) => DefKind::Static { mt: s.mutability, nested: false },
|
||||
ItemKind::Const(..) => DefKind::Const,
|
||||
ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
|
||||
ItemKind::MacroDef(..) => {
|
||||
@ -214,7 +214,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||
|
||||
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||
let def_kind = match fi.kind {
|
||||
ForeignItemKind::Static(_, mt, _) => DefKind::Static { mt },
|
||||
ForeignItemKind::Static(_, mt, _) => DefKind::Static { mt, nested: false },
|
||||
ForeignItemKind::Fn(_) => DefKind::Fn,
|
||||
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
|
||||
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
||||
|
@ -1514,7 +1514,7 @@ impl Disambiguator {
|
||||
"union" => Kind(DefKind::Union),
|
||||
"module" | "mod" => Kind(DefKind::Mod),
|
||||
"const" | "constant" => Kind(DefKind::Const),
|
||||
"static" => Kind(DefKind::Static { mt: Mutability::Not }),
|
||||
"static" => Kind(DefKind::Static { mt: Mutability::Not, nested: false }),
|
||||
"function" | "fn" | "method" => Kind(DefKind::Fn),
|
||||
"derive" => Kind(DefKind::Macro(MacroKind::Derive)),
|
||||
"type" => NS(Namespace::TypeNS),
|
||||
|
@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||
ExprKind::Path(QPath::Resolved(
|
||||
_,
|
||||
hir::Path {
|
||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _),
|
||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _),
|
||||
..
|
||||
},
|
||||
)) => {
|
||||
@ -149,7 +149,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||
ExprKind::Path(QPath::Resolved(
|
||||
_,
|
||||
hir::Path {
|
||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _),
|
||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _),
|
||||
..
|
||||
}
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user