Skip to content

Commit 2fbdc79

Browse files
committed
Remove a Clean impl for a tuple (1)
This commit removes the first of nine Clean impls on tuples, converting it to a function instead. The fact that these are impls causes several problems: 1. They are nameless, so it's unclear what they do. 2. It's hard to find where they're used apart from removing them and seeing what errors occur (this applies to all Clean impls, not just the tuple ones). 3. Rustc doesn't currently warn when impls are unused, so dead code can accumulate easily (all Clean impls). 4. Their bodies often use tuple field indexing syntax (e.g., `self.1`) to refer to their "arguments", which makes reading the code more difficult. As I noted, some of these problems apply to all Clean impls, but even those problems are exacerbated by the tuple impls since they make general understanding of the code harder. Converting the impls to functions solves all four of these problems.
1 parent f2ecfc7 commit 2fbdc79

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ impl Clean<GenericBound> for hir::GenericBound<'_> {
102102
_ => bug!("clean: parenthesized `GenericBound::LangItemTrait`"),
103103
};
104104

105+
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
105106
GenericBound::TraitBound(
106-
PolyTrait {
107-
trait_: (trait_ref, &bindings[..]).clean(cx),
108-
generic_params: vec![],
109-
},
107+
PolyTrait { trait_, generic_params: vec![] },
110108
hir::TraitBoundModifier::None,
111109
)
112110
}
@@ -117,29 +115,26 @@ impl Clean<GenericBound> for hir::GenericBound<'_> {
117115
}
118116
}
119117

120-
impl Clean<Path> for (ty::TraitRef<'_>, &[TypeBinding]) {
121-
fn clean(&self, cx: &mut DocContext<'_>) -> Path {
122-
let (trait_ref, bindings) = *self;
123-
let kind = cx.tcx.def_kind(trait_ref.def_id).into();
124-
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
125-
span_bug!(
126-
cx.tcx.def_span(trait_ref.def_id),
127-
"`TraitRef` had unexpected kind {:?}",
128-
kind
129-
);
130-
}
131-
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
132-
let path = external_path(cx, trait_ref.def_id, true, bindings.to_vec(), trait_ref.substs);
118+
fn clean_trait_ref_with_bindings(
119+
cx: &mut DocContext<'_>,
120+
trait_ref: ty::TraitRef<'_>,
121+
bindings: &[TypeBinding],
122+
) -> Path {
123+
let kind = cx.tcx.def_kind(trait_ref.def_id).into();
124+
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
125+
span_bug!(cx.tcx.def_span(trait_ref.def_id), "`TraitRef` had unexpected kind {:?}", kind);
126+
}
127+
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
128+
let path = external_path(cx, trait_ref.def_id, true, bindings.to_vec(), trait_ref.substs);
133129

134-
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
130+
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
135131

136-
path
137-
}
132+
path
138133
}
139134

140135
impl Clean<Path> for ty::TraitRef<'tcx> {
141136
fn clean(&self, cx: &mut DocContext<'_>) -> Path {
142-
(*self, &[][..]).clean(cx)
137+
clean_trait_ref_with_bindings(cx, *self, &[])
143138
}
144139
}
145140

@@ -162,11 +157,9 @@ impl Clean<GenericBound> for (ty::PolyTraitRef<'_>, &[TypeBinding]) {
162157
})
163158
.collect();
164159

160+
let trait_ = clean_trait_ref_with_bindings(cx, poly_trait_ref.skip_binder(), bindings);
165161
GenericBound::TraitBound(
166-
PolyTrait {
167-
trait_: (poly_trait_ref.skip_binder(), bindings).clean(cx),
168-
generic_params: late_bound_regions,
169-
},
162+
PolyTrait { trait_, generic_params: late_bound_regions },
170163
hir::TraitBoundModifier::None,
171164
)
172165
}

0 commit comments

Comments
 (0)