mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 02:00:00 +03:00
len_zero: Check HIR tree first
This commit is contained in:
@@ -121,11 +121,9 @@
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for LenZero {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let ItemKind::Trait(_, _, _, _, trait_items) = item.kind {
|
||||
if let ItemKind::Trait(_, _, _, _, trait_items) = item.kind
|
||||
&& !item.span.from_expansion()
|
||||
{
|
||||
check_trait_items(cx, item, trait_items);
|
||||
}
|
||||
}
|
||||
@@ -162,17 +160,14 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>)
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Let(lt) = expr.kind
|
||||
&& has_is_empty(cx, lt.init)
|
||||
&& match lt.pat.kind {
|
||||
PatKind::Slice([], None, []) => true,
|
||||
PatKind::Lit(lit) if is_empty_string(lit) => true,
|
||||
_ => false,
|
||||
}
|
||||
&& !expr.span.from_expansion()
|
||||
&& has_is_empty(cx, lt.init)
|
||||
{
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
||||
@@ -190,7 +185,9 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
);
|
||||
}
|
||||
|
||||
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind {
|
||||
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind
|
||||
&& !expr.span.from_expansion()
|
||||
{
|
||||
// expr.span might contains parenthesis, see issue #10529
|
||||
let actual_span = span_without_enclosing_paren(cx, expr.span);
|
||||
match cmp {
|
||||
|
||||
Reference in New Issue
Block a user