rust-diagnostics

This is a utility to insert diagnostics of code fragments as comments in Rust code and checks whether a warning/error in the diagnostics has been fixed in git commit history.

Rust compiler displays many diagnostics to the console, using file name and line numbers to indicate their exact locations. Without an IDE, it requires a programmer to go back and forth between command console and the editor.

This utility inserts the diagnostic messages in-place, which could enable transformer-based machine learning approaches to analyse Rust diagnostic semantics.

Through additional arguments, this utility also checks whether a warning found in revision r1 has been manually fixed by a revision r2.

Currently we integrate the utility with clippy and git-rs.

optional feature: fix

Automated fix of warnings by clippy could be recorded as transformations, including the programs before and after of fixes. Furthermore, scope of such transformations are narrowed down to the individual items, making it easier to spot whether the exact warnings get fixed or not. The remaining unfixed warnings are still kept in the transformed results.

Installation

bash cargo install rust-diagnostics

Usage:

bash rust-diagnostics [--patch <commit_id> [--confirm]]

Inserting warnings info into Rust code

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)/*

[Warning(clippy::dbg_macro)

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 aWarningas the diagnostic code, andclippy::dbgmacroas the name of the lint rule violated by the codedbg!(&msg)`.

Analyse the manually fixed warnings from change history

If you inspect the code and wonder whether revision r2 has fixed the warning of revision r1, you can use git log -p to identify the revisions' commit id first. Then run bash git checkout $r1 rust-diagnostics --patch $r2 --confirm The output includes the count of warnings of $r1 and the hunks between $r1..$r2 that matters to fix the warnings listed in front of the hunks.

(optional) Generating inputs and outputs of warning fixes by cargo clippy --fix

This requires that the 'fix’ feature being enabled when building the tool.

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.

(optional) Inherit Rustc flags to analyse diagnostics

This requires that the 'rustc_flags’ feature being enabled when building the tool.

Rustc flags used in .cargo/config are typically inherited by the cargo clippy. In this way one can avoid typing multiple -Wclippy::... options from the command line. Using rustc_flags feature it is possible to inherit them from the compiler options.

Updates (including bugfixes)

Acknowledgement