Implementation of the const_static_lifetime lint.#2151
Conversation
|
You need to run |
|
Hey, I just fixed the test thing ! |
oli-obk
left a comment
There was a problem hiding this comment.
Please undo all the unrelated formatting changes or use the most recent rustfmt, which should produce the previous layout.
| } | ||
|
|
||
| // Tuples are of the form (constant, name, min_digits) | ||
| const KNOWN_CONSTS: &'static [(f64, &'static str, usize)] = &[ |
There was a problem hiding this comment.
Please don't make unrelated formatting changes
| &format!( | ||
| "approximate value of `{}::consts::{}` found. \ | ||
| Consider using it directly", | ||
| module, |
There was a problem hiding this comment.
more unrelated formatting changes
| if let TyKind::Path(_, _) = borrow_type.ty.node { | ||
| // Verify that the path is a str | ||
| if lifetime.ident.name == "'static" { | ||
| span_help_and_lint(cx, |
There was a problem hiding this comment.
Can you use span_help_and_then and add a suggestion to remove the lifetime? (Search for span_suggestion for examples)
|
I think all your request have been implemented. |
oli-obk
left a comment
There was a problem hiding this comment.
Thanks! This is much easier to review.
Just some nits left
| OPENING_PAREN, | ||
| r"[a-z]+\.(com|org|net)", | ||
| ]); | ||
| let set = RegexSet::new(&[r"[a-z]+@[a-z]+\.(com|org|net)", r"[a-z]+\.(com|org|net)"]); |
There was a problem hiding this comment.
Some leftover formatting changes
| let mut sug: String = String::new(); | ||
| // This should be ok, since we know that the current type is a borrow. | ||
| sug.push('&'); | ||
| sug += &snippet(cx, borrow_type.ty.span, "<expr>").into_owned(); |
There was a problem hiding this comment.
The suggestion should be empty. It is the code that is written over 'static, not over &'static T.
There was a problem hiding this comment.
Oh, thanks I couldn't figured it out.
Is this for the application that automatically applies suggestions ?
There was a problem hiding this comment.
Yea. In the future rls will probably make use of it, too. So you'll be able to fix these things with a single click on the offending error message.
There was a problem hiding this comment.
I am currently applying your requests, but cargo test fails because :
error: Unnecessary `!=` operation
--> clippy_lints/src/loops.rs:754:21
|
754 | / if offset_left.var_name != offset_right.var_name {
755 | | Some((offset_left, offset_right))
756 | | } else {
757 | | None
758 | | }
| |_____________________^
|
= note: `-D if-not-else` implied by `-D clippy-pedantic`
= help: change to `==` and swap the blocks of the if/else
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.166/index.html#if_not_else
error: aborting due to previous error
Is this related to the latest nigthly or some error in my changes ?
There was a problem hiding this comment.
curious. I wonder why travis didn't catch that on the other PRs... I'll push a quick fix that you can rebase over
There was a problem hiding this comment.
You can rebase over the master branch, I fixed it
| @@ -0,0 +1 @@ | |||
| array | |||
There was a problem hiding this comment.
Accidentally commited debug output?
|
Something really weird happened. you have all of our commits in this PR now. Try |
|
Thanks, I was looking into it ! |
|
Thanks! This lint is so much in the spirit of clippy. Annoying as hell 😆 I will keep doing it wrong until clippy beats |
|
I really enjoyed implementing this first lint, thanks for your help ! |
Hello,
After a few month, I decided to come back on some unfinished work (previous pr : #1829, issue : #1762).
Currently, the lint has the correct behaviour, but I am struggling setting up the test.
./tests/ui/const_static_lifetime.rscontains some tests, but I can't figure out how to generate a correct .stderr output:./target/debug/test_build_base/const_static_lifetime.errcontains hardcoded strings for file location (tests/ui/const_static_lifetime.rs), whereas other tests contains$DIR/<real_filename>.Moreover, I have broken two test :
./tests/ui/regex.rsthat I fixed (it contained a constant with an explicit static lifetime) and./tests/ui/for_loop.rs. I can't figure what broke on this done...Anyway, if some of you want to give some more test cases, I will be glad to add them in the test file.
Thanks for your time !
PS: Please be tolerant, english is not my native language, I am trying my best to avoid mistakes.