Is there a tool to convert original trait bounds to where clauses?

57 Views Asked by At

Is there a tool that can convert original trait bounds like this:

fn foo<V: Debug>(value: V) {
   // ...
}

to the "newer" (2014) where clause:

fn foo<V>(value: V)
where
    V: Debug,
{
    // ...
}

?

This is mostly a stylistic choice; since discussions around those can raise tensions, being able to enforce this (f.e. in CI) would be valuable. Can rustfmt or clippy do this?

1

There are 1 best solutions below

0
On

Rust-analyzer can do this. In VSCode, if you put the cursor in the angle brackets and run quick-fix (cmd/ctrl. by default), Rust analyzer will suggest moving the bound to a where clause, as shown below.

Screenshot of VSCode Rust code and RA