Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display name of crate requiring rustc_private in error messages. #62819

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,15 @@ impl<'tcx> Index<'tcx> {
// while maintaining the invariant that all sysroot crates are unstable
// by default and are unable to be used.
if tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
let reason = "this crate is being loaded from the sysroot, an \
unstable location; did you mean to load this crate \
from crates.io via `Cargo.toml` instead?";
let reason = format!(
"crate \"{}\" is being loaded from the sysroot, an \
unstable location; did you mean to load this crate \
from crates.io via `Cargo.toml` instead?",
tcx.crate_name(LOCAL_CRATE)
);
let stability = tcx.intern_stability(Stability {
level: attr::StabilityLevel::Unstable {
reason: Some(Symbol::intern(reason)),
reason: Some(Symbol::intern(&reason)),
issue: 27812,
},
feature: sym::rustc_private,
Expand Down
3 changes: 2 additions & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#![unstable(feature = "test", issue = "27812")]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
#![feature(asm)]
#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc, rustc_private))]
#![feature(libc)]
#![feature(rustc_private)]
#![feature(nll)]
#![feature(set_stdio)]
#![feature(panic_unwind)]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui-fulldeps/hash-stable-is-unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ use rustc_macros::HashStable;

#[derive(HashStable)]
//~^ use of unstable library feature 'rustc_private'
//~| use of unstable library feature 'rustc_private'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for this duplicate line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those directives match the start of an error message. Both error messages start the same, but then contain a different crate being loaded from the sysroot: crate "rustc_data_structures" is being from the sysroot, [...] and crate "rustc" is being from the sysroot, [...].

struct Test;
21 changes: 15 additions & 6 deletions src/test/ui-fulldeps/hash-stable-is-unstable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0601]: `main` function not found in crate `hash_stable_is_unstable`
|
= note: consider adding a `main` function to `$DIR/hash-stable-is-unstable.rs`

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
error[E0658]: use of unstable library feature 'rustc_private': crate "rustc_data_structures" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:3:1
|
LL | extern crate rustc_data_structures;
Expand All @@ -11,7 +11,7 @@ LL | extern crate rustc_data_structures;
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
error[E0658]: use of unstable library feature 'rustc_private': crate "rustc" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:5:1
|
LL | extern crate rustc;
Expand All @@ -20,7 +20,7 @@ LL | extern crate rustc;
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
error[E0658]: use of unstable library feature 'rustc_private': crate "rustc_macros" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:7:1
|
LL | extern crate rustc_macros;
Expand All @@ -29,7 +29,7 @@ LL | extern crate rustc_macros;
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
error[E0658]: use of unstable library feature 'rustc_private': crate "rustc_macros" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:10:5
|
LL | use rustc_macros::HashStable;
Expand All @@ -38,7 +38,7 @@ LL | use rustc_macros::HashStable;
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
error[E0658]: use of unstable library feature 'rustc_private': crate "rustc_data_structures" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:13:10
|
LL | #[derive(HashStable)]
Expand All @@ -47,7 +47,16 @@ LL | #[derive(HashStable)]
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error: aborting due to 6 previous errors
error[E0658]: use of unstable library feature 'rustc_private': crate "rustc" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/hash-stable-is-unstable.rs:13:10
|
LL | #[derive(HashStable)]
| ^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.
4 changes: 4 additions & 0 deletions src/test/ui/feature-gates/feature-gate-rustc_private-libc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
extern crate libc; //~ ERROR use of unstable
use libc::*; //~ ERROR unresolved import
}
19 changes: 19 additions & 0 deletions src/test/ui/feature-gates/feature-gate-rustc_private-libc.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0432]: unresolved import `libc`
--> $DIR/feature-gate-rustc_private-libc.rs:3:9
|
LL | use libc::*;
| ^^^^ maybe a missing `extern crate libc;`?

error[E0658]: use of unstable library feature 'rustc_private': crate "libc" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/feature-gate-rustc_private-libc.rs:2:5
|
LL | extern crate libc;
| ^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(rustc_private)]` to the crate attributes to enable

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0658.
For more information about an error, try `rustc --explain E0432`.
4 changes: 4 additions & 0 deletions src/test/ui/feature-gates/feature-gate-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
extern crate test; //~ ERROR use of unstable
use test::*; //~ ERROR unresolved import
}
19 changes: 19 additions & 0 deletions src/test/ui/feature-gates/feature-gate-test.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0432]: unresolved import `test`
--> $DIR/feature-gate-test.rs:3:9
|
LL | use test::*;
| ^^^^ maybe a missing `extern crate test;`?

error[E0658]: use of unstable library feature 'test'
--> $DIR/feature-gate-test.rs:2:5
|
LL | extern crate test;
| ^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add `#![feature(test)]` to the crate attributes to enable

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0658.
For more information about an error, try `rustc --explain E0432`.
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-37887.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0432]: unresolved import `libc`
LL | use libc::*;
| ^^^^ maybe a missing `extern crate libc;`?

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
error[E0658]: use of unstable library feature 'rustc_private': crate "libc" is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
--> $DIR/issue-37887.rs:2:5
|
LL | extern crate libc;
Expand Down