mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-31 21:16:44 +00:00
This one is a heavy `'tcx` user.
Two interesting ones:
This one had the `'tcx` declared on the function, despite the trait taking a `'tcx`:
```diff
-impl Visitor<'_> for UsedLocals {
+impl<'tcx> Visitor<'tcx> for UsedLocals {
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
```
This one use in-band for one, and underscore for the other:
```diff
-pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
+pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
```
24 lines
735 B
Rust
24 lines
735 B
Rust
use rustc_middle::mir::visit::Visitor;
|
|
use rustc_middle::mir::{Constant, Location};
|
|
use rustc_middle::ty::ConstKind;
|
|
|
|
pub struct RequiredConstsVisitor<'a, 'tcx> {
|
|
required_consts: &'a mut Vec<Constant<'tcx>>,
|
|
}
|
|
|
|
impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
|
|
pub fn new(required_consts: &'a mut Vec<Constant<'tcx>>) -> Self {
|
|
RequiredConstsVisitor { required_consts }
|
|
}
|
|
}
|
|
|
|
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
|
|
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
|
|
if let Some(ct) = constant.literal.const_for_ty() {
|
|
if let ConstKind::Unevaluated(_) = ct.val {
|
|
self.required_consts.push(*constant);
|
|
}
|
|
}
|
|
}
|
|
}
|