@@ -154,6 +154,28 @@ impl<'tcx> SpanMapVisitor<'tcx> {
154154 self . matches . insert ( new_span, link_from_src) ;
155155 true
156156 }
157+
158+ fn handle_call ( & mut self , hir_id : HirId , expr_hir_id : Option < HirId > , span : Span ) {
159+ let hir = self . tcx . hir ( ) ;
160+ let body_id = hir. enclosing_body_owner ( hir_id) ;
161+ // FIXME: this is showing error messages for parts of the code that are not
162+ // compiled (because of cfg)!
163+ //
164+ // See discussion in https://github.com/rust-lang/rust/issues/69426#issuecomment-1019412352
165+ let typeck_results = self
166+ . tcx
167+ . typeck_body ( hir. maybe_body_owned_by ( body_id) . expect ( "a body which isn't a body" ) ) ;
168+ // Interestingly enough, for method calls, we need the whole expression whereas for static
169+ // method/function calls, we need the call expression specifically.
170+ if let Some ( def_id) = typeck_results. type_dependent_def_id ( expr_hir_id. unwrap_or ( hir_id) ) {
171+ let link = if def_id. as_local ( ) . is_some ( ) {
172+ LinkFromSrc :: Local ( rustc_span ( def_id, self . tcx ) )
173+ } else {
174+ LinkFromSrc :: External ( def_id)
175+ } ;
176+ self . matches . insert ( span, link) ;
177+ }
178+ }
157179}
158180
159181impl < ' tcx > Visitor < ' tcx > for SpanMapVisitor < ' tcx > {
@@ -191,27 +213,17 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
191213 }
192214
193215 fn visit_expr ( & mut self , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
194- if let ExprKind :: MethodCall ( segment, ..) = expr. kind {
195- let hir = self . tcx . hir ( ) ;
196- let body_id = hir. enclosing_body_owner ( segment. hir_id ) ;
197- // FIXME: this is showing error messages for parts of the code that are not
198- // compiled (because of cfg)!
199- //
200- // See discussion in https://github.com/rust-lang/rust/issues/69426#issuecomment-1019412352
201- let typeck_results = self
202- . tcx
203- . typeck_body ( hir. maybe_body_owned_by ( body_id) . expect ( "a body which isn't a body" ) ) ;
204- if let Some ( def_id) = typeck_results. type_dependent_def_id ( expr. hir_id ) {
205- let link = if def_id. as_local ( ) . is_some ( ) {
206- LinkFromSrc :: Local ( rustc_span ( def_id, self . tcx ) )
207- } else {
208- LinkFromSrc :: External ( def_id)
209- } ;
210- self . matches . insert ( segment. ident . span , link) ;
216+ match expr. kind {
217+ ExprKind :: MethodCall ( segment, ..) => {
218+ self . handle_call ( segment. hir_id , Some ( expr. hir_id ) , segment. ident . span )
219+ }
220+ ExprKind :: Call ( call, ..) => self . handle_call ( call. hir_id , None , call. span ) ,
221+ _ => {
222+ if self . handle_macro ( expr. span ) {
223+ // We don't want to go deeper into the macro.
224+ return ;
225+ }
211226 }
212- } else if self . handle_macro ( expr. span ) {
213- // We don't want to go deeper into the macro.
214- return ;
215227 }
216228 intravisit:: walk_expr ( self , expr) ;
217229 }
0 commit comments