don't take TyCtxt
by reference
This commit is contained in:
parent
2c69266c06
commit
925cd26162
@ -17,7 +17,7 @@ use rustc_target::spec::PanicStrategy;
|
|||||||
impl<'tcx> TyCtxt<'tcx> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Returns the `DefId` for a given `LangItem`.
|
/// Returns the `DefId` for a given `LangItem`.
|
||||||
/// If not found, fatally aborts compilation.
|
/// If not found, fatally aborts compilation.
|
||||||
pub fn require_lang_item(&self, lang_item: LangItem, span: Option<Span>) -> DefId {
|
pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId {
|
||||||
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
|
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
|
||||||
if let Some(span) = span {
|
if let Some(span) = span {
|
||||||
self.sess.span_fatal(span, &msg)
|
self.sess.span_fatal(span, &msg)
|
||||||
@ -27,7 +27,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fn_trait_kind_from_lang_item(&self, id: DefId) -> Option<ty::ClosureKind> {
|
pub fn fn_trait_kind_from_lang_item(self, id: DefId) -> Option<ty::ClosureKind> {
|
||||||
let items = self.lang_items();
|
let items = self.lang_items();
|
||||||
match Some(id) {
|
match Some(id) {
|
||||||
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),
|
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),
|
||||||
@ -37,7 +37,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
|
pub fn is_weak_lang_item(self, item_def_id: DefId) -> bool {
|
||||||
self.lang_items().is_weak_lang_item(item_def_id)
|
self.lang_items().is_weak_lang_item(item_def_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,14 +447,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
///
|
///
|
||||||
/// Make sure to call `set_alloc_id_memory` or `set_alloc_id_same_memory` before returning such
|
/// Make sure to call `set_alloc_id_memory` or `set_alloc_id_same_memory` before returning such
|
||||||
/// an `AllocId` from a query.
|
/// an `AllocId` from a query.
|
||||||
pub fn reserve_alloc_id(&self) -> AllocId {
|
pub fn reserve_alloc_id(self) -> AllocId {
|
||||||
self.alloc_map.lock().reserve()
|
self.alloc_map.lock().reserve()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reserves a new ID *if* this allocation has not been dedup-reserved before.
|
/// Reserves a new ID *if* this allocation has not been dedup-reserved before.
|
||||||
/// Should only be used for function pointers and statics, we don't want
|
/// Should only be used for function pointers and statics, we don't want
|
||||||
/// to dedup IDs for "real" memory!
|
/// to dedup IDs for "real" memory!
|
||||||
fn reserve_and_set_dedup(&self, alloc: GlobalAlloc<'tcx>) -> AllocId {
|
fn reserve_and_set_dedup(self, alloc: GlobalAlloc<'tcx>) -> AllocId {
|
||||||
let mut alloc_map = self.alloc_map.lock();
|
let mut alloc_map = self.alloc_map.lock();
|
||||||
match alloc {
|
match alloc {
|
||||||
GlobalAlloc::Function(..) | GlobalAlloc::Static(..) => {}
|
GlobalAlloc::Function(..) | GlobalAlloc::Static(..) => {}
|
||||||
@ -472,13 +472,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Generates an `AllocId` for a static or return a cached one in case this function has been
|
/// Generates an `AllocId` for a static or return a cached one in case this function has been
|
||||||
/// called on the same static before.
|
/// called on the same static before.
|
||||||
pub fn create_static_alloc(&self, static_id: DefId) -> AllocId {
|
pub fn create_static_alloc(self, static_id: DefId) -> AllocId {
|
||||||
self.reserve_and_set_dedup(GlobalAlloc::Static(static_id))
|
self.reserve_and_set_dedup(GlobalAlloc::Static(static_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates an `AllocId` for a function. Depending on the function type,
|
/// Generates an `AllocId` for a function. Depending on the function type,
|
||||||
/// this might get deduplicated or assigned a new ID each time.
|
/// this might get deduplicated or assigned a new ID each time.
|
||||||
pub fn create_fn_alloc(&self, instance: Instance<'tcx>) -> AllocId {
|
pub fn create_fn_alloc(self, instance: Instance<'tcx>) -> AllocId {
|
||||||
// Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
|
// Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
|
||||||
// by the linker (we set the "unnamed_addr" attribute for LLVM) and functions can be
|
// by the linker (we set the "unnamed_addr" attribute for LLVM) and functions can be
|
||||||
// duplicated across crates.
|
// duplicated across crates.
|
||||||
@ -507,7 +507,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// Statics with identical content will still point to the same `Allocation`, i.e.,
|
/// Statics with identical content will still point to the same `Allocation`, i.e.,
|
||||||
/// their data will be deduplicated through `Allocation` interning -- but they
|
/// their data will be deduplicated through `Allocation` interning -- but they
|
||||||
/// are different places in memory and as such need different IDs.
|
/// are different places in memory and as such need different IDs.
|
||||||
pub fn create_memory_alloc(&self, mem: &'tcx Allocation) -> AllocId {
|
pub fn create_memory_alloc(self, mem: &'tcx Allocation) -> AllocId {
|
||||||
let id = self.reserve_alloc_id();
|
let id = self.reserve_alloc_id();
|
||||||
self.set_alloc_id_memory(id, mem);
|
self.set_alloc_id_memory(id, mem);
|
||||||
id
|
id
|
||||||
@ -519,7 +519,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// This function exists to allow const eval to detect the difference between evaluation-
|
/// This function exists to allow const eval to detect the difference between evaluation-
|
||||||
/// local dangling pointers and allocations in constants/statics.
|
/// local dangling pointers and allocations in constants/statics.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_global_alloc(&self, id: AllocId) -> Option<GlobalAlloc<'tcx>> {
|
pub fn get_global_alloc(self, id: AllocId) -> Option<GlobalAlloc<'tcx>> {
|
||||||
self.alloc_map.lock().alloc_map.get(&id).cloned()
|
self.alloc_map.lock().alloc_map.get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +529,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// constants (as all constants must pass interning and validation that check for dangling
|
/// constants (as all constants must pass interning and validation that check for dangling
|
||||||
/// ids), this function is frequently used throughout rustc, but should not be used within
|
/// ids), this function is frequently used throughout rustc, but should not be used within
|
||||||
/// the miri engine.
|
/// the miri engine.
|
||||||
pub fn global_alloc(&self, id: AllocId) -> GlobalAlloc<'tcx> {
|
pub fn global_alloc(self, id: AllocId) -> GlobalAlloc<'tcx> {
|
||||||
match self.get_global_alloc(id) {
|
match self.get_global_alloc(id) {
|
||||||
Some(alloc) => alloc,
|
Some(alloc) => alloc,
|
||||||
None => bug!("could not find allocation for {}", id),
|
None => bug!("could not find allocation for {}", id),
|
||||||
@ -538,7 +538,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. Trying to
|
/// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. Trying to
|
||||||
/// call this function twice, even with the same `Allocation` will ICE the compiler.
|
/// call this function twice, even with the same `Allocation` will ICE the compiler.
|
||||||
pub fn set_alloc_id_memory(&self, id: AllocId, mem: &'tcx Allocation) {
|
pub fn set_alloc_id_memory(self, id: AllocId, mem: &'tcx Allocation) {
|
||||||
if let Some(old) = self.alloc_map.lock().alloc_map.insert(id, GlobalAlloc::Memory(mem)) {
|
if let Some(old) = self.alloc_map.lock().alloc_map.insert(id, GlobalAlloc::Memory(mem)) {
|
||||||
bug!("tried to set allocation ID {}, but it was already existing as {:#?}", id, old);
|
bug!("tried to set allocation ID {}, but it was already existing as {:#?}", id, old);
|
||||||
}
|
}
|
||||||
@ -546,7 +546,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. May be called
|
/// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. May be called
|
||||||
/// twice for the same `(AllocId, Allocation)` pair.
|
/// twice for the same `(AllocId, Allocation)` pair.
|
||||||
fn set_alloc_id_same_memory(&self, id: AllocId, mem: &'tcx Allocation) {
|
fn set_alloc_id_same_memory(self, id: AllocId, mem: &'tcx Allocation) {
|
||||||
self.alloc_map.lock().alloc_map.insert_same(id, GlobalAlloc::Memory(mem));
|
self.alloc_map.lock().alloc_map.insert_same(id, GlobalAlloc::Memory(mem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1403,7 +1403,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the `DefId` and the `BoundRegion` corresponding to the given region.
|
// Returns the `DefId` and the `BoundRegion` corresponding to the given region.
|
||||||
pub fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
pub fn is_suitable_region(self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
||||||
let (suitable_region_binding_scope, bound_region) = match *region {
|
let (suitable_region_binding_scope, bound_region) = match *region {
|
||||||
ty::ReFree(ref free_region) => {
|
ty::ReFree(ref free_region) => {
|
||||||
(free_region.scope.expect_local(), free_region.bound_region)
|
(free_region.scope.expect_local(), free_region.bound_region)
|
||||||
@ -1433,7 +1433,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
|
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
|
||||||
pub fn return_type_impl_or_dyn_traits(
|
pub fn return_type_impl_or_dyn_traits(
|
||||||
&self,
|
self,
|
||||||
scope_def_id: LocalDefId,
|
scope_def_id: LocalDefId,
|
||||||
) -> Vec<&'tcx hir::Ty<'tcx>> {
|
) -> Vec<&'tcx hir::Ty<'tcx>> {
|
||||||
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
|
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
|
||||||
@ -1479,7 +1479,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
v.0
|
v.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn return_type_impl_trait(&self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
|
pub fn return_type_impl_trait(self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
|
||||||
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
|
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
|
||||||
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
|
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
|
||||||
match self.hir().get(hir_id) {
|
match self.hir().get(hir_id) {
|
||||||
@ -1497,7 +1497,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
let ret_ty = self.type_of(scope_def_id);
|
let ret_ty = self.type_of(scope_def_id);
|
||||||
match ret_ty.kind() {
|
match ret_ty.kind() {
|
||||||
ty::FnDef(_, _) => {
|
ty::FnDef(_, _) => {
|
||||||
let sig = ret_ty.fn_sig(*self);
|
let sig = ret_ty.fn_sig(self);
|
||||||
let output = self.erase_late_bound_regions(&sig.output());
|
let output = self.erase_late_bound_regions(&sig.output());
|
||||||
if output.is_impl_trait() {
|
if output.is_impl_trait() {
|
||||||
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
|
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
|
||||||
@ -1511,7 +1511,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Checks if the bound region is in Impl Item.
|
// Checks if the bound region is in Impl Item.
|
||||||
pub fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: LocalDefId) -> bool {
|
pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool {
|
||||||
let container_id =
|
let container_id =
|
||||||
self.associated_item(suitable_region_binding_scope.to_def_id()).container.id();
|
self.associated_item(suitable_region_binding_scope.to_def_id()).container.id();
|
||||||
if self.impl_trait_ref(container_id).is_some() {
|
if self.impl_trait_ref(container_id).is_some() {
|
||||||
@ -1528,21 +1528,21 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Determines whether identifiers in the assembly have strict naming rules.
|
/// Determines whether identifiers in the assembly have strict naming rules.
|
||||||
/// Currently, only NVPTX* targets need it.
|
/// Currently, only NVPTX* targets need it.
|
||||||
pub fn has_strict_asm_symbol_naming(&self) -> bool {
|
pub fn has_strict_asm_symbol_naming(self) -> bool {
|
||||||
self.sess.target.target.arch.contains("nvptx")
|
self.sess.target.target.arch.contains("nvptx")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `&'static core::panic::Location<'static>`.
|
/// Returns `&'static core::panic::Location<'static>`.
|
||||||
pub fn caller_location_ty(&self) -> Ty<'tcx> {
|
pub fn caller_location_ty(self) -> Ty<'tcx> {
|
||||||
self.mk_imm_ref(
|
self.mk_imm_ref(
|
||||||
self.lifetimes.re_static,
|
self.lifetimes.re_static,
|
||||||
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
|
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
|
||||||
.subst(*self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
|
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
|
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
|
||||||
pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
|
pub fn article_and_description(self, def_id: DefId) -> (&'static str, &'static str) {
|
||||||
match self.def_kind(def_id) {
|
match self.def_kind(def_id) {
|
||||||
DefKind::Generator => match self.generator_kind(def_id).unwrap() {
|
DefKind::Generator => match self.generator_kind(def_id).unwrap() {
|
||||||
rustc_hir::GeneratorKind::Async(..) => ("an", "async closure"),
|
rustc_hir::GeneratorKind::Async(..) => ("an", "async closure"),
|
||||||
|
@ -546,7 +546,7 @@ impl<T> Trait<T> for X {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_constraint(
|
fn suggest_constraint(
|
||||||
&self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
db: &mut DiagnosticBuilder<'_>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
@ -554,14 +554,14 @@ impl<T> Trait<T> for X {
|
|||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let assoc = self.associated_item(proj_ty.item_def_id);
|
let assoc = self.associated_item(proj_ty.item_def_id);
|
||||||
let trait_ref = proj_ty.trait_ref(*self);
|
let trait_ref = proj_ty.trait_ref(self);
|
||||||
if let Some(item) = self.hir().get_if_local(body_owner_def_id) {
|
if let Some(item) = self.hir().get_if_local(body_owner_def_id) {
|
||||||
if let Some(hir_generics) = item.generics() {
|
if let Some(hir_generics) = item.generics() {
|
||||||
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
|
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
|
||||||
// This will also work for `impl Trait`.
|
// This will also work for `impl Trait`.
|
||||||
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
|
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
|
||||||
let generics = self.generics_of(body_owner_def_id);
|
let generics = self.generics_of(body_owner_def_id);
|
||||||
generics.type_param(¶m_ty, *self).def_id
|
generics.type_param(param_ty, self).def_id
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -629,7 +629,7 @@ impl<T> Trait<T> for X {
|
|||||||
/// and the `impl`, we provide a generic `help` to constrain the assoc type or call an assoc
|
/// and the `impl`, we provide a generic `help` to constrain the assoc type or call an assoc
|
||||||
/// fn that returns the type.
|
/// fn that returns the type.
|
||||||
fn expected_projection(
|
fn expected_projection(
|
||||||
&self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
db: &mut DiagnosticBuilder<'_>,
|
||||||
proj_ty: &ty::ProjectionTy<'tcx>,
|
proj_ty: &ty::ProjectionTy<'tcx>,
|
||||||
values: &ExpectedFound<Ty<'tcx>>,
|
values: &ExpectedFound<Ty<'tcx>>,
|
||||||
@ -734,7 +734,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn point_at_methods_that_satisfy_associated_type(
|
fn point_at_methods_that_satisfy_associated_type(
|
||||||
&self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
db: &mut DiagnosticBuilder<'_>,
|
||||||
assoc_container_id: DefId,
|
assoc_container_id: DefId,
|
||||||
current_method_ident: Option<Symbol>,
|
current_method_ident: Option<Symbol>,
|
||||||
@ -789,7 +789,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn point_at_associated_type(
|
fn point_at_associated_type(
|
||||||
&self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
db: &mut DiagnosticBuilder<'_>,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -623,7 +623,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// Replaces any late-bound regions bound in `value` with
|
/// Replaces any late-bound regions bound in `value` with
|
||||||
/// free variants attached to `all_outlive_scope`.
|
/// free variants attached to `all_outlive_scope`.
|
||||||
pub fn liberate_late_bound_regions<T>(
|
pub fn liberate_late_bound_regions<T>(
|
||||||
&self,
|
self,
|
||||||
all_outlive_scope: DefId,
|
all_outlive_scope: DefId,
|
||||||
value: &ty::Binder<T>,
|
value: &ty::Binder<T>,
|
||||||
) -> T
|
) -> T
|
||||||
@ -644,7 +644,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// variables and equate `value` with something else, those
|
/// variables and equate `value` with something else, those
|
||||||
/// variables will also be equated.
|
/// variables will also be equated.
|
||||||
pub fn collect_constrained_late_bound_regions<T>(
|
pub fn collect_constrained_late_bound_regions<T>(
|
||||||
&self,
|
self,
|
||||||
value: &Binder<T>,
|
value: &Binder<T>,
|
||||||
) -> FxHashSet<ty::BoundRegion>
|
) -> FxHashSet<ty::BoundRegion>
|
||||||
where
|
where
|
||||||
@ -655,7 +655,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
/// Returns a set of all late-bound regions that appear in `value` anywhere.
|
/// Returns a set of all late-bound regions that appear in `value` anywhere.
|
||||||
pub fn collect_referenced_late_bound_regions<T>(
|
pub fn collect_referenced_late_bound_regions<T>(
|
||||||
&self,
|
self,
|
||||||
value: &Binder<T>,
|
value: &Binder<T>,
|
||||||
) -> FxHashSet<ty::BoundRegion>
|
) -> FxHashSet<ty::BoundRegion>
|
||||||
where
|
where
|
||||||
@ -665,7 +665,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn collect_late_bound_regions<T>(
|
fn collect_late_bound_regions<T>(
|
||||||
&self,
|
self,
|
||||||
value: &Binder<T>,
|
value: &Binder<T>,
|
||||||
just_constraint: bool,
|
just_constraint: bool,
|
||||||
) -> FxHashSet<ty::BoundRegion>
|
) -> FxHashSet<ty::BoundRegion>
|
||||||
|
@ -170,9 +170,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
});
|
});
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
|
||||||
pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
|
pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
|
||||||
if let ty::Adt(def, substs) = *ty.kind() {
|
if let ty::Adt(def, substs) = *ty.kind() {
|
||||||
for field in def.all_fields() {
|
for field in def.all_fields() {
|
||||||
@ -526,22 +524,22 @@ 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.
|
||||||
pub fn is_static(&self, def_id: DefId) -> bool {
|
pub fn is_static(self, def_id: DefId) -> bool {
|
||||||
self.static_mutability(def_id).is_some()
|
self.static_mutability(def_id).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
pub fn is_thread_local_static(&self, def_id: DefId) -> bool {
|
pub fn is_thread_local_static(self, def_id: DefId) -> bool {
|
||||||
self.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
|
self.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the node pointed to by `def_id` is a mutable `static` item.
|
/// Returns `true` if the node pointed to by `def_id` is a mutable `static` item.
|
||||||
pub fn is_mutable_static(&self, def_id: DefId) -> bool {
|
pub fn is_mutable_static(self, def_id: DefId) -> bool {
|
||||||
self.static_mutability(def_id) == Some(hir::Mutability::Mut)
|
self.static_mutability(def_id) == Some(hir::Mutability::Mut)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the type of the pointer to the static that we use in MIR.
|
/// Get the type of the pointer to the static that we use in MIR.
|
||||||
pub fn static_ptr_ty(&self, def_id: DefId) -> Ty<'tcx> {
|
pub fn static_ptr_ty(self, def_id: DefId) -> Ty<'tcx> {
|
||||||
// Make sure that any constants in the static's type are evaluated.
|
// Make sure that any constants in the static's type are evaluated.
|
||||||
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id));
|
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user