Skip to content

Commit b4f77df

Browse files
committed
rustdoc: Delete ReceiverTy (formerly known as SelfTy)
It was barely used, and the places that used it are actually clearer without it since they were often undoing some of its work. This also avoids an unnecessary clone of the receiver type and removes a layer of logical indirection in the code.
1 parent e452e3d commit b4f77df

File tree

3 files changed

+18
-45
lines changed

3 files changed

+18
-45
lines changed

src/librustdoc/clean/types.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use thin_vec::ThinVec;
3434
use {rustc_ast as ast, rustc_hir as hir};
3535

3636
pub(crate) use self::ItemKind::*;
37-
pub(crate) use self::ReceiverTy::*;
3837
pub(crate) use self::Type::{
3938
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
4039
RawPointer, SelfTy, Slice, Tuple,
@@ -1384,7 +1383,7 @@ pub(crate) struct FnDecl {
13841383
}
13851384

13861385
impl FnDecl {
1387-
pub(crate) fn receiver_type(&self) -> Option<ReceiverTy> {
1386+
pub(crate) fn receiver_type(&self) -> Option<&Type> {
13881387
self.inputs.values.get(0).and_then(|v| v.to_receiver())
13891388
}
13901389
}
@@ -1403,27 +1402,9 @@ pub(crate) struct Argument {
14031402
pub(crate) is_const: bool,
14041403
}
14051404

1406-
#[derive(Clone, PartialEq, Debug)]
1407-
pub(crate) enum ReceiverTy {
1408-
SelfValue,
1409-
SelfBorrowed(Option<Lifetime>, Mutability),
1410-
SelfExplicit(Type),
1411-
}
1412-
14131405
impl Argument {
1414-
pub(crate) fn to_receiver(&self) -> Option<ReceiverTy> {
1415-
if self.name != kw::SelfLower {
1416-
return None;
1417-
}
1418-
if self.type_.is_self_type() {
1419-
return Some(SelfValue);
1420-
}
1421-
match self.type_ {
1422-
BorrowedRef { ref lifetime, mutability, ref type_ } if type_.is_self_type() => {
1423-
Some(SelfBorrowed(lifetime.clone(), mutability))
1424-
}
1425-
_ => Some(SelfExplicit(self.type_.clone())),
1426-
}
1406+
pub(crate) fn to_receiver(&self) -> Option<&Type> {
1407+
if self.name == kw::SelfLower { Some(&self.type_) } else { None }
14271408
}
14281409
}
14291410

src/librustdoc/html/format.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -1455,27 +1455,20 @@ impl clean::FnDecl {
14551455
for (i, input) in self.inputs.values.iter().enumerate() {
14561456
if let Some(selfty) = input.to_receiver() {
14571457
match selfty {
1458-
clean::SelfValue => {
1458+
clean::SelfTy => {
14591459
write!(f, "self")?;
14601460
}
1461-
clean::SelfBorrowed(Some(ref lt), mutability) => {
1462-
write!(
1463-
f,
1464-
"{amp}{lifetime} {mutability}self",
1465-
lifetime = lt.print(),
1466-
mutability = mutability.print_with_space(),
1467-
)?;
1468-
}
1469-
clean::SelfBorrowed(None, mutability) => {
1470-
write!(
1471-
f,
1472-
"{amp}{mutability}self",
1473-
mutability = mutability.print_with_space(),
1474-
)?;
1461+
clean::BorrowedRef { lifetime, mutability, type_: box clean::SelfTy } => {
1462+
write!(f, "{amp}")?;
1463+
match lifetime {
1464+
Some(lt) => write!(f, "{lt} ", lt = lt.print())?,
1465+
None => {}
1466+
}
1467+
write!(f, "{mutability}self", mutability = mutability.print_with_space())?;
14751468
}
1476-
clean::SelfExplicit(ref typ) => {
1469+
_ => {
14771470
write!(f, "self: ")?;
1478-
typ.print(cx).fmt(f)?;
1471+
selfty.print(cx).fmt(f)?;
14791472
}
14801473
}
14811474
} else {

src/librustdoc/html/render/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use serde::{Serialize, Serializer};
5858

5959
pub(crate) use self::context::*;
6060
pub(crate) use self::span_map::{collect_spans_and_sources, LinkFromSrc};
61-
use crate::clean::{self, ItemId, ReceiverTy, RenderedLink};
61+
use crate::clean::{self, ItemId, RenderedLink};
6262
use crate::error::Error;
6363
use crate::formats::cache::Cache;
6464
use crate::formats::item_type::ItemType;
@@ -1378,15 +1378,14 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
13781378
};
13791379

13801380
if let Some(self_ty) = self_type_opt {
1381-
let (by_mut_ref, by_box, by_value) = match self_ty {
1382-
ReceiverTy::SelfBorrowed(_, mutability)
1383-
| ReceiverTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
1381+
let (by_mut_ref, by_box, by_value) = match *self_ty {
1382+
clean::Type::BorrowedRef { mutability, .. } => {
13841383
(mutability == Mutability::Mut, false, false)
13851384
}
1386-
ReceiverTy::SelfExplicit(clean::Type::Path { path }) => {
1385+
clean::Type::Path { ref path } => {
13871386
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
13881387
}
1389-
ReceiverTy::SelfValue => (false, false, true),
1388+
clean::Type::SelfTy => (false, false, true),
13901389
_ => (false, false, false),
13911390
};
13921391

0 commit comments

Comments
 (0)