mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #90349 - willcrichton:example-analyzer, r=jyn514
Fix rare ICE during typeck in rustdoc scrape_examples While testing the `--scrape-examples` extension on the [wasmtime](https://github.com/bytecodealliance/wasmtime) repository, I found some additional edge cases. Specifically, when asking to typecheck a body containing a function call, I would sometimes get an ICE if: * The body doesn't exist * The function's HIR node didn't have a type This adds checks for both of those conditions. (Also this updates a test to check that the sources of a reverse-dependency are correctly generated and linked.) r? `@jyn514`
This commit is contained in:
commit
3730485a24
@ -132,12 +132,28 @@ where
|
||||
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
|
||||
intravisit::walk_expr(self, ex);
|
||||
|
||||
// Get type of function if expression is a function call
|
||||
let tcx = self.tcx;
|
||||
|
||||
// If we visit an item that contains an expression outside a function body,
|
||||
// then we need to exit before calling typeck (which will panic). See
|
||||
// test/run-make/rustdoc-scrape-examples-invalid-expr for an example.
|
||||
let hir = tcx.hir();
|
||||
let owner = hir.local_def_id_to_hir_id(ex.hir_id.owner);
|
||||
if hir.maybe_body_owned_by(owner).is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get type of function if expression is a function call
|
||||
let (ty, span) = match ex.kind {
|
||||
hir::ExprKind::Call(f, _) => {
|
||||
let types = tcx.typeck(ex.hir_id.owner);
|
||||
(types.node_type(f.hir_id), ex.span)
|
||||
|
||||
match types.node_type_opt(f.hir_id) {
|
||||
Some(ty) => (ty, ex.span),
|
||||
None => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ExprKind::MethodCall(_, _, _, span) => {
|
||||
let types = tcx.typeck(ex.hir_id.owner);
|
||||
|
@ -0,0 +1,5 @@
|
||||
deps := ex
|
||||
|
||||
-include ../rustdoc-scrape-examples-multiple/scrape.mk
|
||||
|
||||
all: scrape
|
@ -0,0 +1,2 @@
|
||||
pub struct Foo([usize; foobar::f()]);
|
||||
fn main() {}
|
@ -0,0 +1 @@
|
||||
pub const fn f() -> usize { 5 }
|
@ -1,4 +1,6 @@
|
||||
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//*[@class="prev"]' ''
|
||||
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' ''
|
||||
// @has src/ex/ex.rs.html
|
||||
// @has foobar/fn.ok.html '//a[@href="../src/ex/ex.rs.html#2"]' ''
|
||||
|
||||
pub fn ok() {}
|
||||
|
Loading…
Reference in New Issue
Block a user