rust/compiler
bors d2baa49a10 Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot
de-duplicate condition scoping logic between AST→HIR lowering and `ScopeTree` construction

There was some overlap between `rustc_ast_lowering::LoweringContext::lower_cond` and `rustc_hir_analysis::check::region::resolve_expr`, so I've removed the former and migrated its logic to the latter, with some simplifications.

Consequences:
- For `while` and `if` expressions' `let`-chains, this changes the `HirId`s for the `&&`s to properly correspond to their AST nodes. This is how guards were handled already.
- This makes match guards share previously-duplicated logic with `if`/`while` expressions. This will also be used by guard pattern[^1] guards.
- Aside from legacy syntax extensions (e.g. some builtin macros) that directly feed AST to the compiler, it's currently impossible to put attributes directly on `&&` operators in `let` chains[^2]. Nonetheless, attributes on `&&` operators in `let` chains in `if`/`while` expression conditions are no longer silently ignored and will be lowered.
- This no longer wraps conditions in `DropTemps`, so the HIR and THIR will be slightly smaller.
- `DesugaringKind::CondTemporary` is now gone. It's no longer applied to any spans, and all uses of it were dead since they were made to account for `if` and `while` being desugared to `match` on a boolean scrutinee.
- Should be a marginal perf improvement beyond that due to leveraging [`ScopeTree` construction](5e749eb66f/compiler/rustc_hir_analysis/src/check/region.rs (L312-L355))'s clever handling of `&&` and `||`:
  - This removes some unnecessary terminating scopes that were placed around top-level `&&` and `||` operators in conditions. When lowered to MIR, logical operator chains don't create intermediate boolean temporaries, so there's no temporary to drop. The linked snippet handles wrapping the operands in terminating scopes as necessary, in case they create temporaries.
  - The linked snippet takes care of letting `let` temporaries live and terminating other operands, so we don't need separate traversals of `&&` chains for that.

[^1]: rust-lang/rust#129967
[^2]: Case-by-case, here's my justification: `#[attr] e1 && e2` applies the attribute to `e1`. In `#[attr] (e1 && e2)` , the attribute is on the parentheses in the AST, plus it'd fail to parse if `e1` or `e2` contains a `let`. In `#[attr] expands_to_let_chain!()`, the attribute would already be ignored (rust-lang/rust#63221) and it'd fail to parse anyway; even if the expansion site is a condition, the expansion wouldn't be parsed with `Restrictions::ALLOW_LET`. If it *was* allowed, the notion of a "reparse context" from https://github.com/rust-lang/rust/issues/61733#issuecomment-509626449 would be necessary in order to make `let`-chains left-associative; multiple places in the compiler assume they are.
2025-07-13 04:20:07 +00:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee 2025-07-07 17:28:14 +00:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_ast_passes compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
rustc_ast_pretty fix: Include frontmatter in -Zunpretty output 2025-07-10 10:26:02 -05:00
rustc_attr_data_structures Port #[rustc_coherence_is_core] to the new attribute system 2025-07-09 01:26:39 +03:00
rustc_attr_parsing Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmann 2025-07-11 19:45:22 +02:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Expose nested bodies in rustc_borrowck::consumers 2025-07-08 19:09:14 -07:00
rustc_builtin_macros Rollup merge of #143544 - workingjubilee:rename-bare-fn, r=fmease 2025-07-07 03:26:09 +02:00
rustc_codegen_cranelift Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
rustc_codegen_gcc Auto merge of #142911 - mejrs:unsized, r=compiler-errors 2025-07-11 05:27:32 +00:00
rustc_codegen_llvm Rollup merge of #143633 - dillona:noinline-assert, r=fee1-dead 2025-07-11 19:45:23 +02:00
rustc_codegen_ssa Auto merge of #143810 - matthiaskrgr:rollup-iw7a23z, r=matthiaskrgr 2025-07-12 10:46:43 +00:00
rustc_const_eval Avoid creating a helper allocation for creating new TypeId values in the interpreter 2025-07-09 16:37:11 +00:00
rustc_data_structures Fix wrong cache event query key 2025-07-07 15:16:42 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Rollup merge of #143019 - danielframpton:codegen-backend-parse, r=bjorn3 2025-06-30 20:49:40 +02:00
rustc_error_codes compiler: Trim the misleading C of C-cmse from errors 2025-06-25 00:52:10 -07:00
rustc_error_messages Remove unused feature gates 2025-06-28 23:36:46 +00:00
rustc_errors Rollup merge of #143661 - Muscraft:other-suggestion-message, r=estebank 2025-07-11 07:35:20 +02:00
rustc_expand mbe: Refactor the diagnostic for unrecognized metavariable expressions 2025-07-09 21:11:09 -04:00
rustc_feature Auto merge of #143214 - camsteffen:remove-let-chains-feature, r=est31 2025-07-02 17:18:47 +00:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
rustc_hir_analysis Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_hir_pretty compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
rustc_hir_typeck Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer Remove unused allow attrs 2025-07-07 12:58:16 +00:00
rustc_interface Save metadata among work products. 2025-07-04 14:02:17 +00:00
rustc_lexer test(lexer): Add frontmatter unit test 2025-07-10 10:25:29 -05:00
rustc_lint Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_lint_defs Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_llvm awhile -> a while where appropriate 2025-07-02 20:17:29 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Fix line break after ":" in unpretty attribute print 2025-07-06 09:51:47 +02:00
rustc_metadata Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
rustc_middle Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
rustc_mir_build Auto merge of #143472 - dianne:deref-pat-column-check, r=Nadrieril 2025-07-09 09:45:36 +00:00
rustc_mir_dataflow Remove support for SwitchInt edge effects in backward dataflow analyses 2025-07-11 10:56:50 +02:00
rustc_mir_transform Propagate from borrowed locals in CopyProp 2025-07-10 09:36:20 +02:00
rustc_monomorphize Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
rustc_next_trait_solver Don't compress input universes 2025-07-05 18:41:59 +00:00
rustc_parse Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmann 2025-07-11 19:45:22 +02:00
rustc_parse_format update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
rustc_passes Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_pattern_analysis only check for mixed deref/normal constructors when needed 2025-07-04 23:47:31 -07:00
rustc_privacy Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
rustc_proc_macro update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
rustc_query_impl Remove unused allow attrs 2025-07-07 12:58:16 +00:00
rustc_query_system use is_multiple_of instead of manual modulo 2025-07-05 10:55:35 +02:00
rustc_resolve Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_sanitizers Remove support for dyn* 2025-07-01 19:00:21 +00:00
rustc_serialize use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_session stabilize -Clink-self-contained=-linker on x64 linux 2025-07-08 09:21:35 +00:00
rustc_smir Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee 2025-07-07 17:28:14 +00:00
rustc_span Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_symbol_mangling Remove support for dyn* 2025-07-01 19:00:21 +00:00
rustc_target stabilize -Clinker-features=-lld on x64 linux 2025-07-08 09:04:21 +00:00
rustc_thread_pool Correct comments. 2025-06-28 17:58:21 +08:00
rustc_trait_selection Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_traits Remove fast path from codegen_select, since Sized has no methods 2025-07-02 00:33:06 +00:00
rustc_transmute compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
rustc_ty_utils Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
rustc_type_ir setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00