Rustfix implementation


An idea of a ‘rustfix’ tool has been floated several times. Has anybody started working on it yet?

I’m interested in writing something quite close to this.

After manual C to Rust conversion I end up needing to manually fix code to make it more idiomatic and e.g. convert pointers to slices, or replace integer return type with Result. These types of source-to-source changes sound quite close to what rustfix will need to do.

  • Has work on rustfix started yet?
  • If not, are there any components ready to get started? (e.g. Rust parser and serializer that preserves whitespace and comments accurately (syntex is inaccurate, and also dead)).



I have a tool that I’ve been working on. I’m not sure it exactly fits the use-case you describe, but probably falls into the same category of tool and perhaps could be extended to cover these use-cases.

It’s a search-replace tool that matches code based on syntax trees. The search/replace code can contain placeholders. Placeholders are typed, possibly with generics and the placeholder will only match expressions that unify with the type of the placeholder.

It also supports replacing patterns, types and trait references, although these are a bit more limited. e.g. types don’t support placeholders yet.

It doesn’t alter file contents outside of what is matched. It also preserves formatting and comments within whatever is matched by placeholders. Comments adjacent to placeholders are not currently always preserved, but I’ve got ideas how to fix that.

It’s not quite ready to release yet though. I’ve done the development so far from tests and haven’t actually built the command line, or cargo integration yet. I’ve had pretty limited time lately since my partner has been working on her thesis, so I’ve been looking after the kids more than usual. Mostly I’ve just been making the occasional update to fix it when changes in the nightly compiler break it. Hoping to have more time soon.

It’s very much nightly only since it uses HIR in order to get type information.


Yes, that’s very interesting! It would be great if you could share it.


Certainly. There might be a bit of a delay since I’ve got to get approval from work to publish it. Hopefully that won’t take too long.


OK, sorry that took a while. I spent probably too long discussing licensing with the people I needed approval to release. It’s finally up at Let me know if you have any comments, suggestions etc