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

@ -61,10 +61,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.params
.iter()
.filter_map(|param| match param.kind {
ty::GenericParamDefKind::Lifetime => Some(param.name.to_string()),
ty::GenericParamDefKind::Lifetime => Some(param.name),
_ => None,
})
.map(|name| (name.clone(), Lifetime(name)))
.map(|name| (name, Lifetime(name)))
.collect();
let lifetime_predicates = self.handle_lifetimes(&region_data, &names_map);
let new_generics = self.param_env_to_generics(
@ -145,21 +145,21 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
fn get_lifetime(
&self,
region: Region<'_>,
names_map: &FxHashMap<String, Lifetime>,
names_map: &FxHashMap<Symbol, Lifetime>,
) -> Lifetime {
self.region_name(region)
.map(|name| {
names_map.get(&name).unwrap_or_else(|| {
panic!("Missing lifetime with name {:?} for {:?}", name, region)
panic!("Missing lifetime with name {:?} for {:?}", name.as_str(), region)
})
})
.unwrap_or(&Lifetime::statik())
.clone()
}
fn region_name(&self, region: Region<'_>) -> Option<String> {
fn region_name(&self, region: Region<'_>) -> Option<Symbol> {
match region {
&ty::ReEarlyBound(r) => Some(r.name.to_string()),
&ty::ReEarlyBound(r) => Some(r.name),
_ => None,
}
}
@ -177,7 +177,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
fn handle_lifetimes<'cx>(
&self,
regions: &RegionConstraintData<'cx>,
names_map: &FxHashMap<String, Lifetime>,
names_map: &FxHashMap<Symbol, Lifetime>,
) -> Vec<WherePredicate> {
// Our goal is to 'flatten' the list of constraints by eliminating
// all intermediate RegionVids. At the end, all constraints should

View file

@ -486,13 +486,13 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
const_stability: None,
deprecation: None,
kind: clean::ImportItem(clean::Import::new_simple(
item.ident.to_string(),
item.ident.name,
clean::ImportSource {
path: clean::Path {
global: false,
res: item.res,
segments: vec![clean::PathSegment {
name: clean::PrimitiveType::from(p).as_str().to_string(),
name: clean::PrimitiveType::from(p).as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Vec::new(),
bindings: Vec::new(),
@ -562,11 +562,11 @@ fn build_macro(cx: &DocContext<'_>, did: DefId, name: Symbol) -> clean::ItemKind
.collect::<String>()
);
clean::MacroItem(clean::Macro { source, imported_from: Some(imported_from).clean(cx) })
clean::MacroItem(clean::Macro { source, imported_from: Some(imported_from) })
}
LoadedMacro::ProcMacro(ext) => clean::ProcMacroItem(clean::ProcMacro {
kind: ext.macro_kind(),
helpers: ext.helper_attrs.clean(cx),
helpers: ext.helper_attrs,
}),
}
}

View file

@ -379,7 +379,7 @@ impl Clean<Lifetime> for hir::Lifetime {
}
_ => {}
}
Lifetime(self.name.ident().to_string())
Lifetime(self.name.ident().name)
}
}
@ -397,9 +397,9 @@ impl Clean<Lifetime> for hir::GenericParam<'_> {
for bound in bounds {
s.push_str(&format!(" + {}", bound.name.ident()));
}
Lifetime(s)
Lifetime(Symbol::intern(&s))
} else {
Lifetime(self.name.ident().to_string())
Lifetime(self.name.ident().name)
}
}
_ => panic!(),
@ -423,16 +423,16 @@ impl Clean<Constant> for hir::ConstArg {
impl Clean<Lifetime> for ty::GenericParamDef {
fn clean(&self, _cx: &DocContext<'_>) -> Lifetime {
Lifetime(self.name.to_string())
Lifetime(self.name)
}
}
impl Clean<Option<Lifetime>> for ty::RegionKind {
fn clean(&self, cx: &DocContext<'_>) -> Option<Lifetime> {
fn clean(&self, _cx: &DocContext<'_>) -> Option<Lifetime> {
match *self {
ty::ReStatic => Some(Lifetime::statik()),
ty::ReLateBound(_, ty::BrNamed(_, name)) => Some(Lifetime(name.to_string())),
ty::ReEarlyBound(ref data) => Some(Lifetime(data.name.clean(cx))),
ty::ReLateBound(_, ty::BrNamed(_, name)) => Some(Lifetime(name)),
ty::ReEarlyBound(ref data) => Some(Lifetime(data.name)),
ty::ReLateBound(..)
| ty::ReFree(..)
@ -897,7 +897,7 @@ fn clean_fn_or_proc_macro(
}
}
}
ProcMacroItem(ProcMacro { kind, helpers: helpers.clean(cx) })
ProcMacroItem(ProcMacro { kind, helpers })
}
None => {
let mut func = (sig, generics, body_id).clean(cx);
@ -1914,7 +1914,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
impl Clean<PathSegment> for hir::PathSegment<'_> {
fn clean(&self, cx: &DocContext<'_>) -> PathSegment {
PathSegment { name: self.ident.name.clean(cx), args: self.generic_args().clean(cx) }
PathSegment { name: self.ident.name, args: self.generic_args().clean(cx) }
}
}
@ -2132,7 +2132,6 @@ fn clean_extern_crate(
return items;
}
}
let path = orig_name.map(|x| x.to_string());
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
vec![Item {
name: None,
@ -2143,7 +2142,7 @@ fn clean_extern_crate(
stability: None,
const_stability: None,
deprecation: None,
kind: ExternCrateItem(name.clean(cx), path),
kind: ExternCrateItem(name, orig_name),
}]
}
@ -2215,7 +2214,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
const_stability: None,
deprecation: None,
kind: ImportItem(Import::new_simple(
self.name.clean(cx),
self.name,
resolve_use_source(cx, path),
false,
)),
@ -2223,7 +2222,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
return items;
}
}
Import::new_simple(name.clean(cx), resolve_use_source(cx, path), true)
Import::new_simple(name, resolve_use_source(cx, path), true)
};
vec![Item {

View file

@ -295,7 +295,7 @@ impl Item {
#[derive(Clone, Debug)]
crate enum ItemKind {
ExternCrateItem(String, Option<String>),
ExternCrateItem(Symbol, Option<Symbol>),
ImportItem(Import),
StructItem(Struct),
UnionItem(Union),
@ -877,21 +877,19 @@ impl GenericBound {
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct Lifetime(pub String);
crate struct Lifetime(pub Symbol);
impl Lifetime {
crate fn get_ref<'a>(&'a self) -> &'a str {
let Lifetime(ref s) = *self;
let s: &'a str = s;
s
crate fn get_ref(&self) -> SymbolStr {
self.0.as_str()
}
crate fn statik() -> Lifetime {
Lifetime("'static".to_string())
Lifetime(kw::StaticLifetime)
}
crate fn elided() -> Lifetime {
Lifetime("'_".to_string())
Lifetime(kw::UnderscoreLifetime)
}
}
@ -1675,13 +1673,17 @@ crate struct Path {
}
impl Path {
crate fn last_name(&self) -> &str {
crate fn last(&self) -> Symbol {
self.segments.last().expect("segments were empty").name
}
crate fn last_name(&self) -> SymbolStr {
self.segments.last().expect("segments were empty").name.as_str()
}
crate fn whole_name(&self) -> String {
String::from(if self.global { "::" } else { "" })
+ &self.segments.iter().map(|s| s.name.clone()).collect::<Vec<_>>().join("::")
+ &self.segments.iter().map(|s| s.name.to_string()).collect::<Vec<_>>().join("::")
}
}
@ -1700,7 +1702,7 @@ crate enum GenericArgs {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct PathSegment {
crate name: String,
crate name: Symbol,
crate args: GenericArgs,
}
@ -1777,7 +1779,7 @@ crate struct Import {
}
impl Import {
crate fn new_simple(name: String, source: ImportSource, should_be_displayed: bool) -> Self {
crate fn new_simple(name: Symbol, source: ImportSource, should_be_displayed: bool) -> Self {
Self { kind: ImportKind::Simple(name), source, should_be_displayed }
}
@ -1789,7 +1791,7 @@ impl Import {
#[derive(Clone, Debug)]
crate enum ImportKind {
// use source as str;
Simple(String),
Simple(Symbol),
// use source::*;
Glob,
}
@ -1803,13 +1805,13 @@ crate struct ImportSource {
#[derive(Clone, Debug)]
crate struct Macro {
crate source: String,
crate imported_from: Option<String>,
crate imported_from: Option<Symbol>,
}
#[derive(Clone, Debug)]
crate struct ProcMacro {
crate kind: MacroKind,
crate helpers: Vec<String>,
crate helpers: Vec<Symbol>,
}
/// An type binding on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or

View file

@ -153,7 +153,7 @@ pub(super) fn external_path(
global: false,
res: Res::Err,
segments: vec![PathSegment {
name: name.to_string(),
name,
args: external_generic_args(cx, trait_did, has_self, bindings, substs),
}],
}