Skip to content

Commit 79a5881

Browse files
committed
Don't special-case ExprKind::Call
Don't unnecessarily try to obtain the type-dependent definition of callees in `visit_expr`, just let `visit_qpath` handle callees. This means that for callees that are * `Resolved` paths (the majority of callees) we don't try to `typeck` the enclosing body which should improve perf if the body doesn't contain any type-dependent definitions. * actually `TypeRelative` paths we don't resolve them twice (with slightly different spans)
1 parent 516bace commit 79a5881

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

src/librustdoc/html/render/span_map.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,23 +316,14 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
316316
}
317317

318318
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
319-
let mut handle_type_dependent_def = |hir_id: HirId, span: rustc_span::Span| {
320-
// Exprs *have* to exist in a body, so typeck results should always be available.
321-
let typeck_results = self.maybe_typeck_results().unwrap();
322-
if let Some(def_id) = typeck_results.type_dependent_def_id(hir_id) {
323-
self.matches.insert(span.into(), self.link_for_def(def_id));
324-
}
325-
};
326-
327319
match expr.kind {
328-
ExprKind::MethodCall(seg, ..) => handle_type_dependent_def(expr.hir_id, seg.ident.span),
329-
// FIXME(fmease): We needlessly request `TypeckResults` even if the callee isn't
330-
// type-relative. In the majority of cases, it's just gonna be a
331-
// `Resolved` path meaning we can end up unnecessarily
332-
// `typeck`'ing the body which is super costly!
333-
// Moreover, if it actually is a type-relative path, we end up
334-
// "resolving" it twice (with slightly different spans).
335-
ExprKind::Call(callee, ..) => handle_type_dependent_def(callee.hir_id, callee.span),
320+
ExprKind::MethodCall(segment, ..) => {
321+
// Exprs *have* to exist in a body, so typeck results should always be available.
322+
let typeck_results = self.maybe_typeck_results().unwrap();
323+
if let Some(def_id) = typeck_results.type_dependent_def_id(expr.hir_id) {
324+
self.matches.insert(segment.ident.span.into(), self.link_for_def(def_id));
325+
}
326+
}
336327
// We don't want to go deeper into the macro.
337328
_ if self.handle_macro(expr.span) => return,
338329
_ => {}

0 commit comments

Comments
 (0)