Skip to content

Using deprecated items within the crate that deprecated them issues warnings #47219

Open
@CasualX

Description

@CasualX

When deprecating an item, you typically still want the helper methods supporting it to work without the compiler whining that the item is deprecated.

I tried this code: playground

#[deprecated]
pub struct Foo;

impl Foo {
    fn foo() -> Foo { Foo }
}

I expected to see this happen: The code compiles without deprecation warnings.

Instead, this happened: Litterally every usage of Foo gets a use of deprecated item Foo warning.

The fact that I'm deprecating an item doesn't mean the crate itself should now be spammed with deprecation warnings. Working around it by either a global #![allow(deprecated)] will swallow legitimate deprecation warnings or require all uses to be tagged with it.

Meta

Playground, all channels (how do you get the version info from the playground?)

Activity

CasualX

CasualX commented on Jan 5, 2018

@CasualX
Author

Whelp, I only read the RFC (rust-lang/rfcs#1270), not its accompanying tracking issue (#29935) where some people have written concerns about the extreme verbosity of deprecated warnings but the discussion died out.

I was thinking in the direction of allowing access to deprecated items in the crate which defines it in its entirety but I imagine that's more something for rust-lang/rfcs. Still the extreme verbosity of deprecated warning deserves an issue.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
on Feb 6, 2018
stevenroose

stevenroose commented on Jan 16, 2020

@stevenroose

So I still have this issue. We deprecated a type, and suddenly we get tens of deprecation warnings of internal usage of this type, which are just method implementations on those types. Adding a deprecation warning to all these methods doesn't change anything.

I tried adding #[allow(deprecated)] to the impl block of the deprecated type, but then I got this weird warning message without line number (albeit shorter):

warning: use of deprecated item 'util::bip143::SighashComponents': please use `SigHashCache` instead
  |
  = note: `#[warn(deprecated)]` on by default

warning: use of deprecated item 'util::bip143::SighashComponents': please use `SigHashCache` instead

    Finished dev [unoptimized + debuginfo] target(s) in 2.95s
added 2 commits that reference this issue on Nov 3, 2020
WiSaGaN

WiSaGaN commented on Apr 2, 2021

@WiSaGaN
Contributor

Another related case is whether we should still output deprecated usage warnings for deprecated items inside an already deprecated item.

Say we have an deprecated item Foo in crate foo, and we have below code (in crate foo or in another crate foo2)

#[deprecated]
pub fn drop_foo(f: Foo) {
}

In this case the usage is already in a deprecated function, there is little upside to change the already deprecated code. We can however to add an option if it may indeed be useful in some cases.

added
C-bugCategory: This is a bug.
and removed
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
on Dec 2, 2023
Enselic

Enselic commented on Nov 12, 2024

@Enselic
Member

When deprecating an item, you typically still want the helper methods supporting it to work without the compiler whining that the item is deprecated.

Typically you want to know about all usages of a deprecated item, since you want to remove all usage of it. And where you want to temporarily still use it it makes sense to have to add #[allow(deprecated)]. I use the term "temporary" since long term the item will be removed.

Triage: Changing to T-lang since I don't think it's self evident that this should be changed.

added
T-langRelevant to the language team
and removed
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 12, 2024
CasualX

CasualX commented on Nov 15, 2024

@CasualX
Author

Typically you want to know about all usages of a deprecated item, since you want to remove all usage of it. And where you want to temporarily still use it it makes sense to have to add #[allow(deprecated)]. I use the term "temporary" since long term the item will be removed.

When I made this issue I came from a perspective of using deprecated as a tool to guide consumers of the crate on what to use (without breaking compatibility).

Within my own crate I can just xref all uses and break/fix things as there is no compatibility hazard.

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Dec 28, 2024
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-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-deprecatedLint: deprecatedT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Enselic@stevenroose@WiSaGaN@pietroalbini@CasualX

        Issue actions

          Using deprecated items within the crate that deprecated them issues warnings · Issue #47219 · rust-lang/rust