Skip to content

Commit 14c1e71

Browse files
committed
Auto merge of #91501 - camelid:rm-tuple-impls-2, r=GuillaumeGomez
rustdoc: Remove Clean impls for tuples This PR removes all nine Clean impls on tuples, converting them to functions 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. r? `@GuillaumeGomez`
2 parents 532d2b1 + e36561d commit 14c1e71

File tree

4 files changed

+428
-414
lines changed

4 files changed

+428
-414
lines changed

src/librustdoc/clean/auto_trait.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
100100
// Instead, we generate `impl !Send for Foo<T>`, which better
101101
// expresses the fact that `Foo<T>` never implements `Send`,
102102
// regardless of the choice of `T`.
103-
let params = (tcx.generics_of(item_def_id), ty::GenericPredicates::default())
104-
.clean(self.cx)
105-
.params;
103+
let raw_generics = clean_ty_generics(
104+
self.cx,
105+
tcx.generics_of(item_def_id),
106+
ty::GenericPredicates::default(),
107+
);
108+
let params = raw_generics.params;
106109

107110
Generics { params, where_predicates: Vec::new() }
108111
}
@@ -451,10 +454,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
451454
})
452455
.map(|p| p.fold_with(&mut replacer));
453456

454-
let mut generic_params =
455-
(tcx.generics_of(item_def_id), tcx.explicit_predicates_of(item_def_id))
456-
.clean(self.cx)
457-
.params;
457+
let raw_generics = clean_ty_generics(
458+
self.cx,
459+
tcx.generics_of(item_def_id),
460+
tcx.explicit_predicates_of(item_def_id),
461+
);
462+
let mut generic_params = raw_generics.params;
458463

459464
debug!("param_env_to_generics({:?}): generic_params={:?}", item_def_id, generic_params);
460465

src/librustdoc/clean/blanket_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
107107
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
108108
kind: box ImplItem(Impl {
109109
unsafety: hir::Unsafety::Normal,
110-
generics: (
110+
generics: clean_ty_generics(
111+
self.cx,
111112
self.cx.tcx.generics_of(impl_def_id),
112113
self.cx.tcx.explicit_predicates_of(impl_def_id),
113-
)
114-
.clean(self.cx),
114+
),
115115
// FIXME(eddyb) compute both `trait_` and `for_` from
116116
// the post-inference `trait_ref`, as it's more accurate.
117117
trait_: Some(trait_ref.clean(self.cx)),

src/librustdoc/clean/inline.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ use rustc_span::hygiene::MacroKind;
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616

1717
use crate::clean::{
18-
self, utils, Attributes, AttributesExt, ImplKind, ItemId, NestedAttributesExt, Type,
18+
self, clean_fn_decl_from_did_and_sig, clean_ty_generics, utils, Attributes, AttributesExt,
19+
Clean, ImplKind, ItemId, NestedAttributesExt, Type, Visibility,
1920
};
2021
use crate::core::DocContext;
2122
use crate::formats::item_type::ItemType;
2223

23-
use super::{Clean, Visibility};
24-
2524
type Attrs<'hir> = rustc_middle::ty::Attributes<'hir>;
2625

2726
/// Attempt to inline a definition into this AST.
@@ -208,7 +207,7 @@ crate fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Tra
208207
.collect();
209208

210209
let predicates = cx.tcx.predicates_of(did);
211-
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
210+
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
212211
let generics = filter_non_trait_generics(did, generics);
213212
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
214213
let is_auto = cx.tcx.trait_is_auto(did);
@@ -230,7 +229,9 @@ fn build_external_function(cx: &mut DocContext<'_>, did: DefId) -> clean::Functi
230229
let predicates = cx.tcx.predicates_of(did);
231230
let (generics, decl) = clean::enter_impl_trait(cx, |cx| {
232231
// NOTE: generics need to be cleaned before the decl!
233-
((cx.tcx.generics_of(did), predicates).clean(cx), (did, sig).clean(cx))
232+
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
233+
let decl = clean_fn_decl_from_did_and_sig(cx, did, sig);
234+
(generics, decl)
234235
});
235236
clean::Function {
236237
decl,
@@ -243,7 +244,7 @@ fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {
243244
let predicates = cx.tcx.explicit_predicates_of(did);
244245

245246
clean::Enum {
246-
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
247+
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
247248
variants_stripped: false,
248249
variants: cx.tcx.adt_def(did).variants.iter().map(|v| v.clean(cx)).collect(),
249250
}
@@ -255,7 +256,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
255256

256257
clean::Struct {
257258
struct_type: variant.ctor_kind,
258-
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
259+
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
259260
fields: variant.fields.iter().map(|x| x.clean(cx)).collect(),
260261
fields_stripped: false,
261262
}
@@ -265,7 +266,7 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
265266
let predicates = cx.tcx.explicit_predicates_of(did);
266267
let variant = cx.tcx.adt_def(did).non_enum_variant();
267268

268-
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
269+
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
269270
let fields = variant.fields.iter().map(|x| x.clean(cx)).collect();
270271
clean::Union { generics, fields, fields_stripped: false }
271272
}
@@ -276,7 +277,7 @@ fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef {
276277

277278
clean::Typedef {
278279
type_,
279-
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
280+
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
280281
item_type: None,
281282
}
282283
}
@@ -440,7 +441,9 @@ crate fn build_impl(
440441
}
441442
})
442443
.collect::<Vec<_>>(),
443-
clean::enter_impl_trait(cx, |cx| (tcx.generics_of(did), predicates).clean(cx)),
444+
clean::enter_impl_trait(cx, |cx| {
445+
clean_ty_generics(cx, tcx.generics_of(did), predicates)
446+
}),
444447
),
445448
};
446449
let polarity = tcx.impl_polarity(did);

0 commit comments

Comments
 (0)