/// True if this is a foreign item (i.e., linked via `extern { ... }`).
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`
/// instead.
query crate_variances(_: CrateNum) -> Lrc<ty::CrateVariancesMap> {
//! 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::map::DefPathData;
-use crate::hir::{self, Node};
use crate::mir::interpret::{sign_extend, truncate};
use crate::ich::NodeIdHashingMode;
use crate::traits::{self, ObligationCause};
/// 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> {
- if let Some(node) = self.hir().get_if_local(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
- }
- }
+ self.static_mutability(def_id)
}
/// Expands the given impl trait type, stopping if the type is recursive.
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_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) }
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
lookup_stability => {
}
}
+ 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,
id: DefIndex,
tcx: TyCtxt<'a, 'tcx, 'tcx>)
impl_trait_ref,
impl_polarity,
is_foreign_item,
+ static_mutability,
codegen_fn_attrs,
collect_mod_item_types,
..*providers
}
}
+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(
tcx: TyCtxt<'_, '_, '_>,
id: DefId,