Skip to content

Commit 94e4025

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 c4175ec commit 94e4025

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,
@@ -1387,7 +1386,7 @@ pub(crate) struct FnDecl {
13871386
}
13881387

13891388
impl FnDecl {
1390-
pub(crate) fn receiver_type(&self) -> Option<ReceiverTy> {
1389+
pub(crate) fn receiver_type(&self) -> Option<&Type> {
13911390
self.inputs.values.get(0).and_then(|v| v.to_receiver())
13921391
}
13931392
}
@@ -1406,27 +1405,9 @@ pub(crate) struct Argument {
14061405
pub(crate) is_const: bool,
14071406
}
14081407

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

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;
@@ -1385,15 +1385,14 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
13851385
};
13861386

13871387
if let Some(self_ty) = self_type_opt {
1388-
let (by_mut_ref, by_box, by_value) = match self_ty {
1389-
ReceiverTy::SelfBorrowed(_, mutability)
1390-
| ReceiverTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
1388+
let (by_mut_ref, by_box, by_value) = match *self_ty {
1389+
clean::Type::BorrowedRef { mutability, .. } => {
13911390
(mutability == Mutability::Mut, false, false)
13921391
}
1393-
ReceiverTy::SelfExplicit(clean::Type::Path { path }) => {
1392+
clean::Type::Path { ref path } => {
13941393
(false, Some(path.def_id()) == tcx.lang_items().owned_box(), false)
13951394
}
1396-
ReceiverTy::SelfValue => (false, false, true),
1395+
clean::Type::SelfTy => (false, false, true),
13971396
_ => (false, false, false),
13981397
};
13991398

0 commit comments

Comments
 (0)