Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danielhenrymantilla opened this issue Apr 26, 2021 · 0 comments
Open

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

danielhenrymantilla opened this issue Apr 26, 2021 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Apr 26, 2021

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

@danielhenrymantilla danielhenrymantilla added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 26, 2021
@rustbot rustbot added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Apr 26, 2021
ugur-a added a commit to ugur-a/libaoc that referenced this issue Oct 23, 2024
- leave a reexport for backwards-compatibility
  - mark it as deprecated
    - doesn't actually work, see^[1]

^[1]: rust-lang/rust#84584
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 12, 2024
Add lint rule for `#[deprecated]` on re-exports

As reported in rust-lang#30827 and rust-lang#84584, marking a re-export (`pub use`) with `#[deprecated]` does not produce a warning for consumers. In fact, there are instances of this in the `core` and `std` crates (see past issue rust-lang#82080 where this caused some confusion).

This change modifies the stability annotation visitor to mark `#[deprecated]` annotations on `use` statements with `AnnotationKind::DeprecationProhibited` so that library developers are aware that the annotation is not warning their users as expected.

```rust
#[deprecated]
pub use a_module::ActiveType;
```
```
error: this `#[deprecated]` annotation has no effect
  --> $DIR/deprecated_use.rs:6:1
   |
LL | #[deprecated]
   | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
   |
   = note: `#[deny(useless_deprecated)]` on by default

error: aborting due to 1 previous error
```
Zalathar added a commit to Zalathar/rust that referenced this issue Dec 13, 2024
Add lint rule for `#[deprecated]` on re-exports

As reported in rust-lang#30827 and rust-lang#84584, marking a re-export (`pub use`) with `#[deprecated]` does not produce a warning for consumers. In fact, there are instances of this in the `core` and `std` crates (see past issue rust-lang#82080 where this caused some confusion).

This change modifies the stability annotation visitor to mark `#[deprecated]` annotations on `use` statements with `AnnotationKind::DeprecationProhibited` so that library developers are aware that the annotation is not warning their users as expected.

```rust
#[deprecated]
pub use a_module::ActiveType;
```
```
error: this `#[deprecated]` annotation has no effect
  --> $DIR/deprecated_use.rs:6:1
   |
LL | #[deprecated]
   | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
   |
   = note: `#[deny(useless_deprecated)]` on by default

error: aborting due to 1 previous error
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 13, 2024
Add lint rule for `#[deprecated]` on re-exports

As reported in rust-lang#30827 and rust-lang#84584, marking a re-export (`pub use`) with `#[deprecated]` does not produce a warning for consumers. In fact, there are instances of this in the `core` and `std` crates (see past issue rust-lang#82080 where this caused some confusion).

This change modifies the stability annotation visitor to mark `#[deprecated]` annotations on `use` statements with `AnnotationKind::DeprecationProhibited` so that library developers are aware that the annotation is not warning their users as expected.

```rust
#[deprecated]
pub use a_module::ActiveType;
```
```
error: this `#[deprecated]` annotation has no effect
  --> $DIR/deprecated_use.rs:6:1
   |
LL | #[deprecated]
   | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
   |
   = note: `#[deny(useless_deprecated)]` on by default

error: aborting due to 1 previous error
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 13, 2024
Add lint rule for `#[deprecated]` on re-exports

As reported in rust-lang#30827 and rust-lang#84584, marking a re-export (`pub use`) with `#[deprecated]` does not produce a warning for consumers. In fact, there are instances of this in the `core` and `std` crates (see past issue rust-lang#82080 where this caused some confusion).

This change modifies the stability annotation visitor to mark `#[deprecated]` annotations on `use` statements with `AnnotationKind::DeprecationProhibited` so that library developers are aware that the annotation is not warning their users as expected.

```rust
#[deprecated]
pub use a_module::ActiveType;
```
```
error: this `#[deprecated]` annotation has no effect
  --> $DIR/deprecated_use.rs:6:1
   |
LL | #[deprecated]
   | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
   |
   = note: `#[deny(useless_deprecated)]` on by default

error: aborting due to 1 previous error
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 13, 2024
Add lint rule for `#[deprecated]` on re-exports

As reported in rust-lang#30827 and rust-lang#84584, marking a re-export (`pub use`) with `#[deprecated]` does not produce a warning for consumers. In fact, there are instances of this in the `core` and `std` crates (see past issue rust-lang#82080 where this caused some confusion).

This change modifies the stability annotation visitor to mark `#[deprecated]` annotations on `use` statements with `AnnotationKind::DeprecationProhibited` so that library developers are aware that the annotation is not warning their users as expected.

```rust
#[deprecated]
pub use a_module::ActiveType;
```
```
error: this `#[deprecated]` annotation has no effect
  --> $DIR/deprecated_use.rs:6:1
   |
LL | #[deprecated]
   | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
   |
   = note: `#[deny(useless_deprecated)]` on by default

error: aborting due to 1 previous error
```
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 13, 2024
Add lint rule for `#[deprecated]` on re-exports

As reported in rust-lang#30827 and rust-lang#84584, marking a re-export (`pub use`) with `#[deprecated]` does not produce a warning for consumers. In fact, there are instances of this in the `core` and `std` crates (see past issue rust-lang#82080 where this caused some confusion).

This change modifies the stability annotation visitor to mark `#[deprecated]` annotations on `use` statements with `AnnotationKind::DeprecationProhibited` so that library developers are aware that the annotation is not warning their users as expected.

```rust
#[deprecated]
pub use a_module::ActiveType;
```
```
error: this `#[deprecated]` annotation has no effect
  --> $DIR/deprecated_use.rs:6:1
   |
LL | #[deprecated]
   | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
   |
   = note: `#[deny(useless_deprecated)]` on by default

error: aborting due to 1 previous error
```

try-job: dist-x86_64-linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants