How to do it...

Follow the steps to implement this recipe:

  1. Open the main.rs file in the src directory in your preferred text editor.
  2. Write the code header with the relevant information:
        //-- #########################
//-- Task: Testing rust-clippy tool
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 28 April 17
//-- #########################
  1. Create a main function, and copy and paste the code:
        fn main(){
let x = Some(1u8);
match x {
Some(y) => println!("{:?}", y),
_ => ()
}
}
  1. 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))]
  1. Run Clippy with the command cargo build --features "clippy".
  2. For running Clippy as a subcommand, run the following command:
        cargo clippy
  1. 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)]
  1. 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:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.75.165