Skip to content

Commit 4896a65

Browse files
committed
Add a UI test for stdlib-private dependencies
Introduce a test that shows stdlib-private dependencies leaking into diagnostics. This is resolved by a later commit.
1 parent 627513a commit 4896a65

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0405]: cannot find trait `Equivalent` in this scope
2+
--> $DIR/sysroot-private.rs:26:18
3+
|
4+
LL | trait Trait2<K>: Equivalent<K> {}
5+
| ^^^^^^^^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `K` in this scope
8+
--> $DIR/sysroot-private.rs:31:35
9+
|
10+
LL | fn trait_member<T>(val: &T, key: &K) -> bool {
11+
| - ^
12+
| |
13+
| similarly named type parameter `T` defined here
14+
|
15+
help: a type parameter with a similar name exists
16+
|
17+
LL | fn trait_member<T>(val: &T, key: &T) -> bool {
18+
| ~
19+
help: you might be missing a type parameter
20+
|
21+
LL | fn trait_member<T, K>(val: &T, key: &K) -> bool {
22+
| +++
23+
24+
error[E0220]: associated type `ExpressionStack` not found for `Trait`
25+
--> $DIR/sysroot-private.rs:21:31
26+
|
27+
LL | type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>;
28+
| ^^^^^^^^^^^^^^^ there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage`
29+
30+
error[E0425]: cannot find function `memchr2` in this scope
31+
--> $DIR/sysroot-private.rs:39:5
32+
|
33+
LL | memchr2(b'a', b'b', buf)
34+
| ^^^^^^^ not found in this scope
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0220, E0405, E0412, E0425.
39+
For more information about an error, try `rustc --explain E0220`.

tests/ui/privacy/sysroot-private.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! Test that private dependencies of `std` that live in the sysroot do not reach through to
2+
//! diagnostics.
3+
//!
4+
//! This test would be more robust if we could patch the sysroot with an "evil" crate that
5+
//! provided known types that we control; however, this would effectively require rebuilding
6+
//! `std` (or patching crate metadata). So, this test relies on what is currently public API
7+
//! of `std`'s dependencies, but may not be robust against dependency upgrades/changes.
8+
9+
//@ only-unix Windows sysroots seem to not expose this dependency
10+
//@ revisions: default rustc_private_enabled
11+
12+
// Enabling `rustc_private` should `std`'s dependencies accessible, so they should show up
13+
// in diagnostics. NB: not all diagnostics are affected by this.
14+
#![cfg_attr(rustc_private_enabled, feature(rustc_private))]
15+
#![crate_type = "lib"]
16+
17+
trait Trait { type Bar; }
18+
19+
// Attempt to get a suggestion for `gimli::read::op::EvaluationStoreage`, which should not be
20+
// present in diagnostics (it is a dependency of the compiler).
21+
type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>;
22+
//~^ ERROR associated type `ExpressionStack` not found
23+
//~| NOTE there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage`
24+
25+
// Attempt to get a suggestion for `hashbrown::Equivalent`
26+
trait Trait2<K>: Equivalent<K> {}
27+
//~^ ERROR cannot find trait
28+
//~| NOTE not found
29+
30+
// Attempt to get a suggestion for `hashbrown::Equivalent::equivalent`
31+
fn trait_member<T>(val: &T, key: &K) -> bool {
32+
//~^ ERROR cannot find type `K`
33+
//~| NOTE similarly named
34+
val.equivalent(key)
35+
}
36+
37+
// Attempt to get a suggestion for `memchr::memchr2`
38+
fn free_function(buf: &[u8]) -> Option<usize> {
39+
memchr2(b'a', b'b', buf)
40+
//~^ ERROR cannot find function
41+
//~| NOTE not found
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0405]: cannot find trait `Equivalent` in this scope
2+
--> $DIR/sysroot-private.rs:26:18
3+
|
4+
LL | trait Trait2<K>: Equivalent<K> {}
5+
| ^^^^^^^^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `K` in this scope
8+
--> $DIR/sysroot-private.rs:31:35
9+
|
10+
LL | fn trait_member<T>(val: &T, key: &K) -> bool {
11+
| - ^
12+
| |
13+
| similarly named type parameter `T` defined here
14+
|
15+
help: a type parameter with a similar name exists
16+
|
17+
LL | fn trait_member<T>(val: &T, key: &T) -> bool {
18+
| ~
19+
help: you might be missing a type parameter
20+
|
21+
LL | fn trait_member<T, K>(val: &T, key: &K) -> bool {
22+
| +++
23+
24+
error[E0220]: associated type `ExpressionStack` not found for `Trait`
25+
--> $DIR/sysroot-private.rs:21:31
26+
|
27+
LL | type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>;
28+
| ^^^^^^^^^^^^^^^ there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage`
29+
30+
error[E0425]: cannot find function `memchr2` in this scope
31+
--> $DIR/sysroot-private.rs:39:5
32+
|
33+
LL | memchr2(b'a', b'b', buf)
34+
| ^^^^^^^ not found in this scope
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0220, E0405, E0412, E0425.
39+
For more information about an error, try `rustc --explain E0220`.

0 commit comments

Comments
 (0)