forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MirPass to collect Unevaluated consts in MIR body
- Loading branch information
1 parent
6807bb7
commit f8976e3
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use rustc_middle::mir::visit::Visitor; | ||
use rustc_middle::mir::{Constant, Location}; | ||
use rustc_middle::ty::ConstKind; | ||
|
||
pub struct UnevalConstSetVisitor<'a, 'tcx> { | ||
uneval_consts: &'a mut Vec<Constant<'tcx>>, | ||
} | ||
|
||
impl<'a, 'tcx> UnevalConstSetVisitor<'a, 'tcx> { | ||
pub fn new(uneval_consts: &'a mut Vec<Constant<'tcx>>) -> Self { | ||
UnevalConstSetVisitor { uneval_consts } | ||
} | ||
} | ||
|
||
impl<'a, 'tcx> Visitor<'tcx> for UnevalConstSetVisitor<'a, 'tcx> { | ||
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) { | ||
let const_kind = constant.literal.val; | ||
|
||
if let ConstKind::Unevaluated(_, _, _) = const_kind { | ||
self.uneval_consts.push(*constant); | ||
} | ||
} | ||
} |