mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Change DefKind::Static
to a struct variant
This commit is contained in:
parent
12e2846514
commit
9816915954
@ -196,7 +196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
.get_partial_res(sym.id)
|
||||
.and_then(|res| res.full_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,
|
||||
});
|
||||
|
||||
|
@ -87,7 +87,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
|
||||
|
||||
// Only consider nodes that actually have exported symbols.
|
||||
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() => {}
|
||||
_ => return None,
|
||||
};
|
||||
@ -483,7 +483,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
|
||||
let target = &tcx.sess.target.llvm_target;
|
||||
// WebAssembly cannot export data symbols, so reduce their export level
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
|
||||
|| matches!(
|
||||
ecx.tcx.def_kind(cid.instance.def_id()),
|
||||
DefKind::Const
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
|
@ -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).
|
||||
assert!(!self.ecx.tcx.is_thread_local_static(did));
|
||||
assert!(self.ecx.tcx.is_static(did));
|
||||
let is_mut =
|
||||
matches!(self.ecx.tcx.def_kind(did), DefKind::Static(Mutability::Mut))
|
||||
|| !self
|
||||
.ecx
|
||||
.tcx
|
||||
.type_of(did)
|
||||
.no_bound_vars()
|
||||
.expect("statics should not have generic parameters")
|
||||
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all());
|
||||
let is_mut = matches!(
|
||||
self.ecx.tcx.def_kind(did),
|
||||
DefKind::Static { mt: Mutability::Mut }
|
||||
) || !self
|
||||
.ecx
|
||||
.tcx
|
||||
.type_of(did)
|
||||
.no_bound_vars()
|
||||
.expect("statics should not have generic parameters")
|
||||
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all());
|
||||
// Mode-specific checks
|
||||
match self.ctfe_mode {
|
||||
Some(
|
||||
|
@ -75,7 +75,10 @@ pub enum DefKind {
|
||||
Const,
|
||||
/// Constant generic parameter: `struct Foo<const N: usize> { ... }`
|
||||
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.
|
||||
///
|
||||
/// The reason `Ctor` exists in addition to [`DefKind::Struct`] and
|
||||
@ -136,7 +139,7 @@ impl DefKind {
|
||||
DefKind::Fn => "function",
|
||||
DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
|
||||
DefKind::Mod => "module",
|
||||
DefKind::Static(..) => "static",
|
||||
DefKind::Static { .. } => "static",
|
||||
DefKind::Enum => "enum",
|
||||
DefKind::Variant => "variant",
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
|
||||
@ -209,7 +212,7 @@ impl DefKind {
|
||||
DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst => Some(Namespace::ValueNS),
|
||||
@ -248,7 +251,7 @@ impl DefKind {
|
||||
DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Field => DefPathData::ValueNs(name),
|
||||
@ -278,7 +281,7 @@ impl DefKind {
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::Closure
|
||||
| DefKind::Static(_) => true,
|
||||
| DefKind::Static { .. } => true,
|
||||
DefKind::Mod
|
||||
| DefKind::Struct
|
||||
| DefKind::Union
|
||||
|
@ -1616,7 +1616,7 @@ impl Expr<'_> {
|
||||
pub fn is_place_expr(&self, mut allow_projections_from: impl FnMut(&Self) -> bool) -> bool {
|
||||
match self.kind {
|
||||
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
|
||||
|
@ -107,7 +107,7 @@ impl Target {
|
||||
match item.kind {
|
||||
ItemKind::ExternCrate(..) => Target::ExternCrate,
|
||||
ItemKind::Use(..) => Target::Use,
|
||||
ItemKind::Static(..) => Target::Static,
|
||||
ItemKind::Static { .. } => Target::Static,
|
||||
ItemKind::Const(..) => Target::Const,
|
||||
ItemKind::Fn(..) => Target::Fn,
|
||||
ItemKind::Macro(..) => Target::MacroDef,
|
||||
@ -130,7 +130,7 @@ impl Target {
|
||||
match def_kind {
|
||||
DefKind::ExternCrate => Target::ExternCrate,
|
||||
DefKind::Use => Target::Use,
|
||||
DefKind::Static(..) => Target::Static,
|
||||
DefKind::Static { .. } => Target::Static,
|
||||
DefKind::Const => Target::Const,
|
||||
DefKind::Fn => Target::Fn,
|
||||
DefKind::Macro(..) => Target::MacroDef,
|
||||
|
@ -1934,7 +1934,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
Ok(l) => l,
|
||||
// Foreign statics that overflow their allowed size should emit an error
|
||||
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) =>
|
||||
{
|
||||
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) {
|
||||
let _indenter = indenter();
|
||||
match tcx.def_kind(def_id) {
|
||||
DefKind::Static(..) => {
|
||||
DefKind::Static { .. } => {
|
||||
tcx.ensure().typeck(def_id);
|
||||
maybe_check_static_with_link_section(tcx, def_id);
|
||||
check_static_inhabited(tcx, def_id);
|
||||
|
@ -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 } = def_kind
|
||||
&& matches!(mt, Mutability::Mut)
|
||||
{
|
||||
return Some(qpath_to_string(&qpath));
|
||||
|
@ -182,7 +182,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
tcx.hir().par_body_owners(|item_def_id| {
|
||||
let def_kind = tcx.def_kind(item_def_id);
|
||||
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()),
|
||||
_ => (),
|
||||
}
|
||||
|
@ -699,7 +699,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
hir::Path {
|
||||
res:
|
||||
hir::def::Res::Def(
|
||||
hir::def::DefKind::Static(_) | hir::def::DefKind::Const,
|
||||
hir::def::DefKind::Static { .. } | hir::def::DefKind::Const,
|
||||
def_id,
|
||||
),
|
||||
..
|
||||
|
@ -398,7 +398,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
||||
)
|
||||
| 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()))
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ impl<T> Trait<T> for X {
|
||||
&& matches!(
|
||||
tcx.def_kind(body_owner_def_id),
|
||||
DefKind::Fn
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
|
@ -863,7 +863,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
@ -894,7 +894,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Macro(_)
|
||||
@ -936,7 +936,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
@ -968,7 +968,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
@ -1001,7 +1001,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
|
||||
| DefKind::AssocConst
|
||||
| DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::Fn
|
||||
| DefKind::ForeignMod
|
||||
@ -1099,7 +1099,7 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
|
||||
| DefKind::AssocConst
|
||||
| DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::ForeignMod
|
||||
| DefKind::Impl { .. }
|
||||
@ -1131,7 +1131,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
@ -1163,7 +1163,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
|
||||
| DefKind::Field
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::TyAlias
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::Impl { .. }
|
||||
@ -1222,7 +1222,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
|
||||
| DefKind::Variant
|
||||
| DefKind::Field
|
||||
| DefKind::Const
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::TyAlias
|
||||
| DefKind::OpaqueTy
|
||||
@ -1263,7 +1263,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AnonConst
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::TyAlias
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::Impl { of_trait: false }
|
||||
@ -1295,7 +1295,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::Field
|
||||
| DefKind::Fn
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::TyAlias
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::ForeignTy
|
||||
@ -1469,7 +1469,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
.coroutine_for_closure
|
||||
.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) {
|
||||
let data = self.tcx.eval_static_initializer(def_id).unwrap();
|
||||
record!(self.tables.eval_static_initializer[def_id] <- data);
|
||||
|
@ -155,8 +155,8 @@ fixed_size_enum! {
|
||||
( Impl { of_trait: false } )
|
||||
( Impl { of_trait: true } )
|
||||
( Closure )
|
||||
( Static(ast::Mutability::Not) )
|
||||
( Static(ast::Mutability::Mut) )
|
||||
( Static{mt:ast::Mutability::Not} )
|
||||
( Static{mt:ast::Mutability::Mut} )
|
||||
( 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 } => BodyOwnerKind::Static(mt),
|
||||
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
|
||||
}
|
||||
}
|
||||
|
@ -498,8 +498,8 @@ 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(hir::Mutability::Not), _) => write!(w, "static ")?,
|
||||
(DefKind::Static(hir::Mutability::Mut), _) => write!(w, "static mut ")?,
|
||||
(DefKind::Static { mt: hir::Mutability::Not }, _) => write!(w, "static ")?,
|
||||
(DefKind::Static { mt: hir::Mutability::Mut }, _) => 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),
|
||||
|
@ -1708,7 +1708,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
debug!("returned from def_kind: {:?}", def_kind);
|
||||
match def_kind {
|
||||
DefKind::Const
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AnonConst
|
||||
|
@ -359,7 +359,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||
| DefKind::TyAlias
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Static(_) = kind
|
||||
| DefKind::Static { .. } = kind
|
||||
{
|
||||
} else {
|
||||
// If not covered above, like for example items out of `impl` blocks, fallback.
|
||||
|
@ -616,12 +616,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Returns `true` if the node pointed to by `def_id` is a `static` item.
|
||||
#[inline]
|
||||
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]
|
||||
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.
|
||||
|
@ -631,7 +631,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AnonConst
|
||||
| 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 => {
|
||||
let sig = tcx.liberate_late_bound_regions(
|
||||
def_id.to_def_id(),
|
||||
|
@ -942,7 +942,7 @@ impl<'tcx> Cx<'tcx> {
|
||||
|
||||
// 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
|
||||
Res::Def(DefKind::Static(_), id) => {
|
||||
Res::Def(DefKind::Static { .. }, id) => {
|
||||
let ty = self.tcx.static_ptr_ty(id);
|
||||
let temp_lifetime = self
|
||||
.rvalue_scopes
|
||||
|
@ -453,7 +453,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||
Res::Def(DefKind::ConstParam, _) => {
|
||||
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(NonConstPath { span }),
|
||||
|
@ -333,7 +333,7 @@ fn mir_promoted(
|
||||
}
|
||||
DefKind::AssocConst
|
||||
| DefKind::Const
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AnonConst => tcx.mir_const_qualif(def),
|
||||
_ => ConstQualifs::default(),
|
||||
|
@ -1037,7 +1037,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
|
||||
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.
|
||||
return false;
|
||||
}
|
||||
@ -1254,7 +1254,7 @@ impl<'v> RootCollector<'_, 'v> {
|
||||
);
|
||||
self.output.push(dummy_spanned(MonoItem::GlobalAsm(id)));
|
||||
}
|
||||
DefKind::Static(..) => {
|
||||
DefKind::Static { .. } => {
|
||||
let def_id = id.owner_id.to_def_id();
|
||||
debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id));
|
||||
self.output.push(dummy_spanned(MonoItem::Static(def_id)));
|
||||
|
@ -150,7 +150,7 @@ fn mark_used_by_default_parameters<'tcx>(
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(_, _)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
|
@ -801,7 +801,7 @@ fn check_foreign_item(
|
||||
worklist: &mut Vec<(LocalDefId, ComesFromAllowExpect)>,
|
||||
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)
|
||||
{
|
||||
worklist.push((id.owner_id.def_id, comes_from_allow));
|
||||
@ -1058,7 +1058,7 @@ impl<'tcx> DeadVisitor<'tcx> {
|
||||
DefKind::AssocConst
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Fn
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::TyAlias
|
||||
| DefKind::Enum
|
||||
|
@ -73,7 +73,7 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
|
||||
match res {
|
||||
// Reachable constants and reachable statics can have their contents inlined
|
||||
// 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);
|
||||
}
|
||||
_ => {
|
||||
|
@ -549,7 +549,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
||||
self.update(def_id, macro_ev, Level::Reachable);
|
||||
match def_kind {
|
||||
// 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) {
|
||||
self.update(def_id, macro_ev, Level::Reachable);
|
||||
}
|
||||
@ -1170,12 +1170,12 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
|
||||
let def = def.filter(|(kind, _)| {
|
||||
matches!(
|
||||
kind,
|
||||
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static(_)
|
||||
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static { .. }
|
||||
)
|
||||
});
|
||||
if let Some((kind, def_id)) = def {
|
||||
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 {
|
||||
let name = match *qpath {
|
||||
hir::QPath::LangItem(it, ..) => {
|
||||
@ -1496,7 +1496,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
|
||||
let def_kind = tcx.def_kind(def_id);
|
||||
|
||||
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 {
|
||||
self.check_unnameable(def_id, effective_vis);
|
||||
}
|
||||
|
@ -990,7 +990,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
Res::Def(
|
||||
DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Ctor(..),
|
||||
|
@ -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(s.mutability),
|
||||
ItemKind::Static(s) => DefKind::Static { mt: s.mutability },
|
||||
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 },
|
||||
ForeignItemKind::Fn(_) => DefKind::Fn,
|
||||
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
|
||||
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
||||
|
@ -574,7 +574,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params, def_kind) => {
|
||||
use errs::GenericParamsFromOuterItemLabel as Label;
|
||||
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),
|
||||
_ => None,
|
||||
};
|
||||
|
@ -500,7 +500,7 @@ impl<'a> PathSource<'a> {
|
||||
Res::Def(
|
||||
DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
|
||||
| DefKind::Const
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
@ -3645,7 +3645,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}
|
||||
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
|
||||
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
|
||||
// to something unusable as a pattern (e.g., constructor function),
|
||||
|
@ -264,7 +264,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
||||
use rustc_hir::def::DefKind;
|
||||
match tcx.def_kind(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(
|
||||
tables.intern_ty(rustc_middle::ty::Ty::new_foreign(tcx, def_id)),
|
||||
),
|
||||
|
@ -95,7 +95,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
|
||||
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
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::Fn) => ItemKind::Ctor(CtorKind::Fn),
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
|
||||
| DefKind::TyParam
|
||||
| DefKind::Const
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(_, _)
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::ExternCrate
|
||||
|
@ -318,7 +318,7 @@ fn opaque_types_defined_by<'tcx>(
|
||||
match kind {
|
||||
DefKind::AssocFn
|
||||
| DefKind::Fn
|
||||
| DefKind::Static(_)
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AnonConst => {
|
||||
|
@ -43,7 +43,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
|
||||
// Walk over the type behind the alias
|
||||
DefKind::TyAlias {..} | DefKind::AssocTy |
|
||||
// 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 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
|
||||
|
@ -120,7 +120,7 @@ pub(crate) fn try_inline(
|
||||
record_extern_fqn(cx, did, ItemType::Module);
|
||||
clean::ModuleItem(build_module(cx, did, visited))
|
||||
}
|
||||
Res::Def(DefKind::Static(_), did) => {
|
||||
Res::Def(DefKind::Static { .. }, did) => {
|
||||
record_extern_fqn(cx, did, ItemType::Static);
|
||||
cx.with_param_env(did, |cx| {
|
||||
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
|
||||
|
@ -526,7 +526,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
|
||||
| Mod
|
||||
| ForeignTy
|
||||
| Const
|
||||
| Static(_)
|
||||
| Static { .. }
|
||||
| Macro(..)
|
||||
| TraitAlias),
|
||||
did,
|
||||
|
@ -128,7 +128,7 @@ impl ItemType {
|
||||
DefKind::Fn => Self::Function,
|
||||
DefKind::Mod => Self::Module,
|
||||
DefKind::Const => Self::Constant,
|
||||
DefKind::Static(_) => Self::Static,
|
||||
DefKind::Static { .. } => Self::Static,
|
||||
DefKind::Struct => Self::Struct,
|
||||
DefKind::Union => Self::Union,
|
||||
DefKind::Trait => Self::Trait,
|
||||
|
@ -123,7 +123,7 @@ impl Res {
|
||||
DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
"const"
|
||||
}
|
||||
DefKind::Static(_) => "static",
|
||||
DefKind::Static { .. } => "static",
|
||||
// Now handle things that don't have a specific disambiguator
|
||||
_ => match kind
|
||||
.ns()
|
||||
@ -1514,7 +1514,7 @@ impl Disambiguator {
|
||||
"union" => Kind(DefKind::Union),
|
||||
"module" | "mod" => Kind(DefKind::Mod),
|
||||
"const" | "constant" => Kind(DefKind::Const),
|
||||
"static" => Kind(DefKind::Static(Mutability::Not)),
|
||||
"static" => Kind(DefKind::Static { mt: Mutability::Not }),
|
||||
"function" | "fn" | "method" => Kind(DefKind::Fn),
|
||||
"derive" => Kind(DefKind::Macro(MacroKind::Derive)),
|
||||
"type" => NS(Namespace::TypeNS),
|
||||
@ -1926,7 +1926,7 @@ fn resolution_failure(
|
||||
| OpaqueTy
|
||||
| TraitAlias
|
||||
| TyParam
|
||||
| Static(_) => "associated item",
|
||||
| Static { .. } => "associated item",
|
||||
Impl { .. } | GlobalAsm => unreachable!("not a path"),
|
||||
}
|
||||
} else {
|
||||
|
@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||
}
|
||||
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 {
|
||||
self.indexed_directly.insert(
|
||||
seqvar.segments[0].ident.name,
|
||||
|
@ -101,7 +101,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
|
||||
Res::Local(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);
|
||||
self.def_ids.insert(def_id, mutable);
|
||||
},
|
||||
|
@ -91,7 +91,7 @@ pub(super) fn check<'tcx>(
|
||||
},
|
||||
hir::ExprKind::Path(ref p) => matches!(
|
||||
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,
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||
ExprKind::Path(QPath::Resolved(
|
||||
_,
|
||||
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(
|
||||
_,
|
||||
hir::Path {
|
||||
res: Res::Def(DefKind::Static(Mutability::Mut), _),
|
||||
res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _),
|
||||
..
|
||||
}
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user