Skip to content

#[deprecated] on re-exported items does not work #84584

Open
@danielhenrymantilla

Description

Problem

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ac1e0d070ba838247ac3587ca23bbaed

#[derive(PartialEq, Eq)]
struct New;

#[deprecated(note = "bang")]
use New as DeprecatedAlias;

#[deprecated(note = "bang")]
type ConstAndTy = New; // 

#[deprecated(note = "bang")]
#[allow(nonstandard_style)]
const ConstAndTy: New = New;

fn main ()
{
    // 😭 (does not warn)
    let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
    let _ = DeprecatedAlias {};
    
    // OK (does warn)
    let self::ConstAndTy: ConstAndTy = ConstAndTy;
    let _ = ConstAndTy {};
}

The current output is:

  • deprecated warnings for all four usages of ConstAndTy (constant value, type, constant pattern, literal struct constructor).

  • No warnings whatsoever for any of the four usages of DeprecatedAlias.

warning: use of deprecated constant `ConstAndTy`: bang
  --> src/main.rs:21:40
   |
21 |     let self::ConstAndTy: ConstAndTy = ConstAndTy;
   |                                        ^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated constant `ConstAndTy`: bang
  --> src/main.rs:21:9
   |
21 |     let self::ConstAndTy: ConstAndTy = ConstAndTy;
   |         ^^^^^^^^^^^^^^^^

warning: use of deprecated type alias `ConstAndTy`: bang
  --> src/main.rs:21:27
   |
21 |     let self::ConstAndTy: ConstAndTy = ConstAndTy;
   |                           ^^^^^^^^^^

warning: use of deprecated type alias `ConstAndTy`: bang
  --> src/main.rs:22:13
   |
22 |     let _ = ConstAndTy {};
   |             ^^^^^^^^^^

Moreover, even if it were to lint about the use-reexported deprecated item, I suspect there would be no mention of the item at the origin of the re-export, even when visible and not deprecated itself.

Suggested improvement

Ideally:

  • the output should warn about DeprecatedAlias too:

    warning: use of deprecated constant `DeprecatedAlias`: bang
      --> src/main.rs:17:50
       |
    17 |     let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
       |                                                  ^^^^^^^^^^^^^^^
       |
       = note: `#[warn(deprecated)]` on by default
    
    warning: use of deprecated constant `DeprecatedAlias`: bang
      --> src/main.rs:17:9
       |
    17 |     let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
       |         ^^^^^^^^^^^^^^^^^^^^^
    
    warning: use of deprecated type alias `DeprecatedAlias`: bang
      --> src/main.rs:17:32
       |
    17 |     let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
       |                                ^^^^^^^^^^^^^^^
    
    warning: use of deprecated type alias `DeprecatedAlias`: bang
      --> src/main.rs:18:13
       |
    18 |     let _ = DeprecatedAlias {};
       |             ^^^^^^^^^^^^^^^
    
  • And when the source of the re-export is visible to the scope where the deprecated alias is used, it should also suggest using that path instead:

      warning: use of deprecated constant `DeprecatedAlias`: bang
        --> src/main.rs:17:50
         |
      17 |     let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
         |                                                  ^^^^^^^^^^^^^^^
    +    |                                                  help: use the non-deprecated path: `New`
         |
         = note: `#[warn(deprecated)]` on by default
      
      warning: use of deprecated constant `DeprecatedAlias`: bang
        --> src/main.rs:17:9
         |
      17 |     let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
         |         ^^^^^^^^^^^^^^^^^^^^^
    +    |         help: use the non-deprecated path: `self::New`
      
      warning: use of deprecated type alias `DeprecatedAlias`: bang
        --> src/main.rs:17:32
         |
      17 |     let self::DeprecatedAlias: DeprecatedAlias = DeprecatedAlias;
         |                                ^^^^^^^^^^^^^^^
    +    |                                help: use the non-deprecated path: `New`
      
      warning: use of deprecated type alias `DeprecatedAlias`: bang
        --> src/main.rs:18:13
         |
      18 |     let _ = DeprecatedAlias {};
         |             ^^^^^^^^^^^^^^^
    +    |             help: use the non-deprecated path: `New`

Rationale and further discussion

c.f. https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Updating.20reverse.20dependencies.20using.20code.20modification

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-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