Skip to content

Commit 58eabb2

Browse files
committed
Add method that applies DefUse effect
1 parent 4462b4a commit 58eabb2

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ where
122122
}
123123

124124
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
125-
match DefUse::for_place(local.into(), context) {
126-
Some(DefUse::Def) => self.0.kill(local),
127-
Some(DefUse::Use) => self.0.gen(local),
128-
None => {}
129-
}
125+
DefUse::apply(self.0, local.into(), context);
130126
}
131127
}
132128

@@ -137,20 +133,12 @@ where
137133
T: GenKill<Local>,
138134
{
139135
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
140-
match DefUse::for_place(*place, context) {
141-
Some(DefUse::Def) => self.0.kill(place.local),
142-
Some(DefUse::Use) => self.0.gen(place.local),
143-
None => {}
144-
}
136+
DefUse::apply(self.0, *place, context);
145137
self.visit_projection(place.as_ref(), context, location);
146138
}
147139

148140
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
149-
match DefUse::for_place(local.into(), context) {
150-
Some(DefUse::Def) => self.0.kill(local),
151-
Some(DefUse::Use) => self.0.gen(local),
152-
None => {}
153-
}
141+
DefUse::apply(self.0, local.into(), context);
154142
}
155143
}
156144

@@ -161,6 +149,14 @@ enum DefUse {
161149
}
162150

163151
impl DefUse {
152+
fn apply<'tcx>(trans: &mut impl GenKill<Local>, place: Place<'tcx>, context: PlaceContext) {
153+
match DefUse::for_place(place, context) {
154+
Some(DefUse::Def) => trans.kill(place.local),
155+
Some(DefUse::Use) => trans.gen(place.local),
156+
None => {}
157+
}
158+
}
159+
164160
fn for_place<'tcx>(place: Place<'tcx>, context: PlaceContext) -> Option<DefUse> {
165161
match context {
166162
PlaceContext::NonUse(_) => None,

0 commit comments

Comments
 (0)