Skip to content

rust deprecated suggestion is wrong for mod #85403

Closed
@hellow554

Description

@hellow554

This is an extension of #84637

First and foremost, thank you @hi-rustin for fixing the original issue in #85018.

Just a quick question: Why did you create a new file instead of extending the existing one?


While the code perfectly works for associated functions, it does not work for modules and inner functions.

Given the following code: (Playground)

#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#![deny(deprecated)]

mod new {
    #[rustc_deprecated(since = "1.0.0", reason = "Use no", suggestion = "no")]
    #[stable(since = "1.0.0", feature = "test")]
    pub fn yes() {}
    pub fn no() {}
}

#[rustc_deprecated(since = "1.0.0", reason = "Use new", suggestion = "new")]
#[stable(since = "1.0.0", feature = "test")]
mod old {
    pub fn yes() {}
}

fn main() {
    old::yes();
    new::yes();
    new::no();
}

The current output is:

error: use of deprecated function `old::yes`: Use new
  --> src/main.rs:19:5
   |
19 |     old::yes();
   |     ^^^^^^^^ help: replace the use of the deprecated function: `new`
   |
note: the lint level is defined here
  --> src/main.rs:3:9
   |
3  | #![deny(deprecated)]
   |         ^^^^^^^^^^

error: use of deprecated function `new::yes`: Use no
  --> src/main.rs:20:5
   |
20 |     new::yes();
   |     ^^^^^^^^ help: replace the use of the deprecated function: `no`

Ideally the output should look like:

error: use of deprecated function `old::yes`: Use new
  --> src/main.rs:19:5
   |
19 |     old::yes();
   |     ^^^ help: replace the use of the deprecated function: `new`
   |
note: the lint level is defined here
  --> src/main.rs:3:9
   |
3  | #![deny(deprecated)]
   |         ^^^^^^^^^^

error: use of deprecated function `new::yes`: Use no
  --> src/main.rs:20:5
   |
20 |     new::yes();
   |          ^^^ help: replace the use of the deprecated function: `no`

Please note that it still says deprecated function. I'm not entirely sure if rustc_deprecated is allowed on modules, but I guess so.

I think it should say:

error: use of deprecated module `old`: Use new
  --> src/main.rs:19:5
   |
19 |     old::yes();
   |     ^^^ help: replace the use of the deprecated module by: `new`
   |

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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