Skip to content

Commit 18f65dd

Browse files
committed
Add Rvalue::is_pure
This method is used by the liveness (dead code elimination) pass, but for some reason I never ended up staging it for commit
1 parent d203b9c commit 18f65dd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/librustc/mir/repr.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,23 @@ impl UnOp {
10621062
}
10631063
}
10641064

1065+
impl<'tcx> Rvalue<'tcx> {
1066+
pub fn is_pure(&self) -> bool {
1067+
use self::Rvalue::*;
1068+
match *self {
1069+
// Arbitrary side effects
1070+
InlineAsm { .. } |
1071+
// Side effect: allocation
1072+
Box(_) |
1073+
// Side effect: assertion
1074+
CheckedBinaryOp(..) => false,
1075+
// No side effects
1076+
Use(_) | Repeat(..) | Len(_) | Cast(..) | BinaryOp(..) | UnaryOp(..) |
1077+
Ref(..) | Aggregate(..) => true
1078+
}
1079+
}
1080+
}
1081+
10651082
impl<'tcx> Debug for Rvalue<'tcx> {
10661083
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
10671084
use self::Rvalue::*;

0 commit comments

Comments
 (0)