Skip to content

Commit a17ccfa

Browse files
committed
Accept TyCtxt instead of TyCtxtAt in Ty::is_* functions
Functions in answer: - `Ty::is_freeze` - `Ty::is_sized` - `Ty::is_unpin` - `Ty::is_copy_modulo_regions`
1 parent 44fcfb0 commit a17ccfa

File tree

29 files changed

+51
-69
lines changed

29 files changed

+51
-69
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17761776
// `Sized` bound in no way depends on precise regions, so this
17771777
// shouldn't affect `is_sized`.
17781778
let erased_ty = tcx.erase_regions(ty);
1779-
if !erased_ty.is_sized(tcx.at(span), self.param_env) {
1779+
if !erased_ty.is_sized(tcx, self.param_env) {
17801780
// in current MIR construction, all non-control-flow rvalue
17811781
// expressions evaluate through `as_temp` or `into` a return
17821782
// slot or local, so to find all unsized rvalues it is enough

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::common::TypeKind;
55
use crate::mir::place::PlaceRef;
66
use rustc_middle::ty::layout::TyAndLayout;
77
use rustc_middle::ty::{self, Ty};
8-
use rustc_span::DUMMY_SP;
98
use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg};
109
use rustc_target::abi::{AddressSpace, Integer};
1110

@@ -75,16 +74,16 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
7574
}
7675

7776
fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
78-
ty.is_sized(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
77+
ty.is_sized(self.tcx(), ty::ParamEnv::reveal_all())
7978
}
8079

8180
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
82-
ty.is_freeze(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
81+
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all())
8382
}
8483

8584
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
8685
let param_env = ty::ParamEnv::reveal_all();
87-
if ty.is_sized(self.tcx().at(DUMMY_SP), param_env) {
86+
if ty.is_sized(self.tcx(), param_env) {
8887
return false;
8988
}
9089

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn create_pointee_place<'tcx>(
212212
) -> MPlaceTy<'tcx> {
213213
let tcx = ecx.tcx.tcx;
214214

215-
if !ty.is_sized(ecx.tcx, ty::ParamEnv::empty()) {
215+
if !ty.is_sized(*ecx.tcx, ty::ParamEnv::empty()) {
216216
// We need to create `Allocation`s for custom DSTs
217217

218218
let (unsized_inner_ty, num_elems) = get_info_on_unsized_field(ty, valtree, tcx);
@@ -398,7 +398,7 @@ fn valtree_into_mplace<'tcx>(
398398

399399
let mut place_inner = match ty.kind() {
400400
ty::Str | ty::Slice(_) => ecx.mplace_index(&place, i as u64).unwrap(),
401-
_ if !ty.is_sized(ecx.tcx, ty::ParamEnv::empty())
401+
_ if !ty.is_sized(*ecx.tcx, ty::ParamEnv::empty())
402402
&& i == branches.len() - 1 =>
403403
{
404404
// Note: For custom DSTs we need to manually process the last unsized field.

compiler/rustc_const_eval/src/interpret/eval_context.rs

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

469469
#[inline]
470470
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
471-
ty.is_freeze(self.tcx, self.param_env)
471+
ty.is_freeze(*self.tcx, self.param_env)
472472
}
473473

474474
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
@@ -114,7 +114,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
114114
if let InternMode::Static(mutability) = mode {
115115
// For this, we need to take into account `UnsafeCell`. When `ty` is `None`, we assume
116116
// no interior mutability.
117-
let frozen = ty.map_or(true, |ty| ty.is_freeze(ecx.tcx, ecx.param_env));
117+
let frozen = ty.map_or(true, |ty| ty.is_freeze(*ecx.tcx, ecx.param_env));
118118
// For statics, allocation mutability is the combination of place mutability and
119119
// type mutability.
120120
// The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::mir::interpret::InterpError;
1515
use rustc_middle::ty;
1616
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1717
use rustc_span::symbol::{sym, Symbol};
18-
use rustc_span::DUMMY_SP;
1918
use rustc_target::abi::{Abi, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange};
2019

2120
use std::hash::Hash;
@@ -726,7 +725,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
726725
) -> InterpResult<'tcx> {
727726
// Special check preventing `UnsafeCell` inside unions in the inner part of constants.
728727
if matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { inner: true, .. })) {
729-
if !op.layout.ty.is_freeze(self.ecx.tcx.at(DUMMY_SP), self.ecx.param_env) {
728+
if !op.layout.ty.is_freeze(*self.ecx.tcx, self.ecx.param_env) {
730729
throw_validation_failure!(self.path, { "`UnsafeCell` in a `const`" });
731730
}
732731
}

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_infer::infer::TyCtxtInferExt;
88
use rustc_middle::mir;
99
use rustc_middle::mir::*;
1010
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
11-
use rustc_span::DUMMY_SP;
1211
use rustc_trait_selection::traits::{
1312
self, ImplSource, Obligation, ObligationCause, SelectionContext,
1413
};
@@ -92,7 +91,7 @@ impl Qualif for HasMutInterior {
9291
}
9392

9493
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
95-
!ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env)
94+
!ty.is_freeze(cx.tcx, cx.param_env)
9695
}
9796

9897
fn in_adt_inherently<'tcx>(

compiler/rustc_const_eval/src/transform/check_consts/resolver.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_middle::mir::{self, BasicBlock, Local, Location, Statement, StatementK
88
use rustc_mir_dataflow::fmt::DebugWithContext;
99
use rustc_mir_dataflow::JoinSemiLattice;
1010
use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces};
11-
use rustc_span::DUMMY_SP;
1211

1312
use std::fmt;
1413
use std::marker::PhantomData;
@@ -120,10 +119,7 @@ where
120119
///
121120
/// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
122121
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.at(DUMMY_SP), self.ccx.param_env)
122+
!place.ty(self.ccx.body, self.ccx.tcx).ty.is_freeze(self.ccx.tcx, self.ccx.param_env)
127123
}
128124
}
129125

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
235235
// `Operand::Copy` is only supposed to be used with `Copy` types.
236236
if let Operand::Copy(place) = operand {
237237
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
238-
let span = self.body.source_info(location).span;
239238

240-
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
239+
if !ty.is_copy_modulo_regions(self.tcx, self.param_env) {
241240
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
242241
}
243242
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
114114
_ => {
115115
// Fallback case: allow `ManuallyDrop` and things that are `Copy`.
116116
ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop())
117-
|| ty.is_copy_modulo_regions(tcx.at(span), param_env)
117+
|| ty.is_copy_modulo_regions(tcx, param_env)
118118
}
119119
}
120120
}

0 commit comments

Comments
 (0)