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
5 changes: 4 additions & 1 deletion src/diagnostics/rules/redundant_readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::diagnostics::workspace_rel_path;
use crate::workspace::Package;
use crate::workspace::Workspace;
use crate::workspace::parser::DEFAULT_README_FILES;
use crate::workspace::parser::default_readme_from_package_root;

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

if !DEFAULT_README_FILES.contains(&readme.as_str()) {
if !DEFAULT_README_FILES.contains(&readme.as_str())
|| default_readme_from_package_root(pkg.root()).as_deref() != Some(readme)
{
return Ok(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/workspace/parser/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() {
Comment on lines +44 to +45

@epage epage Jul 22, 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.

Sorry, forgot to call out our contrib guide encourages a specific commit structure with tests where a commit is added with the test, showing a reproduction of the undesired behavior. The follow up commit with the fix then also updates the test to show the new behavior.

See also https://epage.github.io/dev/pr-style/#c-split

View changes since the review

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