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