Skip to content

merged doctests: implicit unused overrides explicit attributes with no_run #130681

Closed
@ehuss

Description

@ehuss

With the 2024 merged doctests, there is a slight change in behavior with regards to the unused lints with a no_run test. Because there is an implicit #![allow(unused)] on each test when the test is no_run (code), this overrides any #![doc(test(attr(...)))] attributes.

When building standalone, this doesn't happen because I believe this code checks for any doc test attributes before adding the allow(unused).

I tried this code:

#![doc(test(attr(allow(unused_variables), deny(warnings))))]

/// Example
///
/// ```rust,no_run
/// trait T { fn f(); }
/// ```
pub fn f() {}

On edition 2021, the above will fail because the deny(warnings) generates an error with #[deny(dead_code)] implied by #[deny(warnings)]. This also fails on 2024 with standalone.

On edition 2024, the above will pass.

I generally would expect the behavior to be the same. I'm not sure if it is possible to check if there are any attributes before adding the allow(unused). I'm also unclear why no_run is significant here.

Meta

rustdoc 1.83.0-nightly (da889684c 2024-09-20)
binary: rustdoc
commit-hash: da889684c80508036ff036db8c159ffdcf27648a
commit-date: 2024-09-20
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocA-edition-2024Area: The 2024 editionC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions