Skip to content

Commit 963a480

Browse files
authored
Rollup merge of #73578 - RalfJung:ty-ctxt-at, r=jonas-schievink
Make is_freeze and is_copy_modulo_regions take TyCtxtAt Make is_freeze and is_copy_modulo_regions take TyCtxtAt instead of separately taking TyCtxt and Span. This is consistent with is_sized.
2 parents 4dfae77 + 1c74ab4 commit 963a480

File tree

23 files changed

+32
-40
lines changed

23 files changed

+32
-40
lines changed

src/librustc_codegen_ssa/traits/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
7474
}
7575

7676
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
77-
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SP)
77+
ty.is_freeze(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
7878
}
7979

8080
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
562562
return;
563563
}
564564
let param_env = ty::ParamEnv::empty();
565-
if ty.is_copy_modulo_regions(cx.tcx, param_env, item.span) {
565+
if ty.is_copy_modulo_regions(cx.tcx.at(item.span), param_env) {
566566
return;
567567
}
568568
if can_type_implement_copy(cx.tcx, param_env, ty).is_ok() {

src/librustc_middle/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ where
21592159

21602160
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
21612161
let tcx = cx.tcx();
2162-
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
2162+
let is_freeze = ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env());
21632163
let kind = match mt {
21642164
hir::Mutability::Not => {
21652165
if is_freeze {

src/librustc_middle/ty/util.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,10 @@ impl<'tcx> ty::TyS<'tcx> {
681681
/// winds up being reported as an error during NLL borrow check.
682682
pub fn is_copy_modulo_regions(
683683
&'tcx self,
684-
tcx: TyCtxt<'tcx>,
684+
tcx_at: TyCtxtAt<'tcx>,
685685
param_env: ty::ParamEnv<'tcx>,
686-
span: Span,
687686
) -> bool {
688-
tcx.at(span).is_copy_raw(param_env.and(self))
687+
tcx_at.is_copy_raw(param_env.and(self))
689688
}
690689

691690
/// Checks whether values of this type `T` have a size known at
@@ -706,13 +705,8 @@ impl<'tcx> ty::TyS<'tcx> {
706705
/// that the `Freeze` trait is not exposed to end users and is
707706
/// effectively an implementation detail.
708707
// FIXME: use `TyCtxtAt` instead of separate `Span`.
709-
pub fn is_freeze(
710-
&'tcx self,
711-
tcx: TyCtxt<'tcx>,
712-
param_env: ty::ParamEnv<'tcx>,
713-
span: Span,
714-
) -> bool {
715-
self.is_trivially_freeze() || tcx.at(span).is_freeze_raw(param_env.and(self))
708+
pub fn is_freeze(&'tcx self, tcx_at: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
709+
self.is_trivially_freeze() || tcx_at.is_freeze_raw(param_env.and(self))
716710
}
717711

718712
/// Fast path helper for testing if a type is `Freeze`.

src/librustc_mir/dataflow/impls/borrowed_locals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl MutBorrow<'mir, 'tcx> {
233233
///
234234
/// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
235235
fn shared_borrow_allows_mutation(&self, place: Place<'tcx>) -> bool {
236-
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx, self.param_env, DUMMY_SP)
236+
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env)
237237
}
238238
}
239239

src/librustc_mir/interpret/eval_context.rs

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

392392
#[inline]
393393
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
394-
ty.is_freeze(*self.tcx, self.param_env, self.tcx.span)
394+
ty.is_freeze(self.tcx, self.param_env)
395395
}
396396

397397
pub fn load_mir(

src/librustc_mir/interpret/intern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
111111
if let InternMode::Static(mutability) = mode {
112112
// For this, we need to take into account `UnsafeCell`. When `ty` is `None`, we assume
113113
// no interior mutability.
114-
let frozen = ty.map_or(true, |ty| ty.is_freeze(*ecx.tcx, ecx.param_env, ecx.tcx.span));
114+
let frozen = ty.map_or(true, |ty| ty.is_freeze(ecx.tcx, ecx.param_env));
115115
// For statics, allocation mutability is the combination of the place mutability and
116116
// the type mutability.
117117
// The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.

src/librustc_mir/shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
327327
let param_env = tcx.param_env(def_id);
328328

329329
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
330-
let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env, builder.span);
330+
let is_copy = self_ty.is_copy_modulo_regions(tcx.at(builder.span), param_env);
331331

332332
let dest = Place::return_place();
333333
let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0)));

src/librustc_mir/transform/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Qualif for HasMutInterior {
7777
}
7878

7979
fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
80-
!ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP)
80+
!ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env)
8181
}
8282

8383
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
282282
),
283283
};
284284
if !elem_ty.is_copy_modulo_regions(
285-
self.tcx,
285+
self.tcx.at(self.source_info.span),
286286
self.param_env,
287-
self.source_info.span,
288287
) {
289288
self.require_unsafe(
290289
"assignment to non-`Copy` union field",
@@ -459,11 +458,11 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
459458

460459
// Check `is_freeze` as late as possible to avoid cycle errors
461460
// with opaque types.
462-
} else if !place.ty(self.body, self.tcx).ty.is_freeze(
463-
self.tcx,
464-
self.param_env,
465-
self.source_info.span,
466-
) {
461+
} else if !place
462+
.ty(self.body, self.tcx)
463+
.ty
464+
.is_freeze(self.tcx.at(self.source_info.span), self.param_env)
465+
{
467466
(
468467
"borrow of layout constrained field with interior \
469468
mutability",

0 commit comments

Comments
 (0)