Skip to content

Commit 88e8877

Browse files
authored
Unrolled build for rust-lang#120220
Rollup merge of rust-lang#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 rust-lang#119875. r? ``@petrochenkov``
2 parents d5fd099 + c4fc9ff commit 88e8877

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

library/proc_macro/src/lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ impl ToString for TokenStream {
191191
/// Prints the token stream as a string that is supposed to be losslessly convertible back
192192
/// into the same token stream (modulo spans), except for possibly `TokenTree::Group`s
193193
/// with `Delimiter::None` delimiters and negative numeric literals.
194+
///
195+
/// Note: the exact form of the output is subject to change, e.g. there might
196+
/// be changes in the whitespace used between tokens. Therefore, you should
197+
/// *not* do any kind of simple substring matching on the output string (as
198+
/// produced by `to_string`) to implement a proc macro, because that matching
199+
/// might stop working if such changes happen. Instead, you should work at the
200+
/// `TokenTree` level, e.g. matching against `TokenTree::Ident`,
201+
/// `TokenTree::Punct`, or `TokenTree::Literal`.
194202
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
195203
impl fmt::Display for TokenStream {
196204
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -758,6 +766,14 @@ impl ToString for TokenTree {
758766
/// Prints the token tree as a string that is supposed to be losslessly convertible back
759767
/// into the same token tree (modulo spans), except for possibly `TokenTree::Group`s
760768
/// with `Delimiter::None` delimiters and negative numeric literals.
769+
///
770+
/// Note: the exact form of the output is subject to change, e.g. there might
771+
/// be changes in the whitespace used between tokens. Therefore, you should
772+
/// *not* do any kind of simple substring matching on the output string (as
773+
/// produced by `to_string`) to implement a proc macro, because that matching
774+
/// might stop working if such changes happen. Instead, you should work at the
775+
/// `TokenTree` level, e.g. matching against `TokenTree::Ident`,
776+
/// `TokenTree::Punct`, or `TokenTree::Literal`.
761777
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
762778
impl fmt::Display for TokenTree {
763779
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)