Remove unnecessary lifetime in ConditionVisitor
.
By making it own two of its fields.
This commit is contained in:
parent
56e849ca21
commit
c69d174311
@ -708,9 +708,9 @@ fn report_use_of_uninitialized(
|
|||||||
// for the branching codepaths that aren't covered, to point at them.
|
// for the branching codepaths that aren't covered, to point at them.
|
||||||
let map = self.infcx.tcx.hir();
|
let map = self.infcx.tcx.hir();
|
||||||
let body = map.body_owned_by(self.mir_def_id());
|
let body = map.body_owned_by(self.mir_def_id());
|
||||||
let mut visitor =
|
let mut visitor = ConditionVisitor { tcx: self.infcx.tcx, spans, name, errors: vec![] };
|
||||||
ConditionVisitor { tcx: self.infcx.tcx, spans: &spans, name: &name, errors: vec![] };
|
|
||||||
visitor.visit_body(&body);
|
visitor.visit_body(&body);
|
||||||
|
let spans = visitor.spans;
|
||||||
|
|
||||||
let mut show_assign_sugg = false;
|
let mut show_assign_sugg = false;
|
||||||
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
|
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
|
||||||
@ -4465,20 +4465,20 @@ fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
|
|||||||
|
|
||||||
/// Given a set of spans representing statements initializing the relevant binding, visit all the
|
/// Given a set of spans representing statements initializing the relevant binding, visit all the
|
||||||
/// function expressions looking for branching code paths that *do not* initialize the binding.
|
/// function expressions looking for branching code paths that *do not* initialize the binding.
|
||||||
struct ConditionVisitor<'b, 'tcx> {
|
struct ConditionVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
spans: &'b [Span],
|
spans: Vec<Span>,
|
||||||
name: &'b str,
|
name: String,
|
||||||
errors: Vec<(Span, String)>,
|
errors: Vec<(Span, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
|
impl<'v, 'tcx> Visitor<'v> for ConditionVisitor<'tcx> {
|
||||||
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
|
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
hir::ExprKind::If(cond, body, None) => {
|
hir::ExprKind::If(cond, body, None) => {
|
||||||
// `if` expressions with no `else` that initialize the binding might be missing an
|
// `if` expressions with no `else` that initialize the binding might be missing an
|
||||||
// `else` arm.
|
// `else` arm.
|
||||||
if ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break() {
|
if ReferencedStatementsVisitor(&self.spans).visit_expr(body).is_break() {
|
||||||
self.errors.push((
|
self.errors.push((
|
||||||
cond.span,
|
cond.span,
|
||||||
format!(
|
format!(
|
||||||
@ -4495,8 +4495,8 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
|
|||||||
hir::ExprKind::If(cond, body, Some(other)) => {
|
hir::ExprKind::If(cond, body, Some(other)) => {
|
||||||
// `if` expressions where the binding is only initialized in one of the two arms
|
// `if` expressions where the binding is only initialized in one of the two arms
|
||||||
// might be missing a binding initialization.
|
// might be missing a binding initialization.
|
||||||
let a = ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break();
|
let a = ReferencedStatementsVisitor(&self.spans).visit_expr(body).is_break();
|
||||||
let b = ReferencedStatementsVisitor(self.spans).visit_expr(other).is_break();
|
let b = ReferencedStatementsVisitor(&self.spans).visit_expr(other).is_break();
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
(true, true) | (false, false) => {}
|
(true, true) | (false, false) => {}
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
@ -4536,7 +4536,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
|
|||||||
// arms might be missing an initialization.
|
// arms might be missing an initialization.
|
||||||
let results: Vec<bool> = arms
|
let results: Vec<bool> = arms
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arm| ReferencedStatementsVisitor(self.spans).visit_arm(arm).is_break())
|
.map(|arm| ReferencedStatementsVisitor(&self.spans).visit_arm(arm).is_break())
|
||||||
.collect();
|
.collect();
|
||||||
if results.iter().any(|x| *x) && !results.iter().all(|x| *x) {
|
if results.iter().any(|x| *x) && !results.iter().all(|x| *x) {
|
||||||
for (arm, seen) in arms.iter().zip(results) {
|
for (arm, seen) in arms.iter().zip(results) {
|
||||||
|
Loading…
Reference in New Issue
Block a user