-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Exclude dependencies of std
for diagnostics
#135278
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
Changes from 3 commits
4896a65
4dc866c
9c34253
2da9acc
ed63539
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -876,6 +876,11 @@ impl<'tcx> TyCtxt<'tcx> { | |
/// [public]: TyCtxt::is_private_dep | ||
/// [direct]: rustc_session::cstore::ExternCrate::is_direct | ||
pub fn is_user_visible_dep(self, key: CrateNum) -> bool { | ||
// `#![rustc_private]` overrides defaults to make private dependencies usable. | ||
if self.features().enabled(sym::rustc_private) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not really. There are a lot of external custom drivers that need to enable this feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting that it is worth filtering here to only expose crates that are dependencies of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the override for rustc_private should be removed. Even with rustc_private enabled you generally shouldn't do something like |
||
return true; | ||
} | ||
|
||
// | Private | Direct | Visible | | | ||
// |---------|--------|---------|--------------------| | ||
// | Yes | Yes | Yes | !true || true | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0405]: cannot find trait `Equivalent` in this scope | ||
--> $DIR/sysroot-private.rs:26:18 | ||
| | ||
LL | trait Trait2<K>: Equivalent<K> {} | ||
| ^^^^^^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `K` in this scope | ||
--> $DIR/sysroot-private.rs:31:35 | ||
| | ||
LL | fn trait_member<T>(val: &T, key: &K) -> bool { | ||
| - ^ | ||
| | | ||
| similarly named type parameter `T` defined here | ||
| | ||
help: a type parameter with a similar name exists | ||
| | ||
LL | fn trait_member<T>(val: &T, key: &T) -> bool { | ||
| ~ | ||
help: you might be missing a type parameter | ||
| | ||
LL | fn trait_member<T, K>(val: &T, key: &K) -> bool { | ||
| +++ | ||
|
||
error[E0220]: associated type `ExpressionStack` not found for `Trait` | ||
--> $DIR/sysroot-private.rs:21:31 | ||
| | ||
LL | type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>; | ||
| ^^^^^^^^^^^^^^^ there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage` | ||
|
||
error[E0425]: cannot find function `memchr2` in this scope | ||
--> $DIR/sysroot-private.rs:39:5 | ||
| | ||
LL | memchr2(b'a', b'b', buf) | ||
| ^^^^^^^ not found in this scope | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0220, E0405, E0412, E0425. | ||
For more information about an error, try `rustc --explain E0220`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Test that private dependencies of `std` that live in the sysroot do not reach through to | ||
//! diagnostics. | ||
//! | ||
//! This test would be more robust if we could patch the sysroot with an "evil" crate that | ||
//! provided known types that we control; however, this would effectively require rebuilding | ||
//! `std` (or patching crate metadata). So, this test relies on what is currently public API | ||
//! of `std`'s dependencies, but may not be robust against dependency upgrades/changes. | ||
|
||
//@ only-unix Windows sysroots seem to not expose this dependency | ||
//@ revisions: default rustc_private_enabled | ||
|
||
// Enabling `rustc_private` should `std`'s dependencies accessible, so they should show up | ||
// in diagnostics. NB: not all diagnostics are affected by this. | ||
#![cfg_attr(rustc_private_enabled, feature(rustc_private))] | ||
#![crate_type = "lib"] | ||
|
||
trait Trait { type Bar; } | ||
|
||
// Attempt to get a suggestion for `gimli::read::op::EvaluationStoreage`, which should not be | ||
// present in diagnostics (it is a dependency of the compiler). | ||
type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>; | ||
//~^ ERROR associated type `ExpressionStack` not found | ||
//~| NOTE there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage` | ||
|
||
// Attempt to get a suggestion for `hashbrown::Equivalent` | ||
trait Trait2<K>: Equivalent<K> {} | ||
//~^ ERROR cannot find trait | ||
//~| NOTE not found | ||
|
||
// Attempt to get a suggestion for `hashbrown::Equivalent::equivalent` | ||
fn trait_member<T>(val: &T, key: &K) -> bool { | ||
//~^ ERROR cannot find type `K` | ||
//~| NOTE similarly named | ||
val.equivalent(key) | ||
} | ||
|
||
// Attempt to get a suggestion for `memchr::memchr2` | ||
fn free_function(buf: &[u8]) -> Option<usize> { | ||
memchr2(b'a', b'b', buf) | ||
//~^ ERROR cannot find function | ||
//~| NOTE not found | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0405]: cannot find trait `Equivalent` in this scope | ||
--> $DIR/sysroot-private.rs:26:18 | ||
| | ||
LL | trait Trait2<K>: Equivalent<K> {} | ||
| ^^^^^^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `K` in this scope | ||
--> $DIR/sysroot-private.rs:31:35 | ||
| | ||
LL | fn trait_member<T>(val: &T, key: &K) -> bool { | ||
| - ^ | ||
| | | ||
| similarly named type parameter `T` defined here | ||
| | ||
help: a type parameter with a similar name exists | ||
| | ||
LL | fn trait_member<T>(val: &T, key: &T) -> bool { | ||
| ~ | ||
help: you might be missing a type parameter | ||
| | ||
LL | fn trait_member<T, K>(val: &T, key: &K) -> bool { | ||
| +++ | ||
|
||
error[E0220]: associated type `ExpressionStack` not found for `Trait` | ||
--> $DIR/sysroot-private.rs:21:31 | ||
| | ||
LL | type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>; | ||
| ^^^^^^^^^^^^^^^ there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage` | ||
|
||
error[E0425]: cannot find function `memchr2` in this scope | ||
--> $DIR/sysroot-private.rs:39:5 | ||
| | ||
LL | memchr2(b'a', b'b', buf) | ||
| ^^^^^^^ not found in this scope | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0220, E0405, E0412, E0425. | ||
For more information about an error, try `rustc --explain E0220`. |
Uh oh!
There was an error while loading. Please reload this page.