Skip to content

Commit 335fb69

Browse files
Add more PlaceContext utility methods
1 parent c9cab06 commit 335fb69

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/librustc_middle/mir/visit.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1184,9 +1184,34 @@ impl PlaceContext {
11841184
PlaceContext::MutatingUse(
11851185
MutatingUseContext::Store
11861186
| MutatingUseContext::Call
1187+
| MutatingUseContext::Yield
11871188
| MutatingUseContext::AsmOutput,
11881189
) => true,
11891190
_ => false,
11901191
}
11911192
}
1193+
1194+
/// Returns `true` if this context could read the contents of the place.
1195+
pub fn is_read(&self) -> bool {
1196+
match *self {
1197+
PlaceContext::MutatingUse(
1198+
MutatingUseContext::Store | MutatingUseContext::Call | MutatingUseContext::Yield,
1199+
)
1200+
| PlaceContext::NonUse(_) => false,
1201+
1202+
PlaceContext::MutatingUse(_) | PlaceContext::NonMutatingUse(_) => true,
1203+
}
1204+
}
1205+
1206+
/// Returns `true` if this context does not read from this place but does write to it.
1207+
///
1208+
/// This is relevant for inline assembly, which has read/write parameters.
1209+
pub fn is_write_only(&self) -> bool {
1210+
matches!(
1211+
self,
1212+
PlaceContext::MutatingUse(
1213+
MutatingUseContext::Store | MutatingUseContext::Call | MutatingUseContext::Yield
1214+
)
1215+
)
1216+
}
11921217
}

0 commit comments

Comments
 (0)