mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
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.
This commit is contained in:
+19
-26
@@ -102,11 +102,9 @@ fn clean(&self, cx: &mut DocContext<'_>) -> GenericBound {
|
||||
_ => bug!("clean: parenthesized `GenericBound::LangItemTrait`"),
|
||||
};
|
||||
|
||||
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
|
||||
GenericBound::TraitBound(
|
||||
PolyTrait {
|
||||
trait_: (trait_ref, &bindings[..]).clean(cx),
|
||||
generic_params: vec![],
|
||||
},
|
||||
PolyTrait { trait_, generic_params: vec![] },
|
||||
hir::TraitBoundModifier::None,
|
||||
)
|
||||
}
|
||||
@@ -117,29 +115,26 @@ fn clean(&self, cx: &mut DocContext<'_>) -> GenericBound {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clean<Path> for (ty::TraitRef<'_>, &[TypeBinding]) {
|
||||
fn clean(&self, cx: &mut DocContext<'_>) -> Path {
|
||||
let (trait_ref, bindings) = *self;
|
||||
let kind = cx.tcx.def_kind(trait_ref.def_id).into();
|
||||
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
|
||||
span_bug!(
|
||||
cx.tcx.def_span(trait_ref.def_id),
|
||||
"`TraitRef` had unexpected kind {:?}",
|
||||
kind
|
||||
);
|
||||
}
|
||||
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
|
||||
let path = external_path(cx, trait_ref.def_id, true, bindings.to_vec(), trait_ref.substs);
|
||||
|
||||
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
|
||||
|
||||
path
|
||||
fn clean_trait_ref_with_bindings(
|
||||
cx: &mut DocContext<'_>,
|
||||
trait_ref: ty::TraitRef<'_>,
|
||||
bindings: &[TypeBinding],
|
||||
) -> Path {
|
||||
let kind = cx.tcx.def_kind(trait_ref.def_id).into();
|
||||
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
|
||||
span_bug!(cx.tcx.def_span(trait_ref.def_id), "`TraitRef` had unexpected kind {:?}", kind);
|
||||
}
|
||||
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
|
||||
let path = external_path(cx, trait_ref.def_id, true, bindings.to_vec(), trait_ref.substs);
|
||||
|
||||
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
impl Clean<Path> for ty::TraitRef<'tcx> {
|
||||
fn clean(&self, cx: &mut DocContext<'_>) -> Path {
|
||||
(*self, &[][..]).clean(cx)
|
||||
clean_trait_ref_with_bindings(cx, *self, &[])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,11 +157,9 @@ fn clean(&self, cx: &mut DocContext<'_>) -> GenericBound {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let trait_ = clean_trait_ref_with_bindings(cx, poly_trait_ref.skip_binder(), bindings);
|
||||
GenericBound::TraitBound(
|
||||
PolyTrait {
|
||||
trait_: (poly_trait_ref.skip_binder(), bindings).clean(cx),
|
||||
generic_params: late_bound_regions,
|
||||
},
|
||||
PolyTrait { trait_, generic_params: late_bound_regions },
|
||||
hir::TraitBoundModifier::None,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user