mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
dogfood clippy
This commit is contained in:
parent
1b4e2ef3d7
commit
8f9c738ce9
2 changed files with 61 additions and 52 deletions
|
@ -187,14 +187,11 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
|
|||
}
|
||||
|
||||
fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str, String)> {
|
||||
match output.kind {
|
||||
TyKind::Tup(tys) if tys.is_empty() => {
|
||||
if let TyKind::Tup([]) = output.kind {
|
||||
let sugg = "remove the return type";
|
||||
Some((sugg, String::new()))
|
||||
},
|
||||
_ => {
|
||||
} else {
|
||||
let sugg = "return the output of the future directly";
|
||||
snippet_opt(cx, output.span).map(|snip| (sugg, format!(" -> {snip}")))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_hir::def::{DefKind, Res};
|
|||
use rustc_hir::{Arm, BinOpKind, Expr, ExprKind, Guard, MatchSource, Node, Pat, PatKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use std::borrow::Cow;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
|
@ -105,10 +105,24 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
|
|||
&& let ExprKind::MethodCall(path, recv, args, ..) = if_expr.kind
|
||||
&& let Some(binding) = get_pat_binding(cx, recv, outer_arm)
|
||||
{
|
||||
check_method_calls(cx, outer_arm, path.ident.name, recv, args, if_expr, &binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_method_calls<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
arm: &Arm<'tcx>,
|
||||
method: Symbol,
|
||||
recv: &Expr<'_>,
|
||||
args: &[Expr<'_>],
|
||||
if_expr: &Expr<'_>,
|
||||
binding: &PatBindingInfo,
|
||||
) {
|
||||
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
||||
let slice_like = ty.is_slice() || ty.is_array();
|
||||
|
||||
let sugg = if path.ident.name == sym!(is_empty) {
|
||||
let sugg = if method == sym!(is_empty) {
|
||||
// `s if s.is_empty()` becomes ""
|
||||
// `arr if arr.is_empty()` becomes []
|
||||
|
||||
|
@ -117,7 +131,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
|
|||
} else if slice_like {
|
||||
"[]".into()
|
||||
} else {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
} else if slice_like
|
||||
&& let Some(needle) = args.first()
|
||||
|
@ -133,22 +147,20 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
|
|||
|
||||
if needles.is_empty() {
|
||||
sugg.insert_str(1, "..");
|
||||
} else if path.ident.name == sym!(starts_with) {
|
||||
} else if method == sym!(starts_with) {
|
||||
sugg.insert_str(sugg.len() - 1, ", ..");
|
||||
} else if path.ident.name == sym!(ends_with) {
|
||||
} else if method == sym!(ends_with) {
|
||||
sugg.insert_str(1, ".., ");
|
||||
} else {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
sugg.into()
|
||||
} else {
|
||||
continue;
|
||||
return;
|
||||
};
|
||||
|
||||
emit_redundant_guards(cx, outer_arm, if_expr.span, sugg, &binding, None);
|
||||
}
|
||||
}
|
||||
emit_redundant_guards(cx, arm, if_expr.span, sugg, binding, None);
|
||||
}
|
||||
|
||||
struct PatBindingInfo {
|
||||
|
|
Loading…
Reference in a new issue