From a5181d2fd6d149dac10a7f888be0c46ba4a34d89 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Fri, 3 Apr 2026 20:37:45 +1100 Subject: [PATCH 1/7] Remove `rfail` support from incremental tests Incremental revisions beginning with `rfail` would cause the incremental test runner to build the test program, expecting success, and then run the test program, expecting failure. Expecting incremental tests to fail at runtime is of questionable utility, because in almost all cases an equivalent test program can be made to succeed at runtime instead. Removing `rfail` support is a small step towards cleaning up compiletest's incremental test runner, and its overall handling of pass/fail expectations. There was one existing regression test using `rfail` revisions: `tests/incremental/issue-80691-bad-eval-cache.rs`. The test code is complex, and reverting the fix in RUST-83220 does not actually cause the test to fail, suggesting that it is no longer a useful regression test. This commit therefore deletes that test. --- .../rustc-dev-guide/src/tests/compiletest.md | 4 +- src/tools/compiletest/src/runtest.rs | 7 +- .../compiletest/src/runtest/incremental.rs | 32 +-- .../incremental/issue-80691-bad-eval-cache.rs | 186 ------------------ 4 files changed, 7 insertions(+), 222 deletions(-) delete mode 100644 tests/incremental/issue-80691-bad-eval-cache.rs diff --git a/src/doc/rustc-dev-guide/src/tests/compiletest.md b/src/doc/rustc-dev-guide/src/tests/compiletest.md index a239310d124ec..83fcfecc1de7b 100644 --- a/src/doc/rustc-dev-guide/src/tests/compiletest.md +++ b/src/doc/rustc-dev-guide/src/tests/compiletest.md @@ -158,9 +158,9 @@ then runs the compiler for each revision, reusing the incremental results from p The revisions should start with: -* `rpass` — the test should compile and run successfully -* `rfail` — the test should compile successfully, but the executable should fail to run * `cfail` — the test should fail to compile +* `cpass` — the test should compile successully +* `rpass` — the test should compile and run successfully To make the revisions unique, you should add a suffix like `rpass1` and `rpass2`. diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 53599179cfce0..5fc3dbbfbc545 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -333,15 +333,12 @@ impl<'test> TestCx<'test> { TestMode::Incremental => { let revision = self.revision.expect("incremental tests require a list of revisions"); - if revision.starts_with("cpass") - || revision.starts_with("rpass") - || revision.starts_with("rfail") - { + if revision.starts_with("cpass") || revision.starts_with("rpass") { true } else if revision.starts_with("cfail") { pm.is_some() } else { - panic!("revision name must begin with cpass, rpass, rfail, or cfail"); + panic!("revision name must begin with `cfail`, `cpass`, or `rpass`"); } } mode => panic!("unimplemented for mode {:?}", mode), diff --git a/src/tools/compiletest/src/runtest/incremental.rs b/src/tools/compiletest/src/runtest/incremental.rs index 5e7698e24858b..75e43006486ec 100644 --- a/src/tools/compiletest/src/runtest/incremental.rs +++ b/src/tools/compiletest/src/runtest/incremental.rs @@ -5,17 +5,16 @@ impl TestCx<'_> { pub(super) fn run_incremental_test(&self) { // Basic plan for a test incremental/foo/bar.rs: // - load list of revisions rpass1, cfail2, rpass3 - // - each should begin with `cpass`, `rpass`, `cfail`, or `rfail` + // - each should begin with `cfail`, `cpass`, or `rpass` // - if `cpass`, expect compilation to succeed, don't execute // - if `rpass`, expect compilation and execution to succeed // - if `cfail`, expect compilation to fail - // - if `rfail`, expect compilation to succeed and execution to fail // - create a directory build/foo/bar.incremental // - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C rpass1 // - because name of revision starts with "rpass", expect success // - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C cfail2 // - because name of revision starts with "cfail", expect an error - // - load expected errors as usual, but filter for those that end in `[rfail2]` + // - load expected errors as usual, but filter for those with `[cfail2]` // - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C rpass3 // - because name of revision starts with "rpass", expect success // - execute build/foo/bar.exe and save output @@ -43,15 +42,10 @@ impl TestCx<'_> { self.fatal("can only use should-ice in cfail tests"); } self.run_rpass_test(); - } else if revision.starts_with("rfail") { - if self.props.should_ice { - self.fatal("can only use should-ice in cfail tests"); - } - self.run_rfail_test(); } else if revision.starts_with("cfail") { self.run_cfail_test(); } else { - self.fatal("revision name must begin with cpass, rpass, rfail, or cfail"); + self.fatal("revision name must begin with `cfail`, `cpass`, or `rpass`"); } } @@ -111,24 +105,4 @@ impl TestCx<'_> { self.check_forbid_output(&output_to_check, &proc_res); } - - fn run_rfail_test(&self) { - let pm = self.pass_mode(); - let should_run = self.run_if_enabled(); - let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm)); - - if !proc_res.status.success() { - self.fatal_proc_rec("compilation failed!", &proc_res); - } - - if let WillExecute::Disabled = should_run { - return; - } - - let proc_res = self.exec_compiled_test(); - - let output_to_check = self.get_output(&proc_res); - self.check_correct_failure_status(&proc_res); - self.check_all_error_patterns(&output_to_check, &proc_res); - } } diff --git a/tests/incremental/issue-80691-bad-eval-cache.rs b/tests/incremental/issue-80691-bad-eval-cache.rs deleted file mode 100644 index 2d3dbf6fed661..0000000000000 --- a/tests/incremental/issue-80691-bad-eval-cache.rs +++ /dev/null @@ -1,186 +0,0 @@ -//@ revisions: rfail1 rfail2 -//@ failure-status: 101 -//@ error-pattern: not implemented -//@ needs-unwind -Cpanic=abort causes abort instead of exit(101) -//@ ignore-backends: gcc - -pub trait Interner { - type InternedVariableKinds; -} - -trait RustIrDatabase { - fn associated_ty_data(&self) -> AssociatedTyDatum; - fn impl_datum(&self) -> ImplDatum; -} - -trait Fold { - type Result; -} -impl Fold for Binders -where - T: HasInterner + Fold, - >::Result: HasInterner, - I: Interner, -{ - type Result = Binders; -} -impl Fold for WhereClause { - type Result = Binders>; -} - -trait HasInterner { - type Interner: Interner; -} -impl HasInterner for Vec { - type Interner = T::Interner; -} -impl HasInterner for &T { - type Interner = T::Interner; -} - -pub struct VariableKind { - _marker: std::marker::PhantomData, -} - -struct VariableKinds { - _interned: I::InternedVariableKinds, -} - -struct WhereClause { - _marker: std::marker::PhantomData, -} -impl HasInterner for WhereClause { - type Interner = I; -} - -struct Binders { - _marker: std::marker::PhantomData, -} -impl HasInterner for Binders { - type Interner = T::Interner; -} -impl Binders<&T> { - fn cloned(self) -> Binders { - unimplemented!() - } -} -impl Binders { - fn map_ref<'a, U, OP>(&'a self, _op: OP) -> Binders - where - OP: FnOnce(&'a T) -> U, - U: HasInterner, - { - unimplemented!() - } -} -impl Binders -where - T: Fold + HasInterner, - I: Interner, -{ - fn substitute(self) -> T::Result { - unimplemented!() - } -} -impl IntoIterator for Binders -where - V: HasInterner + IntoIterator, - U: HasInterner, -{ - type Item = Binders; - type IntoIter = BindersIntoIterator; - fn into_iter(self) -> Self::IntoIter { - unimplemented!() - } -} -struct BindersIntoIterator { - _binders: VariableKinds, -} -impl Iterator for BindersIntoIterator -where - V: HasInterner + IntoIterator, - ::Item: HasInterner, -{ - type Item = Binders<::Item>; - fn next(&mut self) -> Option { - unimplemented!() - } -} - -struct ImplDatum { - binders: Binders>, -} -struct ImplDatumBound { - where_clauses: Vec>>, -} -impl HasInterner for ImplDatumBound { - type Interner = I; -} - -struct AssociatedTyDatum { - binders: Binders>, -} - -struct AssociatedTyDatumBound { - where_clauses: Vec>>, -} -impl HasInterner for AssociatedTyDatumBound { - type Interner = I; -} - -struct ClauseBuilder<'me, I: Interner> { - db: &'me dyn RustIrDatabase, -} -impl<'me, I: Interner> ClauseBuilder<'me, I> { - fn new() -> Self { - unimplemented!() - } - fn push_clause(&mut self, _conditions: impl Iterator>>>) { - unimplemented!() - } -} - -pub(crate) struct Forest { - _marker: std::marker::PhantomData, -} - -impl Forest { - fn iter_answers<'f>(&'f self) { - let builder = &mut ClauseBuilder::::new(); - let impl_datum = builder.db.impl_datum(); - let impl_where_clauses = impl_datum - .binders - .map_ref(|b| &b.where_clauses) - .into_iter() - .map(|wc| wc.cloned().substitute()); - let associated_ty = builder.db.associated_ty_data(); - let assoc_ty_where_clauses = associated_ty - .binders - .map_ref(|b| &b.where_clauses) - .into_iter() - .map(|wc| wc.cloned().substitute()); - builder.push_clause(impl_where_clauses.chain(assoc_ty_where_clauses)); - } -} - -pub struct SLGSolver { - pub(crate) forest: Forest, -} -impl SLGSolver { - fn new() -> Self { - unimplemented!() - } - fn solve_multiple(&self) { - let _answers = self.forest.iter_answers(); - } -} - -pub struct ChalkIr; -impl Interner for ChalkIr { - type InternedVariableKinds = Vec>; -} - -fn main() { - let solver = SLGSolver::new(); - solver.solve_multiple(); -} From 56603e486769118a89d55a2a76a251e34d4ee9a1 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Thu, 2 Apr 2026 12:20:42 +0200 Subject: [PATCH 2/7] rename `{ref=>imm_ptr}_to_mplace`, `mplace_to_{ref=>imm_ptr}` --- .../rustc_const_eval/src/const_eval/machine.rs | 2 +- .../rustc_const_eval/src/const_eval/type_info.rs | 4 ++-- .../src/const_eval/type_info/adt.rs | 2 +- compiler/rustc_const_eval/src/interpret/call.rs | 6 +++--- .../rustc_const_eval/src/interpret/intrinsics.rs | 2 +- compiler/rustc_const_eval/src/interpret/place.rs | 16 ++++++++-------- .../rustc_const_eval/src/interpret/validity.rs | 2 +- .../src/borrow_tracker/stacked_borrows/mod.rs | 2 +- .../miri/src/borrow_tracker/tree_borrows/mod.rs | 2 +- src/tools/miri/src/shims/panic.rs | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index a19bf0b4da8be..316bca5a258f1 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -840,7 +840,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { { // That next check is expensive, that's why we have all the guards above. let is_immutable = ty.is_freeze(*ecx.tcx, ecx.typing_env()); - let place = ecx.ref_to_mplace(val)?; + let place = ecx.imm_ptr_to_mplace(val)?; let new_place = if is_immutable { place.map_provenance(CtfeProvenance::as_immutable) } else { diff --git a/compiler/rustc_const_eval/src/const_eval/type_info.rs b/compiler/rustc_const_eval/src/const_eval/type_info.rs index 0ed04a5ab20b4..427100e78aae4 100644 --- a/compiler/rustc_const_eval/src/const_eval/type_info.rs +++ b/compiler/rustc_const_eval/src/const_eval/type_info.rs @@ -261,7 +261,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { None => Cow::Owned(idx.to_string()), // For tuples }; let name_place = self.allocate_str_dedup(&name)?; - let ptr = self.mplace_to_ref(&name_place)?; + let ptr = self.mplace_to_imm_ptr(&name_place)?; self.write_immediate(*ptr, &field_place)? } sym::ty => { @@ -444,7 +444,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { other_abi => { let (variant, variant_place) = self.downcast(&field_place, sym::Named)?; let str_place = self.allocate_str_dedup(other_abi.as_str())?; - let str_ref = self.mplace_to_ref(&str_place)?; + let str_ref = self.mplace_to_imm_ptr(&str_place)?; let payload = self.project_field(&variant_place, FieldIdx::ZERO)?; self.write_immediate(*str_ref, &payload)?; self.write_discriminant(variant, &field_place)?; diff --git a/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs b/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs index 60f7b95e799a6..ac730faf9d431 100644 --- a/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs +++ b/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs @@ -165,7 +165,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { match field_def.name { sym::name => { let name_place = self.allocate_str_dedup(variant_def.name.as_str())?; - let ptr = self.mplace_to_ref(&name_place)?; + let ptr = self.mplace_to_imm_ptr(&name_place)?; self.write_immediate(*ptr, &field_place)? } sym::fields => { diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 0ac9f3025d48c..ef99a64cb147c 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -704,7 +704,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // actually access memory to resolve this method. // Also see . let val = self.read_immediate(&receiver)?; - break self.ref_to_mplace(&val)?; + break self.imm_ptr_to_mplace(&val)?; } ty::Dynamic(..) => break receiver.assert_mem_place(), // no immediate unsized values _ => { @@ -877,7 +877,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // then dispatches that to the normal call machinery. However, our call machinery currently // only supports calling `VtblEntry::Method`; it would choke on a `MetadataDropInPlace`. So // instead we do the virtual call stuff ourselves. It's easier here than in `eval_fn_call` - // since we can just get a place of the underlying type and use `mplace_to_ref`. + // since we can just get a place of the underlying type and use `mplace_to_imm_ptr`. let place = match place.layout.ty.kind() { ty::Dynamic(data, _) => { // Dropping a trait object. Need to find actual drop fn. @@ -898,7 +898,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { }; let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?; - let arg = self.mplace_to_ref(&place)?; + let arg = self.mplace_to_imm_ptr(&place)?; let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?); self.init_fn_call( diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 17311188879c1..79a9b616cfcfa 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -281,7 +281,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { sym::align_of_val | sym::size_of_val => { // Avoid `deref_pointer` -- this is not a deref, the ptr does not have to be // dereferenceable! - let place = self.ref_to_mplace(&self.read_immediate(&args[0])?)?; + let place = self.imm_ptr_to_mplace(&self.read_immediate(&args[0])?)?; let (size, align) = self .size_and_align_of_val(&place)? .ok_or_else(|| err_unsup_format!("`extern type` does not have known layout"))?; diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index b410e8f6c57ea..0e0ee1ccd8f39 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -417,22 +417,22 @@ where self.ptr_with_meta_to_mplace(ptr, MemPlaceMeta::None, layout, /*unaligned*/ true) } - /// Take a value, which represents a (thin or wide) reference, and make it a place. - /// Alignment is just based on the type. This is the inverse of `mplace_to_ref()`. + /// Take a value, which represents a (thin or wide) pointer, and make it a place. + /// Alignment is just based on the type. This is the inverse of `mplace_to_imm_ptr()`. /// /// Only call this if you are sure the place is "valid" (aligned and inbounds), or do not /// want to ever use the place for memory access! /// Generally prefer `deref_pointer`. - pub fn ref_to_mplace( + pub fn imm_ptr_to_mplace( &self, val: &ImmTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> { let pointee_type = - val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type"); + val.layout.ty.builtin_deref(true).expect("`imm_ptr_to_mplace` called on non-ptr type"); let layout = self.layout_of(pointee_type)?; let (ptr, meta) = val.to_scalar_and_meta(); - // `ref_to_mplace` is called on raw pointers even if they don't actually get dereferenced; + // `imm_ptr_to_mplace` is called on raw pointers even if they don't actually get dereferenced; // we hence can't call `size_and_align_of` since that asserts more validity than we want. let ptr = ptr.to_pointer(self)?; interp_ok(self.ptr_with_meta_to_mplace(ptr, meta, layout, /*unaligned*/ false)) @@ -440,8 +440,8 @@ where /// Turn a mplace into a (thin or wide) mutable raw pointer, pointing to the same space. /// `align` information is lost! - /// This is the inverse of `ref_to_mplace`. - pub fn mplace_to_ref( + /// This is the inverse of `imm_ptr_to_mplace`. + pub fn mplace_to_imm_ptr( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> { @@ -467,7 +467,7 @@ where let val = self.read_immediate(src)?; trace!("deref to {} on {:?}", val.layout.ty, *val); - let mplace = self.ref_to_mplace(&val)?; + let mplace = self.imm_ptr_to_mplace(&val)?; interp_ok(mplace) } diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index de340057d0e81..c1b72369dfadf 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -572,7 +572,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> { self.add_data_range_place(val); } // Now turn it into a place. - self.ecx.ref_to_mplace(&imm) + self.ecx.imm_ptr_to_mplace(&imm) } fn check_wide_ptr_meta( diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs index 66e804d972b76..8adb6d3127694 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs @@ -859,7 +859,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> { info: RetagInfo, // diagnostics info about this retag ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); - let place = this.ref_to_mplace(val)?; + let place = this.imm_ptr_to_mplace(val)?; let new_place = this.sb_retag_place(&place, new_perm, info)?; interp_ok(ImmTy::from_immediate(new_place.to_ref(this), val.layout)) } diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index a205502327307..b191359501d18 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -415,7 +415,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { new_perm: NewPermission, ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); - let place = this.ref_to_mplace(val)?; + let place = this.imm_ptr_to_mplace(val)?; let new_place = this.tb_retag_place(&place, new_perm)?; interp_ok(ImmTy::from_immediate(new_place.to_ref(this), val.layout)) } diff --git a/src/tools/miri/src/shims/panic.rs b/src/tools/miri/src/shims/panic.rs index 85564e47685f2..34589ecf7af6a 100644 --- a/src/tools/miri/src/shims/panic.rs +++ b/src/tools/miri/src/shims/panic.rs @@ -20,7 +20,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.call_function( panic, ExternAbi::Rust, - &[this.mplace_to_ref(&msg)?], + &[this.mplace_to_imm_ptr(&msg)?], None, ReturnContinuation::Goto { ret: None, unwind }, ) @@ -39,7 +39,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.call_function( panic, ExternAbi::Rust, - &[this.mplace_to_ref(&msg)?], + &[this.mplace_to_imm_ptr(&msg)?], None, ReturnContinuation::Goto { ret: None, unwind: mir::UnwindAction::Unreachable }, ) From 407259b2ff7ebe66eaacd566570a7ac7d28b3e19 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Sun, 5 Apr 2026 20:01:45 +0200 Subject: [PATCH 3/7] allow `mplace_to_imm_ptr` to return different types of pointers --- .../rustc_const_eval/src/const_eval/type_info.rs | 4 ++-- .../rustc_const_eval/src/const_eval/type_info/adt.rs | 2 +- compiler/rustc_const_eval/src/interpret/call.rs | 2 +- compiler/rustc_const_eval/src/interpret/place.rs | 12 +++++++++++- src/tools/miri/src/shims/panic.rs | 4 ++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/type_info.rs b/compiler/rustc_const_eval/src/const_eval/type_info.rs index 427100e78aae4..dffc66f731af0 100644 --- a/compiler/rustc_const_eval/src/const_eval/type_info.rs +++ b/compiler/rustc_const_eval/src/const_eval/type_info.rs @@ -261,7 +261,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { None => Cow::Owned(idx.to_string()), // For tuples }; let name_place = self.allocate_str_dedup(&name)?; - let ptr = self.mplace_to_imm_ptr(&name_place)?; + let ptr = self.mplace_to_imm_ptr(&name_place, None)?; self.write_immediate(*ptr, &field_place)? } sym::ty => { @@ -444,7 +444,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { other_abi => { let (variant, variant_place) = self.downcast(&field_place, sym::Named)?; let str_place = self.allocate_str_dedup(other_abi.as_str())?; - let str_ref = self.mplace_to_imm_ptr(&str_place)?; + let str_ref = self.mplace_to_imm_ptr(&str_place, None)?; let payload = self.project_field(&variant_place, FieldIdx::ZERO)?; self.write_immediate(*str_ref, &payload)?; self.write_discriminant(variant, &field_place)?; diff --git a/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs b/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs index ac730faf9d431..2143313bbbada 100644 --- a/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs +++ b/compiler/rustc_const_eval/src/const_eval/type_info/adt.rs @@ -165,7 +165,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { match field_def.name { sym::name => { let name_place = self.allocate_str_dedup(variant_def.name.as_str())?; - let ptr = self.mplace_to_imm_ptr(&name_place)?; + let ptr = self.mplace_to_imm_ptr(&name_place, None)?; self.write_immediate(*ptr, &field_place)? } sym::fields => { diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index ef99a64cb147c..d948b78a0bcf9 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -898,7 +898,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { }; let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?; - let arg = self.mplace_to_imm_ptr(&place)?; + let arg = self.mplace_to_imm_ptr(&place, None)?; let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?); self.init_fn_call( diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 0e0ee1ccd8f39..0118fd71a5975 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -439,14 +439,24 @@ where } /// Turn a mplace into a (thin or wide) mutable raw pointer, pointing to the same space. + /// /// `align` information is lost! /// This is the inverse of `imm_ptr_to_mplace`. + /// + /// If `ptr_ty` is provided, the resulting pointer will be of that type. Otherwise, it defaults to `*mut _`. + /// `ptr_ty` must be a type with builtin deref which derefs to the type of `mplace` (`mplace.layout.ty`). pub fn mplace_to_imm_ptr( &self, mplace: &MPlaceTy<'tcx, M::Provenance>, + ptr_ty: Option>, ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> { let imm = mplace.mplace.to_ref(self); - let layout = self.layout_of(Ty::new_mut_ptr(self.tcx.tcx, mplace.layout.ty))?; + + let ptr_ty = ptr_ty + .inspect(|t| assert_eq!(t.builtin_deref(true), Some(mplace.layout.ty))) + .unwrap_or_else(|| Ty::new_mut_ptr(self.tcx.tcx, mplace.layout.ty)); + + let layout = self.layout_of(ptr_ty)?; interp_ok(ImmTy::from_immediate(imm, layout)) } diff --git a/src/tools/miri/src/shims/panic.rs b/src/tools/miri/src/shims/panic.rs index 34589ecf7af6a..50e32cffaee3f 100644 --- a/src/tools/miri/src/shims/panic.rs +++ b/src/tools/miri/src/shims/panic.rs @@ -20,7 +20,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.call_function( panic, ExternAbi::Rust, - &[this.mplace_to_imm_ptr(&msg)?], + &[this.mplace_to_imm_ptr(&msg, None)?], None, ReturnContinuation::Goto { ret: None, unwind }, ) @@ -39,7 +39,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.call_function( panic, ExternAbi::Rust, - &[this.mplace_to_imm_ptr(&msg)?], + &[this.mplace_to_imm_ptr(&msg, None)?], None, ReturnContinuation::Goto { ret: None, unwind: mir::UnwindAction::Unreachable }, ) From d5f98fbb27f6f31a7d211353b016941fa45f699d Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 6 Apr 2026 17:01:55 +0200 Subject: [PATCH 4/7] implement `StructuralPartialEq` for `MaybeDangling` This fixes a stable-to-stable regression where constants of type `ManuallyDrop` would not be allowed to be used as a pattern due to `MaybeDangling` in `ManuallyDrop` not implementing `StructuralPartialEq`. --- library/core/src/mem/maybe_dangling.rs | 3 +++ tests/ui/consts/manually_drop_structural_eq.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/ui/consts/manually_drop_structural_eq.rs diff --git a/library/core/src/mem/maybe_dangling.rs b/library/core/src/mem/maybe_dangling.rs index c85576b5778cc..2c9c435c24085 100644 --- a/library/core/src/mem/maybe_dangling.rs +++ b/library/core/src/mem/maybe_dangling.rs @@ -1,5 +1,6 @@ #![unstable(feature = "maybe_dangling", issue = "118166")] +use crate::marker::StructuralPartialEq; use crate::{mem, ptr}; /// Allows wrapped [references] and [boxes] to dangle. @@ -109,3 +110,5 @@ impl MaybeDangling

{ x } } + +impl StructuralPartialEq for MaybeDangling {} diff --git a/tests/ui/consts/manually_drop_structural_eq.rs b/tests/ui/consts/manually_drop_structural_eq.rs new file mode 100644 index 0000000000000..1768ebd5f9c4e --- /dev/null +++ b/tests/ui/consts/manually_drop_structural_eq.rs @@ -0,0 +1,16 @@ +// Check that `ManuallyDrop` types can be used as a constant when matching. +// I.e. that `ManuallyDrop` implements `StructuralPartialEq`. +// +// Regression test for . +// +//@ check-pass +use std::mem::ManuallyDrop; + +fn main() { + const X: ManuallyDrop = ManuallyDrop::new(1); + + match ManuallyDrop::new(1) { + X => println!("blah"), + _ => println!("bleh"), + } +} From 31c694d71b7d3c6fa5f0b66eab3092dc5fda370f Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Mon, 6 Apr 2026 19:03:06 +0200 Subject: [PATCH 5/7] Update books --- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/reference b/src/doc/reference index 7446bf9697c95..d2715c07e9dd9 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 7446bf9697c95d155eef33c6a9d91fbd29a5e359 +Subproject commit d2715c07e9dd9839c0c7675ecfa18bec539a6ee9 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 5383db524711c..b31e3b8da01ee 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 5383db524711c0c9c43c3ca9e5e706089672ed6a +Subproject commit b31e3b8da01eeba0460f86a52a55af82709fadf5 From fc71bad873a361c98a6d1db74bc72ccb6503a098 Mon Sep 17 00:00:00 2001 From: Lars Schumann Date: Thu, 2 Apr 2026 21:13:28 +0000 Subject: [PATCH 6/7] de-non_const some iterator methods --- library/core/src/array/mod.rs | 10 ++-- .../core/src/iter/adapters/array_chunks.rs | 2 +- library/core/src/iter/adapters/chain.rs | 2 +- library/core/src/iter/adapters/cloned.rs | 2 +- library/core/src/iter/adapters/copied.rs | 2 +- library/core/src/iter/adapters/cycle.rs | 3 +- library/core/src/iter/adapters/enumerate.rs | 2 +- library/core/src/iter/adapters/filter.rs | 2 +- library/core/src/iter/adapters/filter_map.rs | 2 +- library/core/src/iter/adapters/flatten.rs | 9 ++-- library/core/src/iter/adapters/fuse.rs | 2 +- library/core/src/iter/adapters/inspect.rs | 2 +- library/core/src/iter/adapters/intersperse.rs | 4 +- library/core/src/iter/adapters/map.rs | 2 +- library/core/src/iter/adapters/map_while.rs | 2 +- library/core/src/iter/adapters/map_windows.rs | 4 +- library/core/src/iter/adapters/peekable.rs | 2 +- library/core/src/iter/adapters/rev.rs | 2 +- library/core/src/iter/adapters/scan.rs | 2 +- library/core/src/iter/adapters/skip.rs | 2 +- library/core/src/iter/adapters/skip_while.rs | 2 +- library/core/src/iter/adapters/take.rs | 2 +- library/core/src/iter/adapters/take_while.rs | 2 +- library/core/src/iter/traits/accum.rs | 6 ++- library/core/src/iter/traits/iterator.rs | 50 +++++-------------- .../ui/typeck/typeck_type_placeholder_item.rs | 4 +- .../typeck_type_placeholder_item.stderr | 42 +++++++--------- 27 files changed, 74 insertions(+), 94 deletions(-) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index b116841578902..fc540e2d20dd2 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -1005,9 +1005,10 @@ impl const Drop for Guard<'_, T> { /// dropped. /// /// Used for [`Iterator::next_chunk`]. +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] #[inline] -pub(crate) fn iter_next_chunk( - iter: &mut impl Iterator, +pub(crate) const fn iter_next_chunk( + iter: &mut impl [const] Iterator, ) -> Result<[T; N], IntoIter> { let mut array = [const { MaybeUninit::uninit() }; N]; let r = iter_next_chunk_erased(&mut array, iter); @@ -1028,10 +1029,11 @@ pub(crate) fn iter_next_chunk( /// /// Unfortunately this loop has two exit conditions, the buffer filling up /// or the iterator running out of items, making it tend to optimize poorly. +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] #[inline] -fn iter_next_chunk_erased( +const fn iter_next_chunk_erased( buffer: &mut [MaybeUninit], - iter: &mut impl Iterator, + iter: &mut impl [const] Iterator, ) -> Result<(), usize> { // if `Iterator::next` panics, this guard will drop already initialized items let mut guard = Guard { array_mut: buffer, initialized: 0 }; diff --git a/library/core/src/iter/adapters/array_chunks.rs b/library/core/src/iter/adapters/array_chunks.rs index 7c003cff10c7b..a3e5ae5e7698b 100644 --- a/library/core/src/iter/adapters/array_chunks.rs +++ b/library/core/src/iter/adapters/array_chunks.rs @@ -26,7 +26,7 @@ where I: Iterator, { #[track_caller] - pub(in crate::iter) fn new(iter: I) -> Self { + pub(in crate::iter) const fn new(iter: I) -> Self { assert!(N != 0, "chunk size must be non-zero"); Self { iter, remainder: None } } diff --git a/library/core/src/iter/adapters/chain.rs b/library/core/src/iter/adapters/chain.rs index 0ece54554d464..d143b67fd4353 100644 --- a/library/core/src/iter/adapters/chain.rs +++ b/library/core/src/iter/adapters/chain.rs @@ -33,7 +33,7 @@ pub struct Chain { b: Option, } impl Chain { - pub(in super::super) fn new(a: A, b: B) -> Chain { + pub(in super::super) const fn new(a: A, b: B) -> Chain { Chain { a: Some(a), b: Some(b) } } } diff --git a/library/core/src/iter/adapters/cloned.rs b/library/core/src/iter/adapters/cloned.rs index aea6d64281aec..54d132813e4db 100644 --- a/library/core/src/iter/adapters/cloned.rs +++ b/library/core/src/iter/adapters/cloned.rs @@ -20,7 +20,7 @@ pub struct Cloned { } impl Cloned { - pub(in crate::iter) fn new(it: I) -> Cloned { + pub(in crate::iter) const fn new(it: I) -> Cloned { Cloned { it } } } diff --git a/library/core/src/iter/adapters/copied.rs b/library/core/src/iter/adapters/copied.rs index 9627ace29795c..ba87fb7216059 100644 --- a/library/core/src/iter/adapters/copied.rs +++ b/library/core/src/iter/adapters/copied.rs @@ -21,7 +21,7 @@ pub struct Copied { } impl Copied { - pub(in crate::iter) fn new(it: I) -> Copied { + pub(in crate::iter) const fn new(it: I) -> Copied { Copied { it } } diff --git a/library/core/src/iter/adapters/cycle.rs b/library/core/src/iter/adapters/cycle.rs index 6cb1a3a46763e..86a6966ebf85b 100644 --- a/library/core/src/iter/adapters/cycle.rs +++ b/library/core/src/iter/adapters/cycle.rs @@ -17,7 +17,8 @@ pub struct Cycle { iter: I, } -impl Cycle { +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] +const impl Cycle { pub(in crate::iter) fn new(iter: I) -> Cycle { Cycle { orig: iter.clone(), iter } } diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index f7b9f0b7a5e9d..916ba88e6160a 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -20,7 +20,7 @@ pub struct Enumerate { count: usize, } impl Enumerate { - pub(in crate::iter) fn new(iter: I) -> Enumerate { + pub(in crate::iter) const fn new(iter: I) -> Enumerate { Enumerate { iter, count: 0 } } diff --git a/library/core/src/iter/adapters/filter.rs b/library/core/src/iter/adapters/filter.rs index b22419ccf080a..cf21536784a28 100644 --- a/library/core/src/iter/adapters/filter.rs +++ b/library/core/src/iter/adapters/filter.rs @@ -24,7 +24,7 @@ pub struct Filter { predicate: P, } impl Filter { - pub(in crate::iter) fn new(iter: I, predicate: P) -> Filter { + pub(in crate::iter) const fn new(iter: I, predicate: P) -> Filter { Filter { iter, predicate } } } diff --git a/library/core/src/iter/adapters/filter_map.rs b/library/core/src/iter/adapters/filter_map.rs index 24ec6b1741ce1..3fd7e16d1c148 100644 --- a/library/core/src/iter/adapters/filter_map.rs +++ b/library/core/src/iter/adapters/filter_map.rs @@ -20,7 +20,7 @@ pub struct FilterMap { f: F, } impl FilterMap { - pub(in crate::iter) fn new(iter: I, f: F) -> FilterMap { + pub(in crate::iter) const fn new(iter: I, f: F) -> FilterMap { FilterMap { iter, f } } } diff --git a/library/core/src/iter/adapters/flatten.rs b/library/core/src/iter/adapters/flatten.rs index c50f07ff6bb66..7e3c69e29e96f 100644 --- a/library/core/src/iter/adapters/flatten.rs +++ b/library/core/src/iter/adapters/flatten.rs @@ -185,7 +185,8 @@ pub struct Flatten> { inner: FlattenCompat::IntoIter>, } -impl> Flatten { +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] +const impl> Flatten { pub(in super::super) fn new(iter: I) -> Flatten { Flatten { inner: FlattenCompat::new(iter) } } @@ -358,9 +359,11 @@ struct FlattenCompat { frontiter: Option, backiter: Option, } -impl FlattenCompat + +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] +const impl FlattenCompat where - I: Iterator, + I: [const] Iterator, { /// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`. fn new(iter: I) -> FlattenCompat { diff --git a/library/core/src/iter/adapters/fuse.rs b/library/core/src/iter/adapters/fuse.rs index 0072a95e8dfe0..ef956e8bdef5d 100644 --- a/library/core/src/iter/adapters/fuse.rs +++ b/library/core/src/iter/adapters/fuse.rs @@ -21,7 +21,7 @@ pub struct Fuse { iter: Option, } impl Fuse { - pub(in crate::iter) fn new(iter: I) -> Fuse { + pub(in crate::iter) const fn new(iter: I) -> Fuse { Fuse { iter: Some(iter) } } diff --git a/library/core/src/iter/adapters/inspect.rs b/library/core/src/iter/adapters/inspect.rs index 0e2a68a503e44..de94951bc80ff 100644 --- a/library/core/src/iter/adapters/inspect.rs +++ b/library/core/src/iter/adapters/inspect.rs @@ -20,7 +20,7 @@ pub struct Inspect { f: F, } impl Inspect { - pub(in crate::iter) fn new(iter: I, f: F) -> Inspect { + pub(in crate::iter) const fn new(iter: I, f: F) -> Inspect { Inspect { iter, f } } } diff --git a/library/core/src/iter/adapters/intersperse.rs b/library/core/src/iter/adapters/intersperse.rs index f64dea2df862c..1669a32ae77d2 100644 --- a/library/core/src/iter/adapters/intersperse.rs +++ b/library/core/src/iter/adapters/intersperse.rs @@ -20,7 +20,7 @@ impl Intersperse where I::Item: Clone, { - pub(in crate::iter) fn new(iter: I, separator: I::Item) -> Self { + pub(in crate::iter) const fn new(iter: I, separator: I::Item) -> Self { Self { started: false, separator, next_item: None, iter } } } @@ -129,7 +129,7 @@ where I: Iterator, G: FnMut() -> I::Item, { - pub(in crate::iter) fn new(iter: I, separator: G) -> Self { + pub(in crate::iter) const fn new(iter: I, separator: G) -> Self { Self { started: false, separator, next_item: None, iter } } } diff --git a/library/core/src/iter/adapters/map.rs b/library/core/src/iter/adapters/map.rs index 007c2d5acc2d0..f768f077aa27e 100644 --- a/library/core/src/iter/adapters/map.rs +++ b/library/core/src/iter/adapters/map.rs @@ -65,7 +65,7 @@ pub struct Map { } impl Map { - pub(in crate::iter) fn new(iter: I, f: F) -> Map { + pub(in crate::iter) const fn new(iter: I, f: F) -> Map { Map { iter, f } } diff --git a/library/core/src/iter/adapters/map_while.rs b/library/core/src/iter/adapters/map_while.rs index c047c40de050e..3e34427da6142 100644 --- a/library/core/src/iter/adapters/map_while.rs +++ b/library/core/src/iter/adapters/map_while.rs @@ -20,7 +20,7 @@ pub struct MapWhile { } impl MapWhile { - pub(in crate::iter) fn new(iter: I, predicate: P) -> MapWhile { + pub(in crate::iter) const fn new(iter: I, predicate: P) -> MapWhile { MapWhile { iter, predicate } } } diff --git a/library/core/src/iter/adapters/map_windows.rs b/library/core/src/iter/adapters/map_windows.rs index 9398fbbe8a1cd..097a0745c61c7 100644 --- a/library/core/src/iter/adapters/map_windows.rs +++ b/library/core/src/iter/adapters/map_windows.rs @@ -43,7 +43,7 @@ struct Buffer { } impl MapWindows { - pub(in crate::iter) fn new(iter: I, f: F) -> Self { + pub(in crate::iter) const fn new(iter: I, f: F) -> Self { assert!(N != 0, "array in `Iterator::map_windows` must contain more than 0 elements"); // Only ZST arrays' length can be so large. @@ -60,7 +60,7 @@ impl MapWindows { impl MapWindowsInner { #[inline] - fn new(iter: I) -> Self { + const fn new(iter: I) -> Self { Self { iter, buffer: None } } diff --git a/library/core/src/iter/adapters/peekable.rs b/library/core/src/iter/adapters/peekable.rs index 9f6d1df57dbe8..4bddc2025c26e 100644 --- a/library/core/src/iter/adapters/peekable.rs +++ b/library/core/src/iter/adapters/peekable.rs @@ -21,7 +21,7 @@ pub struct Peekable { } impl Peekable { - pub(in crate::iter) fn new(iter: I) -> Peekable { + pub(in crate::iter) const fn new(iter: I) -> Peekable { Peekable { iter, peeked: None } } } diff --git a/library/core/src/iter/adapters/rev.rs b/library/core/src/iter/adapters/rev.rs index 17d3eef597dcb..b9ada504525f9 100644 --- a/library/core/src/iter/adapters/rev.rs +++ b/library/core/src/iter/adapters/rev.rs @@ -17,7 +17,7 @@ pub struct Rev { } impl Rev { - pub(in crate::iter) fn new(iter: T) -> Rev { + pub(in crate::iter) const fn new(iter: T) -> Rev { Rev { iter } } diff --git a/library/core/src/iter/adapters/scan.rs b/library/core/src/iter/adapters/scan.rs index e12375c94e067..7d084a89bd940 100644 --- a/library/core/src/iter/adapters/scan.rs +++ b/library/core/src/iter/adapters/scan.rs @@ -21,7 +21,7 @@ pub struct Scan { } impl Scan { - pub(in crate::iter) fn new(iter: I, state: St, f: F) -> Scan { + pub(in crate::iter) const fn new(iter: I, state: St, f: F) -> Scan { Scan { iter, state, f } } } diff --git a/library/core/src/iter/adapters/skip.rs b/library/core/src/iter/adapters/skip.rs index 55c4a7f14fbd6..f7a6beb2b8c63 100644 --- a/library/core/src/iter/adapters/skip.rs +++ b/library/core/src/iter/adapters/skip.rs @@ -24,7 +24,7 @@ pub struct Skip { } impl Skip { - pub(in crate::iter) fn new(iter: I, n: usize) -> Skip { + pub(in crate::iter) const fn new(iter: I, n: usize) -> Skip { Skip { iter, n } } } diff --git a/library/core/src/iter/adapters/skip_while.rs b/library/core/src/iter/adapters/skip_while.rs index 8ae453e76fa0d..ced4fd8f2abc4 100644 --- a/library/core/src/iter/adapters/skip_while.rs +++ b/library/core/src/iter/adapters/skip_while.rs @@ -21,7 +21,7 @@ pub struct SkipWhile { } impl SkipWhile { - pub(in crate::iter) fn new(iter: I, predicate: P) -> SkipWhile { + pub(in crate::iter) const fn new(iter: I, predicate: P) -> SkipWhile { SkipWhile { iter, flag: false, predicate } } } diff --git a/library/core/src/iter/adapters/take.rs b/library/core/src/iter/adapters/take.rs index b96335f415257..ecd462c60eda3 100644 --- a/library/core/src/iter/adapters/take.rs +++ b/library/core/src/iter/adapters/take.rs @@ -20,7 +20,7 @@ pub struct Take { } impl Take { - pub(in crate::iter) fn new(iter: I, n: usize) -> Take { + pub(in crate::iter) const fn new(iter: I, n: usize) -> Take { Take { iter, n } } } diff --git a/library/core/src/iter/adapters/take_while.rs b/library/core/src/iter/adapters/take_while.rs index 06028ea98e7fd..6e40629567a83 100644 --- a/library/core/src/iter/adapters/take_while.rs +++ b/library/core/src/iter/adapters/take_while.rs @@ -21,7 +21,7 @@ pub struct TakeWhile { } impl TakeWhile { - pub(in crate::iter) fn new(iter: I, predicate: P) -> TakeWhile { + pub(in crate::iter) const fn new(iter: I, predicate: P) -> TakeWhile { TakeWhile { iter, flag: false, predicate } } } diff --git a/library/core/src/iter/traits/accum.rs b/library/core/src/iter/traits/accum.rs index 375b5ef52859f..3787e41f0a0b1 100644 --- a/library/core/src/iter/traits/accum.rs +++ b/library/core/src/iter/traits/accum.rs @@ -10,11 +10,12 @@ use crate::num::{Saturating, Wrapping}; /// [`sum()`]: Iterator::sum /// [`FromIterator`]: iter::FromIterator #[stable(feature = "iter_arith_traits", since = "1.12.0")] +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] #[diagnostic::on_unimplemented( message = "a value of type `{Self}` cannot be made by summing an iterator over elements of type `{A}`", label = "value of type `{Self}` cannot be made by summing a `std::iter::Iterator`" )] -pub trait Sum: Sized { +pub const trait Sum: Sized { /// Takes an iterator and generates `Self` from the elements by "summing up" /// the items. #[stable(feature = "iter_arith_traits", since = "1.12.0")] @@ -31,11 +32,12 @@ pub trait Sum: Sized { /// [`product()`]: Iterator::product /// [`FromIterator`]: iter::FromIterator #[stable(feature = "iter_arith_traits", since = "1.12.0")] +#[rustc_const_unstable(feature = "const_iter", issue = "92476")] #[diagnostic::on_unimplemented( message = "a value of type `{Self}` cannot be made by multiplying all elements of type `{A}` from an iterator", label = "value of type `{Self}` cannot be made by multiplying all elements from a `std::iter::Iterator`" )] -pub trait Product: Sized { +pub const trait Product: Sized { /// Takes an iterator and generates `Self` from the elements by multiplying /// the items. #[stable(feature = "iter_arith_traits", since = "1.12.0")] diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index b2c11fff99fad..c6a06c133a156 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -109,7 +109,6 @@ pub const trait Iterator { /// ``` #[inline] #[unstable(feature = "iter_next_chunk", issue = "98326")] - #[rustc_non_const_trait_method] fn next_chunk( &mut self, ) -> Result<[Self::Item; N], array::IntoIter> @@ -222,16 +221,18 @@ pub const trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn count(self) -> usize where - Self: Sized, + Self: Sized + [const] Destruct, + Self::Item: [const] Destruct, { - self.fold( - 0, - #[rustc_inherit_overflow_checks] - |count, _| count + 1, - ) + // FIXME(const-hack): revert this to a const closure + #[rustc_const_unstable(feature = "const_iter", issue = "92476")] + #[rustc_inherit_overflow_checks] + const fn plus_one(accum: usize, _elem: T) -> usize { + accum + 1 + } + self.fold(0, plus_one) } /// Consumes the iterator, returning the last element. @@ -508,11 +509,10 @@ pub const trait Iterator { /// [`OsStr`]: ../../std/ffi/struct.OsStr.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn chain(self, other: U) -> Chain where Self: Sized, - U: IntoIterator, + U: [const] IntoIterator, { Chain::new(self, other.into_iter()) } @@ -692,7 +692,6 @@ pub const trait Iterator { /// [`intersperse_with`]: Iterator::intersperse_with #[inline] #[unstable(feature = "iter_intersperse", issue = "79524")] - #[rustc_non_const_trait_method] fn intersperse(self, separator: Self::Item) -> Intersperse where Self: Sized, @@ -772,7 +771,6 @@ pub const trait Iterator { /// [`intersperse_with`]: Iterator::intersperse_with #[inline] #[unstable(feature = "iter_intersperse", issue = "79524")] - #[rustc_non_const_trait_method] fn intersperse_with(self, separator: G) -> IntersperseWith where Self: Sized, @@ -832,7 +830,6 @@ pub const trait Iterator { #[rustc_diagnostic_item = "IteratorMap"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn map(self, f: F) -> Map where Self: Sized, @@ -954,7 +951,6 @@ pub const trait Iterator { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "iter_filter"] - #[rustc_non_const_trait_method] fn filter

(self, predicate: P) -> Filter where Self: Sized, @@ -1000,7 +996,6 @@ pub const trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn filter_map(self, f: F) -> FilterMap where Self: Sized, @@ -1048,7 +1043,6 @@ pub const trait Iterator { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "enumerate_method"] - #[rustc_non_const_trait_method] fn enumerate(self) -> Enumerate where Self: Sized, @@ -1120,7 +1114,6 @@ pub const trait Iterator { /// [`next`]: Iterator::next #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn peekable(self) -> Peekable where Self: Sized, @@ -1186,7 +1179,6 @@ pub const trait Iterator { #[inline] #[doc(alias = "drop_while")] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn skip_while

(self, predicate: P) -> SkipWhile where Self: Sized, @@ -1265,7 +1257,6 @@ pub const trait Iterator { /// the iteration should stop, but wasn't placed back into the iterator. #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn take_while

(self, predicate: P) -> TakeWhile where Self: Sized, @@ -1354,7 +1345,6 @@ pub const trait Iterator { /// [`fuse`]: Iterator::fuse #[inline] #[stable(feature = "iter_map_while", since = "1.57.0")] - #[rustc_non_const_trait_method] fn map_while(self, predicate: P) -> MapWhile where Self: Sized, @@ -1384,7 +1374,6 @@ pub const trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn skip(self, n: usize) -> Skip where Self: Sized, @@ -1457,7 +1446,6 @@ pub const trait Iterator { #[doc(alias = "limit")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn take(self, n: usize) -> Take where Self: Sized, @@ -1505,7 +1493,6 @@ pub const trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn scan(self, initial_state: St, f: F) -> Scan where Self: Sized, @@ -1629,7 +1616,6 @@ pub const trait Iterator { /// [`flat_map()`]: Iterator::flat_map #[inline] #[stable(feature = "iterator_flatten", since = "1.29.0")] - #[rustc_non_const_trait_method] fn flatten(self) -> Flatten where Self: Sized, @@ -1784,7 +1770,6 @@ pub const trait Iterator { /// ``` #[inline] #[unstable(feature = "iter_map_windows", issue = "87155")] - #[rustc_non_const_trait_method] fn map_windows(self, f: F) -> MapWindows where Self: Sized, @@ -1847,7 +1832,6 @@ pub const trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn fuse(self) -> Fuse where Self: Sized, @@ -1932,7 +1916,6 @@ pub const trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn inspect(self, f: F) -> Inspect where Self: Sized, @@ -3459,7 +3442,6 @@ pub const trait Iterator { #[inline] #[doc(alias = "reverse")] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_non_const_trait_method] fn rev(self) -> Rev where Self: Sized + DoubleEndedIterator, @@ -3528,7 +3510,6 @@ pub const trait Iterator { /// ``` #[stable(feature = "iter_copied", since = "1.36.0")] #[rustc_diagnostic_item = "iter_copied"] - #[rustc_non_const_trait_method] fn copied<'a, T>(self) -> Copied where T: Copy + 'a, @@ -3577,7 +3558,6 @@ pub const trait Iterator { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "iter_cloned"] - #[rustc_non_const_trait_method] fn cloned<'a, T>(self) -> Cloned where T: Clone + 'a, @@ -3609,10 +3589,9 @@ pub const trait Iterator { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - #[rustc_non_const_trait_method] fn cycle(self) -> Cycle where - Self: Sized + Clone, + Self: Sized + [const] Clone, { Cycle::new(self) } @@ -3653,7 +3632,6 @@ pub const trait Iterator { /// ``` #[track_caller] #[unstable(feature = "iter_array_chunks", issue = "100450")] - #[rustc_non_const_trait_method] fn array_chunks(self) -> ArrayChunks where Self: Sized, @@ -3690,11 +3668,10 @@ pub const trait Iterator { /// assert_eq!(sum, -0.0_f32); /// ``` #[stable(feature = "iter_arith", since = "1.11.0")] - #[rustc_non_const_trait_method] fn sum(self) -> S where Self: Sized, - S: Sum, + S: [const] Sum, { Sum::sum(self) } @@ -3723,11 +3700,10 @@ pub const trait Iterator { /// assert_eq!(factorial(5), 120); /// ``` #[stable(feature = "iter_arith", since = "1.11.0")] - #[rustc_non_const_trait_method] fn product

(self) -> P where Self: Sized, - P: Product, + P: [const] Product, { Product::product(self) } diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index 48547c019d628..fa140b25cd1f9 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -239,5 +239,5 @@ fn evens_squared(n: usize) -> _ { const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); //~^ ERROR the placeholder -//~| ERROR cannot call non-const -//~| ERROR cannot call non-const +//~| ERROR the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied +//~| ERROR the trait bound `Filter diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 2772d55f953a8..c144651c3c004 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -587,17 +587,29 @@ LL - fn evens_squared(n: usize) -> _ { LL + fn evens_squared(n: usize) -> impl Iterator { | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:240:10 +error[E0277]: the trait bound `std::ops::Range<{integer}>: const Iterator` is not satisfied + --> $DIR/typeck_type_placeholder_item.rs:240:15 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^ not allowed in type signatures + | ^^^^^ ------ required by a bound introduced by this call + | +note: trait `Iterator` is implemented but not `const` + --> $SRC_DIR/core/src/iter/range.rs:LL:COL + +error[E0277]: the trait bound `Filter, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}>: const Iterator` is not satisfied + --> $DIR/typeck_type_placeholder_item.rs:240:45 | -note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:240:29}>, {closure@typeck_type_placeholder_item.rs:240:49}>` cannot be named - --> $DIR/typeck_type_placeholder_item.rs:240:14 +LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); + | ^^^ + | +note: trait `Iterator` is implemented but not `const` + --> $SRC_DIR/core/src/iter/adapters/filter.rs:LL:COL + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:240:10 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/typeck_type_placeholder_item.rs:40:24 @@ -678,23 +690,7 @@ LL | fn map(_: fn() -> Option<&'static T>) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}>` in constants - --> $DIR/typeck_type_placeholder_item.rs:240:22 - | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants - -error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:240:45 - | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants - error: aborting due to 83 previous errors -Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403. +Some errors have detailed explanations: E0015, E0046, E0121, E0277, E0282, E0403. For more information about an error, try `rustc --explain E0015`. From 3ff4201fd132f5b46d504d49c4fd116772b694a1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 25 Mar 2026 08:54:32 +1100 Subject: [PATCH 7/7] Move `rustc_middle::mir::mono` to `rustc_middle::mono` Because the things in this module aren't MIR and don't use anything from `rustc_middle::mir`. Also, modules that use `mono` often don't use anything else from `rustc_middle::mir`. --- compiler/rustc_codegen_cranelift/src/driver/aot.rs | 2 +- compiler/rustc_codegen_cranelift/src/driver/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/linkage.rs | 2 +- compiler/rustc_codegen_gcc/src/base.rs | 2 +- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_codegen_gcc/src/mono_item.rs | 2 +- compiler/rustc_codegen_llvm/src/base.rs | 2 +- compiler/rustc_codegen_llvm/src/consts.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- .../rustc_codegen_llvm/src/coverageinfo/mapgen/unused.rs | 6 +++--- compiler/rustc_codegen_llvm/src/mono_item.rs | 2 +- compiler/rustc_codegen_ssa/src/assert_module_sources.rs | 2 +- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/naked_asm.rs | 2 +- compiler/rustc_codegen_ssa/src/mono_item.rs | 2 +- compiler/rustc_codegen_ssa/src/traits/declare.rs | 2 +- compiler/rustc_middle/src/arena.rs | 2 +- compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 +- compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/middle/codegen_fn_attrs.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 1 - compiler/rustc_middle/src/{mir => }/mono.rs | 0 compiler/rustc_middle/src/queries.rs | 2 +- compiler/rustc_middle/src/query/erase.rs | 4 ++-- compiler/rustc_middle/src/query/keys.rs | 2 +- compiler/rustc_middle/src/query/on_disk_cache.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 4 +--- compiler/rustc_monomorphize/src/graph_checks/mod.rs | 2 +- compiler/rustc_monomorphize/src/graph_checks/statics.rs | 2 +- compiler/rustc_monomorphize/src/partitioning.rs | 2 +- compiler/rustc_public/src/unstable/convert/internal.rs | 4 ++-- compiler/rustc_public/src/unstable/convert/stable/mir.rs | 2 +- compiler/rustc_symbol_mangling/src/lib.rs | 2 +- 36 files changed, 38 insertions(+), 40 deletions(-) rename compiler/rustc_middle/src/{mir => }/mono.rs (100%) diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index b855e1fa4b780..c74e0b9b1a669 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -19,7 +19,7 @@ use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; use rustc_hir::attrs::Linkage as RLinkage; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::mir::mono::{CodegenUnit, MonoItem, MonoItemData, Visibility}; +use rustc_middle::mono::{CodegenUnit, MonoItem, MonoItemData, Visibility}; use rustc_session::Session; use rustc_session::config::{OutputFilenames, OutputType}; diff --git a/compiler/rustc_codegen_cranelift/src/driver/mod.rs b/compiler/rustc_codegen_cranelift/src/driver/mod.rs index 9f2b7b4b09f22..8d962aa1c7fba 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/mod.rs @@ -6,7 +6,7 @@ use rustc_data_structures::profiling::SelfProfilerRef; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::mir::mono::{MonoItem, MonoItemData}; +use rustc_middle::mono::{MonoItem, MonoItemData}; use crate::prelude::*; diff --git a/compiler/rustc_codegen_cranelift/src/linkage.rs b/compiler/rustc_codegen_cranelift/src/linkage.rs index d76ab9d0109f0..e373268d76b76 100644 --- a/compiler/rustc_codegen_cranelift/src/linkage.rs +++ b/compiler/rustc_codegen_cranelift/src/linkage.rs @@ -1,5 +1,5 @@ use rustc_hir::attrs::Linkage as RLinkage; -use rustc_middle::mir::mono::{MonoItem, Visibility}; +use rustc_middle::mono::{MonoItem, Visibility}; use crate::prelude::*; diff --git a/compiler/rustc_codegen_gcc/src/base.rs b/compiler/rustc_codegen_gcc/src/base.rs index d1637dd663bb7..73b0723895b4a 100644 --- a/compiler/rustc_codegen_gcc/src/base.rs +++ b/compiler/rustc_codegen_gcc/src/base.rs @@ -11,7 +11,7 @@ use rustc_codegen_ssa::traits::DebugInfoCodegenMethods; use rustc_hir::attrs::Linkage; use rustc_middle::dep_graph; #[cfg(feature = "master")] -use rustc_middle::mir::mono::Visibility; +use rustc_middle::mono::Visibility; use rustc_middle::ty::TyCtxt; use rustc_session::config::DebugInfo; use rustc_span::Symbol; diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index c34c615306aae..c7a2b92ac139c 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -11,7 +11,7 @@ use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, MiscCodege use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_middle::mir::interpret::Allocation; -use rustc_middle::mir::mono::CodegenUnit; +use rustc_middle::mono::CodegenUnit; use rustc_middle::span_bug; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, diff --git a/compiler/rustc_codegen_gcc/src/mono_item.rs b/compiler/rustc_codegen_gcc/src/mono_item.rs index 1429738a7e7ac..d5874779021d2 100644 --- a/compiler/rustc_codegen_gcc/src/mono_item.rs +++ b/compiler/rustc_codegen_gcc/src/mono_item.rs @@ -6,7 +6,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::mir::mono::Visibility; +use rustc_middle::mono::Visibility; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf}; use rustc_middle::ty::{self, Instance, TypeVisitableExt}; diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 2276809477121..e1a6785942638 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -21,7 +21,7 @@ use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::attrs::Linkage; use rustc_middle::dep_graph; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrs, SanitizerFnAttrs}; -use rustc_middle::mir::mono::Visibility; +use rustc_middle::mono::Visibility; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, Offload}; use rustc_span::Symbol; diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 1bdafbd3e4c6d..3514fb145612a 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -12,7 +12,7 @@ use rustc_middle::mir::interpret::{ Allocation, ConstAllocation, ErrorHandled, InitChunk, Pointer, Scalar as InterpScalar, read_target_uint, }; -use rustc_middle::mir::mono::MonoItem; +use rustc_middle::mono::MonoItem; use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf}; use rustc_middle::ty::{self, Instance}; use rustc_middle::{bug, span_bug}; diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 80d939a25701e..5b730b820b84a 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::PatchableFunctionEntry; -use rustc_middle::mir::mono::CodegenUnit; +use rustc_middle::mono::CodegenUnit; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers, }; diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/unused.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/unused.rs index fe3a7a1580b53..4fe3ee09175cc 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/unused.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/unused.rs @@ -2,7 +2,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods}; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::mir; -use rustc_middle::mir::mono::MonoItemPartitions; +use rustc_middle::mono::{MonoItem, MonoItemPartitions}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::def_id::DefIdSet; @@ -109,8 +109,8 @@ fn prepare_usage_sets<'tcx>(tcx: TyCtxt<'tcx>) -> UsageSets<'tcx> { .iter() .flat_map(|cgu| cgu.items().keys()) .filter_map(|item| match item { - mir::mono::MonoItem::Fn(instance) => Some(instance), - mir::mono::MonoItem::Static(_) | mir::mono::MonoItem::GlobalAsm(_) => None, + MonoItem::Fn(instance) => Some(instance), + MonoItem::Static(_) | MonoItem::GlobalAsm(_) => None, }) // We only need one arbitrary instance per definition. .filter(move |instance| def_ids_seen.insert(instance.def_id())) diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 44a77f0fad7df..0783282bc6e56 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -8,7 +8,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; -use rustc_middle::mir::mono::Visibility; +use rustc_middle::mono::Visibility; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf}; use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; use rustc_session::config::CrateType; diff --git a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs index 9858d9335dc6f..508b9add24aa0 100644 --- a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs +++ b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs @@ -31,7 +31,7 @@ use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_hir::attrs::{CguFields, CguKind}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{self as hir, find_attr}; -use rustc_middle::mir::mono::CodegenUnitNameBuilder; +use rustc_middle::mono::CodegenUnitNameBuilder; use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::{Span, Symbol}; diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 687ec7ca059d1..2460bf18b13d1 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -240,7 +240,7 @@ fn exported_generic_symbols_provider_local<'tcx>( if tcx.local_crate_exports_generics() { use rustc_hir::attrs::Linkage; - use rustc_middle::mir::mono::{MonoItem, Visibility}; + use rustc_middle::mono::{MonoItem, Visibility}; use rustc_middle::ty::InstanceKind; // Normally, we require that shared monomorphizations are not hidden, diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 911844bdbd5de..f291aa846ecc3 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -24,7 +24,7 @@ use rustc_middle::middle::exported_symbols::{self, SymbolExportKind}; use rustc_middle::middle::lang_items; use rustc_middle::mir::BinOp; use rustc_middle::mir::interpret::ErrorHandled; -use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem, MonoItemPartitions}; +use rustc_middle::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem, MonoItemPartitions}; use rustc_middle::query::Providers; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 6dd4f2d6b5925..820436bb6a265 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -9,7 +9,7 @@ use rustc_macros::Diagnostic; use rustc_middle::middle::codegen_fn_attrs::{ CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs, }; -use rustc_middle::mir::mono::Visibility; +use rustc_middle::mono::Visibility; use rustc_middle::query::Providers; use rustc_middle::ty::{self as ty, TyCtxt}; use rustc_session::lint; diff --git a/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs b/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs index f12410c65d986..ccd5fbcaec8b5 100644 --- a/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs +++ b/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs @@ -1,8 +1,8 @@ use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind}; use rustc_hir::attrs::{InstructionSetAttr, Linkage}; use rustc_hir::def_id::LOCAL_CRATE; -use rustc_middle::mir::mono::{MonoItemData, Visibility}; use rustc_middle::mir::{InlineAsmOperand, START_BLOCK}; +use rustc_middle::mono::{MonoItemData, Visibility}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; use rustc_middle::ty::{Instance, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, ty}; diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs index 8f03dc1e6b5e0..f2cd9e228f282 100644 --- a/compiler/rustc_codegen_ssa/src/mono_item.rs +++ b/compiler/rustc_codegen_ssa/src/mono_item.rs @@ -1,6 +1,6 @@ use rustc_hir::attrs::Linkage; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::mir::mono::{MonoItem, MonoItemData, Visibility}; +use rustc_middle::mono::{MonoItem, MonoItemData, Visibility}; use rustc_middle::ty::layout::HasTyCtxt; use tracing::debug; diff --git a/compiler/rustc_codegen_ssa/src/traits/declare.rs b/compiler/rustc_codegen_ssa/src/traits/declare.rs index 8d5f0a5b939a2..fc978024b8414 100644 --- a/compiler/rustc_codegen_ssa/src/traits/declare.rs +++ b/compiler/rustc_codegen_ssa/src/traits/declare.rs @@ -1,6 +1,6 @@ use rustc_hir::attrs::Linkage; use rustc_hir::def_id::DefId; -use rustc_middle::mir::mono::Visibility; +use rustc_middle::mono::Visibility; use rustc_middle::ty::Instance; pub trait PreDefineCodegenMethods<'tcx> { diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 33237ef840415..de6a105ee2b7b 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -87,7 +87,7 @@ macro_rules! arena_types { [] effective_visibilities: rustc_middle::middle::privacy::EffectiveVisibilities, [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap, [] dyn_compatibility_violations: rustc_middle::traits::DynCompatibilityViolation, - [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<'tcx>, + [] codegen_unit: rustc_middle::mono::CodegenUnit<'tcx>, [decode] attribute: rustc_hir::Attribute, [] name_set: rustc_data_structures::unord::UnordSet, [] autodiff_item: rustc_hir::attrs::AutoDiffItem, diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index c69908b86b279..16cb556c5a323 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -59,7 +59,7 @@ use rustc_span::Symbol; use super::{KeyFingerprintStyle, SerializedDepNodeIndex}; use crate::dep_graph::DepNodeKey; -use crate::mir::mono::MonoItem; +use crate::mono::MonoItem; use crate::ty::{TyCtxt, tls}; // `enum DepKind` is generated by `define_dep_nodes!` below. diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index c8702c42c47f6..1d6132ba2a3ea 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -78,6 +78,7 @@ pub mod lint; pub mod metadata; pub mod middle; pub mod mir; +pub mod mono; pub mod queries; pub mod query; pub mod thir; diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index 4f600af0cbfce..6f5b927bc17c4 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -7,7 +7,7 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable}; use rustc_span::Symbol; use rustc_target::spec::SanitizerSet; -use crate::mir::mono::Visibility; +use crate::mono::Visibility; use crate::ty::{InstanceKind, TyCtxt}; impl<'tcx> TyCtxt<'tcx> { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index a3746db653559..892d3bfea653e 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -43,7 +43,6 @@ mod generic_graph; pub mod generic_graphviz; pub mod graphviz; pub mod interpret; -pub mod mono; pub mod pretty; mod query; mod statement; diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mono.rs similarity index 100% rename from compiler/rustc_middle/src/mir/mono.rs rename to compiler/rustc_middle/src/mono.rs diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 63be8a63e9f27..1017ccffb0b2a 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -98,7 +98,7 @@ use crate::mir::interpret::{ EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult, EvalToValTreeResult, GlobalId, }; -use crate::mir::mono::{ +use crate::mono::{ CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions, NormalizationErrorInMono, }; use crate::query::describe_as_module; diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 7a31682b4ad98..a6ff238ad6f0b 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -15,7 +15,7 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_span::{ErrorGuaranteed, Spanned}; -use crate::mir::mono::{MonoItem, NormalizationErrorInMono}; +use crate::mono::{MonoItem, NormalizationErrorInMono}; use crate::ty::{self, Ty, TyCtxt}; use crate::{mir, thir, traits}; @@ -221,7 +221,7 @@ impl_erasable_for_types_with_no_type_params! { rustc_middle::mir::interpret::AllocId, rustc_middle::mir::interpret::EvalStaticInitializerRawResult<'_>, rustc_middle::mir::interpret::EvalToValTreeResult<'_>, - rustc_middle::mir::mono::MonoItemPartitions<'_>, + rustc_middle::mono::MonoItemPartitions<'_>, rustc_middle::traits::query::MethodAutoderefStepsResult<'_>, rustc_middle::ty::AdtDef<'_>, rustc_middle::ty::AnonConstKind, diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index e5e56b8e28b27..ad101cf34da3b 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -13,7 +13,7 @@ use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; use crate::dep_graph::DepNodeIndex; use crate::ich::StableHashingContext; use crate::infer::canonical::CanonicalQueryInput; -use crate::mir::mono::CollectionMode; +use crate::mono::CollectionMode; use crate::query::{DefIdCache, DefaultCache, SingleCache, VecCache}; use crate::ty::fast_reject::SimplifiedType; use crate::ty::layout::ValidityRequirement; diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 4dbceba924036..df2c8d8b98f97 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -24,8 +24,8 @@ use rustc_span::{ use crate::dep_graph::{DepNodeIndex, QuerySideEffect, SerializedDepNodeIndex}; use crate::mir::interpret::{AllocDecodingSession, AllocDecodingState}; -use crate::mir::mono::MonoItem; use crate::mir::{self, interpret}; +use crate::mono::MonoItem; use crate::ty::codec::{RefDecodable, TyDecoder, TyEncoder}; use crate::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 6652c5a758daa..28bdeabf34dc1 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -20,7 +20,7 @@ use rustc_span::{Span, SpanDecoder, SpanEncoder, Spanned}; use crate::arena::ArenaAllocatable; use crate::infer::canonical::{CanonicalVarKind, CanonicalVarKinds}; use crate::mir::interpret::{AllocId, ConstAllocation, CtfeProvenance}; -use crate::mir::mono::MonoItem; +use crate::mono::MonoItem; use crate::ty::{self, AdtDef, GenericArgsRef, Ty, TyCtxt}; use crate::{mir, traits}; diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index cab87daff5aa6..5c21ff1464c3d 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -219,11 +219,9 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::limit::Limit; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar}; -use rustc_middle::mir::mono::{ - CollectionMode, InstantiationMode, MonoItem, NormalizationErrorInMono, -}; use rustc_middle::mir::visit::Visitor as MirVisitor; use rustc_middle::mir::{self, Body, Location, MentionedItem, traversal}; +use rustc_middle::mono::{CollectionMode, InstantiationMode, MonoItem, NormalizationErrorInMono}; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion}; use rustc_middle::ty::layout::ValidityRequirement; diff --git a/compiler/rustc_monomorphize/src/graph_checks/mod.rs b/compiler/rustc_monomorphize/src/graph_checks/mod.rs index 2b9b7cfff0b21..87cd2c733b69a 100644 --- a/compiler/rustc_monomorphize/src/graph_checks/mod.rs +++ b/compiler/rustc_monomorphize/src/graph_checks/mod.rs @@ -1,5 +1,5 @@ //! Checks that need to operate on the entire mono item graph -use rustc_middle::mir::mono::MonoItem; +use rustc_middle::mono::MonoItem; use rustc_middle::ty::TyCtxt; use crate::collector::UsageMap; diff --git a/compiler/rustc_monomorphize/src/graph_checks/statics.rs b/compiler/rustc_monomorphize/src/graph_checks/statics.rs index 90993e55906f2..1e97d196e72d4 100644 --- a/compiler/rustc_monomorphize/src/graph_checks/statics.rs +++ b/compiler/rustc_monomorphize/src/graph_checks/statics.rs @@ -4,7 +4,7 @@ use rustc_data_structures::graph::{DirectedGraph, Successors}; use rustc_data_structures::unord::UnordMap; use rustc_hir::def_id::DefId; use rustc_index::{Idx, IndexVec, newtype_index}; -use rustc_middle::mir::mono::MonoItem; +use rustc_middle::mono::MonoItem; use rustc_middle::ty::TyCtxt; use crate::collector::UsageMap; diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index fb3fb1b0918ac..6f9795fb3bff1 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -109,7 +109,7 @@ use rustc_hir::definitions::DefPathDataName; use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; -use rustc_middle::mir::mono::{ +use rustc_middle::mono::{ CodegenUnit, CodegenUnitNameBuilder, InstantiationMode, MonoItem, MonoItemData, MonoItemPartitions, Visibility, }; diff --git a/compiler/rustc_public/src/unstable/convert/internal.rs b/compiler/rustc_public/src/unstable/convert/internal.rs index 8594f65100415..b8533dcaa8d67 100644 --- a/compiler/rustc_public/src/unstable/convert/internal.rs +++ b/compiler/rustc_public/src/unstable/convert/internal.rs @@ -368,14 +368,14 @@ impl RustcInternal for MirConst { } impl RustcInternal for MonoItem { - type T<'tcx> = rustc_middle::mir::mono::MonoItem<'tcx>; + type T<'tcx> = rustc_middle::mono::MonoItem<'tcx>; fn internal<'tcx>( &self, tables: &mut Tables<'_, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - use rustc_middle::mir::mono as rustc_mono; + use rustc_middle::mono as rustc_mono; match self { MonoItem::Fn(instance) => rustc_mono::MonoItem::Fn(instance.internal(tables, tcx)), MonoItem::Static(def) => rustc_mono::MonoItem::Static(def.internal(tables, tcx)), diff --git a/compiler/rustc_public/src/unstable/convert/stable/mir.rs b/compiler/rustc_public/src/unstable/convert/stable/mir.rs index d25751c81f3f5..0d04053aab76b 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mir.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mir.rs @@ -1,6 +1,6 @@ //! Conversion of internal Rust compiler `mir` items to stable ones. -use rustc_middle::mir::mono::MonoItem; +use rustc_middle::mono::MonoItem; use rustc_middle::{bug, mir}; use rustc_public_bridge::context::CompilerCtxt; use rustc_public_bridge::{Tables, bridge}; diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index ae0f5ec2a72d9..3ac8a566374cf 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -90,7 +90,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; -use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; +use rustc_middle::mono::{InstantiationMode, MonoItem}; use rustc_middle::query::Providers; use rustc_middle::ty::{self, Instance, TyCtxt}; use rustc_session::config::SymbolManglingVersion;