Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lints table doesn't seem to work with doctests #12497

Closed
ehuss opened this issue Aug 14, 2023 · 1 comment · Fixed by #12501
Closed

Lints table doesn't seem to work with doctests #12497

ehuss opened this issue Aug 14, 2023 · 1 comment · Fixed by #12501
Labels
A-doctests Area: rustdoc --test A-lints-table Area: [lints] table C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 14, 2023

Problem

Lints defined in the lints table doesn't seem to work with doctests, whereas lints defined as an attribute do work. This seems inconsistent, as I would expect them to behave the same.

Steps

Example rust file:

/// Test
///
/// [`Foo`]
///
/// ```
/// let s = "rust";
/// let s_s = "rust2";
/// ```
pub fn f() {}
pub const Ě: i32 = 1;
pub const Ĕ: i32 = 2;

With manifest:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]

[lints.rust]
confusable-idents = 'allow'

Running cargo check -Zlints produces no warnings:

    Checking foo v0.1.0 (/Users/eric/Temp/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s

Running cargo test --doc -Zlints produces warnings:

   Compiling foo v0.1.0 (/Users/eric/Temp/foo)
    Finished test [unoptimized + debuginfo] target(s) in 0.02s
   Doc-tests foo
warning: found both `Ě` and `Ĕ` as identifiers, which look alike
  --> src/lib.rs:11:11
   |
10 | pub const Ě: i32 = 1;
   |           - other identifier used here
11 | pub const Ĕ: i32 = 2;
   |           ^ this identifier can be confused with `Ě`
   |
   = note: `#[warn(confusable_idents)]` on by default

warning: 1 warning emitted


running 1 test
test src/lib.rs - f (line 5) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s

If you put #![allow(confusable_idents)] at the top of the file, then no warning is generated.

Possible Solution(s)

I think lint flags should be passed to rustdoc here when building the rustdoc comand line. I'm not sure if there was a reason this wasn't added.

Notes

No response

Version

cargo 1.73.0-nightly (d78bbf4bd 2023-08-03)
release: 1.73.0-nightly
commit-hash: d78bbf4bde3c6b95caca7512f537c6f9721426ff
commit-date: 2023-08-03
host: aarch64-apple-darwin
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 7.88.1 (sys:0.4.65+curl-8.2.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Mac OS 13.4.1 [64-bit]
@ehuss ehuss added C-bug Category: bug A-doctests Area: rustdoc --test S-triage Status: This issue is waiting on initial triage. A-lints-table Area: [lints] table labels Aug 14, 2023
@epage
Copy link
Contributor

epage commented Aug 14, 2023

Huh, wasn't aware of this compilation pass since, for the most parts, lints don't apply.

In talking to ehuss, this is from cargo calling into rustdoc to extract doc comments. The lint pass isn't being run but some lints are done in other passes anyways. See also https://rustc-dev-guide.rust-lang.org/diagnostics.html#when-do-lints-run

bors added a commit that referenced this issue Aug 14, 2023
fix(lints): Doctest extraction should respect `[lints]`

Note the first commit shows the bug and the second commit fixes it

Fixes #12497
@bors bors closed this as completed in 9984855 Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: rustdoc --test A-lints-table Area: [lints] table C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants