diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-01-22 22:12:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-22 22:12:10 +0100 |
| commit | a4307184beeefe263bc764ea5df0ff0f4c62c71f (patch) | |
| tree | e91404332f4eb676ecdfc8c3d196342854ee8312 | |
| parent | 31b56a8a3532de8bc80f961c237b603f654fd5d6 (diff) | |
| parent | c4fc9ff0d30a56dae9ca1ba44e407d20f21e6516 (diff) | |
| download | rust-a4307184beeefe263bc764ea5df0ff0f4c62c71f.tar.gz rust-a4307184beeefe263bc764ea5df0ff0f4c62c71f.zip | |
Rollup merge of #120220 - nnethercote:TokenStream-Display-docs, r=petrochenkov
Document `Token{Stream,Tree}::Display` more thoroughly.
To expressly warn against the kind of proc macro implementation that was broken in #119875.
r? ``@petrochenkov``
| -rw-r--r-- | library/proc_macro/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index ca83e2be5c1..87e89a464bc 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -191,6 +191,14 @@ impl ToString for TokenStream { /// Prints the token stream as a string that is supposed to be losslessly convertible back /// into the same token stream (modulo spans), except for possibly `TokenTree::Group`s /// with `Delimiter::None` delimiters and negative numeric literals. +/// +/// Note: the exact form of the output is subject to change, e.g. there might +/// be changes in the whitespace used between tokens. Therefore, you should +/// *not* do any kind of simple substring matching on the output string (as +/// produced by `to_string`) to implement a proc macro, because that matching +/// might stop working if such changes happen. Instead, you should work at the +/// `TokenTree` level, e.g. matching against `TokenTree::Ident`, +/// `TokenTree::Punct`, or `TokenTree::Literal`. #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl fmt::Display for TokenStream { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -758,6 +766,14 @@ impl ToString for TokenTree { /// Prints the token tree as a string that is supposed to be losslessly convertible back /// into the same token tree (modulo spans), except for possibly `TokenTree::Group`s /// with `Delimiter::None` delimiters and negative numeric literals. +/// +/// Note: the exact form of the output is subject to change, e.g. there might +/// be changes in the whitespace used between tokens. Therefore, you should +/// *not* do any kind of simple substring matching on the output string (as +/// produced by `to_string`) to implement a proc macro, because that matching +/// might stop working if such changes happen. Instead, you should work at the +/// `TokenTree` level, e.g. matching against `TokenTree::Ident`, +/// `TokenTree::Punct`, or `TokenTree::Literal`. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl fmt::Display for TokenTree { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
