Skip to content

Commit

Permalink
Rollup merge of rust-lang#80372 - jyn514:fix-panics, r=Manishearth
Browse files Browse the repository at this point in the history
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.

Fixes rust-lang#72381.

r? `@kinnison` if you have time, otherwise `@Manishearth`
  • Loading branch information
JohnTitor committed Jan 8, 2021
2 parents 0afd72e + 7edd181 commit 901b9a2
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 @@ -434,16 +434,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 901b9a2

Please sign in to comment.