Skip to content

Commit 5053cce

Browse files
committed
remove it
1 parent f426146 commit 5053cce

36 files changed

+83
-166
lines changed

compiler/rustc_borrowck/src/invalidation.rs

-5
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
289289
| Rvalue::ShallowInitBox(ref operand, _ /*ty*/) => {
290290
self.consume_operand(location, operand)
291291
}
292-
Rvalue::CopyForDeref(ref place) => {
293-
let op = &Operand::Copy(*place);
294-
self.consume_operand(location, op);
295-
}
296-
297292
Rvalue::Len(place) | Rvalue::Discriminant(place) => {
298293
let af = match *rvalue {
299294
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),

compiler/rustc_borrowck/src/lib.rs

-18
Original file line numberDiff line numberDiff line change
@@ -1236,24 +1236,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12361236
| Rvalue::ShallowInitBox(ref operand, _ /*ty*/) => {
12371237
self.consume_operand(location, (operand, span), flow_state)
12381238
}
1239-
Rvalue::CopyForDeref(place) => {
1240-
self.access_place(
1241-
location,
1242-
(place, span),
1243-
(Deep, Read(ReadKind::Copy)),
1244-
LocalMutationIsAllowed::No,
1245-
flow_state,
1246-
);
1247-
1248-
// Finally, check if path was already moved.
1249-
self.check_if_path_or_subpath_is_moved(
1250-
location,
1251-
InitializationRequiringAction::Use,
1252-
(place.as_ref(), span),
1253-
flow_state,
1254-
);
1255-
}
1256-
12571239
Rvalue::Len(place) | Rvalue::Discriminant(place) => {
12581240
let af = match *rvalue {
12591241
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),

compiler/rustc_borrowck/src/type_check/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2283,10 +2283,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22832283
Rvalue::Use(operand) | Rvalue::UnaryOp(_, operand) => {
22842284
self.check_operand(operand, location);
22852285
}
2286-
Rvalue::CopyForDeref(place) => {
2287-
let op = &Operand::Copy(*place);
2288-
self.check_operand(op, location);
2289-
}
22902286

22912287
Rvalue::BinaryOp(_, box (left, right))
22922288
| Rvalue::CheckedBinaryOp(_, box (left, right)) => {
@@ -2317,7 +2313,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23172313
| Rvalue::BinaryOp(..)
23182314
| Rvalue::CheckedBinaryOp(..)
23192315
| Rvalue::NullaryOp(..)
2320-
| Rvalue::CopyForDeref(..)
23212316
| Rvalue::UnaryOp(..)
23222317
| Rvalue::Discriminant(..) => None,
23232318

compiler/rustc_codegen_cranelift/src/base.rs

-5
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,6 @@ fn codegen_stmt<'tcx>(
503503
let val = codegen_operand(fx, operand);
504504
lval.write_cvalue(fx, val);
505505
}
506-
Rvalue::CopyForDeref(place) => {
507-
let cplace = codegen_place(fx, place);
508-
let val = cplace.to_cvalue(fx);
509-
lval.write_cvalue(fx, val)
510-
}
511506
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
512507
let place = codegen_place(fx, place);
513508
let ref_ = place.place_ref(fx, lval.layout());

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::traits::*;
88
use crate::MemFlags;
99

1010
use rustc_middle::mir;
11-
use rustc_middle::mir::Operand;
1211
use rustc_middle::ty::cast::{CastTy, IntTy};
1312
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
1413
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
@@ -345,10 +344,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
345344
self.codegen_place_to_pointer(bx, place, mk_ref)
346345
}
347346

348-
mir::Rvalue::CopyForDeref(place) => {
349-
let operand = self.codegen_operand(&mut bx, &Operand::Copy(place));
350-
(bx, operand)
351-
}
352347
mir::Rvalue::AddressOf(mutability, place) => {
353348
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
354349
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
@@ -703,7 +698,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
703698
pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool {
704699
match *rvalue {
705700
mir::Rvalue::Ref(..) |
706-
mir::Rvalue::CopyForDeref(..) |
707701
mir::Rvalue::AddressOf(..) |
708702
mir::Rvalue::Len(..) |
709703
mir::Rvalue::Cast(..) | // (*)

compiler/rustc_const_eval/src/interpret/step.rs

-5
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
172172
self.copy_op(&op, &dest, /*allow_transmute*/ false)?;
173173
}
174174

175-
CopyForDeref(ref place) => {
176-
let op = self.eval_place_to_op(*place, Some(dest.layout))?;
177-
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
178-
}
179-
180175
BinaryOp(bin_op, box (ref left, ref right)) => {
181176
let layout = binop_left_homogeneous(bin_op).then_some(dest.layout);
182177
let left = self.read_immediate(&self.eval_operand(left, layout)?)?;

compiler/rustc_const_eval/src/transform/check_consts/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
446446
Rvalue::ThreadLocalRef(_) => self.check_op(ops::ThreadLocalAccess),
447447

448448
Rvalue::Use(_)
449-
| Rvalue::CopyForDeref(..)
450449
| Rvalue::Repeat(..)
451450
| Rvalue::Discriminant(..)
452451
| Rvalue::Len(_)

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ where
260260
in_place::<Q, _>(cx, in_local, place.as_ref())
261261
}
262262

263-
Rvalue::CopyForDeref(place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
264-
265263
Rvalue::Use(operand)
266264
| Rvalue::Repeat(operand, _)
267265
| Rvalue::UnaryOp(_, operand)

compiler/rustc_const_eval/src/transform/check_consts/resolver.rs

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ where
199199
mir::Rvalue::Cast(..)
200200
| mir::Rvalue::ShallowInitBox(..)
201201
| mir::Rvalue::Use(..)
202-
| mir::Rvalue::CopyForDeref(..)
203202
| mir::Rvalue::ThreadLocalRef(..)
204203
| mir::Rvalue::Repeat(..)
205204
| mir::Rvalue::Len(..)

compiler/rustc_const_eval/src/transform/promote_consts.rs

-5
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,6 @@ impl<'tcx> Validator<'_, 'tcx> {
494494
Rvalue::Use(operand) | Rvalue::Repeat(operand, _) => {
495495
self.validate_operand(operand)?;
496496
}
497-
Rvalue::CopyForDeref(place) => {
498-
let op = &Operand::Copy(*place);
499-
self.validate_operand(op)?
500-
}
501-
502497
Rvalue::Discriminant(place) | Rvalue::Len(place) => {
503498
self.validate_place(place.as_ref())?
504499
}

compiler/rustc_const_eval/src/transform/validate.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,24 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
227227
{
228228
// `Operand::Copy` is only supposed to be used with `Copy` types.
229229
if let Operand::Copy(place) = operand {
230-
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
231-
let span = self.body.source_info(location).span;
230+
// We skip `DerefTemp` values
231+
let mut check = true;
232+
if let Some(stmt) = self.body.stmt_at(location).left() {
233+
if let StatementKind::Assign(box (dest, Rvalue::Use(Operand::Copy(_)))) =
234+
stmt.kind
235+
{
236+
if self.body.local_decls[dest.local].is_deref_temp() {
237+
check = false;
238+
}
239+
}
240+
}
241+
if check {
242+
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
243+
let span = self.body.source_info(location).span;
232244

233-
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
234-
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
245+
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
246+
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
247+
}
235248
}
236249
}
237250
}
@@ -382,7 +395,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
382395
};
383396
}
384397
match rvalue {
385-
Rvalue::Use(_) | Rvalue::CopyForDeref(_) => {}
398+
Rvalue::Use(_) => {}
386399
Rvalue::Aggregate(agg_kind, _) => {
387400
let disallowed = match **agg_kind {
388401
AggregateKind::Array(..) => false,
@@ -592,17 +605,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
592605
),
593606
);
594607
}
595-
if let Rvalue::CopyForDeref(place) = rvalue {
596-
if !place.ty(&self.body.local_decls, self.tcx).ty.builtin_deref(true).is_some()
597-
{
598-
self.fail(
599-
location,
600-
"`CopyForDeref` should only be used for dereferenceable types",
601-
)
602-
}
603-
}
604608
// FIXME(JakobDegen): Check this for all rvalues, not just this one.
605609
if let Rvalue::Use(Operand::Copy(src) | Operand::Move(src)) = rvalue {
610+
if !src.ty(&self.body.local_decls, self.tcx).ty.builtin_deref(true).is_some() {}
606611
// The sides of an assignment must not alias. Currently this just checks whether
607612
// the places are identical.
608613
if dest == src {

compiler/rustc_middle/src/mir/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,6 @@ impl<'tcx> Rvalue<'tcx> {
18101810
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => false,
18111811

18121812
Rvalue::Use(_)
1813-
| Rvalue::CopyForDeref(_)
18141813
| Rvalue::Repeat(_, _)
18151814
| Rvalue::Ref(_, _, _)
18161815
| Rvalue::ThreadLocalRef(_)
@@ -1905,8 +1904,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
19051904
write!(fmt, "&{}{}{:?}", region, kind_str, place)
19061905
}
19071906

1908-
CopyForDeref(ref place) => write!(fmt, "deref_copy {:#?}", place),
1909-
19101907
AddressOf(mutability, ref place) => {
19111908
let kind_str = match mutability {
19121909
Mutability::Mut => "mut",

compiler/rustc_middle/src/mir/syntax.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1058,16 +1058,6 @@ pub enum Rvalue<'tcx> {
10581058
/// initialized but its content as uninitialized. Like other pointer casts, this in general
10591059
/// affects alias analysis.
10601060
ShallowInitBox(Operand<'tcx>, Ty<'tcx>),
1061-
1062-
/// A CopyForDeref is equivalent to a read from a place at the
1063-
/// codegen level, but is treated specially by drop elaboration. When such a read happens, it
1064-
/// is guaranteed (via nature of the mir_opt `Derefer` in rustc_mir_transform/src/deref_separator)
1065-
/// that the only use of the returned value is a deref operation, immediately
1066-
/// followed by one or more projections. Drop elaboration treats this rvalue as if the
1067-
/// read never happened and just projects further. This allows simplifying various MIR
1068-
/// optimizations and codegen backends that previously had to handle deref operations anywhere
1069-
/// in a place.
1070-
CopyForDeref(Place<'tcx>),
10711061
}
10721062

10731063
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]

compiler/rustc_middle/src/mir/tcx.rs

-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ impl<'tcx> Rvalue<'tcx> {
213213
}
214214
},
215215
Rvalue::ShallowInitBox(_, ty) => tcx.mk_box(ty),
216-
Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty,
217216
}
218217
}
219218

compiler/rustc_middle/src/mir/type_foldable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
122122
Ref(region, bk, place) => {
123123
Ref(region.try_fold_with(folder)?, bk, place.try_fold_with(folder)?)
124124
}
125-
CopyForDeref(place) => CopyForDeref(place.try_fold_with(folder)?),
126125
AddressOf(mutability, place) => AddressOf(mutability, place.try_fold_with(folder)?),
127126
Len(place) => Len(place.try_fold_with(folder)?),
128127
Cast(kind, op, ty) => Cast(kind, op.try_fold_with(folder)?, ty.try_fold_with(folder)?),

compiler/rustc_middle/src/mir/type_visitable.rs

-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ impl<'tcx> TypeVisitable<'tcx> for Rvalue<'tcx> {
7878
use crate::mir::Rvalue::*;
7979
match *self {
8080
Use(ref op) => op.visit_with(visitor),
81-
CopyForDeref(ref place) => {
82-
let op = &Operand::Copy(*place);
83-
op.visit_with(visitor)
84-
}
8581
Repeat(ref op, _) => op.visit_with(visitor),
8682
ThreadLocalRef(did) => did.visit_with(visitor),
8783
Ref(region, _, ref place) => {

compiler/rustc_middle/src/mir/visit.rs

-8
Original file line numberDiff line numberDiff line change
@@ -711,14 +711,6 @@ macro_rules! make_mir_visitor {
711711
};
712712
self.visit_place(path, ctx, location);
713713
}
714-
Rvalue::CopyForDeref(place) => {
715-
self.visit_place(
716-
place,
717-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
718-
location
719-
);
720-
}
721-
722714
Rvalue::AddressOf(m, path) => {
723715
let ctx = match m {
724716
Mutability::Mut => PlaceContext::MutatingUse(

compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ where
102102
| mir::Rvalue::NullaryOp(..)
103103
| mir::Rvalue::UnaryOp(..)
104104
| mir::Rvalue::Discriminant(..)
105-
| mir::Rvalue::Aggregate(..)
106-
| mir::Rvalue::CopyForDeref(..) => {}
105+
| mir::Rvalue::Aggregate(..) => {}
107106
}
108107
}
109108

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -284,31 +284,30 @@ struct Gatherer<'b, 'a, 'tcx> {
284284
impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
285285
fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
286286
match &stmt.kind {
287-
StatementKind::Assign(box (place, Rvalue::CopyForDeref(reffed))) => {
288-
assert!(place.projection.is_empty());
289-
if self.builder.body.local_decls[place.local].is_deref_temp() {
290-
self.builder.un_derefer.derefer_sidetable.insert(place.local, *reffed);
291-
}
292-
}
293287
StatementKind::Assign(box (place, rval)) => {
294-
self.create_move_path(*place);
295-
if let RvalueInitializationState::Shallow = rval.initialization_state() {
296-
// Box starts out uninitialized - need to create a separate
297-
// move-path for the interior so it will be separate from
298-
// the exterior.
299-
self.create_move_path(self.builder.tcx.mk_place_deref(*place));
300-
self.gather_init(place.as_ref(), InitKind::Shallow);
288+
if self.builder.body.local_decls[place.local].is_deref_temp() {
289+
if let Rvalue::Use(Operand::Copy(reffed)) = rval {
290+
self.builder.un_derefer.derefer_sidetable.insert(place.local, *reffed);
291+
}
301292
} else {
302-
self.gather_init(place.as_ref(), InitKind::Deep);
293+
self.create_move_path(*place);
294+
if let RvalueInitializationState::Shallow = rval.initialization_state() {
295+
// Box starts out uninitialized - need to create a separate
296+
// move-path for the interior so it will be separate from
297+
// the exterior.
298+
self.create_move_path(self.builder.tcx.mk_place_deref(*place));
299+
self.gather_init(place.as_ref(), InitKind::Shallow);
300+
} else {
301+
self.gather_init(place.as_ref(), InitKind::Deep);
302+
}
303+
self.gather_rvalue(rval);
303304
}
304-
self.gather_rvalue(rval);
305305
}
306306
StatementKind::FakeRead(box (_, place)) => {
307307
self.create_move_path(*place);
308308
}
309309
StatementKind::StorageLive(_) => {}
310310
StatementKind::StorageDead(local) => {
311-
// DerefTemp locals (results of CopyForDeref) don't actually move anything.
312311
if !self.builder.un_derefer.derefer_sidetable.contains_key(&local) {
313312
self.gather_move(Place::from(*local));
314313
}
@@ -345,7 +344,6 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
345344
self.gather_operand(operand);
346345
}
347346
}
348-
Rvalue::CopyForDeref(..) => unreachable!(),
349347
Rvalue::Ref(..)
350348
| Rvalue::AddressOf(..)
351349
| Rvalue::Discriminant(..)

compiler/rustc_mir_dataflow/src/un_derefer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'tcx> UnDerefer<'tcx> {
2323
for (_bb, data) in body.basic_blocks().iter_enumerated() {
2424
for stmt in data.statements.iter() {
2525
match stmt.kind {
26-
StatementKind::Assign(box (place, Rvalue::CopyForDeref(reffed))) => {
26+
StatementKind::Assign(box (place, Rvalue::Use(Operand::Copy(reffed)))) => {
2727
if body.local_decls[place.local].is_deref_temp() {
2828
self.derefer_sidetable.insert(place.local, reffed);
2929
}

compiler/rustc_mir_transform/src/const_prop.rs

-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
621621
// There's no other checking to do at this time.
622622
Rvalue::Aggregate(..)
623623
| Rvalue::Use(..)
624-
| Rvalue::CopyForDeref(..)
625624
| Rvalue::Repeat(..)
626625
| Rvalue::Len(..)
627626
| Rvalue::Cast(..)

compiler/rustc_mir_transform/src/const_prop_lint.rs

-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
693693
// There's no other checking to do at this time.
694694
Rvalue::Aggregate(..)
695695
| Rvalue::Use(..)
696-
| Rvalue::CopyForDeref(..)
697696
| Rvalue::Repeat(..)
698697
| Rvalue::Len(..)
699698
| Rvalue::Cast(..)

compiler/rustc_mir_transform/src/deref_separator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
5555
self.patcher.add_assign(
5656
loc,
5757
Place::from(temp),
58-
Rvalue::CopyForDeref(deref_place),
58+
Rvalue::Use(Operand::Copy(deref_place)),
5959
);
6060
place_local = temp;
6161
last_len = p_ref.projection.len();

compiler/rustc_mir_transform/src/separate_const_switch.rs

-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ fn is_likely_const<'tcx>(mut tracked_place: Place<'tcx>, block: &BasicBlockData<
218218
// These rvalues move the place to track
219219
Rvalue::Cast(_, Operand::Copy(place) | Operand::Move(place), _)
220220
| Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
221-
| Rvalue::CopyForDeref(place)
222221
| Rvalue::UnaryOp(_, Operand::Copy(place) | Operand::Move(place))
223222
| Rvalue::Discriminant(place) => tracked_place = place,
224223
}
@@ -280,7 +279,6 @@ fn find_determining_place<'tcx>(
280279
// that may be const in the predecessor
281280
Rvalue::Use(Operand::Move(new) | Operand::Copy(new))
282281
| Rvalue::UnaryOp(_, Operand::Copy(new) | Operand::Move(new))
283-
| Rvalue::CopyForDeref(new)
284282
| Rvalue::Cast(_, Operand::Move(new) | Operand::Copy(new), _)
285283
| Rvalue::Repeat(Operand::Move(new) | Operand::Copy(new), _)
286284
| Rvalue::Discriminant(new)

0 commit comments

Comments
 (0)