Skip to content

Commit d21c6a6

Browse files
authored
Merge pull request #264 from dtolnay/jointlast
Confirm that fallback TokenStream can preserve jointness of last punct
2 parents ed6fc44 + 237c566 commit d21c6a6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/test.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use proc_macro2::{Ident, Literal, Spacing, Span, TokenStream, TokenTree};
1+
use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
22
use std::str::{self, FromStr};
33

44
#[test]
@@ -304,6 +304,22 @@ fn punct_before_comment() {
304304
}
305305
}
306306

307+
#[test]
308+
fn joint_last_token() {
309+
// This test verifies that we match the behavior of libproc_macro *not* in
310+
// the range nightly-2020-09-06 through nightly-2020-09-10, in which this
311+
// behavior was temporarily broken.
312+
// See https://github.com/rust-lang/rust/issues/76399
313+
314+
let joint_punct = Punct::new(':', Spacing::Joint);
315+
let stream = TokenStream::from(TokenTree::Punct(joint_punct));
316+
let punct = match stream.into_iter().next().unwrap() {
317+
TokenTree::Punct(punct) => punct,
318+
_ => unreachable!(),
319+
};
320+
assert_eq!(punct.spacing(), Spacing::Joint);
321+
}
322+
307323
#[test]
308324
fn raw_identifier() {
309325
let mut tts = TokenStream::from_str("r#dyn").unwrap().into_iter();

0 commit comments

Comments
 (0)