All Projects → mre → Cargo Inspect

mre / Cargo Inspect

Licence: other
Pssst!... see what Rust is doing behind the curtains 🕵🤫

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Cargo Inspect

cppcheck-configs
Configuration files that allow cppcheck to provide better static analysis results
Stars: ✭ 15 (-94.92%)
Mutual labels:  static-analysis
Tool lists
Links to tools by subject
Stars: ✭ 270 (-8.47%)
Mutual labels:  static-analysis
Nullaway
A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
Stars: ✭ 3,035 (+928.81%)
Mutual labels:  static-analysis
mobsfscan
mobsfscan is a static analysis tool that can find insecure code patterns in your Android and iOS source code. Supports Java, Kotlin, Swift, and Objective C Code. mobsfscan uses MobSF static analysis rules and is powered by semgrep and libsast pattern matcher.
Stars: ✭ 148 (-49.83%)
Mutual labels:  static-analysis
Goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 2,943 (+897.63%)
Mutual labels:  static-analysis
Chronos
Chronos - A static race detector for the go language
Stars: ✭ 272 (-7.8%)
Mutual labels:  static-analysis
freki
🐺 Malware analysis platform
Stars: ✭ 327 (+10.85%)
Mutual labels:  static-analysis
Clang Power Tools
Bringing clang-tidy magic to Visual Studio C++ developers.
Stars: ✭ 285 (-3.39%)
Mutual labels:  static-analysis
Seahorn
SeaHorn Verification Framework
Stars: ✭ 270 (-8.47%)
Mutual labels:  static-analysis
Cleancppproject
Clean C++ project for you to use. Features: Modern CMake, CPack, Doxygen, PlantUML, Catch Unit testing, static analysis
Stars: ✭ 276 (-6.44%)
Mutual labels:  static-analysis
Krane
Kubernetes RBAC static Analysis & visualisation tool
Stars: ✭ 254 (-13.9%)
Mutual labels:  static-analysis
Cfripper
Library and CLI tool for analysing CloudFormation templates and check them for security compliance.
Stars: ✭ 265 (-10.17%)
Mutual labels:  static-analysis
Dingo Hunter
Static analyser for finding Deadlocks in Go
Stars: ✭ 272 (-7.8%)
Mutual labels:  static-analysis
codeclimate-duplication
Code Climate engine for code duplication analysis
Stars: ✭ 96 (-67.46%)
Mutual labels:  static-analysis
Rascal
The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
Stars: ✭ 284 (-3.73%)
Mutual labels:  static-analysis
unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (-59.66%)
Mutual labels:  static-analysis
Wotan
Pluggable TypeScript and JavaScript linter
Stars: ✭ 271 (-8.14%)
Mutual labels:  static-analysis
Sonar Php
🐘 SonarPHP: PHP static analyzer for SonarQube & SonarLint
Stars: ✭ 288 (-2.37%)
Mutual labels:  static-analysis
Freki
🐺 Malware analysis platform
Stars: ✭ 285 (-3.39%)
Mutual labels:  static-analysis
Linter
Static Analysis Compiler Plugin for Scala
Stars: ✭ 273 (-7.46%)
Mutual labels:  static-analysis

cargo-inspect

Logo

docs Build Status

What is Rust doing behind the scenes?

There are only two ways to live your life.
One is as though nothing is a miracle. The other is as though everything is a miracle. -- Albert Einstein

Installation

You need Rust nightly and rustfmt to get started.
You can install those via rustup:

rustup install nightly
rustup component add rustfmt

All set? Let's get cracking!

cargo install cargo-inspect

Usage

Call it on any Rust file:

cargo inspect main.rs

If you don't specify a file, the current crate will be analyzed instead.

cargo inspect

Depending on the size of the crate, this might take a while.
Please be patient.

It can also compare two file outputs! Try this:

cargo inspect --diff examples/range.rs,examples/range_inclusive.rs --plain

Configuration

USAGE:
    cargo inspect [FLAGS] [OPTIONS] [INPUT_FILE]

FLAGS:
    -h, --help
            Prints help information

        --list-themes
            Should we list all pretty printer themes?

        --plain
            Don't highlight output

    -V, --version
            Prints version information

    -v, --verbose
            Print the original code as a comment above the desugared code


OPTIONS:
        --theme <THEME>
            Specify a theme override for the pretty printer

        --diff <files>
            Diff input files

        --format <format>
            Override for the format that gets outputted when the `unpretty` mode is set to `flowgraph` [default: svg]

        --unpretty <unpretty>
            rustc "unpretty" parameters

            *Note*: For `--unpretty=flowgraph=[symbol]` you need to have `dot` on your PATH. [default: hir]

ARGS:
    <INPUT_FILE>
            Input file

Background

Rust allows for a lot of syntactic sugar, that makes it a pleasure to write. It is sometimes hard, however, to look behind the curtain and see what the compiler is really doing with our code.

To quote @tshepang, "It is good to know what these conveniences are, to avoid being mystified by what's going on under the hood... the less magical thinking we have of the world, the better."

  • lifetime elisions
  • type inference
  • syntactic sugar
  • implicit dereferencing
  • type coercions
  • hidden code (e.g. the prelude)

I was always interested in how programming languages work in the background, how my code was unrolled to make the compiler backend easier to maintain.

The goal is to make the compiler more approachable for mere mortals.
Mystery! Exploration! Discovery!

Read more on the background of cargo-inspect on my blog.

Code Examples

If-let gets desugared into match

Consider the following code snippet:

fn main() {
    if let Some(x) = Some(1) {
        // Do something with x
    }
}

When you compile it, the first thing Rust does is desugar it. To see what the code looks like after this step, run

cargo inspect examples/if_let.rs

This produces the following output:

Please run the command to reproduce the desugared output

You can see that the if let was desugared into a match statement.

To change the colorscheme, try cargo-inspect --list-themes, e.g.

cargo inspect examples/if_let.rs --theme GitHub

Please run the command to reproduce the desugared output

Oh, and if you have graphviz installed, you can also print a pretty flowgraph from your code:

cargo inspect --unpretty=flowgraph=main examples/if_let.rs

Please run the command to reproduce the desugared output

More examples

Please find more examples in the examples folder. You can also contribute more.

The Magic Sauce

The best things in the world are assembled from simple building blocks. This tool stands on the shoulders of giants. To work its magic, it runs the following commands:

  1. rustc -Zinspect=hir, for retrieving the HIR.
  2. rustfmt, for formatting the output.
  3. prettyprint, for syntax-highlighting, which is just a wrapper around the awesome syntect and bat crates.

Contributing

This is a young project, which has downsides and upsides.

  • Everything is in flux and things can break at any time. 😫
  • There's plenty of opportunity to shape and form the project. 😊

Thus, become a contributor today!

Known issues

As of now, this is a very fragile tool. If it fails, it might will produce horrible output. You have been warned. That said, it won't eat your code, of course. 😊

License

Licensed under either of

at your option.

Credits

Magnifying glass designed by Rawpixel.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].