#[deprecated] on re-exported items does not work (original) (raw)
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. Details
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
DeprecatedAliastoo:
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🔞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 constantDeprecatedAlias: 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🔞13
|
18 | let _ = DeprecatedAlias {};
| ^^^^^^^^^^^^^^^
- | help: use the non-deprecated path:
New