提交 8e89184a 编写于 作者: N Niko Matsakis

rename `type_moves_by_default` to `type_is_copy_modulo_regions`

上级 4c8fd2e8
......@@ -1400,18 +1400,19 @@ pub fn verify_generic_bound(
.verify_generic_bound(origin, kind, a, bound);
}
pub fn type_moves_by_default(
pub fn type_is_copy_modulo_regions(
&self,
param_env: ty::ParamEnv<'tcx>,
ty: Ty<'tcx>,
span: Span,
) -> bool {
let ty = self.resolve_type_vars_if_possible(&ty);
// Even if the type may have no inference variables, during
// type-checking closure types are in local tables only.
if !self.in_progress_tables.is_some() || !ty.has_closure_types() {
if let Some((param_env, ty)) = self.tcx.lift_to_global(&(param_env, ty)) {
return ty.moves_by_default(self.tcx.global_tcx(), param_env, span);
return ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span);
}
}
......@@ -1421,7 +1422,7 @@ pub fn type_moves_by_default(
// rightly refuses to work with inference variables, but
// moves_by_default has a cache, which we want to use in other
// cases.
!traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id, span)
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id, span)
}
/// Obtains the latest type of the given closure; this may be a
......
......@@ -976,7 +976,7 @@ fn copy_or_move<'a, 'gcx, 'tcx>(mc: &mc::MemCategorizationContext<'a, 'gcx, 'tcx
move_reason: MoveReason)
-> ConsumeMode
{
if mc.type_moves_by_default(param_env, cmt.ty, cmt.span) {
if !mc.type_is_copy_modulo_regions(param_env, cmt.ty, cmt.span) {
Move(move_reason)
} else {
Copy
......
......@@ -443,15 +443,16 @@ pub fn with_infer(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
}
}
pub fn type_moves_by_default(&self,
pub fn type_is_copy_modulo_regions(
&self,
param_env: ty::ParamEnv<'tcx>,
ty: Ty<'tcx>,
span: Span)
-> bool {
self.infcx.map(|infcx| infcx.type_moves_by_default(param_env, ty, span))
span: Span,
) -> bool {
self.infcx.map(|infcx| infcx.type_is_copy_modulo_regions(param_env, ty, span))
.or_else(|| {
self.tcx.lift_to_global(&(param_env, ty)).map(|(param_env, ty)| {
ty.moves_by_default(self.tcx.global_tcx(), param_env, span)
ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span)
})
})
.unwrap_or(true)
......
......@@ -382,7 +382,7 @@
/// might want to use `reveal_all()` method to change modes.
[] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
/// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
/// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
/// `ty.is_copy()`, etc, since that will prune the environment where possible.
[] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
[] fn is_sized_raw: is_sized_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
......
......@@ -203,7 +203,7 @@ pub fn can_type_implement_copy<'a>(self,
let cause = ObligationCause { span, ..ObligationCause::dummy() };
let ctx = traits::FulfillmentContext::new();
match traits::fully_normalize(&infcx, ctx, cause, self, &ty) {
Ok(ty) => if infcx.type_moves_by_default(self, ty, span) {
Ok(ty) => if !infcx.type_is_copy_modulo_regions(self, ty, span) {
infringing.push(field);
}
Err(errors) => {
......@@ -628,12 +628,12 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
/// does copies even when the type actually doesn't satisfy the
/// full requirements for the `Copy` trait (cc #29149) -- this
/// winds up being reported as an error during NLL borrow check.
pub fn moves_by_default(&'tcx self,
pub fn is_copy_modulo_regions(&'tcx self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
span: Span)
-> bool {
!tcx.at(span).is_copy_raw(param_env.and(self))
tcx.at(span).is_copy_raw(param_env.and(self))
}
/// 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>,
// `ManuallyDrop` doesn't have a destructor regardless of field types.
ty::Adt(def, _) if Some(def.did) == tcx.lang_items().manually_drop() => false,
// Issue #22536: We first query type_moves_by_default. It sees a
// Issue #22536: We first query `is_copy_modulo_regions`. It sees a
// normalized version of the type, and therefore will definitely
// know whether the type implements Copy (and thus needs no
// cleanup/drop/zeroing) ...
_ if !ty.moves_by_default(tcx, param_env, DUMMY_SP) => false,
_ if ty.is_copy_modulo_regions(tcx, param_env, DUMMY_SP) => false,
// ... (issue #22536 continued) but as an optimization, still use
// prior logic of asking for the structural "may drop".
......
......@@ -540,7 +540,7 @@ fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
return;
}
let param_env = ty::ParamEnv::empty();
if !ty.moves_by_default(cx.tcx, param_env, item.span) {
if ty.is_copy_modulo_regions(cx.tcx, param_env, item.span) {
return;
}
if param_env.can_type_implement_copy(cx.tcx, ty).is_ok() {
......
......@@ -503,13 +503,17 @@ fn sanitize_place(
substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
};
// In order to have a Copy operand, the type T of the value must be Copy. Note that we
// prove that T: Copy, rather than using the type_moves_by_default test. This is
// important because type_moves_by_default ignores the resulting region obligations and
// assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
// (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
// fully apply: in effect, the rule is that if a value of some type could implement
// Copy, then it must.
// In order to have a Copy operand, the type T of the
// value must be Copy. Note that we prove that T: Copy,
// rather than using the `is_copy_modulo_regions`
// test. This is important because
// `is_copy_modulo_regions` ignores the resulting region
// obligations and assumes they pass. This can result in
// bounds from Copy impls being unsoundly ignored (e.g.,
// #29149). Note that we decide to use Copy before knowing
// whether the bounds fully apply: in effect, the rule is
// that if a value of some type could implement Copy, then
// it must.
self.cx.prove_trait_ref(
trait_ref,
location.to_locations(),
......
......@@ -71,7 +71,7 @@ pub fn push_usize(&mut self,
pub fn consume_by_copy_or_move(&self, place: Place<'tcx>) -> Operand<'tcx> {
let tcx = self.hir.tcx();
let ty = place.ty(&self.local_decls, tcx).to_ty(tcx);
if self.hir.type_moves_by_default(ty, DUMMY_SP) {
if !self.hir.type_is_copy_modulo_regions(ty, DUMMY_SP) {
Operand::Move(place)
} else {
Operand::Copy(place)
......
......@@ -223,8 +223,8 @@ pub fn check_overflow(&self) -> bool {
self.check_overflow
}
pub fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
self.infcx.type_moves_by_default(self.param_env, ty, span)
pub fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>, span: Span) -> bool {
self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span)
}
}
......
......@@ -545,7 +545,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
match bm {
ty::BindByValue(..) => {
let pat_ty = cx.tables.node_id_to_type(p.hir_id);
if pat_ty.moves_by_default(cx.tcx, cx.param_env, pat.span) {
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
check_move(p, sub.as_ref().map(|p| &**p), span_vec);
}
}
......
......@@ -310,7 +310,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
debug!("build_clone_shim(def_id={:?})", def_id);
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
let is_copy = !self_ty.moves_by_default(tcx, tcx.param_env(def_id), builder.span);
let is_copy = self_ty.is_copy_modulo_regions(tcx, tcx.param_env(def_id), builder.span);
let dest = Place::Local(RETURN_PLACE);
let src = Place::Local(Local::new(1+0)).deref();
......
......@@ -224,8 +224,11 @@ fn visit_place(&mut self,
"non-field projection {:?} from union?",
place)
};
if elem_ty.moves_by_default(self.tcx, self.param_env,
self.source_info.span) {
if !elem_ty.is_copy_modulo_regions(
self.tcx,
self.param_env,
self.source_info.span,
) {
self.require_unsafe(
"assignment to non-`Copy` union field",
"the previous content of the field will be dropped, which \
......
......@@ -353,7 +353,7 @@ pub fn check_ref(&self,
// Maybe add `*`? Only if `T: Copy`.
_ => {
if !self.infcx.type_moves_by_default(self.param_env,
if self.infcx.type_is_copy_modulo_regions(self.param_env,
checked,
sp) {
// do not suggest if the span comes from a macro (#52783)
......
......@@ -262,7 +262,7 @@ fn check_overloaded_binop(&self,
let mut suggested_deref = false;
if let Ref(_, mut rty, _) = lhs_ty.sty {
if {
!self.infcx.type_moves_by_default(self.param_env,
self.infcx.type_is_copy_modulo_regions(self.param_env,
rty,
lhs_expr.span) &&
self.lookup_op_method(rty,
......@@ -334,7 +334,7 @@ fn check_overloaded_binop(&self,
let mut suggested_deref = false;
if let Ref(_, mut rty, _) = lhs_ty.sty {
if {
!self.infcx.type_moves_by_default(self.param_env,
self.infcx.type_is_copy_modulo_regions(self.param_env,
rty,
lhs_expr.span) &&
self.lookup_op_method(rty,
......
......@@ -7,7 +7,7 @@ LL | impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
|
= note: this behavior recently changed as a result of a bug fix; see #XXX for details
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
error: aborting due to previous error
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册