1
Fork 0

Rollup merge of #134285 - oli-obk:push-vwrqsqlwnuxo, r=Urgau

Add some convenience helper methods on `hir::Safety`

Makes a lot of call sites simpler and should make any refactorings needed for https://github.com/rust-lang/rust/pull/134090#issuecomment-2541332415 simpler, as fewer sites have to be touched in case we end up storing some information in the variants of `hir::Safety`
This commit is contained in:
Stuart Cook 2024-12-15 20:01:38 +11:00 committed by GitHub
commit d48af09ffd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 74 additions and 70 deletions

View file

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

View file

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

View file

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