{"id":13503081,"url":"https://github.com/mre/cargo-inspect","last_synced_at":"2025-04-12T17:45:17.531Z","repository":{"id":33244069,"uuid":"156773103","full_name":"mre/cargo-inspect","owner":"mre","description":"Pssst!... see what Rust is doing behind the curtains 🕵🤫","archived":false,"fork":false,"pushed_at":"2023-02-27T05:02:44.000Z","size":575,"stargazers_count":380,"open_issues_count":4,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T20:11:09.856Z","etag":null,"topics":["desugar","inspect","static-analysis","syntactic-sugar","unpretty"],"latest_commit_sha":null,"homepage":"https://endler.dev/2018/cargo-inspect","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mre.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"mre","patreon":"hellorust"}},"created_at":"2018-11-08T21:45:54.000Z","updated_at":"2024-12-24T08:27:38.000Z","dependencies_parsed_at":"2024-01-23T07:49:45.344Z","dependency_job_id":null,"html_url":"https://github.com/mre/cargo-inspect","commit_stats":{"total_commits":123,"total_committers":8,"mean_commits":15.375,"dds":0.4552845528455285,"last_synced_commit":"80cbb580019818ca8026700eecef17ff8e10fc7d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fcargo-inspect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fcargo-inspect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fcargo-inspect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fcargo-inspect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mre","download_url":"https://codeload.github.com/mre/cargo-inspect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248609541,"owners_count":21132915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["desugar","inspect","static-analysis","syntactic-sugar","unpretty"],"created_at":"2024-07-31T22:02:36.164Z","updated_at":"2025-04-12T17:45:17.514Z","avatar_url":"https://github.com/mre.png","language":"Rust","funding_links":["https://github.com/sponsors/mre","https://patreon.com/hellorust"],"categories":["Rust"],"sub_categories":[],"readme":"# cargo-inspect\n\n![Logo](./assets/logo.svg)\n\n[![docs](https://docs.rs/cargo-inspect/badge.svg)](https://docs.rs/cargo-inspect/)\n[![Build Status](https://travis-ci.org/mre/cargo-inspect.svg?branch=master)](https://travis-ci.org/mre/cargo-inspect)\n\n## Thanks All!\n\nℹ️ This crate was **superceded by [cargo-expand](https://github.com/dtolnay/cargo-expand)**, which added support for all the features that were missing\nwhen we started to work on cargo-inspect. Thanks all for your feedback and support.\n\n## What is Rust doing behind the scenes?\n\n\u003e There are only two ways to live your life.  \n\u003e One is as though nothing is a miracle. The other is as though everything is a\n\u003e miracle. -- Albert Einstein\n\n## Installation\n\nYou need Rust nightly and `rustfmt` to get started.  \nYou can install those via [rustup]:\n\n```\nrustup install nightly\nrustup component add rustfmt\n```\n\nAll set? Let's get cracking!\n\n```\ncargo install cargo-inspect\n```\n\n## Usage\n\nCall it on any Rust file:\n\n```\ncargo inspect main.rs\n```\n\nIf you don't specify a file, the current crate will be analyzed instead.\n\n```\ncargo inspect\n```\n\nDepending on the size of the crate, this might take a while.  \nPlease be patient.\n\nIt can also compare two file outputs! Try this:\n\n```\ncargo inspect --diff examples/range.rs,examples/range_inclusive.rs --plain\n```\n\n## Configuration \n\n```\nUSAGE:\n    cargo inspect [FLAGS] [OPTIONS] [INPUT_FILE]\n\nFLAGS:\n    -h, --help\n            Prints help information\n\n        --list-themes\n            Should we list all pretty printer themes?\n\n        --plain\n            Don't highlight output\n\n    -V, --version\n            Prints version information\n\n    -v, --verbose\n            Print the original code as a comment above the desugared code\n\n\nOPTIONS:\n        --theme \u003cTHEME\u003e\n            Specify a theme override for the pretty printer\n\n        --diff \u003cfiles\u003e\n            Diff input files\n\n        --format \u003cformat\u003e\n            Override for the format that gets outputted when the `unpretty` mode is set to `flowgraph` [default: svg]\n\n        --unpretty \u003cunpretty\u003e\n            rustc \"unpretty\" parameters\n\n            *Note*: For `--unpretty=flowgraph=[symbol]` you need to have `dot` on your PATH. [default: hir]\n\nARGS:\n    \u003cINPUT_FILE\u003e\n            Input file\n```\n\n## Background\n\nRust allows for a lot of syntactic sugar, that makes it a pleasure to write. It\nis sometimes hard, however, to look behind the curtain and see what the compiler\nis really doing with our code.\n\nTo quote @tshepang, \"It is good to know what these conveniences are, to avoid\nbeing mystified by what's going on under the hood... the less magical thinking\nwe have of the world, the better.\"\n\n* lifetime elisions\n* type inference\n* syntactic sugar\n* implicit dereferencing\n* type coercions\n* hidden code (e.g. the prelude)\n\nI was always interested in how programming languages work in the background, how\nmy code was unrolled to make the compiler backend easier to maintain.\n\nThe goal is to make the compiler more approachable for mere mortals.  \nMystery! Exploration! Discovery! \n\nRead more on the background of `cargo-inspect` [on my blog](https://matthias-endler.de/2018/cargo-inspect/).\n\n## Code Examples\n\n### `If-let` gets desugared into `match`\n\nConsider the following code snippet:\n\n```rust\nfn main() {\n    if let Some(x) = Some(1) {\n        // Do something with x\n    }\n}\n```\n\nWhen you compile it, the first thing Rust does is desugar it. To see what the\ncode looks like after this step, run\n\n```\ncargo inspect examples/if_let.rs\n```\n\nThis produces the following output:\n\n![Please run the command to reproduce the desugared output](assets/if-let.png)\n\nYou can see that the `if let` was desugared into a `match` statement.\n\nTo change the colorscheme, try `cargo-inspect --list-themes`, e.g.\n\n```\ncargo inspect examples/if_let.rs --theme GitHub\n```\n\n![Please run the command to reproduce the desugared output](assets/if-let-white.png)\n\nOh, and if you have [`graphviz`](https://graphviz.gitlab.io/download/) installed, you can also print a pretty flowgraph from your code:\n\n```\ncargo inspect --unpretty=flowgraph=main examples/if_let.rs\n```\n\n![Please run the command to reproduce the desugared output](assets/if-let-flowgraph.svg)\n\n### More examples\n\nPlease find more examples in the `examples` folder. You can also contribute\nmore.\n\n## The Magic Sauce\n\nThe best things in the world are assembled from simple building blocks. This\ntool stands on the shoulders of giants. To work its magic, it runs the following\ncommands:\n\n1. `rustc -Zinspect=hir`, for retrieving the HIR.\n2. `rustfmt`, for formatting the output.\n3. [`prettyprint`](https://github.com/mre/prettyprint), for syntax-highlighting,\n   which is just a wrapper around the awesome\n   [syntect](https://github.com/trishume/syntect/blob/master/examples/syncat.rs)\n   and [bat](https://github.com/sharkdp/bat/) crates.\n\n## Contributing\n\nThis is a young project, which has downsides and upsides.\n\n* Everything is in flux and things can break at any time. 😫\n* There's plenty of opportunity to shape and form the project. 😊\n\nThus, become a contributor today!\n\n## Known issues\n\nAs of now, this is a very fragile tool. If it fails, it ~~might~~ will produce\nhorrible output. You have been warned. That said, it won't eat your code, of\ncourse. :blush:\n\n## License\n\nLicensed under either of\n\n* Apache License, Version 2.0, (LICENSE-APACHE or\n  http://www.apache.org/licenses/LICENSE-2.0)\n* MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)\n\nat your option.\n\n[rustup]: https://rustup.rs/\n\n\n## Credits\n\nMagnifying glass designed by [Rawpixel.com]( https://www.freepik.com/free-vector/illustration-of-a-magnifying-glass_2945064.htm) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2Fcargo-inspect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmre%2Fcargo-inspect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2Fcargo-inspect/lists"}