Skip to content

Commit 4c4bb5f

Browse files
committed
driver: Extract handling of --explain to separate function
1 parent 9951ac4 commit 4c4bb5f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/librustc_driver/lib.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -329,35 +329,38 @@ pub trait CompilerCalls<'a> {
329329
#[derive(Copy, Clone)]
330330
pub struct RustcDefaultCalls;
331331

332+
fn handle_explain(code: &str,
333+
descriptions: &diagnostics::registry::Registry,
334+
output: ErrorOutputType) {
335+
let normalised = if !code.starts_with("E") {
336+
format!("E{0:0>4}", code)
337+
} else {
338+
code.to_string()
339+
};
340+
match descriptions.find_description(&normalised) {
341+
Some(ref description) => {
342+
// Slice off the leading newline and print.
343+
print!("{}", &description[1..]);
344+
}
345+
None => {
346+
early_error(output, &format!("no extended information for {}", code));
347+
}
348+
}
349+
}
350+
332351
impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
333352
fn early_callback(&mut self,
334353
matches: &getopts::Matches,
335354
_sopts: &config::Options,
336355
descriptions: &diagnostics::registry::Registry,
337356
output: ErrorOutputType)
338357
-> Compilation {
339-
match matches.opt_str("explain") {
340-
Some(ref code) => {
341-
let normalised = if !code.starts_with("E") {
342-
format!("E{0:0>4}", code)
343-
} else {
344-
code.to_string()
345-
};
346-
match descriptions.find_description(&normalised) {
347-
Some(ref description) => {
348-
// Slice off the leading newline and print.
349-
print!("{}", &description[1..]);
350-
}
351-
None => {
352-
early_error(output, &format!("no extended information for {}", code));
353-
}
354-
}
355-
return Compilation::Stop;
356-
}
357-
None => (),
358+
if let Some(ref code) = matches.opt_str("explain") {
359+
handle_explain(code, descriptions, output);
360+
return Compilation::Stop;
358361
}
359362

360-
return Compilation::Continue;
363+
Compilation::Continue
361364
}
362365

363366
fn no_input(&mut self,

0 commit comments

Comments
 (0)