about summary refs log tree commit diff
path: root/compiler/rustc_index/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-03-12 08:06:50 +0100
committerGitHub <noreply@github.com>2025-03-12 08:06:50 +0100
commitb849aa9f61e96b3a8a9fa11f85e991dd07fbfc37 (patch)
treee62c7020aa364e674750ee81d9f30703fe50f739 /compiler/rustc_index/src
parent5833dfa78ab8c0702581f53c9d6bb1d224c86957 (diff)
parentfaa5b3f7de0db76e41bcf5c54c401d7651e69c58 (diff)
downloadrust-b849aa9f61e96b3a8a9fa11f85e991dd07fbfc37.tar.gz
rust-b849aa9f61e96b3a8a9fa11f85e991dd07fbfc37.zip
Rollup merge of #138360 - Urgau:fix-fp-expr_or_init, r=wesleywiser
Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint

This PR fixes the logic for finding initializer in the `expr_or_init` and `expr_or_init_with_outside_body` functions.

If the binding were to be mutable (`let mut`), the logic wouldn't consider that the initializer expression could have been modified and would return the init expression even-trough multiple subsequent assignments could have been done.

Example:
```rust
let mut a = [99, 108, 130, 105, 112, 112]; // invalid, not UTF-8
loop {
    a = *b"clippy"; // valid
    break;
}
std::str::from_utf8_mut(&mut a); // currently warns, with this PR it doesn't
```

This PR modifies the logic to excludes mutable let bindings.

Found when using `expr_or_init` in https://github.com/rust-lang/rust/pull/119220.

r? compiler
Diffstat (limited to 'compiler/rustc_index/src')
0 files changed, 0 insertions, 0 deletions