Skip to content

Commit

Permalink
Add a regression test for #44692
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petrochenkov committed Jul 10, 2019
1 parent 7b74d72 commit e86e5cb
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/test/ui/derives/auxiliary/derive-marker-tricky.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// force-host
// no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::*;

#[proc_macro_derive(NoMarker)]
pub fn f(input: TokenStream) -> TokenStream {
if input.to_string().contains("rustc_copy_clone_marker") {
panic!("found `#[rustc_copy_clone_marker]`");
}
TokenStream::new()
}
16 changes: 16 additions & 0 deletions src/test/ui/derives/derive-marker-tricky.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test that `#[rustc_copy_clone_marker]` is not injected when a user-defined derive shadows
// a built-in derive in non-trivial scope (e.g. in a nested module).

// check-pass
// aux-build:derive-marker-tricky.rs

extern crate derive_marker_tricky;

mod m {
use derive_marker_tricky::NoMarker as Copy;

#[derive(Copy)]
struct S;
}

fn main() {}
28 changes: 28 additions & 0 deletions src/test/ui/hygiene/extern-prelude-from-opaque-fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![feature(decl_macro)]

macro a() {
extern crate core as my_core;
mod v {
// Early resolution.
use my_core; //~ ERROR unresolved import `my_core`
}
mod u {
// Late resolution.
fn f() { my_core::mem::drop(0); }
//~^ ERROR failed to resolve: use of undeclared type or module `my_core`
}
}

a!();

mod v {
// Early resolution.
use my_core; //~ ERROR unresolved import `my_core`
}
mod u {
// Late resolution.
fn f() { my_core::mem::drop(0); }
//~^ ERROR failed to resolve: use of undeclared type or module `my_core`
}

fn main() {}
37 changes: 37 additions & 0 deletions src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0432]: unresolved import `my_core`
--> $DIR/extern-prelude-from-opaque-fail.rs:20:9
|
LL | use my_core;
| ^^^^^^^
| |
| no `my_core` in the root
| help: a similar name exists in the module: `my_core`

error[E0432]: unresolved import `my_core`
--> $DIR/extern-prelude-from-opaque-fail.rs:7:13
|
LL | use my_core;
| ^^^^^^^ no `my_core` in the root
...
LL | a!();
| ----- in this macro invocation

error[E0433]: failed to resolve: use of undeclared type or module `my_core`
--> $DIR/extern-prelude-from-opaque-fail.rs:11:18
|
LL | fn f() { my_core::mem::drop(0); }
| ^^^^^^^ use of undeclared type or module `my_core`
...
LL | a!();
| ----- in this macro invocation

error[E0433]: failed to resolve: use of undeclared type or module `my_core`
--> $DIR/extern-prelude-from-opaque-fail.rs:24:14
|
LL | fn f() { my_core::mem::drop(0); }
| ^^^^^^^ use of undeclared type or module `my_core`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
14 changes: 14 additions & 0 deletions src/test/ui/macros/derive-in-eager-expansion-hang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for the issue #44692

macro_rules! hang { () => {
{ //~ ERROR format argument must be a string literal
#[derive(Clone)]
struct S;

""
}
}}

fn main() {
format_args!(hang!());
}
17 changes: 17 additions & 0 deletions src/test/ui/macros/derive-in-eager-expansion-hang.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: format argument must be a string literal
--> $DIR/derive-in-eager-expansion-hang.rs:4:5
|
LL | / {
LL | | #[derive(Clone)]
LL | | struct S;
LL | |
LL | | ""
LL | | }
| |_____^
help: you might be missing a string literal to format with
|
LL | format_args!("{}", hang!());
| ^^^^^

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/proc-macro/macro-namespace-reserved-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ LL | #[my_macro]
| ^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/29642
= help: add #![feature(custom_attribute)] to the crate attributes to enable
= help: add `#![feature(custom_attribute)]` to the crate attributes to enable

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

0 comments on commit e86e5cb

Please sign in to comment.