Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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).
  • Loading branch information
camelid committed Oct 19, 2020
commit 48060f1a63aa8b1ae04b34c3597f691d4b5e13db
17 changes: 8 additions & 9 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
}

Expand All @@ -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,);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to just use a plain dash (-) rather than a Unicode en dash (–) since I think that's what other page titles use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use - for now so it's consistent; if you want to use then let's make a separate PR making all of the pages use at once.

let desc = format!("Source of the Rust file `{}`.", filename);
let page = layout::Page {
title: &title,
css_class: "source",
Expand Down