Uh oh!
There was an error while loading. Please reload this page.
proc_macro: Use ToTokens trait in quote macro - #134693
Conversation
This comment has been minimized.
This comment has been minimized.
519aec5 to
0b32decCompareUh oh!
There was an error while loading. Please reload this page.
commented
Dec 23, 2024
Thanks for working on this! Could you update the new test file with applicable tests from https://github.com/dtolnay/quote/blob/aafba72e10919ad47c05169271cb78e614fb2b9d/tests/test.rs? Because of token stream limitations we can't actually mark them We can probably reuse the UI tests from https://github.com/dtolnay/quote/tree/aafba72e10919ad47c05169271cb78e614fb2b9d/tests/ui too. I think you can just make a new |
Uh oh!
There was an error while loading. Please reload this page.
0b32dec to
7e77f06Compare
commented
Jan 4, 2025
I have updated the PR for the macro implementation, and I will migrate the test cases from |
This comment has been minimized.
This comment has been minimized.
7e77f06 to
5d0a6c5Compare
This comment has been minimized.
This comment has been minimized.
5d0a6c5 to
858ad51Compare
commented
Jan 4, 2025
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
858ad51 to
6404cf5Compare
commented
Jan 8, 2025 •
I'm working on migrating the applicable tests from https://github.com/dtolnay/quote/blob/0245506323a3616daa2ee41c6ad0b871e4d78ae4/tests/test.rs. It seems like the current // - quote_spanned:// - fn test_quote_spanned_impl// - fn test_type_inference_for_span// - format_ident:// - fn test_format_ident// - fn test_format_ident_strip_raw// - repetition:// - fn test_iter// - fn test_array// - fn test_fancy_repetition// - fn test_nested_fancy_repetition// - fn test_duplicate_name_repetition// - fn test_duplicate_name_repetition_no_copy// - fn test_btreeset_repetition// - fn test_variable_name_conflict// - fn test_nonrep_in_repetition// - fn test_closure// - fn test_star_after_repetitionAnd many tests cases failed with /*message: assertion `left == right` failed left: "impl < 'a , T : ToTokens > ToTokens for & 'a T { fn to_tokens (& self , tokens : & mut TokenStream) { (* * self) . to_tokens (tokens) } }" right: "impl < 'a, T : ToTokens > ToTokens for & 'a T\n{\n fn to_tokens(& self, tokens : & mut TokenStream)\n { (** self).to_tokens(tokens) }\n}"*/fntest_quote_impl(){let tokens = quote!{impl<'a,T:ToTokens> ToTokensfor&'a T{fn to_tokens(&self, tokens:&mutTokenStream){(**self).to_tokens(tokens)}}};let expected = concat!("impl < 'a , T : ToTokens > ToTokens for & 'a T { ","fn to_tokens (& self , tokens : & mut TokenStream) { ","(* * self) . to_tokens (tokens) ","} ","}");assert_eq!(expected, tokens.to_string());}/*message: assertion `left == right` failed left: "X < X > (X) [X] { X }" right: "X <X > (X) [X] { X }"*/fntest_substitution(){let x = X;let tokens = quote!($x <$x> ($x)[$x]{$x});let expected = "X < X > (X) [X] { X }";assert_eq!(expected, tokens.to_string());}/*message: assertion `left == right` failed left: "struct SerializeWith < 'a , T > where T : Serialize { value : & 'a String , phantom : :: std :: marker :: PhantomData < Cow < 'a , str > > , } impl < 'a , T > :: serde :: Serialize for SerializeWith < 'a , T > where T : Serialize { fn serialize < S > (& self , s : & mut S) -> Result < () , S :: Error > where S : :: serde :: Serializer { SomeTrait :: serialize_with (self . value , s) } } SerializeWith { value : self . x , phantom : :: std :: marker :: PhantomData :: < Cow < 'a , str > > , }" right: "struct SerializeWith < 'a, T > where T : Serialize\n{\n value : & 'a String, phantom : :: std :: marker :: PhantomData <Cow < 'a,\n str > >,\n} impl < 'a, T > :: serde :: Serialize for SerializeWith < 'a, T > where T :\nSerialize\n{\n fn serialize < S > (& self, s : & mut S) -> Result < (), S :: Error >\n where S : :: serde :: Serializer\n { SomeTrait :: serialize_with(self.value, s) }\n} SerializeWith\n{\n value : self.x, phantom : :: std :: marker :: PhantomData ::<Cow < 'a, str\n > >,\n}"*/fntest_advanced(){/* ... */}and more. I propose to open a new PR to add these test cases with fixes, and leave a FIXME for these unimplemented features, to keep this PR clean. What do you think? @tgross35 |
commented
Jan 8, 2025
At least at this time, there is no plan for
The examples you listed look like they have the same meaning but some different spacing. Updating the whitespace to match should be fine, as long as there aren't other inconsistencies. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
commented
Jan 8, 2025 •
Something is wrong with raw string. /*message: assertion `left == right` failed left: "# [doc = r\" doc\"]" right: "#[doc = \" doc\"]"*/fntest_outer_line_comment(){let tokens = quote!{/// doc};let expected = "# [doc = r\" doc\"]";assert_eq!(expected, tokens.to_string());}/*message: `"r#raw_id"` is not a valid identifier*/fntest_quote_raw_id(){let id = quote!(r#raw_id);assert_eq!(id.to_string(),"r#raw_id");} |
commented
Jan 8, 2025
We probably need to call to For doc comments, maybe |
commented
Jan 8, 2025 •
Also if you prefer not to fix this here, it is okay to just open an issue and leave the test as a FIXME. I'd be happy to merge this nearly as-is since it's a big improvement over what we have, as long as tests pass and dtolnay has no objection. Same goes for the |
commented
Jan 8, 2025
I'm fine to fix it in this PR as long as it's not a huge diff :) Also, compilefail tests are still being migrated. |
8859f8d to
b13e0a6Compare
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
b13e0a6 to
3a2f3b9Compare3a2f3b9 to
ef69c30Compare
commented
Jan 9, 2025
The job Click to see the possible cause of the failure (guessed by this bot) |
commented
Jan 9, 2025
This is a significant improvement, thanks for the changes! Tree is closed for the CI fixes so this will have to wait a bit to merge. |
commented
Jan 10, 2025
@bors r+ |
Tracking issues: #130977, #54722
This PR changed
proc_macro::quote!to useToTokenstrait instead ofTokenStream::from, and migrated test cases fromquotecrate.r? @dtolnay
CC @tgross35