Skip to content

Commit 9325a25

Browse files
committed
Make PlaceMention a non-mutating use.
1 parent 77dac91 commit 9325a25

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

compiler/rustc_borrowck/src/def_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
5454

5555
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
5656
// contain dangling references.
57-
PlaceContext::NonUse(NonUseContext::PlaceMention) |
57+
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
5858
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
5959

6060
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |

compiler/rustc_borrowck/src/type_check/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
771771

772772
match context {
773773
PlaceContext::MutatingUse(_) => ty::Invariant,
774-
PlaceContext::NonUse(StorageDead | StorageLive | PlaceMention | VarDebugInfo) => {
775-
ty::Invariant
776-
}
774+
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
777775
PlaceContext::NonMutatingUse(
778-
Inspect | Copy | Move | SharedBorrow | ShallowBorrow | UniqueBorrow | AddressOf
779-
| Projection,
776+
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow
777+
| AddressOf | Projection,
780778
) => ty::Covariant,
781779
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
782780
}

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
203203
self.assign(local, DefLocation::Body(location));
204204
}
205205

206-
PlaceContext::NonUse(_) | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
206+
PlaceContext::NonUse(_)
207+
| PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention)
208+
| PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
207209

208210
PlaceContext::NonMutatingUse(
209211
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,

compiler/rustc_middle/src/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ macro_rules! make_mir_visitor {
410410
StatementKind::PlaceMention(place) => {
411411
self.visit_place(
412412
place,
413-
PlaceContext::NonUse(NonUseContext::PlaceMention),
413+
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
414414
location
415415
);
416416
}
@@ -1251,6 +1251,8 @@ pub enum NonMutatingUseContext {
12511251
UniqueBorrow,
12521252
/// AddressOf for *const pointer.
12531253
AddressOf,
1254+
/// PlaceMention statement.
1255+
PlaceMention,
12541256
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
12551257
/// For example, the projection `x.y` is not marked as a mutation in these cases:
12561258
/// ```ignore (illustrative)
@@ -1301,8 +1303,6 @@ pub enum NonUseContext {
13011303
AscribeUserTy,
13021304
/// The data of a user variable, for debug info.
13031305
VarDebugInfo,
1304-
/// PlaceMention statement.
1305-
PlaceMention,
13061306
}
13071307

13081308
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ impl DefUse {
197197
| NonMutatingUseContext::Copy
198198
| NonMutatingUseContext::Inspect
199199
| NonMutatingUseContext::Move
200+
| NonMutatingUseContext::PlaceMention
200201
| NonMutatingUseContext::ShallowBorrow
201202
| NonMutatingUseContext::SharedBorrow
202203
| NonMutatingUseContext::UniqueBorrow,

compiler/rustc_mir_transform/src/const_prop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ impl Visitor<'_> for CanConstProp {
774774
| NonMutatingUse(NonMutatingUseContext::Move)
775775
| NonMutatingUse(NonMutatingUseContext::Inspect)
776776
| NonMutatingUse(NonMutatingUseContext::Projection)
777+
| NonMutatingUse(NonMutatingUseContext::PlaceMention)
777778
| NonUse(_) => {}
778779

779780
// These could be propagated with a smarter analysis or just some careful thinking about

tests/mir-opt/dead-store-elimination/place_mention.main.DeadStoreElimination.diff

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
bb0: {
1111
StorageLive(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
12-
- _1 = (const "Hello", const "World"); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
13-
- // mir::Constant
14-
- // + span: $DIR/place_mention.rs:8:19: 8:26
15-
- // + literal: Const { ty: &str, val: Value(Slice(..)) }
16-
- // mir::Constant
17-
- // + span: $DIR/place_mention.rs:8:28: 8:35
18-
- // + literal: Const { ty: &str, val: Value(Slice(..)) }
12+
_1 = (const "Hello", const "World"); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
13+
// mir::Constant
14+
// + span: $DIR/place_mention.rs:8:19: 8:26
15+
// + literal: Const { ty: &str, val: Value(Slice(..)) }
16+
// mir::Constant
17+
// + span: $DIR/place_mention.rs:8:28: 8:35
18+
// + literal: Const { ty: &str, val: Value(Slice(..)) }
1919
PlaceMention(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
2020
StorageDead(_1); // scope 0 at $DIR/place_mention.rs:+3:36: +3:37
2121
_0 = const (); // scope 0 at $DIR/place_mention.rs:+0:11: +4:2

0 commit comments

Comments
 (0)