Skip to content

Commit b9ecdca

Browse files
committed
Don't panic when scraping invalid calls
1 parent d1416d5 commit b9ecdca

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/librustdoc/scrape_examples.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,22 @@ where
192192
return;
193193
}
194194

195-
assert!(
196-
enclosing_item_span.contains(call_span),
197-
"Attempted to scrape call at [{call_span:?}] whose enclosing item [{enclosing_item_span:?}] doesn't contain the span of the call.",
198-
);
199-
200-
assert!(
201-
call_span.contains(ident_span),
202-
"Attempted to scrape call at [{call_span:?}] whose identifier [{ident_span:?}] was not contained in the span of the call."
203-
);
195+
// If the enclosing item doesn't actually enclose the call, this means we probably have a weird
196+
// macro issue even though the spans aren't tagged as being from an expansion.
197+
if !enclosing_item_span.contains(call_span) {
198+
warn!(
199+
"Attempted to scrape call at [{call_span:?}] whose enclosing item [{enclosing_item_span:?}] doesn't contain the span of the call."
200+
);
201+
return;
202+
}
203+
204+
// Similarly for the call w/ the function ident.
205+
if !call_span.contains(ident_span) {
206+
warn!(
207+
"Attempted to scrape call at [{call_span:?}] whose identifier [{ident_span:?}] was not contained in the span of the call."
208+
);
209+
return;
210+
}
204211

205212
// Save call site if the function resolves to a concrete definition
206213
if let ty::FnDef(def_id, _) = ty.kind() {

0 commit comments

Comments
 (0)