Functions introducing procedural macros reserve a slot in the macro namespace as well

This commit is contained in:
Vadim Petrochenkov 2018-07-12 13:24:59 +03:00
parent 1731f0af22
commit 431aefb2d4
11 changed files with 247 additions and 11 deletions

View file

@ -21,7 +21,7 @@ pub fn foo(input: TokenStream) -> TokenStream {
input
}
#[proc_macro_derive(A)] //~ ERROR: derive mode defined twice in this crate
#[proc_macro_derive(A)] //~ ERROR the name `A` is defined multiple times
pub fn bar(input: TokenStream) -> TokenStream {
input
}

View file

@ -0,0 +1,56 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// no-prefer-dynamic
#![feature(proc_macro)]
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::*;
#[proc_macro]
pub fn my_macro(input: TokenStream) -> TokenStream {
input
}
#[proc_macro_attribute]
pub fn my_macro_attr(input: TokenStream, _: TokenStream) -> TokenStream {
input
}
#[proc_macro_derive(MyTrait)]
pub fn my_macro_derive(input: TokenStream) -> TokenStream {
input
}
fn check_bang1() {
my_macro!(); //~ ERROR can't use a procedural macro from the same crate that defines it
}
fn check_bang2() {
my_macro_attr!(); //~ ERROR can't use a procedural macro from the same crate that defines it
}
fn check_bang3() {
MyTrait!(); //~ ERROR can't use a procedural macro from the same crate that defines it
}
#[my_macro] //~ ERROR can't use a procedural macro from the same crate that defines it
fn check_attr1() {}
#[my_macro_attr] //~ ERROR can't use a procedural macro from the same crate that defines it
fn check_attr2() {}
#[MyTrait] //~ ERROR can't use a procedural macro from the same crate that defines it
fn check_attr3() {}
#[derive(my_macro)] //~ ERROR can't use a procedural macro from the same crate that defines it
struct CheckDerive1;
#[derive(my_macro_attr)] //~ ERROR can't use a procedural macro from the same crate that defines it
struct CheckDerive2;
#[derive(MyTrait)] //~ ERROR can't use a procedural macro from the same crate that defines it
struct CheckDerive3;

View file

@ -0,0 +1,56 @@
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:35:5
|
LL | my_macro!(); //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:38:5
|
LL | my_macro_attr!(); //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:41:5
|
LL | MyTrait!(); //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:44:1
|
LL | #[my_macro] //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:46:1
|
LL | #[my_macro_attr] //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:48:1
|
LL | #[MyTrait] //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:51:10
|
LL | #[derive(my_macro)] //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:53:10
|
LL | #[derive(my_macro_attr)] //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^^^^^^^
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:55:10
|
LL | #[derive(MyTrait)] //~ ERROR can't use a procedural macro from the same crate that defines it
| ^^^^^^^
error: aborting due to 9 previous errors

View file

@ -0,0 +1,47 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// no-prefer-dynamic
#![feature(proc_macro, decl_macro)]
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::*;
#[proc_macro]
pub fn my_macro(input: TokenStream) -> TokenStream {
input
}
#[proc_macro_attribute]
pub fn my_macro_attr(input: TokenStream, _: TokenStream) -> TokenStream {
input
}
#[proc_macro_derive(MyTrait)]
pub fn my_macro_derive(input: TokenStream) -> TokenStream {
input
}
macro my_macro() {} //~ ERROR the name `my_macro` is defined multiple times
macro my_macro_attr() {} //~ ERROR the name `my_macro_attr` is defined multiple times
macro MyTrait() {} //~ ERROR the name `MyTrait` is defined multiple times
#[proc_macro_derive(SameName)]
pub fn foo(input: TokenStream) -> TokenStream {
input
}
#[proc_macro]
pub fn SameName(input: TokenStream) -> TokenStream {
//~^ ERROR the name `SameName` is defined multiple times
input
}

View file

@ -0,0 +1,47 @@
error[E0428]: the name `my_macro` is defined multiple times
--> $DIR/macro-namespace-reserved.rs:34:1
|
LL | pub fn my_macro(input: TokenStream) -> TokenStream {
| -------------------------------------------------- previous definition of the macro `my_macro` here
...
LL | macro my_macro() {} //~ ERROR the name `my_macro` is defined multiple times
| ^^^^^^^^^^^^^^^^ `my_macro` redefined here
|
= note: `my_macro` must be defined only once in the macro namespace of this module
error[E0428]: the name `my_macro_attr` is defined multiple times
--> $DIR/macro-namespace-reserved.rs:35:1
|
LL | pub fn my_macro_attr(input: TokenStream, _: TokenStream) -> TokenStream {
| ----------------------------------------------------------------------- previous definition of the macro `my_macro_attr` here
...
LL | macro my_macro_attr() {} //~ ERROR the name `my_macro_attr` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^^^ `my_macro_attr` redefined here
|
= note: `my_macro_attr` must be defined only once in the macro namespace of this module
error[E0428]: the name `MyTrait` is defined multiple times
--> $DIR/macro-namespace-reserved.rs:36:1
|
LL | #[proc_macro_derive(MyTrait)]
| ------- previous definition of the macro `MyTrait` here
...
LL | macro MyTrait() {} //~ ERROR the name `MyTrait` is defined multiple times
| ^^^^^^^^^^^^^^^ `MyTrait` redefined here
|
= note: `MyTrait` must be defined only once in the macro namespace of this module
error[E0428]: the name `SameName` is defined multiple times
--> $DIR/macro-namespace-reserved.rs:44:1
|
LL | #[proc_macro_derive(SameName)]
| -------- previous definition of the macro `SameName` here
...
LL | pub fn SameName(input: TokenStream) -> TokenStream {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SameName` redefined here
|
= note: `SameName` must be defined only once in the macro namespace of this module
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0428`.