提交 50797444 编写于 作者: J Joshua Nelson

Remove `PrimitiveType::as_str`

上级 132211bc
...@@ -1767,37 +1767,6 @@ impl PrimitiveType { ...@@ -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> { crate fn impls(&self, tcx: TyCtxt<'_>) -> &'static ArrayVec<DefId, 4> {
Self::all_impls(tcx).get(self).expect("missing impl for primitive type") Self::all_impls(tcx).get(self).expect("missing impl for primitive type")
} }
......
...@@ -574,7 +574,7 @@ fn primitive_link( ...@@ -574,7 +574,7 @@ fn primitive_link(
f, f,
"<a class=\"primitive\" href=\"{}primitive.{}.html\">", "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
"../".repeat(len), "../".repeat(len),
prim.as_str() prim.as_sym()
)?; )?;
needs_termination = true; needs_termination = true;
} }
...@@ -603,7 +603,7 @@ fn primitive_link( ...@@ -603,7 +603,7 @@ fn primitive_link(
f, f,
"<a class=\"primitive\" href=\"{}/primitive.{}.html\">", "<a class=\"primitive\" href=\"{}/primitive.{}.html\">",
loc.join("/"), loc.join("/"),
prim.as_str() prim.as_sym()
)?; )?;
needs_termination = true; needs_termination = true;
} }
...@@ -677,7 +677,7 @@ fn fmt_type<'cx>( ...@@ -677,7 +677,7 @@ fn fmt_type<'cx>(
fmt::Display::fmt(&tybounds(param_names, cx), f) fmt::Display::fmt(&tybounds(param_names, cx), f)
} }
clean::Infer => write!(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) => { clean::BareFunction(ref decl) => {
if f.alternate() { if f.alternate() {
write!( write!(
......
...@@ -379,7 +379,7 @@ fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self { ...@@ -379,7 +379,7 @@ fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
.unwrap_or_default(), .unwrap_or_default(),
}, },
Generic(s) => Type::Generic(s.to_string()), 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))), BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
Tuple(t) => Type::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()), Tuple(t) => Type::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()),
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))), Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
......
...@@ -91,10 +91,10 @@ fn article(self) -> &'static str { ...@@ -91,10 +91,10 @@ fn article(self) -> &'static str {
} }
} }
fn name(self, tcx: TyCtxt<'_>) -> String { fn name(self, tcx: TyCtxt<'_>) -> Symbol {
match self { match self {
Res::Def(_, id) => tcx.item_name(id).to_string(), Res::Def(_, id) => tcx.item_name(id),
Res::Primitive(prim) => prim.as_str().to_string(), Res::Primitive(prim) => prim.as_sym(),
} }
} }
...@@ -388,7 +388,7 @@ fn resolve_primitive_associated_item( ...@@ -388,7 +388,7 @@ fn resolve_primitive_associated_item(
ty::AssocKind::Const => "associatedconstant", ty::AssocKind::Const => "associatedconstant",
ty::AssocKind::Type => "associatedtype", 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))) (Res::Primitive(prim_ty), fragment, Some((kind.as_def_kind(), item.def_id)))
}) })
}) })
...@@ -481,7 +481,7 @@ fn resolve<'path>( ...@@ -481,7 +481,7 @@ fn resolve<'path>(
AnchorFailure::RustdocAnchorConflict(res), 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())), _ => return Ok((res, extra_fragment.clone())),
} }
...@@ -1148,7 +1148,7 @@ fn resolve_link( ...@@ -1148,7 +1148,7 @@ fn resolve_link(
return None; return None;
} }
res = prim; res = prim;
fragment = Some(prim.name(self.cx.tcx)); fragment = Some(prim.name(self.cx.tcx).to_string());
} else { } else {
// `[char]` when a `char` module is in scope // `[char]` when a `char` module is in scope
let candidates = vec![res, prim]; let candidates = vec![res, prim];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册