Merge commit '37f4fbb929' into clippy-subtree-update
This commit is contained in:
parent
6d674685ae
commit
4e6851e50b
291 changed files with 4890 additions and 5205 deletions
|
|
@ -23,6 +23,7 @@ mod while_let_loop;
|
|||
mod while_let_on_iterator;
|
||||
|
||||
use clippy_config::msrvs::Msrv;
|
||||
use clippy_config::Conf;
|
||||
use clippy_utils::higher;
|
||||
use rustc_hir::{Expr, ExprKind, LoopSource, Pat};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -717,10 +718,10 @@ pub struct Loops {
|
|||
enforce_iter_loop_reborrow: bool,
|
||||
}
|
||||
impl Loops {
|
||||
pub fn new(msrv: Msrv, enforce_iter_loop_reborrow: bool) -> Self {
|
||||
pub fn new(conf: &'static Conf) -> Self {
|
||||
Self {
|
||||
msrv,
|
||||
enforce_iter_loop_reborrow,
|
||||
msrv: conf.msrv.clone(),
|
||||
enforce_iter_loop_reborrow: conf.enforce_iter_loop_reborrow,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use rustc_lint::LateContext;
|
|||
use rustc_middle::mir::FakeReadCause;
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::Span;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) {
|
||||
if let Some(higher::Range {
|
||||
|
|
@ -114,7 +115,6 @@ impl MutatePairDelegate<'_, '_> {
|
|||
struct BreakAfterExprVisitor {
|
||||
hir_id: HirId,
|
||||
past_expr: bool,
|
||||
past_candidate: bool,
|
||||
break_after_expr: bool,
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,6 @@ impl BreakAfterExprVisitor {
|
|||
let mut visitor = BreakAfterExprVisitor {
|
||||
hir_id,
|
||||
past_expr: false,
|
||||
past_candidate: false,
|
||||
break_after_expr: false,
|
||||
};
|
||||
|
||||
|
|
@ -135,21 +134,19 @@ impl BreakAfterExprVisitor {
|
|||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for BreakAfterExprVisitor {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
|
||||
if self.past_candidate {
|
||||
return;
|
||||
}
|
||||
|
||||
type Result = ControlFlow<()>;
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) -> ControlFlow<()> {
|
||||
if expr.hir_id == self.hir_id {
|
||||
self.past_expr = true;
|
||||
ControlFlow::Continue(())
|
||||
} else if self.past_expr {
|
||||
if matches!(&expr.kind, ExprKind::Break(..)) {
|
||||
self.break_after_expr = true;
|
||||
}
|
||||
|
||||
self.past_candidate = true;
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
intravisit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use clippy_utils::visitors::contains_break_or_continue;
|
|||
use rustc_ast::util::parser::PREC_PREFIX;
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{is_range_literal, BorrowKind, Expr, ExprKind, Pat};
|
||||
use rustc_hir::{is_range_literal, BorrowKind, Expr, ExprKind, Pat, PatKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::sym;
|
||||
|
|
@ -70,7 +70,10 @@ pub(super) fn check<'tcx>(
|
|||
&& !contains_break_or_continue(body)
|
||||
{
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let pat_snip = snippet_with_applicability(cx, pat.span, "..", &mut applicability);
|
||||
let mut pat_snip = snippet_with_applicability(cx, pat.span, "..", &mut applicability);
|
||||
if matches!(pat.kind, PatKind::Or(..)) {
|
||||
pat_snip = format!("({pat_snip})").into();
|
||||
}
|
||||
let mut arg_snip = snippet_with_applicability(cx, arg_expression.span, "..", &mut applicability);
|
||||
let mut block_str = snippet_with_applicability(cx, block.span, "..", &mut applicability).into_owned();
|
||||
block_str.remove(0);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use rustc_hir::def_id::DefIdMap;
|
|||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{Expr, ExprKind, HirIdSet, QPath};
|
||||
use rustc_lint::LateContext;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
|
||||
if constant(cx, cx.typeck_results(), cond).is_some() {
|
||||
|
|
@ -35,11 +36,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'
|
|||
};
|
||||
let mutable_static_in_cond = var_visitor.def_ids.items().any(|(_, v)| *v);
|
||||
|
||||
let mut has_break_or_return_visitor = HasBreakOrReturnVisitor {
|
||||
has_break_or_return: false,
|
||||
};
|
||||
has_break_or_return_visitor.visit_expr(expr);
|
||||
let has_break_or_return = has_break_or_return_visitor.has_break_or_return;
|
||||
let mut has_break_or_return_visitor = HasBreakOrReturnVisitor;
|
||||
let has_break_or_return = has_break_or_return_visitor.visit_expr(expr).is_break();
|
||||
|
||||
if no_cond_variable_mutated && !mutable_static_in_cond {
|
||||
span_lint_and_then(
|
||||
|
|
@ -59,25 +57,19 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'
|
|||
}
|
||||
}
|
||||
|
||||
struct HasBreakOrReturnVisitor {
|
||||
has_break_or_return: bool,
|
||||
}
|
||||
struct HasBreakOrReturnVisitor;
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.has_break_or_return {
|
||||
return;
|
||||
}
|
||||
|
||||
type Result = ControlFlow<()>;
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) -> ControlFlow<()> {
|
||||
match expr.kind {
|
||||
ExprKind::Ret(_) | ExprKind::Break(_, _) => {
|
||||
self.has_break_or_return = true;
|
||||
return;
|
||||
return ControlFlow::Break(());
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
walk_expr(self, expr);
|
||||
walk_expr(self, expr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue