Skip to content

Commit 15e821a

Browse files
committed
Auto merge of #150083 - Enselic:same-crate-same-macro, r=Kivooeo
tests/run-make-cargo/same-crate-name-and-macro-name: New regression test Closes #71259 which just **E-needs-test**. See #71259 (comment) for a good description of what we should test (which we do in this PR). The project we add fails with an old nightly without the fix: ```console $ cargo +nightly-2020-03-10 run Compiling consumer v0.1.0 (/home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/consumer) Finished dev [unoptimized + debuginfo] target(s) in 0.14s Running `target/debug/consumer` thread 'main' panicked at 'assertion failed: `(left == right)` left: `"version 1"`, right: `"version 2"`', src/main.rs:6:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` and passes with a recent toolchain: ```console $ cargo run warning: /home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/consumer/Cargo.toml: no edition set: defaulting to the 2015 edition while the latest is 2024 warning: /home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/mylib_v1/Cargo.toml: no edition set: defaulting to the 2015 edition while the latest is 2024 warning: /home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/mylib_v2/Cargo.toml: no edition set: defaulting to the 2015 edition while the latest is 2024 Compiling mylib v2.0.0 (/home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/mylib_v2) Compiling mylib v1.0.0 (/home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/mylib_v1) Compiling consumer v0.1.0 (/home/martin/src/rust-same-crate-same-macro/tests/run-make-cargo/same-crate-name-and-macro-name/consumer) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s Running `target/debug/consumer` ``` in other words, the test tests what it should and will catch regressions.
2 parents ed0006a + 60b616d commit 15e821a

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "consumer"
3+
version = "0.1.0"
4+
5+
[dependencies]
6+
mylib_v1 = { path = "../mylib_v1", package = "mylib" }
7+
mylib_v2 = { path = "../mylib_v2", package = "mylib" }
8+
9+
# Avoid interference with root workspace when casually testing
10+
[workspace]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let v1 = mylib_v1::my_macro!();
3+
assert_eq!(v1, "version 1");
4+
5+
let v2 = mylib_v2::my_macro!();
6+
assert_eq!(v2, "version 2");
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "mylib"
3+
version = "1.0.0"
4+
5+
# Avoid interference with root workspace when casually testing
6+
[workspace]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_export]
2+
macro_rules! my_macro {
3+
() => {
4+
"version 1"
5+
};
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "mylib"
3+
version = "2.0.0"
4+
5+
# Avoid interference with root workspace when casually testing
6+
[workspace]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_export]
2+
macro_rules! my_macro {
3+
() => {
4+
"version 2"
5+
};
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Regression test for
2+
//! <https://github.com/rust-lang/rust/issues/71259#issuecomment-615879925>
3+
//! (that particular comment describes the issue well).
4+
//!
5+
//! We test that two library crates with the same name can export macros with
6+
//! the same name without causing interference when both are used in another
7+
//! crate.
8+
9+
use run_make_support::cargo;
10+
11+
fn main() {
12+
cargo().current_dir("consumer").arg("run").run();
13+
}

0 commit comments

Comments
 (0)