Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cargo/diagnostics/rules/redundant_readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::diagnostics::LintLevelSource;
use crate::diagnostics::ScopedDiagnosticStats;
use crate::diagnostics::get_key_value_span;
use crate::diagnostics::workspace_rel_path;
use crate::util::toml::DEFAULT_README_FILES;
use crate::util::toml::default_readme_from_package_root;

pub static LINT: &Lint = &Lint {
name: "redundant_readme",
Expand Down Expand Up @@ -109,7 +109,7 @@ fn lint_package_inner(
return Ok(());
};

if !DEFAULT_README_FILES.contains(&readme.as_str()) {
if default_readme_from_package_root(pkg.root()).as_deref() != Some(readme) {

@epage epage Jul 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the check of DEFAULT_README_FILES as a fast path?

View changes since the review

return Ok(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ pub const DEFAULT_README_FILES: [&str; 3] = ["README.md", "README.txt", "README"

/// Checks if a file with any of the default README file names exists in the package root.
/// If so, returns a `String` representing that name.
fn default_readme_from_package_root(package_root: &Path) -> Option<String> {
pub(crate) fn default_readme_from_package_root(package_root: &Path) -> Option<String> {
for &readme_filename in DEFAULT_README_FILES.iter() {
if package_root.join(readme_filename).is_file() {
return Some(readme_filename.to_string());
Expand Down
68 changes: 68 additions & 0 deletions tests/testsuite/lints/redundant_readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,74 @@ redundant_readme = "warn"
.run();
}

#[cargo_test]
fn lower_priority_readme() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
readme = "README.txt"

[lints.cargo]
default = { level = "allow", priority = -1 }
redundant_readme = "warn"
"#,
)
.file("src/main.rs", "fn main() {}")
.file("README.md", "")
.file("README.txt", "")
.build();

p.cargo("fetch -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr_data(str![""])
.run();
}

#[cargo_test]
fn explicit_readme_txt() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
readme = "README.txt"

[lints.cargo]
default = { level = "allow", priority = -1 }
redundant_readme = "warn"
"#,
)
.file("src/main.rs", "fn main() {}")
.file("README.txt", "")
.build();

p.cargo("fetch -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr_data(str![[r#"
[WARNING] explicit `package.readme` can be inferred
--> Cargo.toml:7:1
|
7 | readme = "README.txt"
| ^^^^^^^^^^^^^^^^^^^^^
|
= [NOTE] `cargo::redundant_readme` is set to `warn` in `[lints]`
[HELP] consider removing `package.readme`
[WARNING] `foo` (manifest) generated 1 warning

"#]])
.run();
}

#[cargo_test]
fn implicit_readme() {
let p = project()
Expand Down