Skip to content

Commit 90a8ea8

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 90a8ea8

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-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:24: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:29: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 `Buf` not found for `Trait`
25+
--> $DIR/sysroot-private.rs:19:31
26+
|
27+
LL | type AssociatedTy = dyn Trait<Buf = i32, Bar = i32>;
28+
| ^^^ there is an associated type `Buf` in the trait `addr2line::lookup::LookupContinuation`
29+
30+
error[E0425]: cannot find function `memchr2` in this scope
31+
--> $DIR/sysroot-private.rs:37: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/std/sysroot-private.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 `addr2line::LookupContinuation`, which has member `Buf`
19+
type AssociatedTy = dyn Trait<Buf = i32, Bar = i32>;
20+
//~^ ERROR associated type `Buf` not found
21+
//~| NOTE there is an associated type `Buf` in the trait `addr2line::lookup::LookupContinuation`
22+
23+
// Attempt to get a suggestion for `hashbrown::Equivalent`
24+
trait Trait2<K>: Equivalent<K> {}
25+
//~^ ERROR cannot find trait
26+
//~| NOTE not found
27+
28+
// Attempt to get a suggestion for `hashbrown::Equivalent::equivalent`
29+
fn trait_member<T>(val: &T, key: &K) -> bool {
30+
//~^ ERROR cannot find type `K`
31+
//~| NOTE similarly named
32+
val.equivalent(key)
33+
}
34+
35+
// Attempt to get a suggestion for `memchr::memchr2`
36+
fn free_function(buf: &[u8]) -> Option<usize> {
37+
memchr2(b'a', b'b', buf)
38+
//~^ ERROR cannot find function
39+
//~| NOTE not found
40+
}
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:24: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:29: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 `Buf` not found for `Trait`
25+
--> $DIR/sysroot-private.rs:19:31
26+
|
27+
LL | type AssociatedTy = dyn Trait<Buf = i32, Bar = i32>;
28+
| ^^^ there is an associated type `Buf` in the trait `addr2line::lookup::LookupContinuation`
29+
30+
error[E0425]: cannot find function `memchr2` in this scope
31+
--> $DIR/sysroot-private.rs:37: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)