1
Fork 0

Change DefKind::Static to a struct variant

This commit is contained in:
Oli Scherer 2024-02-23 23:12:20 +00:00
parent 12e2846514
commit 9816915954
47 changed files with 90 additions and 86 deletions

View file

@ -196,7 +196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.get_partial_res(sym.id) .get_partial_res(sym.id)
.and_then(|res| res.full_res()) .and_then(|res| res.full_res())
.and_then(|res| match res { .and_then(|res| match res {
Res::Def(DefKind::Static(_), def_id) => Some(def_id), Res::Def(DefKind::Static { .. }, def_id) => Some(def_id),
_ => None, _ => None,
}); });

View file

@ -87,7 +87,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
// Only consider nodes that actually have exported symbols. // Only consider nodes that actually have exported symbols.
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Fn | DefKind::Static(_) => {} DefKind::Fn | DefKind::Static { .. } => {}
DefKind::AssocFn if tcx.impl_of_method(def_id.to_def_id()).is_some() => {} DefKind::AssocFn if tcx.impl_of_method(def_id.to_def_id()).is_some() => {}
_ => return None, _ => return None,
}; };
@ -483,7 +483,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
let target = &tcx.sess.target.llvm_target; let target = &tcx.sess.target.llvm_target;
// WebAssembly cannot export data symbols, so reduce their export level // WebAssembly cannot export data symbols, so reduce their export level
if target.contains("emscripten") { if target.contains("emscripten") {
if let DefKind::Static(_) = tcx.def_kind(sym_def_id) { if let DefKind::Static { .. } = tcx.def_kind(sym_def_id) {
return SymbolExportLevel::Rust; return SymbolExportLevel::Rust;
} }
} }

View file

@ -37,7 +37,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
|| matches!( || matches!(
ecx.tcx.def_kind(cid.instance.def_id()), ecx.tcx.def_kind(cid.instance.def_id()),
DefKind::Const DefKind::Const
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::AnonConst | DefKind::AnonConst
| DefKind::InlineConst | DefKind::InlineConst

View file

@ -457,15 +457,16 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// Special handling for pointers to statics (irrespective of their type). // Special handling for pointers to statics (irrespective of their type).
assert!(!self.ecx.tcx.is_thread_local_static(did)); assert!(!self.ecx.tcx.is_thread_local_static(did));
assert!(self.ecx.tcx.is_static(did)); assert!(self.ecx.tcx.is_static(did));
let is_mut = let is_mut = matches!(
matches!(self.ecx.tcx.def_kind(did), DefKind::Static(Mutability::Mut)) self.ecx.tcx.def_kind(did),
|| !self DefKind::Static { mt: Mutability::Mut }
.ecx ) || !self
.tcx .ecx
.type_of(did) .tcx
.no_bound_vars() .type_of(did)
.expect("statics should not have generic parameters") .no_bound_vars()
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()); .expect("statics should not have generic parameters")
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all());
// Mode-specific checks // Mode-specific checks
match self.ctfe_mode { match self.ctfe_mode {
Some( Some(

View file

@ -75,7 +75,10 @@ pub enum DefKind {
Const, Const,
/// Constant generic parameter: `struct Foo<const N: usize> { ... }` /// Constant generic parameter: `struct Foo<const N: usize> { ... }`
ConstParam, ConstParam,
Static(ast::Mutability), Static {
/// Whether it's a `static mut` or just a `static`.
mt: ast::Mutability,
},
/// Refers to the struct or enum variant's constructor. /// Refers to the struct or enum variant's constructor.
/// ///
/// The reason `Ctor` exists in addition to [`DefKind::Struct`] and /// The reason `Ctor` exists in addition to [`DefKind::Struct`] and
@ -136,7 +139,7 @@ impl DefKind {
DefKind::Fn => "function", DefKind::Fn => "function",
DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate", DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
DefKind::Mod => "module", DefKind::Mod => "module",
DefKind::Static(..) => "static", DefKind::Static { .. } => "static",
DefKind::Enum => "enum", DefKind::Enum => "enum",
DefKind::Variant => "variant", DefKind::Variant => "variant",
DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant", DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
@ -209,7 +212,7 @@ impl DefKind {
DefKind::Fn DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst => Some(Namespace::ValueNS), | DefKind::AssocConst => Some(Namespace::ValueNS),
@ -248,7 +251,7 @@ impl DefKind {
DefKind::Fn DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Field => DefPathData::ValueNs(name), | DefKind::Field => DefPathData::ValueNs(name),
@ -278,7 +281,7 @@ impl DefKind {
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::Closure | DefKind::Closure
| DefKind::Static(_) => true, | DefKind::Static { .. } => true,
DefKind::Mod DefKind::Mod
| DefKind::Struct | DefKind::Struct
| DefKind::Union | DefKind::Union

View file

@ -1616,7 +1616,7 @@ impl Expr<'_> {
pub fn is_place_expr(&self, mut allow_projections_from: impl FnMut(&Self) -> bool) -> bool { pub fn is_place_expr(&self, mut allow_projections_from: impl FnMut(&Self) -> bool) -> bool {
match self.kind { match self.kind {
ExprKind::Path(QPath::Resolved(_, ref path)) => { ExprKind::Path(QPath::Resolved(_, ref path)) => {
matches!(path.res, Res::Local(..) | Res::Def(DefKind::Static(_), _) | Res::Err) matches!(path.res, Res::Local(..) | Res::Def(DefKind::Static { .. }, _) | Res::Err)
} }
// Type ascription inherits its place expression kind from its // Type ascription inherits its place expression kind from its

View file

@ -107,7 +107,7 @@ impl Target {
match item.kind { match item.kind {
ItemKind::ExternCrate(..) => Target::ExternCrate, ItemKind::ExternCrate(..) => Target::ExternCrate,
ItemKind::Use(..) => Target::Use, ItemKind::Use(..) => Target::Use,
ItemKind::Static(..) => Target::Static, ItemKind::Static { .. } => Target::Static,
ItemKind::Const(..) => Target::Const, ItemKind::Const(..) => Target::Const,
ItemKind::Fn(..) => Target::Fn, ItemKind::Fn(..) => Target::Fn,
ItemKind::Macro(..) => Target::MacroDef, ItemKind::Macro(..) => Target::MacroDef,
@ -130,7 +130,7 @@ impl Target {
match def_kind { match def_kind {
DefKind::ExternCrate => Target::ExternCrate, DefKind::ExternCrate => Target::ExternCrate,
DefKind::Use => Target::Use, DefKind::Use => Target::Use,
DefKind::Static(..) => Target::Static, DefKind::Static { .. } => Target::Static,
DefKind::Const => Target::Const, DefKind::Const => Target::Const,
DefKind::Fn => Target::Fn, DefKind::Fn => Target::Fn,
DefKind::Macro(..) => Target::MacroDef, DefKind::Macro(..) => Target::MacroDef,

View file

@ -1934,7 +1934,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
// Case 3. Reference to a top-level value. // Case 3. Reference to a top-level value.
DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static(_) => { DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
path_segs.push(PathSeg(def_id, last)); path_segs.push(PathSeg(def_id, last));
} }

View file

@ -226,7 +226,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
Ok(l) => l, Ok(l) => l,
// Foreign statics that overflow their allowed size should emit an error // Foreign statics that overflow their allowed size should emit an error
Err(LayoutError::SizeOverflow(_)) Err(LayoutError::SizeOverflow(_))
if matches!(tcx.def_kind(def_id), DefKind::Static(_) if matches!(tcx.def_kind(def_id), DefKind::Static{..}
if tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod) => if tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod) =>
{ {
tcx.dcx().emit_err(errors::TooLargeStatic { span }); tcx.dcx().emit_err(errors::TooLargeStatic { span });
@ -505,7 +505,7 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) { pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let _indenter = indenter(); let _indenter = indenter();
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Static(..) => { DefKind::Static { .. } => {
tcx.ensure().typeck(def_id); tcx.ensure().typeck(def_id);
maybe_check_static_with_link_section(tcx, def_id); maybe_check_static_with_link_section(tcx, def_id);
check_static_inhabited(tcx, def_id); check_static_inhabited(tcx, def_id);

View file

@ -48,7 +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) = def_kind && let hir::def::DefKind::Static { mt } = def_kind
&& matches!(mt, Mutability::Mut) && matches!(mt, Mutability::Mut)
{ {
return Some(qpath_to_string(&qpath)); return Some(qpath_to_string(&qpath));

View file

@ -182,7 +182,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
tcx.hir().par_body_owners(|item_def_id| { tcx.hir().par_body_owners(|item_def_id| {
let def_kind = tcx.def_kind(item_def_id); let def_kind = tcx.def_kind(item_def_id);
match def_kind { match def_kind {
DefKind::Static(_) => tcx.ensure().eval_static_initializer(item_def_id), DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()), DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()),
_ => (), _ => (),
} }

View file

@ -699,7 +699,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::Path { hir::Path {
res: res:
hir::def::Res::Def( hir::def::Res::Def(
hir::def::DefKind::Static(_) | hir::def::DefKind::Const, hir::def::DefKind::Static { .. } | hir::def::DefKind::Const,
def_id, def_id,
), ),
.. ..

View file

@ -398,7 +398,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
) )
| Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, expr_ty)), | Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, expr_ty)),
Res::Def(DefKind::Static(_), _) => { Res::Def(DefKind::Static { .. }, _) => {
Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::StaticItem, Vec::new())) Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::StaticItem, Vec::new()))
} }

View file

@ -372,7 +372,7 @@ impl<T> Trait<T> for X {
&& matches!( && matches!(
tcx.def_kind(body_owner_def_id), tcx.def_kind(body_owner_def_id),
DefKind::Fn DefKind::Fn
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Const | DefKind::Const
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst

View file

@ -863,7 +863,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
@ -894,7 +894,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
| DefKind::AssocTy | DefKind::AssocTy
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Macro(_) | DefKind::Macro(_)
@ -936,7 +936,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
@ -968,7 +968,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
| DefKind::AssocTy | DefKind::AssocTy
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
@ -1001,7 +1001,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::TyParam | DefKind::TyParam
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::Const | DefKind::Const
| DefKind::Fn | DefKind::Fn
| DefKind::ForeignMod | DefKind::ForeignMod
@ -1099,7 +1099,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::TyParam | DefKind::TyParam
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::Const | DefKind::Const
| DefKind::ForeignMod | DefKind::ForeignMod
| DefKind::Impl { .. } | DefKind::Impl { .. }
@ -1131,7 +1131,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
| DefKind::AssocTy | DefKind::AssocTy
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
@ -1163,7 +1163,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
| DefKind::Field | DefKind::Field
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::TyAlias | DefKind::TyAlias
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::Impl { .. } | DefKind::Impl { .. }
@ -1222,7 +1222,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
| DefKind::Variant | DefKind::Variant
| DefKind::Field | DefKind::Field
| DefKind::Const | DefKind::Const
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::TyAlias | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
@ -1263,7 +1263,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
| DefKind::Const | DefKind::Const
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::AnonConst | DefKind::AnonConst
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::TyAlias | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::Impl { of_trait: false } | DefKind::Impl { of_trait: false }
@ -1295,7 +1295,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::Field | DefKind::Field
| DefKind::Fn | DefKind::Fn
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::TyAlias | DefKind::TyAlias
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::ForeignTy | DefKind::ForeignTy
@ -1469,7 +1469,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
.coroutine_for_closure .coroutine_for_closure
.set_some(def_id.index, self.tcx.coroutine_for_closure(def_id).into()); .set_some(def_id.index, self.tcx.coroutine_for_closure(def_id).into());
} }
if let DefKind::Static(_) = def_kind { if let DefKind::Static { .. } = def_kind {
if !self.tcx.is_foreign_item(def_id) { if !self.tcx.is_foreign_item(def_id) {
let data = self.tcx.eval_static_initializer(def_id).unwrap(); let data = self.tcx.eval_static_initializer(def_id).unwrap();
record!(self.tables.eval_static_initializer[def_id] <- data); record!(self.tables.eval_static_initializer[def_id] <- data);

View file

@ -155,8 +155,8 @@ fixed_size_enum! {
( Impl { of_trait: false } ) ( Impl { of_trait: false } )
( Impl { of_trait: true } ) ( Impl { of_trait: true } )
( Closure ) ( Closure )
( Static(ast::Mutability::Not) ) ( Static{mt:ast::Mutability::Not} )
( Static(ast::Mutability::Mut) ) ( Static{mt:ast::Mutability::Mut} )
( 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) )

View file

@ -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) => BodyOwnerKind::Static(mt), DefKind::Static { mt } => BodyOwnerKind::Static(mt),
dk => bug!("{:?} is not a body node: {:?}", def_id, dk), dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
} }
} }

View file

@ -498,8 +498,8 @@ 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(hir::Mutability::Not), _) => write!(w, "static ")?, (DefKind::Static { mt: hir::Mutability::Not }, _) => write!(w, "static ")?,
(DefKind::Static(hir::Mutability::Mut), _) => write!(w, "static mut ")?, (DefKind::Static { mt: hir::Mutability::Mut }, _) => write!(w, "static mut ")?,
(_, _) if is_function => write!(w, "fn ")?, (_, _) if is_function => write!(w, "fn ")?,
(DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item (DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item
_ => bug!("Unexpected def kind {:?}", kind), _ => bug!("Unexpected def kind {:?}", kind),

View file

@ -1708,7 +1708,7 @@ impl<'tcx> TyCtxt<'tcx> {
debug!("returned from def_kind: {:?}", def_kind); debug!("returned from def_kind: {:?}", def_kind);
match def_kind { match def_kind {
DefKind::Const DefKind::Const
| DefKind::Static(..) | DefKind::Static { .. }
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::AnonConst | DefKind::AnonConst

View file

@ -359,7 +359,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
| DefKind::TyAlias | DefKind::TyAlias
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::Static(_) = kind | DefKind::Static { .. } = kind
{ {
} else { } else {
// If not covered above, like for example items out of `impl` blocks, fallback. // If not covered above, like for example items out of `impl` blocks, fallback.

View file

@ -616,12 +616,12 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns `true` if the node pointed to by `def_id` is a `static` item. /// Returns `true` if the node pointed to by `def_id` is a `static` item.
#[inline] #[inline]
pub fn is_static(self, def_id: DefId) -> bool { pub fn is_static(self, def_id: DefId) -> bool {
matches!(self.def_kind(def_id), DefKind::Static(_)) matches!(self.def_kind(def_id), DefKind::Static { .. })
} }
#[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 { mt } = self.def_kind(def_id) { Some(mt) } 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.

View file

@ -631,7 +631,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::AnonConst | DefKind::AnonConst
| DefKind::InlineConst | DefKind::InlineConst
| DefKind::Static(_) => (vec![], tcx.type_of(def_id).instantiate_identity(), None), | DefKind::Static { .. } => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => { DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => {
let sig = tcx.liberate_late_bound_regions( let sig = tcx.liberate_late_bound_regions(
def_id.to_def_id(), def_id.to_def_id(),

View file

@ -942,7 +942,7 @@ impl<'tcx> Cx<'tcx> {
// We encode uses of statics as a `*&STATIC` where the `&STATIC` part is // We encode uses of statics as a `*&STATIC` where the `&STATIC` part is
// a constant reference (or constant raw pointer for `static mut`) in MIR // a constant reference (or constant raw pointer for `static mut`) in MIR
Res::Def(DefKind::Static(_), id) => { Res::Def(DefKind::Static { .. }, id) => {
let ty = self.tcx.static_ptr_ty(id); let ty = self.tcx.static_ptr_ty(id);
let temp_lifetime = self let temp_lifetime = self
.rvalue_scopes .rvalue_scopes

View file

@ -453,7 +453,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
Res::Def(DefKind::ConstParam, _) => { Res::Def(DefKind::ConstParam, _) => {
self.tcx.dcx().emit_err(ConstParamInPattern { span }) self.tcx.dcx().emit_err(ConstParamInPattern { span })
} }
Res::Def(DefKind::Static(_), _) => { Res::Def(DefKind::Static { .. }, _) => {
self.tcx.dcx().emit_err(StaticInPattern { span }) self.tcx.dcx().emit_err(StaticInPattern { span })
} }
_ => self.tcx.dcx().emit_err(NonConstPath { span }), _ => self.tcx.dcx().emit_err(NonConstPath { span }),

View file

@ -333,7 +333,7 @@ fn mir_promoted(
} }
DefKind::AssocConst DefKind::AssocConst
| DefKind::Const | DefKind::Const
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::InlineConst | DefKind::InlineConst
| DefKind::AnonConst => tcx.mir_const_qualif(def), | DefKind::AnonConst => tcx.mir_const_qualif(def),
_ => ConstQualifs::default(), _ => ConstQualifs::default(),

View file

@ -1037,7 +1037,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
return false; return false;
} }
if let DefKind::Static(_) = tcx.def_kind(def_id) { if let DefKind::Static { .. } = tcx.def_kind(def_id) {
// We cannot monomorphize statics from upstream crates. // We cannot monomorphize statics from upstream crates.
return false; return false;
} }
@ -1254,7 +1254,7 @@ impl<'v> RootCollector<'_, 'v> {
); );
self.output.push(dummy_spanned(MonoItem::GlobalAsm(id))); self.output.push(dummy_spanned(MonoItem::GlobalAsm(id)));
} }
DefKind::Static(..) => { DefKind::Static { .. } => {
let def_id = id.owner_id.to_def_id(); let def_id = id.owner_id.to_def_id();
debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id)); debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id));
self.output.push(dummy_spanned(MonoItem::Static(def_id))); self.output.push(dummy_spanned(MonoItem::Static(def_id)));

View file

@ -150,7 +150,7 @@ fn mark_used_by_default_parameters<'tcx>(
| DefKind::Fn | DefKind::Fn
| DefKind::Const | DefKind::Const
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Ctor(_, _) | DefKind::Ctor(_, _)
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst

View file

@ -801,7 +801,7 @@ fn check_foreign_item(
worklist: &mut Vec<(LocalDefId, ComesFromAllowExpect)>, worklist: &mut Vec<(LocalDefId, ComesFromAllowExpect)>,
id: hir::ForeignItemId, id: hir::ForeignItemId,
) { ) {
if matches!(tcx.def_kind(id.owner_id), DefKind::Static(_) | DefKind::Fn) if matches!(tcx.def_kind(id.owner_id), DefKind::Static { .. } | DefKind::Fn)
&& let Some(comes_from_allow) = has_allow_dead_code_or_lang_attr(tcx, id.owner_id.def_id) && let Some(comes_from_allow) = has_allow_dead_code_or_lang_attr(tcx, id.owner_id.def_id)
{ {
worklist.push((id.owner_id.def_id, comes_from_allow)); worklist.push((id.owner_id.def_id, comes_from_allow));
@ -1058,7 +1058,7 @@ impl<'tcx> DeadVisitor<'tcx> {
DefKind::AssocConst DefKind::AssocConst
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::Fn | DefKind::Fn
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Const | DefKind::Const
| DefKind::TyAlias | DefKind::TyAlias
| DefKind::Enum | DefKind::Enum

View file

@ -73,7 +73,7 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
match res { match res {
// Reachable constants and reachable statics can have their contents inlined // Reachable constants and reachable statics can have their contents inlined
// into other crates. Mark them as reachable and recurse into their body. // into other crates. Mark them as reachable and recurse into their body.
Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::Static(_), _) => { Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::Static { .. }, _) => {
self.worklist.push(def_id); self.worklist.push(def_id);
} }
_ => { _ => {

View file

@ -549,7 +549,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
self.update(def_id, macro_ev, Level::Reachable); self.update(def_id, macro_ev, Level::Reachable);
match def_kind { match def_kind {
// No type privacy, so can be directly marked as reachable. // No type privacy, so can be directly marked as reachable.
DefKind::Const | DefKind::Static(_) | DefKind::TraitAlias | DefKind::TyAlias => { DefKind::Const | DefKind::Static { .. } | DefKind::TraitAlias | DefKind::TyAlias => {
if vis.is_accessible_from(module, self.tcx) { if vis.is_accessible_from(module, self.tcx) {
self.update(def_id, macro_ev, Level::Reachable); self.update(def_id, macro_ev, Level::Reachable);
} }
@ -1170,12 +1170,12 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
let def = def.filter(|(kind, _)| { let def = def.filter(|(kind, _)| {
matches!( matches!(
kind, kind,
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static(_) DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static { .. }
) )
}); });
if let Some((kind, def_id)) = def { if let Some((kind, def_id)) = def {
let is_local_static = let is_local_static =
if let DefKind::Static(_) = kind { def_id.is_local() } else { false }; if let DefKind::Static { .. } = kind { def_id.is_local() } else { false };
if !self.item_is_accessible(def_id) && !is_local_static { if !self.item_is_accessible(def_id) && !is_local_static {
let name = match *qpath { let name = match *qpath {
hir::QPath::LangItem(it, ..) => { hir::QPath::LangItem(it, ..) => {
@ -1496,7 +1496,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
let def_kind = tcx.def_kind(def_id); let def_kind = tcx.def_kind(def_id);
match def_kind { match def_kind {
DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias => { DefKind::Const | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias => {
if let DefKind::TyAlias = def_kind { if let DefKind::TyAlias = def_kind {
self.check_unnameable(def_id, effective_vis); self.check_unnameable(def_id, effective_vis);
} }

View file

@ -990,7 +990,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
Res::Def( Res::Def(
DefKind::Fn DefKind::Fn
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Const | DefKind::Const
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Ctor(..), | DefKind::Ctor(..),

View file

@ -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(s.mutability), ItemKind::Static(s) => DefKind::Static { mt: s.mutability },
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,7 @@ 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), ForeignItemKind::Static(_, mt, _) => DefKind::Static { mt },
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),

View file

@ -574,7 +574,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params, def_kind) => { ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params, def_kind) => {
use errs::GenericParamsFromOuterItemLabel as Label; use errs::GenericParamsFromOuterItemLabel as Label;
let static_or_const = match def_kind { let static_or_const = match def_kind {
DefKind::Static(_) => Some(errs::GenericParamsFromOuterItemStaticOrConst::Static), DefKind::Static{..} => Some(errs::GenericParamsFromOuterItemStaticOrConst::Static),
DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const), DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const),
_ => None, _ => None,
}; };

View file

@ -500,7 +500,7 @@ impl<'a> PathSource<'a> {
Res::Def( Res::Def(
DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn) DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
| DefKind::Const | DefKind::Const
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Fn | DefKind::Fn
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
@ -3645,7 +3645,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
} }
Some(res) Some(res)
} }
Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::Static(_), _) => { Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::Static{..}, _) => {
// This is unambiguously a fresh binding, either syntactically // This is unambiguously a fresh binding, either syntactically
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves // (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
// to something unusable as a pattern (e.g., constructor function), // to something unusable as a pattern (e.g., constructor function),

View file

@ -264,7 +264,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)), DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)),
DefKind::Static(..) => ForeignItemKind::Static(tables.static_def(def_id)), DefKind::Static { .. } => ForeignItemKind::Static(tables.static_def(def_id)),
DefKind::ForeignTy => ForeignItemKind::Type( DefKind::ForeignTy => ForeignItemKind::Type(
tables.intern_ty(rustc_middle::ty::Ty::new_foreign(tcx, def_id)), tables.intern_ty(rustc_middle::ty::Ty::new_foreign(tcx, def_id)),
), ),

View file

@ -95,7 +95,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => { DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
ItemKind::Const ItemKind::Const
} }
DefKind::Static(_) => ItemKind::Static, DefKind::Static { .. } => ItemKind::Static,
DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const), DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn), DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),
} }

View file

@ -134,7 +134,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
| DefKind::TyParam | DefKind::TyParam
| DefKind::Const | DefKind::Const
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Ctor(_, _) | DefKind::Ctor(_, _)
| DefKind::Macro(_) | DefKind::Macro(_)
| DefKind::ExternCrate | DefKind::ExternCrate

View file

@ -318,7 +318,7 @@ fn opaque_types_defined_by<'tcx>(
match kind { match kind {
DefKind::AssocFn DefKind::AssocFn
| DefKind::Fn | DefKind::Fn
| DefKind::Static(_) | DefKind::Static { .. }
| DefKind::Const | DefKind::Const
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::AnonConst => { | DefKind::AnonConst => {

View file

@ -43,7 +43,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
// Walk over the type behind the alias // Walk over the type behind the alias
DefKind::TyAlias {..} | DefKind::AssocTy | DefKind::TyAlias {..} | DefKind::AssocTy |
// Walk over the type of the item // Walk over the type of the item
DefKind::Static(_) | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => { DefKind::Static{..} | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
if let Some(ty) = tcx.hir_node_by_def_id(item).ty() { if let Some(ty) = tcx.hir_node_by_def_id(item).ty() {
// If the type of the item uses `_`, we're gonna error out anyway, but // If the type of the item uses `_`, we're gonna error out anyway, but
// typeck (which type_of invokes below), will call back into opaque_types_defined_by // typeck (which type_of invokes below), will call back into opaque_types_defined_by

View file

@ -120,7 +120,7 @@ pub(crate) fn try_inline(
record_extern_fqn(cx, did, ItemType::Module); record_extern_fqn(cx, did, ItemType::Module);
clean::ModuleItem(build_module(cx, did, visited)) clean::ModuleItem(build_module(cx, did, visited))
} }
Res::Def(DefKind::Static(_), did) => { Res::Def(DefKind::Static { .. }, did) => {
record_extern_fqn(cx, did, ItemType::Static); record_extern_fqn(cx, did, ItemType::Static);
cx.with_param_env(did, |cx| { cx.with_param_env(did, |cx| {
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did))) clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))

View file

@ -526,7 +526,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
| Mod | Mod
| ForeignTy | ForeignTy
| Const | Const
| Static(_) | Static { .. }
| Macro(..) | Macro(..)
| TraitAlias), | TraitAlias),
did, did,

View file

@ -128,7 +128,7 @@ impl ItemType {
DefKind::Fn => Self::Function, DefKind::Fn => Self::Function,
DefKind::Mod => Self::Module, DefKind::Mod => Self::Module,
DefKind::Const => Self::Constant, DefKind::Const => Self::Constant,
DefKind::Static(_) => Self::Static, DefKind::Static { .. } => Self::Static,
DefKind::Struct => Self::Struct, DefKind::Struct => Self::Struct,
DefKind::Union => Self::Union, DefKind::Union => Self::Union,
DefKind::Trait => Self::Trait, DefKind::Trait => Self::Trait,

View file

@ -123,7 +123,7 @@ impl Res {
DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst => { DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst => {
"const" "const"
} }
DefKind::Static(_) => "static", DefKind::Static { .. } => "static",
// Now handle things that don't have a specific disambiguator // Now handle things that don't have a specific disambiguator
_ => match kind _ => match kind
.ns() .ns()
@ -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(Mutability::Not)), "static" => Kind(DefKind::Static { mt: Mutability::Not }),
"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),
@ -1926,7 +1926,7 @@ fn resolution_failure(
| OpaqueTy | OpaqueTy
| TraitAlias | TraitAlias
| TyParam | TyParam
| Static(_) => "associated item", | Static { .. } => "associated item",
Impl { .. } | GlobalAsm => unreachable!("not a path"), Impl { .. } | GlobalAsm => unreachable!("not a path"),
} }
} else { } else {

View file

@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
} }
return false; // no need to walk further *on the variable* return false; // no need to walk further *on the variable*
}, },
Res::Def(DefKind::Static(_) | DefKind::Const, ..) => { Res::Def(DefKind::Static{..} | DefKind::Const, ..) => {
if index_used_directly { if index_used_directly {
self.indexed_directly.insert( self.indexed_directly.insert(
seqvar.segments[0].ident.name, seqvar.segments[0].ident.name,

View file

@ -101,7 +101,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
Res::Local(hir_id) => { Res::Local(hir_id) => {
self.ids.insert(hir_id); self.ids.insert(hir_id);
}, },
Res::Def(DefKind::Static(_), def_id) => { Res::Def(DefKind::Static{..}, def_id) => {
let mutable = self.cx.tcx.is_mutable_static(def_id); let mutable = self.cx.tcx.is_mutable_static(def_id);
self.def_ids.insert(def_id, mutable); self.def_ids.insert(def_id, mutable);
}, },

View file

@ -91,7 +91,7 @@ pub(super) fn check<'tcx>(
}, },
hir::ExprKind::Path(ref p) => matches!( hir::ExprKind::Path(ref p) => matches!(
cx.qpath_res(p, arg.hir_id), cx.qpath_res(p, arg.hir_id),
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _) hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static{..}, _)
), ),
_ => false, _ => false,
} }

View file

@ -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(Mutability::Mut), _), res: Res::Def(DefKind::Static{mt: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(Mutability::Mut), _), res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _),
.. ..
} }
)) ))