From 7edd1810b41e239ea59b22a73a87f8c377d2293f Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 25 Dec 2020 19:04:50 -0500 Subject: [PATCH] Don't panic when an external crate can't be resolved This isn't actually a bug, it can occur when rustdoc tries to resolve a crate that isn't used in the main code. --- src/librustdoc/core.rs | 9 ++++----- .../rustdoc-ui/intra-doc/unused-extern-crate.rs | 5 +++++ .../intra-doc/unused-extern-crate.stderr | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs create mode 100644 src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 7e85342ac7d5d..819dc06845f8b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -428,16 +428,15 @@ crate fn create_resolver<'a>( sess.time("load_extern_crates", || { for extern_name in &extern_names { debug!("loading extern crate {}", extern_name); - resolver + if let Err(()) = resolver .resolve_str_path_error( DUMMY_SP, extern_name, TypeNS, LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(), - ) - .unwrap_or_else(|()| { - panic!("Unable to resolve external crate {}", extern_name) - }); + ) { + warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name) + } } }); }); diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs new file mode 100644 index 0000000000000..186503cf69d3f --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs @@ -0,0 +1,5 @@ +// compile-flags: --extern zip=whatever.rlib +#![deny(broken_intra_doc_links)] +/// See [zip] crate. +//~^ ERROR unresolved +pub struct ArrayZip; diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr new file mode 100644 index 0000000000000..b3b57fd131838 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr @@ -0,0 +1,15 @@ +error: unresolved link to `zip` + --> $DIR/unused-extern-crate.rs:3:10 + | +LL | /// See [zip] crate. + | ^^^ no item named `zip` in scope + | +note: the lint level is defined here + --> $DIR/unused-extern-crate.rs:2:9 + | +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` + +error: aborting due to previous error +