mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-13 17:13:48 +00:00
Introduce query static_mutability
This commit is contained in:
parent
4d9c6cd722
commit
286a469a16
@ -238,6 +238,9 @@ rustc_queries! {
|
|||||||
/// True if this is a foreign item (i.e., linked via `extern { ... }`).
|
/// True if this is a foreign item (i.e., linked via `extern { ... }`).
|
||||||
query is_foreign_item(_: DefId) -> bool {}
|
query is_foreign_item(_: DefId) -> bool {}
|
||||||
|
|
||||||
|
/// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
|
||||||
|
query static_mutability(_: DefId) -> Option<hir::Mutability> {}
|
||||||
|
|
||||||
/// Get a map with the variance of every item; use `item_variance`
|
/// Get a map with the variance of every item; use `item_variance`
|
||||||
/// instead.
|
/// instead.
|
||||||
query crate_variances(_: CrateNum) -> Lrc<ty::CrateVariancesMap> {
|
query crate_variances(_: CrateNum) -> Lrc<ty::CrateVariancesMap> {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
|
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
|
||||||
|
|
||||||
use crate::hir::def::Def;
|
use crate::hir;
|
||||||
use crate::hir::def_id::DefId;
|
use crate::hir::def_id::DefId;
|
||||||
use crate::hir::map::DefPathData;
|
use crate::hir::map::DefPathData;
|
||||||
use crate::hir::{self, Node};
|
|
||||||
use crate::mir::interpret::{sign_extend, truncate};
|
use crate::mir::interpret::{sign_extend, truncate};
|
||||||
use crate::ich::NodeIdHashingMode;
|
use crate::ich::NodeIdHashingMode;
|
||||||
use crate::traits::{self, ObligationCause};
|
use crate::traits::{self, ObligationCause};
|
||||||
@ -615,32 +614,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
|
|
||||||
/// Returns `true` if the node pointed to by `def_id` is a static item, and its mutability.
|
/// Returns `true` if the node pointed to by `def_id` is a static item, and its mutability.
|
||||||
pub fn is_static(&self, def_id: DefId) -> Option<hir::Mutability> {
|
pub fn is_static(&self, def_id: DefId) -> Option<hir::Mutability> {
|
||||||
if let Some(node) = self.hir().get_if_local(def_id) {
|
self.static_mutability(def_id)
|
||||||
match node {
|
|
||||||
Node::Item(&hir::Item {
|
|
||||||
node: hir::ItemKind::Static(_, mutbl, _), ..
|
|
||||||
}) => Some(mutbl),
|
|
||||||
Node::ForeignItem(&hir::ForeignItem {
|
|
||||||
node: hir::ForeignItemKind::Static(_, is_mutbl), ..
|
|
||||||
}) =>
|
|
||||||
Some(if is_mutbl {
|
|
||||||
hir::Mutability::MutMutable
|
|
||||||
} else {
|
|
||||||
hir::Mutability::MutImmutable
|
|
||||||
}),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match self.describe_def(def_id) {
|
|
||||||
Some(Def::Static(_, is_mutbl)) =>
|
|
||||||
Some(if is_mutbl {
|
|
||||||
hir::Mutability::MutMutable
|
|
||||||
} else {
|
|
||||||
hir::Mutability::MutImmutable
|
|
||||||
}),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Expands the given impl trait type, stopping if the type is recursive.
|
/// Expands the given impl trait type, stopping if the type is recursive.
|
||||||
|
@ -137,6 +137,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||||||
inherent_impls => { Lrc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
|
inherent_impls => { Lrc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
|
||||||
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
|
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
|
||||||
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||||
|
static_mutability => { cdata.static_mutability(def_id.index) }
|
||||||
describe_def => { cdata.get_def(def_id.index) }
|
describe_def => { cdata.get_def(def_id.index) }
|
||||||
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||||
lookup_stability => {
|
lookup_stability => {
|
||||||
|
@ -1163,6 +1163,16 @@ impl<'a, 'tcx> CrateMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate fn static_mutability(&self, id: DefIndex) -> Option<hir::Mutability> {
|
||||||
|
match self.entry(id).kind {
|
||||||
|
EntryKind::ImmStatic |
|
||||||
|
EntryKind::ForeignImmStatic => Some(hir::MutImmutable),
|
||||||
|
EntryKind::MutStatic |
|
||||||
|
EntryKind::ForeignMutStatic => Some(hir::MutMutable),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn fn_sig(&self,
|
pub fn fn_sig(&self,
|
||||||
id: DefIndex,
|
id: DefIndex,
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
||||||
|
@ -78,6 +78,7 @@ pub fn provide(providers: &mut Providers<'_>) {
|
|||||||
impl_trait_ref,
|
impl_trait_ref,
|
||||||
impl_polarity,
|
impl_polarity,
|
||||||
is_foreign_item,
|
is_foreign_item,
|
||||||
|
static_mutability,
|
||||||
codegen_fn_attrs,
|
codegen_fn_attrs,
|
||||||
collect_mod_item_types,
|
collect_mod_item_types,
|
||||||
..*providers
|
..*providers
|
||||||
@ -2361,6 +2362,22 @@ fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn static_mutability<'a, 'tcx>(
|
||||||
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
def_id: DefId,
|
||||||
|
) -> Option<hir::Mutability> {
|
||||||
|
match tcx.hir().get_if_local(def_id) {
|
||||||
|
Some(Node::Item(&hir::Item {
|
||||||
|
node: hir::ItemKind::Static(_, mutbl, _), ..
|
||||||
|
})) => Some(mutbl),
|
||||||
|
Some(Node::ForeignItem( &hir::ForeignItem {
|
||||||
|
node: hir::ForeignItemKind::Static(_, mutbl), ..
|
||||||
|
})) => Some(if mutbl { hir::MutMutable } else { hir::MutImmutable }),
|
||||||
|
Some(_) => None,
|
||||||
|
_ => bug!("static_mutability applied to non-local def-id {:?}", def_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn from_target_feature(
|
fn from_target_feature(
|
||||||
tcx: TyCtxt<'_, '_, '_>,
|
tcx: TyCtxt<'_, '_, '_>,
|
||||||
id: DefId,
|
id: DefId,
|
||||||
|
Loading…
Reference in New Issue
Block a user