14
14
#![ feature( associated_type_defaults) ]
15
15
#![ feature( box_into_inner) ]
16
16
#![ feature( box_patterns) ]
17
+ #![ feature( debug_closure_helpers) ]
17
18
#![ feature( error_reporter) ]
19
+ #![ feature( exact_size_is_empty) ]
18
20
#![ feature( extract_if) ]
19
21
#![ feature( if_let_guard) ]
20
22
#![ feature( let_chains) ]
@@ -36,6 +38,7 @@ use std::borrow::Cow;
36
38
use std:: cell:: Cell ;
37
39
use std:: error:: Report ;
38
40
use std:: ffi:: OsStr ;
41
+ use std:: fmt:: Write as _;
39
42
use std:: hash:: Hash ;
40
43
use std:: io:: Write ;
41
44
use std:: num:: NonZero ;
@@ -995,17 +998,17 @@ impl<'a> DiagCtxtHandle<'a> {
995
998
count => Cow :: from ( format ! ( "aborting due to {count} previous errors" ) ) ,
996
999
} ;
997
1000
998
- match ( errors. len ( ) , warnings. len ( ) ) {
999
- ( 0 , 0 ) => return ,
1000
- ( 0 , _) => {
1001
+ match ( errors. is_empty ( ) , warnings. is_empty ( ) ) {
1002
+ ( true , true ) => return ,
1003
+ ( true , _) => {
1001
1004
// Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a
1002
1005
// configuration like `--cap-lints allow --force-warn bare_trait_objects`.
1003
1006
inner. emit_diagnostic (
1004
1007
DiagInner :: new ( ForceWarning ( None ) , DiagMessage :: Str ( warnings) ) ,
1005
1008
None ,
1006
1009
) ;
1007
1010
}
1008
- ( _, 0 ) => {
1011
+ ( _, true ) => {
1009
1012
inner. emit_diagnostic ( DiagInner :: new ( Error , errors) , self . tainted_with_errors ) ;
1010
1013
}
1011
1014
( _, _) => {
@@ -1030,28 +1033,32 @@ impl<'a> DiagCtxtHandle<'a> {
1030
1033
}
1031
1034
} )
1032
1035
. collect :: < Vec < _ > > ( ) ;
1033
- if !error_codes. is_empty ( ) {
1034
- error_codes. sort ( ) ;
1035
- if error_codes. len ( ) > 1 {
1036
- let limit = if error_codes. len ( ) > 9 { 9 } else { error_codes. len ( ) } ;
1037
- let msg1 = format ! (
1038
- "Some errors have detailed explanations: {}{}" ,
1039
- error_codes[ ..limit] . join( ", " ) ,
1040
- if error_codes. len( ) > 9 { "..." } else { "." }
1036
+ error_codes. sort ( ) ;
1037
+ match & error_codes[ ..] {
1038
+ [ code] => {
1039
+ let msg = format ! (
1040
+ "For more information about this error, try `rustc --explain {code}`." ,
1041
1041
) ;
1042
+ inner. emit_diagnostic ( DiagInner :: new ( FailureNote , msg) , None ) ;
1043
+ }
1044
+ [ first_code, error_codes @ ..] => {
1045
+ let error_codes = fmt:: from_fn ( |f| {
1046
+ f. write_str ( first_code) ?;
1047
+ let mut error_codes = error_codes. iter ( ) ;
1048
+ for code in error_codes. by_ref ( ) . take ( 8 ) {
1049
+ write ! ( f, ", {code}" ) ?;
1050
+ }
1051
+ if error_codes. is_empty ( ) { f. write_char ( '.' ) } else { f. write_str ( "..." ) }
1052
+ } ) ;
1053
+ // let limit = error_codes.len().max(9);
1054
+ let msg1 = format ! ( "Some errors have detailed explanations: {error_codes}" ) ;
1042
1055
let msg2 = format ! (
1043
- "For more information about an error, try `rustc --explain {}`." ,
1044
- & error_codes[ 0 ]
1056
+ "For more information about an error, try `rustc --explain {first_code}`." ,
1045
1057
) ;
1046
1058
inner. emit_diagnostic ( DiagInner :: new ( FailureNote , msg1) , None ) ;
1047
1059
inner. emit_diagnostic ( DiagInner :: new ( FailureNote , msg2) , None ) ;
1048
- } else {
1049
- let msg = format ! (
1050
- "For more information about this error, try `rustc --explain {}`." ,
1051
- & error_codes[ 0 ]
1052
- ) ;
1053
- inner. emit_diagnostic ( DiagInner :: new ( FailureNote , msg) , None ) ;
1054
1060
}
1061
+ _ => { }
1055
1062
}
1056
1063
}
1057
1064
}
0 commit comments