Skip to content

Commit 359b42c

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 a068f86 commit 359b42c

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

src/librustdoc/html/render/span_map.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,13 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
295295
}
296296

297297
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
298-
let mut handle_type_dependent_def = |hir_id: HirId, span: rustc_span::Span| {
299-
let typeck_results = self.typeck_results_for(hir_id.owner).unwrap();
300-
if let Some(def_id) = typeck_results.type_dependent_def_id(hir_id) {
301-
self.matches.insert(span.into(), self.link_for_def(def_id));
302-
}
303-
};
304-
305298
match expr.kind {
306-
ExprKind::MethodCall(seg, ..) => handle_type_dependent_def(expr.hir_id, seg.ident.span),
307-
// FIXME(fmease): We needlessly request `TypeckResults` even if the callee isn't
308-
// type-relative. In the majority of cases, it's just gonna be a
309-
// `Resolved` path meaning we can end up unnecessarily
310-
// `typeck`'ing the body which is super costly!
311-
// Moreover, if it actually is a type-relative path, we end up
312-
// "resolving" it twice (with slightly different spans).
313-
ExprKind::Call(callee, ..) => handle_type_dependent_def(callee.hir_id, callee.span),
299+
ExprKind::MethodCall(segment, ..) => {
300+
let typeck_results = self.typeck_results_for(expr.hir_id.owner).unwrap();
301+
if let Some(def_id) = typeck_results.type_dependent_def_id(expr.hir_id) {
302+
self.matches.insert(segment.ident.span.into(), self.link_for_def(def_id));
303+
}
304+
}
314305
// We don't want to go deeper into the macro.
315306
_ if self.handle_macro(expr.span) => return,
316307
_ => {}

0 commit comments

Comments
 (0)