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 @@ pub(crate) fn lower_inline_asm(
.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,
});

View file

@ -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;
}
}

View file

@ -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

View file

@ -457,15 +457,16 @@ fn check_safe_pointer(
// 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(

View file

@ -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 @@ pub fn descr(self, def_id: DefId) -> &'static str {
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 @@ pub fn ns(&self) -> Option<Namespace> {
DefKind::Fn
| DefKind::Const
| DefKind::ConstParam
| DefKind::Static(..)
| DefKind::Static { .. }
| DefKind::Ctor(..)
| DefKind::AssocFn
| DefKind::AssocConst => Some(Namespace::ValueNS),
@ -248,7 +251,7 @@ pub fn def_path_data(self, name: Symbol) -> DefPathData {
DefKind::Fn
| DefKind::Const
| DefKind::ConstParam
| DefKind::Static(..)
| DefKind::Static { .. }
| DefKind::AssocFn
| DefKind::AssocConst
| DefKind::Field => DefPathData::ValueNs(name),
@ -278,7 +281,7 @@ pub fn has_codegen_attrs(self) -> bool {
| DefKind::AssocFn
| DefKind::Ctor(..)
| DefKind::Closure
| DefKind::Static(_) => true,
| DefKind::Static { .. } => true,
DefKind::Mod
| DefKind::Struct
| DefKind::Union

View file

@ -1616,7 +1616,7 @@ pub fn is_syntactic_place_expr(&self) -> bool {
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

View file

@ -107,7 +107,7 @@ pub fn from_item(item: &Item<'_>) -> 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 @@ pub fn from_def_kind(def_kind: DefKind) -> 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,

View file

@ -1934,7 +1934,7 @@ pub fn def_ids_for_value_path_segments(
}
// 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));
}

View file

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

View file

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

View file

@ -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()),
_ => (),
}

View file

@ -699,7 +699,7 @@ fn annotate_expected_due_to_let_ty(
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,
),
..

View file

@ -398,7 +398,7 @@ pub(crate) fn cat_res(
)
| 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()))
}

View file

@ -372,7 +372,7 @@ fn foo(&self, x: T) -> T { x }
&& matches!(
tcx.def_kind(body_owner_def_id),
DefKind::Fn
| DefKind::Static(_)
| DefKind::Static { .. }
| DefKind::Const
| DefKind::AssocFn
| DefKind::AssocConst

View file

@ -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 @@ fn encode_def_ids(&mut self) {
.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);

View file

@ -155,8 +155,8 @@ impl FixedSizeEncoding for Option<$ty> {
( 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) )

View file

@ -343,7 +343,7 @@ pub fn body_owner_kind(self, def_id: impl Into<DefId>) -> BodyOwnerKind {
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),
}
}

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) {
(_, 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),

View file

@ -1708,7 +1708,7 @@ pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
debug!("returned from def_kind: {:?}", def_kind);
match def_kind {
DefKind::Const
| DefKind::Static(..)
| DefKind::Static { .. }
| DefKind::AssocConst
| DefKind::Ctor(..)
| DefKind::AnonConst

View file

@ -359,7 +359,7 @@ fn force_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintE
| 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.

View file

@ -616,12 +616,12 @@ pub fn closure_env_ty(
/// 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.

View file

@ -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(),

View file

@ -942,7 +942,7 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
// 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

View file

@ -453,7 +453,7 @@ fn lower_variant_or_leaf(
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 }),

View file

@ -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(),

View file

@ -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 @@ fn process_item(&mut self, id: hir::ItemId) {
);
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)));

View file

@ -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

View file

@ -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 @@ fn check_definition(&mut self, def_id: LocalDefId) {
DefKind::AssocConst
| DefKind::AssocFn
| DefKind::Fn
| DefKind::Static(_)
| DefKind::Static { .. }
| DefKind::Const
| DefKind::TyAlias
| DefKind::Enum

View file

@ -73,7 +73,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'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);
}
_ => {

View file

@ -549,7 +549,7 @@ fn update_macro_reachable_def(
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 @@ fn visit_qpath(&mut self, qpath: &'tcx hir::QPath<'tcx>, id: hir::HirId, span: S
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 @@ pub fn check_item(&mut self, id: ItemId) {
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);
}

View file

@ -990,7 +990,7 @@ fn build_reduced_graph_for_external_crate_res(&mut self, child: &ModChild) {
Res::Def(
DefKind::Fn
| DefKind::AssocFn
| DefKind::Static(_)
| DefKind::Static { .. }
| DefKind::Const
| DefKind::AssocConst
| DefKind::Ctor(..),

View file

@ -127,7 +127,7 @@ fn visit_item(&mut self, i: &'a Item) {
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 @@ fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
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),

View file

@ -574,7 +574,7 @@ pub(crate) fn into_struct_error(
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,
};

View file

@ -500,7 +500,7 @@ pub(crate) fn is_expected(self, res: Res) -> bool {
Res::Def(
DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
| DefKind::Const
| DefKind::Static(_)
| DefKind::Static { .. }
| DefKind::Fn
| DefKind::AssocFn
| DefKind::AssocConst
@ -3645,7 +3645,7 @@ fn try_resolve_as_non_binding(
}
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),

View file

@ -264,7 +264,7 @@ fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind {
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)),
),

View file

@ -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),
}

View file

@ -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

View file

@ -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 => {

View file

@ -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

View file

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

View file

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

View file

@ -128,7 +128,7 @@ pub(crate) fn from_def_kind(kind: DefKind, parent_kind: Option<DefKind>) -> Self
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,

View file

@ -123,7 +123,7 @@ fn disambiguator_suggestion(self) -> Suggestion {
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 @@ fn from_str(link: &str) -> Result<Option<(Self, &str, &str)>, (String, Range<usi
"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 {

View file

@ -273,7 +273,7 @@ fn check(&mut self, idx: &'tcx Expr<'_>, seqexpr: &'tcx Expr<'_>, expr: &'tcx Ex
}
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,

View file

@ -101,7 +101,7 @@ fn insert_def_id(&mut self, ex: &'tcx Expr<'_>) {
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);
},

View file

@ -91,7 +91,7 @@ fn can_be_static_str(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
},
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,
}

View file

@ -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}, _),
..
}
))