Skip to content

Commit 8915c79

Browse files
committed
Add some tests for trimmed paths in diagnostics
1 parent c90bcb9 commit 8915c79

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ edition: 2024
2+
3+
pub struct ActuallyPub {}
4+
#[doc(hidden)]
5+
pub struct DocHidden {}
6+
7+
pub mod pub_mod {
8+
pub struct ActuallyPubInPubMod {}
9+
#[doc(hidden)]
10+
pub struct DocHiddenInPubMod {}
11+
}
12+
13+
#[doc(hidden)]
14+
pub mod hidden_mod {
15+
pub struct ActuallyPubInHiddenMod {}
16+
#[doc(hidden)]
17+
pub struct DocHiddenInHiddenMod {}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ edition: 2024
2+
3+
// Test that the `#[doc(hidden)]` module `core::unicode` module does not
4+
// disqualify another item named `unicode` from path trimming in diagnostics.
5+
6+
use core::marker::PhantomData;
7+
8+
mod inner {
9+
#[expect(non_camel_case_types)]
10+
pub(crate) enum unicode {}
11+
}
12+
13+
fn main() {
14+
let PhantomData::<(inner::unicode, u32)> = PhantomData::<(u32, inner::unicode)>;
15+
//~^ ERROR mismatched types [E0308]
16+
//~| NOTE expected `PhantomData<(u32, unicode)>`, found `PhantomData<(unicode, u32)>`
17+
//~| NOTE this expression has type `PhantomData<(u32, inner::unicode)>`
18+
//~| NOTE expected struct `PhantomData<(u32, inner::unicode)>`
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/core-unicode.rs:14:9
3+
|
4+
LL | let PhantomData::<(inner::unicode, u32)> = PhantomData::<(u32, inner::unicode)>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------------------------------------ this expression has type `PhantomData<(u32, inner::unicode)>`
6+
| |
7+
| expected `PhantomData<(u32, unicode)>`, found `PhantomData<(unicode, u32)>`
8+
|
9+
= note: expected struct `PhantomData<(u32, inner::unicode)>`
10+
found struct `PhantomData<(inner::unicode, u32)>`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//@ edition: 2024
2+
//@ aux-crate: helper=doc_hidden_helper.rs
3+
4+
// Test that `#[doc(hidden)]` items in other crates do not disqualify another
5+
// item with the same name from path trimming in diagnostics.
6+
7+
// Declare several modules and types whose short names match those in the aux crate.
8+
//
9+
// Of these, only `ActuallyPub` and `ActuallyPubInPubMod` should be disqualified
10+
// from path trimming, because the other names only collide with `#[doc(hidden)]`
11+
// names.
12+
mod local {
13+
pub(crate) struct ActuallyPub {}
14+
pub(crate) struct DocHidden {}
15+
16+
pub(crate) mod pub_mod {
17+
pub(crate) struct ActuallyPubInPubMod {}
18+
pub(crate) struct DocHiddenInPubMod {}
19+
}
20+
21+
pub(crate) mod hidden_mod {
22+
pub(crate) struct ActuallyPubInHiddenMod {}
23+
pub(crate) struct DocHiddenInHiddenMod {}
24+
}
25+
}
26+
27+
fn main() {
28+
uses_local();
29+
uses_helper();
30+
}
31+
32+
fn uses_local() {
33+
use local::{ActuallyPub, DocHidden};
34+
use local::pub_mod::{ActuallyPubInPubMod, DocHiddenInPubMod};
35+
use local::hidden_mod::{ActuallyPubInHiddenMod, DocHiddenInHiddenMod};
36+
37+
let _: (
38+
//~^ NOTE expected due to this
39+
ActuallyPub,
40+
DocHidden,
41+
ActuallyPubInPubMod,
42+
DocHiddenInPubMod,
43+
ActuallyPubInHiddenMod,
44+
DocHiddenInHiddenMod,
45+
) = 3u32;
46+
//~^ ERROR mismatched types [E0308]
47+
//~| NOTE expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
48+
//~| NOTE expected tuple `(local::ActuallyPub, local::DocHidden, local::pub_mod::ActuallyPubInPubMod, local::pub_mod::DocHiddenInPubMod, local::hidden_mod::ActuallyPubInHiddenMod, local::hidden_mod::DocHiddenInHiddenMod)`
49+
}
50+
51+
fn uses_helper() {
52+
use helper::{ActuallyPub, DocHidden};
53+
use helper::pub_mod::{ActuallyPubInPubMod, DocHiddenInPubMod};
54+
use helper::hidden_mod::{ActuallyPubInHiddenMod, DocHiddenInHiddenMod};
55+
56+
let _: (
57+
//~^ NOTE expected due to this
58+
ActuallyPub,
59+
DocHidden,
60+
ActuallyPubInPubMod,
61+
DocHiddenInPubMod,
62+
ActuallyPubInHiddenMod,
63+
DocHiddenInHiddenMod,
64+
) = 3u32;
65+
//~^ ERROR mismatched types [E0308]
66+
//~| NOTE expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
67+
//~| NOTE expected tuple `(doc_hidden_helper::ActuallyPub, doc_hidden_helper::DocHidden, doc_hidden_helper::pub_mod::ActuallyPubInPubMod, doc_hidden_helper::pub_mod::DocHiddenInPubMod, doc_hidden_helper::hidden_mod::ActuallyPubInHiddenMod, doc_hidden_helper::hidden_mod::DocHiddenInHiddenMod)`
68+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/doc-hidden.rs:45:9
3+
|
4+
LL | let _: (
5+
| ____________-
6+
LL | |
7+
LL | | ActuallyPub,
8+
LL | | DocHidden,
9+
... |
10+
LL | | DocHiddenInHiddenMod,
11+
LL | | ) = 3u32;
12+
| | - ^^^^ expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
13+
| |_____|
14+
| expected due to this
15+
|
16+
= note: expected tuple `(local::ActuallyPub, local::DocHidden, local::pub_mod::ActuallyPubInPubMod, local::pub_mod::DocHiddenInPubMod, local::hidden_mod::ActuallyPubInHiddenMod, local::hidden_mod::DocHiddenInHiddenMod)`
17+
found type `u32`
18+
19+
error[E0308]: mismatched types
20+
--> $DIR/doc-hidden.rs:64:9
21+
|
22+
LL | let _: (
23+
| ____________-
24+
LL | |
25+
LL | | ActuallyPub,
26+
LL | | DocHidden,
27+
... |
28+
LL | | DocHiddenInHiddenMod,
29+
LL | | ) = 3u32;
30+
| | - ^^^^ expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
31+
| |_____|
32+
| expected due to this
33+
|
34+
= note: expected tuple `(doc_hidden_helper::ActuallyPub, doc_hidden_helper::DocHidden, doc_hidden_helper::pub_mod::ActuallyPubInPubMod, doc_hidden_helper::pub_mod::DocHiddenInPubMod, doc_hidden_helper::hidden_mod::ActuallyPubInHiddenMod, doc_hidden_helper::hidden_mod::DocHiddenInHiddenMod)`
35+
found type `u32`
36+
37+
error: aborting due to 2 previous errors
38+
39+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)