From 0bbb2b34ee714570e123f0e386a43198d2c0da02 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 24 Oct 2020 19:35:25 -0700 Subject: [PATCH 01/81] Update test suite to nightly-2020-10-25 --- tests/common/eq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/eq.rs b/tests/common/eq.rs index 4ec910b596..b0603c64c4 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -266,7 +266,7 @@ spanless_eq_struct!(AnonConst; id value); spanless_eq_struct!(Arm; attrs pat guard body span id is_placeholder); spanless_eq_struct!(AssocTyConstraint; id ident kind span); spanless_eq_struct!(AttrItem; path args tokens); -spanless_eq_struct!(Attribute; kind id style span); +spanless_eq_struct!(Attribute; kind id style span tokens); spanless_eq_struct!(BareFnTy; unsafety ext generic_params decl); spanless_eq_struct!(Block; stmts id rules span tokens); spanless_eq_struct!(Crate; module attrs span proc_macros); From b52cf67333d4b2a124db55df3086598c509de3fd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 28 Oct 2020 17:44:42 -0700 Subject: [PATCH 02/81] Remove deprecated description method from Error impl --- src/error.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 8d65a1b416..cc74c74459 100644 --- a/src/error.rs +++ b/src/error.rs @@ -309,11 +309,7 @@ impl Clone for ErrorMessage { } } -impl std::error::Error for Error { - fn description(&self) -> &str { - "parse error" - } -} +impl std::error::Error for Error {} impl From for Error { fn from(err: LexError) -> Self { From e627ec80ceb1e893a65ca0f852aae610bc5c0ae8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 31 Oct 2020 19:22:44 -0700 Subject: [PATCH 03/81] Update test suite to nightly-2020-11-01 --- 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 b0603c64c4..a9deefbbc6 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -445,8 +445,8 @@ impl SpanlessEq for TokenStream { impl SpanlessEq for LazyTokenStream { fn eq(&self, other: &Self) -> bool { - let this = self.into_token_stream(); - let other = other.into_token_stream(); + let this = self.create_token_stream(); + let other = other.create_token_stream(); SpanlessEq::eq(&this, &other) } } From ba4f188168c11f61f8db79a00a166fe0a1c6a378 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 1 Nov 2020 10:23:25 -0800 Subject: [PATCH 04/81] Add none-group statement parsing test --- tests/test_stmt.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_stmt.rs b/tests/test_stmt.rs index d68b47fd2f..943d856ef6 100644 --- a/tests/test_stmt.rs +++ b/tests/test_stmt.rs @@ -1,6 +1,8 @@ #[macro_use] mod macros; +use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; +use std::iter::FromIterator; use syn::Stmt; #[test] @@ -42,3 +44,31 @@ fn test_raw_variable() { fn test_raw_invalid() { assert!(syn::parse_str::("let _ = &raw x;").is_err()); } + +#[test] +fn test_none_group() { + // <Ø async fn f() {} Ø> + let tokens = TokenStream::from_iter(vec![TokenTree::Group(Group::new( + Delimiter::None, + TokenStream::from_iter(vec![ + TokenTree::Ident(Ident::new("async", Span::call_site())), + TokenTree::Ident(Ident::new("fn", Span::call_site())), + TokenTree::Ident(Ident::new("f", Span::call_site())), + TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())), + TokenTree::Group(Group::new(Delimiter::Brace, TokenStream::new())), + ]), + ))]); + + snapshot!(tokens as Stmt, @r###" + Item(Item::Fn { + vis: Inherited, + sig: Signature { + asyncness: Some, + ident: "f", + generics: Generics, + output: Default, + }, + block: Block, + }) + "###); +} From 49822a497e5fbf15c5dbb848d76b7e718468c821 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 1 Nov 2020 10:15:15 -0800 Subject: [PATCH 05/81] Handle peek2 inside of leading None-delimited group --- src/parse.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parse.rs b/src/parse.rs index f1aecada03..45c8627e54 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -621,6 +621,11 @@ impl<'a> ParseBuffer<'a> { /// ``` pub fn peek2(&self, token: T) -> bool { let _ = token; + if let Some(group) = self.cursor().group(Delimiter::None) { + if group.0.skip().map_or(false, T::Token::peek) { + return true; + } + } self.cursor().skip().map_or(false, T::Token::peek) } From 06361a024db4b4ace663bdf195a71ca7710e0ee9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 1 Nov 2020 10:16:27 -0800 Subject: [PATCH 06/81] Same for peek3 --- src/parse.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/parse.rs b/src/parse.rs index 45c8627e54..39a01a5244 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -632,6 +632,16 @@ impl<'a> ParseBuffer<'a> { /// Looks at the third-next token in the parse stream. pub fn peek3(&self, token: T) -> bool { let _ = token; + if let Some(group) = self.cursor().group(Delimiter::None) { + if group + .0 + .skip() + .and_then(Cursor::skip) + .map_or(false, T::Token::peek) + { + return true; + } + } self.cursor() .skip() .and_then(Cursor::skip) From 0c1ef1241d1233693bb0cbbe9b907d44effb0750 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 1 Nov 2020 10:19:46 -0800 Subject: [PATCH 07/81] Avoid monomorphizing complex peek function bodies --- src/parse.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index 39a01a5244..8c8c4a1417 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -620,32 +620,36 @@ impl<'a> ParseBuffer<'a> { /// } /// ``` pub fn peek2(&self, token: T) -> bool { - let _ = token; - if let Some(group) = self.cursor().group(Delimiter::None) { - if group.0.skip().map_or(false, T::Token::peek) { - return true; + fn peek2(buffer: &ParseBuffer, f: fn(Cursor) -> bool) -> bool { + if let Some(group) = buffer.cursor().group(Delimiter::None) { + if group.0.skip().map_or(false, f) { + return true; + } } + buffer.cursor().skip().map_or(false, f) } - self.cursor().skip().map_or(false, T::Token::peek) + + let _ = token; + peek2(self, T::Token::peek) } /// Looks at the third-next token in the parse stream. pub fn peek3(&self, token: T) -> bool { - let _ = token; - if let Some(group) = self.cursor().group(Delimiter::None) { - if group - .0 + fn peek3(buffer: &ParseBuffer, f: fn(Cursor) -> bool) -> bool { + if let Some(group) = buffer.cursor().group(Delimiter::None) { + if group.0.skip().and_then(Cursor::skip).map_or(false, f) { + return true; + } + } + buffer + .cursor() .skip() .and_then(Cursor::skip) - .map_or(false, T::Token::peek) - { - return true; - } + .map_or(false, f) } - self.cursor() - .skip() - .and_then(Cursor::skip) - .map_or(false, T::Token::peek) + + let _ = token; + peek3(self, T::Token::peek) } /// Parses zero or more occurrences of `T` separated by punctuation of type From 2ea9493e1850c0d3c5f3205a37a0b8456adb17f0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 1 Nov 2020 10:29:02 -0800 Subject: [PATCH 08/81] Clearer name for peek function pointers --- src/parse.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index 8c8c4a1417..5b87508f00 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -620,13 +620,13 @@ impl<'a> ParseBuffer<'a> { /// } /// ``` pub fn peek2(&self, token: T) -> bool { - fn peek2(buffer: &ParseBuffer, f: fn(Cursor) -> bool) -> bool { + fn peek2(buffer: &ParseBuffer, peek: fn(Cursor) -> bool) -> bool { if let Some(group) = buffer.cursor().group(Delimiter::None) { - if group.0.skip().map_or(false, f) { + if group.0.skip().map_or(false, peek) { return true; } } - buffer.cursor().skip().map_or(false, f) + buffer.cursor().skip().map_or(false, peek) } let _ = token; @@ -635,9 +635,9 @@ impl<'a> ParseBuffer<'a> { /// Looks at the third-next token in the parse stream. pub fn peek3(&self, token: T) -> bool { - fn peek3(buffer: &ParseBuffer, f: fn(Cursor) -> bool) -> bool { + fn peek3(buffer: &ParseBuffer, peek: fn(Cursor) -> bool) -> bool { if let Some(group) = buffer.cursor().group(Delimiter::None) { - if group.0.skip().and_then(Cursor::skip).map_or(false, f) { + if group.0.skip().and_then(Cursor::skip).map_or(false, peek) { return true; } } @@ -645,7 +645,7 @@ impl<'a> ParseBuffer<'a> { .cursor() .skip() .and_then(Cursor::skip) - .map_or(false, f) + .map_or(false, peek) } let _ = token; From 925b1e74e9244b390fbef987a66341e092e5bd4b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 1 Nov 2020 10:36:11 -0800 Subject: [PATCH 09/81] Release 1.0.49 --- 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 0e17af4f5a..22e29e410d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syn" -version = "1.0.48" # don't forget to update html_root_url and syn.json +version = "1.0.49" # don't forget to update html_root_url and syn.json authors = ["David Tolnay "] license = "MIT OR Apache-2.0" description = "Parser for Rust source code" diff --git a/src/lib.rs b/src/lib.rs index 3a34eaa626..7e53b58279 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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.48")] +#![doc(html_root_url = "https://docs.rs/syn/1.0.49")] #![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints. #![allow( diff --git a/syn.json b/syn.json index 5b822b5fe0..bf2b2bd5f8 100644 --- a/syn.json +++ b/syn.json @@ -1,5 +1,5 @@ { - "version": "1.0.48", + "version": "1.0.49", "types": [ { "ident": "Abi", From 9eac70784f6fe9c1b054e8e03b82ef09d518a5ed Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Nov 2020 12:08:46 -0800 Subject: [PATCH 10/81] Interpret test path exclusions as relative to Rust repo root --- tests/repo/mod.rs | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 1d3e1f0e74..012c4d59ae 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -13,24 +13,24 @@ const REVISION: &str = "792c645ca7d11a8d254df307d019c5bf01445c37"; #[rustfmt::skip] static EXCLUDE: &[&str] = &[ // Compile-fail expr parameter in const generic position: f::<1 + 2>() - "test/ui/const-generics/const-expression-parameter.rs", + "src/test/ui/const-generics/const-expression-parameter.rs", // Deprecated anonymous parameter syntax in traits - "test/ui/issues/issue-13105.rs", - "test/ui/issues/issue-13775.rs", - "test/ui/issues/issue-34074.rs", - "test/ui/proc-macro/trait-fn-args-2015.rs", + "src/test/ui/issues/issue-13105.rs", + "src/test/ui/issues/issue-13775.rs", + "src/test/ui/issues/issue-34074.rs", + "src/test/ui/proc-macro/trait-fn-args-2015.rs", // Not actually test cases - "test/rustdoc-ui/test-compile-fail2.rs", - "test/rustdoc-ui/test-compile-fail3.rs", - "test/ui/include-single-expr-helper.rs", - "test/ui/include-single-expr-helper-1.rs", - "test/ui/issues/auxiliary/issue-21146-inc.rs", - "test/ui/json-bom-plus-crlf-multifile-aux.rs", - "test/ui/lint/expansion-time-include.rs", - "test/ui/macros/auxiliary/macro-comma-support.rs", - "test/ui/macros/auxiliary/macro-include-items-expr.rs", + "src/test/rustdoc-ui/test-compile-fail2.rs", + "src/test/rustdoc-ui/test-compile-fail3.rs", + "src/test/ui/include-single-expr-helper.rs", + "src/test/ui/include-single-expr-helper-1.rs", + "src/test/ui/issues/auxiliary/issue-21146-inc.rs", + "src/test/ui/json-bom-plus-crlf-multifile-aux.rs", + "src/test/ui/lint/expansion-time-include.rs", + "src/test/ui/macros/auxiliary/macro-comma-support.rs", + "src/test/ui/macros/auxiliary/macro-include-items-expr.rs", ]; pub fn base_dir_filter(entry: &DirEntry) -> bool { @@ -46,23 +46,21 @@ pub fn base_dir_filter(entry: &DirEntry) -> bool { if cfg!(windows) { path_string = path_string.replace('\\', "/").into(); } - let path = if let Some(path) = path_string.strip_prefix("tests/rust/src/") { - path - } else if let Some(path) = path_string.strip_prefix("tests/rust/library/") { + let path = if let Some(path) = path_string.strip_prefix("tests/rust/") { path } else { panic!("unexpected path in Rust dist: {}", path_string); }; // TODO assert that parsing fails on the parse-fail cases - if path.starts_with("test/parse-fail") - || path.starts_with("test/compile-fail") - || path.starts_with("test/rustfix") + if path.starts_with("src/test/parse-fail") + || path.starts_with("src/test/compile-fail") + || path.starts_with("src/test/rustfix") { return false; } - if path.starts_with("test/ui") { + if path.starts_with("src/test/ui") { let stderr_path = entry.path().with_extension("stderr"); if stderr_path.exists() { // Expected to fail in some way @@ -91,10 +89,10 @@ pub fn clone_rust() { download_and_unpack().unwrap(); } let mut missing = String::new(); - let test_src = Path::new("tests/rust/src"); + let test_src = Path::new("tests/rust"); for exclude in EXCLUDE { if !test_src.join(exclude).exists() { - missing += "\ntests/rust/src/"; + missing += "\ntests/rust/"; missing += exclude; } } From 02b536554cff55492311b6b11face8b7b7c43dc0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Nov 2020 12:11:03 -0800 Subject: [PATCH 11/81] Remove parse-fail check no longer present in Rust dist --- tests/repo/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 012c4d59ae..16a47620ec 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -52,11 +52,7 @@ pub fn base_dir_filter(entry: &DirEntry) -> bool { panic!("unexpected path in Rust dist: {}", path_string); }; - // TODO assert that parsing fails on the parse-fail cases - if path.starts_with("src/test/parse-fail") - || path.starts_with("src/test/compile-fail") - || path.starts_with("src/test/rustfix") - { + if path.starts_with("src/test/compile-fail") || path.starts_with("src/test/rustfix") { return false; } From 1787fbd4c161ee6546184b90e06e9da620a1985f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Nov 2020 12:03:37 -0800 Subject: [PATCH 12/81] Update test suite from nightly-2020-08-18 to nightly-2020-11-06 --- tests/repo/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 16a47620ec..b6358b5b0d 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -8,10 +8,23 @@ use std::path::Path; use tar::Archive; use walkdir::DirEntry; -const REVISION: &str = "792c645ca7d11a8d254df307d019c5bf01445c37"; +const REVISION: &str = "9d78d1d02761b906038ba4d54c5f3427f920f5fb"; #[rustfmt::skip] static EXCLUDE: &[&str] = &[ + // TODO + "src/test/ui/const-generics/argument_order.rs", + "src/test/ui/const-generics/closing-args-token.rs", + "src/test/ui/const-generics/const-param-before-other-params.rs", + "src/test/ui/const-generics/defaults/intermixed-lifetime.rs", + "src/test/ui/inline-const/const-expr-array-init.rs", + "src/test/ui/inline-const/const-expr-basic.rs", + "src/test/ui/inline-const/const-expr-reference.rs", + "src/test/ui/inline-const/const-match-pat-range.rs", + "src/test/ui/inline-const/const-match-pat.rs", + "src/test/ui/proc-macro/unsafe-foreign-mod.rs", + "src/test/ui/proc-macro/unsafe-mod.rs", + // Compile-fail expr parameter in const generic position: f::<1 + 2>() "src/test/ui/const-generics/const-expression-parameter.rs", From 30da41f1ddaa10633292b6b18a44231311a33f76 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Nov 2020 12:20:21 -0800 Subject: [PATCH 13/81] Categorize new test exclusions --- tests/repo/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index b6358b5b0d..0e6aac3478 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -12,20 +12,26 @@ const REVISION: &str = "9d78d1d02761b906038ba4d54c5f3427f920f5fb"; #[rustfmt::skip] static EXCLUDE: &[&str] = &[ - // TODO + // TODO: const parameter before lifetime parameter "src/test/ui/const-generics/argument_order.rs", - "src/test/ui/const-generics/closing-args-token.rs", "src/test/ui/const-generics/const-param-before-other-params.rs", "src/test/ui/const-generics/defaults/intermixed-lifetime.rs", + + // TODO: const block "src/test/ui/inline-const/const-expr-array-init.rs", "src/test/ui/inline-const/const-expr-basic.rs", "src/test/ui/inline-const/const-expr-reference.rs", "src/test/ui/inline-const/const-match-pat-range.rs", "src/test/ui/inline-const/const-match-pat.rs", + + // TODO: unsafe extern blocks "src/test/ui/proc-macro/unsafe-foreign-mod.rs", + + // TODO: unsafe modules "src/test/ui/proc-macro/unsafe-mod.rs", // Compile-fail expr parameter in const generic position: f::<1 + 2>() + "src/test/ui/const-generics/closing-args-token.rs", "src/test/ui/const-generics/const-expression-parameter.rs", // Deprecated anonymous parameter syntax in traits From 64b7f9651773a15a0ce747e6f3b351c2521e9bf0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Nov 2020 12:54:56 -0800 Subject: [PATCH 14/81] File issues to track new syntax implementation --- tests/repo/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 0e6aac3478..1698e696ea 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -12,22 +12,22 @@ const REVISION: &str = "9d78d1d02761b906038ba4d54c5f3427f920f5fb"; #[rustfmt::skip] static EXCLUDE: &[&str] = &[ - // TODO: const parameter before lifetime parameter + // TODO: const parameter before lifetime parameter (#920) "src/test/ui/const-generics/argument_order.rs", "src/test/ui/const-generics/const-param-before-other-params.rs", "src/test/ui/const-generics/defaults/intermixed-lifetime.rs", - // TODO: const block + // TODO: const block (#921) "src/test/ui/inline-const/const-expr-array-init.rs", "src/test/ui/inline-const/const-expr-basic.rs", "src/test/ui/inline-const/const-expr-reference.rs", "src/test/ui/inline-const/const-match-pat-range.rs", "src/test/ui/inline-const/const-match-pat.rs", - // TODO: unsafe extern blocks + // TODO: unsafe extern blocks (#918) "src/test/ui/proc-macro/unsafe-foreign-mod.rs", - // TODO: unsafe modules + // TODO: unsafe modules (#919) "src/test/ui/proc-macro/unsafe-mod.rs", // Compile-fail expr parameter in const generic position: f::<1 + 2>() From f8b59d705e51c8b5f5a26a6af9546c623004047c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 10 Nov 2020 18:35:28 -0800 Subject: [PATCH 15/81] Update test suite to nightly-2020-11-11 --- tests/test_precedence.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index 1519cf0202..b3e540a8c5 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -198,7 +198,7 @@ fn librustc_parse_and_rewrite(input: &str) -> Option> { /// This method operates on librustc objects. fn librustc_brackets(mut librustc_expr: P) -> Option> { use rustc_ast::ast::{ - Block, BorrowKind, Expr, ExprKind, Field, GenericArg, MacCall, Pat, Stmt, StmtKind, Ty, + Block, BorrowKind, Expr, ExprKind, Field, GenericArg, Pat, Stmt, StmtKind, Ty, }; use rustc_ast::mut_visit::{noop_visit_generic_arg, MutVisitor}; use rustc_data_structures::map_in_place::MapInPlace; @@ -299,15 +299,6 @@ fn librustc_brackets(mut librustc_expr: P) -> Option> { fn visit_ty(&mut self, ty: &mut P) { let _ = ty; } - - fn visit_mac(&mut self, mac: &mut MacCall) { - // By default when folding over macros, librustc panics. This is - // because it's usually not what you want, you want to run after - // macro expansion. We do want to do that (syn doesn't do macro - // expansion), so we implement visit_mac to just return the macro - // unchanged. - let _ = mac; - } } let mut folder = BracketsVisitor { failed: false }; From 828aa04dd7a0cc0206e2ae2c3159495fb936b2b1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 12 Nov 2020 18:01:24 -0800 Subject: [PATCH 16/81] Update test suite to nightly-2020-11-13 --- 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 a9deefbbc6..577a353ebc 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -266,7 +266,7 @@ spanless_eq_struct!(AnonConst; id value); spanless_eq_struct!(Arm; attrs pat guard body span id is_placeholder); spanless_eq_struct!(AssocTyConstraint; id ident kind span); spanless_eq_struct!(AttrItem; path args tokens); -spanless_eq_struct!(Attribute; kind id style span tokens); +spanless_eq_struct!(Attribute; kind id style span); spanless_eq_struct!(BareFnTy; unsafety ext generic_params decl); spanless_eq_struct!(Block; stmts id rules span tokens); spanless_eq_struct!(Crate; module attrs span proc_macros); @@ -318,7 +318,7 @@ spanless_eq_enum!(AngleBracketedArg; Arg(0) Constraint(0)); spanless_eq_enum!(AssocItemKind; Const(0 1 2) Fn(0 1 2 3) TyAlias(0 1 2 3) MacCall(0)); spanless_eq_enum!(AssocTyConstraintKind; Equality(ty) Bound(bounds)); spanless_eq_enum!(Async; Yes(span closure_id return_impl_trait_id) No); -spanless_eq_enum!(AttrKind; Normal(0) DocComment(0 1)); +spanless_eq_enum!(AttrKind; Normal(0 1) DocComment(0 1)); spanless_eq_enum!(AttrStyle; Outer Inner); spanless_eq_enum!(BinOpKind; Add Sub Mul Div Rem And Or BitXor BitAnd BitOr Shl Shr Eq Lt Le Ne Ge Gt); spanless_eq_enum!(BindingMode; ByRef(0) ByValue(0)); From 8b54d0d983f17dac1855901061d3354cd14ff3f9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 13 Nov 2020 18:01:58 -0800 Subject: [PATCH 17/81] Update test suite to nightly-2020-11-14 --- tests/common/eq.rs | 9 +++++---- tests/test_precedence.rs | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/common/eq.rs b/tests/common/eq.rs index 577a353ebc..8b6c510be5 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -15,10 +15,10 @@ use rustc_ast::ast::{ LlvmInlineAsm, LlvmInlineAsmOutput, Local, MacArgs, MacCall, MacCallStmt, MacDelimiter, MacStmtStyle, MacroDef, Mod, Movability, MutTy, Mutability, NodeId, Param, ParenthesizedArgs, Pat, PatKind, Path, PathSegment, PolyTraitRef, QSelf, RangeEnd, RangeLimits, RangeSyntax, Stmt, - StmtKind, StrLit, StrStyle, StructField, TraitBoundModifier, TraitObjectSyntax, TraitRef, Ty, - TyKind, UintTy, UnOp, Unsafe, UnsafeSource, UseTree, UseTreeKind, Variant, VariantData, - Visibility, VisibilityKind, WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate, - WhereRegionPredicate, + StmtKind, StrLit, StrStyle, StructField, StructRest, TraitBoundModifier, TraitObjectSyntax, + TraitRef, Ty, TyKind, UintTy, UnOp, Unsafe, UnsafeSource, UseTree, UseTreeKind, Variant, + VariantData, Visibility, VisibilityKind, WhereBoundPredicate, WhereClause, WhereEqPredicate, + WherePredicate, WhereRegionPredicate, }; use rustc_ast::ptr::P; use rustc_ast::token::{self, CommentKind, DelimToken, Token, TokenKind}; @@ -353,6 +353,7 @@ spanless_eq_enum!(RangeEnd; Included(0) Excluded); spanless_eq_enum!(RangeLimits; HalfOpen Closed); spanless_eq_enum!(StmtKind; Local(0) Item(0) Expr(0) Semi(0) Empty MacCall(0)); spanless_eq_enum!(StrStyle; Cooked Raw(0)); +spanless_eq_enum!(StructRest; Base(0) Rest(0) None); spanless_eq_enum!(TokenTree; Token(0) Delimited(0 1 2)); spanless_eq_enum!(TraitBoundModifier; None Maybe MaybeConst MaybeConstMaybe); spanless_eq_enum!(TraitObjectSyntax; Dyn None); diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index b3e540a8c5..f6d5998a4c 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -198,7 +198,7 @@ fn librustc_parse_and_rewrite(input: &str) -> Option> { /// This method operates on librustc objects. fn librustc_brackets(mut librustc_expr: P) -> Option> { use rustc_ast::ast::{ - Block, BorrowKind, Expr, ExprKind, Field, GenericArg, Pat, Stmt, StmtKind, Ty, + Block, BorrowKind, Expr, ExprKind, Field, GenericArg, Pat, Stmt, StmtKind, StructRest, Ty, }; use rustc_ast::mut_visit::{noop_visit_generic_arg, MutVisitor}; use rustc_data_structures::map_in_place::MapInPlace; @@ -237,13 +237,15 @@ fn librustc_brackets(mut librustc_expr: P) -> Option> { } fn noop_visit_expr(e: &mut Expr, vis: &mut T) { - use rustc_ast::mut_visit::{noop_visit_expr, visit_opt, visit_thin_attrs}; + use rustc_ast::mut_visit::{noop_visit_expr, visit_thin_attrs}; match &mut e.kind { ExprKind::AddrOf(BorrowKind::Raw, ..) => {} ExprKind::Struct(path, fields, expr) => { vis.visit_path(path); fields.flat_map_in_place(|field| flat_map_field(field, vis)); - visit_opt(expr, |expr| vis.visit_expr(expr)); + if let StructRest::Base(expr) = expr { + vis.visit_expr(expr); + } vis.visit_id(&mut e.id); vis.visit_span(&mut e.span); visit_thin_attrs(&mut e.attrs, vis); From 2c83686bede4f64353e9ad10033a23f77e56eb94 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 15 Nov 2020 17:58:04 -0800 Subject: [PATCH 18/81] Update test suite to nightly-2020-11-16 --- tests/common/eq.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/common/eq.rs b/tests/common/eq.rs index 8b6c510be5..67132c4b96 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -369,9 +369,10 @@ spanless_eq_enum!(ExprKind; Box(0) Array(0) ConstBlock(0) Call(0 1) MethodCall(0 1 2) Tup(0) Binary(0 1 2) Unary(0 1) Lit(0) Cast(0 1) Type(0 1) Let(0 1) If(0 1 2) While(0 1 2) ForLoop(0 1 2 3) Loop(0 1) Match(0 1) Closure(0 1 2 3 4 5) Block(0 1) Async(0 1 2) Await(0) TryBlock(0) - Assign(0 1 2) AssignOp(0 1 2) Field(0 1) Index(0 1) Range(0 1 2) Path(0 1) - AddrOf(0 1 2) Break(0 1) Continue(0) Ret(0) InlineAsm(0) LlvmInlineAsm(0) - MacCall(0) Struct(0 1 2) Repeat(0 1) Paren(0) Try(0) Yield(0) Err); + Assign(0 1 2) AssignOp(0 1 2) Field(0 1) Index(0 1) Underscore Range(0 1 2) + Path(0 1) AddrOf(0 1 2) Break(0 1) Continue(0) Ret(0) InlineAsm(0) + LlvmInlineAsm(0) MacCall(0) Struct(0 1 2) Repeat(0 1) Paren(0) Try(0) + Yield(0) Err); spanless_eq_enum!(InlineAsmOperand; In(reg expr) Out(reg late expr) InOut(reg late expr) SplitInOut(reg late in_expr out_expr) Const(expr) Sym(expr)); From 64e006e9bc31737cc8801f00736f1acd8cb95130 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 21 Nov 2020 16:45:40 +0900 Subject: [PATCH 19/81] Fix panic_fmt warning --- src/lit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lit.rs b/src/lit.rs index e45b81ba1b..211fb7e6c3 100644 --- a/src/lit.rs +++ b/src/lit.rs @@ -1280,7 +1280,7 @@ mod value { fn backslash_u(mut s: &str) -> (char, &str) { if byte(s, 0) != b'{' { - panic!("expected {{ after \\u"); + panic!("{}", "expected { after \\u"); } s = &s[1..]; From b04357f635fb70a71212b681d0f1c73d85fc1f50 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 21 Nov 2020 12:47:35 -0800 Subject: [PATCH 20/81] Fix incorrect doc comment about Lifetime being conditional --- src/lifetime.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lifetime.rs b/src/lifetime.rs index 19f8a22fed..eb80d5edf0 100644 --- a/src/lifetime.rs +++ b/src/lifetime.rs @@ -16,9 +16,6 @@ use crate::lookahead; /// the XID_Start property. /// - All following characters must be Unicode code points with the XID_Continue /// property. -/// -/// *This type is available only if Syn is built with the `"derive"` or `"full"` -/// feature.* pub struct Lifetime { pub apostrophe: Span, pub ident: Ident, From 4315d469858e5027a9f68071d210422ff9c354af Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 21 Nov 2020 12:38:18 -0800 Subject: [PATCH 21/81] Set doc(cfg(...)) on feature gated APIs --- Cargo.toml | 1 + src/attr.rs | 12 ++++++++++ src/data.rs | 11 +++++++++ src/derive.rs | 5 ++++ src/expr.rs | 49 ++++++++++++++++++++++++++++++++++++++++ src/file.rs | 1 + src/generics.rs | 30 ++++++++++++++++++++++++ src/group.rs | 3 +++ src/item.rs | 41 +++++++++++++++++++++++++++++++++ src/lib.rs | 12 ++++++++++ src/lit.rs | 2 ++ src/mac.rs | 4 ++++ src/op.rs | 2 ++ src/parse_macro_input.rs | 1 + src/parse_quote.rs | 1 + src/pat.rs | 17 ++++++++++++++ src/path.rs | 12 ++++++++++ src/punctuated.rs | 4 ++++ src/stmt.rs | 4 ++++ src/ty.rs | 20 ++++++++++++++++ 20 files changed, 232 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 22e29e410d..025ce9cdd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ required-features = ["full", "parsing"] [package.metadata.docs.rs] all-features = true targets = ["x86_64-unknown-linux-gnu"] +rustdoc-args = ["--cfg", "doc_cfg"] [package.metadata.playground] features = ["full", "visit", "visit-mut", "fold", "extra-traits"] diff --git a/src/attr.rs b/src/attr.rs index ea6ab09d1b..5092344210 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -144,6 +144,7 @@ ast_struct! { /// }; /// assert_eq!(doc, attr); /// ``` + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct Attribute { pub pound_token: Token![#], pub style: AttrStyle, @@ -160,6 +161,7 @@ impl Attribute { /// *This function is available only if Syn is built with the `"parsing"` /// feature.* #[cfg(feature = "parsing")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_meta(&self) -> Result { fn clone_ident_segment(segment: &PathSegment) -> PathSegment { PathSegment { @@ -207,6 +209,7 @@ impl Attribute { /// *This function is available only if Syn is built with the `"parsing"` /// feature.* #[cfg(feature = "parsing")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_args(&self) -> Result { self.parse_args_with(T::parse) } @@ -216,6 +219,7 @@ impl Attribute { /// *This function is available only if Syn is built with the `"parsing"` /// feature.* #[cfg(feature = "parsing")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_args_with(&self, parser: F) -> Result { let parser = |input: ParseStream| { let args = enter_args(self, input)?; @@ -229,6 +233,7 @@ impl Attribute { /// *This function is available only if Syn is built with the `"parsing"` /// feature.* #[cfg(feature = "parsing")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_outer(input: ParseStream) -> Result> { let mut attrs = Vec::new(); while input.peek(Token![#]) { @@ -242,6 +247,7 @@ impl Attribute { /// *This function is available only if Syn is built with the `"parsing"` /// feature.* #[cfg(feature = "parsing")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_inner(input: ParseStream) -> Result> { let mut attrs = Vec::new(); while input.peek(Token![#]) && input.peek2(Token![!]) { @@ -321,6 +327,7 @@ ast_enum! { /// - `#![feature(proc_macro)]` /// - `//! # Example` /// - `/*! Please file an issue */` + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum AttrStyle { Outer, Inner(Token![!]), @@ -354,6 +361,7 @@ ast_enum_of_structs! { // // TODO: change syntax-tree-enum link to an intra rustdoc link, currently // blocked on https://github.com/rust-lang/rust/issues/62833 + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum Meta { Path(Path), @@ -370,6 +378,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct MetaList { pub path: Path, pub paren_token: token::Paren, @@ -382,6 +391,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct MetaNameValue { pub path: Path, pub eq_token: Token![=], @@ -408,6 +418,7 @@ ast_enum_of_structs! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum NestedMeta { /// A structured meta item, like the `Copy` in `#[derive(Copy)]` which /// would be a nested `Meta::Path`. @@ -453,6 +464,7 @@ ast_enum_of_structs! { /// # "".parse().unwrap() /// } /// ``` +#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub type AttributeArgs = Vec; pub trait FilterAttrs<'a> { diff --git a/src/data.rs b/src/data.rs index bb6a854f44..1487d288e4 100644 --- a/src/data.rs +++ b/src/data.rs @@ -6,6 +6,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct Variant { /// Attributes tagged on the variant. pub attrs: Vec, @@ -35,6 +36,7 @@ ast_enum_of_structs! { // // TODO: change syntax-tree-enum link to an intra rustdoc link, currently // blocked on https://github.com/rust-lang/rust/issues/62833 + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum Fields { /// Named fields of a struct or struct variant such as `Point { x: f64, /// y: f64 }`. @@ -54,6 +56,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct FieldsNamed { pub brace_token: token::Brace, pub named: Punctuated, @@ -65,6 +68,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct FieldsUnnamed { pub paren_token: token::Paren, pub unnamed: Punctuated, @@ -149,6 +153,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct Field { /// Attributes tagged on the field. pub attrs: Vec, @@ -183,6 +188,7 @@ ast_enum_of_structs! { // // TODO: change syntax-tree-enum link to an intra rustdoc link, currently // blocked on https://github.com/rust-lang/rust/issues/62833 + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum Visibility { /// A public visibility level: `pub`. Public(VisPublic), @@ -204,6 +210,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct VisPublic { pub pub_token: Token![pub], } @@ -214,6 +221,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct VisCrate { pub crate_token: Token![crate], } @@ -225,6 +233,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct VisRestricted { pub pub_token: Token![pub], pub paren_token: token::Paren, @@ -291,6 +300,7 @@ pub mod parsing { impl Field { /// Parses a named (braced struct) field. + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_named(input: ParseStream) -> Result { Ok(Field { attrs: input.call(Attribute::parse_outer)?, @@ -302,6 +312,7 @@ pub mod parsing { } /// Parses an unnamed (tuple struct) field. + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] pub fn parse_unnamed(input: ParseStream) -> Result { Ok(Field { attrs: input.call(Attribute::parse_outer)?, diff --git a/src/derive.rs b/src/derive.rs index cbfd0da54a..83dcc90702 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -5,6 +5,7 @@ ast_struct! { /// Data structure sent to a `proc_macro_derive` macro. /// /// *This type is available only if Syn is built with the `"derive"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] pub struct DeriveInput { /// Attributes tagged on the whole struct or enum. pub attrs: Vec, @@ -36,6 +37,7 @@ ast_enum_of_structs! { // // TODO: change syntax-tree-enum link to an intra rustdoc link, currently // blocked on https://github.com/rust-lang/rust/issues/62833 + #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] pub enum Data { /// A struct input to a `proc_macro_derive` macro. Struct(DataStruct), @@ -55,6 +57,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] pub struct DataStruct { pub struct_token: Token![struct], pub fields: Fields, @@ -67,6 +70,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] pub struct DataEnum { pub enum_token: Token![enum], pub brace_token: token::Brace, @@ -79,6 +83,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))] pub struct DataUnion { pub union_token: Token![union], pub fields: FieldsNamed, diff --git a/src/expr.rs b/src/expr.rs index 45dd0ce347..b246551c1c 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -86,6 +86,7 @@ ast_enum_of_structs! { /// A sign that you may not be choosing the right variable names is if you /// see names getting repeated in your code, like accessing /// `receiver.receiver` or `pat.pat` or `cond.cond`. + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum Expr { /// A slice literal expression: `[a, b, c, d]`. Array(ExprArray), @@ -232,6 +233,7 @@ ast_struct! { /// A slice literal expression: `[a, b, c, d]`. /// /// *This type is available only if Syn is built with the `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprArray #full { pub attrs: Vec, pub bracket_token: token::Bracket, @@ -243,6 +245,7 @@ ast_struct! { /// An assignment expression: `a = compute()`. /// /// *This type is available only if Syn is built with the `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprAssign #full { pub attrs: Vec, pub left: Box, @@ -255,6 +258,7 @@ ast_struct! { /// A compound assignment expression: `counter += 1`. /// /// *This type is available only if Syn is built with the `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprAssignOp #full { pub attrs: Vec, pub left: Box, @@ -267,6 +271,7 @@ ast_struct! { /// An async block: `async { ... }`. /// /// *This type is available only if Syn is built with the `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprAsync #full { pub attrs: Vec, pub async_token: Token![async], @@ -279,6 +284,7 @@ ast_struct! { /// An await expression: `fut.await`. /// /// *This type is available only if Syn is built with the `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprAwait #full { pub attrs: Vec, pub base: Box, @@ -292,6 +298,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct ExprBinary { pub attrs: Vec, pub left: Box, @@ -304,6 +311,7 @@ ast_struct! { /// A blocked scope: `{ ... }`. /// /// *This type is available only if Syn is built with the `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub struct ExprBlock #full { pub attrs: Vec, pub label: Option