Skip to content

Commit 03036c1

Browse files
committed
large_include_file: Check HIR tree first.
1 parent c3dd028 commit 03036c1

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

clippy_lints/src/large_include_file.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_note;
2-
use clippy_utils::is_lint_allowed;
32
use clippy_utils::macros::root_macro_call_first_node;
43
use rustc_ast::LitKind;
54
use rustc_hir::{Expr, ExprKind};
@@ -52,24 +51,19 @@ impl_lint_pass!(LargeIncludeFile => [LARGE_INCLUDE_FILE]);
5251

5352
impl LateLintPass<'_> for LargeIncludeFile {
5453
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
55-
if let Some(macro_call) = root_macro_call_first_node(cx, expr)
56-
&& !is_lint_allowed(cx, LARGE_INCLUDE_FILE, expr.hir_id)
57-
&& (cx.tcx.is_diagnostic_item(sym::include_bytes_macro, macro_call.def_id)
58-
|| cx.tcx.is_diagnostic_item(sym::include_str_macro, macro_call.def_id))
59-
&& let ExprKind::Lit(lit) = &expr.kind
60-
{
61-
let len = match &lit.node {
54+
if let ExprKind::Lit(lit) = &expr.kind
55+
&& let len = match &lit.node {
6256
// include_bytes
6357
LitKind::ByteStr(bstr, _) => bstr.len(),
6458
// include_str
6559
LitKind::Str(sym, _) => sym.as_str().len(),
6660
_ => return,
67-
};
68-
69-
if len as u64 <= self.max_file_size {
70-
return;
7161
}
72-
62+
&& len as u64 > self.max_file_size
63+
&& let Some(macro_call) = root_macro_call_first_node(cx, expr)
64+
&& (cx.tcx.is_diagnostic_item(sym::include_bytes_macro, macro_call.def_id)
65+
|| cx.tcx.is_diagnostic_item(sym::include_str_macro, macro_call.def_id))
66+
{
7367
span_lint_and_note(
7468
cx,
7569
LARGE_INCLUDE_FILE,

0 commit comments

Comments
 (0)