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

rust deprecated suggestion is wrong for mod #85403

Closed
hellow554 opened this issue May 17, 2021 · 4 comments
Closed

rust deprecated suggestion is wrong for mod #85403

hellow554 opened this issue May 17, 2021 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hellow554
Copy link
Contributor

hellow554 commented May 17, 2021

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`
   |
@hellow554 hellow554 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 May 17, 2021
@Rustin170506
Copy link
Member

19 | old::yes();
| ^^^ help: replace the use of the deprecated function: new

Is this a typo?

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

Because I want to bring the number of the issue.

let me try to make it work for modules and inner functions.

@rustbot claim

@hellow554
Copy link
Contributor Author

hellow554 commented May 17, 2021

Is this a typo?

Not sure what you are refering to. To the old module that should be replaced by new?

@Rustin170506
Copy link
Member

Is this a typo?

Not sure what you are refering to. To the old module that should be replaced by new?

I see. No typo. Thanks!

@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 18, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 3, 2021
shrinking the deprecated method span

part of rust-lang#85403

r? `@estebank`
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 3, 2021
shrinking the deprecated method span

part of rust-lang#85403

r? `@estebank`
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 10, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 12, 2021
…tebank

shrinking the deprecated span

ref: rust-lang#85617 (comment)

part of rust-lang#85403

r? `@estebank`

The reason is that if we use method_span directly, it will cause the in_derive_expansion judgment to fail.
@Rustin170506 Rustin170506 removed their assignment Oct 26, 2021
@notriddle
Copy link
Contributor

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=06aa9f19a94ac57e107f9038577b23a6

   Compiling playground v0.0.1 (/playground)
error: use of deprecated function `old::yes`: Use new
  --> src/main.rs:20:10
   |
20 |     old::yes();
   |          ^^^
   |
note: the lint level is defined here
  --> src/main.rs:4:9
   |
4  | #![deny(deprecated)]
   |         ^^^^^^^^^^
help: replace the use of the deprecated function
   |
20 |     old::new();
   |          ~~~

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

error: could not compile `playground` (bin "playground") due to 2 previous errors

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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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

5 participants