@@ -10,7 +10,6 @@ use rustc_data_structures::fx::FxHashMap;
10
10
use rustc_hir:: {
11
11
self as hir,
12
12
intravisit:: { self , Visitor } ,
13
- HirId ,
14
13
} ;
15
14
use rustc_interface:: interface;
16
15
use rustc_macros:: { Decodable , Encodable } ;
@@ -83,15 +82,10 @@ crate struct CallLocation {
83
82
84
83
impl CallLocation {
85
84
fn new (
86
- tcx : TyCtxt < ' _ > ,
87
85
expr_span : rustc_span:: Span ,
88
- expr_id : HirId ,
86
+ enclosing_item_span : rustc_span :: Span ,
89
87
source_file : & SourceFile ,
90
88
) -> Self {
91
- let enclosing_item_span =
92
- tcx. hir ( ) . span_with_body ( tcx. hir ( ) . get_parent_item ( expr_id) ) . source_callsite ( ) ;
93
- assert ! ( enclosing_item_span. contains( expr_span) ) ;
94
-
95
89
CallLocation {
96
90
call_expr : SyntaxRange :: new ( expr_span, source_file) ,
97
91
enclosing_item : SyntaxRange :: new ( enclosing_item_span, source_file) ,
@@ -168,13 +162,29 @@ where
168
162
// If this span comes from a macro expansion, then the source code may not actually show
169
163
// a use of the given item, so it would be a poor example. Hence, we skip all uses in macros.
170
164
if span. from_expansion ( ) {
165
+ trace ! ( "Rejecting expr from macro: {:?}" , span) ;
171
166
return ;
172
167
}
173
168
169
+ // If the enclosing item has a span coming from a proc macro, then we also don't want to include
170
+ // the example.
171
+ let enclosing_item_span = tcx. hir ( ) . span_with_body ( tcx. hir ( ) . get_parent_item ( ex. hir_id ) ) ;
172
+ if enclosing_item_span. from_expansion ( ) {
173
+ trace ! ( "Rejecting expr ({:?}) from macro item: {:?}" , span, enclosing_item_span) ;
174
+ return ;
175
+ }
176
+
177
+ assert ! (
178
+ enclosing_item_span. contains( span) ,
179
+ "Attempted to scrape call at [{:?}] whose enclosing item [{:?}] doesn't contain the span of the call." ,
180
+ span,
181
+ enclosing_item_span
182
+ ) ;
183
+
174
184
// Save call site if the function resolves to a concrete definition
175
185
if let ty:: FnDef ( def_id, _) = ty. kind ( ) {
176
- // Ignore functions not from the crate being documented
177
186
if self . target_crates . iter ( ) . all ( |krate| * krate != def_id. krate ) {
187
+ trace ! ( "Rejecting expr from crate not being documented: {:?}" , span) ;
178
188
return ;
179
189
}
180
190
@@ -198,7 +208,8 @@ where
198
208
let fn_key = tcx. def_path_hash ( * def_id) ;
199
209
let fn_entries = self . calls . entry ( fn_key) . or_default ( ) ;
200
210
201
- let location = CallLocation :: new ( tcx, span, ex. hir_id , & file) ;
211
+ trace ! ( "Including expr: {:?}" , span) ;
212
+ let location = CallLocation :: new ( span, enclosing_item_span, & file) ;
202
213
fn_entries. entry ( abs_path) . or_insert_with ( mk_call_data) . locations . push ( location) ;
203
214
}
204
215
}
0 commit comments