This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 11use std:: borrow:: Cow ;
2+ use std:: fs:: File ;
23use std:: hash:: { DefaultHasher , Hash , Hasher } ;
4+ use std:: io:: { Read , Write } ;
35use std:: path:: PathBuf ;
46
57use rustc_errors:: pluralize;
@@ -250,8 +252,8 @@ impl<'tcx> TyCtxt<'tcx> {
250252 }
251253
252254 let width = self . sess . diagnostic_width ( ) ;
253- let length_limit = width. saturating_sub ( 30 ) ;
254- if regular. len ( ) <= width {
255+ let length_limit = width / 2 ;
256+ if regular. len ( ) <= width * 2 / 3 {
255257 return regular;
256258 }
257259 let short = self . ty_string_with_limit ( ty, length_limit) ;
@@ -265,7 +267,20 @@ impl<'tcx> TyCtxt<'tcx> {
265267 * path = Some ( path. take ( ) . unwrap_or_else ( || {
266268 self . output_filenames ( ( ) ) . temp_path_ext ( & format ! ( "long-type-{hash}.txt" ) , None )
267269 } ) ) ;
268- match std:: fs:: write ( path. as_ref ( ) . unwrap ( ) , & format ! ( "{regular}\n " ) ) {
270+ let Ok ( mut file) =
271+ File :: options ( ) . create ( true ) . read ( true ) . append ( true ) . open ( & path. as_ref ( ) . unwrap ( ) )
272+ else {
273+ return regular;
274+ } ;
275+
276+ // Do not write the same type to the file multiple times.
277+ let mut contents = String :: new ( ) ;
278+ let _ = file. read_to_string ( & mut contents) ;
279+ if let Some ( _) = contents. lines ( ) . find ( |line| line == & regular) {
280+ return short;
281+ }
282+
283+ match write ! ( file, "{regular}\n " ) {
269284 Ok ( _) => short,
270285 Err ( _) => regular,
271286 }
You can’t perform that action at this time.
0 commit comments