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.