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

#![cfg(platform)] causes rustc to ignore #![allow(...)] directives #78237

Open
kjvalencik opened this issue Oct 22, 2020 · 3 comments
Open

#![cfg(platform)] causes rustc to ignore #![allow(...)] directives #78237

kjvalencik opened this issue Oct 22, 2020 · 3 comments
Labels
A-attributes Area: #[attributes(..)] A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kjvalencik
Copy link

I tried this code:

#![cfg(windows)]
#![allow(missing_docs)]

pub fn a_function() {}

And ran RUSTFLAGS="-D missing_docs" cargo check.

I expected to see this happen:

On all platforms, the missing docs on a_function to be allowed.

Instead, this happened:

On Windows it worked as expected and on other platforms (Linux, macOS):

error: missing documentation for crate
 --> src/lib.rs:1:1
  |
1 | / #![cfg(windows)]
2 | | #![allow(missing_docs)]
3 | |
4 | | pub fn a_function() {}
  | |______________________^

Meta

rustc --version --verbose:

rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-apple-darwin
release: 1.46.0
LLVM version: 10.0

Also tested:

rustc 1.49.0-nightly (1eaadebb3 2020-10-21)
binary: rustc
commit-hash: 1eaadebb3dee31669c7649b32747381d11614fae
commit-date: 2020-10-21
host: x86_64-apple-darwin
release: 1.49.0-nightly
LLVM version: 11.0
@kjvalencik kjvalencik added the C-bug Category: This is a bug. label Oct 22, 2020
@Mark-Simulacrum
Copy link
Member

Command line arguments generally override things specified in code -- I believe this is expected behavior. Is there a reason you're not expecting them to override the lint specification in code? I believe that's pretty common behavior in most tooling.

It would be good to see if we can provide a help: to the lint that indicates the CLI override of the allow, though.

@kjvalencik
Copy link
Author

@Mark-Simulacrum For lints, allow in code takes precedence over command line arguments. This works as expected without the #![cfg(windows)].

The ideal scenario is for explicit allows to override command line arguments. This allows to keep deny(lint) out of code which is problematic because it fails during development, it also relies on remembering to put the deny in all new code.

Denying with a command line flag allows globally applying the lints only in CI.

@kjvalencik
Copy link
Author

Adding to this, even if you do document the code, the lint still fails--presumably because #![cfg(windows)] is removing the documentation, but the code is still linted.

error: missing documentation for the crate
 --> src/lib.rs:1:1
  |
1 | / //! Doc this
2 | | #![cfg(windows)]
3 | |
4 | | /// Doc this
5 | | pub fn a_function() {}
  | |______________________^
  |
  = note: requested on the command line with `-D missing-docs`

error: aborting due to previous error

@jyn514 jyn514 added A-attributes Area: #[attributes(..)] A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: #[attributes(..)] A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants