From 132211bce500096330b893e939968f6b2fd5cfb0 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 22:00:26 -0400 Subject: [PATCH 1/2] Remove `to_url_str` --- src/librustdoc/clean/types.rs | 4 ---- src/librustdoc/html/format.rs | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index edd3d77eeb780..86b952e1bf7f7 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1860,10 +1860,6 @@ impl PrimitiveType { }) } - crate fn to_url_str(&self) -> &'static str { - self.as_str() - } - crate fn as_sym(&self) -> Symbol { use PrimitiveType::*; match self { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index fa57c9bda74da..e6e2f011906d4 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -574,7 +574,7 @@ fn primitive_link( f, "", "../".repeat(len), - prim.to_url_str() + prim.as_str() )?; needs_termination = true; } @@ -603,7 +603,7 @@ fn primitive_link( f, "", loc.join("/"), - prim.to_url_str() + prim.as_str() )?; needs_termination = true; } From 5079744414ccc44bd41490619dc8bb277f26b30a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 22:04:50 -0400 Subject: [PATCH 2/2] Remove `PrimitiveType::as_str` --- src/librustdoc/clean/types.rs | 31 ------------------- src/librustdoc/html/format.rs | 6 ++-- src/librustdoc/json/conversions.rs | 2 +- .../passes/collect_intra_doc_links.rs | 12 +++---- 4 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 86b952e1bf7f7..859e525627aba 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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 { Self::all_impls(tcx).get(self).expect("missing impl for primitive type") } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index e6e2f011906d4..8448b07d0be6b 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -574,7 +574,7 @@ fn primitive_link( f, "", "../".repeat(len), - prim.as_str() + prim.as_sym() )?; needs_termination = true; } @@ -603,7 +603,7 @@ fn primitive_link( f, "", loc.join("/"), - prim.as_str() + prim.as_sym() )?; needs_termination = true; } @@ -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!( diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 5ac43c7364622..e0c0e241497b1 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -379,7 +379,7 @@ impl FromWithTcx 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))), diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 81c90f4eaa75b..e6e6497902c26 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -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(), } } @@ -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))) }) }) @@ -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())), } @@ -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];