Follow the steps to implement this recipe:
- Open the main.rs file in the src directory in your preferred text editor.
- Write the code header with the relevant information:
//-- #########################
//-- Task: Testing rust-clippy tool
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 28 April 17
//-- #########################
- Create a main function, and copy and paste the code:
fn main(){
let x = Some(1u8);
match x {
Some(y) => println!("{:?}", y),
_ => ()
}
}
- Copy and paste the code snippet above the main function at the beginning of the code to use rust-clippy as an optional dependency:
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
- Run Clippy with the command cargo build --features "clippy".
- For running Clippy as a subcommand, run the following command:
cargo clippy
- Copy paste the code snippet above the main function at the beginning of the code to use rust-clippy as a compiler plugin:
#![feature(plugin)]
#![plugin(clippy)]
- When we run the cargo run command, Cargo will install Clippy and show a warning.
We will get the following output for the preceding three different methods:
- Running Clippy as an optional dependency:
- Running Clippy as a Cargo subcommand:
- Running Clippy as a compiler plugin: