diff options
author | Haibo Huang <hhb@google.com> | 2020-05-15 23:36:50 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-05-15 23:36:50 -0700 |
commit | 548c6a34835dd62b4f3dfee7b6a09194ad924bd6 (patch) | |
tree | b2fe033e659be887071f4143958b76fabf563450 | |
parent | 304b615e15a5f576a05a97708b502f0e83a417d0 (diff) | |
download | platform_external_rust_crates_syn-548c6a34835dd62b4f3dfee7b6a09194ad924bd6.tar.gz platform_external_rust_crates_syn-548c6a34835dd62b4f3dfee7b6a09194ad924bd6.tar.bz2 platform_external_rust_crates_syn-548c6a34835dd62b4f3dfee7b6a09194ad924bd6.zip |
Upgrade rust/crates/syn to 1.0.22
Test: None
Change-Id: Icb173886fa6b0ea21560d851ae40ca4897c27f4e
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | Cargo.toml.orig | 8 | ||||
-rw-r--r-- | METADATA | 4 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/lit.rs | 212 | ||||
-rw-r--r-- | src/pat.rs | 3 | ||||
-rw-r--r-- | src/path.rs | 2 | ||||
-rw-r--r-- | tests/common/mod.rs | 9 | ||||
-rw-r--r-- | tests/features/error.rs | 1 | ||||
-rw-r--r-- | tests/features/mod.rs | 22 | ||||
-rw-r--r-- | tests/test_asyncness.rs | 2 | ||||
-rw-r--r-- | tests/test_attribute.rs | 2 | ||||
-rw-r--r-- | tests/test_derive_input.rs | 2 | ||||
-rw-r--r-- | tests/test_generics.rs | 2 | ||||
-rw-r--r-- | tests/test_grouping.rs | 2 | ||||
-rw-r--r-- | tests/test_ident.rs | 2 | ||||
-rw-r--r-- | tests/test_iterators.rs | 2 | ||||
-rw-r--r-- | tests/test_lit.rs | 32 | ||||
-rw-r--r-- | tests/test_meta.rs | 2 | ||||
-rw-r--r-- | tests/test_pat.rs | 2 | ||||
-rw-r--r-- | tests/test_precedence.rs | 3 | ||||
-rw-r--r-- | tests/test_receiver.rs | 2 | ||||
-rw-r--r-- | tests/test_round_trip.rs | 3 | ||||
-rw-r--r-- | tests/test_should_parse.rs | 2 | ||||
-rw-r--r-- | tests/test_size.rs | 2 | ||||
-rw-r--r-- | tests/test_token_trees.rs | 2 | ||||
-rw-r--r-- | tests/test_visibility.rs | 2 |
28 files changed, 197 insertions, 143 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index bfd416f7..02ce07f0 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "f6c814ae039b0e3c30b3ad9223edd78d331c8b30" + "sha1": "0e44fcbc2c756af716d7880438d231ebbfb01e55" } } @@ -13,7 +13,7 @@ [package] edition = "2018" name = "syn" -version = "1.0.21" +version = "1.0.22" authors = ["David Tolnay <dtolnay@gmail.com>"] include = ["/benches/**", "/build.rs", "/Cargo.toml", "/LICENSE-APACHE", "/LICENSE-MIT", "/README.md", "/src/**", "/tests/**"] description = "Parser for Rust source code" @@ -38,7 +38,7 @@ required-features = ["full", "parsing"] name = "file" required-features = ["full", "parsing"] [dependencies.proc-macro2] -version = "1.0.7" +version = "1.0.13" default-features = false [dependencies.quote] @@ -70,6 +70,9 @@ version = "1.0" version = "0.10" features = ["blocking"] +[dev-dependencies.syn-test-suite] +version = "0" + [dev-dependencies.tar] version = "0.4" @@ -89,5 +92,6 @@ full = [] parsing = [] printing = ["quote"] proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"] +test = ["syn-test-suite/all-features"] visit = [] visit-mut = [] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 8774079d..5988ca74 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "syn" -version = "1.0.21" # don't forget to update html_root_url and syn.json +version = "1.0.22" # don't forget to update html_root_url and syn.json authors = ["David Tolnay <dtolnay@gmail.com>"] license = "MIT OR Apache-2.0" description = "Parser for Rust source code" @@ -32,9 +32,10 @@ fold = [] clone-impls = [] extra-traits = [] proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"] +test = ["syn-test-suite/all-features"] [dependencies] -proc-macro2 = { version = "1.0.7", default-features = false } +proc-macro2 = { version = "1.0.13", default-features = false } quote = { version = "1.0", optional = true, default-features = false } unicode-xid = "0.2" @@ -46,6 +47,7 @@ rayon = "1.0" ref-cast = "1.0" regex = "1.0" reqwest = { version = "0.10", features = ["blocking"] } +syn-test-suite = { version = "0", path = "tests/features" } tar = "0.4" termcolor = "1.0" walkdir = "2.1" @@ -67,4 +69,4 @@ targets = ["x86_64-unknown-linux-gnu"] all-features = true [workspace] -members = ["dev", "json"] +members = ["dev", "json", "tests/features"] @@ -9,11 +9,11 @@ third_party { type: GIT value: "https://github.com/dtolnay/syn" } - version: "1.0.21" + version: "1.0.22" license_type: NOTICE last_upgrade_date { year: 2020 month: 5 - day: 12 + day: 15 } } @@ -250,7 +250,7 @@ //! dynamic library libproc_macro from rustc toolchain. // Syn types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/syn/1.0.21")] +#![doc(html_root_url = "https://docs.rs/syn/1.0.22")] #![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints. #![allow( @@ -260,6 +260,7 @@ clippy::eval_order_dependence, clippy::inherent_to_string, clippy::large_enum_variant, + clippy::manual_non_exhaustive, clippy::match_on_vec_items, clippy::needless_doctest_main, clippy::needless_pass_by_value, @@ -62,37 +62,37 @@ ast_enum_of_structs! { ast_struct! { /// A UTF-8 string literal: `"foo"`. pub struct LitStr #manual_extra_traits_debug { - repr: Box<LitStrRepr>, + repr: Box<LitRepr>, } } -#[cfg_attr(feature = "clone-impls", derive(Clone))] -struct LitStrRepr { - token: Literal, - suffix: Box<str>, -} - ast_struct! { /// A byte string literal: `b"foo"`. pub struct LitByteStr #manual_extra_traits_debug { - token: Literal, + repr: Box<LitRepr>, } } ast_struct! { /// A byte literal: `b'f'`. pub struct LitByte #manual_extra_traits_debug { - token: Literal, + repr: Box<LitRepr>, } } ast_struct! { /// A character literal: `'a'`. pub struct LitChar #manual_extra_traits_debug { - token: Literal, + repr: Box<LitRepr>, } } +#[cfg_attr(feature = "clone-impls", derive(Clone))] +struct LitRepr { + token: Literal, + suffix: Box<str>, +} + ast_struct! { /// An integer literal: `1` or `1u16`. pub struct LitInt #manual_extra_traits_debug { @@ -196,18 +196,19 @@ impl Hash for Lit { impl LitStr { pub fn new(value: &str, span: Span) -> Self { - let mut lit = Literal::string(value); - lit.set_span(span); + let mut token = Literal::string(value); + token.set_span(span); LitStr { - repr: Box::new(LitStrRepr { - token: lit, + repr: Box::new(LitRepr { + token, suffix: Box::<str>::default(), }), } } pub fn value(&self) -> String { - let (value, _) = value::parse_lit_str(&self.repr.token.to_string()); + let repr = self.repr.token.to_string(); + let (value, _suffix) = value::parse_lit_str(&repr); String::from(value) } @@ -321,19 +322,30 @@ impl LitByteStr { pub fn new(value: &[u8], span: Span) -> Self { let mut token = Literal::byte_string(value); token.set_span(span); - LitByteStr { token } + LitByteStr { + repr: Box::new(LitRepr { + token, + suffix: Box::<str>::default(), + }), + } } pub fn value(&self) -> Vec<u8> { - value::parse_lit_byte_str(&self.token.to_string()) + let repr = self.repr.token.to_string(); + let (value, _suffix) = value::parse_lit_byte_str(&repr); + value } pub fn span(&self) -> Span { - self.token.span() + self.repr.token.span() } pub fn set_span(&mut self, span: Span) { - self.token.set_span(span) + self.repr.token.set_span(span) + } + + pub fn suffix(&self) -> &str { + &self.repr.suffix } } @@ -341,19 +353,30 @@ impl LitByte { pub fn new(value: u8, span: Span) -> Self { let mut token = Literal::u8_suffixed(value); token.set_span(span); - LitByte { token } + LitByte { + repr: Box::new(LitRepr { + token, + suffix: Box::<str>::default(), + }), + } } pub fn value(&self) -> u8 { - value::parse_lit_byte(&self.token.to_string()) + let repr = self.repr.token.to_string(); + let (value, _suffix) = value::parse_lit_byte(&repr); + value } pub fn span(&self) -> Span { - self.token.span() + self.repr.token.span() } pub fn set_span(&mut self, span: Span) { - self.token.set_span(span) + self.repr.token.set_span(span) + } + + pub fn suffix(&self) -> &str { + &self.repr.suffix } } @@ -361,19 +384,30 @@ impl LitChar { pub fn new(value: char, span: Span) -> Self { let mut token = Literal::character(value); token.set_span(span); - LitChar { token } + LitChar { + repr: Box::new(LitRepr { + token, + suffix: Box::<str>::default(), + }), + } } pub fn value(&self) -> char { - value::parse_lit_char(&self.token.to_string()) + let repr = self.repr.token.to_string(); + let (value, _suffix) = value::parse_lit_char(&repr); + value } pub fn span(&self) -> Span { - self.token.span() + self.repr.token.span() } pub fn set_span(&mut self, span: Span) { - self.token.set_span(span) + self.repr.token.set_span(span) + } + + pub fn suffix(&self) -> &str { + &self.repr.suffix } } @@ -561,7 +595,7 @@ mod debug_impls { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter .debug_struct("LitByteStr") - .field("token", &format_args!("{}", self.token)) + .field("token", &format_args!("{}", self.repr.token)) .finish() } } @@ -570,7 +604,7 @@ mod debug_impls { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter .debug_struct("LitByte") - .field("token", &format_args!("{}", self.token)) + .field("token", &format_args!("{}", self.repr.token)) .finish() } } @@ -579,7 +613,7 @@ mod debug_impls { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter .debug_struct("LitChar") - .field("token", &format_args!("{}", self.token)) + .field("token", &format_args!("{}", self.repr.token)) .finish() } } @@ -644,9 +678,9 @@ macro_rules! lit_extra_traits { } lit_extra_traits!(LitStr, repr.token); -lit_extra_traits!(LitByteStr, token); -lit_extra_traits!(LitByte, token); -lit_extra_traits!(LitChar, token); +lit_extra_traits!(LitByteStr, repr.token); +lit_extra_traits!(LitByte, repr.token); +lit_extra_traits!(LitChar, repr.token); lit_extra_traits!(LitInt, repr.token); lit_extra_traits!(LitFloat, repr.token); lit_extra_traits!(LitBool, value); @@ -836,19 +870,19 @@ mod printing { impl ToTokens for LitByteStr { fn to_tokens(&self, tokens: &mut TokenStream) { - self.token.to_tokens(tokens); + self.repr.token.to_tokens(tokens); } } impl ToTokens for LitByte { fn to_tokens(&self, tokens: &mut TokenStream) { - self.token.to_tokens(tokens); + self.repr.token.to_tokens(tokens); } } impl ToTokens for LitChar { fn to_tokens(&self, tokens: &mut TokenStream) { - self.token.to_tokens(tokens); + self.repr.token.to_tokens(tokens); } } @@ -888,20 +922,29 @@ mod value { b'"' | b'r' => { let (_, suffix) = parse_lit_str(&repr); return Lit::Str(LitStr { - repr: Box::new(LitStrRepr { token, suffix }), + repr: Box::new(LitRepr { token, suffix }), }); } b'b' => match byte(&repr, 1) { b'"' | b'r' => { - return Lit::ByteStr(LitByteStr { token }); + let (_, suffix) = parse_lit_byte_str(&repr); + return Lit::ByteStr(LitByteStr { + repr: Box::new(LitRepr { token, suffix }), + }); } b'\'' => { - return Lit::Byte(LitByte { token }); + let (_, suffix) = parse_lit_byte(&repr); + return Lit::Byte(LitByte { + repr: Box::new(LitRepr { token, suffix }), + }); } _ => {} }, b'\'' => { - return Lit::Char(LitChar { token }); + let (_, suffix) = parse_lit_char(&repr); + return Lit::Char(LitChar { + repr: Box::new(LitRepr { token, suffix }), + }); } b'0'..=b'9' | b'-' => { if !(repr.ends_with("f32") || repr.ends_with("f64")) { @@ -938,6 +981,18 @@ mod value { panic!("Unrecognized literal: `{}`", repr); } + + pub fn suffix(&self) -> &str { + match self { + Lit::Str(lit) => lit.suffix(), + Lit::ByteStr(lit) => lit.suffix(), + Lit::Byte(lit) => lit.suffix(), + Lit::Char(lit) => lit.suffix(), + Lit::Int(lit) => lit.suffix(), + Lit::Float(lit) => lit.suffix(), + Lit::Bool(_) | Lit::Verbatim(_) => "", + } + } } /// Get the byte at offset idx, or a default of `b'\0'` if we're looking @@ -1037,19 +1092,18 @@ mod value { pounds += 1; } assert_eq!(byte(s, pounds), b'"'); - assert_eq!(byte(s, s.len() - pounds - 1), b'"'); - for end in s[s.len() - pounds..].bytes() { + let close = s.rfind('"').unwrap(); + for end in s[close + 1..close + 1 + pounds].bytes() { assert_eq!(end, b'#'); } - let content = s[pounds + 1..s.len() - pounds - 1] - .to_owned() - .into_boxed_str(); - let suffix = Box::<str>::default(); // todo + let content = s[pounds + 1..close].to_owned().into_boxed_str(); + let suffix = s[close + 1 + pounds..].to_owned().into_boxed_str(); (content, suffix) } - pub fn parse_lit_byte_str(s: &str) -> Vec<u8> { + // Returns (content, suffix). + pub fn parse_lit_byte_str(s: &str) -> (Vec<u8>, Box<str>) { assert_eq!(byte(s, 0), b'b'); match byte(s, 1) { b'"' => parse_lit_byte_str_cooked(s), @@ -1061,25 +1115,25 @@ mod value { // Clippy false positive // https://github.com/rust-lang-nursery/rust-clippy/issues/2329 #[allow(clippy::needless_continue)] - fn parse_lit_byte_str_cooked(mut s: &str) -> Vec<u8> { + fn parse_lit_byte_str_cooked(mut s: &str) -> (Vec<u8>, Box<str>) { assert_eq!(byte(s, 0), b'b'); assert_eq!(byte(s, 1), b'"'); s = &s[2..]; // We're going to want to have slices which don't respect codepoint boundaries. - let mut s = s.as_bytes(); + let mut v = s.as_bytes(); let mut out = Vec::new(); 'outer: loop { - let byte = match byte(s, 0) { + let byte = match byte(v, 0) { b'"' => break, b'\\' => { - let b = byte(s, 1); - s = &s[2..]; + let b = byte(v, 1); + v = &v[2..]; match b { b'x' => { - let (b, rest) = backslash_x(s); - s = rest; + let (b, rest) = backslash_x(v); + v = rest; b } b'n' => b'\n', @@ -1090,10 +1144,10 @@ mod value { b'\'' => b'\'', b'"' => b'"', b'\r' | b'\n' => loop { - let byte = byte(s, 0); + let byte = byte(v, 0); let ch = char::from_u32(u32::from(byte)).unwrap(); if ch.is_whitespace() { - s = &s[1..]; + v = &v[1..]; } else { continue 'outer; } @@ -1102,42 +1156,45 @@ mod value { } } b'\r' => { - assert_eq!(byte(s, 1), b'\n', "Bare CR not allowed in string"); - s = &s[2..]; + assert_eq!(byte(v, 1), b'\n', "Bare CR not allowed in string"); + v = &v[2..]; b'\n' } b => { - s = &s[1..]; + v = &v[1..]; b } }; out.push(byte); } - assert_eq!(s, b"\""); - out + assert_eq!(byte(v, 0), b'"'); + let suffix = s[s.len() - v.len() + 1..].to_owned().into_boxed_str(); + (out, suffix) } - fn parse_lit_byte_str_raw(s: &str) -> Vec<u8> { + fn parse_lit_byte_str_raw(s: &str) -> (Vec<u8>, Box<str>) { assert_eq!(byte(s, 0), b'b'); - String::from(parse_lit_str_raw(&s[1..]).0).into_bytes() + let (value, suffix) = parse_lit_str_raw(&s[1..]); + (String::from(value).into_bytes(), suffix) } - pub fn parse_lit_byte(s: &str) -> u8 { + // Returns (value, suffix). + pub fn parse_lit_byte(s: &str) -> (u8, Box<str>) { assert_eq!(byte(s, 0), b'b'); assert_eq!(byte(s, 1), b'\''); // We're going to want to have slices which don't respect codepoint boundaries. - let mut s = s[2..].as_bytes(); + let mut v = s[2..].as_bytes(); - let b = match byte(s, 0) { + let b = match byte(v, 0) { b'\\' => { - let b = byte(s, 1); - s = &s[2..]; + let b = byte(v, 1); + v = &v[2..]; match b { b'x' => { - let (b, rest) = backslash_x(s); - s = rest; + let (b, rest) = backslash_x(v); + v = rest; b } b'n' => b'\n', @@ -1151,16 +1208,18 @@ mod value { } } b => { - s = &s[1..]; + v = &v[1..]; b } }; - assert_eq!(byte(s, 0), b'\''); - b + assert_eq!(byte(v, 0), b'\''); + let suffix = s[s.len() - v.len() + 1..].to_owned().into_boxed_str(); + (b, suffix) } - pub fn parse_lit_char(mut s: &str) -> char { + // Returns (value, suffix). + pub fn parse_lit_char(mut s: &str) -> (char, Box<str>) { assert_eq!(byte(s, 0), b'\''); s = &s[1..]; @@ -1196,8 +1255,9 @@ mod value { ch } }; - assert_eq!(s, "\'", "Expected end of char literal"); - ch + assert_eq!(byte(s, 0), b'\''); + let suffix = s[1..].to_owned().into_boxed_str(); + (ch, suffix) } fn backslash_x<S>(s: &S) -> (u8, &S) @@ -97,6 +97,9 @@ ast_struct! { ast_struct! { /// A pattern that binds a new variable: `ref mut binding @ SUBPATTERN`. /// + /// It may also be a unit struct or struct variant (e.g. `None`), or a + /// constant; these cannot be distinguished syntactically. + /// /// *This type is available if Syn is built with the `"full"` feature.* pub struct PatIdent { pub attrs: Vec<Attribute>, diff --git a/src/path.rs b/src/path.rs index 8dda43ee..6e37bf35 100644 --- a/src/path.rs +++ b/src/path.rs @@ -2,7 +2,7 @@ use super::*; use crate::punctuated::Punctuated; ast_struct! { - /// A path at which a named item is exported: `std::collections::HashMap`. + /// A path at which a named item is exported (e.g. `std::collections::HashMap`). /// /// *This type is available if Syn is built with the `"derive"` or `"full"` /// feature.* diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 8b784bee..1b0b23cc 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] +use rayon::ThreadPoolBuilder; use std::env; pub mod eq; @@ -12,3 +13,11 @@ pub fn abort_after() -> usize { Err(_) => usize::max_value(), } } + +/// Configure Rayon threadpool. +pub fn rayon_init() { + ThreadPoolBuilder::new() + .stack_size(10 * 1024 * 1024) + .build_global() + .unwrap(); +} diff --git a/tests/features/error.rs b/tests/features/error.rs deleted file mode 100644 index 10ac8896..00000000 --- a/tests/features/error.rs +++ /dev/null @@ -1 +0,0 @@ -"Hello! You want: cargo test --release --all-features" diff --git a/tests/features/mod.rs b/tests/features/mod.rs deleted file mode 100644 index 83fbe13e..00000000 --- a/tests/features/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -#[allow(unused_macros)] -macro_rules! hide_from_rustfmt { - ($mod:item) => { - $mod - }; -} - -#[cfg(not(all( - feature = "derive", - feature = "full", - feature = "parsing", - feature = "printing", - feature = "visit", - feature = "visit-mut", - feature = "fold", - feature = "clone-impls", - feature = "extra-traits", - feature = "proc-macro", -)))] -hide_from_rustfmt! { - mod error; -} diff --git a/tests/test_asyncness.rs b/tests/test_asyncness.rs index e09e816d..0efef597 100644 --- a/tests/test_asyncness.rs +++ b/tests/test_asyncness.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_attribute.rs b/tests/test_attribute.rs index e1b0142b..c26bd090 100644 --- a/tests/test_attribute.rs +++ b/tests/test_attribute.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_derive_input.rs b/tests/test_derive_input.rs index e3685aea..96563b7f 100644 --- a/tests/test_derive_input.rs +++ b/tests/test_derive_input.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_generics.rs b/tests/test_generics.rs index e863b779..9957c0e4 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_grouping.rs b/tests/test_grouping.rs index 4e43ab8a..c53ab346 100644 --- a/tests/test_grouping.rs +++ b/tests/test_grouping.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_ident.rs b/tests/test_ident.rs index 7578381e..ee01bfcc 100644 --- a/tests/test_ident.rs +++ b/tests/test_ident.rs @@ -1,5 +1,3 @@ -mod features; - use proc_macro2::{Ident, Span, TokenStream}; use std::str::FromStr; use syn::Result; diff --git a/tests/test_iterators.rs b/tests/test_iterators.rs index f1072977..2c8359c1 100644 --- a/tests/test_iterators.rs +++ b/tests/test_iterators.rs @@ -1,8 +1,6 @@ use syn::punctuated::{Pair, Punctuated}; use syn::Token; -mod features; - #[macro_use] mod macros; diff --git a/tests/test_lit.rs b/tests/test_lit.rs index d4495ce4..7addc0fa 100644 --- a/tests/test_lit.rs +++ b/tests/test_lit.rs @@ -1,5 +1,3 @@ -mod features; - use proc_macro2::{Span, TokenStream, TokenTree}; use quote::ToTokens; use std::str::FromStr; @@ -46,6 +44,9 @@ fn strings() { "contains\nnewlinesescaped newlines", ); test_string("r\"raw\nstring\\\nhere\"", "raw\nstring\\\nhere"); + test_string("\"...\"q", "..."); + test_string("r\"...\"q", "..."); + test_string("r##\"...\"##q", "..."); } #[test] @@ -75,6 +76,9 @@ fn byte_strings() { b"contains\nnewlinesescaped newlines", ); test_byte_string("br\"raw\nstring\\\nhere\"", b"raw\nstring\\\nhere"); + test_byte_string("b\"...\"q", b"..."); + test_byte_string("br\"...\"q", b"..."); + test_byte_string("br##\"...\"##q", b"..."); } #[test] @@ -96,6 +100,7 @@ fn bytes() { test_byte("b'\\t'", b'\t'); test_byte("b'\\''", b'\''); test_byte("b'\"'", b'"'); + test_byte("b'a'q", b'a'); } #[test] @@ -121,6 +126,7 @@ fn chars() { test_char("'\\''", '\''); test_char("'\"'", '"'); test_char("'\\u{1F415}'", '\u{1F415}'); + test_char("'a'q", 'a'); } #[test] @@ -195,3 +201,25 @@ fn negative() { assert_eq!("-1.5f32", LitFloat::new("-1.5f32", span).to_string()); assert_eq!("-1.5f64", LitFloat::new("-1.5f64", span).to_string()); } + +#[test] +fn suffix() { + fn get_suffix(token: &str) -> String { + let lit = syn::parse_str::<Lit>(token).unwrap(); + match lit { + Lit::Str(lit) => lit.suffix().to_owned(), + Lit::ByteStr(lit) => lit.suffix().to_owned(), + Lit::Byte(lit) => lit.suffix().to_owned(), + Lit::Char(lit) => lit.suffix().to_owned(), + _ => unimplemented!(), + } + } + + assert_eq!(get_suffix("\"\"s"), "s"); + assert_eq!(get_suffix("r\"\"r"), "r"); + assert_eq!(get_suffix("b\"\"b"), "b"); + assert_eq!(get_suffix("br\"\"br"), "br"); + assert_eq!(get_suffix("r#\"\"#r"), "r"); + assert_eq!(get_suffix("'c'c"), "c"); + assert_eq!(get_suffix("b'b'b"), "b"); +} diff --git a/tests/test_meta.rs b/tests/test_meta.rs index 618296e2..d37dda94 100644 --- a/tests/test_meta.rs +++ b/tests/test_meta.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_pat.rs b/tests/test_pat.rs index cce4b809..8cba735f 100644 --- a/tests/test_pat.rs +++ b/tests/test_pat.rs @@ -1,5 +1,3 @@ -mod features; - use quote::quote; use syn::Pat; diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index 0841f7cd..08d3c1e0 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -18,8 +18,6 @@ extern crate rustc_ast; extern crate rustc_data_structures; extern crate rustc_span; -mod features; - use quote::quote; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use regex::Regex; @@ -85,6 +83,7 @@ fn test_simple_precedence() { /// Test expressions from rustc, like in `test_round_trip`. #[test] fn test_rustc_precedence() { + common::rayon_init(); repo::clone_rust(); let abort_after = common::abort_after(); if abort_after == 0 { diff --git a/tests/test_receiver.rs b/tests/test_receiver.rs index 7169891e..923df96b 100644 --- a/tests/test_receiver.rs +++ b/tests/test_receiver.rs @@ -1,5 +1,3 @@ -mod features; - use syn::{parse_quote, FnArg, Receiver, TraitItemMethod}; #[test] diff --git a/tests/test_round_trip.rs b/tests/test_round_trip.rs index d4f525b1..4dde5f25 100644 --- a/tests/test_round_trip.rs +++ b/tests/test_round_trip.rs @@ -9,8 +9,6 @@ extern crate rustc_parse as parse; extern crate rustc_session; extern crate rustc_span; -mod features; - use quote::quote; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rustc_ast::ast; @@ -40,6 +38,7 @@ use common::eq::SpanlessEq; #[test] fn test_round_trip() { + common::rayon_init(); repo::clone_rust(); let abort_after = common::abort_after(); if abort_after == 0 { diff --git a/tests/test_should_parse.rs b/tests/test_should_parse.rs index d4f7ac34..180d8599 100644 --- a/tests/test_should_parse.rs +++ b/tests/test_should_parse.rs @@ -1,5 +1,3 @@ -mod features; - macro_rules! should_parse { ($name:ident, { $($in:tt)* }) => { #[test] diff --git a/tests/test_size.rs b/tests/test_size.rs index 386d4df8..01e84011 100644 --- a/tests/test_size.rs +++ b/tests/test_size.rs @@ -1,7 +1,5 @@ #![cfg(target_pointer_width = "64")] -mod features; - use std::mem; use syn::*; diff --git a/tests/test_token_trees.rs b/tests/test_token_trees.rs index 5d7610bb..75c7e40c 100644 --- a/tests/test_token_trees.rs +++ b/tests/test_token_trees.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_visibility.rs b/tests/test_visibility.rs index 21c49c99..21f9adf2 100644 --- a/tests/test_visibility.rs +++ b/tests/test_visibility.rs @@ -1,5 +1,3 @@ -mod features; - use proc_macro2::TokenStream; use syn::parse::{Parse, ParseStream}; use syn::{Result, Visibility}; |