Skip to content

Commit 941416a

Browse files
Add test for idents incl. raw idents
1 parent 9cf99a9 commit 941416a

File tree

2 files changed

+25
-1
lines changed
  • crates

2 files changed

+25
-1
lines changed

crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ fn test_fn_like_mk_literals() {
8484
);
8585
}
8686

87+
#[test]
88+
fn test_fn_like_mk_idents() {
89+
// FIXME: this test is wrong: raw should be 'r#raw' but ABIs 1.64 and below
90+
// simply ignore `is_raw` when implementing the `Ident` interface.
91+
assert_expand(
92+
"fn_like_mk_idents",
93+
r#""#,
94+
expect![[r#"
95+
SUBTREE $
96+
IDENT standard 4294967295
97+
IDENT raw 4294967295"#]],
98+
);
99+
}
100+
87101
#[test]
88102
fn test_fn_like_macro_clone_literals() {
89103
assert_expand(
@@ -134,6 +148,7 @@ fn list_test_macros() {
134148
fn_like_error [FuncLike]
135149
fn_like_clone_tokens [FuncLike]
136150
fn_like_mk_literals [FuncLike]
151+
fn_like_mk_idents [FuncLike]
137152
attr_noop [Attr]
138153
attr_panic [Attr]
139154
attr_error [Attr]

crates/proc-macro-test/imp/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
44

5-
use proc_macro::{Group, Ident, Literal, Punct, TokenStream, TokenTree};
5+
use proc_macro::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};
66

77
#[proc_macro]
88
pub fn fn_like_noop(args: TokenStream) -> TokenStream {
@@ -40,6 +40,15 @@ pub fn fn_like_mk_literals(_args: TokenStream) -> TokenStream {
4040
TokenStream::from_iter(trees)
4141
}
4242

43+
#[proc_macro]
44+
pub fn fn_like_mk_idents(_args: TokenStream) -> TokenStream {
45+
let trees: Vec<TokenTree> = vec![
46+
TokenTree::from(Ident::new("standard", Span::call_site())),
47+
TokenTree::from(Ident::new_raw("raw", Span::call_site())),
48+
];
49+
TokenStream::from_iter(trees)
50+
}
51+
4352
#[proc_macro_attribute]
4453
pub fn attr_noop(_args: TokenStream, item: TokenStream) -> TokenStream {
4554
item

0 commit comments

Comments
 (0)