Skip to content

Commit 48060f1

Browse files
committed
rustdoc: Show the correct source filename, without .html
Previously the title would be lib.rs.html -- source if `lib.rs` was the actual source filename. Now the title is lib.rs – source (note the en dash).
1 parent b1496c6 commit 48060f1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/librustdoc/html/sources.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::html::layout;
88
use crate::html::render::{SharedContext, BASIC_KEYWORDS};
99
use rustc_hir::def_id::LOCAL_CRATE;
1010
use rustc_span::source_map::FileName;
11-
use std::ffi::OsStr;
11+
use std::ffi::{OsStr, OsString};
1212
use std::fs;
1313
use std::path::{Component, Path, PathBuf};
1414

@@ -84,7 +84,7 @@ impl<'a> SourceCollector<'a> {
8484
};
8585

8686
// Remove the utf-8 BOM if any
87-
if contents.starts_with("\u{feff}") {
87+
if contents.starts_with('\u{feff}') {
8888
contents.drain(..3);
8989
}
9090

@@ -99,16 +99,15 @@ impl<'a> SourceCollector<'a> {
9999
href.push('/');
100100
});
101101
self.scx.ensure_dir(&cur)?;
102-
let mut fname = p.file_name().expect("source has no filename").to_os_string();
103-
fname.push(".html");
102+
103+
let src_fname =
104+
String::from(p.file_name().expect("source has no filename").to_string_lossy());
105+
let fname = OsString::from(src_fname.clone() + ".html");
104106
cur.push(&fname);
105107
href.push_str(&fname.to_string_lossy());
106108

107-
let title = format!(
108-
"{} -- source",
109-
cur.file_name().expect("failed to get file name").to_string_lossy()
110-
);
111-
let desc = format!("Source to the Rust file `{}`.", filename);
109+
let title = format!("{} – source", src_fname,);
110+
let desc = format!("Source of the Rust file `{}`.", filename);
112111
let page = layout::Page {
113112
title: &title,
114113
css_class: "source",

0 commit comments

Comments
 (0)