diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2022-11-15 17:38:39 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2022-11-18 08:42:59 -0800 |
| commit | d49c10ac62c6f781b05bb2136b63bdf7a4608439 (patch) | |
| tree | 241d05c0a31daac1cc9eda82a1e8f4d7de486d5f /compiler/rustc_monomorphize | |
| parent | fd3bfb35511cbcff59ce1454d3db627b576d7e92 (diff) | |
| download | rust-d49c10ac62c6f781b05bb2136b63bdf7a4608439.tar.gz rust-d49c10ac62c6f781b05bb2136b63bdf7a4608439.zip | |
Make "long type" printing type aware
Instead of simple string cutting, use a custom printer to hide parts of long printed types.
Diffstat (limited to 'compiler/rustc_monomorphize')
| -rw-r--r-- | compiler/rustc_monomorphize/src/collector.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index cdf8011d4f5..d74893bf0f0 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -197,7 +197,6 @@ use rustc_session::lint::builtin::LARGE_ASSIGNMENTS; use rustc_session::Limit; use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP}; use rustc_target::abi::Size; -use std::iter; use std::ops::Range; use std::path::PathBuf; @@ -541,29 +540,23 @@ fn collect_items_rec<'tcx>( } /// Format instance name that is already known to be too long for rustc. -/// Show only the first and last 32 characters to avoid blasting +/// Show only the first 2 types if it is longer than 32 characters to avoid blasting /// the user's terminal with thousands of lines of type-name. /// /// If the type name is longer than before+after, it will be written to a file. fn shrunk_instance_name<'tcx>( tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>, - before: usize, - after: usize, ) -> (String, Option<PathBuf>) { let s = instance.to_string(); // Only use the shrunk version if it's really shorter. // This also avoids the case where before and after slices overlap. - if s.chars().nth(before + after + 1).is_some() { - // An iterator of all byte positions including the end of the string. - let positions = || s.char_indices().map(|(i, _)| i).chain(iter::once(s.len())); - - let shrunk = format!( - "{before}...{after}", - before = &s[..positions().nth(before).unwrap_or(s.len())], - after = &s[positions().rev().nth(after).unwrap_or(0)..], - ); + if s.chars().nth(33).is_some() { + let shrunk = format!("{}", ty::ShortInstance(instance, 4)); + if shrunk == s { + return (s, None); + } let path = tcx.output_filenames(()).temp_path_ext("long-type.txt", None); let written_to_path = std::fs::write(&path, s).ok().map(|_| path); @@ -599,7 +592,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, 32, 32); + let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance); let mut path = PathBuf::new(); let was_written = if written_to_path.is_some() { path = written_to_path.unwrap(); @@ -641,7 +634,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { // // Bail out in these cases to avoid that bad user experience. if !tcx.type_length_limit().value_within_limit(type_length) { - let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance, 32, 32); + let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance); let span = tcx.def_span(instance.def_id()); let mut path = PathBuf::new(); let was_written = if written_to_path.is_some() { |
