Skip to content

Commit

Permalink
Handle pub use Trait as _ cases correctly: the item is unnameable.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Sep 26, 2023
1 parent 9e3fd5c commit f34b7f0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test_crates/nested_reexport_as_underscore/Cargo.toml
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]
22 changes: 22 additions & 0 deletions test_crates/nested_reexport_as_underscore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! 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 () {}

pub struct Struct {}
}

mod second {
pub use Trait as _;
}

pub use second::*;
9 changes: 9 additions & 0 deletions test_crates/reexport_as_underscore/Cargo.toml
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]
30 changes: 30 additions & 0 deletions test_crates/reexport_as_underscore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! 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 hidden {
pub struct UnderscoreImported;
}

pub use inner::{
Struct,
Trait as _,
};

pub use hidden as _;

0 comments on commit f34b7f0

Please sign in to comment.