Skip to content

Warn that #[deprecated] does not work on re-exports #142436

Open
@kpreid

Description

@kpreid

Code

#![allow(unused)]

mod library {
    pub struct Foo;
    
    #[deprecated] // this doesn't work
    pub use Foo as DeprFooUse;
    
    #[deprecated] // this works
    pub type DeprFooAlias = Foo;
}

mod user {
    #[expect(deprecated)]
    use super::library::DeprFooUse as _;

    #[expect(deprecated)]
    use super::library::DeprFooAlias as _;
}

Current output

warning: this lint expectation is unfulfilled
  --> src/lib.rs:14:14
   |
14 |     #[expect(deprecated)]
   |              ^^^^^^^^^^
   |
   = note: `#[warn(unfulfilled_lint_expectations)]` on by default

Desired output

warning: #[deprecated] currently has no effect on `use` items
  --> src/lib.rs:6
  ...

warning: this lint expectation is unfulfilled
  --> src/lib.rs:14:14
  ...

Rationale and extra context

Per #30827, deprecating a re-export is a desired feature. But, that will require substantial work. We can fix a footgun now by warning that #[deprecated] has no effect when applied to use.

Rust Version

1.87.0

@rustbot label +L-deprecated

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsL-deprecatedLint: deprecatedT-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

    Issue actions