Skip to content

Commit 50d7dea

Browse files
committed
prepare visit_statement for checking more kinds of statements
1 parent 810f309 commit 50d7dea

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/librustc_mir/transform/validate.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,34 +133,37 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
133133
}
134134

135135
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
136-
if let StatementKind::Assign(box (dest, rvalue)) = &statement.kind {
137-
// LHS and RHS of the assignment must have the same type.
138-
let left_ty = dest.ty(&self.body.local_decls, self.tcx).ty;
139-
let right_ty = rvalue.ty(&self.body.local_decls, self.tcx);
140-
if !mir_assign_valid_types(self.tcx, right_ty, left_ty) {
141-
self.fail(
142-
location,
143-
format!(
144-
"encountered `Assign` statement with incompatible types:\n\
145-
left-hand side has type: {}\n\
146-
right-hand side has type: {}",
147-
left_ty, right_ty,
148-
),
149-
);
150-
}
151-
// The sides of an assignment must not alias. Currently this just checks whether the places
152-
// are identical.
153-
match rvalue {
154-
Rvalue::Use(Operand::Copy(src) | Operand::Move(src)) => {
155-
if dest == src {
156-
self.fail(
157-
location,
158-
"encountered `Assign` statement with overlapping memory",
159-
);
136+
match &statement.kind {
137+
StatementKind::Assign(box (dest, rvalue)) => {
138+
// LHS and RHS of the assignment must have the same type.
139+
let left_ty = dest.ty(&self.body.local_decls, self.tcx).ty;
140+
let right_ty = rvalue.ty(&self.body.local_decls, self.tcx);
141+
if !mir_assign_valid_types(self.tcx, right_ty, left_ty) {
142+
self.fail(
143+
location,
144+
format!(
145+
"encountered `Assign` statement with incompatible types:\n\
146+
left-hand side has type: {}\n\
147+
right-hand side has type: {}",
148+
left_ty, right_ty,
149+
),
150+
);
151+
}
152+
// The sides of an assignment must not alias. Currently this just checks whether the places
153+
// are identical.
154+
match rvalue {
155+
Rvalue::Use(Operand::Copy(src) | Operand::Move(src)) => {
156+
if dest == src {
157+
self.fail(
158+
location,
159+
"encountered `Assign` statement with overlapping memory",
160+
);
161+
}
160162
}
163+
_ => {}
161164
}
162-
_ => {}
163165
}
166+
_ => {}
164167
}
165168
}
166169

0 commit comments

Comments
 (0)