Skip to content

Commit 08b6beb

Browse files
committed
use unwrap_or_else to prevent unnecessary alloc
1 parent 1beeb5a commit 08b6beb

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
@@ -365,13 +365,12 @@ fn handle_explain(code: &str,
365365
if dedented_line.starts_with("```") {
366366
is_in_code_block = !is_in_code_block;
367367
text.push_str(&line[..(indent_level+3)]);
368-
text.push('\n');
369368
} else if is_in_code_block && dedented_line.starts_with("# ") {
370369
continue;
371370
} else {
372371
text.push_str(line);
373-
text.push('\n');
374372
}
373+
text.push('\n');
375374
}
376375

377376
show_content_with_pager(&text);
@@ -383,7 +382,7 @@ fn handle_explain(code: &str,
383382
}
384383

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

0 commit comments

Comments
 (0)