Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Guided renames by deprecations #151

Closed
bluss opened this issue Nov 20, 2018 · 5 comments
Closed

Guided renames by deprecations #151

bluss opened this issue Nov 20, 2018 · 5 comments

Comments

@bluss
Copy link
Member

bluss commented Nov 20, 2018

(Excuse me if this is not the right place to bring this up.)

What if a library could use #[deprecated] + a convention about what to put in the note to enable cargo fix to automatically fix the deprecation, if it's due to a rename.

#[deprecated(note="Renamed to `new_name`")]
pub fn old_name(x: i32) -> i32 {
    new_name(x)
}

pub fn new_name(x: i32) -> i32 {
    unimplemented!()
}

Here's the rustc warning:

Warning: use of deprecated item 'old_name': Renamed to `new_name`
  --> src/visit/reversed.rs:56:40
   |
56 |         old_name(3)
   |         ^^^^^^^^
   |
   = note: #[warn(deprecated)] on by default

In that sense it is guided by rustc. I don't know at all if this is doable, but I imagine it would require some kind of agreed "protocol" for the format of the deprecation message. A more formal way to go about it would be to design this in rustc and for example use a new attribute or a new option on the attribute like #[deprecated(renamed_to="new_name")]

@killercup
Copy link
Member

Very interesting!

Technically, this will require attibutes (or, this specific attribute) to produce diagnostic messages that contain suggestions -- which I think is already somewhat possible with proc macros?

@llogiq
Copy link

llogiq commented Nov 20, 2018

Technically, the attribute will already show the diagnostic message – we'd just need to match the note (e.g. "renamed to ...") and set the applicability if it fits.

@bluss
Copy link
Member Author

bluss commented Dec 6, 2020

rustc_deprecated supports the suggestion="new method name" for this. Could we still live with just a convention? Or should the deprecated attribute get a new feature to match rustc_deprecated?

@jhpratt
Copy link
Member

jhpratt commented Jun 6, 2023

This is tracked in rust-lang/rust#94785.

@ehuss
Copy link
Collaborator

ehuss commented Nov 22, 2023

Closing in preference to rust-lang/rust#94785.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants