rust/compiler/rustc_lint/src
Matthias Krüger dc1ccc5264
Rollup merge of #131035 - dingxiangfei2009:tweak-if-let-rescope-lint, r=jieyouxu
Preserve brackets around if-lets and skip while-lets

r? `@jieyouxu`

Tracked by #124085

Fresh out of #129466, we have discovered 9 crates that the lint did not successfully migrate because the span of `if let` includes the surrounding brackets `(..)` like the following, which surprised me a bit.

```rust
if (if let .. { .. } else { .. }) {
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// the span somehow includes the surrounding brackets
}
```

There is one crate that failed the migration because some suggestion spans cross the macro expansion boundaries. Surely there is no way to patch them with `match` rewrite. To handle this case, we will instead require all spans to be tested for admissibility as suggestion spans.

Besides, there are 4 false negative cases discovered with desugared-`while let`. We don't need to lint them, because the `else` branch surely contains exactly one statement because the drop order is not changed whatsoever in this case.

```rust
while let Some(value) = droppy().get() {
..
}
// is desugared into
loop {
    if let Some(value) = droppy().get() {
        ..
    } else {
        break;
        // here can be nothing observable in this block
    }
}
```

I believe this is the one and only false positive that I have found. I think we have finally nailed all the corner cases this time.
2024-09-30 18:25:14 +02:00
..
context Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
nonstandard_style
types Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
async_closures.rs docs: Enable required feature for 'closure_returning_async_block' lint 2024-09-14 10:43:26 +02:00
async_fn_in_trait.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
builtin.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
context.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
deref_into_dyn_supertrait.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
drop_forget_useless.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
early.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
enum_intrinsics_non_enums.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
errors.rs Add warn(unreachable_pub) to rustc_lint. 2024-08-27 15:24:11 +10:00
expect.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
for_loops_over_fallibles.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
foreign_modules.rs Make clashing_extern_declarations considering generic args for ADT field 2024-09-27 16:37:43 +08:00
hidden_unicode_codepoints.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
if_let_rescope.rs Rollup merge of #131035 - dingxiangfei2009:tweak-if-let-rescope-lint, r=jieyouxu 2024-09-30 18:25:14 +02:00
impl_trait_overcaptures.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
internal.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
invalid_from_utf8.rs Remove extern crate rustc_session from rustc_lint. 2024-04-29 13:57:41 +10:00
late.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
let_underscore.rs Fix the misleading diagnostic for let_underscore_drop on type without Drop implementation 2024-09-26 10:18:18 +08:00
levels.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
lib.rs add unqualified_local_imports lint 2024-09-23 11:57:28 +02:00
lints.rs Auto merge of #127117 - Urgau:non_local_def-syntactic, r=BoxyUwU 2024-09-24 03:43:01 +00:00
macro_expr_fragment_specifier_2024_migration.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
map_unit_fn.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
methods.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
multiple_supertrait_upcastable.rs Compiler: Rename "object safe" to "dyn compatible" 2024-09-25 13:26:48 +02:00
non_ascii_idents.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
non_fmt_panic.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
non_local_def.rs Remove with/without trait and bounds consideration 2024-09-23 10:01:59 +02:00
nonstandard_style.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
noop_method_call.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
opaque_hidden_inferred_bound.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
pass_by_value.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
passes.rs add unqualified_local_imports lint 2024-09-23 11:57:28 +02: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 Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
reference_casting.rs Use bool in favor of Option<()> for diagnostics 2024-08-21 01:31:11 -04:00
shadowed_into_iter.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
static_mut_refs.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
tail_expr_drop_order.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
tests.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
traits.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
types.rs Revert "Add recursion limit to FFI safety lint" 2024-09-23 12:43:44 -04:00
unit_bindings.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
unqualified_local_imports.rs add unqualified_local_imports lint 2024-09-23 11:57:28 +02:00
unused.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00