Skip to content

Commit c4bbc47

Browse files
authored
Auto merge of #37660 - nikomatsakis:incremental-36349, r=eddyb
Separate impl items from the parent impl This change separates impl item bodies out of the impl itself. This gives incremental more resolution. In so doing, it refactors how the visitors work, and cleans up a bit of the collect/check logic (mostly by moving things out of collect that didn't really belong there, because they were just checking conditions). However, this is not as effective as I expected, for a kind of frustrating reason. In particular, when invoking `foo.bar()` you still wind up with dependencies on private items. The problem is that the method resolution code scans that list for methods with the name `bar` -- and this winds up touching *all* the methods, even private ones. I can imagine two obvious ways to fix this: - separating fn bodies from fn sigs (#35078, currently being pursued by @flodiebold) - a more aggressive model of incremental that @michaelwoerister has been advocating, in which we hash the intermediate results (e.g., the outputs of collect) so that we can see that the intermediate result hasn't changed, even if a particular impl item has changed. So all in all I'm not quite sure whether to land this or not. =) It still seems like it has to be a win in some cases, but not with the test cases we have just now. I can try to gin up some test cases, but I'm not sure if they will be totally realistic. On the other hand, some of the early refactorings to the visitor trait seem worthwhile to me regardless. cc #36349 -- well, this is basically a fix for that issue, I guess r? @michaelwoerister NB: Based atop of @eddyb's PR rust-lang/rust#37402; don't land until that lands.
2 parents 6a6119c + 3b51004 commit c4bbc47

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
364364
let trait_items = tcx.associated_items(did).filter_map(|item| {
365365
match item.kind {
366366
ty::AssociatedKind::Const => {
367-
let default = if item.has_value {
367+
let default = if item.defaultness.has_value() {
368368
Some(pprust::expr_to_string(
369369
lookup_const_by_id(tcx, item.def_id, None).unwrap().0))
370370
} else {
@@ -407,7 +407,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
407407
abi: abi
408408
})
409409
}
410-
_ => panic!("not a tymethod"),
410+
ref r => panic!("not a tymethod: {:?}", r),
411411
};
412412
Some(cleaned)
413413
}

clean/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,10 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
13731373
}
13741374
}
13751375
}
1376+
13761377
let provided = match self.container {
13771378
ty::ImplContainer(_) => false,
1378-
ty::TraitContainer(_) => self.has_value
1379+
ty::TraitContainer(_) => self.defaultness.has_value()
13791380
};
13801381
if provided {
13811382
MethodItem(Method {
@@ -1440,7 +1441,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
14401441
None => bounds.push(TyParamBound::maybe_sized(cx)),
14411442
}
14421443

1443-
let ty = if self.has_value {
1444+
let ty = if self.defaultness.has_value() {
14441445
Some(cx.tcx().item_type(self.def_id))
14451446
} else {
14461447
None

visit_ast.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
502502
om.traits.push(t);
503503
},
504504

505-
hir::ItemImpl(unsafety, polarity, ref gen, ref tr, ref ty, ref items) => {
505+
hir::ItemImpl(unsafety, polarity, ref gen, ref tr, ref ty, ref item_ids) => {
506506
// Don't duplicate impls when inlining, we'll pick them up
507507
// regardless of where they're located.
508508
if !self.inlining {
509+
let items = item_ids.iter()
510+
.map(|ii| self.cx.map.impl_item(ii.id).clone())
511+
.collect();
509512
let i = Impl {
510513
unsafety: unsafety,
511514
polarity: polarity,
512515
generics: gen.clone(),
513516
trait_: tr.clone(),
514517
for_: ty.clone(),
515-
items: items.clone(),
518+
items: items,
516519
attrs: item.attrs.clone(),
517520
id: item.id,
518521
whence: item.span,

0 commit comments

Comments
 (0)