Skip to content

Commit 8e89184

Browse files
committed
rename type_moves_by_default to type_is_copy_modulo_regions
1 parent 4c8fd2e commit 8e89184

File tree

15 files changed

+55
-46
lines changed

15 files changed

+55
-46
lines changed

src/librustc/infer/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1400,18 +1400,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14001400
.verify_generic_bound(origin, kind, a, bound);
14011401
}
14021402

1403-
pub fn type_moves_by_default(
1403+
pub fn type_is_copy_modulo_regions(
14041404
&self,
14051405
param_env: ty::ParamEnv<'tcx>,
14061406
ty: Ty<'tcx>,
14071407
span: Span,
14081408
) -> bool {
14091409
let ty = self.resolve_type_vars_if_possible(&ty);
1410+
14101411
// Even if the type may have no inference variables, during
14111412
// type-checking closure types are in local tables only.
14121413
if !self.in_progress_tables.is_some() || !ty.has_closure_types() {
14131414
if let Some((param_env, ty)) = self.tcx.lift_to_global(&(param_env, ty)) {
1414-
return ty.moves_by_default(self.tcx.global_tcx(), param_env, span);
1415+
return ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span);
14151416
}
14161417
}
14171418

@@ -1421,7 +1422,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14211422
// rightly refuses to work with inference variables, but
14221423
// moves_by_default has a cache, which we want to use in other
14231424
// cases.
1424-
!traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id, span)
1425+
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id, span)
14251426
}
14261427

14271428
/// Obtains the latest type of the given closure; this may be a

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ fn copy_or_move<'a, 'gcx, 'tcx>(mc: &mc::MemCategorizationContext<'a, 'gcx, 'tcx
976976
move_reason: MoveReason)
977977
-> ConsumeMode
978978
{
979-
if mc.type_moves_by_default(param_env, cmt.ty, cmt.span) {
979+
if !mc.type_is_copy_modulo_regions(param_env, cmt.ty, cmt.span) {
980980
Move(move_reason)
981981
} else {
982982
Copy

src/librustc/middle/mem_categorization.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
443443
}
444444
}
445445

446-
pub fn type_moves_by_default(&self,
447-
param_env: ty::ParamEnv<'tcx>,
448-
ty: Ty<'tcx>,
449-
span: Span)
450-
-> bool {
451-
self.infcx.map(|infcx| infcx.type_moves_by_default(param_env, ty, span))
446+
pub fn type_is_copy_modulo_regions(
447+
&self,
448+
param_env: ty::ParamEnv<'tcx>,
449+
ty: Ty<'tcx>,
450+
span: Span,
451+
) -> bool {
452+
self.infcx.map(|infcx| infcx.type_is_copy_modulo_regions(param_env, ty, span))
452453
.or_else(|| {
453454
self.tcx.lift_to_global(&(param_env, ty)).map(|(param_env, ty)| {
454-
ty.moves_by_default(self.tcx.global_tcx(), param_env, span)
455+
ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span)
455456
})
456457
})
457458
.unwrap_or(true)

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ define_queries! { <'tcx>
382382
/// might want to use `reveal_all()` method to change modes.
383383
[] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
384384

385-
/// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
385+
/// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
386386
/// `ty.is_copy()`, etc, since that will prune the environment where possible.
387387
[] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
388388
[] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,

src/librustc/ty/util.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'tcx> ty::ParamEnv<'tcx> {
203203
let cause = ObligationCause { span, ..ObligationCause::dummy() };
204204
let ctx = traits::FulfillmentContext::new();
205205
match traits::fully_normalize(&infcx, ctx, cause, self, &ty) {
206-
Ok(ty) => if infcx.type_moves_by_default(self, ty, span) {
206+
Ok(ty) => if !infcx.type_is_copy_modulo_regions(self, ty, span) {
207207
infringing.push(field);
208208
}
209209
Err(errors) => {
@@ -628,12 +628,12 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
628628
/// does copies even when the type actually doesn't satisfy the
629629
/// full requirements for the `Copy` trait (cc #29149) -- this
630630
/// winds up being reported as an error during NLL borrow check.
631-
pub fn moves_by_default(&'tcx self,
632-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
633-
param_env: ty::ParamEnv<'tcx>,
634-
span: Span)
635-
-> bool {
636-
!tcx.at(span).is_copy_raw(param_env.and(self))
631+
pub fn is_copy_modulo_regions(&'tcx self,
632+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
633+
param_env: ty::ParamEnv<'tcx>,
634+
span: Span)
635+
-> bool {
636+
tcx.at(span).is_copy_raw(param_env.and(self))
637637
}
638638

639639
/// Checks whether values of this type `T` have a size known at
@@ -947,11 +947,11 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
947947
// `ManuallyDrop` doesn't have a destructor regardless of field types.
948948
ty::Adt(def, _) if Some(def.did) == tcx.lang_items().manually_drop() => false,
949949

950-
// Issue #22536: We first query type_moves_by_default. It sees a
950+
// Issue #22536: We first query `is_copy_modulo_regions`. It sees a
951951
// normalized version of the type, and therefore will definitely
952952
// know whether the type implements Copy (and thus needs no
953953
// cleanup/drop/zeroing) ...
954-
_ if !ty.moves_by_default(tcx, param_env, DUMMY_SP) => false,
954+
_ if ty.is_copy_modulo_regions(tcx, param_env, DUMMY_SP) => false,
955955

956956
// ... (issue #22536 continued) but as an optimization, still use
957957
// prior logic of asking for the structural "may drop".

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
540540
return;
541541
}
542542
let param_env = ty::ParamEnv::empty();
543-
if !ty.moves_by_default(cx.tcx, param_env, item.span) {
543+
if ty.is_copy_modulo_regions(cx.tcx, param_env, item.span) {
544544
return;
545545
}
546546
if param_env.can_type_implement_copy(cx.tcx, ty).is_ok() {

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,17 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
503503
substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
504504
};
505505

506-
// In order to have a Copy operand, the type T of the value must be Copy. Note that we
507-
// prove that T: Copy, rather than using the type_moves_by_default test. This is
508-
// important because type_moves_by_default ignores the resulting region obligations and
509-
// assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
510-
// (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
511-
// fully apply: in effect, the rule is that if a value of some type could implement
512-
// Copy, then it must.
506+
// In order to have a Copy operand, the type T of the
507+
// value must be Copy. Note that we prove that T: Copy,
508+
// rather than using the `is_copy_modulo_regions`
509+
// test. This is important because
510+
// `is_copy_modulo_regions` ignores the resulting region
511+
// obligations and assumes they pass. This can result in
512+
// bounds from Copy impls being unsoundly ignored (e.g.,
513+
// #29149). Note that we decide to use Copy before knowing
514+
// whether the bounds fully apply: in effect, the rule is
515+
// that if a value of some type could implement Copy, then
516+
// it must.
513517
self.cx.prove_trait_ref(
514518
trait_ref,
515519
location.to_locations(),

src/librustc_mir/build/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
7171
pub fn consume_by_copy_or_move(&self, place: Place<'tcx>) -> Operand<'tcx> {
7272
let tcx = self.hir.tcx();
7373
let ty = place.ty(&self.local_decls, tcx).to_ty(tcx);
74-
if self.hir.type_moves_by_default(ty, DUMMY_SP) {
74+
if !self.hir.type_is_copy_modulo_regions(ty, DUMMY_SP) {
7575
Operand::Move(place)
7676
} else {
7777
Operand::Copy(place)

src/librustc_mir/hair/cx/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
223223
self.check_overflow
224224
}
225225

226-
pub fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
227-
self.infcx.type_moves_by_default(self.param_env, ty, span)
226+
pub fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>, span: Span) -> bool {
227+
self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span)
228228
}
229229
}
230230

src/librustc_mir/hair/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
545545
match bm {
546546
ty::BindByValue(..) => {
547547
let pat_ty = cx.tables.node_id_to_type(p.hir_id);
548-
if pat_ty.moves_by_default(cx.tcx, cx.param_env, pat.span) {
548+
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
549549
check_move(p, sub.as_ref().map(|p| &**p), span_vec);
550550
}
551551
}

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
310310
debug!("build_clone_shim(def_id={:?})", def_id);
311311

312312
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
313-
let is_copy = !self_ty.moves_by_default(tcx, tcx.param_env(def_id), builder.span);
313+
let is_copy = self_ty.is_copy_modulo_regions(tcx, tcx.param_env(def_id), builder.span);
314314

315315
let dest = Place::Local(RETURN_PLACE);
316316
let src = Place::Local(Local::new(1+0)).deref();

src/librustc_mir/transform/check_unsafety.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
224224
"non-field projection {:?} from union?",
225225
place)
226226
};
227-
if elem_ty.moves_by_default(self.tcx, self.param_env,
228-
self.source_info.span) {
227+
if !elem_ty.is_copy_modulo_regions(
228+
self.tcx,
229+
self.param_env,
230+
self.source_info.span,
231+
) {
229232
self.require_unsafe(
230233
"assignment to non-`Copy` union field",
231234
"the previous content of the field will be dropped, which \

src/librustc_typeck/check/demand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
353353

354354
// Maybe add `*`? Only if `T: Copy`.
355355
_ => {
356-
if !self.infcx.type_moves_by_default(self.param_env,
357-
checked,
358-
sp) {
356+
if self.infcx.type_is_copy_modulo_regions(self.param_env,
357+
checked,
358+
sp) {
359359
// do not suggest if the span comes from a macro (#52783)
360360
if let (Ok(code),
361361
true) = (cm.span_to_snippet(sp), sp == expr.span) {

src/librustc_typeck/check/op.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
262262
let mut suggested_deref = false;
263263
if let Ref(_, mut rty, _) = lhs_ty.sty {
264264
if {
265-
!self.infcx.type_moves_by_default(self.param_env,
266-
rty,
267-
lhs_expr.span) &&
265+
self.infcx.type_is_copy_modulo_regions(self.param_env,
266+
rty,
267+
lhs_expr.span) &&
268268
self.lookup_op_method(rty,
269269
&[rhs_ty],
270270
Op::Binary(op, is_assign))
@@ -334,9 +334,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
334334
let mut suggested_deref = false;
335335
if let Ref(_, mut rty, _) = lhs_ty.sty {
336336
if {
337-
!self.infcx.type_moves_by_default(self.param_env,
338-
rty,
339-
lhs_expr.span) &&
337+
self.infcx.type_is_copy_modulo_regions(self.param_env,
338+
rty,
339+
lhs_expr.span) &&
340340
self.lookup_op_method(rty,
341341
&[rhs_ty],
342342
Op::Binary(op, is_assign))

src/test/ui/coherence/coherence-subtyping.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
77
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
99
|
10-
= note: this behavior recently changed as a result of a bug fix; see #XXX for details
10+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)