Skip to content

Commit e86e5cb

Browse files
committed
Add a regression test for rust-lang#44692
Add a test for the issue resolved by removing `resolve_macro_path` Add a test making sure that extern prelude entries introduced from an opaque macro are not visible anywhere, even it that macro Fix test output after rebase
1 parent 7b74d72 commit e86e5cb

7 files changed

+128
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
use proc_macro::*;
8+
9+
#[proc_macro_derive(NoMarker)]
10+
pub fn f(input: TokenStream) -> TokenStream {
11+
if input.to_string().contains("rustc_copy_clone_marker") {
12+
panic!("found `#[rustc_copy_clone_marker]`");
13+
}
14+
TokenStream::new()
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that `#[rustc_copy_clone_marker]` is not injected when a user-defined derive shadows
2+
// a built-in derive in non-trivial scope (e.g. in a nested module).
3+
4+
// check-pass
5+
// aux-build:derive-marker-tricky.rs
6+
7+
extern crate derive_marker_tricky;
8+
9+
mod m {
10+
use derive_marker_tricky::NoMarker as Copy;
11+
12+
#[derive(Copy)]
13+
struct S;
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![feature(decl_macro)]
2+
3+
macro a() {
4+
extern crate core as my_core;
5+
mod v {
6+
// Early resolution.
7+
use my_core; //~ ERROR unresolved import `my_core`
8+
}
9+
mod u {
10+
// Late resolution.
11+
fn f() { my_core::mem::drop(0); }
12+
//~^ ERROR failed to resolve: use of undeclared type or module `my_core`
13+
}
14+
}
15+
16+
a!();
17+
18+
mod v {
19+
// Early resolution.
20+
use my_core; //~ ERROR unresolved import `my_core`
21+
}
22+
mod u {
23+
// Late resolution.
24+
fn f() { my_core::mem::drop(0); }
25+
//~^ ERROR failed to resolve: use of undeclared type or module `my_core`
26+
}
27+
28+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0432]: unresolved import `my_core`
2+
--> $DIR/extern-prelude-from-opaque-fail.rs:20:9
3+
|
4+
LL | use my_core;
5+
| ^^^^^^^
6+
| |
7+
| no `my_core` in the root
8+
| help: a similar name exists in the module: `my_core`
9+
10+
error[E0432]: unresolved import `my_core`
11+
--> $DIR/extern-prelude-from-opaque-fail.rs:7:13
12+
|
13+
LL | use my_core;
14+
| ^^^^^^^ no `my_core` in the root
15+
...
16+
LL | a!();
17+
| ----- in this macro invocation
18+
19+
error[E0433]: failed to resolve: use of undeclared type or module `my_core`
20+
--> $DIR/extern-prelude-from-opaque-fail.rs:11:18
21+
|
22+
LL | fn f() { my_core::mem::drop(0); }
23+
| ^^^^^^^ use of undeclared type or module `my_core`
24+
...
25+
LL | a!();
26+
| ----- in this macro invocation
27+
28+
error[E0433]: failed to resolve: use of undeclared type or module `my_core`
29+
--> $DIR/extern-prelude-from-opaque-fail.rs:24:14
30+
|
31+
LL | fn f() { my_core::mem::drop(0); }
32+
| ^^^^^^^ use of undeclared type or module `my_core`
33+
34+
error: aborting due to 4 previous errors
35+
36+
Some errors have detailed explanations: E0432, E0433.
37+
For more information about an error, try `rustc --explain E0432`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for the issue #44692
2+
3+
macro_rules! hang { () => {
4+
{ //~ ERROR format argument must be a string literal
5+
#[derive(Clone)]
6+
struct S;
7+
8+
""
9+
}
10+
}}
11+
12+
fn main() {
13+
format_args!(hang!());
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: format argument must be a string literal
2+
--> $DIR/derive-in-eager-expansion-hang.rs:4:5
3+
|
4+
LL | / {
5+
LL | | #[derive(Clone)]
6+
LL | | struct S;
7+
LL | |
8+
LL | | ""
9+
LL | | }
10+
| |_____^
11+
help: you might be missing a string literal to format with
12+
|
13+
LL | format_args!("{}", hang!());
14+
| ^^^^^
15+
16+
error: aborting due to previous error
17+

src/test/ui/proc-macro/macro-namespace-reserved-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ LL | #[my_macro]
8383
| ^^^^^^^^
8484
|
8585
= note: for more information, see https://github.com/rust-lang/rust/issues/29642
86-
= help: add #![feature(custom_attribute)] to the crate attributes to enable
86+
= help: add `#![feature(custom_attribute)]` to the crate attributes to enable
8787

8888
error: can't use a procedural macro from the same crate that defines it
8989
--> $DIR/macro-namespace-reserved-2.rs:39:3

0 commit comments

Comments
 (0)