File tree 1 file changed +18
-3
lines changed
compiler/rustc_middle/src/ty
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 1
1
use std:: borrow:: Cow ;
2
+ use std:: fs:: File ;
2
3
use std:: hash:: { DefaultHasher , Hash , Hasher } ;
4
+ use std:: io:: { Read , Write } ;
3
5
use std:: path:: PathBuf ;
4
6
5
7
use rustc_errors:: pluralize;
@@ -250,8 +252,8 @@ impl<'tcx> TyCtxt<'tcx> {
250
252
}
251
253
252
254
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 {
255
257
return regular;
256
258
}
257
259
let short = self . ty_string_with_limit ( ty, length_limit) ;
@@ -265,7 +267,20 @@ impl<'tcx> TyCtxt<'tcx> {
265
267
* path = Some ( path. take ( ) . unwrap_or_else ( || {
266
268
self . output_filenames ( ( ) ) . temp_path_ext ( & format ! ( "long-type-{hash}.txt" ) , None )
267
269
} ) ) ;
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 " ) {
269
284
Ok ( _) => short,
270
285
Err ( _) => regular,
271
286
}
You can’t perform that action at this time.
0 commit comments