thir::Visitor
only needs to visit &'thir
data
This commit is contained in:
parent
4ae024c754
commit
2b4f84f2b2
4 changed files with 43 additions and 28 deletions
|
@ -3,26 +3,26 @@ use super::{
|
||||||
PatKind, Stmt, StmtKind, Thir,
|
PatKind, Stmt, StmtKind, Thir,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait Visitor<'a, 'tcx: 'a>: Sized {
|
pub trait Visitor<'thir, 'tcx: 'thir>: Sized {
|
||||||
fn thir(&self) -> &'a Thir<'tcx>;
|
fn thir(&self) -> &'thir Thir<'tcx>;
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'thir Expr<'tcx>) {
|
||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
|
fn visit_stmt(&mut self, stmt: &'thir Stmt<'tcx>) {
|
||||||
walk_stmt(self, stmt);
|
walk_stmt(self, stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_block(&mut self, block: &Block) {
|
fn visit_block(&mut self, block: &'thir Block) {
|
||||||
walk_block(self, block);
|
walk_block(self, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
|
fn visit_arm(&mut self, arm: &'thir Arm<'tcx>) {
|
||||||
walk_arm(self, arm);
|
walk_arm(self, arm);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
|
fn visit_pat(&mut self, pat: &'thir Pat<'tcx>) {
|
||||||
walk_pat(self, pat);
|
walk_pat(self, pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,10 @@ pub trait Visitor<'a, 'tcx: 'a>: Sized {
|
||||||
// other `visit*` functions.
|
// other `visit*` functions.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
|
pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
||||||
|
visitor: &mut V,
|
||||||
|
expr: &'thir Expr<'tcx>,
|
||||||
|
) {
|
||||||
use ExprKind::*;
|
use ExprKind::*;
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
Scope { value, region_scope: _, lint_level: _ } => {
|
Scope { value, region_scope: _, lint_level: _ } => {
|
||||||
|
@ -168,7 +171,10 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stmt<'tcx>) {
|
pub fn walk_stmt<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
||||||
|
visitor: &mut V,
|
||||||
|
stmt: &'thir Stmt<'tcx>,
|
||||||
|
) {
|
||||||
match &stmt.kind {
|
match &stmt.kind {
|
||||||
StmtKind::Expr { expr, scope: _ } => visitor.visit_expr(&visitor.thir()[*expr]),
|
StmtKind::Expr { expr, scope: _ } => visitor.visit_expr(&visitor.thir()[*expr]),
|
||||||
StmtKind::Let {
|
StmtKind::Let {
|
||||||
|
@ -191,7 +197,10 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &Block) {
|
pub fn walk_block<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
||||||
|
visitor: &mut V,
|
||||||
|
block: &'thir Block,
|
||||||
|
) {
|
||||||
for &stmt in &*block.stmts {
|
for &stmt in &*block.stmts {
|
||||||
visitor.visit_stmt(&visitor.thir()[stmt]);
|
visitor.visit_stmt(&visitor.thir()[stmt]);
|
||||||
}
|
}
|
||||||
|
@ -200,7 +209,10 @@ pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'tcx>) {
|
pub fn walk_arm<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
||||||
|
visitor: &mut V,
|
||||||
|
arm: &'thir Arm<'tcx>,
|
||||||
|
) {
|
||||||
match arm.guard {
|
match arm.guard {
|
||||||
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
|
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
|
||||||
Some(Guard::IfLet(ref pat, expr)) => {
|
Some(Guard::IfLet(ref pat, expr)) => {
|
||||||
|
@ -213,7 +225,10 @@ pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'
|
||||||
visitor.visit_expr(&visitor.thir()[arm.body]);
|
visitor.visit_expr(&visitor.thir()[arm.body]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
|
pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
||||||
|
visitor: &mut V,
|
||||||
|
pat: &'thir Pat<'tcx>,
|
||||||
|
) {
|
||||||
use PatKind::*;
|
use PatKind::*;
|
||||||
match &pat.kind {
|
match &pat.kind {
|
||||||
AscribeUserType { subpattern, ascription: _ }
|
AscribeUserType { subpattern, ascription: _ }
|
||||||
|
|
|
@ -175,7 +175,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> {
|
||||||
self.thir
|
self.thir
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Field { lhs, .. } => {
|
ExprKind::Field { lhs, .. } => {
|
||||||
if let ty::Adt(adt_def, _) = self.thir[lhs].ty.kind() {
|
if let ty::Adt(adt_def, _) = self.thir[lhs].ty.kind() {
|
||||||
|
@ -206,7 +206,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
||||||
self.thir
|
self.thir
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_block(&mut self, block: &Block) {
|
fn visit_block(&mut self, block: &'a Block) {
|
||||||
match block.safety_mode {
|
match block.safety_mode {
|
||||||
// compiler-generated unsafe code should not count towards the usefulness of
|
// compiler-generated unsafe code should not count towards the usefulness of
|
||||||
// an outer unsafe block
|
// an outer unsafe block
|
||||||
|
@ -234,7 +234,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
|
fn visit_pat(&mut self, pat: &'a Pat<'tcx>) {
|
||||||
if self.in_union_destructure {
|
if self.in_union_destructure {
|
||||||
match pat.kind {
|
match pat.kind {
|
||||||
// binding to a variable allows getting stuff out of variable
|
// binding to a variable allows getting stuff out of variable
|
||||||
|
@ -319,7 +319,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
|
||||||
// could we be in the LHS of an assignment to a field?
|
// could we be in the LHS of an assignment to a field?
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Field { .. }
|
ExprKind::Field { .. }
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
|
fn visit_arm(&mut self, arm: &'thir Arm<'tcx>) {
|
||||||
self.with_lint_level(arm.lint_level, |this| {
|
self.with_lint_level(arm.lint_level, |this| {
|
||||||
match arm.guard {
|
match arm.guard {
|
||||||
Some(Guard::If(expr)) => {
|
Some(Guard::If(expr)) => {
|
||||||
|
@ -121,7 +121,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn visit_expr(&mut self, ex: &Expr<'tcx>) {
|
fn visit_expr(&mut self, ex: &'thir Expr<'tcx>) {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
ExprKind::Scope { value, lint_level, .. } => {
|
ExprKind::Scope { value, lint_level, .. } => {
|
||||||
self.with_lint_level(lint_level, |this| {
|
self.with_lint_level(lint_level, |this| {
|
||||||
|
@ -174,7 +174,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
||||||
self.with_let_source(LetSource::None, |this| visit::walk_expr(this, ex));
|
self.with_let_source(LetSource::None, |this| visit::walk_expr(this, ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, stmt: &Stmt<'tcx>) {
|
fn visit_stmt(&mut self, stmt: &'thir Stmt<'tcx>) {
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
StmtKind::Let {
|
StmtKind::Let {
|
||||||
box ref pattern, initializer, else_block, lint_level, span, ..
|
box ref pattern, initializer, else_block, lint_level, span, ..
|
||||||
|
@ -224,7 +224,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
/// subexpressions we are not handling ourselves.
|
/// subexpressions we are not handling ourselves.
|
||||||
fn visit_land(
|
fn visit_land(
|
||||||
&mut self,
|
&mut self,
|
||||||
ex: &Expr<'tcx>,
|
ex: &'thir Expr<'tcx>,
|
||||||
accumulator: &mut Vec<Option<(Span, RefutableFlag)>>,
|
accumulator: &mut Vec<Option<(Span, RefutableFlag)>>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
|
@ -251,7 +251,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
/// expression. This must call `visit_expr` on the subexpressions we are not handling ourselves.
|
/// expression. This must call `visit_expr` on the subexpressions we are not handling ourselves.
|
||||||
fn visit_land_rhs(
|
fn visit_land_rhs(
|
||||||
&mut self,
|
&mut self,
|
||||||
ex: &Expr<'tcx>,
|
ex: &'thir Expr<'tcx>,
|
||||||
) -> Result<Option<(Span, RefutableFlag)>, ErrorGuaranteed> {
|
) -> Result<Option<(Span, RefutableFlag)>, ErrorGuaranteed> {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
ExprKind::Scope { value, lint_level, .. } => {
|
ExprKind::Scope { value, lint_level, .. } => {
|
||||||
|
@ -276,7 +276,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
fn lower_pattern(
|
fn lower_pattern(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &MatchCheckCtxt<'p, 'tcx>,
|
cx: &MatchCheckCtxt<'p, 'tcx>,
|
||||||
pat: &Pat<'tcx>,
|
pat: &'thir Pat<'tcx>,
|
||||||
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
|
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
|
||||||
if let Err(err) = pat.pat_error_reported() {
|
if let Err(err) = pat.pat_error_reported() {
|
||||||
self.error = Err(err);
|
self.error = Err(err);
|
||||||
|
@ -395,7 +395,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn check_let(&mut self, pat: &Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
|
fn check_let(&mut self, pat: &'thir Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
|
||||||
assert!(self.let_source != LetSource::None);
|
assert!(self.let_source != LetSource::None);
|
||||||
let scrut = scrutinee.map(|id| &self.thir[id]);
|
let scrut = scrutinee.map(|id| &self.thir[id]);
|
||||||
if let LetSource::PlainLet = self.let_source {
|
if let LetSource::PlainLet = self.let_source {
|
||||||
|
@ -547,7 +547,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
|
|
||||||
fn analyze_binding(
|
fn analyze_binding(
|
||||||
&mut self,
|
&mut self,
|
||||||
pat: &Pat<'tcx>,
|
pat: &'thir Pat<'tcx>,
|
||||||
refutability: RefutableFlag,
|
refutability: RefutableFlag,
|
||||||
scrut: Option<&Expr<'tcx>>,
|
scrut: Option<&Expr<'tcx>>,
|
||||||
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
|
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
|
||||||
|
@ -560,7 +560,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
|
|
||||||
fn is_let_irrefutable(
|
fn is_let_irrefutable(
|
||||||
&mut self,
|
&mut self,
|
||||||
pat: &Pat<'tcx>,
|
pat: &'thir Pat<'tcx>,
|
||||||
scrut: Option<&Expr<'tcx>>,
|
scrut: Option<&Expr<'tcx>>,
|
||||||
) -> Result<RefutableFlag, ErrorGuaranteed> {
|
) -> Result<RefutableFlag, ErrorGuaranteed> {
|
||||||
let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?;
|
let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?;
|
||||||
|
@ -575,7 +575,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn check_binding_is_irrefutable(
|
fn check_binding_is_irrefutable(
|
||||||
&mut self,
|
&mut self,
|
||||||
pat: &Pat<'tcx>,
|
pat: &'thir Pat<'tcx>,
|
||||||
origin: &str,
|
origin: &str,
|
||||||
scrut: Option<&Expr<'tcx>>,
|
scrut: Option<&Expr<'tcx>>,
|
||||||
sp: Option<Span>,
|
sp: Option<Span>,
|
||||||
|
|
|
@ -379,7 +379,7 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'a thir::Expr<'tcx>) {
|
||||||
self.is_poly |= self.expr_is_poly(expr);
|
self.is_poly |= self.expr_is_poly(expr);
|
||||||
if !self.is_poly {
|
if !self.is_poly {
|
||||||
visit::walk_expr(self, expr)
|
visit::walk_expr(self, expr)
|
||||||
|
@ -387,7 +387,7 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
|
fn visit_pat(&mut self, pat: &'a thir::Pat<'tcx>) {
|
||||||
self.is_poly |= self.pat_is_poly(pat);
|
self.is_poly |= self.pat_is_poly(pat);
|
||||||
if !self.is_poly {
|
if !self.is_poly {
|
||||||
visit::walk_pat(self, pat);
|
visit::walk_pat(self, pat);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue