Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::doc_include_without_cfg: Checks if included files in doc comments are included only for cfg(doc)
What it meansChecks if included files in doc comments are included only for cfg(doc). It is in the restriction group and off by default.
Does it matter?
These files are not useful for compilation but will still be included. Also, if any of these non-source code file is updated, it will trigger a recompilation.
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 can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
#![doc = include_str!("some_file.md")]
Write this instead
#![cfg_attr(doc, doc = include_str!("some_file.md"))]
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]
doc_include_without_cfg = "warn"In code
#![warn(clippy::doc_include_without_cfg)]One run
cargo clippy -- -W clippy::doc-include-without-cfgThe [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.
Clippy's own documentation
What it does
Checks if included files in doc comments are included only for cfg(doc).
Why restrict this?
These files are not useful for compilation but will still be included. Also, if any of these non-source code file is updated, it will trigger a recompilation.
Known problems
Excluding this will currently result in the file being left out if the item’s docs are inlined from another crate. This may be fixed in a future version of rustdoc.
Example
#![doc = include_str!("some_file.md")]
Use instead:
#![cfg_attr(doc, doc = include_str!("some_file.md"))]
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
- definition_in_module_rootChecks for definitions (structs, functions, traits, etc.) in mod.rs files
- deref_by_slicingslicing when dereferencing would work
- disallowed_script_identsidentifier `счётчик` has a Unicode script that is not allowed by configuration: Cyrillic
- doc_paragraphs_missing_punctuationChecks for doc comments whose paragraphs do not end with a period or another punctuation mark. Various Markdowns constructs are taken into account to avoid false positives
- else_if_without_else`if` expression with an `else if`, but without a final `else`
- empty_dropempty drop implementation
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?