Merge pull request #80 from alexcrichton/spacing

Fix spacing of op followed by comment
This commit is contained in:
Alex Crichton 2018-04-23 08:21:07 -05:00 committed by GitHub
commit 861af7ddb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -1198,6 +1198,11 @@ fn op(input: Cursor) -> PResult<Op> {
}
fn op_char(input: Cursor) -> PResult<char> {
if input.starts_with("//") || input.starts_with("/*") {
// Do not accept `/` of a comment as an op.
return Err(LexError);
}
let mut chars = input.chars();
let first = match chars.next() {
Some(ch) => ch,

View File

@ -2,7 +2,7 @@ extern crate proc_macro2;
use std::str::{self, FromStr};
use proc_macro2::{Literal, Span, Term, TokenStream, TokenTree};
use proc_macro2::{Literal, Spacing, Span, Term, TokenStream, TokenTree};
#[test]
fn terms() {
@ -293,6 +293,18 @@ fn tricky_doc_comment() {
assert!(tokens.len() == 3, "not length 3 -- {:?}", tokens);
}
#[test]
fn op_before_comment() {
let mut tts = TokenStream::from_str("~// comment").unwrap().into_iter();
match tts.next().unwrap() {
TokenTree::Op(tt) => {
assert_eq!(tt.op(), '~');
assert_eq!(tt.spacing(), Spacing::Alone);
}
wrong => panic!("wrong token {:?}", wrong),
}
}
#[test]
fn raw_identifier() {
let mut tts = TokenStream::from_str("r#dyn").unwrap().into_iter();