diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-07-29 01:13:50 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-08-06 22:21:49 +0000 |
| commit | 025fbe8f698a85865d0e9dba7e97ec6a82eac59b (patch) | |
| tree | a31f3a36c2fde641f70a6f7e35f113cbcfec7f01 /compiler/rustc_monomorphize/src | |
| parent | 29cdc6a109ee98a382f974bf89d3971b4385399c (diff) | |
| download | rust-025fbe8f698a85865d0e9dba7e97ec6a82eac59b.tar.gz rust-025fbe8f698a85865d0e9dba7e97ec6a82eac59b.zip | |
Add support for shortening `Instance` and use it
Replace ad-hoc type path shortening logic for recursive mono instantiation errors to use `tcx.short_string()` instead.
Diffstat (limited to 'compiler/rustc_monomorphize/src')
| -rw-r--r-- | compiler/rustc_monomorphize/src/collector.rs | 46 | ||||
| -rw-r--r-- | compiler/rustc_monomorphize/src/errors.rs | 23 |
2 files changed, 35 insertions, 34 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 35b80a9b96f..26ca8518434 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -206,7 +206,6 @@ //! regardless of whether it is actually needed or not. use std::cell::OnceCell; -use std::path::PathBuf; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::{MTLock, par_for_each_in}; @@ -224,7 +223,6 @@ use rustc_middle::mir::{self, Location, MentionedItem, traversal}; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion}; use rustc_middle::ty::layout::ValidityRequirement; -use rustc_middle::ty::print::{shrunk_instance_name, with_no_trimmed_paths}; use rustc_middle::ty::{ self, GenericArgs, GenericParamDefKind, Instance, InstanceKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, VtblEntry, @@ -237,7 +235,10 @@ use rustc_span::source_map::{Spanned, dummy_spanned, respan}; use rustc_span::{DUMMY_SP, Span}; use tracing::{debug, instrument, trace}; -use crate::errors::{self, EncounteredErrorWhileInstantiating, NoOptimizedMir, RecursionLimit}; +use crate::errors::{ + self, EncounteredErrorWhileInstantiating, EncounteredErrorWhileInstantiatingGlobalAsm, + NoOptimizedMir, RecursionLimit, +}; #[derive(PartialEq)] pub(crate) enum MonoItemCollectionStrategy { @@ -525,11 +526,23 @@ fn collect_items_rec<'tcx>( && starting_item.node.is_generic_fn() && starting_item.node.is_user_defined() { - let formatted_item = with_no_trimmed_paths!(starting_item.node.to_string()); - tcx.dcx().emit_note(EncounteredErrorWhileInstantiating { - span: starting_item.span, - formatted_item, - }); + match starting_item.node { + MonoItem::Fn(instance) => tcx.dcx().emit_note(EncounteredErrorWhileInstantiating { + span: starting_item.span, + kind: "fn", + instance, + }), + MonoItem::Static(def_id) => tcx.dcx().emit_note(EncounteredErrorWhileInstantiating { + span: starting_item.span, + kind: "static", + instance: Instance::new_raw(def_id, GenericArgs::empty()), + }), + MonoItem::GlobalAsm(_) => { + tcx.dcx().emit_note(EncounteredErrorWhileInstantiatingGlobalAsm { + span: starting_item.span, + }) + } + } } // Only updating `usage_map` for used items as otherwise we may be inserting the same item // multiple times (if it is first 'mentioned' and then later actually used), and the usage map @@ -612,22 +625,7 @@ fn check_recursion_limit<'tcx>( if !recursion_limit.value_within_limit(adjusted_recursion_depth) { let def_span = tcx.def_span(def_id); let def_path_str = tcx.def_path_str(def_id); - let (shrunk, written_to_path) = shrunk_instance_name(tcx, instance); - let mut path = PathBuf::new(); - let was_written = if let Some(written_to_path) = written_to_path { - path = written_to_path; - true - } else { - false - }; - tcx.dcx().emit_fatal(RecursionLimit { - span, - shrunk, - def_span, - def_path_str, - was_written, - path, - }); + tcx.dcx().emit_fatal(RecursionLimit { span, instance, def_span, def_path_str }); } recursion_depths.insert(def_id, recursion_depth + 1); diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index 938c427b56c..89a78897dea 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -1,21 +1,16 @@ -use std::path::PathBuf; - use rustc_macros::{Diagnostic, LintDiagnostic}; -use rustc_middle::ty::Ty; +use rustc_middle::ty::{Instance, Ty}; use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] #[diag(monomorphize_recursion_limit)] -pub(crate) struct RecursionLimit { +pub(crate) struct RecursionLimit<'tcx> { #[primary_span] pub span: Span, - pub shrunk: String, + pub instance: Instance<'tcx>, #[note] pub def_span: Span, pub def_path_str: String, - #[note(monomorphize_written_to_path)] - pub was_written: bool, - pub path: PathBuf, } #[derive(Diagnostic)] @@ -53,10 +48,18 @@ pub(crate) struct CouldntDumpMonoStats { #[derive(Diagnostic)] #[diag(monomorphize_encountered_error_while_instantiating)] -pub(crate) struct EncounteredErrorWhileInstantiating { +pub(crate) struct EncounteredErrorWhileInstantiating<'tcx> { + #[primary_span] + pub span: Span, + pub kind: &'static str, + pub instance: Instance<'tcx>, +} + +#[derive(Diagnostic)] +#[diag(monomorphize_encountered_error_while_instantiating_global_asm)] +pub(crate) struct EncounteredErrorWhileInstantiatingGlobalAsm { #[primary_span] pub span: Span, - pub formatted_item: String, } #[derive(Diagnostic)] |
