Add some convenience helper methods on hir::Safety
This commit is contained in:
parent
3a64bef2ba
commit
8a4e5d7444
27 changed files with 72 additions and 68 deletions
|
@ -586,7 +586,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
fn trait_is_unsafe(self, trait_def_id: Self::DefId) -> bool {
|
||||
self.trait_def(trait_def_id).safety == hir::Safety::Unsafe
|
||||
self.trait_def(trait_def_id).safety.is_unsafe()
|
||||
}
|
||||
|
||||
fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
|
||||
|
@ -722,7 +722,7 @@ impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
|
|||
}
|
||||
|
||||
fn is_safe(self) -> bool {
|
||||
matches!(self, hir::Safety::Safe)
|
||||
self.is_safe()
|
||||
}
|
||||
|
||||
fn prefix_str(self) -> &'static str {
|
||||
|
@ -2521,7 +2521,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// that is, a `fn` type that is equivalent in every way for being
|
||||
/// unsafe.
|
||||
pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
|
||||
assert_eq!(sig.safety(), hir::Safety::Safe);
|
||||
assert!(sig.safety().is_safe());
|
||||
Ty::new_fn_ptr(self, sig.map_bound(|sig| ty::FnSig { safety: hir::Safety::Unsafe, ..sig }))
|
||||
}
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ use rustc_data_structures::intern::Interned;
|
|||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_errors::{Diag, ErrorGuaranteed, StashKey};
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::{LangItem, Safety};
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_macros::{
|
||||
Decodable, Encodable, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable,
|
||||
|
@ -1279,7 +1279,7 @@ impl VariantDef {
|
|||
|
||||
/// Returns whether this variant has unsafe fields.
|
||||
pub fn has_unsafe_fields(&self) -> bool {
|
||||
self.fields.iter().any(|x| x.safety == Safety::Unsafe)
|
||||
self.fields.iter().any(|x| x.safety.is_unsafe())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1291,7 +1291,7 @@ impl<'tcx> Ty<'tcx> {
|
|||
/// Checks whether this type is an ADT that has unsafe fields.
|
||||
pub fn has_unsafe_fields(self) -> bool {
|
||||
if let ty::Adt(adt_def, ..) = self.kind() {
|
||||
adt_def.all_fields().any(|x| x.safety == hir::Safety::Unsafe)
|
||||
adt_def.all_fields().any(|x| x.safety.is_unsafe())
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue