mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
driver: Extract handling of --explain to separate function
This commit is contained in:
parent
9951ac4be9
commit
4c4bb5ff5c
@ -329,6 +329,25 @@ pub trait CompilerCalls<'a> {
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct RustcDefaultCalls;
|
pub struct RustcDefaultCalls;
|
||||||
|
|
||||||
|
fn handle_explain(code: &str,
|
||||||
|
descriptions: &diagnostics::registry::Registry,
|
||||||
|
output: ErrorOutputType) {
|
||||||
|
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..]);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
early_error(output, &format!("no extended information for {}", code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
||||||
fn early_callback(&mut self,
|
fn early_callback(&mut self,
|
||||||
matches: &getopts::Matches,
|
matches: &getopts::Matches,
|
||||||
@ -336,28 +355,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||||||
descriptions: &diagnostics::registry::Registry,
|
descriptions: &diagnostics::registry::Registry,
|
||||||
output: ErrorOutputType)
|
output: ErrorOutputType)
|
||||||
-> Compilation {
|
-> Compilation {
|
||||||
match matches.opt_str("explain") {
|
if let Some(ref code) = matches.opt_str("explain") {
|
||||||
Some(ref code) => {
|
handle_explain(code, descriptions, output);
|
||||||
let normalised = if !code.starts_with("E") {
|
return Compilation::Stop;
|
||||||
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..]);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
early_error(output, &format!("no extended information for {}", code));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Compilation::Stop;
|
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Compilation::Continue;
|
Compilation::Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_input(&mut self,
|
fn no_input(&mut self,
|
||||||
|
Loading…
Reference in New Issue
Block a user