Skip to content

cargo::redundant_readme false positive when having multiple readme candidates #17206

Description

@weihanglo

Problem

cargo::redundant_readme lint only checks that the value is one of the default filenames,
without probing the filesystem.
But inference picks the first existing file in ["README.md", "README.txt", "README"].

For example, readme = "README.txt" with README.md also present -> removal switches to README.md.

Steps

#[cargo_test]
fn lower_priority_readme() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
[package]
name = "foo"
edition = "2015"
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![[r#"
[WARNING] explicit `package.readme` can be inferred
 --> Cargo.toml:6:1
  |
6 | 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();
}

Possible Solution(s)

Add filesystem probes to the lint? Or this works as intended?

Notes

Found during the stabilization review.
I don't think it is a stabilization blocker though.

Version

cargo 1.99.0-nightly (59800466c 2026-07-07)
release: 1.99.0-nightly
commit-hash: 59800466c5c41c444d264b1010b4d57e85a7117f
commit-date: 2026-07-07
host: aarch64-apple-darwin
libgit2: 1.9.4 (sys:0.21.0 vendored)
libcurl: 8.7.1 (sys:0.4.90+curl-8.21.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.6.3 9 Jun 2026
os: Mac OS 26.5.2 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions