rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

"Convert `as X` to `X::from`" assist

Open SludgePhD opened this issue 1 month ago • 3 comments

It would be useful if rust-analyzer had an assist that allows quickly changing an as x cast to an x::from-style cast (when the appropriate From impl exists). This would save a bunch of typing when refactoring casts to be more precise (since as _ will wrap).

Additionally, it could also offer a conversion to .try_into().unwrap() when there is only a TryFrom/TryInto impl but no From/Into impl, since that's a common change too.

SludgePhD avatar Dec 08 '25 12:12 SludgePhD

@ShoyuVanilla @ChayimFriedman2 I have raised a PR for this issue. Thanks !

benodiwal avatar Dec 09 '25 22:12 benodiwal

@benodiwal It is not clear that we want to accept new assists currently, or this assist at all. While creating a PR is fine, it'd be better (for you, to not waste work) if you would've discussed with team members whether we want that instead of jumping to implementing it.

ChayimFriedman2 avatar Dec 09 '25 23:12 ChayimFriedman2

Got it, I’ll be careful about this going forward.

benodiwal avatar Dec 10 '25 05:12 benodiwal