Skip to content

Commit 861af7d

Browse files
authored
Merge pull request #80 from alexcrichton/spacing
Fix spacing of op followed by comment
2 parents 1143735 + 3a592ad commit 861af7d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/stable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,11 @@ fn op(input: Cursor) -> PResult<Op> {
11981198
}
11991199

12001200
fn op_char(input: Cursor) -> PResult<char> {
1201+
if input.starts_with("//") || input.starts_with("/*") {
1202+
// Do not accept `/` of a comment as an op.
1203+
return Err(LexError);
1204+
}
1205+
12011206
let mut chars = input.chars();
12021207
let first = match chars.next() {
12031208
Some(ch) => ch,

tests/test.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate proc_macro2;
22

33
use std::str::{self, FromStr};
44

5-
use proc_macro2::{Literal, Span, Term, TokenStream, TokenTree};
5+
use proc_macro2::{Literal, Spacing, Span, Term, TokenStream, TokenTree};
66

77
#[test]
88
fn terms() {
@@ -293,6 +293,18 @@ fn tricky_doc_comment() {
293293
assert!(tokens.len() == 3, "not length 3 -- {:?}", tokens);
294294
}
295295

296+
#[test]
297+
fn op_before_comment() {
298+
let mut tts = TokenStream::from_str("~// comment").unwrap().into_iter();
299+
match tts.next().unwrap() {
300+
TokenTree::Op(tt) => {
301+
assert_eq!(tt.op(), '~');
302+
assert_eq!(tt.spacing(), Spacing::Alone);
303+
}
304+
wrong => panic!("wrong token {:?}", wrong),
305+
}
306+
}
307+
296308
#[test]
297309
fn raw_identifier() {
298310
let mut tts = TokenStream::from_str("r#dyn").unwrap().into_iter();

0 commit comments

Comments
 (0)