Skip to content

Commit 7837058

Browse files
committed
Add help for the error message when missing rustc_driver
1 parent 5c84f76 commit 7837058

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

compiler/rustc_error_messages/locales/en-US/metadata.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ metadata_rlib_required =
44
metadata_lib_required =
55
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
66
7+
metadata_rustc_lib_required =
8+
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
9+
.note = only .rmeta files are distributed for `rustc_private` crates other than `rustc_driver`
10+
.help = try adding `extern crate rustc_driver;` at the top level of this crate
11+
712
metadata_crate_dep_multiple =
813
cannot satisfy dependencies so `{$crate_name}` only shows up once
914
.help = having upstream crates all available in one format will likely make this go away

compiler/rustc_metadata/src/dependency_format.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
use crate::creader::CStore;
5555
use crate::errors::{
5656
BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy, LibRequired,
57-
RequiredPanicStrategy, RlibRequired, TwoPanicRuntimes,
57+
RequiredPanicStrategy, RlibRequired, RustcLibRequired, TwoPanicRuntimes,
5858
};
5959

6060
use rustc_data_structures::fx::FxHashMap;
@@ -224,7 +224,12 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
224224
Linkage::Static => "rlib",
225225
_ => "dylib",
226226
};
227-
sess.emit_err(LibRequired { crate_name: tcx.crate_name(cnum), kind: kind });
227+
let crate_name = tcx.crate_name(cnum);
228+
if crate_name.as_str().starts_with("rustc_") {
229+
sess.emit_err(RustcLibRequired { crate_name, kind });
230+
} else {
231+
sess.emit_err(LibRequired { crate_name, kind });
232+
}
228233
}
229234
}
230235
}

compiler/rustc_metadata/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub struct LibRequired<'a> {
2424
pub kind: &'a str,
2525
}
2626

27+
#[derive(Diagnostic)]
28+
#[diag(metadata_rustc_lib_required)]
29+
#[help]
30+
pub struct RustcLibRequired<'a> {
31+
pub crate_name: Symbol,
32+
pub kind: &'a str,
33+
}
34+
2735
#[derive(Diagnostic)]
2836
#[diag(metadata_crate_dep_multiple)]
2937
#[help]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Test that we get the following hint when trying to use a compiler crate without rustc_driver.
2+
// error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate
3+
// compile-flags: --emit link
4+
5+
#![feature(rustc_private)]
6+
7+
extern crate rustc_serialize;
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: crate `rustc_serialize` required to be available in rlib format, but was not found in this form
2+
|
3+
= help: try adding `extern crate rustc_driver;` at the top level of this crate
4+
5+
error: crate `smallvec` required to be available in rlib format, but was not found in this form
6+
7+
error: crate `thin_vec` required to be available in rlib format, but was not found in this form
8+
9+
error: crate `indexmap` required to be available in rlib format, but was not found in this form
10+
11+
error: crate `hashbrown` required to be available in rlib format, but was not found in this form
12+
13+
error: crate `ahash` required to be available in rlib format, but was not found in this form
14+
15+
error: crate `once_cell` required to be available in rlib format, but was not found in this form
16+
17+
error: crate `getrandom` required to be available in rlib format, but was not found in this form
18+
19+
error: crate `cfg_if` required to be available in rlib format, but was not found in this form
20+
21+
error: crate `libc` required to be available in rlib format, but was not found in this form
22+
23+
error: aborting due to 10 previous errors
24+

0 commit comments

Comments
 (0)