summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/ty/error.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_middle/src/ty/error.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/ty/error.rs')
-rw-r--r--compiler/rustc_middle/src/ty/error.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs
index 738bb5e8b..0e4487852 100644
--- a/compiler/rustc_middle/src/ty/error.rs
+++ b/compiler/rustc_middle/src/ty/error.rs
@@ -7,8 +7,7 @@ use rustc_hir::def_id::DefId;
use rustc_span::symbol::Symbol;
use rustc_target::spec::abi;
use std::borrow::Cow;
-use std::collections::hash_map::DefaultHasher;
-use std::hash::{Hash, Hasher};
+use std::hash::{DefaultHasher, Hash, Hasher};
use std::path::PathBuf;
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)]
@@ -236,7 +235,7 @@ impl<'tcx> Ty<'tcx> {
_ => "fn item".into(),
},
ty::FnPtr(_) => "fn pointer".into(),
- ty::Dynamic(ref inner, ..) if let Some(principal) = inner.principal() => {
+ ty::Dynamic(inner, ..) if let Some(principal) = inner.principal() => {
format!("`dyn {}`", tcx.def_path_str(principal.def_id())).into()
}
ty::Dynamic(..) => "trait object".into(),
@@ -282,7 +281,7 @@ impl<'tcx> Ty<'tcx> {
| ty::Float(_)
| ty::Str
| ty::Never => "type".into(),
- ty::Tuple(ref tys) if tys.is_empty() => "unit type".into(),
+ ty::Tuple(tys) if tys.is_empty() => "unit type".into(),
ty::Adt(def, _) => def.descr().into(),
ty::Foreign(_) => "extern type".into(),
ty::Array(..) => "array".into(),
@@ -346,33 +345,35 @@ impl<'tcx> TyCtxt<'tcx> {
short
}
- pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
+ pub fn short_ty_string(self, ty: Ty<'tcx>, path: &mut Option<PathBuf>) -> String {
let regular = FmtPrinter::print_string(self, hir::def::Namespace::TypeNS, |cx| {
cx.pretty_print_type(ty)
})
.expect("could not write to `String`");
if !self.sess.opts.unstable_opts.write_long_types_to_disk {
- return (regular, None);
+ return regular;
}
let width = self.sess.diagnostic_width();
let length_limit = width.saturating_sub(30);
if regular.len() <= width {
- return (regular, None);
+ return regular;
}
let short = self.ty_string_with_limit(ty, length_limit);
if regular == short {
- return (regular, None);
+ return regular;
}
- // Multiple types might be shortened in a single error, ensure we create a file for each.
+ // Ensure we create an unique file for the type passed in when we create a file.
let mut s = DefaultHasher::new();
ty.hash(&mut s);
let hash = s.finish();
- let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
- match std::fs::write(&path, &regular) {
- Ok(_) => (short, Some(path)),
- Err(_) => (regular, None),
+ *path = Some(path.take().unwrap_or_else(|| {
+ self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None)
+ }));
+ match std::fs::write(path.as_ref().unwrap(), &format!("{regular}\n")) {
+ Ok(_) => short,
+ Err(_) => regular,
}
}
}