]> git.lizzy.rs Git - rust.git/commitdiff
Make `--explain` Handle Partial Error Codes
authorWill Speak <lithiumflame@gmail.com>
Tue, 6 Oct 2015 20:15:04 +0000 (21:15 +0100)
committerWill Speak <will.speak@crispthinking.com>
Wed, 7 Oct 2015 10:59:51 +0000 (11:59 +0100)
Currently the explain command requires full erorr codes, complete with
the leading zeros and the E at the beginning. This commit changes that,
if you don't supply a full erorr code then the error number is padded
out to the required size and the E is added to the beginning.

This means that where previously you would need to write E0001, you can
now write 0001, 001, 01 or jsut 1 to refer to the same error.

src/librustc_driver/lib.rs

index d5644d49e1ea4afc4c3896e5ae94d3c7d2b85193..e4f033efb58e3e83251d6c177d7f89dbb57bc8ec 100644 (file)
@@ -285,7 +285,12 @@ fn early_callback(&mut self,
                       -> Compilation {
         match matches.opt_str("explain") {
             Some(ref code) => {
-                match descriptions.find_description(&code[..]) {
+                let normalised = if !code.starts_with("E") {
+                    format!("E{0:0>4}", code)
+                } else {
+                    code.to_string()
+                };
+                match descriptions.find_description(&normalised) {
                     Some(ref description) => {
                         // Slice off the leading newline and print.
                         print!("{}", &description[1..]);