diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 3283bcc4c453c..c09ba26ba7568 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -823,7 +823,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Make sure all the constants required by this frame evaluate successfully (post-monomorphization check). if M::POST_MONO_CHECKS { - for &const_ in &body.required_consts { + for &const_ in &self.tcx.required_and_mentioned_items(instance.def).required_consts { let c = self .instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?; c.eval(*self.tcx, self.param_env, const_.span).map_err(|err| { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index b69a295f010f3..2dcd9ec999a1d 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -222,6 +222,15 @@ provide! { tcx, def_id, other, cdata, object_lifetime_default => { table } thir_abstract_const => { table } optimized_mir => { table } + required_and_mentioned_items_of_item => { + cdata + .root + .tables + .required_and_mentioned_items_of_item + .get(cdata, def_id.index) + .map(|lazy| lazy.decode((cdata, tcx))) + .unwrap_or_default() + } mir_for_ctfe => { table } closure_saved_names_of_captured_variables => { table } mir_coroutine_witnesses => { table } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 7b10ea535248f..1e088ce598001 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -12,7 +12,7 @@ use rustc_hir::definitions::DefPathData; use rustc_hir_pretty::id_to_string; use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::metadata_symbol_name; -use rustc_middle::mir::interpret; +use rustc_middle::mir::{interpret, RequiredAndMentionedItems}; use rustc_middle::query::LocalCrate; use rustc_middle::query::Providers; use rustc_middle::traits::specialization_graph; @@ -1648,6 +1648,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { for (def_id, encode_const, encode_opt) in keys_and_jobs { debug_assert!(encode_const || encode_opt); + let items = tcx.required_and_mentioned_items_of_item(def_id); + let RequiredAndMentionedItems { required_consts, mentioned_items } = items; + if !required_consts.is_empty() || !mentioned_items.is_empty() { + record!(self.tables.required_and_mentioned_items_of_item[def_id.to_def_id()] <- items); + } + debug!("EntryBuilder::encode_mir({:?})", def_id); if encode_opt { record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id)); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 5b0be8ac230d4..0f8f523469f8a 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -428,6 +428,7 @@ define_tables! { const_param_default: Table>>>, object_lifetime_default: Table>, optimized_mir: Table>>, + required_and_mentioned_items_of_item: Table>>, mir_for_ctfe: Table>>, closure_saved_names_of_captured_variables: Table>>, mir_coroutine_witnesses: Table>>, diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index ad166620bccf1..b527f449b2654 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -22,7 +22,6 @@ use rustc_hir::{ ImplicitSelfKind, }; use rustc_session::Session; -use rustc_span::source_map::Spanned; use rustc_target::abi::{FieldIdx, VariantIdx}; use polonius_engine::Atom; @@ -61,6 +60,7 @@ pub mod mono; pub mod patch; pub mod pretty; mod query; +mod required_items; mod statement; mod syntax; pub mod tcx; @@ -77,6 +77,7 @@ pub use self::pretty::{ }; pub use consts::*; use pretty::pretty_print_const_value; +pub use required_items::{MentionedItem, RequiredAndMentionedItems}; pub use statement::*; pub use syntax::*; pub use terminator::*; @@ -308,21 +309,6 @@ impl<'tcx> CoroutineInfo<'tcx> { } } -/// Some item that needs to monomorphize successfully for a MIR body to be considered well-formed. -#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, HashStable, TyEncodable, TyDecodable)] -#[derive(TypeFoldable, TypeVisitable)] -pub enum MentionedItem<'tcx> { - /// A function that gets called. We don't necessarily know its precise type yet, since it can be - /// hidden behind a generic. - Fn(Ty<'tcx>), - /// A type that has its drop shim called. - Drop(Ty<'tcx>), - /// Unsizing casts might require vtables, so we have to record them. - UnsizeCast { source_ty: Ty<'tcx>, target_ty: Ty<'tcx> }, - /// A closure that is coerced to a function pointer. - Closure(Ty<'tcx>), -} - /// The lowered representation of a single function. #[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)] pub struct Body<'tcx> { @@ -384,26 +370,6 @@ pub struct Body<'tcx> { /// A span representing this MIR, for error reporting. pub span: Span, - /// Constants that are required to evaluate successfully for this MIR to be well-formed. - /// We hold in this field all the constants we are not able to evaluate yet. - /// - /// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a - /// function have successfully evaluated if the function ever gets executed at runtime. - pub required_consts: Vec>, - - /// Further items that were mentioned in this function and hence *may* become monomorphized, - /// depending on optimizations. We use this to avoid optimization-dependent compile errors: the - /// collector recursively traverses all "mentioned" items and evaluates all their - /// `required_consts`. - /// - /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee. - /// All that's relevant is that this set is optimization-level-independent, and that it includes - /// everything that the collector would consider "used". (For example, we currently compute this - /// set after drop elaboration, so some drop calls that can never be reached are not considered - /// "mentioned".) See the documentation of `CollectionMode` in - /// `compiler/rustc_monomorphize/src/collector.rs` for more context. - pub mentioned_items: Vec>>, - /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check. /// /// Note that this does not actually mean that this body is not computable right now. @@ -479,8 +445,6 @@ impl<'tcx> Body<'tcx> { spread_arg: None, var_debug_info, span, - required_consts: Vec::new(), - mentioned_items: Vec::new(), is_polymorphic: false, injection_phase: None, tainted_by_errors, @@ -509,8 +473,6 @@ impl<'tcx> Body<'tcx> { arg_count: 0, spread_arg: None, span: DUMMY_SP, - required_consts: Vec::new(), - mentioned_items: Vec::new(), var_debug_info: Vec::new(), is_polymorphic: false, injection_phase: None, diff --git a/compiler/rustc_middle/src/mir/required_items.rs b/compiler/rustc_middle/src/mir/required_items.rs new file mode 100644 index 0000000000000..c09ac5df4b075 --- /dev/null +++ b/compiler/rustc_middle/src/mir/required_items.rs @@ -0,0 +1,68 @@ +use rustc_span::source_map::Spanned; + +use crate::ty::{self, Ty, TyCtxt}; + +use super::ConstOperand; + +#[derive(Debug, HashStable, TyEncodable, TyDecodable, Default)] +pub struct RequiredAndMentionedItems<'tcx> { + /// Constants that are required to evaluate successfully for this MIR to be well-formed. + /// We hold in this field all the constants we are not able to evaluate yet. + /// + /// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a + /// function have successfully evaluated if the function ever gets executed at runtime. + pub required_consts: Vec>, + + /// Further items that were mentioned in this function and hence *may* become monomorphized, + /// depending on optimizations. We use this to avoid optimization-dependent compile errors: the + /// collector recursively traverses all "mentioned" items and evaluates all their + /// `required_consts`. + /// + /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee. + /// All that's relevant is that this set is optimization-level-independent, and that it includes + /// everything that the collector would consider "used". (For example, we currently compute this + /// set after drop elaboration, so some drop calls that can never be reached are not considered + /// "mentioned".) See the documentation of `CollectionMode` in + /// `compiler/rustc_monomorphize/src/collector.rs` for more context. + pub mentioned_items: Vec>>, +} + +/// Some item that needs to monomorphize successfully for a MIR body to be considered well-formed. +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, HashStable, TyEncodable, TyDecodable)] +#[derive(TypeFoldable, TypeVisitable)] +pub enum MentionedItem<'tcx> { + /// A function that gets called. We don't necessarily know its precise type yet, since it can be + /// hidden behind a generic. + Fn(Ty<'tcx>), + /// A type that has its drop shim called. + Drop(Ty<'tcx>), + /// Unsizing casts might require vtables, so we have to record them. + UnsizeCast { source_ty: Ty<'tcx>, target_ty: Ty<'tcx> }, + /// A closure that is coerced to a function pointer. + Closure(Ty<'tcx>), +} + +impl<'tcx> TyCtxt<'tcx> { + pub fn required_and_mentioned_items( + self, + key: ty::InstanceDef<'tcx>, + ) -> &'tcx RequiredAndMentionedItems<'tcx> { + match key { + ty::InstanceDef::Item(id) => self.required_and_mentioned_items_of_item(id), + ty::InstanceDef::Intrinsic(_) + | ty::InstanceDef::VTableShim(_) + | ty::InstanceDef::ReifyShim(..) + | ty::InstanceDef::FnPtrShim(_, _) + | ty::InstanceDef::Virtual(_, _) + | ty::InstanceDef::ClosureOnceShim { .. } + | ty::InstanceDef::ConstructCoroutineInClosureShim { .. } + | ty::InstanceDef::CoroutineKindShim { .. } + | ty::InstanceDef::ThreadLocalShim(_) + | ty::InstanceDef::DropGlue(_, _) + | ty::InstanceDef::CloneShim(_, _) + | ty::InstanceDef::FnPtrAddrShim(_, _) => { + self.required_and_mentioned_items_of_shim(key) + } + } + } +} diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 4f7b2f7cbe48b..01c5335580e1a 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -1050,11 +1050,6 @@ macro_rules! super_body { } $self.visit_span($(& $mutability)? $body.span); - - for const_ in &$($mutability)? $body.required_consts { - let location = Location::START; - $self.visit_constant(const_, location); - } } } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 62a60a650eccf..42456409d6550 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -584,6 +584,21 @@ rustc_queries! { separate_provide_extern } + /// Cross-crate cache of `required_and_mentioned_items`. Do not call directly. + query required_and_mentioned_items_of_item(key: DefId) -> &'tcx mir::RequiredAndMentionedItems<'tcx> { + desc { |tcx| "computing required and mentioned items for `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } + arena_cache + separate_provide_extern + } + + /// Internal implementation detail of `required_and_mentioned_items`. Do not call directly. + query required_and_mentioned_items_of_shim(key: ty::InstanceDef<'tcx>) -> &'tcx mir::RequiredAndMentionedItems<'tcx> { + desc { |tcx| "computing required and mentioned items for `{}`", tcx.def_path_str(key.def_id()) } + cache_on_disk_if { true } + arena_cache + } + /// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass /// (for compiler option `-Cinstrument-coverage`), after MIR optimizations /// have had a chance to potentially remove some of them. diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs index 571c6e918dcbe..805292159ef22 100644 --- a/compiler/rustc_middle/src/ty/parameterized.rs +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -126,6 +126,7 @@ macro_rules! parameterized_over_tcx { parameterized_over_tcx! { crate::middle::exported_symbols::ExportedSymbol, crate::mir::Body, + crate::mir::RequiredAndMentionedItems, crate::mir::CoroutineLayout, crate::mir::interpret::ConstAllocation, ty::Ty, diff --git a/compiler/rustc_mir_build/src/build/custom/mod.rs b/compiler/rustc_mir_build/src/build/custom/mod.rs index 30877e38318d6..0affe1fae1e5d 100644 --- a/compiler/rustc_mir_build/src/build/custom/mod.rs +++ b/compiler/rustc_mir_build/src/build/custom/mod.rs @@ -55,8 +55,6 @@ pub(super) fn build_custom_mir<'tcx>( spread_arg: None, var_debug_info: Vec::new(), span, - required_consts: Vec::new(), - mentioned_items: Vec::new(), is_polymorphic: false, tainted_by_errors: None, injection_phase: None, diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 60513a674af95..acf8e4a9e38b2 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -566,8 +566,7 @@ impl<'tcx> Inliner<'tcx> { mut callee_body: Body<'tcx>, ) { let terminator = caller_body[callsite.block].terminator.take().unwrap(); - let TerminatorKind::Call { func, args, destination, unwind, target, .. } = terminator.kind - else { + let TerminatorKind::Call { args, destination, unwind, target, .. } = terminator.kind else { bug!("unexpected terminator kind {:?}", terminator.kind); }; @@ -706,37 +705,6 @@ impl<'tcx> Inliner<'tcx> { source_info: callsite.source_info, kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) }, }); - - // Copy only unevaluated constants from the callee_body into the caller_body. - // Although we are only pushing `ConstKind::Unevaluated` consts to - // `required_consts`, here we may not only have `ConstKind::Unevaluated` - // because we are calling `instantiate_and_normalize_erasing_regions`. - caller_body.required_consts.extend(callee_body.required_consts.iter().copied().filter( - |&ct| match ct.const_ { - Const::Ty(_) => { - bug!("should never encounter ty::UnevaluatedConst in `required_consts`") - } - Const::Val(..) | Const::Unevaluated(..) => true, - }, - )); - // Now that we incorporated the callee's `required_consts`, we can remove the callee from - // `mentioned_items` -- but we have to take their `mentioned_items` in return. This does - // some extra work here to save the monomorphization collector work later. It helps a lot, - // since monomorphization can avoid a lot of work when the "mentioned items" are similar to - // the actually used items. By doing this we can entirely avoid visiting the callee! - // We need to reconstruct the `required_item` for the callee so that we can find and - // remove it. - let callee_item = MentionedItem::Fn(func.ty(caller_body, self.tcx)); - if let Some(idx) = - caller_body.mentioned_items.iter().position(|item| item.node == callee_item) - { - // We found the callee, so remove it and add its items instead. - caller_body.mentioned_items.remove(idx); - caller_body.mentioned_items.extend(callee_body.mentioned_items); - } else { - // If we can't find the callee, there's no point in adding its items. - // Probably it already got removed by being inlined elsewhere in the same function. - } } fn make_call_args( diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index e477c068229ff..eb6570cb6ae96 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -32,7 +32,7 @@ use rustc_hir::intravisit::{self, Visitor}; use rustc_index::IndexVec; use rustc_middle::mir::visit::Visitor as _; use rustc_middle::mir::{ - traversal, AnalysisPhase, Body, CallSource, ClearCrossCrate, ConstOperand, ConstQualifs, + self, traversal, AnalysisPhase, Body, CallSource, ClearCrossCrate, ConstOperand, ConstQualifs, LocalDecl, MirPass, MirPhase, Operand, Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo, Statement, StatementKind, TerminatorKind, START_BLOCK, }; @@ -128,6 +128,10 @@ pub fn provide(providers: &mut Providers) { mir_built, mir_const_qualif, mir_promoted, + required_and_mentioned_items_of_item: |tcx, key| { + required_and_mentioned_items(tcx, ty::InstanceDef::Item(key.into())) + }, + required_and_mentioned_items_of_shim: required_and_mentioned_items, mir_drops_elaborated_and_const_checked, mir_for_ctfe, mir_coroutine_witnesses: coroutine::mir_coroutine_witnesses, @@ -328,18 +332,12 @@ fn mir_promoted( }; // has_ffi_unwind_calls query uses the raw mir, so make sure it is run. tcx.ensure_with_value().has_ffi_unwind_calls(def); + tcx.ensure().required_and_mentioned_items_of_item(def); let mut body = tcx.mir_built(def).steal(); if let Some(error_reported) = const_qualifs.tainted_by_errors { body.tainted_by_errors = Some(error_reported); } - let mut required_consts = Vec::new(); - let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts); - for (bb, bb_data) in traversal::reverse_postorder(&body) { - required_consts_visitor.visit_basic_block_data(bb, bb_data); - } - body.required_consts = required_consts; - // What we need to run borrowck etc. let promote_pass = promote_consts::PromoteTemps::default(); pm::run_passes( @@ -353,6 +351,41 @@ fn mir_promoted( (tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted)) } +fn required_and_mentioned_items<'tcx>( + tcx: TyCtxt<'tcx>, + key: ty::InstanceDef<'tcx>, +) -> mir::RequiredAndMentionedItems<'tcx> { + let tmp; + let body = match key { + ty::InstanceDef::Item(id) + if matches!(tcx.def_kind(id), DefKind::Ctor(..)) + || !tcx.is_mir_available(id) + || tcx.lang_items().drop_in_place_fn() == Some(id) => + { + return Default::default(); + } + ty::InstanceDef::Item(id) => { + tmp = tcx.mir_built(id.expect_local()).borrow(); + &*tmp + } + _ => tcx.mir_shims(key), + }; + + trace!("{body:#?}"); + + let mut required_consts = Vec::new(); + let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts); + for (bb, bb_data) in traversal::reverse_postorder(body) { + required_consts_visitor.visit_basic_block_data(bb, bb_data); + } + + let mut mentioned_items = Vec::new(); + mentioned_items::MentionedItemsVisitor { tcx, body, mentioned_items: &mut mentioned_items } + .visit_body(body); + + mir::RequiredAndMentionedItems { required_consts, mentioned_items } +} + /// Compute the MIR that is used during CTFE (and thus has no optimizations run on it) fn mir_for_ctfe(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &Body<'_> { tcx.arena.alloc(inner_mir_for_ctfe(tcx, def_id)) @@ -555,9 +588,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { tcx, body, &[ - // Before doing anything, remember which items are being mentioned so that the set of items - // visited does not depend on the optimization level. - &mentioned_items::MentionedItems, // Add some UB checks before any UB gets optimized away. &check_alignment::CheckAlignment, // Before inlining: trim down MIR with passes to reduce inlining work. diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs index 57b6126dece93..e7a7405a89deb 100644 --- a/compiler/rustc_mir_transform/src/mentioned_items.rs +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -1,32 +1,12 @@ use rustc_middle::mir::visit::Visitor; -use rustc_middle::mir::{self, Location, MentionedItem, MirPass}; +use rustc_middle::mir::{self, Location, MentionedItem}; use rustc_middle::ty::{self, adjustment::PointerCoercion, TyCtxt}; -use rustc_session::Session; use rustc_span::source_map::Spanned; -pub struct MentionedItems; - -struct MentionedItemsVisitor<'a, 'tcx> { - tcx: TyCtxt<'tcx>, - body: &'a mir::Body<'tcx>, - mentioned_items: &'a mut Vec>>, -} - -impl<'tcx> MirPass<'tcx> for MentionedItems { - fn is_enabled(&self, _sess: &Session) -> bool { - // If this pass is skipped the collector assume that nothing got mentioned! We could - // potentially skip it in opt-level 0 if we are sure that opt-level will never *remove* uses - // of anything, but that still seems fragile. Furthermore, even debug builds use level 1, so - // special-casing level 0 is just not worth it. - true - } - - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) { - debug_assert!(body.mentioned_items.is_empty()); - let mut mentioned_items = Vec::new(); - MentionedItemsVisitor { tcx, body, mentioned_items: &mut mentioned_items }.visit_body(body); - body.mentioned_items = mentioned_items; - } +pub struct MentionedItemsVisitor<'a, 'tcx> { + pub tcx: TyCtxt<'tcx>, + pub body: &'a mir::Body<'tcx>, + pub mentioned_items: &'a mut Vec>>, } // This visitor is carefully in sync with the one in `rustc_monomorphize::collector`. We are @@ -34,6 +14,7 @@ impl<'tcx> MirPass<'tcx> for MentionedItems { // have to remain generic and just recording the relevant information in `mentioned_items`, where it // will then be monomorphized later during "mentioned items" collection. impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { + #[instrument(skip(self))] fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) { self.super_terminator(terminator, location); let span = || self.body.source_info(location).span; diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index fa6906bdd554f..2eff40f6f17ca 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -17,7 +17,7 @@ use std::iter; use crate::{ abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, deref_separator, - mentioned_items, pass_manager as pm, remove_noop_landing_pads, simplify, + pass_manager as pm, remove_noop_landing_pads, simplify, }; use rustc_middle::mir::patch::MirPatch; use rustc_mir_dataflow::elaborate_drops::{self, DropElaborator, DropFlagMode, DropStyle}; @@ -112,7 +112,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' tcx, &mut body, &[ - &mentioned_items::MentionedItems, &abort_unwinding_calls::AbortUnwindingCalls, &add_call_guards::CriticalCallEdges, ], @@ -144,7 +143,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' tcx, &mut result, &[ - &mentioned_items::MentionedItems, &add_moves_for_packed_drops::AddMovesForPackedDrops, &deref_separator::Derefer, &remove_noop_landing_pads::RemoveNoopLandingPads, diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 0c35f9838ed3f..cf911b27ab1cb 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1413,22 +1413,22 @@ fn collect_items_of_instance<'tcx>( skip_move_check_fns: None, }; + let items = tcx.required_and_mentioned_items(instance.def); + if mode == CollectionMode::UsedItems { - // Visit everything. Here we rely on the visitor also visiting `required_consts`, so that we - // evaluate them and abort compilation if any of them errors. collector.visit_body(body); - } else { - // We only need to evaluate all constants, but can ignore the rest of the MIR. - for const_op in &body.required_consts { - if let Some(val) = collector.eval_constant(const_op) { - collect_const_value(tcx, val, mentioned_items); - } + } + + // Always evaluate all required constants. + for const_op in &items.required_consts { + if let Some(val) = collector.eval_constant(const_op) { + collect_const_value(tcx, val, mentioned_items); } } // Always gather mentioned items. We try to avoid processing items that we have already added to // `used_items` above. - for item in &body.mentioned_items { + for item in &items.mentioned_items { if !collector.used_mentioned_items.contains(&item.node) { let item_mono = collector.monomorphize(item.node); visit_mentioned_item(tcx, &item_mono, item.span, mentioned_items); diff --git a/src/tools/miri/tests/fail/erroneous_const2.stderr b/src/tools/miri/tests/fail/erroneous_const2.stderr index 2227436707482..eadd0fbc2ea91 100644 --- a/src/tools/miri/tests/fail/erroneous_const2.stderr +++ b/src/tools/miri/tests/fail/erroneous_const2.stderr @@ -18,6 +18,20 @@ LL | println!("{}", FOO); | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +note: erroneous constant encountered + --> $DIR/erroneous_const2.rs:LL:CC + | +LL | println!("{}", FOO); + | ^^^^ + +note: erroneous constant encountered + --> $DIR/erroneous_const2.rs:LL:CC + | +LL | println!("{}", FOO); + | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + note: erroneous constant encountered --> $DIR/erroneous_const2.rs:LL:CC | diff --git a/tests/ui/associated-consts/defaults-not-assumed-fail.stderr b/tests/ui/associated-consts/defaults-not-assumed-fail.stderr index 4b53603cfe851..8245e05786b3e 100644 --- a/tests/ui/associated-consts/defaults-not-assumed-fail.stderr +++ b/tests/ui/associated-consts/defaults-not-assumed-fail.stderr @@ -18,6 +18,81 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:32:5 + | +LL | assert_eq!(<() as Tr>::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:32:5 + | +LL | assert_eq!(<() as Tr>::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:32:5 + | +LL | assert_eq!(<() as Tr>::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:32:5 + | +LL | assert_eq!(<() as Tr>::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:5 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:5 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + note: erroneous constant encountered --> $DIR/defaults-not-assumed-fail.rs:33:5 | @@ -35,6 +110,306 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:36:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:36:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:36:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:36:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:37:5 + | +LL | assert_eq!(::B, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:37:5 + | +LL | assert_eq!(::B, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:37:5 + | +LL | assert_eq!(::B, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:37:5 + | +LL | assert_eq!(::B, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:39:5 + | +LL | assert_eq!(::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:39:5 + | +LL | assert_eq!(::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:39:5 + | +LL | assert_eq!(::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:39:5 + | +LL | assert_eq!(::A, 255); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:40:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:40:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:40:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:40:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:42:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:42:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:42:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:42:5 + | +LL | assert_eq!(::A, 254); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:43:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:43:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:33:16 + | +LL | assert_eq!(<() as Tr>::B, 0); // causes the error above + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:43:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/defaults-not-assumed-fail.rs:43:5 + | +LL | assert_eq!(::B, 0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) + error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/assoc_const_generic_impl.stderr b/tests/ui/consts/assoc_const_generic_impl.stderr index 4521950839670..53b3df5477956 100644 --- a/tests/ui/consts/assoc_const_generic_impl.stderr +++ b/tests/ui/consts/assoc_const_generic_impl.stderr @@ -10,6 +10,20 @@ note: erroneous constant encountered LL | Self::I_AM_ZERO_SIZED; | ^^^^^^^^^^^^^^^^^^^^^ +note: erroneous constant encountered + --> $DIR/assoc_const_generic_impl.rs:12:18 + | +LL | println!("requires_zero_size called"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +note: erroneous constant encountered + --> $DIR/assoc_const_generic_impl.rs:11:9 + | +LL | Self::I_AM_ZERO_SIZED; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + note: the above error was encountered while instantiating `fn ::requires_zero_size` --> $DIR/assoc_const_generic_impl.rs:18:5 | diff --git a/tests/ui/consts/const-eval/issue-44578.stderr b/tests/ui/consts/const-eval/issue-44578.stderr index 7d5cf86d3965d..840386aad03be 100644 --- a/tests/ui/consts/const-eval/issue-44578.stderr +++ b/tests/ui/consts/const-eval/issue-44578.stderr @@ -18,6 +18,28 @@ LL | println!("{}", as Foo>::AMT); | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +note: erroneous constant encountered + --> $DIR/issue-44578.rs:25:14 + | +LL | println!("{}", as Foo>::AMT); + | ^^^^ + +note: erroneous constant encountered + --> $DIR/issue-44578.rs:25:14 + | +LL | println!("{}", as Foo>::AMT); + | ^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/issue-44578.rs:25:20 + | +LL | println!("{}", as Foo>::AMT); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + note: erroneous constant encountered --> $DIR/issue-44578.rs:25:20 | diff --git a/tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr b/tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr index 2de68d3fee9e0..13757ab1f46fd 100644 --- a/tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr +++ b/tests/ui/consts/const-eval/issue-50814-2.mir-opt.stderr @@ -48,14 +48,6 @@ LL | & as Foo>::BAR | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -note: erroneous constant encountered - --> $DIR/issue-50814-2.rs:20:6 - | -LL | & as Foo>::BAR - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-forget.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-forget.noopt.stderr new file mode 100644 index 0000000000000..bae5a45951b7b --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-forget.noopt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::::C` failed + --> $DIR/collect-in-dead-forget.rs:8:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-forget.rs:8:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-forget.rs:16:17 + | +LL | let _ = Fail::::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn as std::ops::Drop>::drop` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-forget.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-forget.opt.stderr new file mode 100644 index 0000000000000..bae5a45951b7b --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-forget.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::::C` failed + --> $DIR/collect-in-dead-forget.rs:8:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-forget.rs:8:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-forget.rs:16:17 + | +LL | let _ = Fail::::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn as std::ops::Drop>::drop` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-forget.rs b/tests/ui/consts/required-consts/collect-in-dead-forget.rs index 7586004116c36..759798a41dbc3 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-forget.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-forget.rs @@ -1,12 +1,12 @@ //@revisions: noopt opt -//@build-pass +//@build-fail //@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -//! This passes without optimizations, so it can (and should) also pass with optimizations. struct Fail(T); impl Fail { const C: () = panic!(); + //~^ ERROR: evaluation of `Fail::::C` failed } // This function is not actually called, but is mentioned implicitly as destructor in dead code in a @@ -23,7 +23,7 @@ fn called(x: T) { let v = Fail(x); std::mem::forget(v); // Now the destructor never gets "mentioned" so this build should *not* fail. - // IOW, this demonstrates that we are using a post-drop-elab notion of "mentioned". + // IOW, this demonstrates that we are not using a post-drop-elab notion of "mentioned". } } diff --git a/tests/ui/consts/uninhabited-const-issue-61744.stderr b/tests/ui/consts/uninhabited-const-issue-61744.stderr index c6dd11ee5db92..7ab0c52275ab4 100644 --- a/tests/ui/consts/uninhabited-const-issue-61744.stderr +++ b/tests/ui/consts/uninhabited-const-issue-61744.stderr @@ -659,6 +659,31 @@ LL | dbg!(i32::CONSTANT); | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +note: erroneous constant encountered + --> $DIR/uninhabited-const-issue-61744.rs:18:10 + | +LL | dbg!(i32::CONSTANT); + | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +note: erroneous constant encountered + --> $DIR/uninhabited-const-issue-61744.rs:18:5 + | +LL | dbg!(i32::CONSTANT); + | ^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/uninhabited-const-issue-61744.rs:18:5 + | +LL | dbg!(i32::CONSTANT); + | ^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this note originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) + error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/inline-const/required-const.stderr b/tests/ui/inline-const/required-const.stderr index 2a13d18547c54..c1632c2834735 100644 --- a/tests/ui/inline-const/required-const.stderr +++ b/tests/ui/inline-const/required-const.stderr @@ -12,6 +12,12 @@ note: erroneous constant encountered LL | const { panic!() } | ^^^^^^^^^^^^^^^^^^ +note: the above error was encountered while instantiating `fn foo::` + --> $DIR/required-const.rs:12:5 + | +LL | foo::(); + | ^^^^^^^^^^^^ + error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/nll/issue-97997.rs b/tests/ui/nll/issue-97997.rs index c64e720b12f7f..8e0fbe89ac230 100644 --- a/tests/ui/nll/issue-97997.rs +++ b/tests/ui/nll/issue-97997.rs @@ -12,5 +12,4 @@ fn main() { ::ASSOC; //~^ ERROR implementation of `Foo` is not general enough - //~| ERROR implementation of `Foo` is not general enough } diff --git a/tests/ui/nll/issue-97997.stderr b/tests/ui/nll/issue-97997.stderr index 89eaf77adf063..ff08daaeaac07 100644 --- a/tests/ui/nll/issue-97997.stderr +++ b/tests/ui/nll/issue-97997.stderr @@ -7,15 +7,5 @@ LL | ::ASSOC; = note: `Foo` would have to be implemented for the type `for<'a> fn(&'a u8)` = note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0` -error: implementation of `Foo` is not general enough - --> $DIR/issue-97997.rs:13:5 - | -LL | ::ASSOC; - | ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough - | - = note: `Foo` would have to be implemented for the type `for<'a> fn(&'a u8)` - = note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error