Skip to content

Commit 16fb6b0

Browse files
Reduce error codes length when too much are thrown
1 parent 5747fd6 commit 16fb6b0

File tree

7 files changed

+136
-7
lines changed

7 files changed

+136
-7
lines changed

src/librustc_errors/emitter.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ impl Drop for EmitterWriter {
122122
let mut error_codes = self.error_codes.clone().into_iter().collect::<Vec<_>>();
123123
error_codes.sort();
124124
if error_codes.len() > 1 {
125+
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
125126
writeln!(self.dst,
126-
"You've got a few errors: {}",
127-
error_codes.join(", ")).expect("failed to give tips...");
127+
"You've got a few errors: {}{}",
128+
error_codes[..limit].join(", "),
129+
if error_codes.len() > 9 { "..." } else { "" }
130+
).expect("failed to give tips...");
128131
writeln!(self.dst,
129132
"If you want more information on an error, try using \
130133
\"rustc --explain {}\"",

src/test/ui-fulldeps/custom-derive/issue-36935.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
thread 'rustc' panicked at 'lolnope', $DIR/auxiliary/plugin.rs:27:5
2-
note: Run with `RUST_BACKTRACE=1` for a backtrace.
31
error: proc-macro derive panicked
42
--> $DIR/issue-36935.rs:18:15
53
|

src/test/ui-fulldeps/proc-macro/load-panic.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
thread 'rustc' panicked at 'nope!', $DIR/auxiliary/derive-panic.rs:22:5
2-
note: Run with `RUST_BACKTRACE=1` for a backtrace.
31
error: proc-macro derive panicked
42
--> $DIR/load-panic.rs:17:10
53
|

src/test/ui/error-festival.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Question {
12+
Yes,
13+
No,
14+
}
15+
16+
mod foo {
17+
const FOO: u32 = 0;
18+
}
19+
20+
fn main() {
21+
let x = "a";
22+
x += 2;
23+
//~^ ERROR E0368
24+
y = 2;
25+
//~^ ERROR E0425
26+
x.z();
27+
//~^ ERROR E0599
28+
29+
!Question::Yes;
30+
//~^ ERROR E0600
31+
32+
foo::FOO;
33+
//~^ ERROR E0603
34+
35+
0u32 as char;
36+
//~^ ERROR E0604
37+
38+
let x = 0u8;
39+
x as Vec<u8>;
40+
//~^ ERROR E0605
41+
42+
let x = 5;
43+
let x_is_nonzero = x as bool;
44+
//~^ ERROR E0054
45+
46+
let x = &0u8;
47+
let y: u32 = x as u32;
48+
//~^ ERROR E0606
49+
50+
let v = 0 as *const u8;
51+
v as *const [u8];
52+
//~^ ERROR E0607
53+
}

src/test/ui/error-festival.stderr

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
error[E0425]: cannot find value `y` in this scope
2+
--> $DIR/error-festival.rs:24:5
3+
|
4+
24 | y = 2;
5+
| ^ did you mean `x`?
6+
7+
error[E0603]: constant `FOO` is private
8+
--> $DIR/error-festival.rs:32:5
9+
|
10+
32 | foo::FOO;
11+
| ^^^^^^^^
12+
13+
error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
14+
--> $DIR/error-festival.rs:22:5
15+
|
16+
22 | x += 2;
17+
| -^^^^^
18+
| |
19+
| cannot use `+=` on type `&str`
20+
21+
error[E0599]: no method named `z` found for type `&str` in the current scope
22+
--> $DIR/error-festival.rs:26:7
23+
|
24+
26 | x.z();
25+
| ^
26+
27+
error[E0600]: cannot apply unary operator `!` to type `Question`
28+
--> $DIR/error-festival.rs:29:5
29+
|
30+
29 | !Question::Yes;
31+
| ^^^^^^^^^^^^^^
32+
33+
error[E0604]: only `u8` can be cast as `char`, not `u32`
34+
--> $DIR/error-festival.rs:35:5
35+
|
36+
35 | 0u32 as char;
37+
| ^^^^^^^^^^^^
38+
39+
error[E0605]: non-primitive cast: `u8` as `std::vec::Vec<u8>`
40+
--> $DIR/error-festival.rs:39:5
41+
|
42+
39 | x as Vec<u8>;
43+
| ^^^^^^^^^^^^
44+
|
45+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
46+
47+
error[E0054]: cannot cast as `bool`
48+
--> $DIR/error-festival.rs:43:24
49+
|
50+
43 | let x_is_nonzero = x as bool;
51+
| ^^^^^^^^^ unsupported cast
52+
|
53+
= help: compare with zero instead
54+
55+
error[E0606]: casting `&u8` as `u32` is invalid
56+
--> $DIR/error-festival.rs:47:18
57+
|
58+
47 | let y: u32 = x as u32;
59+
| ^^^^^^^^ cannot cast `&u8` as `u32`
60+
|
61+
help: did you mean `*x`?
62+
--> $DIR/error-festival.rs:47:18
63+
|
64+
47 | let y: u32 = x as u32;
65+
| ^
66+
67+
error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
68+
--> $DIR/error-festival.rs:51:5
69+
|
70+
51 | v as *const [u8];
71+
| ^^^^^^^^^^^^^^^^
72+
73+
error: aborting due to 10 previous errors
74+
75+
You've got a few errors: E0054, E0368, E0425, E0599, E0600, E0603, E0604, E0605, E0606...
76+
If you want more information on an error, try using "rustc --explain E0054"

src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ help: change the closure to accept a tuple instead of individual arguments
1212

1313
error: aborting due to previous error
1414

15+
If you want more information on this error, try using "rustc --explain E0593"

src/test/ui/span/issue-42234-unknown-receiver-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ error[E0282]: type annotations needed
1515

1616
error: aborting due to 2 previous errors
1717

18-
If you want more information on this error, try using "rustc --explain E0619"
18+
If you want more information on this error, try using "rustc --explain E0282"

0 commit comments

Comments
 (0)