From 6983dd25724c4824f06213dc1c49fc19721105e9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 24 Aug 2023 20:16:47 -0700 Subject: [PATCH 1/7] Update test suite to nightly-2023-08-25 --- tests/common/eq.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/eq.rs b/tests/common/eq.rs index 68fd1949e4..d9cd7f42d9 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -598,8 +598,8 @@ spanless_eq_enum!(PatKind; Wild Ident(0 1 2) Struct(0 1 2 3) TupleStruct(0 1 2) Or(0) Path(0 1) Tuple(0) Box(0) Ref(0 1) Lit(0) Range(0 1 2) Slice(0) Rest Paren(0) MacCall(0)); spanless_eq_enum!(TyKind; Slice(0) Array(0 1) Ptr(0) Ref(0 1) BareFn(0) Never - Tup(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) Paren(0) Typeof(0) Infer - ImplicitSelf MacCall(0) Err CVarArgs); + Tup(0) AnonStruct(0) AnonUnion(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) + Paren(0) Typeof(0) Infer ImplicitSelf MacCall(0) Err CVarArgs); impl SpanlessEq for Ident { fn eq(&self, other: &Self) -> bool { From 4cc6f7663a58db3d2fb052f32f525aa97ddafec9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 27 Aug 2023 15:23:48 -0700 Subject: [PATCH 2/7] Opt out -Zrustdoc-scrape-examples on docs.rs I'd like a chance to audit all the code that rustdoc is inserting into the docs. Currently I am skeptical that showing syn-codegen's internal usages of APIs is a net benefit to the public documentation. I am also skeptical that quite so many examples are needed, and that they should be featured so prominently in comparison to handwritten docs. Lastly I wish there were a way to turn this behavior off on a more granular basis. --- json/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/json/Cargo.toml b/json/Cargo.toml index 73b944ee02..e6ff2d544d 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -19,6 +19,9 @@ serde_derive = "1.0.88" [dev-dependencies] serde_json = "1" +[lib] +doc-scrape-examples = false + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = ["--generate-link-to-definition"] From ceafc59305d76f52269a083b759c98a2520b0951 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Sep 2023 13:47:10 -0700 Subject: [PATCH 3/7] Delete syn-parse-crates tool --- Cargo.toml | 1 - tests/crates/Cargo.toml | 17 --------- tests/crates/main.rs | 84 ----------------------------------------- 3 files changed, 102 deletions(-) delete mode 100644 tests/crates/Cargo.toml delete mode 100644 tests/crates/main.rs diff --git a/Cargo.toml b/Cargo.toml index 9394660098..a9052fcdd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,5 @@ members = [ "examples/lazy-static/lazy-static", "examples/trace-var/example", "examples/trace-var/trace-var", - "tests/crates", "tests/features", ] diff --git a/tests/crates/Cargo.toml b/tests/crates/Cargo.toml deleted file mode 100644 index 7bd6cddd41..0000000000 --- a/tests/crates/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "syn-parse-crates" -version = "0.0.0" -authors = ["David Tolnay "] -edition = "2021" -publish = false - -[[bin]] -name = "syn-parse-crates" -path = "main.rs" - -[dependencies] -anyhow = "1" -flate2 = "1" -rayon = "1" -syn = { path = "../..", default-features = false, features = ["full", "parsing"] } -tar = "0.4" diff --git a/tests/crates/main.rs b/tests/crates/main.rs deleted file mode 100644 index 35b866b168..0000000000 --- a/tests/crates/main.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Run parser on contents of all *.crate files in a specified directory. This is -// intended to discover panics in syn or its dependencies. -// -// cargo run --release -- path/to/crates -// -// Published *.crate files from crates.io can be downloaded like this: -// -// git clone https://github.com/rust-lang/crates.io-index -// grep -hr . crates.io-index/*/ \ -// | jq '"https://static.crates.io/crates/" + .name + "/" + .name + "-" + .vers + ".crate"' -r \ -// | xargs -P10 -n100 wget -nc - -#![allow(clippy::let_underscore_untyped, clippy::uninlined_format_args)] - -use anyhow::{ensure, Result}; -use flate2::read::GzDecoder; -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; -use rayon::ThreadPoolBuilder; -use std::env; -use std::ffi::OsStr; -use std::fs::{self, File}; -use std::io::{BufReader, Read}; -use std::path::Path; -use std::sync::atomic::{AtomicUsize, Ordering}; -use tar::Archive; - -fn main() -> Result<()> { - let mut args = env::args_os(); - ensure!(args.len() == 2); - args.next().unwrap(); - let dir = args.next().unwrap(); - - let mut paths = Vec::new(); - for entry in fs::read_dir(dir)? { - let entry = entry?; - let path = entry.path(); - if path.extension() == Some(OsStr::new("crate")) { - paths.push(path); - } - } - - ThreadPoolBuilder::new() - .stack_size(20 * 1024 * 1024) - .build_global() - .unwrap(); - - let oversize_count = AtomicUsize::new(0); - paths.par_iter().for_each(|path| { - if let Err(err) = parse(path, &oversize_count) { - eprintln!("{}: {}", path.display(), err); - } - }); - - let oversize_count = oversize_count.into_inner(); - if oversize_count > 0 { - eprintln!("{} oversized source files not checked", oversize_count); - } - - Ok(()) -} - -fn parse(path: &Path, oversize_count: &AtomicUsize) -> Result<()> { - let file = File::open(path)?; - let reader = BufReader::new(file); - let tar = GzDecoder::new(reader); - let mut archive = Archive::new(tar); - for entry in archive.entries()? { - let mut entry = entry?; - if entry.size() > 10 * 1024 * 1024 { - oversize_count.fetch_add(1, Ordering::Relaxed); - continue; - } - let path = entry.path()?; - if path.extension() != Some(OsStr::new("rs")) { - continue; - } - let mut contents = String::new(); - if entry.read_to_string(&mut contents).is_err() { - break; - } - let _ = syn::parse_file(&contents); - } - Ok(()) -} From b8cf87c8352ed48d805fefeb6f2865871bd99a85 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Sep 2023 21:13:11 -0700 Subject: [PATCH 4/7] Update test suite to nightly-2023-09-03 --- tests/repo/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 780ad823b0..10b48f3211 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -13,10 +13,20 @@ use std::path::{Path, PathBuf}; use tar::Archive; use walkdir::{DirEntry, WalkDir}; -const REVISION: &str = "85bf07972a1041b9e25393b803d0e006bec3eaaf"; +const REVISION: &str = "9f5fc1bd443f59583e7af0d94d289f95fe1e20c4"; #[rustfmt::skip] static EXCLUDE_FILES: &[&str] = &[ + // TODO + "src/tools/rustfmt/tests/target/anonymous-types.rs", + "tests/rustdoc/generic-const-items.rs", + "tests/rustdoc/inline_cross/auxiliary/generic-const-items.rs", + "tests/ui/generic-const-items/associated-const-equality.rs", + "tests/ui/generic-const-items/basic.rs", + "tests/ui/generic-const-items/recursive.rs", + "tests/ui/object-safety/assoc_const_bounds.rs", + "tests/ui/object-safety/assoc_const_bounds_sized.rs", + // CStr literals (c"…") are not yet supported by rustc's lexer // https://github.com/rust-lang/rust/issues/113333 "src/tools/clippy/tests/ui/needless_raw_string_hashes.rs", @@ -115,7 +125,6 @@ static EXCLUDE_FILES: &[&str] = &[ // Various extensions to Rust syntax made up by rust-analyzer "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs", - "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0040_crate_keyword_vis.rs", "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0058_range_pat.rs", "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0123_param_list_vararg.rs", "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0131_existential_type.rs", From face31f20f166d19d61c702d237d51f755f89ad8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Sep 2023 21:20:14 -0700 Subject: [PATCH 5/7] Categorize new todo rustc test cases --- tests/repo/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 10b48f3211..0c61f4abef 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -17,8 +17,12 @@ const REVISION: &str = "9f5fc1bd443f59583e7af0d94d289f95fe1e20c4"; #[rustfmt::skip] static EXCLUDE_FILES: &[&str] = &[ - // TODO + // TODO: anonymous union and struct + // https://github.com/dtolnay/syn/issues/1049 "src/tools/rustfmt/tests/target/anonymous-types.rs", + + // TODO: generic const items + // https://github.com/dtolnay/syn/issues/1497 "tests/rustdoc/generic-const-items.rs", "tests/rustdoc/inline_cross/auxiliary/generic-const-items.rs", "tests/ui/generic-const-items/associated-const-equality.rs", From e827aca234742d3dc734892c6402532fd6018318 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Sep 2023 21:45:05 -0700 Subject: [PATCH 6/7] Parse unnamed struct/union syntax --- src/data.rs | 38 +++++++++++++++++++++++++++++--------- tests/repo/mod.rs | 4 ---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/data.rs b/src/data.rs index 185f88ba01..431c0857d4 100644 --- a/src/data.rs +++ b/src/data.rs @@ -214,17 +214,37 @@ pub(crate) mod parsing { /// Parses a named (braced struct) field. #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_named(input: ParseStream) -> Result { + let attrs = input.call(Attribute::parse_outer)?; + let vis: Visibility = input.parse()?; + + let unnamed_field = cfg!(feature = "full") && input.peek(Token![_]); + let ident = if unnamed_field { + input.call(Ident::parse_any) + } else { + input.parse() + }?; + + let colon_token: Token![:] = input.parse()?; + + let ty: Type = if unnamed_field + && (input.peek(Token![struct]) + || input.peek(Token![union]) && input.peek2(token::Brace)) + { + let begin = input.fork(); + input.call(Ident::parse_any)?; + input.parse::()?; + Type::Verbatim(verbatim::between(&begin, input)) + } else { + input.parse()? + }; + Ok(Field { - attrs: input.call(Attribute::parse_outer)?, - vis: input.parse()?, + attrs, + vis, mutability: FieldMutability::None, - ident: Some(if input.peek(Token![_]) { - input.call(Ident::parse_any) - } else { - input.parse() - }?), - colon_token: Some(input.parse()?), - ty: input.parse()?, + ident: Some(ident), + colon_token: Some(colon_token), + ty, }) } diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 0c61f4abef..8ae1ae2d44 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -17,10 +17,6 @@ const REVISION: &str = "9f5fc1bd443f59583e7af0d94d289f95fe1e20c4"; #[rustfmt::skip] static EXCLUDE_FILES: &[&str] = &[ - // TODO: anonymous union and struct - // https://github.com/dtolnay/syn/issues/1049 - "src/tools/rustfmt/tests/target/anonymous-types.rs", - // TODO: generic const items // https://github.com/dtolnay/syn/issues/1497 "tests/rustdoc/generic-const-items.rs", From 78f94eac59ceb2d37fa3bbb86fc8769c9833f0c5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Sep 2023 22:01:40 -0700 Subject: [PATCH 7/7] Release 2.0.30 --- Cargo.toml | 2 +- src/lib.rs | 2 +- syn.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9052fcdd5..bd2913ccb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syn" -version = "2.0.29" # don't forget to update html_root_url and syn.json +version = "2.0.30" # don't forget to update html_root_url and syn.json authors = ["David Tolnay "] categories = ["development-tools::procedural-macro-helpers", "parser-implementations"] description = "Parser for Rust source code" diff --git a/src/lib.rs b/src/lib.rs index 4adaa85873..534ac8e5aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -249,7 +249,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/2.0.29")] +#![doc(html_root_url = "https://docs.rs/syn/2.0.30")] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![allow(non_camel_case_types)] #![allow( diff --git a/syn.json b/syn.json index aa6b203762..4f5c7fa003 100644 --- a/syn.json +++ b/syn.json @@ -1,5 +1,5 @@ { - "version": "2.0.29", + "version": "2.0.30", "types": [ { "ident": "Abi",