Closed wackazong closed 1 month ago
use proc_macro::TokenStream; use quote::quote; use syn::parse::{Parse, ParseStream}; use syn::parse_macro_input; use syn::*; #[allow(dead_code)] #[proc_macro_attribute] pub fn my_macro(_args: TokenStream, input: TokenStream) -> TokenStream { parse_macro_input!(input as MyInput); quote! {}.into() } #[allow(dead_code)] struct MyInput {} impl Parse for MyInput { fn parse(input: ParseStream) -> Result<Self> { input.parse::<ItemFn>()?; Ok(Self {}) } }
use proc_macro::my_macro; #[my_macro] pub fn my_func() { let my_field = String::default(); let _this_is_fine = MyEnum::MyVariant { my_field }; let my_var = String::default(); let _this_produces_a_parse_error = MyEnum::MyVariant { my_field: my_var }; } #[allow(dead_code)] enum MyEnum { MyVariant { my_field: String }, }
Am I missing something or is this a bug?
Find the testcase at https://github.com/wackazong/syn-parse-error-testcase
Ok, after some more poking around it turns out it is the fault of rust-analyzer, I was using the pre-release version in VSCodium.
Proc Macro
Test Case
Am I missing something or is this a bug?
Find the testcase at https://github.com/wackazong/syn-parse-error-testcase