Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 948cec0

Browse files
committed
move fn is_item_raw to TypingEnv
1 parent 89b6885 commit 948cec0

File tree

60 files changed

+181
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+181
-168
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17271727
// `Sized` bound in no way depends on precise regions, so this
17281728
// shouldn't affect `is_sized`.
17291729
let erased_ty = tcx.erase_regions(ty);
1730-
if !erased_ty.is_sized(tcx, self.infcx.param_env) {
1730+
// FIXME(#132279): Using `Ty::is_sized` causes us to incorrectly handle opaques here.
1731+
if !erased_ty.is_sized(tcx, self.infcx.typing_env(self.infcx.param_env)) {
17311732
// in current MIR construction, all non-control-flow rvalue
17321733
// expressions evaluate through `as_temp` or `into` a return
17331734
// slot or local, so to find all unsized rvalues it is enough

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1111
use rustc_middle::mir::InlineAsmMacro;
1212
use rustc_middle::ty::TypeVisitableExt;
1313
use rustc_middle::ty::adjustment::PointerCoercion;
14-
use rustc_middle::ty::layout::FnAbiOf;
14+
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
1616

1717
use crate::constant::ConstantCx;
@@ -841,7 +841,7 @@ fn codegen_stmt<'tcx>(
841841
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
842842
}
843843
Rvalue::NullaryOp(ref null_op, ty) => {
844-
assert!(lval.layout().ty.is_sized(fx.tcx, ty::ParamEnv::reveal_all()));
844+
assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env()));
845845
let layout = fx.layout_of(fx.monomorphize(ty));
846846
let val = match null_op {
847847
NullOp::SizeOf => layout.size.bytes(),

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn clif_pair_type_from_ty<'tcx>(
103103

104104
/// Is a pointer to this type a wide ptr?
105105
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
106-
if ty.is_sized(tcx, ty::ParamEnv::reveal_all()) {
106+
if ty.is_sized(tcx, ty::TypingEnv::fully_monomorphized()) {
107107
return false;
108108
}
109109

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
7878
}
7979

8080
fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
81-
ty.is_sized(self.tcx(), ty::ParamEnv::reveal_all())
81+
ty.is_sized(self.tcx(), self.typing_env())
8282
}
8383

8484
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
85-
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all())
85+
ty.is_freeze(self.tcx(), self.typing_env())
8686
}
8787

8888
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
89-
if ty.is_sized(self.tcx(), self.param_env()) {
89+
if ty.is_sized(self.tcx(), self.typing_env()) {
9090
return false;
9191
}
9292

compiler/rustc_const_eval/src/check_consts/resolver.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ where
120120
///
121121
/// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
122122
fn shared_borrow_allows_mutation(&self, place: mir::Place<'tcx>) -> bool {
123-
!place
124-
.ty(self.ccx.body, self.ccx.tcx)
125-
.ty
126-
.is_freeze(self.ccx.tcx, self.ccx.typing_env.param_env)
123+
!place.ty(self.ccx.body, self.ccx.tcx).ty.is_freeze(self.ccx.tcx, self.ccx.typing_env)
127124
}
128125
}
129126

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
667667
.is_some_and(|p| !p.immutable())
668668
{
669669
// That next check is expensive, that's why we have all the guards above.
670-
let is_immutable = ty.is_freeze(*ecx.tcx, ecx.param_env);
670+
let is_immutable = ty.is_freeze(*ecx.tcx, ecx.typing_env());
671671
let place = ecx.ref_to_mplace(val)?;
672672
let new_place = if is_immutable {
673673
place.map_provenance(CtfeProvenance::as_immutable)

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
250250

251251
#[inline]
252252
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
253-
ty.is_freeze(*self.tcx, self.param_env)
253+
ty.is_freeze(*self.tcx, self.typing_env())
254254
}
255255

256256
pub fn load_mir(

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx, const_eval
165165
InternKind::Static(Mutability::Not) => {
166166
(
167167
// Outermost allocation is mutable if `!Freeze`.
168-
if ret.layout.ty.is_freeze(*ecx.tcx, ecx.param_env) {
168+
if ret.layout.ty.is_freeze(*ecx.tcx, ecx.typing_env()) {
169169
Mutability::Not
170170
} else {
171171
Mutability::Mut

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
860860
// # Global allocations
861861
if let Some(global_alloc) = self.tcx.try_get_global_alloc(id) {
862862
let (size, align) = global_alloc.size_and_align(*self.tcx, self.typing_env());
863-
let mutbl = global_alloc.mutability(*self.tcx, self.param_env);
863+
let mutbl = global_alloc.mutability(*self.tcx, self.typing_env());
864864
let kind = match global_alloc {
865865
GlobalAlloc::Static { .. } | GlobalAlloc::Memory { .. } => AllocKind::LiveData,
866866
GlobalAlloc::Function { .. } => bug!("We already checked function pointers above"),

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
619619
};
620620
// Determine what it actually points to.
621621
let alloc_actual_mutbl =
622-
global_alloc.mutability(*self.ecx.tcx, self.ecx.param_env);
622+
global_alloc.mutability(*self.ecx.tcx, self.ecx.typing_env());
623623
// Mutable pointer to immutable memory is no good.
624624
if ptr_expected_mutbl == Mutability::Mut
625625
&& alloc_actual_mutbl == Mutability::Not
@@ -848,7 +848,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
848848
if let Some(alloc_id) = mplace.ptr().provenance.and_then(|p| p.get_alloc_id()) {
849849
let tcx = *self.ecx.tcx;
850850
// Everything must be already interned.
851-
let mutbl = tcx.global_alloc(alloc_id).mutability(tcx, self.ecx.param_env);
851+
let mutbl = tcx.global_alloc(alloc_id).mutability(tcx, self.ecx.typing_env());
852852
if let Some((_, alloc)) = self.ecx.memory.alloc_map.get(alloc_id) {
853853
assert_eq!(alloc.mutability, mutbl);
854854
}
@@ -1085,7 +1085,9 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
10851085
) -> InterpResult<'tcx> {
10861086
// Special check for CTFE validation, preventing `UnsafeCell` inside unions in immutable memory.
10871087
if self.ctfe_mode.is_some_and(|c| !c.allow_immutable_unsafe_cell()) {
1088-
if !val.layout.is_zst() && !val.layout.ty.is_freeze(*self.ecx.tcx, self.ecx.param_env) {
1088+
if !val.layout.is_zst()
1089+
&& !val.layout.ty.is_freeze(*self.ecx.tcx, self.ecx.typing_env())
1090+
{
10891091
if !self.in_mutable_memory(val) {
10901092
throw_validation_failure!(self.path, UnsafeCellInImmutable);
10911093
}

0 commit comments

Comments
 (0)