Reduce error codes length when too much are thrown

This commit is contained in:
Guillaume Gomez 2018-02-24 15:48:53 +01:00
parent 5747fd6611
commit 16fb6b082d
7 changed files with 136 additions and 7 deletions

View File

@ -122,9 +122,12 @@ impl Drop for EmitterWriter {
let mut error_codes = self.error_codes.clone().into_iter().collect::<Vec<_>>(); let mut error_codes = self.error_codes.clone().into_iter().collect::<Vec<_>>();
error_codes.sort(); error_codes.sort();
if error_codes.len() > 1 { if error_codes.len() > 1 {
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
writeln!(self.dst, writeln!(self.dst,
"You've got a few errors: {}", "You've got a few errors: {}{}",
error_codes.join(", ")).expect("failed to give tips..."); error_codes[..limit].join(", "),
if error_codes.len() > 9 { "..." } else { "" }
).expect("failed to give tips...");
writeln!(self.dst, writeln!(self.dst,
"If you want more information on an error, try using \ "If you want more information on an error, try using \
\"rustc --explain {}\"", \"rustc --explain {}\"",

View File

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

View File

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

View File

@ -0,0 +1,53 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Question {
Yes,
No,
}
mod foo {
const FOO: u32 = 0;
}
fn main() {
let x = "a";
x += 2;
//~^ ERROR E0368
y = 2;
//~^ ERROR E0425
x.z();
//~^ ERROR E0599
!Question::Yes;
//~^ ERROR E0600
foo::FOO;
//~^ ERROR E0603
0u32 as char;
//~^ ERROR E0604
let x = 0u8;
x as Vec<u8>;
//~^ ERROR E0605
let x = 5;
let x_is_nonzero = x as bool;
//~^ ERROR E0054
let x = &0u8;
let y: u32 = x as u32;
//~^ ERROR E0606
let v = 0 as *const u8;
v as *const [u8];
//~^ ERROR E0607
}

View File

@ -0,0 +1,76 @@
error[E0425]: cannot find value `y` in this scope
--> $DIR/error-festival.rs:24:5
|
24 | y = 2;
| ^ did you mean `x`?
error[E0603]: constant `FOO` is private
--> $DIR/error-festival.rs:32:5
|
32 | foo::FOO;
| ^^^^^^^^
error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
--> $DIR/error-festival.rs:22:5
|
22 | x += 2;
| -^^^^^
| |
| cannot use `+=` on type `&str`
error[E0599]: no method named `z` found for type `&str` in the current scope
--> $DIR/error-festival.rs:26:7
|
26 | x.z();
| ^
error[E0600]: cannot apply unary operator `!` to type `Question`
--> $DIR/error-festival.rs:29:5
|
29 | !Question::Yes;
| ^^^^^^^^^^^^^^
error[E0604]: only `u8` can be cast as `char`, not `u32`
--> $DIR/error-festival.rs:35:5
|
35 | 0u32 as char;
| ^^^^^^^^^^^^
error[E0605]: non-primitive cast: `u8` as `std::vec::Vec<u8>`
--> $DIR/error-festival.rs:39:5
|
39 | x as Vec<u8>;
| ^^^^^^^^^^^^
|
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
error[E0054]: cannot cast as `bool`
--> $DIR/error-festival.rs:43:24
|
43 | let x_is_nonzero = x as bool;
| ^^^^^^^^^ unsupported cast
|
= help: compare with zero instead
error[E0606]: casting `&u8` as `u32` is invalid
--> $DIR/error-festival.rs:47:18
|
47 | let y: u32 = x as u32;
| ^^^^^^^^ cannot cast `&u8` as `u32`
|
help: did you mean `*x`?
--> $DIR/error-festival.rs:47:18
|
47 | let y: u32 = x as u32;
| ^
error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
--> $DIR/error-festival.rs:51:5
|
51 | v as *const [u8];
| ^^^^^^^^^^^^^^^^
error: aborting due to 10 previous errors
You've got a few errors: E0054, E0368, E0425, E0599, E0600, E0603, E0604, E0605, E0606...
If you want more information on an error, try using "rustc --explain E0054"

View File

@ -12,3 +12,4 @@ help: change the closure to accept a tuple instead of individual arguments
error: aborting due to previous error error: aborting due to previous error
If you want more information on this error, try using "rustc --explain E0593"

View File

@ -15,4 +15,4 @@ error[E0282]: type annotations needed
error: aborting due to 2 previous errors error: aborting due to 2 previous errors
If you want more information on this error, try using "rustc --explain E0619" If you want more information on this error, try using "rustc --explain E0282"