Skip to content

Commit d2a0ead

Browse files
committed
use unwrap_or_else to prevent unnecessary alloc
1 parent f8aad9d commit d2a0ead

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/librustc_driver/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,12 @@ fn handle_explain(code: &str,
367367
if dedented_line.starts_with("```") {
368368
is_in_code_block = !is_in_code_block;
369369
text.push_str(&line[..(indent_level+3)]);
370-
text.push('\n');
371370
} else if is_in_code_block && dedented_line.starts_with("# ") {
372371
continue;
373372
} else {
374373
text.push_str(line);
375-
text.push('\n');
376374
}
375+
text.push('\n');
377376
}
378377

379378
show_content_with_pager(&text);
@@ -385,7 +384,7 @@ fn handle_explain(code: &str,
385384
}
386385

387386
fn show_content_with_pager(content: &String) {
388-
let pager_name = env::var_os("PAGER").unwrap_or(if cfg!(windows) {
387+
let pager_name = env::var_os("PAGER").unwrap_or_else(|| if cfg!(windows) {
389388
OsString::from("more.com")
390389
} else {
391390
OsString::from("less")

0 commit comments

Comments
 (0)