Skip to content

Commit cd7cc60

Browse files
authored
Rollup merge of rust-lang#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 fd4558e + 1c74ab4 commit cd7cc60

File tree

23 files changed

+32
-40
lines changed

23 files changed

+32
-40
lines changed

src/librustc_codegen_ssa/traits/type_.rs

+1-1
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

+1-1
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

+1-1
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

+4-10
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+6-7
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",

src/librustc_mir/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'tcx> Validator<'_, 'tcx> {
341341
Place::ty_from(place.local, proj_base, self.body, self.tcx)
342342
.projection_ty(self.tcx, elem)
343343
.ty;
344-
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
344+
if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
345345
has_mut_interior = false;
346346
break;
347347
}
@@ -678,7 +678,7 @@ impl<'tcx> Validator<'_, 'tcx> {
678678
let ty = Place::ty_from(place.local, proj_base, self.body, self.tcx)
679679
.projection_ty(self.tcx, elem)
680680
.ty;
681-
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
681+
if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
682682
has_mut_interior = false;
683683
break;
684684
}

src/librustc_mir/transform/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
9090
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
9191
let span = self.body.source_info(location).span;
9292

93-
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, span) {
93+
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
9494
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
9595
}
9696
}

src/librustc_mir_build/build/expr/as_operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
172172

173173
if !ty.is_sized(tcx.at(span), param_env) {
174174
// !sized means !copy, so this is an unsized move
175-
assert!(!ty.is_copy_modulo_regions(tcx, param_env, span));
175+
assert!(!ty.is_copy_modulo_regions(tcx.at(span), param_env));
176176

177177
// As described above, detect the case where we are passing a value of unsized
178178
// type, and that value is coming from the deref of a box.

src/librustc_mir_build/hair/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[super::Pat<'_>]) -> Vec<Span>
579579

580580
/// Check if a by-value binding is by-value. That is, check if the binding's type is not `Copy`.
581581
fn is_binding_by_move(cx: &MatchVisitor<'_, '_>, hir_id: HirId, span: Span) -> bool {
582-
!cx.tables.node_type(hir_id).is_copy_modulo_regions(cx.tcx, cx.param_env, span)
582+
!cx.tables.node_type(hir_id).is_copy_modulo_regions(cx.tcx.at(span), cx.param_env)
583583
}
584584

585585
/// Check the legality of legality of by-move bindings.

src/librustc_passes/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl ExprVisitor<'tcx> {
214214

215215
// Check that the type implements Copy. The only case where this can
216216
// possibly fail is for SIMD types which don't #[derive(Copy)].
217-
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) {
217+
if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
218218
let msg = "arguments for inline assembly must be copyable";
219219
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
220220
err.note(&format!("`{}` does not implement the Copy trait", ty));

src/librustc_trait_selection/infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
4444
let ty = self.resolve_vars_if_possible(&ty);
4545

4646
if !(param_env, ty).needs_infer() {
47-
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
47+
return ty.is_copy_modulo_regions(self.tcx.at(span), param_env);
4848
}
4949

5050
let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem, None);

src/librustc_ty/needs_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ where
9191

9292
for component in components {
9393
match component.kind {
94-
_ if component.is_copy_modulo_regions(tcx, self.param_env, DUMMY_SP) => (),
94+
_ if component.is_copy_modulo_regions(tcx.at(DUMMY_SP), self.param_env) => (),
9595

9696
ty::Closure(_, substs) => {
9797
for upvar_ty in substs.as_closure().upvar_tys() {

src/tools/clippy/clippy_lints/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
513513
// primitive types are never mutable
514514
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
515515
ty::Adt(ref adt, ref substs) => {
516-
tys.insert(adt.did) && !ty.is_freeze(cx.tcx, cx.param_env, span)
516+
tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env)
517517
|| KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
518518
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
519519
},

src/tools/clippy/clippy_lints/src/let_if_seq.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
7474
let span = stmt.span.to(if_.span);
7575

7676
let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze(
77-
cx.tcx,
77+
cx.tcx.at(span),
7878
cx.param_env,
79-
span
8079
);
8180
if has_interior_mutability { return; }
8281

src/tools/clippy/clippy_lints/src/mut_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn is_mutable_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Spa
118118
size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_mutable_type(cx, inner_ty, span)
119119
},
120120
Tuple(..) => ty.tuple_fields().any(|ty| is_mutable_type(cx, ty, span)),
121-
Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx, cx.param_env, span),
121+
Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(span), cx.param_env),
122122
_ => false,
123123
}
124124
}

src/tools/clippy/clippy_lints/src/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Source {
110110
}
111111

112112
fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: Source) {
113-
if ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP) || is_copy(cx, ty) {
113+
if ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env) || is_copy(cx, ty) {
114114
// An `UnsafeCell` is `!Copy`, and an `UnsafeCell` is also the only type which
115115
// is `!Freeze`, thus if our type is `Copy` we can be sure it must be `Freeze`
116116
// as well.

src/tools/clippy/clippy_lints/src/question_mark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl QuestionMark {
137137
fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {
138138
let expr_ty = cx.tables.expr_ty(expression);
139139

140-
!expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span)
140+
!expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env)
141141
}
142142

143143
fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {

src/tools/clippy/clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ pub fn type_is_unsafe_function<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx
891891
}
892892

893893
pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
894-
ty.is_copy_modulo_regions(cx.tcx, cx.param_env, DUMMY_SP)
894+
ty.is_copy_modulo_regions(cx.tcx.at(DUMMY_SP), cx.param_env)
895895
}
896896

897897
/// Checks if an expression is constructing a tuple-like enum variant or struct

0 commit comments

Comments
 (0)