This is a utility to insert diagnostics of code fragments as comments in Rust code.
Rust compiler produces many diagnostic information to the console, using file name and line numbers to indicate the exact locations.
However, that requires a programmer to go back and forth between command console and the editor. This utility would make it easier to insert the diagnostic messages in-place.
The diagnostic information added into the code sequence could enable transformer-based machine learning approaches to analyse the semantics of Rust programs.
The automated fixes of warnings are also recorded as transformations, including programs before and after of the fixes. Furthermore, scope of such transformations are narrowed down to the individual items, making it easier to spot the exact warnings get fixed or not. The remaining unfixed warnings are still kept in the transformed results.
Currently we integrate the utility with clippy
.
bash
cargo install rust-diagnostics
bash
rust-diagnostics
The commented code is generated from the Rust code.
Note that this is a result of applying the utilility on its own implementation,
i.e., eating our own dog food. We have manually resolved all the clippy
warnings according to the specified clippy rules, except for the one on
dbg_macro
to show the results as an example:
```rust /#[Warning(clippy::dbg_macro)/dbg!(&r)/*
note: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#dbgmacro
the lint level is defined here
ensure to avoid having uses of it in version control*/;
``
contains a
Warningas the diagnostic code, and
clippy::dbgmacroas the name of the lint rule violated by the code
dbg!(&msg)`.
cargo clippy --fix
The code snippets before fix are listed as *.2.rs
, and after fix are listed
as *.3.rs
under the transform/foo/
folder, where foo.rs
is the Rust code
that contains the fixed warnings.
count_diagnostics.sh
clippy --fix
into the transform
folder txl
through txl-rs
cargo
--message-format=json
option to get diagnostic information from the Rust compiler, which saves tremendous effort in modifying the Rust compiler. Now our solution is kind of independent from the Rust compiler implementations;unwrap()
warnings using if-let
statements;