rust/compiler/rustc_lint/src
Matthias Krüger b849aa9f61
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
2025-03-12 08:06:50 +01:00
..
early Reword message 2025-02-20 17:55:31 +00:00
nonstandard_style
types fix: fix overflowing hex wrong suggestion 2025-02-28 07:25:52 +05:30
async_closures.rs Move some Map methods onto TyCtxt. 2025-02-17 13:21:02 +11:00
async_fn_in_trait.rs nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
builtin.rs Change span field accesses to method calls 2025-02-24 14:22:31 +01:00
context.rs Fix false-positive in expr_or_init and in the invalid_from_utf8 lint 2025-03-11 21:56:53 +01:00
dangling.rs Implement .use keyword as an alias of clone 2025-03-06 17:58:32 -03:00
default_could_be_derived.rs chore: Fix some comments 2025-03-09 18:31:14 +08:00
deref_into_dyn_supertrait.rs update version placeholders 2025-02-18 08:50:21 -08:00
drop_forget_useless.rs Move methods from Map to TyCtxt, part 3. 2025-02-21 14:31:09 +11:00
early.rs fix empty after lint on impl/trait items 2025-02-07 16:47:26 +01:00
enum_intrinsics_non_enums.rs Rustfmt 2025-02-08 22:12:13 +00:00
errors.rs Add warn(unreachable_pub) to rustc_lint. 2024-08-27 15:24:11 +10:00
expect.rs Introduce new-style attribute parsers for several attributes 2025-02-24 14:31:17 +01:00
for_loops_over_fallibles.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
foreign_modules.rs Change span field accesses to method calls 2025-02-24 14:22:31 +01:00
hidden_unicode_codepoints.rs Rustfmt 2025-02-08 22:12:13 +00:00
if_let_rescope.rs Print out destructor 2025-02-26 19:03:29 +00:00
impl_trait_overcaptures.rs Rollup merge of #136787 - compiler-errors:lt2024feat, r=oli-obk 2025-02-22 01:01:40 +01:00
internal.rs Move methods from Map to TyCtxt, part 3. 2025-02-21 14:31:09 +11:00
invalid_from_utf8.rs invalid_from_utf8[_unchecked]: also lint inherent methods 2025-02-16 16:34:51 +03:00
late.rs Move visit_id calls. 2025-03-07 19:35:41 +11:00
let_underscore.rs Rustfmt 2025-02-08 22:12:13 +00:00
levels.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
lib.rs Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
lints.rs Reword message 2025-02-20 17:55:31 +00:00
macro_expr_fragment_specifier_2024_migration.rs Rename RefTokenTreeCursor. 2024-12-18 10:39:07 +11:00
map_unit_fn.rs Rustfmt 2025-02-08 22:12:13 +00:00
multiple_supertrait_upcastable.rs Compiler: Finalize dyn compatibility renaming 2025-01-26 21:20:31 +01:00
non_ascii_idents.rs Fix binding mode problems 2025-02-22 00:13:19 +00:00
non_fmt_panic.rs Rustfmt 2025-02-08 22:12:13 +00:00
non_local_def.rs Rustfmt 2025-02-08 22:12:13 +00:00
nonstandard_style.rs Introduce new-style attribute parsers for several attributes 2025-02-24 14:31:17 +01:00
noop_method_call.rs Rustfmt 2025-02-08 22:12:13 +00:00
opaque_hidden_inferred_bound.rs Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
pass_by_value.rs Rustfmt 2025-02-08 22:12:13 +00:00
passes.rs fix empty after lint on impl/trait items 2025-02-07 16:47:26 +01:00
precedence.rs Temporarily switch ambiguous_negative_literals lint to allow 2024-07-31 19:36:47 +02:00
ptr_nulls.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
redundant_semicolon.rs Rustfmt 2025-02-08 22:12:13 +00:00
reference_casting.rs move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
shadowed_into_iter.rs Move methods from Map to TyCtxt, part 3. 2025-02-21 14:31:09 +11:00
static_mut_refs.rs Rustfmt 2025-02-08 22:12:13 +00:00
tests.rs update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
traits.rs Rustfmt 2025-02-08 22:12:13 +00:00
types.rs Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
unit_bindings.rs Rustfmt 2025-02-08 22:12:13 +00:00
unqualified_local_imports.rs Move methods from Map to TyCtxt, part 3. 2025-02-21 14:31:09 +11:00
unused.rs Remove unnecessary check code in unused_delims 2025-02-15 07:35:28 +08:00