From 44e226ceb753075b44bcaadf349b1d1b6a23ad8d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 17 Dec 2020 14:02:09 +0100 Subject: Continue String to Symbol conversion in rustdoc --- src/librustdoc/html/format.rs | 17 ++++++++--------- src/librustdoc/html/render/cache.rs | 14 +++++++------- src/librustdoc/html/render/mod.rs | 12 ++++++------ 3 files changed, 21 insertions(+), 22 deletions(-) (limited to 'src/librustdoc/html') diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index c49c4892237..f80346aa50b 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -308,7 +308,7 @@ impl<'a> fmt::Display for WhereClause<'a> { } impl clean::Lifetime { - crate fn print(&self) -> &str { + crate fn print(&self) -> impl fmt::Display + '_ { self.get_ref() } } @@ -445,11 +445,10 @@ impl clean::GenericArgs { impl clean::PathSegment { crate fn print(&self) -> impl fmt::Display + '_ { display_fn(move |f| { - f.write_str(&self.name)?; if f.alternate() { - write!(f, "{:#}", self.args.print()) + write!(f, "{}{:#}", self.name, self.args.print()) } else { - write!(f, "{}", self.args.print()) + write!(f, "{}{}", self.name, self.args.print()) } }) } @@ -544,7 +543,7 @@ fn resolved_path( last.name.to_string() } } else { - anchor(did, &last.name).to_string() + anchor(did, &*last.name.as_str()).to_string() }; write!(w, "{}{}", path, last.args.print())?; } @@ -1159,11 +1158,11 @@ impl PrintWithSpace for hir::Mutability { impl clean::Import { crate fn print(&self) -> impl fmt::Display + '_ { display_fn(move |f| match self.kind { - clean::ImportKind::Simple(ref name) => { - if *name == self.source.path.last_name() { + clean::ImportKind::Simple(name) => { + if name == self.source.path.last() { write!(f, "use {};", self.source.print()) } else { - write!(f, "use {} as {};", self.source.print(), *name) + write!(f, "use {} as {};", self.source.print(), name) } } clean::ImportKind::Glob => { @@ -1187,7 +1186,7 @@ impl clean::ImportSource { } let name = self.path.last_name(); if let hir::def::Res::PrimTy(p) = self.path.res { - primitive_link(f, PrimitiveType::from(p), name)?; + primitive_link(f, PrimitiveType::from(p), &*name)?; } else { write!(f, "{}", name)?; } diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 80f54d8e161..94a8b3fef47 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -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 { +fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option { 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> { .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, }) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 00294878fe5..1e888e83e19 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2137,14 +2137,14 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean: w, "{}extern crate {} as {};", myitem.visibility.print_with_space(), - anchor(myitem.def_id, src), + anchor(myitem.def_id, &*src.as_str()), name ), None => write!( w, "{}extern crate {};", myitem.visibility.print_with_space(), - anchor(myitem.def_id, name) + anchor(myitem.def_id, &*name.as_str()) ), } write!(w, ""); @@ -2444,7 +2444,7 @@ fn render_implementor( implementor: &Impl, parent: &clean::Item, w: &mut Buffer, - implementor_dups: &FxHashMap<&str, (DefId, bool)>, + implementor_dups: &FxHashMap, aliases: &[String], cache: &Cache, ) { @@ -2455,7 +2455,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( @@ -2704,7 +2704,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 = FxHashMap::default(); for implementor in implementors { match implementor.inner_impl().for_ { clean::ResolvedPath { ref path, did, is_generic: false, .. } @@ -2713,7 +2713,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; } -- cgit 1.4.1-3-g733a5