Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::large_include_file: Checks for the inclusion of large files via include_bytes!() or include_str!()
What it meansChecks for the inclusion of large files via include_bytes!() or include_str!(). It is in the restriction group and off by default.
Does it matter?
Including large files can undesirably increase the size of the binary produced by the compiler. This lint may be used to catch mistakes where an unexpectedly large file is included, or temporarily to obtain a list of all large files.
Lints that forbid language features for specific codebases (no unwrap, no indexing...). Off by default; pick them one by one, never the whole group.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
let included_str = include_str!("very_large_file.txt");
let included_bytes = include_bytes!("very_large_file.txt");
Write this instead
use std::fs;
// You can load the file at runtime
let string = fs::read_to_string("very_large_file.txt")?;
let bytes = fs::read("very_large_file.txt")?;
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
large_include_file = "warn"In code
#![warn(clippy::large_include_file)]One run
cargo clippy -- -W clippy::large-include-fileThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Settings in clippy.toml
max-include-file-size: The maximum size of a file included via include_bytes!() or include_str!(), in bytes
Clippy's own documentation
What it does
Checks for the inclusion of large files via include_bytes!()
or include_str!().
Why restrict this?
Including large files can undesirably increase the size of the binary produced by the compiler. This lint may be used to catch mistakes where an unexpectedly large file is included, or temporarily to obtain a list of all large files.
Example
let included_str = include_str!("very_large_file.txt");
let included_bytes = include_bytes!("very_large_file.txt");
Use instead:
use std::fs;
// You can load the file at runtime
let string = fs::read_to_string("very_large_file.txt")?;
let bytes = fs::read("very_large_file.txt")?;
Configuration
-
max-include-file-size: The maximum size of a file included viainclude_bytes!()orinclude_str!(), in bytes(default:
1000000)
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on Options
- module_name_repetitionsDetects public item names that are prefixed or suffixed by the containing public module’s name
- expect_usedChecks for .expect() or .expect_err() calls on Results and .expect() call on Options
- integer_divisioninteger division
- integer_division_remainder_useduse of `/` has been disallowed in this context
- iter_over_hash_typeiteration over unordered hash-based type
- let_underscore_must_usenon-binding `let` on an expression with `#[must_use]` type
- let_underscore_untypednon-binding `let` without a type annotation
- little_endian_bytesuse of `to_le_bytes`
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on OptionsRead it next →Did this answer your question?