diff options
| author | bors <bors@rust-lang.org> | 2022-07-20 15:33:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-20 15:33:19 +0000 |
| commit | cd2c2406c0c5a11d3e998998845ca5c8be683676 (patch) | |
| tree | c9b01339207e26a0b2d9b65f13b81f3242a91b84 | |
| parent | 7dc36eeb781fcf35a69bb1a75e7005397a9da418 (diff) | |
| parent | f5042947ce93b40e5c6e7ddeb683d11e8faed51c (diff) | |
| download | rust-cd2c2406c0c5a11d3e998998845ca5c8be683676.tar.gz rust-cd2c2406c0c5a11d3e998998845ca5c8be683676.zip | |
Auto merge of #12833 - fasterthanlime:literal-tests, r=Veykril
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. This changed is tracked in: * https://github.com/rust-lang/rust-analyzer/issues/12818
| -rw-r--r-- | crates/proc-macro-srv/src/tests/mod.rs | 24 | ||||
| -rw-r--r-- | crates/proc-macro-test/imp/src/lib.rs | 10 |
2 files changed, 30 insertions, 4 deletions
diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs index 9356e6dcb01..d4be992465c 100644 --- a/crates/proc-macro-srv/src/tests/mod.rs +++ b/crates/proc-macro-srv/src/tests/mod.rs @@ -27,7 +27,7 @@ fn test_derive_error() { } #[test] -fn test_fn_like_macro() { +fn test_fn_like_macro_noop() { assert_expand( "fn_like_noop", r#"ident, 0, 1, []"#, @@ -44,7 +44,7 @@ fn test_fn_like_macro() { } #[test] -fn test_fn_like_macro2() { +fn test_fn_like_macro_clone_ident_subtree() { assert_expand( "fn_like_clone_tokens", r#"ident, []"#, @@ -57,6 +57,26 @@ fn test_fn_like_macro2() { } #[test] +fn test_fn_like_macro_clone_literals() { + assert_expand( + "fn_like_clone_tokens", + r#"1u16, 2_u32, -4i64, 3.14f32, "hello bridge""#, + expect![[r#" + SUBTREE $ + LITERAL 1u16 4294967295 + PUNCH , [alone] 4294967295 + LITERAL 2_u32 4294967295 + PUNCH , [alone] 4294967295 + PUNCH - [alone] 4294967295 + LITERAL 4i64 4294967295 + PUNCH , [alone] 4294967295 + LITERAL 3.14f32 4294967295 + PUNCH , [alone] 4294967295 + LITERAL "hello bridge" 4294967295"#]], + ); +} + +#[test] fn test_attr_macro() { // Corresponds to // #[proc_macro_test::attr_error(some arguments)] diff --git a/crates/proc-macro-test/imp/src/lib.rs b/crates/proc-macro-test/imp/src/lib.rs index f74d04729ba..0082eb7bdaf 100644 --- a/crates/proc-macro-test/imp/src/lib.rs +++ b/crates/proc-macro-test/imp/src/lib.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] -use proc_macro::{Group, Ident, Punct, TokenStream, TokenTree}; +use proc_macro::{Group, Ident, Literal, Punct, TokenStream, TokenTree}; #[proc_macro] pub fn fn_like_noop(args: TokenStream) -> TokenStream { @@ -71,6 +71,12 @@ fn clone_tree(t: TokenTree) -> TokenTree { new.set_span(orig.span()); TokenTree::Punct(new) } - TokenTree::Literal(_orig) => unimplemented!(), + TokenTree::Literal(orig) => { + // this goes through `literal_from_str` as of 2022-07-18, cf. + // https://github.com/rust-lang/rust/commit/b34c79f8f1ef4d0149ad4bf77e1759c07a9a01a8 + let mut new: Literal = orig.to_string().parse().unwrap(); + new.set_span(orig.span()); + TokenTree::Literal(new) + } } } |
