Auto merge of #80119 - GuillaumeGomez:str-to-symbol, r=jyn514

Continue String to Symbol conversion in rustdoc

Follow-up of https://github.com/rust-lang/rust/pull/80091.

This PR is already big enough so I'll stop here before the next one.

r? `@jyn514`
This commit is contained in:
bors 2020-12-18 05:55:24 +00:00
commit fee693d08e
9 changed files with 74 additions and 69 deletions

View file

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::path::Path;
use rustc_data_structures::fx::FxHashMap;
use rustc_span::symbol::sym;
use rustc_span::symbol::{sym, Symbol};
use serde::Serialize;
use crate::clean::types::GetDefId;
@ -191,12 +191,12 @@ fn get_index_type(clean_type: &clean::Type) -> RenderType {
RenderType {
ty: clean_type.def_id(),
idx: None,
name: get_index_type_name(clean_type, true).map(|s| s.to_ascii_lowercase()),
name: get_index_type_name(clean_type, true).map(|s| s.as_str().to_ascii_lowercase()),
generics: get_generics(clean_type),
}
}
fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<String> {
fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<Symbol> {
match *clean_type {
clean::ResolvedPath { ref path, .. } => {
let segments = &path.segments;
@ -206,10 +206,10 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
clean_type, accept_generic
)
});
Some(path_segment.name.clone())
Some(path_segment.name)
}
clean::Generic(s) if accept_generic => Some(s.to_string()),
clean::Primitive(ref p) => Some(format!("{:?}", p)),
clean::Generic(s) if accept_generic => Some(s),
clean::Primitive(ref p) => Some(p.as_sym()),
clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_, accept_generic),
// FIXME: add all from clean::Type.
_ => None,
@ -222,7 +222,7 @@ fn get_generics(clean_type: &clean::Type) -> Option<Vec<Generic>> {
.iter()
.filter_map(|t| {
get_index_type_name(t, false).map(|name| Generic {
name: name.to_ascii_lowercase(),
name: name.as_str().to_ascii_lowercase(),
defid: t.def_id(),
idx: None,
})

View file

@ -2141,14 +2141,14 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
w,
"<tr><td><code>{}extern crate {} as {};",
myitem.visibility.print_with_space(),
anchor(myitem.def_id, src),
anchor(myitem.def_id, &*src.as_str()),
name
),
None => write!(
w,
"<tr><td><code>{}extern crate {};",
myitem.visibility.print_with_space(),
anchor(myitem.def_id, name)
anchor(myitem.def_id, &*name.as_str())
),
}
write!(w, "</code></td></tr>");
@ -2448,7 +2448,7 @@ fn render_implementor(
implementor: &Impl,
parent: &clean::Item,
w: &mut Buffer,
implementor_dups: &FxHashMap<&str, (DefId, bool)>,
implementor_dups: &FxHashMap<Symbol, (DefId, bool)>,
aliases: &[String],
cache: &Cache,
) {
@ -2459,7 +2459,7 @@ fn render_implementor(
| clean::BorrowedRef {
type_: box clean::ResolvedPath { ref path, is_generic: false, .. },
..
} => implementor_dups[path.last_name()].1,
} => implementor_dups[&path.last()].1,
_ => false,
};
render_impl(
@ -2708,7 +2708,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
if let Some(implementors) = cache.implementors.get(&it.def_id) {
// The DefId is for the first Type found with that name. The bool is
// if any Types with the same name but different DefId have been found.
let mut implementor_dups: FxHashMap<&str, (DefId, bool)> = FxHashMap::default();
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
for implementor in implementors {
match implementor.inner_impl().for_ {
clean::ResolvedPath { ref path, did, is_generic: false, .. }
@ -2717,7 +2717,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
..
} => {
let &mut (prev_did, ref mut has_duplicates) =
implementor_dups.entry(path.last_name()).or_insert((did, false));
implementor_dups.entry(path.last()).or_insert((did, false));
if prev_did != did {
*has_duplicates = true;
}