rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.34k stars 1.53k forks source link

"newbie mode" that contains helpful hints that don't work as lints #1737

Open Manishearth opened 7 years ago

Manishearth commented 7 years ago

It would be interesting to have a "newbie mode" (basically another lint group) that points out various features in your code, not necessarily suggesting fixes or anything.

For example impl Trait for OtherTrait can explain the difference between impl<T: OtherTrait> Trait for T and itself" or fn foo(mut x: Bar) can tell you that mut x does not mutate the outer variable when Bar is copy. Stuff like this, that doesn't work well as a lint (because there are plenty of good reasons to do it), but do merit a "watch out this may not do what you think" for newbies.

Thoughts? Ideas for similar newbie hint-lints?

oli-obk commented 7 years ago

My main concern is discoverability of such a group. Newcomers have enough on their plate starting out with Rust. I can tell my students to enable it, but how will someone who finds Rust on their own know about such lints? We can't "detect" newcomers, because we can't differentiate them from someone who just created a small crate to test something.

Once clippy is stable, we could consider this by asking the rustc devs to

  1. put #[warn(clippy_for_new_rustaceans)] into the cargo new --bin template conditionally on some hidden config file which stores the date of the first rustc usage of the user and the number of crates created. Then the template could revert to its normal version after the count reaches 5 or the age reaches a month.
  2. or just add several suggestions in the book about adding this flag
Manishearth commented 7 years ago

I do intend to insert clippy into the docs along with rustfmt once it is stable.

CBenoit commented 7 years ago

I absolutely love the idea.

oli-obk commented 7 years ago

We should discuss this with the rustc team, because this would also be a good idea for error messages. Some errors are obvious mistakes made by new rustaceans, but after a while it will be a more complex issue

golddranks commented 7 years ago

Of course, rustup could also ask about the default when installing the toolchain.

joshlf commented 7 years ago

Maybe make it default to assuming you're a newbie, but also make it easy to turn off? That way newbies are covered, and non-newbies should find it easy to disable.