Skip to content

Commit 55e0e5f

Browse files
authored
Merge pull request #595 from immunant/kkysen/update-rustc
Update `rustc` to `nightly-2022-08-08`
2 parents 5576c6c + 52b6693 commit 55e0e5f

File tree

20 files changed

+182
-175
lines changed

20 files changed

+182
-175
lines changed

c2rust-analyze/src/borrowck/def_use.rs

Lines changed: 8 additions & 4 deletions
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

@@ -127,15 +131,15 @@ impl<'tcx> Visitor<'tcx> for DefUseVisitor<'tcx, '_> {
127131
}
128132
}
129133

130-
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) {
134+
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
131135
eprintln!(
132136
"visit local {:?} with context {:?} = {:?} at {:?}",
133137
local,
134138
context,
135139
categorize(context),
136140
location
137141
);
138-
let var = self.maps.variable(*local);
142+
let var = self.maps.variable(local);
139143
let point = self.maps.point_mid_location(location);
140144
match categorize(context) {
141145
Some(DefUse::Def) => {
@@ -255,7 +259,7 @@ impl<'tcx> Visitor<'tcx> for LoanInvalidatedAtVisitor<'tcx, '_> {
255259
}
256260
}
257261

258-
fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) {
262+
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
259263
eprintln!(
260264
"loan_invalidated_at: visit local {:?} with context {:?} = {:?} at {:?}",
261265
local,
@@ -264,7 +268,7 @@ impl<'tcx> Visitor<'tcx> for LoanInvalidatedAtVisitor<'tcx, '_> {
264268
location
265269
);
266270

267-
let local_loans = self.loans.get(local).map_or(&[] as &[_], |x| x);
271+
let local_loans = self.loans.get(&local).map_or(&[] as &[_], |x| x);
268272
for &(_path, loan, borrow_kind) in local_loans {
269273
// All paths rooted in this local overlap the local.
270274
self.access_loan_at_location(loan, borrow_kind, context, location);

c2rust-analyze/src/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn run_polonius<'tcx>(
138138
let term_start = maps.point(bb, term_idx, SubPoint::Start);
139139
let term_mid = maps.point(bb, term_idx, SubPoint::Mid);
140140
facts.cfg_edge.push((term_start, term_mid));
141-
for &succ in bb_data.terminator().successors() {
141+
for succ in bb_data.terminator().successors() {
142142
let succ_start = maps.point(succ, 0, SubPoint::Start);
143143
facts.cfg_edge.push((term_mid, succ_start));
144144
}

c2rust-analyze/src/borrowck/type_check.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
210210
ref func,
211211
ref args,
212212
destination,
213+
target,
213214
..
214215
} => {
215216
let func_ty = func.ty(self.local_decls, *self.ltcx);
@@ -218,9 +219,10 @@ impl<'tcx> TypeChecker<'tcx, '_> {
218219
Some(Callee::PtrOffset { .. }) => {
219220
// We handle this like a pointer assignment.
220221

221-
// `destination` must be `Some` because the function doesn't diverge.
222-
let destination = destination.unwrap();
223-
let pl_lty = self.visit_place(destination.0);
222+
// `target` must be `Some` because the function doesn't diverge.
223+
// TODO(kkysen) I kept the `.unwrap()` so that the behavior is identical. Do we need this?
224+
target.unwrap();
225+
let pl_lty = self.visit_place(destination);
224226
assert!(args.len() == 2);
225227
let rv_lty = self.visit_operand(&args[0]);
226228
self.do_assign(pl_lty, rv_lty);

c2rust-analyze/src/context.rs

Lines changed: 1 addition & 0 deletions
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/dataflow/type_check.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
196196
ref func,
197197
ref args,
198198
destination,
199+
target,
199200
..
200201
} => {
201202
let func_ty = func.ty(self.mir, tcx);
@@ -204,10 +205,11 @@ impl<'tcx> TypeChecker<'tcx, '_> {
204205
Some(Callee::PtrOffset { .. }) => {
205206
// We handle this like a pointer assignment.
206207

207-
// `destination` must be `Some` because the function doesn't diverge.
208-
let destination = destination.unwrap();
208+
// `target` must be `Some` because the function doesn't diverge.
209+
// TODO(kkysen) I kept the `.unwrap()` so that the behavior is identical. Do we need this?
210+
target.unwrap();
209211
let ctx = PlaceContext::MutatingUse(MutatingUseContext::Store);
210-
let pl_lty = self.visit_place(destination.0, ctx);
212+
let pl_lty = self.visit_place(destination, ctx);
211213
assert!(args.len() == 2);
212214
let rv_lty = self.visit_operand(&args[0]);
213215
self.do_assign(pl_lty.label, rv_lty.label);

c2rust-analyze/src/expr_rewrite.rs

Lines changed: 18 additions & 9 deletions
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(..) => {}
@@ -163,14 +164,16 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> {
163164
ref func,
164165
ref args,
165166
destination,
167+
target,
166168
..
167169
} => {
168170
let func_ty = func.ty(self.mir, tcx);
169-
let pl_ty = destination.map(|(pl, _)| self.acx.type_of(pl));
171+
let pl_ty = self.acx.type_of(destination);
170172

171173
if let Some(callee) = util::ty_callee(tcx, func_ty) {
172174
// Special cases for particular functions.
173-
let pl_ty = pl_ty.unwrap();
175+
// TODO(kkysen) I kept the `.unwrap()` so that the behavior is identical. Do we need this?
176+
target.unwrap();
174177
match callee {
175178
Callee::PtrOffset { .. } => {
176179
self.visit_ptr_offset(&args[0], pl_ty);
@@ -249,23 +252,29 @@ impl<'a, 'tcx> ExprRewriteVisitor<'a, 'tcx> {
249252
Rvalue::ShallowInitBox(ref _op, _ty) => {
250253
// TODO
251254
}
255+
Rvalue::CopyForDeref(pl) => {
256+
self.enter_rvalue_operand(0, |v| v.visit_place(pl, expect_ty));
257+
}
252258
}
253259
}
254260

255261
fn visit_operand(&mut self, op: &Operand<'tcx>, expect_ty: LTy<'tcx>) {
256262
match *op {
257263
Operand::Copy(pl) | Operand::Move(pl) => {
258-
if let Some(ptr) = self.acx.ptr_of(pl) {
259-
let expect_ptr = expect_ty.label;
260-
self.emit_ptr_cast(ptr, expect_ptr);
261-
}
262-
263-
// TODO: walk over `pl` to handle all derefs (casts, `*x` -> `(*x).get()`)
264+
self.visit_place(pl, expect_ty);
264265
}
265266
Operand::Constant(..) => {}
266267
}
267268
}
268269

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+
269278
fn visit_operand_desc(
270279
&mut self,
271280
op: &Operand<'tcx>,

c2rust-analyze/src/labeled_ty.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> {
153153
/// Label a `Ty` using a callback. The callback runs at every type constructor to produce a
154154
/// label for that node in the tree.
155155
pub fn label<F: FnMut(Ty<'tcx>) -> L>(&self, ty: Ty<'tcx>, f: &mut F) -> LabeledTy<'tcx, L> {
156-
use rustc_middle::ty::TyKind::*;
156+
use rustc_type_ir::TyKind::*;
157157
let label = f(ty);
158158
match ty.kind() {
159159
// Types with no arguments
@@ -166,19 +166,19 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> {
166166
let args = substs.types().map(|t| self.label(t, f)).collect::<Vec<_>>();
167167
self.mk(ty, self.mk_slice(&args), label)
168168
}
169-
Array(elem, _) => {
169+
&Array(elem, _) => {
170170
let args = [self.label(elem, f)];
171171
self.mk(ty, self.mk_slice(&args), label)
172172
}
173-
Slice(elem) => {
173+
&Slice(elem) => {
174174
let args = [self.label(elem, f)];
175175
self.mk(ty, self.mk_slice(&args), label)
176176
}
177177
RawPtr(mty) => {
178178
let args = [self.label(mty.ty, f)];
179179
self.mk(ty, self.mk_slice(&args), label)
180180
}
181-
Ref(_, mty, _) => {
181+
&Ref(_, mty, _) => {
182182
let args = [self.label(mty, f)];
183183
self.mk(ty, self.mk_slice(&args), label)
184184
}
@@ -199,10 +199,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> {
199199
self.mk(ty, self.mk_slice(&args), label)
200200
}
201201
Tuple(elems) => {
202-
let args = elems
203-
.types()
204-
.map(|ty| self.label(ty, f))
205-
.collect::<Vec<_>>();
202+
let args = elems.iter().map(|ty| self.label(ty, f)).collect::<Vec<_>>();
206203
self.mk(ty, self.mk_slice(&args), label)
207204
}
208205

@@ -220,7 +217,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> {
220217
where
221218
F: FnMut(Ty<'tcx>) -> L,
222219
{
223-
self.mk_slice(&tys.iter().map(|ty| self.label(ty, f)).collect::<Vec<_>>())
220+
self.mk_slice(&tys.iter().map(|&ty| self.label(ty, f)).collect::<Vec<_>>())
224221
}
225222

226223
/// Substitute in arguments for any type parameter references (`Param`) in a labeled type.
@@ -291,7 +288,7 @@ impl<'tcx, L: Copy> LabeledTyCtxt<'tcx, L> {
291288
where
292289
F: FnMut(Ty<'tcx>, &[Ty<'tcx>], L) -> Ty<'tcx>,
293290
{
294-
use rustc_middle::ty::TyKind::*;
291+
use rustc_type_ir::TyKind::*;
295292
let args = lty
296293
.args
297294
.iter()

c2rust-analyze/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern crate rustc_mir_build;
1212
extern crate rustc_session;
1313
extern crate rustc_span;
1414
extern crate rustc_target;
15+
extern crate rustc_type_ir;
1516

1617
use crate::context::{
1718
AnalysisCtxt, FlagSet, GlobalAnalysisCtxt, GlobalAssignment, LTy, LocalAssignment,

c2rust-analyze/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn ty_callee<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Callee<'tcx>>
8282
match name.as_str() {
8383
"offset" => {
8484
// The `offset` inherent method of `*const T` and `*mut T`.
85-
let parent_did = tcx.parent(did)?;
85+
let parent_did = tcx.parent(did);
8686
if tcx.def_kind(parent_did) != DefKind::Impl {
8787
return None;
8888
}

0 commit comments

Comments
 (0)