Skip to content

Commit f504294

Browse files
Add proc-macro-srv integration test that clones literals
This exercises some of the upcoming proc_macro bridge changes. It should also pass for all supported ABIs, with the older-style bridge.
1 parent bd4439f commit f504294

File tree

2 files changed

+30
-4
lines changed
  • crates

2 files changed

+30
-4
lines changed

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn test_derive_error() {
2727
}
2828

2929
#[test]
30-
fn test_fn_like_macro() {
30+
fn test_fn_like_macro_noop() {
3131
assert_expand(
3232
"fn_like_noop",
3333
r#"ident, 0, 1, []"#,
@@ -44,7 +44,7 @@ fn test_fn_like_macro() {
4444
}
4545

4646
#[test]
47-
fn test_fn_like_macro2() {
47+
fn test_fn_like_macro_clone_ident_subtree() {
4848
assert_expand(
4949
"fn_like_clone_tokens",
5050
r#"ident, []"#,
@@ -56,6 +56,26 @@ fn test_fn_like_macro2() {
5656
);
5757
}
5858

59+
#[test]
60+
fn test_fn_like_macro_clone_literals() {
61+
assert_expand(
62+
"fn_like_clone_tokens",
63+
r#"1u16, 2_u32, -4i64, 3.14f32, "hello bridge""#,
64+
expect![[r#"
65+
SUBTREE $
66+
LITERAL 1u16 4294967295
67+
PUNCH , [alone] 4294967295
68+
LITERAL 2_u32 4294967295
69+
PUNCH , [alone] 4294967295
70+
PUNCH - [alone] 4294967295
71+
LITERAL 4i64 4294967295
72+
PUNCH , [alone] 4294967295
73+
LITERAL 3.14f32 4294967295
74+
PUNCH , [alone] 4294967295
75+
LITERAL "hello bridge" 4294967295"#]],
76+
);
77+
}
78+
5979
#[test]
6080
fn test_attr_macro() {
6181
// Corresponds to

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

+8-2
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, Punct, TokenStream, TokenTree};
5+
use proc_macro::{Group, Ident, Literal, Punct, TokenStream, TokenTree};
66

77
#[proc_macro]
88
pub fn fn_like_noop(args: TokenStream) -> TokenStream {
@@ -71,6 +71,12 @@ fn clone_tree(t: TokenTree) -> TokenTree {
7171
new.set_span(orig.span());
7272
TokenTree::Punct(new)
7373
}
74-
TokenTree::Literal(_orig) => unimplemented!(),
74+
TokenTree::Literal(orig) => {
75+
// this goes through `literal_from_str` as of 2022-07-18, cf.
76+
// https://github.com/rust-lang/rust/commit/b34c79f8f1ef4d0149ad4bf77e1759c07a9a01a8
77+
let mut new: Literal = orig.to_string().parse().unwrap();
78+
new.set_span(orig.span());
79+
TokenTree::Literal(new)
80+
}
7581
}
7682
}

0 commit comments

Comments
 (0)