Add some tests for trimmed paths in diagnostics

This commit is contained in:
Zalathar 2025-11-05 20:40:15 +11:00
parent 9b37157ece
commit 3327a92b43
5 changed files with 158 additions and 0 deletions

View file

@ -0,0 +1,18 @@
//@ edition: 2024
pub struct ActuallyPub {}
#[doc(hidden)]
pub struct DocHidden {}
pub mod pub_mod {
pub struct ActuallyPubInPubMod {}
#[doc(hidden)]
pub struct DocHiddenInPubMod {}
}
#[doc(hidden)]
pub mod hidden_mod {
pub struct ActuallyPubInHiddenMod {}
#[doc(hidden)]
pub struct DocHiddenInHiddenMod {}
}

View file

@ -0,0 +1,19 @@
//@ edition: 2024
// Test that the `#[doc(hidden)]` module `core::unicode` module does not
// disqualify another item named `unicode` from path trimming in diagnostics.
use core::marker::PhantomData;
mod inner {
#[expect(non_camel_case_types)]
pub(crate) enum unicode {}
}
fn main() {
let PhantomData::<(inner::unicode, u32)> = PhantomData::<(u32, inner::unicode)>;
//~^ ERROR mismatched types [E0308]
//~| NOTE expected `PhantomData<(u32, unicode)>`, found `PhantomData<(unicode, u32)>`
//~| NOTE this expression has type `PhantomData<(u32, inner::unicode)>`
//~| NOTE expected struct `PhantomData<(u32, inner::unicode)>`
}

View file

@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/core-unicode.rs:14:9
|
LL | let PhantomData::<(inner::unicode, u32)> = PhantomData::<(u32, inner::unicode)>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------------------------------------ this expression has type `PhantomData<(u32, inner::unicode)>`
| |
| expected `PhantomData<(u32, unicode)>`, found `PhantomData<(unicode, u32)>`
|
= note: expected struct `PhantomData<(u32, inner::unicode)>`
found struct `PhantomData<(inner::unicode, u32)>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.

View file

@ -0,0 +1,68 @@
//@ edition: 2024
//@ aux-crate: helper=doc_hidden_helper.rs
// Test that `#[doc(hidden)]` items in other crates do not disqualify another
// item with the same name from path trimming in diagnostics.
// Declare several modules and types whose short names match those in the aux crate.
//
// Of these, only `ActuallyPub` and `ActuallyPubInPubMod` should be disqualified
// from path trimming, because the other names only collide with `#[doc(hidden)]`
// names.
mod local {
pub(crate) struct ActuallyPub {}
pub(crate) struct DocHidden {}
pub(crate) mod pub_mod {
pub(crate) struct ActuallyPubInPubMod {}
pub(crate) struct DocHiddenInPubMod {}
}
pub(crate) mod hidden_mod {
pub(crate) struct ActuallyPubInHiddenMod {}
pub(crate) struct DocHiddenInHiddenMod {}
}
}
fn main() {
uses_local();
uses_helper();
}
fn uses_local() {
use local::{ActuallyPub, DocHidden};
use local::pub_mod::{ActuallyPubInPubMod, DocHiddenInPubMod};
use local::hidden_mod::{ActuallyPubInHiddenMod, DocHiddenInHiddenMod};
let _: (
//~^ NOTE expected due to this
ActuallyPub,
DocHidden,
ActuallyPubInPubMod,
DocHiddenInPubMod,
ActuallyPubInHiddenMod,
DocHiddenInHiddenMod,
) = 3u32;
//~^ ERROR mismatched types [E0308]
//~| NOTE expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
//~| NOTE expected tuple `(local::ActuallyPub, local::DocHidden, local::pub_mod::ActuallyPubInPubMod, local::pub_mod::DocHiddenInPubMod, local::hidden_mod::ActuallyPubInHiddenMod, local::hidden_mod::DocHiddenInHiddenMod)`
}
fn uses_helper() {
use helper::{ActuallyPub, DocHidden};
use helper::pub_mod::{ActuallyPubInPubMod, DocHiddenInPubMod};
use helper::hidden_mod::{ActuallyPubInHiddenMod, DocHiddenInHiddenMod};
let _: (
//~^ NOTE expected due to this
ActuallyPub,
DocHidden,
ActuallyPubInPubMod,
DocHiddenInPubMod,
ActuallyPubInHiddenMod,
DocHiddenInHiddenMod,
) = 3u32;
//~^ ERROR mismatched types [E0308]
//~| NOTE expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
//~| 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)`
}

View file

@ -0,0 +1,39 @@
error[E0308]: mismatched types
--> $DIR/doc-hidden.rs:45:9
|
LL | let _: (
| ____________-
LL | |
LL | | ActuallyPub,
LL | | DocHidden,
... |
LL | | DocHiddenInHiddenMod,
LL | | ) = 3u32;
| | - ^^^^ expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
| |_____|
| expected due to this
|
= note: expected tuple `(local::ActuallyPub, local::DocHidden, local::pub_mod::ActuallyPubInPubMod, local::pub_mod::DocHiddenInPubMod, local::hidden_mod::ActuallyPubInHiddenMod, local::hidden_mod::DocHiddenInHiddenMod)`
found type `u32`
error[E0308]: mismatched types
--> $DIR/doc-hidden.rs:64:9
|
LL | let _: (
| ____________-
LL | |
LL | | ActuallyPub,
LL | | DocHidden,
... |
LL | | DocHiddenInHiddenMod,
LL | | ) = 3u32;
| | - ^^^^ expected `(ActuallyPub, ..., ..., ..., ..., ...)`, found `u32`
| |_____|
| expected due to this
|
= 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)`
found type `u32`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.