Skip to content

Commit f282ae6

Browse files
committed
Ignore more types of mut-use context
1 parent 48b0529 commit f282ae6

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
4949

5050
let any_replacement = ssa.copy_classes().iter_enumerated().any(|(l, &h)| l != h);
5151

52-
if any_replacement {
53-
let storage_to_remove = DenseBitSet::new_empty(fully_moved.domain_size());
52+
let storage_to_remove = DenseBitSet::new_empty(fully_moved.domain_size());
5453

55-
Replacer {
56-
tcx,
57-
copy_classes: ssa.copy_classes(),
58-
fully_moved,
59-
borrowed_locals: ssa.borrowed_locals(),
60-
}
61-
.visit_body_preserves_cfg(body);
54+
Replacer {
55+
tcx,
56+
copy_classes: ssa.copy_classes(),
57+
fully_moved,
58+
borrowed_locals: ssa.borrowed_locals(),
59+
}
60+
.visit_body_preserves_cfg(body);
6261

62+
if any_replacement {
6363
let move_data = MoveData::gather_moves(body, tcx, |_| true);
6464

6565
let maybe_uninit = MaybeUninitializedPlaces::new(tcx, body, &move_data)
@@ -77,9 +77,7 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
7777
storage_checker.storage_to_remove
7878
};
7979
StorageRemover { tcx, storage_to_remove }.visit_body_preserves_cfg(body);
80-
}
8180

82-
if any_replacement {
8381
crate::simplify::remove_unused_definitions(body);
8482
}
8583
}
@@ -187,7 +185,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
187185
*rhs
188186
&& lhs == rhs
189187
{
190-
debug!(?stmt, ?loc, ?lhs, ?rhs, "removing tautological assignment");
191188
stmt.make_nop();
192189
}
193190
}
@@ -201,9 +198,14 @@ struct StorageChecker<'a, 'tcx> {
201198

202199
impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
203200
fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
204-
// We don't need to check storage statements and stores (for which the local doesn't need to be initialized).
201+
// We don't need to check storage statements and statements for which the local doesn't need to be initialized.
205202
match context {
206-
PlaceContext::MutatingUse(MutatingUseContext::Store) | PlaceContext::NonUse(_) => {
203+
PlaceContext::MutatingUse(
204+
MutatingUseContext::Store
205+
| MutatingUseContext::Call
206+
| MutatingUseContext::AsmOutput,
207+
)
208+
| PlaceContext::NonUse(_) => {
207209
return;
208210
}
209211
_ => {}
@@ -234,7 +236,6 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
234236
}
235237
}
236238

237-
/// Utility to help performing substitution of `*pattern` by `target`.
238239
struct StorageRemover<'tcx> {
239240
tcx: TyCtxt<'tcx>,
240241
storage_to_remove: DenseBitSet<Local>,

0 commit comments

Comments
 (0)