-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle
pub use Trait as _
cases correctly: the item is unnameable. (#…
…269)
- Loading branch information
1 parent
faaa8ab
commit 48ef50f
Showing
8 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
publish = false | ||
name = "nested_reexport_as_underscore" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! This crate does not re-export any *nameable* items. | ||
//! | ||
//! However, glob imports of this file (in the style of a prelude) | ||
//! make `Trait::method()` visible, making `().method()` valid Rust. | ||
//! | ||
//! Docs: <https://doc.rust-lang.org/reference/items/use-declarations.html#underscore-imports> | ||
mod inner { | ||
pub trait Trait { | ||
fn method(&self) {} | ||
} | ||
|
||
impl Trait for () {} | ||
} | ||
|
||
mod second { | ||
pub use super::inner::Trait as _; | ||
} | ||
|
||
pub use second::*; | ||
|
||
/// Verify that the trait is indeed visible. | ||
#[allow(dead_code)] | ||
fn proof() { | ||
().method(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
publish = false | ||
name = "overlapping_reexport_as_underscore" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! This crate re-exports only the struct `Example`. | ||
//! | ||
//! Even though `second` imports two items named `Example`, one of them is renamed to `_` | ||
//! making it unnameable. | ||
//! | ||
//! Docs: <https://doc.rust-lang.org/reference/items/use-declarations.html#underscore-imports> | ||
mod inner { | ||
pub trait Example { | ||
fn method(&self) {} | ||
} | ||
} | ||
|
||
mod inner2 { | ||
pub struct Example {} | ||
} | ||
|
||
mod second { | ||
pub use super::inner::Example as _; | ||
pub use super::inner2::Example; | ||
} | ||
|
||
pub use second::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
publish = false | ||
name = "reexport_as_underscore" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! This crate re-exports only the name `Struct`. | ||
//! | ||
//! However, glob imports of this file (in the style of a prelude) | ||
//! also make `Trait::method()` visible as well, making `().method()` valid Rust. | ||
//! | ||
//! The `_` re-export of the module `hidden` is not nameable at all, and here has no effect. | ||
//! `hidden::UnderscoreImported` is not nameable outside this crate. | ||
//! | ||
//! Docs: <https://doc.rust-lang.org/reference/items/use-declarations.html#underscore-imports> | ||
mod inner { | ||
pub trait Trait { | ||
fn method(&self) {} | ||
} | ||
|
||
impl Trait for () {} | ||
|
||
pub struct Struct {} | ||
} | ||
|
||
mod nested { | ||
pub mod hidden { | ||
pub struct UnderscoreImported; | ||
} | ||
} | ||
|
||
pub use inner::{ | ||
Struct, | ||
Trait as _, | ||
}; | ||
|
||
pub use nested::hidden as _; |