rustfix icon indicating copy to clipboard operation
rustfix copied to clipboard

Guided renames by deprecations

Open bluss opened this issue 6 years ago • 3 comments

(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")]

bluss avatar Nov 20 '18 21:11 bluss

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?

killercup avatar Nov 20 '18 21:11 killercup

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.

llogiq avatar Nov 20 '18 22:11 llogiq

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?

bluss avatar Dec 06 '20 14:12 bluss