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.46k stars 1.54k forks source link

Non-lexical lifetimes #2141

Open gnzlbg opened 7 years ago

gnzlbg commented 7 years ago

Once the NLL RFC is implemented, I'd like to get rid of all lifetime workarounds in a couple of code bases.

It would be great if there would be a lint (or groups of lints) for this. Developing this lints can be done before the RFC is approved, and can be useful to determine / quantify the impact of the RFC on any code base.

oli-obk commented 7 years ago

This will be a fun one.

We need to collect examples! Many examples. Sooo many examples...

gnzlbg commented 7 years ago

So let's start with my personal favorite:

// BEFORE:
let tmp = self.non_mutating_method();
self.mutating_method(tmp);

// THE FUTURE:
self.mutating_method(self.non_mutating_method());
// ^^ CURRENTLY: something about already borrowed

I can't wait for the future to arrive.

Manishearth commented 7 years ago

Idk, it's quite often that you want to do something similar (e.g. even when the method doesn't mutate) just for cleaner code.

clarfonthey commented 7 years ago

It'd also be useful to replace uses of RefCell with ones that become now statically okay.

hellow554 commented 5 years ago

I like to remind, that Rust 1.31.0 is out and nll is active :) (at least for 2018 workspaces)