-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
while_immutable_condition false positive with mut pointers #3548
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Comments
dtolnay
added a commit
to dtolnay/unsafe-libyaml
that referenced
this issue
Jul 23, 2022
rust-lang/rust-clippy#3548 error: variables in the condition are not mutated in the loop body --> src/scanner.rs:1031:15 | 1031 | while CHECK!((*parser).buffer, b' ') | _______________^ 1032 | | || ((*parser).flow_level != 0 || (*parser).simple_key_allowed == 0) 1033 | | && CHECK!((*parser).buffer, b'\t') | |__________________________________________________^ | = note: `-D clippy::while-immutable-condition` implied by `-D clippy::all` = note: this may lead to an infinite or to a never running loop = note: this loop contains `return`s or `break`s = help: rewrite it as `if cond { loop { } }` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition error: variables in the condition are not mutated in the loop body --> src/macros.rs:138:9 | 138 | *$string.pointer >= b'0' && *$string.pointer <= b'9' | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ::: src/scanner.rs:1319:11 | 1319 | while IS_DIGIT!((*parser).buffer) { | --------------------------- in this macro invocation | = note: this may lead to an infinite or to a never running loop = note: this loop contains `return`s or `break`s = help: rewrite it as `if cond { loop { } }` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition = note: this error originates in the macro `IS_DIGIT` (in Nightly builds, run with -Z macro-backtrace for more info)
dtolnay
added a commit
to dtolnay/unsafe-libyaml
that referenced
this issue
Jul 23, 2022
rust-lang/rust-clippy#3548 error: variables in the condition are not mutated in the loop body --> src/scanner.rs:1031:15 | 1031 | while CHECK!((*parser).buffer, b' ') | _______________^ 1032 | | || ((*parser).flow_level != 0 || (*parser).simple_key_allowed == 0) 1033 | | && CHECK!((*parser).buffer, b'\t') | |__________________________________________________^ | = note: `-D clippy::while-immutable-condition` implied by `-D clippy::all` = note: this may lead to an infinite or to a never running loop = note: this loop contains `return`s or `break`s = help: rewrite it as `if cond { loop { } }` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition error: variables in the condition are not mutated in the loop body --> src/macros.rs:138:9 | 138 | *$string.pointer >= b'0' && *$string.pointer <= b'9' | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ::: src/scanner.rs:1319:11 | 1319 | while IS_DIGIT!((*parser).buffer) { | --------------------------- in this macro invocation | = note: this may lead to an infinite or to a never running loop = note: this loop contains `return`s or `break`s = help: rewrite it as `if cond { loop { } }` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition = note: this error originates in the macro `IS_DIGIT` (in Nightly builds, run with -Z macro-backtrace for more info)
24 tasks
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Code like the following triggers
clippy::while_immutable_condition
:The exact error message is:
There are clearly two mut pointers involved above, but it's also possible for this to happen with e.g. external functions:
Clippy complains also about the above, although in reality,
stash_the_pointer
could've saved the pointer somewhere, allowinguse_the_pointer
to update it.Having the lint disregard mut pointers entirely would be a simple way of papering over this, but a more accurate fix might be something along the lines of:
But maybe it's not that simple, I didn't really think about it very hard.
The text was updated successfully, but these errors were encountered: