From 48060f1a63aa8b1ae04b34c3597f691d4b5e13db Mon Sep 17 00:00:00 2001 From: Camelid Date: Sun, 18 Oct 2020 19:38:47 -0700 Subject: [PATCH] rustdoc: Show the correct source filename, without `.html` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- src/librustdoc/html/sources.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 02a7362bb3b2e..8dc30895762d9 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -8,7 +8,7 @@ use crate::html::layout; use crate::html::render::{SharedContext, BASIC_KEYWORDS}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_span::source_map::FileName; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::fs; use std::path::{Component, Path, PathBuf}; @@ -84,7 +84,7 @@ impl<'a> SourceCollector<'a> { }; // Remove the utf-8 BOM if any - if contents.starts_with("\u{feff}") { + if contents.starts_with('\u{feff}') { contents.drain(..3); } @@ -99,16 +99,15 @@ impl<'a> SourceCollector<'a> { href.push('/'); }); self.scx.ensure_dir(&cur)?; - let mut fname = p.file_name().expect("source has no filename").to_os_string(); - fname.push(".html"); + + let src_fname = + String::from(p.file_name().expect("source has no filename").to_string_lossy()); + let fname = OsString::from(src_fname.clone() + ".html"); cur.push(&fname); href.push_str(&fname.to_string_lossy()); - let title = format!( - "{} -- source", - cur.file_name().expect("failed to get file name").to_string_lossy() - ); - let desc = format!("Source to the Rust file `{}`.", filename); + let title = format!("{} – source", src_fname,); + let desc = format!("Source of the Rust file `{}`.", filename); let page = layout::Page { title: &title, css_class: "source",