mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-23 07:19:41 +00:00
Merge pull request #80 from alexcrichton/spacing
Fix spacing of op followed by comment
This commit is contained in:
commit
861af7ddb3
@ -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,
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user