Skip to content

Commit

Permalink
Remove PrimitiveType::as_str
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed May 20, 2021
1 parent 132211b commit 5079744
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 41 deletions.
31 changes: 0 additions & 31 deletions src/librustdoc/clean/types.rs
Expand Up @@ -1767,37 +1767,6 @@ impl PrimitiveType {
}
}

crate fn as_str(&self) -> &'static str {
use self::PrimitiveType::*;
match *self {
Isize => "isize",
I8 => "i8",
I16 => "i16",
I32 => "i32",
I64 => "i64",
I128 => "i128",
Usize => "usize",
U8 => "u8",
U16 => "u16",
U32 => "u32",
U64 => "u64",
U128 => "u128",
F32 => "f32",
F64 => "f64",
Str => "str",
Bool => "bool",
Char => "char",
Array => "array",
Slice => "slice",
Tuple => "tuple",
Unit => "unit",
RawPointer => "pointer",
Reference => "reference",
Fn => "fn",
Never => "never",
}
}

crate fn impls(&self, tcx: TyCtxt<'_>) -> &'static ArrayVec<DefId, 4> {
Self::all_impls(tcx).get(self).expect("missing impl for primitive type")
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/format.rs
Expand Up @@ -574,7 +574,7 @@ fn primitive_link(
f,
"<a class=\"primitive\" href=\"{}primitive.{}.html\">",
"../".repeat(len),
prim.as_str()
prim.as_sym()
)?;
needs_termination = true;
}
Expand Down Expand Up @@ -603,7 +603,7 @@ fn primitive_link(
f,
"<a class=\"primitive\" href=\"{}/primitive.{}.html\">",
loc.join("/"),
prim.as_str()
prim.as_sym()
)?;
needs_termination = true;
}
Expand Down Expand Up @@ -677,7 +677,7 @@ fn fmt_type<'cx>(
fmt::Display::fmt(&tybounds(param_names, cx), f)
}
clean::Infer => write!(f, "_"),
clean::Primitive(prim) => primitive_link(f, prim, prim.as_str(), cx),
clean::Primitive(prim) => primitive_link(f, prim, &*prim.as_sym().as_str(), cx),
clean::BareFunction(ref decl) => {
if f.alternate() {
write!(
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Expand Up @@ -379,7 +379,7 @@ impl FromWithTcx<clean::Type> for Type {
.unwrap_or_default(),
},
Generic(s) => Type::Generic(s.to_string()),
Primitive(p) => Type::Primitive(p.as_str().to_string()),
Primitive(p) => Type::Primitive(p.as_sym().to_string()),
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
Tuple(t) => Type::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()),
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Expand Up @@ -91,10 +91,10 @@ impl Res {
}
}

fn name(self, tcx: TyCtxt<'_>) -> String {
fn name(self, tcx: TyCtxt<'_>) -> Symbol {
match self {
Res::Def(_, id) => tcx.item_name(id).to_string(),
Res::Primitive(prim) => prim.as_str().to_string(),
Res::Def(_, id) => tcx.item_name(id),
Res::Primitive(prim) => prim.as_sym(),
}
}

Expand Down Expand Up @@ -388,7 +388,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
ty::AssocKind::Const => "associatedconstant",
ty::AssocKind::Type => "associatedtype",
};
let fragment = format!("{}#{}.{}", prim_ty.as_str(), out, item_name);
let fragment = format!("{}#{}.{}", prim_ty.as_sym(), out, item_name);
(Res::Primitive(prim_ty), fragment, Some((kind.as_def_kind(), item.def_id)))
})
})
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
AnchorFailure::RustdocAnchorConflict(res),
));
}
return Ok((res, Some(ty.as_str().to_owned())));
return Ok((res, Some(ty.as_sym().to_string())));
}
_ => return Ok((res, extra_fragment.clone())),
}
Expand Down Expand Up @@ -1148,7 +1148,7 @@ impl LinkCollector<'_, '_> {
return None;
}
res = prim;
fragment = Some(prim.name(self.cx.tcx));
fragment = Some(prim.name(self.cx.tcx).to_string());
} else {
// `[char]` when a `char` module is in scope
let candidates = vec![res, prim];
Expand Down

0 comments on commit 5079744

Please sign in to comment.