Skip to content

Commit 37cf6b2

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 37cf6b2

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-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:25: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:30: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:20: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:38: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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
//@ revisions: default rustc_private_enabled
10+
11+
// Enabling `rustc_private` should `std`'s dependencies accessible, so they should show up
12+
// in diagnostics. NB: not all diagnostics are affected by this.
13+
#![cfg_attr(rustc_private_enabled, feature(rustc_private))]
14+
#![crate_type = "lib"]
15+
16+
trait Trait { type Bar; }
17+
18+
// Attempt to get a suggestion for `gimli::read::op::EvaluationStoreage`, which should not be
19+
// present in diagnostics (it is a dependency of the compiler).
20+
type AssociatedTy = dyn Trait<ExpressionStack = i32, Bar = i32>;
21+
//~^ ERROR associated type `ExpressionStack` not found
22+
//~| NOTE there is an associated type `ExpressionStack` in the trait `gimli::read::op::EvaluationStorage`
23+
24+
// Attempt to get a suggestion for `hashbrown::Equivalent`
25+
trait Trait2<K>: Equivalent<K> {}
26+
//~^ ERROR cannot find trait
27+
//~| NOTE not found
28+
29+
// Attempt to get a suggestion for `hashbrown::Equivalent::equivalent`
30+
fn trait_member<T>(val: &T, key: &K) -> bool {
31+
//~^ ERROR cannot find type `K`
32+
//~| NOTE similarly named
33+
val.equivalent(key)
34+
}
35+
36+
// Attempt to get a suggestion for `memchr::memchr2`
37+
fn free_function(buf: &[u8]) -> Option<usize> {
38+
memchr2(b'a', b'b', buf)
39+
//~^ ERROR cannot find function
40+
//~| NOTE not found
41+
}
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:25: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:30: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:20: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:38: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)