Skip to content

Commit f708d6d

Browse files
committed
Fix match_same_arms in stable_mir
1 parent f6648f2 commit f708d6d

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

compiler/stable_mir/src/mir/pretty.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,25 @@ fn pretty_terminator_head<W: Write>(writer: &mut W, terminator: &TerminatorKind)
189189
fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec<String> {
190190
use self::TerminatorKind::*;
191191
match terminator {
192-
Resume | Abort | Return | Unreachable => vec![],
192+
Call { target: None, unwind: UnwindAction::Cleanup(_), .. }
193+
| InlineAsm { destination: None, .. } => vec!["unwind".into()],
194+
Resume | Abort | Return | Unreachable | Call { target: None, unwind: _, .. } => vec![],
193195
Goto { .. } => vec!["".to_string()],
194196
SwitchInt { targets, .. } => targets
195197
.branches()
196198
.map(|(val, _target)| format!("{val}"))
197199
.chain(iter::once("otherwise".into()))
198200
.collect(),
199201
Drop { unwind: UnwindAction::Cleanup(_), .. } => vec!["return".into(), "unwind".into()],
200-
Drop { unwind: _, .. } => vec!["return".into()],
201202
Call { target: Some(_), unwind: UnwindAction::Cleanup(_), .. } => {
202203
vec!["return".into(), "unwind".into()]
203204
}
204-
Call { target: Some(_), unwind: _, .. } => vec!["return".into()],
205-
Call { target: None, unwind: UnwindAction::Cleanup(_), .. } => vec!["unwind".into()],
206-
Call { target: None, unwind: _, .. } => vec![],
205+
Drop { unwind: _, .. } | Call { target: Some(_), unwind: _, .. } => vec!["return".into()],
207206
Assert { unwind: UnwindAction::Cleanup(_), .. } => {
208207
vec!["success".into(), "unwind".into()]
209208
}
210209
Assert { unwind: _, .. } => vec!["success".into()],
211210
InlineAsm { destination: Some(_), .. } => vec!["goto".into(), "unwind".into()],
212-
InlineAsm { destination: None, .. } => vec!["unwind".into()],
213211
}
214212
}
215213

compiler/stable_mir/src/mir/visit.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -194,27 +194,17 @@ pub trait MirVisitor {
194194
self.visit_place(place, PlaceContext::MUTATING, location);
195195
self.visit_rvalue(rvalue, location);
196196
}
197-
StatementKind::FakeRead(_, place) => {
197+
StatementKind::FakeRead(_, place) | StatementKind::PlaceMention(place) => {
198198
self.visit_place(place, PlaceContext::NON_MUTATING, location);
199199
}
200-
StatementKind::SetDiscriminant { place, .. } => {
200+
StatementKind::SetDiscriminant { place, .. }
201+
| StatementKind::Deinit(place)
202+
| StatementKind::Retag(_, place) => {
201203
self.visit_place(place, PlaceContext::MUTATING, location);
202204
}
203-
StatementKind::Deinit(place) => {
204-
self.visit_place(place, PlaceContext::MUTATING, location);
205-
}
206-
StatementKind::StorageLive(local) => {
207-
self.visit_local(local, PlaceContext::NON_USE, location);
208-
}
209-
StatementKind::StorageDead(local) => {
205+
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
210206
self.visit_local(local, PlaceContext::NON_USE, location);
211207
}
212-
StatementKind::Retag(_, place) => {
213-
self.visit_place(place, PlaceContext::MUTATING, location);
214-
}
215-
StatementKind::PlaceMention(place) => {
216-
self.visit_place(place, PlaceContext::NON_MUTATING, location);
217-
}
218208
StatementKind::AscribeUserType { place, projections, variance: _ } => {
219209
self.visit_place(place, PlaceContext::NON_USE, location);
220210
self.visit_user_type_projection(projections);
@@ -234,8 +224,7 @@ pub trait MirVisitor {
234224
self.visit_operand(count, location);
235225
}
236226
},
237-
StatementKind::ConstEvalCounter => {}
238-
StatementKind::Nop => {}
227+
StatementKind::ConstEvalCounter | StatementKind::Nop => {}
239228
}
240229
}
241230

@@ -304,14 +293,15 @@ pub trait MirVisitor {
304293
location: Location,
305294
) {
306295
match elem {
307-
ProjectionElem::Deref => {}
296+
ProjectionElem::Downcast(_idx) => {}
297+
ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
298+
| ProjectionElem::Deref
299+
| ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
308300
ProjectionElem::Field(_idx, ty) => self.visit_ty(ty, location),
309301
ProjectionElem::Index(local) => self.visit_local(local, ptx, location),
310-
ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ } => {}
311-
ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
312-
ProjectionElem::Downcast(_idx) => {}
313-
ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location),
314-
ProjectionElem::Subtype(ty) => self.visit_ty(ty, location),
302+
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => {
303+
self.visit_ty(ty, location)
304+
}
315305
}
316306
}
317307

compiler/stable_mir/src/visitor.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ impl Visitable for Ty {
3535
match self.kind() {
3636
super::ty::TyKind::RigidTy(ty) => ty.visit(visitor)?,
3737
super::ty::TyKind::Alias(_, alias) => alias.args.visit(visitor)?,
38-
super::ty::TyKind::Param(_) => {}
39-
super::ty::TyKind::Bound(_, _) => {}
38+
super::ty::TyKind::Param(_) | super::ty::TyKind::Bound(_, _) => {}
4039
}
4140
ControlFlow::Continue(())
4241
}
@@ -48,8 +47,7 @@ impl Visitable for TyConst {
4847
}
4948
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
5049
match &self.kind {
51-
crate::ty::TyConstKind::Param(_) => {}
52-
crate::ty::TyConstKind::Bound(_, _) => {}
50+
crate::ty::TyConstKind::Param(_) | crate::ty::TyConstKind::Bound(_, _) => {}
5351
crate::ty::TyConstKind::Unevaluated(_, args) => args.visit(visitor)?,
5452
crate::ty::TyConstKind::Value(ty, alloc) => {
5553
alloc.visit(visitor)?;
@@ -166,17 +164,17 @@ impl Visitable for RigidTy {
166164
reg.visit(visitor);
167165
ty.visit(visitor)
168166
}
169-
RigidTy::FnDef(_, args) => args.visit(visitor),
167+
RigidTy::Adt(_, args)
168+
| RigidTy::Closure(_, args)
169+
| RigidTy::Coroutine(_, args, _)
170+
| RigidTy::CoroutineWitness(_, args)
171+
| RigidTy::FnDef(_, args) => args.visit(visitor),
170172
RigidTy::FnPtr(sig) => sig.visit(visitor),
171-
RigidTy::Closure(_, args) => args.visit(visitor),
172-
RigidTy::Coroutine(_, args, _) => args.visit(visitor),
173-
RigidTy::CoroutineWitness(_, args) => args.visit(visitor),
174173
RigidTy::Dynamic(pred, r, _) => {
175174
pred.visit(visitor)?;
176175
r.visit(visitor)
177176
}
178177
RigidTy::Tuple(fields) => fields.visit(visitor),
179-
RigidTy::Adt(_, args) => args.visit(visitor),
180178
}
181179
}
182180
}

0 commit comments

Comments
 (0)