Skip to content

#[deprecated] lint doesn't trigger when overriding deprecated method #98990

@m-ou-se

Description

@m-ou-se
Member

This doesn't give any warnings, even though std::error::Error::description is deprecated:

impl std::error::Error for E {
    fn description(&self) -> &str {
        ":)"
    }
}

It seems like this is a deliberate decision:

// Pass `None` to skip deprecation warnings.
self.tcx.check_stability(def_id, None, impl_item_ref.span, None);

Substituting that first None for Some(impl_item_ref.id.hir_id()) makes it work.

Doing so results in the lint triggering in exactly one place in std:

impl Error for Infallible {
fn description(&self) -> &str {
match *self {}
}
}

That's because in all other cases, we have #[allow(deprecated)] there:

impl Error for string::FromUtf16Error {
#[allow(deprecated)]
fn description(&self) -> &str {
"invalid utf-16"
}
}

Which is suprising, as that lint doesn't tigger there, making that #[allow] unnecessary.

It seems as if it used to be necessary in the past, but now no longer is.

Did #[deprecated] trigger on overrides in the past? Was that behavior changed on purpose? Or is it a bug that it doesn't do that anymore?

Activity

added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
A-diagnosticsArea: Messages for errors, warnings, and lints
on Jul 6, 2022
m-ou-se

m-ou-se commented on Jul 6, 2022

@m-ou-se
MemberAuthor

cc @rust-lang/libs-api, should the #[deprecated] lint trigger here or not?

eddyb

eddyb commented on Jul 7, 2022

@eddyb
Member

(reposting #98991 (comment) here as well)

I'm not sure what happened here, but the lack of tests for this is worrying (and may explain how this happened, if it was accidental).

EDIT: much more comprehensive analysis posted in #98991 (comment).

thomaseizinger

thomaseizinger commented on Dec 23, 2022

@thomaseizinger
Contributor

I just ran into this. I'd like to guide my users away from implementing one trait function to new ones in a backwards-compatible way. My thinking was:

  • Add new trait functions with default implementations that call the old one.
  • Deprecate the old function.

I was expecting to have users (the trait provides a plugin-like functionality, so has many external users outside the crate) to see a deprecation warning that they should no longer implement this function but a new one instead.

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Dec 28, 2024
hkBst

hkBst commented on Feb 14, 2025

@hkBst
Member

@rustbot ping libs-api

(see #98990 (comment))

rustbot

rustbot commented on Feb 14, 2025

@rustbot
Collaborator

Error: Parsing ping command in comment failed: ...'g libs-api' | error: expected end of command at >| ' (see http'...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

rustbot

rustbot commented on Feb 14, 2025

@rustbot
Collaborator

Error: Only Rust team members can ping teams.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

added
I-lang-nominatedNominated for discussion during a lang team meeting.
I-libs-api-nominatedNominated for discussion during a libs-api team meeting.
on Mar 29, 2025
removed
I-libs-api-nominatedNominated for discussion during a libs-api team meeting.
on Apr 8, 2025
joshtriplett

joshtriplett commented on May 7, 2025

@joshtriplett
Member

Sorry for the long delay in this being talked about!

We talked about this in today's @rust-lang/lang meeting, and those present (myself, @traviscross, and (representing libs-api) @Amanieu) were all generally in favor. We did feel this needs an FCP, though.

Please do provide a PR implementing this, mark it I-lang-nominated, and we'll FCP it.

added
I-lang-radarItems that are on lang's radar and will need eventual work or consideration.
and removed
I-lang-nominatedNominated for discussion during a lang team meeting.
on May 8, 2025
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-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.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

      Participants

      @eddyb@joshtriplett@Amanieu@m-ou-se@traviscross

      Issue actions

        #[deprecated] lint doesn't trigger when overriding deprecated method · Issue #98990 · rust-lang/rust