-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lint assert!(true / false) #3575
Comments
Take this one :) |
How about replacing |
PR added :) |
Add assert(true) and assert(false) lints This PR add two lints on assert!(true) and assert!(false). #3575
After #3582 was merged this lint can be enhanced by suggestions for
|
…lip1995 Add assert(true) and assert(false) lints This PR add two lints on assert!(true) and assert!(false). rust-lang#3575
…lip1995 Add assert(true) and assert(false) lints This PR add two lints on assert!(true) and assert!(false). rust-lang#3575
Add assert(true) and assert(false) lints This PR add two lints on assert!(true) and assert!(false). #3575
I would like to try and implement the first suggestion ( |
Just for clarification:
suggesting
What I meant with that is, to suggest removing the assert completely if it is |
Right. I didn't think that far. Also I notices the first part is already implemented so I will start on the second part |
I will need some help here. I found rust-clippy/clippy_lints/src/write.rs Lines 324 to 441 in 54bf4ff
But it uses |
Yes, that's why I wrote (advanced) behind this. What you need to do is to look at the expanded code. You can do this with the rustc flag For example: fn main() {
assert!(false, "some {} things", "String");
} expands to #[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std;
fn main() {
match { let _t = !false; _t } {
true => {
{
::std::rt::begin_panic_fmt(&<::core::fmt::Arguments>::new_v1(&["some ",
" things"],
&match (&"String",)
{
(arg0,)
=>
[<::core::fmt::ArgumentV1>::new(arg0,
::core::fmt::Display::fmt)],
}),
&("main.rs", 2u32, 5u32))
}
}
_ => { }
};
} You then have to match the expanded construct. Something similar was done before in |
Add assert message to suggestion in lint assertions_on_constants <!-- Thank you for making Clippy better! We're collecting our changelog from pull request descriptions. If your PR only updates to the latest nightly, you can leave the `changelog` entry as `none`. Otherwise, please write a short comment explaining your change. If your PR fixes an issue, you can add "fixes #issue_number" into this PR description. This way the issue will be automatically closed when your PR is merged. If you added a new lint, here's a checklist for things that will be checked during review or continuous integration. - [x] Followed [lint naming conventions][lint_naming] - [x] Added passing UI tests (including committed `.stderr` file) - [ ] `cargo test` passes locally - [x] Executed `./util/dev update_lints` - [ ] Added lint documentation - [ ] Run `./util/dev fmt` [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints Note that you can skip the above if you are just opening a WIP PR in order to get feedback. Delete this line and everything above before opening your PR --> - [x] suggest replacing `assert!(false, "msg")` with `panic!("msg")` - [x] extend to allow ~~variables~~ any expression for `"msg"` - ~~suggest replacing `assert!(false, "msg {}", "arg")` with `panic!("msg {}", "arg")`~~ changelog: add assert message to suggestion in lint assertions_on_constants Work towards fixing: #3575
The implementation now evaluates the constant and emits different help messages based on whether the assertion is always With #11966 fixed (not linting when the Footnotes
|
assert!(true);
will be optimized out by the compilerassert!(false);
should probably be replaced by apanic!()
.The text was updated successfully, but these errors were encountered: