Skip to content

Should #[expect(warnings)] at some point warn that there are no warnings in the annotated code? #130609

@kamulos

Description

@kamulos

Code

#[expect(warnings)]
pub fn foo() {}

Current output

rustc is happy with an expect annotation on code, that does not trigger a warning

Desired output

probably this should ask to remove the expect annotation?

Rationale and extra context

expect(warnings) is probably not the most idiomatic thing to do, but I found it in my code. And I would think that this behaves like other expect annotations.

Other cases

No response

Rust Version

rustc 1.83.0-nightly (f79a912d9 2024-09-18)
binary: rustc
commit-hash: f79a912d9edc3ad4db910c0e93672ed5c65133fa
commit-date: 2024-09-18
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Anything else?

No response

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Sep 20, 2024
added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Sep 20, 2024
jieyouxu

jieyouxu commented on Sep 20, 2024

@jieyouxu
Member

warnings is a special pseudo lint group, possibly lint expectations behave strangely against that.

Noratrieb

Noratrieb commented on Sep 20, 2024

@Noratrieb
Member

expect(warnings) is a paradox that cannot make sense. if there are no warnings, it will cause a warning, which is a warning, so now there are warnings, which means it shouldn't trigger.
i think the best thing would be to make it an error, but since it's shipped already, we may need to make it a no-op+"don't do this" warning.
@xFrednet

xFrednet

xFrednet commented on Sep 20, 2024

@xFrednet
Member

Currently, it's defined that the unfulfilled_lint_expectations lint can't be expected. So there could be some logic where #[expect(warnings)] could work.

However, the unfulfilled_lint_expectations is emitted at the node that the #[expect] is attached to. My guess is that there is a weird combination with it being a pseudo lint group and the paradox that @Noratrieb mentioned. Even if the lint is emitted, the #[expect()] should suppress it again. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-lint_reasons`#![feature(lint_reasons)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kamulos@xFrednet@jieyouxu@Noratrieb

        Issue actions

          Should `#[expect(warnings)]` at some point warn that there are no warnings in the annotated code? · Issue #130609 · rust-lang/rust