Skip to content

Commit 2414a4c

Browse files
Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors
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` This allows to remove a lot of useless `.at(DUMMY_SP)`, making the code a bit nicer :3 r? `@compiler-errors`
2 parents 692a22e + c8c4971 commit 2414a4c

File tree

45 files changed

+191
-172
lines changed

Some content is hidden

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

45 files changed

+191
-172
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

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

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,7 @@ fn codegen_stmt<'tcx>(
770770
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
771771
}
772772
Rvalue::NullaryOp(null_op, ty) => {
773-
assert!(
774-
lval.layout()
775-
.ty
776-
.is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all())
777-
);
773+
assert!(lval.layout().ty.is_sized(fx.tcx, ParamEnv::reveal_all()));
778774
let layout = fx.layout_of(fx.monomorphize(ty));
779775
let val = match null_op {
780776
NullOp::SizeOf => layout.size.bytes(),

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
55
use rustc_middle::mir::interpret::{
66
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
77
};
8-
use rustc_span::DUMMY_SP;
98

109
use cranelift_module::*;
1110

@@ -291,7 +290,7 @@ fn data_id_for_static(
291290
let is_mutable = if tcx.is_mutable_static(def_id) {
292291
true
293292
} else {
294-
!ty.is_freeze(tcx.at(DUMMY_SP), ParamEnv::reveal_all())
293+
!ty.is_freeze(tcx, ParamEnv::reveal_all())
295294
};
296295
let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes();
297296

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

0 commit comments

Comments
 (0)