{
35 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
36 | match self.get() {
37 | Some(value) => Debug::fmt(value, formatter),
38 | None => formatter.write_str("unknown"),
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/src/verbatim.rs:
--------------------------------------------------------------------------------
1 | use crate::parse::{ParseBuffer, ParseStream};
2 | use proc_macro2::{Delimiter, TokenStream};
3 | use std::cmp::Ordering;
4 | use std::iter;
5 |
6 | pub fn between<'a>(begin: ParseBuffer<'a>, end: ParseStream<'a>) -> TokenStream {
7 | let end = end.cursor();
8 | let mut cursor = begin.cursor();
9 | assert!(crate::buffer::same_buffer(end, cursor));
10 |
11 | let mut tokens = TokenStream::new();
12 | while cursor != end {
13 | let (tt, next) = cursor.token_tree().unwrap();
14 |
15 | if crate::buffer::cmp_assuming_same_buffer(end, next) == Ordering::Less {
16 | // A syntax node can cross the boundary of a None-delimited group
17 | // due to such groups being transparent to the parser in most cases.
18 | // Any time this occurs the group is known to be semantically
19 | // irrelevant. https://github.com/dtolnay/syn/issues/1235
20 | if let Some((inside, _span, after)) = cursor.group(Delimiter::None) {
21 | assert!(next == after);
22 | cursor = inside;
23 | continue;
24 | } else {
25 | panic!("verbatim end must not be inside a delimited group");
26 | }
27 | }
28 |
29 | tokens.extend(iter::once(tt));
30 | cursor = next;
31 | }
32 | tokens
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/common/mod.rs:
--------------------------------------------------------------------------------
1 | #![allow(dead_code)]
2 | #![allow(clippy::module_name_repetitions, clippy::shadow_unrelated)]
3 |
4 | use rayon::ThreadPoolBuilder;
5 | use std::env;
6 |
7 | pub mod eq;
8 | pub mod parse;
9 |
10 | /// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it.
11 | pub fn abort_after() -> usize {
12 | match env::var("ABORT_AFTER_FAILURE") {
13 | Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
14 | Err(_) => usize::max_value(),
15 | }
16 | }
17 |
18 | /// Configure Rayon threadpool.
19 | pub fn rayon_init() {
20 | let stack_size = match env::var("RUST_MIN_STACK") {
21 | Ok(s) => s.parse().expect("failed to parse RUST_MIN_STACK"),
22 | Err(_) => 20 * 1024 * 1024,
23 | };
24 | ThreadPoolBuilder::new()
25 | .stack_size(stack_size)
26 | .build_global()
27 | .unwrap();
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/common/parse.rs:
--------------------------------------------------------------------------------
1 | extern crate rustc_ast;
2 | extern crate rustc_expand;
3 | extern crate rustc_parse as parse;
4 | extern crate rustc_session;
5 | extern crate rustc_span;
6 |
7 | use rustc_ast::ast;
8 | use rustc_ast::ptr::P;
9 | use rustc_session::parse::ParseSess;
10 | use rustc_span::source_map::FilePathMapping;
11 | use rustc_span::FileName;
12 | use std::panic;
13 |
14 | pub fn librustc_expr(input: &str) -> Option> {
15 | match panic::catch_unwind(|| {
16 | let sess = ParseSess::new(FilePathMapping::empty());
17 | let e = parse::new_parser_from_source_str(
18 | &sess,
19 | FileName::Custom("test_precedence".to_string()),
20 | input.to_string(),
21 | )
22 | .parse_expr();
23 | match e {
24 | Ok(expr) => Some(expr),
25 | Err(mut diagnostic) => {
26 | diagnostic.emit();
27 | None
28 | }
29 | }
30 | }) {
31 | Ok(Some(e)) => Some(e),
32 | Ok(None) => None,
33 | Err(_) => {
34 | errorf!("librustc panicked\n");
35 | None
36 | }
37 | }
38 | }
39 |
40 | pub fn syn_expr(input: &str) -> Option {
41 | match syn::parse_str(input) {
42 | Ok(e) => Some(e),
43 | Err(msg) => {
44 | errorf!("syn failed to parse\n{:?}\n", msg);
45 | None
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/regression.rs:
--------------------------------------------------------------------------------
1 | mod regression {
2 | automod::dir!("tests/regression");
3 | }
4 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/regression/issue1108.rs:
--------------------------------------------------------------------------------
1 | #[test]
2 | fn issue1108() {
3 | let data = "impl>::x for";
4 | _ = syn::parse_file(data);
5 | }
6 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/regression/issue1235.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::{Delimiter, Group};
2 | use quote::quote;
3 |
4 | #[test]
5 | fn main() {
6 | // Okay. Rustc allows top-level `static` with no value syntactically, but
7 | // not semantically. Syn parses as Item::Verbatim.
8 | let tokens = quote! {
9 | pub static FOO: usize;
10 | pub static BAR: usize;
11 | };
12 | let file = syn::parse2::(tokens).unwrap();
13 | println!("{:#?}", file);
14 |
15 | // Okay.
16 | let inner = Group::new(
17 | Delimiter::None,
18 | quote!(static FOO: usize = 0; pub static BAR: usize = 0),
19 | );
20 | let tokens = quote!(pub #inner;);
21 | let file = syn::parse2::(tokens).unwrap();
22 | println!("{:#?}", file);
23 |
24 | // Formerly parser crash.
25 | let inner = Group::new(
26 | Delimiter::None,
27 | quote!(static FOO: usize; pub static BAR: usize),
28 | );
29 | let tokens = quote!(pub #inner;);
30 | let file = syn::parse2::(tokens).unwrap();
31 | println!("{:#?}", file);
32 | }
33 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/repo/progress.rs:
--------------------------------------------------------------------------------
1 | use std::io::{Read, Result};
2 | use std::time::{Duration, Instant};
3 |
4 | pub struct Progress {
5 | bytes: usize,
6 | tick: Instant,
7 | stream: R,
8 | }
9 |
10 | impl Progress {
11 | pub fn new(stream: R) -> Self {
12 | Progress {
13 | bytes: 0,
14 | tick: Instant::now() + Duration::from_millis(2000),
15 | stream,
16 | }
17 | }
18 | }
19 |
20 | impl Read for Progress {
21 | fn read(&mut self, buf: &mut [u8]) -> Result {
22 | let num = self.stream.read(buf)?;
23 | self.bytes += num;
24 | let now = Instant::now();
25 | if now > self.tick {
26 | self.tick = now + Duration::from_millis(500);
27 | errorf!("downloading... {} bytes\n", self.bytes);
28 | }
29 | Ok(num)
30 | }
31 | }
32 |
33 | impl Drop for Progress {
34 | fn drop(&mut self) {
35 | errorf!("done ({} bytes)\n", self.bytes);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_asyncness.rs:
--------------------------------------------------------------------------------
1 | #[macro_use]
2 | mod macros;
3 |
4 | use syn::{Expr, Item};
5 |
6 | #[test]
7 | fn test_async_fn() {
8 | let input = "async fn process() {}";
9 |
10 | snapshot!(input as Item, @r###"
11 | Item::Fn {
12 | vis: Inherited,
13 | sig: Signature {
14 | asyncness: Some,
15 | ident: "process",
16 | generics: Generics,
17 | output: Default,
18 | },
19 | block: Block,
20 | }
21 | "###);
22 | }
23 |
24 | #[test]
25 | fn test_async_closure() {
26 | let input = "async || {}";
27 |
28 | snapshot!(input as Expr, @r###"
29 | Expr::Closure {
30 | asyncness: Some,
31 | output: Default,
32 | body: Expr::Block {
33 | block: Block,
34 | },
35 | }
36 | "###);
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_grouping.rs:
--------------------------------------------------------------------------------
1 | #[macro_use]
2 | mod macros;
3 |
4 | use proc_macro2::{Delimiter, Group, Literal, Punct, Spacing, TokenStream, TokenTree};
5 | use std::iter::FromIterator;
6 | use syn::Expr;
7 |
8 | #[test]
9 | fn test_grouping() {
10 | let tokens: TokenStream = TokenStream::from_iter(vec![
11 | TokenTree::Literal(Literal::i32_suffixed(1)),
12 | TokenTree::Punct(Punct::new('+', Spacing::Alone)),
13 | TokenTree::Group(Group::new(
14 | Delimiter::None,
15 | TokenStream::from_iter(vec![
16 | TokenTree::Literal(Literal::i32_suffixed(2)),
17 | TokenTree::Punct(Punct::new('+', Spacing::Alone)),
18 | TokenTree::Literal(Literal::i32_suffixed(3)),
19 | ]),
20 | )),
21 | TokenTree::Punct(Punct::new('*', Spacing::Alone)),
22 | TokenTree::Literal(Literal::i32_suffixed(4)),
23 | ]);
24 |
25 | assert_eq!(tokens.to_string(), "1i32 + 2i32 + 3i32 * 4i32");
26 |
27 | snapshot!(tokens as Expr, @r###"
28 | Expr::Binary {
29 | left: Expr::Lit {
30 | lit: 1i32,
31 | },
32 | op: Add,
33 | right: Expr::Binary {
34 | left: Expr::Group {
35 | expr: Expr::Binary {
36 | left: Expr::Lit {
37 | lit: 2i32,
38 | },
39 | op: Add,
40 | right: Expr::Lit {
41 | lit: 3i32,
42 | },
43 | },
44 | },
45 | op: Mul,
46 | right: Expr::Lit {
47 | lit: 4i32,
48 | },
49 | },
50 | }
51 | "###);
52 | }
53 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_ident.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::{Ident, Span, TokenStream};
2 | use std::str::FromStr;
3 | use syn::Result;
4 |
5 | fn parse(s: &str) -> Result {
6 | syn::parse2(TokenStream::from_str(s).unwrap())
7 | }
8 |
9 | fn new(s: &str) -> Ident {
10 | Ident::new(s, Span::call_site())
11 | }
12 |
13 | #[test]
14 | fn ident_parse() {
15 | parse("String").unwrap();
16 | }
17 |
18 | #[test]
19 | fn ident_parse_keyword() {
20 | parse("abstract").unwrap_err();
21 | }
22 |
23 | #[test]
24 | fn ident_parse_empty() {
25 | parse("").unwrap_err();
26 | }
27 |
28 | #[test]
29 | fn ident_parse_lifetime() {
30 | parse("'static").unwrap_err();
31 | }
32 |
33 | #[test]
34 | fn ident_parse_underscore() {
35 | parse("_").unwrap_err();
36 | }
37 |
38 | #[test]
39 | fn ident_parse_number() {
40 | parse("255").unwrap_err();
41 | }
42 |
43 | #[test]
44 | fn ident_parse_invalid() {
45 | parse("a#").unwrap_err();
46 | }
47 |
48 | #[test]
49 | fn ident_new() {
50 | new("String");
51 | }
52 |
53 | #[test]
54 | fn ident_new_keyword() {
55 | new("abstract");
56 | }
57 |
58 | #[test]
59 | #[should_panic(expected = "use Option")]
60 | fn ident_new_empty() {
61 | new("");
62 | }
63 |
64 | #[test]
65 | #[should_panic(expected = "not a valid Ident")]
66 | fn ident_new_lifetime() {
67 | new("'static");
68 | }
69 |
70 | #[test]
71 | fn ident_new_underscore() {
72 | new("_");
73 | }
74 |
75 | #[test]
76 | #[should_panic(expected = "use Literal instead")]
77 | fn ident_new_number() {
78 | new("255");
79 | }
80 |
81 | #[test]
82 | #[should_panic(expected = "\"a#\" is not a valid Ident")]
83 | fn ident_new_invalid() {
84 | new("a#");
85 | }
86 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_iterators.rs:
--------------------------------------------------------------------------------
1 | use syn::punctuated::{Pair, Punctuated};
2 | use syn::Token;
3 |
4 | #[macro_use]
5 | mod macros;
6 |
7 | macro_rules! check_exact_size_iterator {
8 | ($iter:expr) => {{
9 | let iter = $iter;
10 | let size_hint = iter.size_hint();
11 | let len = iter.len();
12 | let count = iter.count();
13 | assert_eq!(len, count);
14 | assert_eq!(size_hint, (count, Some(count)));
15 | }};
16 | }
17 |
18 | #[test]
19 | fn pairs() {
20 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
21 |
22 | check_exact_size_iterator!(p.pairs());
23 | check_exact_size_iterator!(p.pairs_mut());
24 | check_exact_size_iterator!(p.into_pairs());
25 |
26 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
27 |
28 | assert_eq!(p.pairs().next_back().map(Pair::into_value), Some(&4));
29 | assert_eq!(
30 | p.pairs_mut().next_back().map(Pair::into_value),
31 | Some(&mut 4)
32 | );
33 | assert_eq!(p.into_pairs().next_back().map(Pair::into_value), Some(4));
34 | }
35 |
36 | #[test]
37 | fn iter() {
38 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
39 |
40 | check_exact_size_iterator!(p.iter());
41 | check_exact_size_iterator!(p.iter_mut());
42 | check_exact_size_iterator!(p.into_iter());
43 |
44 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
45 |
46 | assert_eq!(p.iter().next_back(), Some(&4));
47 | assert_eq!(p.iter_mut().next_back(), Some(&mut 4));
48 | assert_eq!(p.into_iter().next_back(), Some(4));
49 | }
50 |
51 | #[test]
52 | fn may_dangle() {
53 | let p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
54 | for element in &p {
55 | if *element == 2 {
56 | drop(p);
57 | break;
58 | }
59 | }
60 |
61 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
62 | for element in &mut p {
63 | if *element == 2 {
64 | drop(p);
65 | break;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_parse_stream.rs:
--------------------------------------------------------------------------------
1 | use syn::ext::IdentExt;
2 | use syn::parse::ParseStream;
3 | use syn::{Ident, Token};
4 |
5 | #[test]
6 | fn test_peek() {
7 | _ = |input: ParseStream| {
8 | _ = input.peek(Ident);
9 | _ = input.peek(Ident::peek_any);
10 | _ = input.peek(Token![::]);
11 | };
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_shebang.rs:
--------------------------------------------------------------------------------
1 | #[macro_use]
2 | mod macros;
3 |
4 | #[test]
5 | fn test_basic() {
6 | let content = "#!/usr/bin/env rustx\nfn main() {}";
7 | let file = syn::parse_file(content).unwrap();
8 | snapshot!(file, @r###"
9 | File {
10 | shebang: Some("#!/usr/bin/env rustx"),
11 | items: [
12 | Item::Fn {
13 | vis: Inherited,
14 | sig: Signature {
15 | ident: "main",
16 | generics: Generics,
17 | output: Default,
18 | },
19 | block: Block,
20 | },
21 | ],
22 | }
23 | "###);
24 | }
25 |
26 | #[test]
27 | fn test_comment() {
28 | let content = "#!//am/i/a/comment\n[allow(dead_code)] fn main() {}";
29 | let file = syn::parse_file(content).unwrap();
30 | snapshot!(file, @r###"
31 | File {
32 | attrs: [
33 | Attribute {
34 | style: Inner,
35 | path: Path {
36 | segments: [
37 | PathSegment {
38 | ident: "allow",
39 | arguments: None,
40 | },
41 | ],
42 | },
43 | tokens: TokenStream(`(dead_code)`),
44 | },
45 | ],
46 | items: [
47 | Item::Fn {
48 | vis: Inherited,
49 | sig: Signature {
50 | ident: "main",
51 | generics: Generics,
52 | output: Default,
53 | },
54 | block: Block,
55 | },
56 | ],
57 | }
58 | "###);
59 | }
60 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_should_parse.rs:
--------------------------------------------------------------------------------
1 | macro_rules! should_parse {
2 | ($name:ident, { $($in:tt)* }) => {
3 | #[test]
4 | fn $name() {
5 | // Make sure we can parse the file!
6 | syn::parse_file(stringify!($($in)*)).unwrap();
7 | }
8 | }
9 | }
10 |
11 | should_parse!(generic_associated_type, {
12 | impl Foo {
13 | type Item = &'a i32;
14 | fn foo<'a>(&'a self) -> Self::Item<'a> {}
15 | }
16 | });
17 |
18 | #[rustfmt::skip]
19 | should_parse!(const_generics_use, {
20 | type X = Foo<5>;
21 | type Y = Foo<"foo">;
22 | type Z = Foo;
23 | type W = Foo<{ X + 10 }>;
24 | });
25 |
26 | should_parse!(trailing_plus_type, {
27 | type A = Box;
28 | type A = Box;
29 | type A = Box<'a + Foo>;
30 | });
31 |
32 | should_parse!(generic_associated_type_where, {
33 | trait Foo {
34 | type Item;
35 | fn foo(&self, t: T) -> Self::Item;
36 | }
37 | });
38 |
39 | should_parse!(match_with_block_expr, {
40 | fn main() {
41 | match false {
42 | _ => {}.a(),
43 | }
44 | }
45 | });
46 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_size.rs:
--------------------------------------------------------------------------------
1 | #![cfg(target_pointer_width = "64")]
2 |
3 | use std::mem;
4 | use syn::{Expr, Item, Lit, Pat, Type};
5 |
6 | #[test]
7 | fn test_expr_size() {
8 | assert_eq!(mem::size_of::(), 272);
9 | }
10 |
11 | #[test]
12 | fn test_item_size() {
13 | assert_eq!(mem::size_of::- (), 320);
14 | }
15 |
16 | #[test]
17 | fn test_type_size() {
18 | assert_eq!(mem::size_of::(), 288);
19 | }
20 |
21 | #[test]
22 | fn test_pat_size() {
23 | assert_eq!(mem::size_of::(), 144);
24 | }
25 |
26 | #[test]
27 | fn test_lit_size() {
28 | assert_eq!(mem::size_of::(), 32);
29 | }
30 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/test_token_trees.rs:
--------------------------------------------------------------------------------
1 | #[macro_use]
2 | mod macros;
3 |
4 | use proc_macro2::TokenStream;
5 | use quote::quote;
6 | use syn::Lit;
7 |
8 | #[test]
9 | fn test_struct() {
10 | let input = "
11 | #[derive(Debug, Clone)]
12 | pub struct Item {
13 | pub ident: Ident,
14 | pub attrs: Vec,
15 | }
16 | ";
17 |
18 | snapshot!(input as TokenStream, @r###"
19 | TokenStream(
20 | `# [derive (Debug , Clone)] pub struct Item { pub ident : Ident , pub attrs : Vec < Attribute >, }`,
21 | )
22 | "###);
23 | }
24 |
25 | #[test]
26 | fn test_literal_mangling() {
27 | let code = "0_4";
28 | let parsed: Lit = syn::parse_str(code).unwrap();
29 | assert_eq!(code, quote!(#parsed).to_string());
30 | }
31 |
--------------------------------------------------------------------------------
/vendor/syn-1.0.109/tests/zzz_stable.rs:
--------------------------------------------------------------------------------
1 | #![cfg(syn_disable_nightly_tests)]
2 |
3 | use std::io::{self, Write};
4 | use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
5 |
6 | const MSG: &str = "\
7 | ‖
8 | ‖ WARNING:
9 | ‖ This is not a nightly compiler so not all tests were able to
10 | ‖ run. Syn includes tests that compare Syn's parser against the
11 | ‖ compiler's parser, which requires access to unstable librustc
12 | ‖ data structures and a nightly compiler.
13 | ‖
14 | ";
15 |
16 | #[test]
17 | fn notice() -> io::Result<()> {
18 | let header = "WARNING";
19 | let index_of_header = MSG.find(header).unwrap();
20 | let before = &MSG[..index_of_header];
21 | let after = &MSG[index_of_header + header.len()..];
22 |
23 | let mut stderr = StandardStream::stderr(ColorChoice::Auto);
24 | stderr.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
25 | write!(&mut stderr, "{}", before)?;
26 | stderr.set_color(ColorSpec::new().set_bold(true).set_fg(Some(Color::Yellow)))?;
27 | write!(&mut stderr, "{}", header)?;
28 | stderr.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
29 | write!(&mut stderr, "{}", after)?;
30 | stderr.reset()?;
31 |
32 | Ok(())
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/syn/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Permission is hereby granted, free of charge, to any
2 | person obtaining a copy of this software and associated
3 | documentation files (the "Software"), to deal in the
4 | Software without restriction, including without
5 | limitation the rights to use, copy, modify, merge,
6 | publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software
8 | is furnished to do so, subject to the following
9 | conditions:
10 |
11 | The above copyright notice and this permission notice
12 | shall be included in all copies or substantial portions
13 | of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/vendor/syn/benches/file.rs:
--------------------------------------------------------------------------------
1 | // $ cargo bench --features full,test --bench file
2 |
3 | #![feature(rustc_private, test)]
4 | #![recursion_limit = "1024"]
5 | #![allow(
6 | clippy::items_after_statements,
7 | clippy::manual_let_else,
8 | clippy::match_like_matches_macro,
9 | clippy::missing_panics_doc,
10 | clippy::must_use_candidate,
11 | clippy::uninlined_format_args
12 | )]
13 |
14 | extern crate test;
15 |
16 | #[macro_use]
17 | #[path = "../tests/macros/mod.rs"]
18 | mod macros;
19 |
20 | #[allow(dead_code)]
21 | #[path = "../tests/repo/mod.rs"]
22 | mod repo;
23 |
24 | use proc_macro2::{Span, TokenStream};
25 | use std::fs;
26 | use std::str::FromStr;
27 | use syn::parse::{ParseStream, Parser};
28 | use test::Bencher;
29 |
30 | const FILE: &str = "tests/rust/library/core/src/str/mod.rs";
31 |
32 | fn get_tokens() -> TokenStream {
33 | repo::clone_rust();
34 | let content = fs::read_to_string(FILE).unwrap();
35 | TokenStream::from_str(&content).unwrap()
36 | }
37 |
38 | #[bench]
39 | fn baseline(b: &mut Bencher) {
40 | let tokens = get_tokens();
41 | b.iter(|| drop(tokens.clone()));
42 | }
43 |
44 | #[bench]
45 | fn create_token_buffer(b: &mut Bencher) {
46 | let tokens = get_tokens();
47 | fn immediate_fail(_input: ParseStream) -> syn::Result<()> {
48 | Err(syn::Error::new(Span::call_site(), ""))
49 | }
50 | b.iter(|| immediate_fail.parse2(tokens.clone()));
51 | }
52 |
53 | #[bench]
54 | fn parse_file(b: &mut Bencher) {
55 | let tokens = get_tokens();
56 | b.iter(|| syn::parse2::(tokens.clone()));
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/syn/src/bigint.rs:
--------------------------------------------------------------------------------
1 | use std::ops::{AddAssign, MulAssign};
2 |
3 | // For implementing base10_digits() accessor on LitInt.
4 | pub(crate) struct BigInt {
5 | digits: Vec,
6 | }
7 |
8 | impl BigInt {
9 | pub(crate) fn new() -> Self {
10 | BigInt { digits: Vec::new() }
11 | }
12 |
13 | pub(crate) fn to_string(&self) -> String {
14 | let mut repr = String::with_capacity(self.digits.len());
15 |
16 | let mut has_nonzero = false;
17 | for digit in self.digits.iter().rev() {
18 | has_nonzero |= *digit != 0;
19 | if has_nonzero {
20 | repr.push((*digit + b'0') as char);
21 | }
22 | }
23 |
24 | if repr.is_empty() {
25 | repr.push('0');
26 | }
27 |
28 | repr
29 | }
30 |
31 | fn reserve_two_digits(&mut self) {
32 | let len = self.digits.len();
33 | let desired =
34 | len + !self.digits.ends_with(&[0, 0]) as usize + !self.digits.ends_with(&[0]) as usize;
35 | self.digits.resize(desired, 0);
36 | }
37 | }
38 |
39 | impl AddAssign for BigInt {
40 | // Assumes increment <16.
41 | fn add_assign(&mut self, mut increment: u8) {
42 | self.reserve_two_digits();
43 |
44 | let mut i = 0;
45 | while increment > 0 {
46 | let sum = self.digits[i] + increment;
47 | self.digits[i] = sum % 10;
48 | increment = sum / 10;
49 | i += 1;
50 | }
51 | }
52 | }
53 |
54 | impl MulAssign for BigInt {
55 | // Assumes base <=16.
56 | fn mul_assign(&mut self, base: u8) {
57 | self.reserve_two_digits();
58 |
59 | let mut carry = 0;
60 | for digit in &mut self.digits {
61 | let prod = *digit * base + carry;
62 | *digit = prod % 10;
63 | carry = prod / 10;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/vendor/syn/src/drops.rs:
--------------------------------------------------------------------------------
1 | use std::iter;
2 | use std::mem::ManuallyDrop;
3 | use std::ops::{Deref, DerefMut};
4 | use std::option;
5 | use std::slice;
6 |
7 | #[repr(transparent)]
8 | pub(crate) struct NoDrop(ManuallyDrop);
9 |
10 | impl NoDrop {
11 | pub(crate) fn new(value: T) -> Self
12 | where
13 | T: TrivialDrop,
14 | {
15 | NoDrop(ManuallyDrop::new(value))
16 | }
17 | }
18 |
19 | impl Deref for NoDrop {
20 | type Target = T;
21 | fn deref(&self) -> &Self::Target {
22 | &self.0
23 | }
24 | }
25 |
26 | impl DerefMut for NoDrop {
27 | fn deref_mut(&mut self) -> &mut Self::Target {
28 | &mut self.0
29 | }
30 | }
31 |
32 | pub(crate) trait TrivialDrop {}
33 |
34 | impl TrivialDrop for iter::Empty {}
35 | impl<'a, T> TrivialDrop for slice::Iter<'a, T> {}
36 | impl<'a, T> TrivialDrop for slice::IterMut<'a, T> {}
37 | impl<'a, T> TrivialDrop for option::IntoIter<&'a T> {}
38 | impl<'a, T> TrivialDrop for option::IntoIter<&'a mut T> {}
39 |
40 | #[test]
41 | fn test_needs_drop() {
42 | use std::mem::needs_drop;
43 |
44 | struct NeedsDrop;
45 |
46 | impl Drop for NeedsDrop {
47 | fn drop(&mut self) {}
48 | }
49 |
50 | assert!(needs_drop::());
51 |
52 | // Test each of the types with a handwritten TrivialDrop impl above.
53 | assert!(!needs_drop::>());
54 | assert!(!needs_drop::>());
55 | assert!(!needs_drop::>());
56 | assert!(!needs_drop::>());
57 | assert!(!needs_drop::>());
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/syn/src/export.rs:
--------------------------------------------------------------------------------
1 | #[doc(hidden)]
2 | pub use std::clone::Clone;
3 | #[doc(hidden)]
4 | pub use std::cmp::{Eq, PartialEq};
5 | #[doc(hidden)]
6 | pub use std::concat;
7 | #[doc(hidden)]
8 | pub use std::default::Default;
9 | #[doc(hidden)]
10 | pub use std::fmt::Debug;
11 | #[doc(hidden)]
12 | pub use std::hash::{Hash, Hasher};
13 | #[doc(hidden)]
14 | pub use std::marker::Copy;
15 | #[doc(hidden)]
16 | pub use std::option::Option::{None, Some};
17 | #[doc(hidden)]
18 | pub use std::result::Result::{Err, Ok};
19 | #[doc(hidden)]
20 | pub use std::stringify;
21 |
22 | #[doc(hidden)]
23 | pub type Formatter<'a> = std::fmt::Formatter<'a>;
24 | #[doc(hidden)]
25 | pub type FmtResult = std::fmt::Result;
26 |
27 | #[doc(hidden)]
28 | pub type bool = std::primitive::bool;
29 | #[doc(hidden)]
30 | pub type str = std::primitive::str;
31 |
32 | #[cfg(feature = "printing")]
33 | #[doc(hidden)]
34 | pub use quote;
35 |
36 | #[doc(hidden)]
37 | pub type Span = proc_macro2::Span;
38 | #[doc(hidden)]
39 | pub type TokenStream2 = proc_macro2::TokenStream;
40 |
41 | #[cfg(feature = "parsing")]
42 | #[doc(hidden)]
43 | pub use crate::group::{parse_braces, parse_brackets, parse_parens};
44 |
45 | #[doc(hidden)]
46 | pub use crate::span::IntoSpans;
47 |
48 | #[cfg(all(feature = "parsing", feature = "printing"))]
49 | #[doc(hidden)]
50 | pub use crate::parse_quote::parse as parse_quote;
51 |
52 | #[cfg(feature = "parsing")]
53 | #[doc(hidden)]
54 | pub use crate::token::parsing::{peek_punct, punct as parse_punct};
55 |
56 | #[cfg(feature = "printing")]
57 | #[doc(hidden)]
58 | pub use crate::token::printing::punct as print_punct;
59 |
60 | #[cfg(feature = "parsing")]
61 | #[doc(hidden)]
62 | pub use crate::token::private::CustomToken;
63 |
64 | #[cfg(feature = "proc-macro")]
65 | #[doc(hidden)]
66 | pub type TokenStream = proc_macro::TokenStream;
67 |
68 | #[cfg(feature = "printing")]
69 | #[doc(hidden)]
70 | pub use quote::{ToTokens, TokenStreamExt};
71 |
72 | #[doc(hidden)]
73 | pub struct private(pub(crate) ());
74 |
--------------------------------------------------------------------------------
/vendor/syn/src/gen_helper.rs:
--------------------------------------------------------------------------------
1 | #[cfg(feature = "fold")]
2 | pub(crate) mod fold {
3 | use crate::punctuated::{Pair, Punctuated};
4 |
5 | pub(crate) trait FoldHelper {
6 | type Item;
7 | fn lift(self, f: F) -> Self
8 | where
9 | F: FnMut(Self::Item) -> Self::Item;
10 | }
11 |
12 | impl FoldHelper for Vec {
13 | type Item = T;
14 | fn lift(self, f: F) -> Self
15 | where
16 | F: FnMut(Self::Item) -> Self::Item,
17 | {
18 | self.into_iter().map(f).collect()
19 | }
20 | }
21 |
22 | impl FoldHelper for Punctuated {
23 | type Item = T;
24 | fn lift(self, mut f: F) -> Self
25 | where
26 | F: FnMut(Self::Item) -> Self::Item,
27 | {
28 | self.into_pairs()
29 | .map(Pair::into_tuple)
30 | .map(|(t, u)| Pair::new(f(t), u))
31 | .collect()
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/vendor/syn/src/print.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::TokenStream;
2 | use quote::ToTokens;
3 |
4 | pub(crate) struct TokensOrDefault<'a, T: 'a>(pub &'a Option);
5 |
6 | impl<'a, T> ToTokens for TokensOrDefault<'a, T>
7 | where
8 | T: ToTokens + Default,
9 | {
10 | fn to_tokens(&self, tokens: &mut TokenStream) {
11 | match self.0 {
12 | Some(t) => t.to_tokens(tokens),
13 | None => T::default().to_tokens(tokens),
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/syn/src/sealed.rs:
--------------------------------------------------------------------------------
1 | #[cfg(feature = "parsing")]
2 | pub(crate) mod lookahead {
3 | pub trait Sealed: Copy {}
4 | }
5 |
--------------------------------------------------------------------------------
/vendor/syn/src/span.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::extra::DelimSpan;
2 | use proc_macro2::{Delimiter, Group, Span, TokenStream};
3 |
4 | #[doc(hidden)]
5 | pub trait IntoSpans
{
6 | fn into_spans(self) -> S;
7 | }
8 |
9 | impl IntoSpans for Span {
10 | fn into_spans(self) -> Span {
11 | self
12 | }
13 | }
14 |
15 | impl IntoSpans<[Span; 1]> for Span {
16 | fn into_spans(self) -> [Span; 1] {
17 | [self]
18 | }
19 | }
20 |
21 | impl IntoSpans<[Span; 2]> for Span {
22 | fn into_spans(self) -> [Span; 2] {
23 | [self, self]
24 | }
25 | }
26 |
27 | impl IntoSpans<[Span; 3]> for Span {
28 | fn into_spans(self) -> [Span; 3] {
29 | [self, self, self]
30 | }
31 | }
32 |
33 | impl IntoSpans<[Span; 1]> for [Span; 1] {
34 | fn into_spans(self) -> [Span; 1] {
35 | self
36 | }
37 | }
38 |
39 | impl IntoSpans<[Span; 2]> for [Span; 2] {
40 | fn into_spans(self) -> [Span; 2] {
41 | self
42 | }
43 | }
44 |
45 | impl IntoSpans<[Span; 3]> for [Span; 3] {
46 | fn into_spans(self) -> [Span; 3] {
47 | self
48 | }
49 | }
50 |
51 | impl IntoSpans for Span {
52 | fn into_spans(self) -> DelimSpan {
53 | let mut group = Group::new(Delimiter::None, TokenStream::new());
54 | group.set_span(self);
55 | group.delim_span()
56 | }
57 | }
58 |
59 | impl IntoSpans for DelimSpan {
60 | fn into_spans(self) -> DelimSpan {
61 | self
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/vendor/syn/src/verbatim.rs:
--------------------------------------------------------------------------------
1 | use crate::parse::ParseStream;
2 | use proc_macro2::{Delimiter, TokenStream};
3 | use std::cmp::Ordering;
4 | use std::iter;
5 |
6 | pub(crate) fn between<'a>(begin: ParseStream<'a>, end: ParseStream<'a>) -> TokenStream {
7 | let end = end.cursor();
8 | let mut cursor = begin.cursor();
9 | assert!(crate::buffer::same_buffer(end, cursor));
10 |
11 | let mut tokens = TokenStream::new();
12 | while cursor != end {
13 | let (tt, next) = cursor.token_tree().unwrap();
14 |
15 | if crate::buffer::cmp_assuming_same_buffer(end, next) == Ordering::Less {
16 | // A syntax node can cross the boundary of a None-delimited group
17 | // due to such groups being transparent to the parser in most cases.
18 | // Any time this occurs the group is known to be semantically
19 | // irrelevant. https://github.com/dtolnay/syn/issues/1235
20 | if let Some((inside, _span, after)) = cursor.group(Delimiter::None) {
21 | assert!(next == after);
22 | cursor = inside;
23 | continue;
24 | } else {
25 | panic!("verbatim end must not be inside a delimited group");
26 | }
27 | }
28 |
29 | tokens.extend(iter::once(tt));
30 | cursor = next;
31 | }
32 | tokens
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/syn/tests/common/mod.rs:
--------------------------------------------------------------------------------
1 | #![allow(dead_code)]
2 | #![allow(clippy::module_name_repetitions, clippy::shadow_unrelated)]
3 |
4 | use rayon::ThreadPoolBuilder;
5 | use std::env;
6 |
7 | pub mod eq;
8 | pub mod parse;
9 |
10 | /// Read the `ABORT_AFTER_FAILURE` environment variable, and parse it.
11 | pub fn abort_after() -> usize {
12 | match env::var("ABORT_AFTER_FAILURE") {
13 | Ok(s) => s.parse().expect("failed to parse ABORT_AFTER_FAILURE"),
14 | Err(_) => usize::max_value(),
15 | }
16 | }
17 |
18 | /// Configure Rayon threadpool.
19 | pub fn rayon_init() {
20 | let stack_size = match env::var("RUST_MIN_STACK") {
21 | Ok(s) => s.parse().expect("failed to parse RUST_MIN_STACK"),
22 | Err(_) => 20 * 1024 * 1024,
23 | };
24 | ThreadPoolBuilder::new()
25 | .stack_size(stack_size)
26 | .build_global()
27 | .unwrap();
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/syn/tests/common/parse.rs:
--------------------------------------------------------------------------------
1 | extern crate rustc_ast;
2 | extern crate rustc_driver;
3 | extern crate rustc_expand;
4 | extern crate rustc_parse as parse;
5 | extern crate rustc_session;
6 | extern crate rustc_span;
7 |
8 | use rustc_ast::ast;
9 | use rustc_ast::ptr::P;
10 | use rustc_session::parse::ParseSess;
11 | use rustc_span::source_map::FilePathMapping;
12 | use rustc_span::FileName;
13 | use std::panic;
14 |
15 | pub fn librustc_expr(input: &str) -> Option> {
16 | match panic::catch_unwind(|| {
17 | let locale_resources = rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec();
18 | let file_path_mapping = FilePathMapping::empty();
19 | let sess = ParseSess::new(locale_resources, file_path_mapping);
20 | let e = parse::new_parser_from_source_str(
21 | &sess,
22 | FileName::Custom("test_precedence".to_string()),
23 | input.to_string(),
24 | )
25 | .parse_expr();
26 | match e {
27 | Ok(expr) => Some(expr),
28 | Err(diagnostic) => {
29 | diagnostic.emit();
30 | None
31 | }
32 | }
33 | }) {
34 | Ok(Some(e)) => Some(e),
35 | Ok(None) => None,
36 | Err(_) => {
37 | errorf!("librustc panicked\n");
38 | None
39 | }
40 | }
41 | }
42 |
43 | pub fn syn_expr(input: &str) -> Option {
44 | match syn::parse_str(input) {
45 | Ok(e) => Some(e),
46 | Err(msg) => {
47 | errorf!("syn failed to parse\n{:?}\n", msg);
48 | None
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/vendor/syn/tests/regression.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::let_underscore_untyped, clippy::uninlined_format_args)]
2 |
3 | mod regression {
4 | automod::dir!("tests/regression");
5 | }
6 |
--------------------------------------------------------------------------------
/vendor/syn/tests/regression/issue1108.rs:
--------------------------------------------------------------------------------
1 | #[test]
2 | fn issue1108() {
3 | let data = "impl>::x for";
4 | let _ = syn::parse_file(data);
5 | }
6 |
--------------------------------------------------------------------------------
/vendor/syn/tests/regression/issue1235.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::{Delimiter, Group};
2 | use quote::quote;
3 |
4 | #[test]
5 | fn main() {
6 | // Okay. Rustc allows top-level `static` with no value syntactically, but
7 | // not semantically. Syn parses as Item::Verbatim.
8 | let tokens = quote! {
9 | pub static FOO: usize;
10 | pub static BAR: usize;
11 | };
12 | let file = syn::parse2::(tokens).unwrap();
13 | println!("{:#?}", file);
14 |
15 | // Okay.
16 | let inner = Group::new(
17 | Delimiter::None,
18 | quote!(static FOO: usize = 0; pub static BAR: usize = 0),
19 | );
20 | let tokens = quote!(pub #inner;);
21 | let file = syn::parse2::(tokens).unwrap();
22 | println!("{:#?}", file);
23 |
24 | // Formerly parser crash.
25 | let inner = Group::new(
26 | Delimiter::None,
27 | quote!(static FOO: usize; pub static BAR: usize),
28 | );
29 | let tokens = quote!(pub #inner;);
30 | let file = syn::parse2::(tokens).unwrap();
31 | println!("{:#?}", file);
32 | }
33 |
--------------------------------------------------------------------------------
/vendor/syn/tests/repo/progress.rs:
--------------------------------------------------------------------------------
1 | use std::io::{Read, Result};
2 | use std::time::{Duration, Instant};
3 |
4 | pub struct Progress {
5 | bytes: usize,
6 | tick: Instant,
7 | stream: R,
8 | }
9 |
10 | impl Progress {
11 | pub fn new(stream: R) -> Self {
12 | Progress {
13 | bytes: 0,
14 | tick: Instant::now() + Duration::from_millis(2000),
15 | stream,
16 | }
17 | }
18 | }
19 |
20 | impl Read for Progress {
21 | fn read(&mut self, buf: &mut [u8]) -> Result {
22 | let num = self.stream.read(buf)?;
23 | self.bytes += num;
24 | let now = Instant::now();
25 | if now > self.tick {
26 | self.tick = now + Duration::from_millis(500);
27 | errorf!("downloading... {} bytes\n", self.bytes);
28 | }
29 | Ok(num)
30 | }
31 | }
32 |
33 | impl Drop for Progress {
34 | fn drop(&mut self) {
35 | errorf!("done ({} bytes)\n", self.bytes);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_asyncness.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::uninlined_format_args)]
2 |
3 | #[macro_use]
4 | mod macros;
5 |
6 | use syn::{Expr, Item};
7 |
8 | #[test]
9 | fn test_async_fn() {
10 | let input = "async fn process() {}";
11 |
12 | snapshot!(input as Item, @r###"
13 | Item::Fn {
14 | vis: Visibility::Inherited,
15 | sig: Signature {
16 | asyncness: Some,
17 | ident: "process",
18 | generics: Generics,
19 | output: ReturnType::Default,
20 | },
21 | block: Block {
22 | stmts: [],
23 | },
24 | }
25 | "###);
26 | }
27 |
28 | #[test]
29 | fn test_async_closure() {
30 | let input = "async || {}";
31 |
32 | snapshot!(input as Expr, @r###"
33 | Expr::Closure {
34 | asyncness: Some,
35 | output: ReturnType::Default,
36 | body: Expr::Block {
37 | block: Block {
38 | stmts: [],
39 | },
40 | },
41 | }
42 | "###);
43 | }
44 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_grouping.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::uninlined_format_args)]
2 |
3 | #[macro_use]
4 | mod macros;
5 |
6 | use proc_macro2::{Delimiter, Group, Literal, Punct, Spacing, TokenStream, TokenTree};
7 | use syn::Expr;
8 |
9 | #[test]
10 | fn test_grouping() {
11 | let tokens: TokenStream = TokenStream::from_iter(vec![
12 | TokenTree::Literal(Literal::i32_suffixed(1)),
13 | TokenTree::Punct(Punct::new('+', Spacing::Alone)),
14 | TokenTree::Group(Group::new(
15 | Delimiter::None,
16 | TokenStream::from_iter(vec![
17 | TokenTree::Literal(Literal::i32_suffixed(2)),
18 | TokenTree::Punct(Punct::new('+', Spacing::Alone)),
19 | TokenTree::Literal(Literal::i32_suffixed(3)),
20 | ]),
21 | )),
22 | TokenTree::Punct(Punct::new('*', Spacing::Alone)),
23 | TokenTree::Literal(Literal::i32_suffixed(4)),
24 | ]);
25 |
26 | assert_eq!(tokens.to_string(), "1i32 + 2i32 + 3i32 * 4i32");
27 |
28 | snapshot!(tokens as Expr, @r###"
29 | Expr::Binary {
30 | left: Expr::Lit {
31 | lit: 1i32,
32 | },
33 | op: BinOp::Add,
34 | right: Expr::Binary {
35 | left: Expr::Group {
36 | expr: Expr::Binary {
37 | left: Expr::Lit {
38 | lit: 2i32,
39 | },
40 | op: BinOp::Add,
41 | right: Expr::Lit {
42 | lit: 3i32,
43 | },
44 | },
45 | },
46 | op: BinOp::Mul,
47 | right: Expr::Lit {
48 | lit: 4i32,
49 | },
50 | },
51 | }
52 | "###);
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_ident.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::{Ident, Span, TokenStream};
2 | use std::str::FromStr;
3 | use syn::Result;
4 |
5 | fn parse(s: &str) -> Result {
6 | syn::parse2(TokenStream::from_str(s).unwrap())
7 | }
8 |
9 | fn new(s: &str) -> Ident {
10 | Ident::new(s, Span::call_site())
11 | }
12 |
13 | #[test]
14 | fn ident_parse() {
15 | parse("String").unwrap();
16 | }
17 |
18 | #[test]
19 | fn ident_parse_keyword() {
20 | parse("abstract").unwrap_err();
21 | }
22 |
23 | #[test]
24 | fn ident_parse_empty() {
25 | parse("").unwrap_err();
26 | }
27 |
28 | #[test]
29 | fn ident_parse_lifetime() {
30 | parse("'static").unwrap_err();
31 | }
32 |
33 | #[test]
34 | fn ident_parse_underscore() {
35 | parse("_").unwrap_err();
36 | }
37 |
38 | #[test]
39 | fn ident_parse_number() {
40 | parse("255").unwrap_err();
41 | }
42 |
43 | #[test]
44 | fn ident_parse_invalid() {
45 | parse("a#").unwrap_err();
46 | }
47 |
48 | #[test]
49 | fn ident_new() {
50 | new("String");
51 | }
52 |
53 | #[test]
54 | fn ident_new_keyword() {
55 | new("abstract");
56 | }
57 |
58 | #[test]
59 | #[should_panic(expected = "use Option")]
60 | fn ident_new_empty() {
61 | new("");
62 | }
63 |
64 | #[test]
65 | #[should_panic(expected = "not a valid Ident")]
66 | fn ident_new_lifetime() {
67 | new("'static");
68 | }
69 |
70 | #[test]
71 | fn ident_new_underscore() {
72 | new("_");
73 | }
74 |
75 | #[test]
76 | #[should_panic(expected = "use Literal instead")]
77 | fn ident_new_number() {
78 | new("255");
79 | }
80 |
81 | #[test]
82 | #[should_panic(expected = "\"a#\" is not a valid Ident")]
83 | fn ident_new_invalid() {
84 | new("a#");
85 | }
86 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_iterators.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::uninlined_format_args)]
2 |
3 | use syn::punctuated::{Pair, Punctuated};
4 | use syn::Token;
5 |
6 | #[macro_use]
7 | mod macros;
8 |
9 | macro_rules! check_exact_size_iterator {
10 | ($iter:expr) => {{
11 | let iter = $iter;
12 | let size_hint = iter.size_hint();
13 | let len = iter.len();
14 | let count = iter.count();
15 | assert_eq!(len, count);
16 | assert_eq!(size_hint, (count, Some(count)));
17 | }};
18 | }
19 |
20 | #[test]
21 | fn pairs() {
22 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
23 |
24 | check_exact_size_iterator!(p.pairs());
25 | check_exact_size_iterator!(p.pairs_mut());
26 | check_exact_size_iterator!(p.into_pairs());
27 |
28 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
29 |
30 | assert_eq!(p.pairs().next_back().map(Pair::into_value), Some(&4));
31 | assert_eq!(
32 | p.pairs_mut().next_back().map(Pair::into_value),
33 | Some(&mut 4)
34 | );
35 | assert_eq!(p.into_pairs().next_back().map(Pair::into_value), Some(4));
36 | }
37 |
38 | #[test]
39 | fn iter() {
40 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
41 |
42 | check_exact_size_iterator!(p.iter());
43 | check_exact_size_iterator!(p.iter_mut());
44 | check_exact_size_iterator!(p.into_iter());
45 |
46 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
47 |
48 | assert_eq!(p.iter().next_back(), Some(&4));
49 | assert_eq!(p.iter_mut().next_back(), Some(&mut 4));
50 | assert_eq!(p.into_iter().next_back(), Some(4));
51 | }
52 |
53 | #[test]
54 | fn may_dangle() {
55 | let p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
56 | for element in &p {
57 | if *element == 2 {
58 | drop(p);
59 | break;
60 | }
61 | }
62 |
63 | let mut p: Punctuated<_, Token![,]> = punctuated!(2, 3, 4);
64 | for element in &mut p {
65 | if *element == 2 {
66 | drop(p);
67 | break;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_parse_stream.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::let_underscore_untyped)]
2 |
3 | use syn::ext::IdentExt as _;
4 | use syn::parse::ParseStream;
5 | use syn::{Ident, Token};
6 |
7 | #[test]
8 | fn test_peek() {
9 | let _ = |input: ParseStream| {
10 | let _ = input.peek(Ident);
11 | let _ = input.peek(Ident::peek_any);
12 | let _ = input.peek(Token![::]);
13 | };
14 | }
15 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_shebang.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::uninlined_format_args)]
2 |
3 | #[macro_use]
4 | mod macros;
5 |
6 | #[test]
7 | fn test_basic() {
8 | let content = "#!/usr/bin/env rustx\nfn main() {}";
9 | let file = syn::parse_file(content).unwrap();
10 | snapshot!(file, @r###"
11 | File {
12 | shebang: Some("#!/usr/bin/env rustx"),
13 | items: [
14 | Item::Fn {
15 | vis: Visibility::Inherited,
16 | sig: Signature {
17 | ident: "main",
18 | generics: Generics,
19 | output: ReturnType::Default,
20 | },
21 | block: Block {
22 | stmts: [],
23 | },
24 | },
25 | ],
26 | }
27 | "###);
28 | }
29 |
30 | #[test]
31 | fn test_comment() {
32 | let content = "#!//am/i/a/comment\n[allow(dead_code)] fn main() {}";
33 | let file = syn::parse_file(content).unwrap();
34 | snapshot!(file, @r###"
35 | File {
36 | attrs: [
37 | Attribute {
38 | style: AttrStyle::Inner,
39 | meta: Meta::List {
40 | path: Path {
41 | segments: [
42 | PathSegment {
43 | ident: "allow",
44 | },
45 | ],
46 | },
47 | delimiter: MacroDelimiter::Paren,
48 | tokens: TokenStream(`dead_code`),
49 | },
50 | },
51 | ],
52 | items: [
53 | Item::Fn {
54 | vis: Visibility::Inherited,
55 | sig: Signature {
56 | ident: "main",
57 | generics: Generics,
58 | output: ReturnType::Default,
59 | },
60 | block: Block {
61 | stmts: [],
62 | },
63 | },
64 | ],
65 | }
66 | "###);
67 | }
68 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_should_parse.rs:
--------------------------------------------------------------------------------
1 | macro_rules! should_parse {
2 | ($name:ident, { $($in:tt)* }) => {
3 | #[test]
4 | fn $name() {
5 | // Make sure we can parse the file!
6 | syn::parse_file(stringify!($($in)*)).unwrap();
7 | }
8 | }
9 | }
10 |
11 | should_parse!(generic_associated_type, {
12 | impl Foo {
13 | type Item = &'a i32;
14 | fn foo<'a>(&'a self) -> Self::Item<'a> {}
15 | }
16 | });
17 |
18 | #[rustfmt::skip]
19 | should_parse!(const_generics_use, {
20 | type X = Foo<5>;
21 | type Y = Foo<"foo">;
22 | type Z = Foo;
23 | type W = Foo<{ X + 10 }>;
24 | });
25 |
26 | should_parse!(trailing_plus_type, {
27 | type A = Box;
28 | type A = Box;
29 | type A = Box<'a + Foo>;
30 | });
31 |
32 | should_parse!(generic_associated_type_where, {
33 | trait Foo {
34 | type Item;
35 | fn foo(&self, t: T) -> Self::Item;
36 | }
37 | });
38 |
39 | should_parse!(match_with_block_expr, {
40 | fn main() {
41 | match false {
42 | _ => {}.a(),
43 | }
44 | }
45 | });
46 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_size.rs:
--------------------------------------------------------------------------------
1 | // Assumes proc-macro2's "span-locations" feature is off.
2 |
3 | #![cfg(target_pointer_width = "64")]
4 |
5 | use std::mem;
6 | use syn::{Expr, Item, Lit, Pat, Type};
7 |
8 | #[rustversion::attr(before(2022-11-24), ignore)]
9 | #[test]
10 | fn test_expr_size() {
11 | assert_eq!(mem::size_of::(), 176);
12 | }
13 |
14 | #[rustversion::attr(before(2022-09-09), ignore)]
15 | #[test]
16 | fn test_item_size() {
17 | assert_eq!(mem::size_of::- (), 360);
18 | }
19 |
20 | #[rustversion::attr(before(2023-04-29), ignore)]
21 | #[test]
22 | fn test_type_size() {
23 | assert_eq!(mem::size_of::(), 232);
24 | }
25 |
26 | #[rustversion::attr(before(2023-04-29), ignore)]
27 | #[test]
28 | fn test_pat_size() {
29 | assert_eq!(mem::size_of::(), 184);
30 | }
31 |
32 | #[rustversion::attr(before(2023-12-20), ignore)]
33 | #[test]
34 | fn test_lit_size() {
35 | assert_eq!(mem::size_of::(), 24);
36 | }
37 |
--------------------------------------------------------------------------------
/vendor/syn/tests/test_token_trees.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::uninlined_format_args)]
2 |
3 | #[macro_use]
4 | mod macros;
5 |
6 | use proc_macro2::TokenStream;
7 | use quote::quote;
8 | use syn::Lit;
9 |
10 | #[test]
11 | fn test_struct() {
12 | let input = "
13 | #[derive(Debug, Clone)]
14 | pub struct Item {
15 | pub ident: Ident,
16 | pub attrs: Vec,
17 | }
18 | ";
19 |
20 | snapshot!(input as TokenStream, @r###"
21 | TokenStream(
22 | `# [derive (Debug , Clone)] pub struct Item { pub ident : Ident , pub attrs : Vec < Attribute >, }`,
23 | )
24 | "###);
25 | }
26 |
27 | #[test]
28 | fn test_literal_mangling() {
29 | let code = "0_4";
30 | let parsed: Lit = syn::parse_str(code).unwrap();
31 | assert_eq!(code, quote!(#parsed).to_string());
32 | }
33 |
--------------------------------------------------------------------------------
/vendor/syn/tests/zzz_stable.rs:
--------------------------------------------------------------------------------
1 | #![cfg(syn_disable_nightly_tests)]
2 |
3 | use std::io::{self, Write};
4 | use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
5 |
6 | const MSG: &str = "\
7 | ‖
8 | ‖ WARNING:
9 | ‖ This is not a nightly compiler so not all tests were able to
10 | ‖ run. Syn includes tests that compare Syn's parser against the
11 | ‖ compiler's parser, which requires access to unstable librustc
12 | ‖ data structures and a nightly compiler.
13 | ‖
14 | ";
15 |
16 | #[test]
17 | fn notice() -> io::Result<()> {
18 | let header = "WARNING";
19 | let index_of_header = MSG.find(header).unwrap();
20 | let before = &MSG[..index_of_header];
21 | let after = &MSG[index_of_header + header.len()..];
22 |
23 | let mut stderr = StandardStream::stderr(ColorChoice::Auto);
24 | stderr.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
25 | write!(&mut stderr, "{}", before)?;
26 | stderr.set_color(ColorSpec::new().set_bold(true).set_fg(Some(Color::Yellow)))?;
27 | write!(&mut stderr, "{}", header)?;
28 | stderr.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
29 | write!(&mut stderr, "{}", after)?;
30 | stderr.reset()?;
31 |
32 | Ok(())
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/.cargo-checksum.json:
--------------------------------------------------------------------------------
1 | {"files":{"Cargo.toml":"7b10355305359d5feefb120329396a8823ce903cd66612d7d27612d51e6ceced","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","LICENSE-UNICODE":"68f5b9f5ea36881a0942ba02f558e9e1faf76cc09cb165ad801744c61b738844","README.md":"eff1f30712e93cc160101c25bf31738448c284b90636deb3e3a651cb9ad20dd1","benches/xid.rs":"a61f61ecc7d5124c759cdeb55ab74470ab69f2f3ca37613da65f16e0e5e33487","src/lib.rs":"2673969775cff349816e3fb30f62476a802523fe4940482288b75bd747cbe748","src/tables.rs":"ffe8e252eabccf261385865cb781b3d76c9f32f6f9503d00196a30fb92d80b29","tests/compare.rs":"62471ffb157744cac6faae1adafdbdf785349d7eb6dc2ff4b4941c9d618397f9","tests/fst/mod.rs":"69a3aaf59acd8bca962ecc6234be56be8c0934ab79b253162f10eb881523901f","tests/fst/xid_continue.fst":"41fc751514b8bde658544d5fe7e100115d299d41897af855934b9f4ebda9d3a2","tests/fst/xid_start.fst":"ffa5e2bfe7dd5f6738fbe4b7a3e6e2083c9777191c54f8291a80d558ec4e2dd2","tests/roaring/mod.rs":"784f65a48477fab7549620c7843c7ad6da533f69a18abca1172f6acb95045e53","tests/static_size.rs":"4524332c1e424cb987d7cee1f47a98aea9ed7b256303a3828eda5aa1d06da240","tests/tables/mod.rs":"e6949172d10fc4b2431ce7546269bfd4f9146454c8c3e31faf5e5d80c16a8ab6","tests/tables/tables.rs":"011404dab8a3958da6e18a1fe9406c191675e6f49bf30ce813e3d05f582e750b","tests/trie/mod.rs":"d4acbb716bcbaf80660039797f45e138ed8bbd66749fa3b19b1a971574679cc9","tests/trie/trie.rs":"3c1ca56062f1b3ffdf2ae2063d3fee8d362b90082778056181b5c95e2e242ad8"},"package":"3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"}
--------------------------------------------------------------------------------
/vendor/unicode-ident/Cargo.toml:
--------------------------------------------------------------------------------
1 | # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
2 | #
3 | # When uploading crates to the registry Cargo will automatically
4 | # "normalize" Cargo.toml files for maximal compatibility
5 | # with all versions of Cargo and also rewrite `path` dependencies
6 | # to registry (e.g., crates.io) dependencies.
7 | #
8 | # If you are reading this file be aware that the original Cargo.toml
9 | # will likely look very different (and much more reasonable).
10 | # See Cargo.toml.orig for the original contents.
11 |
12 | [package]
13 | edition = "2018"
14 | rust-version = "1.31"
15 | name = "unicode-ident"
16 | version = "1.0.12"
17 | authors = ["David Tolnay "]
18 | description = "Determine whether characters have the XID_Start or XID_Continue properties according to Unicode Standard Annex #31"
19 | documentation = "https://docs.rs/unicode-ident"
20 | readme = "README.md"
21 | keywords = [
22 | "unicode",
23 | "xid",
24 | ]
25 | categories = [
26 | "development-tools::procedural-macro-helpers",
27 | "no-std",
28 | "no-std::no-alloc",
29 | ]
30 | license = "(MIT OR Apache-2.0) AND Unicode-DFS-2016"
31 | repository = "https://github.com/dtolnay/unicode-ident"
32 |
33 | [package.metadata.docs.rs]
34 | rustdoc-args = ["--generate-link-to-definition"]
35 | targets = ["x86_64-unknown-linux-gnu"]
36 |
37 | [lib]
38 | doc-scrape-examples = false
39 |
40 | [[bench]]
41 | name = "xid"
42 | harness = false
43 |
44 | [dev-dependencies.criterion]
45 | version = "0.5"
46 | default-features = false
47 |
48 | [dev-dependencies.fst]
49 | version = "0.4"
50 |
51 | [dev-dependencies.rand]
52 | version = "0.8"
53 | features = ["small_rng"]
54 |
55 | [dev-dependencies.roaring]
56 | version = "0.10"
57 |
58 | [dev-dependencies.ucd-trie]
59 | version = "0.1"
60 | default-features = false
61 |
62 | [dev-dependencies.unicode-xid]
63 | version = "0.2.4"
64 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Permission is hereby granted, free of charge, to any
2 | person obtaining a copy of this software and associated
3 | documentation files (the "Software"), to deal in the
4 | Software without restriction, including without
5 | limitation the rights to use, copy, modify, merge,
6 | publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software
8 | is furnished to do so, subject to the following
9 | conditions:
10 |
11 | The above copyright notice and this permission notice
12 | shall be included in all copies or substantial portions
13 | of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/compare.rs:
--------------------------------------------------------------------------------
1 | mod fst;
2 | mod roaring;
3 | mod trie;
4 |
5 | #[test]
6 | fn compare_all_implementations() {
7 | let xid_start_fst = fst::xid_start_fst();
8 | let xid_continue_fst = fst::xid_continue_fst();
9 | let xid_start_roaring = roaring::xid_start_bitmap();
10 | let xid_continue_roaring = roaring::xid_continue_bitmap();
11 |
12 | for ch in '\0'..=char::MAX {
13 | let thought_to_be_start = unicode_ident::is_xid_start(ch);
14 | let thought_to_be_continue = unicode_ident::is_xid_continue(ch);
15 |
16 | // unicode-xid
17 | // FIXME: unicode-xid does not support Unicode 15.1.0 yet.
18 | /*
19 | assert_eq!(
20 | thought_to_be_start,
21 | unicode_xid::UnicodeXID::is_xid_start(ch),
22 | "{ch:?}",
23 | );
24 | assert_eq!(
25 | thought_to_be_continue,
26 | unicode_xid::UnicodeXID::is_xid_continue(ch),
27 | "{ch:?}",
28 | );
29 | */
30 |
31 | // ucd-trie
32 | assert_eq!(
33 | thought_to_be_start,
34 | trie::XID_START.contains_char(ch),
35 | "{ch:?}",
36 | );
37 | assert_eq!(
38 | thought_to_be_continue,
39 | trie::XID_CONTINUE.contains_char(ch),
40 | "{ch:?}",
41 | );
42 |
43 | // fst
44 | assert_eq!(
45 | thought_to_be_start,
46 | xid_start_fst.contains((ch as u32).to_be_bytes()),
47 | "{ch:?}",
48 | );
49 | assert_eq!(
50 | thought_to_be_continue,
51 | xid_continue_fst.contains((ch as u32).to_be_bytes()),
52 | "{ch:?}",
53 | );
54 |
55 | // roaring
56 | assert_eq!(
57 | thought_to_be_start,
58 | xid_start_roaring.contains(ch as u32),
59 | "{ch:?}",
60 | );
61 | assert_eq!(
62 | thought_to_be_continue,
63 | xid_continue_roaring.contains(ch as u32),
64 | "{ch:?}",
65 | );
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/fst/mod.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::module_name_repetitions)]
2 |
3 | pub fn xid_start_fst() -> fst::Set<&'static [u8]> {
4 | let data = include_bytes!("xid_start.fst");
5 | fst::Set::from(fst::raw::Fst::new(data.as_slice()).unwrap())
6 | }
7 |
8 | pub fn xid_continue_fst() -> fst::Set<&'static [u8]> {
9 | let data = include_bytes!("xid_continue.fst");
10 | fst::Set::from(fst::raw::Fst::new(data.as_slice()).unwrap())
11 | }
12 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/fst/xid_continue.fst:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rudd-O/qubes-shared-folders/7fa918909dc72b723df4b23832ac11535c29e0c7/vendor/unicode-ident/tests/fst/xid_continue.fst
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/fst/xid_start.fst:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rudd-O/qubes-shared-folders/7fa918909dc72b723df4b23832ac11535c29e0c7/vendor/unicode-ident/tests/fst/xid_start.fst
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/roaring/mod.rs:
--------------------------------------------------------------------------------
1 | use roaring::RoaringBitmap;
2 |
3 | pub fn xid_start_bitmap() -> RoaringBitmap {
4 | let mut bitmap = RoaringBitmap::new();
5 | for ch in '\0'..=char::MAX {
6 | if unicode_ident::is_xid_start(ch) {
7 | bitmap.insert(ch as u32);
8 | }
9 | }
10 | bitmap
11 | }
12 |
13 | pub fn xid_continue_bitmap() -> RoaringBitmap {
14 | let mut bitmap = RoaringBitmap::new();
15 | for ch in '\0'..=char::MAX {
16 | if unicode_ident::is_xid_continue(ch) {
17 | bitmap.insert(ch as u32);
18 | }
19 | }
20 | bitmap
21 | }
22 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/tables/mod.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::module_inception)]
2 |
3 | #[allow(clippy::redundant_static_lifetimes)]
4 | #[rustfmt::skip]
5 | mod tables;
6 |
7 | pub(crate) use self::tables::*;
8 |
--------------------------------------------------------------------------------
/vendor/unicode-ident/tests/trie/mod.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::module_inception)]
2 |
3 | #[allow(dead_code, clippy::redundant_static_lifetimes, clippy::unreadable_literal)]
4 | #[rustfmt::skip]
5 | mod trie;
6 |
7 | pub(crate) use self::trie::*;
8 |
--------------------------------------------------------------------------------