{"id":16376585,"url":"https://github.com/killercup/presentation-rustfix-fosdem","last_synced_at":"2026-04-07T06:30:18.301Z","repository":{"id":66475154,"uuid":"119749206","full_name":"killercup/presentation-rustfix-fosdem","owner":"killercup","description":"Slides: https://git.io/fosdem-rustfix","archived":false,"fork":false,"pushed_at":"2018-02-04T11:04:07.000Z","size":2710,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-01T08:18:01.733Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.youtube.com/watch?v=ogKBAo2jZns","language":"CSS","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/killercup.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-31T22:01:49.000Z","updated_at":"2018-02-05T13:23:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"ddfae277-e196-4de4-9d56-1393f6413e63","html_url":"https://github.com/killercup/presentation-rustfix-fosdem","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killercup%2Fpresentation-rustfix-fosdem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killercup%2Fpresentation-rustfix-fosdem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killercup%2Fpresentation-rustfix-fosdem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killercup%2Fpresentation-rustfix-fosdem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/killercup","download_url":"https://codeload.github.com/killercup/presentation-rustfix-fosdem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239970661,"owners_count":19727010,"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":[],"created_at":"2024-10-11T03:25:12.355Z","updated_at":"2026-04-07T06:30:18.259Z","avatar_url":"https://github.com/killercup.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"rustfix\"\nsubtitle: \"…and the journey to getting better code automatically\"\nauthor: Pascal Hertleif\ndate: 2018-02-04\ncategories:\n- rust\n- presentation\ntheme: solarized\nprogress: true\nslideNumber: true\nhistory: true\n---\n## Hi, I'm Pascal Hertleif\n\n- Web dev \u0026 Rust freelancer\n- Co-organizer of [Rust Cologne]\n- {[twitter],[github]}.com/killercup\n- Rust-centric blog: [deterministic.space]\n\n[Rust Cologne]: http://rust.cologne/\n[twitter]: https://twitter.com/killercup\n[github]: https://github.com/killercup\n[deterministic.space]: https://deterministic.space/\n\n::: notes\n\nThanks for the kind introduction!\n\n- I've been working with Rust since early 2014\n- If you ever happen to be in Cologne, drop by at one of our monthly meetups!\n- And with that out of the way, let's get started!\n\n:::\n\n# Rust programmers like compiler errors\n\n::: notes\n\nLet's start with something uncontroversial:\nRust programmers like compiler errors\n\n:::\n\n---\n\n```\nerror[E0507]: cannot move out of borrowed content\n   --\u003e src/lib.rs:126:29\n    |\n126 |         if let Some(code) = diagnostic.code {\n    |                     ----    ^^^^^^^^^^ cannot move out of borrowed content\n    |                     |\n    |                     hint: to prevent move, use `ref code` or `ref mut code`\n```\n\n## Why?\n\nRust is all about compile-time checks\n\nBut also: Rust's errors are *pretty* and *helpful*\n\n## Warnings, too\n\n- Lints\n- _Prevent_ errors\n- Examples\n\t- unused `Result`s or `Iterator`s\n\t- Missing docs\n\n## Clippy\n\nIt looks like you're enjoying errors. Would you like some more?\n\n- 208 lints written by the community\n- Find common bugs\n\t- For example: `if_same_then_else`\n\n::: notes\n\nClippy was originally written by Manish Goregaokar\nbut there are a lot of people who contributed to it.\nOliver here, for example!\n\n:::\n\n# Lints as a teaching tool\n\n---\n\n`iter.filter(|x| x == 0).next()`\n\n. . .\n\nDid you know about `iter.find(|x| x == 0)`?\n\n::: notes\n\nAre there any seasoned Rust developers here\nwho know a better way to write this?\n\n:::\n\n---\n\n`if !m.contains_key(\u0026k) { m.insert(k, v) }`\n\n. . .\n\nHave you heard the good news about the Entry API?\n\n`m.entry(k).or_insert(v);`\n\n::: notes\n\nOkay, you get another chance!\nHow about this code?\nWhat would you change?\n\nThe Entry API only needs to compute the hash once!\n\n:::\n\n---\n\n- Learn new APIs when you are _almost_ using them\n- Each clippy lint is documented with examples\n\n::: notes\n\nThis is really powerful,\nas you get the chance to learn something\nvery close to when you where thinking about how to solve this problem.\nSo you are not reading a book\nand much later try to apply you knowledge,\nbut get to learn things by working on your own code.\n\n:::\n\n# Making this interactive\n\n---\n\n## Suggestions\n\n```\nerror: this range is empty so this for loop will never run\n   --\u003e $DIR/for_loop.rs:148:14\n    |\n148 |     for i in 10..0 {\n    |              ^^^^^\n    |\n    = note: `-D reverse-range-loop` implied by `-D warnings`\nhelp: consider using the following if you are attempting to iterate over this range in reverse\n    |\n148 |     for i in (0..10).rev() {\n    |              ^^^^^^^^^^^^^\n```\n\n::: notes\n\nThe compiler can give you suggestions based on your code.\nMany of these suggestions you can copy and paste to your code\n\n:::\n\n## Why fix it yourself?\n\nI'm sold. These suggestions are great. But…\n\n- don't make me type\n- don't make me wait\n- just fix my code already\n\n# Presenting: rustfix\n\n---\n\n## It's already there\n\nNo magic! Just:\n\n- Take existing errors\n- Parse the compiler output (JSON)\n- Apply suggestions (search \u0026 replace)\n\n::: notes\n\nThe rustfix tool is really basic.\nIt uses the already existing building blocks.\nI can't take any credit for those!\n\n:::\n\n## Make it interactive (1)\n\nrustfix as CLI tool is interactive\n\n- for each error (that has a suggestion) it\n\t- shows you the error and the fix(es)\n\t- asks what you want to do\n\t- fixes your code\n\n## Make it interactive (2)\n\nYou need to manually call the CLI tool\n\nYou do that after working on the code\n\nWe can do better\n\n# Fixes via IDE\n\n---\n\n## RLS\n\n- Rust Language Server exposes warnings and suggestions\n- VSCode plugin can already apply fixes\n\n---\n\n![](assets/rls-clippy-1.png)\n\n---\n\n![](assets/rls-clippy-2.png)\n\n# Demo\n\n---\n\n\u003e Laptop didn't work?\n\u003e\n\u003e Totally saw that coming.\n\u003e\n\u003e – Past Me\n\n---\n\n![](assets/len0-1.png)\n\n---\n\n![](assets/len0-2.png)\n\n---\n\n![](assets/len0-3.png)\n\n---\n\n![](assets/binop-1.png)\n\n---\n\n![](assets/binop-2.png)\n\n---\n\n![](assets/binop-3.png)\n\n---\n\n![](assets/pi-1.png)\n\n---\n\n![](assets/pi-2.png)\n\n# Deep dive!\n\n## How does this work?\n\n- Compiler plugin\n- Find nodes and items of interest\n- 'Annotate' spans of code\n- Compiler generates human/JSON output\n\n## What is auto-fixable?\n\n\u003e - A lot!\n\u003e - Do we need to make a list?\n\u003e - Rust PR [#47540] adds flag for \"approximate suggestions\"\n\u003e - rustfix-like tools will use this in the future\n\u003e - **UPDATE** Merged! 🎉\n\n[#47540]: https://github.com/rust-lang/rust/pull/47540\n\n# Thanks!\n\n## You can contribute lints and suggestions!\n\nSearch for \"Rust Clippy\" or go to \u003chttps://github.com/rust-lang-nursery/rust-clippy\u003e\n\nThere are a lot of issues labelled _good first issue_\n\nYou get to call yourself a compiler hacker!\n\n## Any questions?\n\nVisit [rust-lang.org](https://www.rust-lang.org)\n\nFollow me on Twitter: [\\@killercup][twitter]\n\nSlides available at [git.io/fosdem-rustfix](https://git.io/fosdem-rustfix)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkillercup%2Fpresentation-rustfix-fosdem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkillercup%2Fpresentation-rustfix-fosdem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkillercup%2Fpresentation-rustfix-fosdem/lists"}