-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow renaming macro attributes (#1891)
Signed-off-by: maciektr <[email protected]> Co-authored-by: Rémy Baranx <[email protected]> Co-authored-by: Maksim Zdobnikau <[email protected]>
- Loading branch information
1 parent
ce86046
commit 56999bb
Showing
12 changed files
with
242 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use cairo_lang_macro::{attribute_macro, ProcMacroResult, TokenStream}; | ||
|
||
#[attribute_macro(unsupported_key = "some::path")] | ||
fn t1(_a: TokenStream, _b: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: only `parent` argument is supported | ||
--> tests/args/args_01.rs:3:35 | ||
| | ||
3 | #[attribute_macro(unsupported_key = "some::path")] | ||
| ^ | ||
|
||
warning: unused imports: `ProcMacroResult` and `TokenStream` | ||
--> tests/args/args_01.rs:1:41 | ||
| | ||
1 | use cairo_lang_macro::{attribute_macro, ProcMacroResult, TokenStream}; | ||
| ^^^^^^^^^^^^^^^ ^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_imports)]` on by default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use cairo_lang_macro::{attribute_macro, ProcMacroResult, TokenStream}; | ||
|
||
#[attribute_macro(parent = "a-b")] | ||
fn t1(_a: TokenStream, _b: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: `parent` argument is not a valid path | ||
--> tests/args/args_02.rs:3:28 | ||
| | ||
3 | #[attribute_macro(parent = "a-b")] | ||
| ^^^^^ | ||
|
||
warning: unused imports: `ProcMacroResult` and `TokenStream` | ||
--> tests/args/args_02.rs:1:41 | ||
| | ||
1 | use cairo_lang_macro::{attribute_macro, ProcMacroResult, TokenStream}; | ||
| ^^^^^^^^^^^^^^^ ^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_imports)]` on by default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use cairo_lang_macro::{inline_macro, ProcMacroResult, TokenStream, MACRO_DEFINITIONS_SLICE}; | ||
|
||
#[inline_macro(parent = "parent")] | ||
fn t1(_a: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: inline macro cannot use `parent` argument | ||
--> tests/args/args_03.rs:3:25 | ||
| | ||
3 | #[inline_macro(parent = "parent")] | ||
| ^^^^^^^^ | ||
|
||
warning: unused imports: `MACRO_DEFINITIONS_SLICE`, `ProcMacroResult`, and `TokenStream` | ||
--> tests/args/args_03.rs:1:38 | ||
| | ||
1 | use cairo_lang_macro::{inline_macro, ProcMacroResult, TokenStream, MACRO_DEFINITIONS_SLICE}; | ||
| ^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_imports)]` on by default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use cairo_lang_macro::{attribute_macro, ProcMacroResult, TokenStream, MACRO_DEFINITIONS_SLICE}; | ||
use cairo_lang_macro_attributes::derive_macro; | ||
|
||
#[attribute_macro] | ||
fn t1(_a: TokenStream, _b: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
#[attribute_macro(parent = "parent_1::module")] | ||
fn t2(_a: TokenStream, _b: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
#[attribute_macro(parent = "::parent")] | ||
fn t3(_a: TokenStream, _b: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
#[derive_macro(parent = "parent")] | ||
fn t4(_a: TokenStream) -> ProcMacroResult { | ||
ProcMacroResult::new(TokenStream::empty()) | ||
} | ||
|
||
#[test] | ||
fn happy_path() { | ||
let list: Vec<String> = MACRO_DEFINITIONS_SLICE | ||
.iter() | ||
.map(|m| m.name.to_string()) | ||
.collect(); | ||
assert_eq!( | ||
list, | ||
vec!["t1", "parent_1::module::t2", "::parent::t3", "parent::t4"] | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_parsing_errors() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/args/args_*.rs"); | ||
} |