Skip to content

Commit

Permalink
Don't panic when an external crate can't be resolved
Browse files Browse the repository at this point in the history
This isn't actually a bug, it can occur when rustdoc tries to resolve a
crate that isn't used in the main code.
  • Loading branch information
jyn514 committed Dec 26, 2020
1 parent 3ffea60 commit 7edd181
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// compile-flags: --extern zip=whatever.rlib
#![deny(broken_intra_doc_links)]
/// See [zip] crate.
//~^ ERROR unresolved
pub struct ArrayZip;
15 changes: 15 additions & 0 deletions src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7edd181

Please sign in to comment.