rust/compiler
Jonathan Brouwer 53fb684f84
Rollup merge of #150557 - dianne:no-const-block-eval-in-promotion, r=lcnr
Don't try to evaluate const blocks during constant promotion

As of https://github.com/rust-lang/rust/pull/138499, trying to evaluate a const block in anything depended on by borrow-checking will result in a query cycle. Since that could happen in constant promotion, this PR adds a check for const blocks there to stop them from being evaluated.

Admittedly, this is a hack. See https://github.com/rust-lang/rust/issues/124328 for discussion of a more principled fix: removing cases like this from constant promotion altogether. To simplify the conditions under which promotion can occur, we probably shouldn't be implicitly promoting division or array indexing at all if possible. That would likely require a FCW and migration period, so I figure we may as well patch up the cycle now and simplify later.

Fixes rust-lang/rust#150464

I'll also lang-nominate this for visibility. I'm not sure there's much to discuss about this PR specifically, but it does represent a change in semantics. In Rust 1.87, the code below compiled. In Rust 1.88, it became a query cycle error. After this PR, it fails to borrow-check because the temporaries can no longer be promoted.

```rust
let (x, y, z);
// We only promote array indexing if the index is known to be in-bounds.
x = &([0][const { 0 }] & 0);
// We only promote integer division if the divisor is known not to be zero.
y = &(1 / const { 1 });
// Furthermore, if the divisor is `-1`, we only promote if the dividend is
// known not to be `int::MIN`.
z = &(const { 1 } / -1);
// The borrowed temporaries can't be promoted, so they were dropped at the ends
// of their respective statements.
(x, y, z);
```
2026-01-27 17:00:54 +01:00
..
rustc Auto merge of #148925 - madsmtm:jemalloc-perf, r=Kobzol 2025-11-23 20:34:07 +00:00
rustc_abi Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov 2026-01-25 02:49:32 +00:00
rustc_arena Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
rustc_ast Rollup merge of #149174 - GrigorenkoPV:const_block_item, r=me,ytmimi 2026-01-24 15:35:08 +01:00
rustc_ast_ir Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
rustc_ast_lowering Rollup merge of #147996 - pmur:murp/stabilize-ppc-inlineasm, r=Amanieu 2026-01-27 12:50:49 +11:00
rustc_ast_passes Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov 2026-01-25 02:49:32 +00:00
rustc_ast_pretty const_block_items: do not create an AnonConst 2026-01-21 19:36:27 +03:00
rustc_attr_parsing Do not emit errors on non-metaitem diagnostic attr input 2026-01-22 23:42:01 +01:00
rustc_baked_icu_data Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_borrowck Rollup merge of #151374 - BoxyUwU:borrowck_cleanup_3, r=lcnr 2026-01-26 18:19:14 +01:00
rustc_builtin_macros Rollup merge of #151137 - osiewicz:151090-checksum-freshness-binary-files, r=jdonszelmann 2026-01-27 12:50:50 +11:00
rustc_codegen_cranelift Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov 2026-01-25 02:49:32 +00:00
rustc_codegen_gcc Omit standard copyright notice 2026-01-26 17:31:34 +00:00
rustc_codegen_llvm Auto merge of #151337 - the8472:bail-before-memcpy2, r=Mark-Simulacrum 2026-01-25 19:45:35 +00:00
rustc_codegen_ssa Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee 2026-01-24 21:04:15 +01:00
rustc_const_eval Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee 2026-01-24 21:04:15 +01:00
rustc_data_structures refactor rustc-hash integration 2026-01-23 23:16:15 +01:00
rustc_driver Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_driver_impl Move collect_crate_types to rustc_interface, and use new attribute parser 2026-01-22 02:34:28 +00:00
rustc_error_codes Port #[instruction_set] to attribute parser 2025-12-31 03:01:05 +01:00
rustc_error_messages Remove DiagMessage::Translated in favour of DiagMessage::Str 2026-01-18 18:30:11 +01:00
rustc_errors Rollup merge of #151439 - Mark-Simulacrum:bootstrap-bump, r=nnethercote 2026-01-22 00:37:43 -05:00
rustc_expand Rollup merge of #151694 - cyrgani:more-pm-cleanup, r=petrochenkov 2026-01-27 17:00:53 +01:00
rustc_feature Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov 2026-01-25 02:49:32 +00:00
rustc_fluent_macro Bump stage0 2026-01-21 20:03:56 -05:00
rustc_fs_util Avoid using env::temp when linking a binary 2025-12-24 06:41:42 +00:00
rustc_graphviz change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_hashes some cleanups in compiler 2025-10-12 08:08:30 +00:00
rustc_hir Rollup merge of #149174 - GrigorenkoPV:const_block_item, r=me,ytmimi 2026-01-24 15:35:08 +01:00
rustc_hir_analysis Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee 2026-01-24 21:04:15 +01:00
rustc_hir_id
rustc_hir_pretty Introduce hir::ConstArgKind::Array 2026-01-10 12:41:50 +09:00
rustc_hir_typeck don't return incorrectly constrained opaques in method_autoderef_steps 2026-01-26 17:30:18 +08:00
rustc_incremental Make Deps::name lookup a non-self associated function 2026-01-21 12:02:26 +11:00
rustc_index simplify words initialization using Rc::new_zeroed 2026-01-16 04:25:12 +05:30
rustc_index_macros
rustc_infer don't return incorrectly constrained opaques in method_autoderef_steps 2026-01-26 17:30:18 +08:00
rustc_interface Rollup merge of #151137 - osiewicz:151090-checksum-freshness-binary-files, r=jdonszelmann 2026-01-27 12:50:50 +11:00
rustc_lexer lexer/parser: ensure deps use the same unicode version 2025-12-27 11:20:42 +01:00
rustc_lint lint: Use rustc_apfloat for overflowing_literals, add f16 and f128 2026-01-26 18:25:42 -06:00
rustc_lint_defs Port crate_type to attribute parser 2026-01-22 02:34:28 +00:00
rustc_llvm Rollup merge of #150780 - fzakaria:fzakaria/section-threshold, r=jackh726 2026-01-23 11:07:55 +01:00
rustc_log Restrict sysroot crate imports to those defined in this repo. 2025-10-15 13:17:25 +01:00
rustc_macros Bump stage0 2026-01-21 20:03:56 -05:00
rustc_metadata Port crate_type to attribute parser 2026-01-22 02:34:28 +00:00
rustc_middle Rollup merge of #151097 - nnethercote:associated_type_defaults-query-key, r=Noratrieb 2026-01-27 17:36:36 +11:00
rustc_mir_build THIR patterns: Explicitly distinguish &pin from plain &/&mut 2026-01-20 13:41:32 +11:00
rustc_mir_dataflow Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11:00
rustc_mir_transform Don't evaluate const blocks in constant promotion 2026-01-27 04:31:57 -08:00
rustc_monomorphize Rollup merge of #151441 - Keith-Cancel:mgca3, r=BoxyUwU 2026-01-22 13:35:42 +01:00
rustc_next_trait_solver Rollup merge of #148637 - rustc_dyn_incompatible, r=lcnr 2026-01-21 02:04:01 -05:00
rustc_parse Rollup merge of #151290 - Unique-Usman:ua/nostruct, r=estebank 2026-01-26 18:19:12 +01:00
rustc_parse_format rustc_parse_format: improve diagnostics for unsupported python numeric grouping 2026-01-11 23:42:38 +05:30
rustc_passes Rollup merge of #149174 - GrigorenkoPV:const_block_item, r=me,ytmimi 2026-01-24 15:35:08 +01:00
rustc_pattern_analysis THIR patterns: Explicitly distinguish &pin from plain &/&mut 2026-01-20 13:41:32 +11:00
rustc_privacy Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_proc_macro Update literal-escaper version to 0.0.7 2026-01-08 14:10:33 +01:00
rustc_public Rollup merge of #151040 - moulins:public-variant-layout, r=makai410 2026-01-27 12:50:52 +11:00
rustc_public_bridge Overhaul filename handling for cross-compiler consistency 2025-12-12 07:33:09 +01:00
rustc_query_impl Rollup merge of #151390 - nnethercote:revert, r=petrochenkov 2026-01-27 17:36:36 +11:00
rustc_query_system Reintroduce QueryStackFrame split. 2026-01-27 09:42:38 +11:00
rustc_resolve use CmResolver instead of &mut CmResolver 2026-01-25 22:57:15 +01:00
rustc_sanitizers Port #[cfi_encoding] to attribute parser 2025-12-21 22:11:33 +01:00
rustc_serialize Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_session Rollup merge of #151589 - Urgau:documentation-scope, r=GuillaumeGomez 2026-01-26 14:36:22 +11:00
rustc_span Rollup merge of #151661 - estebank:issue-68095, r=mati865 2026-01-26 18:19:17 +01:00
rustc_symbol_mangling Fix v0 symbol mangling for assoc const bindings 2026-01-21 12:53:45 +01:00
rustc_target Adds two new Tier 3 targets - aarch64v8r-unknown-none and aarch64v8r-unknown-none-softfloat. 2026-01-26 12:43:52 +00:00
rustc_thread_pool change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_trait_selection Suggest changing iter/into_iter when the other was meant 2026-01-25 23:12:05 +00:00
rustc_traits implied bounds comments 2026-01-19 16:08:54 +00:00
rustc_transmute Clean up src/dst transmute mess. 2026-01-12 09:22:58 +11:00
rustc_ty_utils Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11:00
rustc_type_ir refactor rustc-hash integration 2026-01-23 23:16:15 +01:00
rustc_type_ir_macros Provide an extended framework for type visit, for use in rust-analyzer 2025-12-16 01:47:28 +02:00
rustc_windows_rc