Skip to content

Commit df32e6c

Browse files
spernsteinerkkysen
authored andcommitted
analyze: misc fixes for rustc update
1 parent 55a5087 commit df32e6c

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

c2rust-analyze/src/borrowck/def_use.rs

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
8181

8282
// Debug info is neither def nor use.
8383
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
84+
85+
PlaceContext::MutatingUse(MutatingUseContext::Deinit | MutatingUseContext::SetDiscriminant) => {
86+
panic!("These statements are not allowed in this MIR phase")
87+
}
8488
}
8589
}
8690

c2rust-analyze/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ impl<'tcx> TypeOf<'tcx> for Rvalue<'tcx> {
342342

343343
match *self {
344344
Rvalue::Use(ref op) => acx.type_of(op),
345+
Rvalue::CopyForDeref(pl) => acx.type_of(pl),
345346
Rvalue::Repeat(ref op, _) => {
346347
let op_lty = acx.type_of(op);
347348
let ty = self.ty(acx, acx.tcx());

c2rust-analyze/src/expr_rewrite.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::pointer_id::PointerTable;
33
use crate::type_desc::{self, Ownership, Quantity};
44
use crate::util::{self, Callee};
55
use rustc_middle::mir::{
6-
BasicBlock, Body, Location, Operand, Rvalue, Statement, StatementKind, Terminator,
6+
BasicBlock, Body, Location, Operand, Place, Rvalue, Statement, StatementKind, Terminator,
77
TerminatorKind,
88
};
99
use rustc_span::{Span, DUMMY_SP};
@@ -132,6 +132,7 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> {
132132
}
133133
StatementKind::FakeRead(..) => {}
134134
StatementKind::SetDiscriminant { .. } => todo!("statement {:?}", stmt),
135+
StatementKind::Deinit(..) => {}
135136
StatementKind::StorageLive(..) => {}
136137
StatementKind::StorageDead(..) => {}
137138
StatementKind::Retag(..) => {}
@@ -251,23 +252,29 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> {
251252
Rvalue::ShallowInitBox(ref _op, _ty) => {
252253
// TODO
253254
}
255+
Rvalue::CopyForDeref(pl) => {
256+
self.enter_rvalue_operand(0, |v| v.visit_place(pl, expect_ty));
257+
}
254258
}
255259
}
256260

257261
fn visit_operand(&mut self, op: &Operand<'tcx>, expect_ty: LTy<'tcx>) {
258262
match *op {
259263
Operand::Copy(pl) | Operand::Move(pl) => {
260-
if let Some(ptr) = self.acx.ptr_of(pl) {
261-
let expect_ptr = expect_ty.label;
262-
self.emit_ptr_cast(ptr, expect_ptr);
263-
}
264-
265-
// TODO: walk over `pl` to handle all derefs (casts, `*x` -> `(*x).get()`)
264+
self.visit_place(pl, expect_ty);
266265
}
267266
Operand::Constant(..) => {}
268267
}
269268
}
270269

270+
fn visit_place(&mut self, pl: Place<'tcx>, expect_ty: LTy<'tcx>) {
271+
if let Some(ptr) = self.acx.ptr_of(pl) {
272+
let expect_ptr = expect_ty.label;
273+
self.emit_ptr_cast(ptr, expect_ptr);
274+
}
275+
// TODO: walk over `pl` to handle all derefs (casts, `*x` -> `(*x).get()`)
276+
}
277+
271278
fn visit_operand_desc(
272279
&mut self,
273280
op: &Operand<'tcx>,

0 commit comments

Comments
 (0)