Skip to content

Commit

Permalink
Add explicit_reexport_of_matching_names test case. (#72) (#102)
Browse files Browse the repository at this point in the history
* Add `explicit_reexport_of_matching_names` test case. (#72)

* Add `explicit_reexport_of_matching_names` test case.

* Fix test case.

* Conditionally enable the `explicit_reexport_of_matching_names` test.

* Avoid clippy lint.

* Reformat.
  • Loading branch information
obi1kenobi authored Mar 23, 2023
1 parent 6138d74 commit c6fc74b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ itertools = "0.10.5"
serde_json = "1.0.85"
serde = { version = "1.0.145", features = ["derive"] }
maplit = "1.0.2"
version_check = "0.9.4"
24 changes: 24 additions & 0 deletions src/indexed_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,5 +1297,29 @@ mod tests {

assert_duplicated_exported_items_match(test_crate, &expected_items);
}

#[test]
fn explicit_reexport_of_matching_names() {
if version_check::is_min_version("1.69.0").unwrap_or(true) {
let test_crate = "explicit_reexport_of_matching_names";
let expected_items = btreemap! {
"Foo" => (2, btreeset![
"explicit_reexport_of_matching_names::Bar",
"explicit_reexport_of_matching_names::Foo",
"explicit_reexport_of_matching_names::nested::Foo",
]),
};

assert_duplicated_exported_items_match(test_crate, &expected_items);
} else {
use std::io::Write;
writeln!(
std::io::stderr(),
"skipping 'explicit_reexport_of_matching_names' test due to Rust {:?}",
version_check::Version::read(),
)
.expect("write failed");
}
}
}
}
8 changes: 8 additions & 0 deletions test_crates/explicit_reexport_of_matching_names/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "explicit_reexport_of_matching_names"
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/explicit_reexport_of_matching_names/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! In Rust, type names and value names (including both `fn` and `const`) have different,
//! mutually-disjoint namespaces. It's allowed for those namespaces to have matching names.
//! When the name is used, the surrounding context determines whether it's resolved
//! to the value or to the type by that name.
//!
//! For the love of all that is good in the world,
//! please *do not* actually write code like this.
//! This is peak "do as I say, not as I do" territory.
//!
//! This package exports the following:
//! - the function `Foo`, also as `Bar` and `nested::Foo`
//! - the type `Foo`, also as `Bar` and `nested::Foo`
pub mod nested {
pub struct Foo {}

#[allow(non_snake_case)]
pub fn Foo() {}
}

pub use nested::Foo;
pub use Foo as Bar;

// Proof that both the type and the function are visible.
// Not exported.
#[allow(dead_code)]
fn proof() -> Bar {
Bar();
Bar {}
}

0 comments on commit c6fc74b

Please sign in to comment.