forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#135278 - tgross35:ignore-std-dep-crates, r=<try>
Exclude dependencies of `std` for diagnostics Currently crates in the sysroot can show up in diagnostic suggestions, such as in rust-lang#135232. To prevent this, duplicate `all_traits` into `visible_traits` which only shows traits in non-private crates. Setting `#![feature(rustc_private)]` overrides this and makes items in private crates visible as well, since `rustc_private` enables use of `std`'s private dependencies. This may be reviewed per-commit. Fixes: rust-lang#135232
- Loading branch information
Showing
11 changed files
with
182 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:25: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:30: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 `Buf` not found for `Trait` | ||
--> $DIR/sysroot-private.rs:20:31 | ||
| | ||
LL | type AssociatedTy = dyn Trait<Buf = i32, Bar = i32>; | ||
| ^^^ help: `Trait` has the following associated type: `Bar` | ||
|
||
error[E0425]: cannot find function `memchr2` in this scope | ||
--> $DIR/sysroot-private.rs:38: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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! 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. | ||
//@ 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 `addr2line::LookupContinuation`, which has member `Buf` | ||
// Note that the suggestion only happens when `rustc_private` is enabled. | ||
type AssociatedTy = dyn Trait<Buf = i32, Bar = i32>; | ||
//~^ ERROR associated type `Buf` not found | ||
//[rustc_private_enabled]~| NOTE there is an associated type `Buf` in the trait `addr2line::lookup::LookupContinuation` | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:25: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:30: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 `Buf` not found for `Trait` | ||
--> $DIR/sysroot-private.rs:20:31 | ||
| | ||
LL | type AssociatedTy = dyn Trait<Buf = i32, Bar = i32>; | ||
| ^^^ there is an associated type `Buf` in the trait `addr2line::lookup::LookupContinuation` | ||
|
||
error[E0425]: cannot find function `memchr2` in this scope | ||
--> $DIR/sysroot-private.rs:38: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`. |