Extend large_include_file lint to also work on attributes

This commit is contained in:
Guillaume Gomez 2024-10-30 20:41:34 +01:00
parent 73bad368f2
commit 0c29fccf03
3 changed files with 63 additions and 19 deletions

View file

@ -1,8 +1,8 @@
#![warn(clippy::large_include_file)]
// Good
const GOOD_INCLUDE_BYTES: &[u8; 581] = include_bytes!("large_include_file.rs");
const GOOD_INCLUDE_STR: &str = include_str!("large_include_file.rs");
const GOOD_INCLUDE_BYTES: &[u8; 68] = include_bytes!("../../ui/author.rs");
const GOOD_INCLUDE_STR: &str = include_str!("../../ui/author.rs");
#[allow(clippy::large_include_file)]
const ALLOWED_TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
@ -11,6 +11,9 @@ const ALLOWED_TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt");
// Bad
const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
//~^ large_include_file
const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt");
//~^ large_include_file
#[doc = include_str!("too_big.txt")] //~ large_include_file
fn main() {}

View file

@ -9,12 +9,20 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
= help: to override `-D warnings` add `#[allow(clippy::large_include_file)]`
error: attempted to include a large file
--> tests/ui-toml/large_include_file/large_include_file.rs:14:35
--> tests/ui-toml/large_include_file/large_include_file.rs:15:35
|
LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the configuration allows a maximum size of 600 bytes
error: aborting due to 2 previous errors
error: attempted to include a large file
--> tests/ui-toml/large_include_file/large_include_file.rs:18:1
|
LL | #[doc = include_str!("too_big.txt")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the configuration allows a maximum size of 600 bytes
error: aborting due to 3 previous errors