Make PlaceMention a non-mutating use.
This commit is contained in:
parent
77dac91d4f
commit
9325a254f0
7 changed files with 19 additions and 17 deletions
|
@ -54,7 +54,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
|
||||||
|
|
||||||
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
|
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
|
||||||
// contain dangling references.
|
// contain dangling references.
|
||||||
PlaceContext::NonUse(NonUseContext::PlaceMention) |
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
|
||||||
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
|
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
|
||||||
|
|
||||||
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
|
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
|
||||||
|
|
|
@ -771,12 +771,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
match context {
|
match context {
|
||||||
PlaceContext::MutatingUse(_) => ty::Invariant,
|
PlaceContext::MutatingUse(_) => ty::Invariant,
|
||||||
PlaceContext::NonUse(StorageDead | StorageLive | PlaceMention | VarDebugInfo) => {
|
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
|
||||||
ty::Invariant
|
|
||||||
}
|
|
||||||
PlaceContext::NonMutatingUse(
|
PlaceContext::NonMutatingUse(
|
||||||
Inspect | Copy | Move | SharedBorrow | ShallowBorrow | UniqueBorrow | AddressOf
|
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow
|
||||||
| Projection,
|
| AddressOf | Projection,
|
||||||
) => ty::Covariant,
|
) => ty::Covariant,
|
||||||
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
|
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,9 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||||
self.assign(local, DefLocation::Body(location));
|
self.assign(local, DefLocation::Body(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceContext::NonUse(_) | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
|
PlaceContext::NonUse(_)
|
||||||
|
| PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention)
|
||||||
|
| PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
|
||||||
|
|
||||||
PlaceContext::NonMutatingUse(
|
PlaceContext::NonMutatingUse(
|
||||||
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,
|
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,
|
||||||
|
|
|
@ -410,7 +410,7 @@ macro_rules! make_mir_visitor {
|
||||||
StatementKind::PlaceMention(place) => {
|
StatementKind::PlaceMention(place) => {
|
||||||
self.visit_place(
|
self.visit_place(
|
||||||
place,
|
place,
|
||||||
PlaceContext::NonUse(NonUseContext::PlaceMention),
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
|
||||||
location
|
location
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1251,6 +1251,8 @@ pub enum NonMutatingUseContext {
|
||||||
UniqueBorrow,
|
UniqueBorrow,
|
||||||
/// AddressOf for *const pointer.
|
/// AddressOf for *const pointer.
|
||||||
AddressOf,
|
AddressOf,
|
||||||
|
/// PlaceMention statement.
|
||||||
|
PlaceMention,
|
||||||
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
|
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
|
||||||
/// For example, the projection `x.y` is not marked as a mutation in these cases:
|
/// For example, the projection `x.y` is not marked as a mutation in these cases:
|
||||||
/// ```ignore (illustrative)
|
/// ```ignore (illustrative)
|
||||||
|
@ -1301,8 +1303,6 @@ pub enum NonUseContext {
|
||||||
AscribeUserTy,
|
AscribeUserTy,
|
||||||
/// The data of a user variable, for debug info.
|
/// The data of a user variable, for debug info.
|
||||||
VarDebugInfo,
|
VarDebugInfo,
|
||||||
/// PlaceMention statement.
|
|
||||||
PlaceMention,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -197,6 +197,7 @@ impl DefUse {
|
||||||
| NonMutatingUseContext::Copy
|
| NonMutatingUseContext::Copy
|
||||||
| NonMutatingUseContext::Inspect
|
| NonMutatingUseContext::Inspect
|
||||||
| NonMutatingUseContext::Move
|
| NonMutatingUseContext::Move
|
||||||
|
| NonMutatingUseContext::PlaceMention
|
||||||
| NonMutatingUseContext::ShallowBorrow
|
| NonMutatingUseContext::ShallowBorrow
|
||||||
| NonMutatingUseContext::SharedBorrow
|
| NonMutatingUseContext::SharedBorrow
|
||||||
| NonMutatingUseContext::UniqueBorrow,
|
| NonMutatingUseContext::UniqueBorrow,
|
||||||
|
|
|
@ -774,6 +774,7 @@ impl Visitor<'_> for CanConstProp {
|
||||||
| NonMutatingUse(NonMutatingUseContext::Move)
|
| NonMutatingUse(NonMutatingUseContext::Move)
|
||||||
| NonMutatingUse(NonMutatingUseContext::Inspect)
|
| NonMutatingUse(NonMutatingUseContext::Inspect)
|
||||||
| NonMutatingUse(NonMutatingUseContext::Projection)
|
| NonMutatingUse(NonMutatingUseContext::Projection)
|
||||||
|
| NonMutatingUse(NonMutatingUseContext::PlaceMention)
|
||||||
| NonUse(_) => {}
|
| NonUse(_) => {}
|
||||||
|
|
||||||
// These could be propagated with a smarter analysis or just some careful thinking about
|
// These could be propagated with a smarter analysis or just some careful thinking about
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
StorageLive(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
|
StorageLive(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
|
||||||
- _1 = (const "Hello", const "World"); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
|
_1 = (const "Hello", const "World"); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
|
||||||
- // mir::Constant
|
// mir::Constant
|
||||||
- // + span: $DIR/place_mention.rs:8:19: 8:26
|
// + span: $DIR/place_mention.rs:8:19: 8:26
|
||||||
- // + literal: Const { ty: &str, val: Value(Slice(..)) }
|
// + literal: Const { ty: &str, val: Value(Slice(..)) }
|
||||||
- // mir::Constant
|
// mir::Constant
|
||||||
- // + span: $DIR/place_mention.rs:8:28: 8:35
|
// + span: $DIR/place_mention.rs:8:28: 8:35
|
||||||
- // + literal: Const { ty: &str, val: Value(Slice(..)) }
|
// + literal: Const { ty: &str, val: Value(Slice(..)) }
|
||||||
PlaceMention(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
|
PlaceMention(_1); // scope 0 at $DIR/place_mention.rs:+3:18: +3:36
|
||||||
StorageDead(_1); // scope 0 at $DIR/place_mention.rs:+3:36: +3:37
|
StorageDead(_1); // scope 0 at $DIR/place_mention.rs:+3:36: +3:37
|
||||||
_0 = const (); // scope 0 at $DIR/place_mention.rs:+0:11: +4:2
|
_0 = const (); // scope 0 at $DIR/place_mention.rs:+0:11: +4:2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue