Skip to content

Commit fc476b9

Browse files
committed
fix rebase error - break feature with refactor to avoid visit_assign
1 parent 2b5cd0f commit fc476b9

27 files changed

Lines changed: 57 additions & 65 deletions

File tree

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
302302
};
303303

304304
self.local_map.entry(borrowed_place.local).or_default().insert(idx);
305-
} else if let &mir::Rvalue::Reborrow(mutability, borrowed_place, _target) = rvalue {
305+
} else if let &mir::Rvalue::Reborrow(_target, mutability, borrowed_place) = rvalue {
306306
let borrowed_place_ty = borrowed_place.ty(self.body, self.tcx).ty;
307307
let &ty::Adt(reborrowed_adt, _reborrowed_args) = borrowed_place_ty.kind() else {
308308
unreachable!()

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
549549
) {
550550
match &stmt.kind {
551551
mir::StatementKind::Assign(box (lhs, rhs)) => {
552-
if let mir::Rvalue::Ref(_, _, place) | mir::Rvalue::Reborrow(_, place, _) = rhs {
552+
if let mir::Rvalue::Ref(_, _, place) | mir::Rvalue::Reborrow(_, _, place) = rhs {
553553
if place.ignore_borrow(
554554
self.tcx,
555555
self.body,

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15091509
);
15101510
}
15111511

1512-
&Rvalue::Reborrow(mutability, place, _target) => {
1512+
&Rvalue::Reborrow(_target, mutability, place) => {
15131513
let access_kind = (
15141514
Deep,
15151515
if mutability == Mutability::Mut {

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
275275
self.access_place(location, place, access_kind, LocalMutationIsAllowed::No);
276276
}
277277

278-
&Rvalue::Reborrow(mutability, place, _target) => {
278+
&Rvalue::Reborrow(_target, mutability, place) => {
279279
let access_kind = (
280280
Deep,
281281
if mutability == Mutability::Mut {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -550,16 +550,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
550550
}
551551

552552
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
553-
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
554-
if let Rvalue::Reborrow(mutability, rvalue, _) = rvalue {
555-
// check rvalue is Reborrow
556-
self.add_generic_reborrow_constraint(*mutability, location, place, rvalue);
557-
} else {
558-
// rest of the cases
559-
self.super_assign(place, rvalue, location);
560-
}
561-
}
562-
563553
fn visit_span(&mut self, span: Span) {
564554
if !span.is_dummy() {
565555
debug!(?span);
@@ -637,10 +627,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
637627
debug!(?rv_ty);
638628
let rv_ty = self.normalize(rv_ty, location);
639629
debug!("normalized rv_ty: {:?}", rv_ty);
640-
if let Rvalue::Reborrow(mutability, rvalue, _) = rv {
641-
// check rvalue is Reborrow
642-
self.add_generic_reborrow_constraint(*mutability, location, place, rvalue);
643-
} else if let Err(terr) =
630+
if let Err(terr) =
644631
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
645632
{
646633
span_mirbug!(
@@ -1594,10 +1581,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
15941581
self.add_reborrow_constraint(location, *region, borrowed_place);
15951582
}
15961583

1597-
Rvalue::Reborrow(..) => {
1584+
Rvalue::Reborrow(target, mutability, borrowed_place) => {
15981585
// Reborrow needs to produce a relation between the source and destination fields,
15991586
// which means that we have had to already handle this in visit_assign.
1600-
unreachable!()
1587+
self.add_generic_reborrow_constraint(
1588+
*mutability,
1589+
location,
1590+
borrowed_place,
1591+
*target,
1592+
);
16011593
}
16021594

16031595
Rvalue::BinaryOp(
@@ -2445,8 +2437,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24452437
&mut self,
24462438
mutability: Mutability,
24472439
location: Location,
2448-
dest: &Place<'tcx>,
24492440
borrowed_place: &Place<'tcx>,
2441+
dest_ty: Ty<'tcx>,
24502442
) {
24512443
// These constraints are only meaningful during borrowck:
24522444
let Self { borrow_set, location_table, polonius_facts, constraints, infcx, body, .. } =
@@ -2459,7 +2451,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24592451

24602452
debug!(
24612453
"add_generic_reborrow_constraint({:?}, {:?}, {:?}, {:?})",
2462-
mutability, location, dest, borrowed_place
2454+
mutability, location, borrowed_place, dest_ty
24632455
);
24642456

24652457
let tcx = infcx.tcx;
@@ -2473,19 +2465,19 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24732465
ConstraintCategory::Boring
24742466
};
24752467

2476-
let dest_ty = dest.ty(self.body, tcx).ty;
24772468
let borrowed_ty = borrowed_place.ty(self.body, tcx).ty;
2478-
let ty::Adt(_, args) = dest_ty.kind() else { bug!() };
2479-
let [arg, ..] = ***args else { bug!() };
2480-
let ty::GenericArgKind::Lifetime(reborrow_region) = arg.kind() else { bug!() };
2481-
constraints.liveness_constraints.add_location(reborrow_region.as_var(), location);
2469+
2470+
let ty::Adt(dest_adt, dest_args) = dest_ty.kind() else { bug!() };
2471+
let [dest_arg, ..] = ***dest_args else { bug!() };
2472+
let ty::GenericArgKind::Lifetime(dest_region) = dest_arg.kind() else { bug!() };
2473+
constraints.liveness_constraints.add_location(dest_region.as_var(), location);
24822474

24832475
// In Polonius mode, we also push a `loan_issued_at` fact
24842476
// linking the loan to the region.
24852477
if let Some(polonius_facts) = polonius_facts {
24862478
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
24872479
if let Some(borrow_index) = borrow_set.get_index_of(&location) {
2488-
let region_vid = reborrow_region.as_var();
2480+
let region_vid = dest_region.as_var();
24892481
polonius_facts.loan_issued_at.push((
24902482
region_vid.into(),
24912483
borrow_index,
@@ -2501,7 +2493,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25012493
// `CustomMut<'a>` and `CustomRef<'a>`, or `CustomMut<'a, T>` and `CustomRef<'a, T>`.
25022494
// Field-by-field relate_types is expected to work based on the wf-checks that the
25032495
// CoerceShared trait performs.
2504-
let ty::Adt(dest_adt, dest_args) = dest_ty.kind() else { unreachable!() };
25052496
let ty::Adt(borrowed_adt, borrowed_args) = borrowed_ty.kind() else { unreachable!() };
25062497
let borrowed_fields = borrowed_adt.all_fields().collect::<Vec<_>>();
25072498
for dest_field in dest_adt.all_fields() {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
629629
let ref_ = place.place_ref(fx, lval.layout());
630630
lval.write_cvalue(fx, ref_);
631631
}
632-
Rvalue::Reborrow(_, place) => {
632+
Rvalue::Reborrow(_, _, place) => {
633633
let cplace = codegen_place(fx, place);
634634
let val = cplace.to_cvalue(fx);
635635
lval.write_cvalue(fx, val)

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
514514
// Generic shared reborrowing is not (necessarily) a simple memcpy, but currently the
515515
// coherence check places such restrictions on the CoerceShared trait as to guarantee
516516
// that it is.
517-
mir::Rvalue::Reborrow(_, place, _) => {
517+
mir::Rvalue::Reborrow(_, _, place) => {
518518
self.codegen_operand(bx, &mir::Operand::Copy(place))
519519
}
520520

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ where
255255
in_place::<Q, _>(cx, in_local, place.as_ref())
256256
}
257257

258-
Rvalue::Reborrow(_, place, _) => in_place::<Q, _>(cx, in_local, place.as_ref()),
258+
Rvalue::Reborrow(_, _, place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
259259

260260
Rvalue::WrapUnsafeBinder(op, _) => in_operand::<Q, _>(cx, in_local, op),
261261

compiler/rustc_const_eval/src/check_consts/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ where
191191
}
192192
}
193193

194-
mir::Rvalue::Reborrow(mutability, borrowed_place, _target) => {
194+
mir::Rvalue::Reborrow(_target, mutability, borrowed_place) => {
195195
if !borrowed_place.is_indirect() && mutability.is_mut() {
196196
let place_ty = borrowed_place.ty(self.ccx.body, self.ccx.tcx).ty;
197197
if Q::in_any_value_of_ty(self.ccx, place_ty) {

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
228228
self.write_immediate(*val, &dest)?;
229229
}
230230

231+
Reborrow(_, _, place) => {
232+
let op = self.eval_place_to_op(place, Some(dest.layout))?;
233+
self.copy_op(&op, &dest)?;
234+
}
235+
231236
RawPtr(kind, place) => {
232237
// Figure out whether this is an addr_of of an already raw place.
233238
let place_base_raw = if place.is_indirect_first_projection() {
@@ -269,11 +274,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
269274
let op = self.eval_operand(op, None)?;
270275
self.copy_op_allow_transmute(&op, &dest)?;
271276
}
272-
273-
Reborrow(_, place, _) => {
274-
let op = self.eval_place_to_op(place, Some(dest.layout))?;
275-
self.copy_op(&op, &dest)?;
276-
}
277277
}
278278

279279
trace!("{:?}", self.dump_place(&dest));

0 commit comments

Comments
 (0)