about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-11-09 13:51:46 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2024-11-09 13:55:20 +0100
commit223bffd0d2c7f26145d2e7861dbe5cbb0aff830e (patch)
tree4fcbdfa104e99bd00eeec1452910294a6744c6d8
parentf712eb5cdccd121d0569af12f20e6a0fabe4364d (diff)
downloadrust-223bffd0d2c7f26145d2e7861dbe5cbb0aff830e.tar.gz
rust-223bffd0d2c7f26145d2e7861dbe5cbb0aff830e.zip
Fix `large_include_file` lint being triggered all the time by doc comments
-rw-r--r--clippy_lints/src/large_include_file.rs2
-rw-r--r--tests/ui-toml/large_include_file/empty.txt0
-rw-r--r--tests/ui-toml/large_include_file/large_include_file.rs6
3 files changed, 7 insertions, 1 deletions
diff --git a/clippy_lints/src/large_include_file.rs b/clippy_lints/src/large_include_file.rs
index ab3d19f89c3..4f22931a4de 100644
--- a/clippy_lints/src/large_include_file.rs
+++ b/clippy_lints/src/large_include_file.rs
@@ -94,6 +94,8 @@ impl LateLintPass<'_> for LargeIncludeFile {
             // Currently, rustc limits the usage of macro at the top-level of attributes,
             // so we don't need to recurse into each level.
             && let AttrKind::Normal(ref normal) = attr.kind
+            && let Some(doc) = attr.doc_str()
+            && doc.as_str().len() as u64 > self.max_file_size
             && let AttrArgs::Eq(_, AttrArgsEq::Hir(ref meta)) = normal.item.args
             && !attr.span.contains(meta.span)
             // Since the `include_str` is already expanded at this point, we can only take the
diff --git a/tests/ui-toml/large_include_file/empty.txt b/tests/ui-toml/large_include_file/empty.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui-toml/large_include_file/empty.txt
diff --git a/tests/ui-toml/large_include_file/large_include_file.rs b/tests/ui-toml/large_include_file/large_include_file.rs
index dc9349f75a0..8a6dd36501c 100644
--- a/tests/ui-toml/large_include_file/large_include_file.rs
+++ b/tests/ui-toml/large_include_file/large_include_file.rs
@@ -15,5 +15,9 @@ const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
 const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt");
 //~^ large_include_file
 
-#[doc = include_str!("too_big.txt")] //~ large_include_file
+#[doc = include_str!("too_big.txt")]
+//~^ large_include_file
+// Should not lint!
+// Regression test for <https://github.com/rust-lang/rust-clippy/issues/13670>.
+#[doc = include_str!("empty.txt")]
 fn main() {}