Repository: dtolnay/syn
Pull request #1299 (2023-01-16 07:06:16)

Update to Rust 2021 edition


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6d852632..d7ce6214 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -36,7 +36,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        rust: [stable, beta, 1.31.0]
+        rust: [stable, beta, 1.56.0]
         include:
           - rust: nightly
             components: rustc-dev
diff --git a/Cargo.toml b/Cargo.toml
index 5dc9af18..4f6454ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["David Tolnay <dtolnay@gmail.com>"]
 categories = ["development-tools::procedural-macro-helpers", "parser-implementations"]
 description = "Parser for Rust source code"
 documentation = "https://docs.rs/syn"
-edition = "2018"
+edition = "2021"
 include = [
     "/benches/**",
     "/build.rs",
@@ -19,7 +19,7 @@ include = [
 keywords = ["macros", "syn"]
 license = "MIT OR Apache-2.0"
 repository = "https://github.com/dtolnay/syn"
-rust-version = "1.31"
+rust-version = "1.56"
 
 [features]
 default = ["derive", "parsing", "printing", "clone-impls", "proc-macro"]
diff --git a/README.md b/README.md
index eeef83dd..30e07c7b 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ contains some APIs that may be useful more generally.
 [`syn::DeriveInput`]: https://docs.rs/syn/1.0/syn/struct.DeriveInput.html
 [parser functions]: https://docs.rs/syn/1.0/syn/parse/index.html
 
-*Version requirement: Syn supports rustc 1.31 and up.*
+*Version requirement: Syn supports rustc 1.56 and up.*
 
 [*Release notes*](https://github.com/dtolnay/syn/releases)
 
@@ -104,9 +104,8 @@ pub fn my_macro(input: TokenStream) -> TokenStream {
 ```
 
 The [`heapsize`] example directory shows a complete working implementation of a
-derive macro. It works on any Rust compiler 1.31+. The example derives a
-`HeapSize` trait which computes an estimate of the amount of heap memory owned
-by a value.
+derive macro. The example derives a `HeapSize` trait which computes an estimate
+of the amount of heap memory owned by a value.
 
 [`heapsize`]: examples/heapsize
 
diff --git a/dev/Cargo.toml b/dev/Cargo.toml
index ebefc1d3..eb3ff57c 100644
--- a/dev/Cargo.toml
+++ b/dev/Cargo.toml
@@ -2,7 +2,7 @@
 name = "syn-dev"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [lib]
diff --git a/examples/dump-syntax/Cargo.toml b/examples/dump-syntax/Cargo.toml
index 68c1bd30..2f33a4f3 100644
--- a/examples/dump-syntax/Cargo.toml
+++ b/examples/dump-syntax/Cargo.toml
@@ -2,7 +2,7 @@
 name = "dump-syntax"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [dependencies]
diff --git a/examples/heapsize/example/Cargo.toml b/examples/heapsize/example/Cargo.toml
index 85c7699c..ab2c4266 100644
--- a/examples/heapsize/example/Cargo.toml
+++ b/examples/heapsize/example/Cargo.toml
@@ -2,7 +2,7 @@
 name = "heapsize_example"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [dependencies]
diff --git a/examples/heapsize/heapsize/Cargo.toml b/examples/heapsize/heapsize/Cargo.toml
index 27bb9541..2b2c31e9 100644
--- a/examples/heapsize/heapsize/Cargo.toml
+++ b/examples/heapsize/heapsize/Cargo.toml
@@ -2,7 +2,7 @@
 name = "heapsize"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [dependencies]
diff --git a/examples/heapsize/heapsize_derive/Cargo.toml b/examples/heapsize/heapsize_derive/Cargo.toml
index a3cfcb6b..06066cca 100644
--- a/examples/heapsize/heapsize_derive/Cargo.toml
+++ b/examples/heapsize/heapsize_derive/Cargo.toml
@@ -2,7 +2,7 @@
 name = "heapsize_derive"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [lib]
diff --git a/examples/lazy-static/example/Cargo.toml b/examples/lazy-static/example/Cargo.toml
index 44d155eb..b6e95a2b 100644
--- a/examples/lazy-static/example/Cargo.toml
+++ b/examples/lazy-static/example/Cargo.toml
@@ -2,7 +2,7 @@
 name = "lazy-static-example"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [dependencies]
diff --git a/examples/lazy-static/lazy-static/Cargo.toml b/examples/lazy-static/lazy-static/Cargo.toml
index 5ee74223..be966caa 100644
--- a/examples/lazy-static/lazy-static/Cargo.toml
+++ b/examples/lazy-static/lazy-static/Cargo.toml
@@ -2,7 +2,7 @@
 name = "lazy_static"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [lib]
diff --git a/examples/trace-var/example/Cargo.toml b/examples/trace-var/example/Cargo.toml
index 45ab3fd2..b95e4c35 100644
--- a/examples/trace-var/example/Cargo.toml
+++ b/examples/trace-var/example/Cargo.toml
@@ -2,7 +2,7 @@
 name = "trace-var-example"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [dependencies]
diff --git a/examples/trace-var/trace-var/Cargo.toml b/examples/trace-var/trace-var/Cargo.toml
index 6490fa4a..21ae0383 100644
--- a/examples/trace-var/trace-var/Cargo.toml
+++ b/examples/trace-var/trace-var/Cargo.toml
@@ -2,7 +2,7 @@
 name = "trace-var"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [lib]
diff --git a/json/Cargo.toml b/json/Cargo.toml
index c4c81144..7a5cc8ef 100644
--- a/json/Cargo.toml
+++ b/json/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["David Tolnay <dtolnay@gmail.com>"]
 categories = ["development-tools::procedural-macro-helpers"]
 description = "Syntax tree describing Syn's syntax tree"
 documentation = "https://docs.rs/syn-codegen"
-edition = "2018"
+edition = "2021"
 keywords = ["syn"]
 license = "MIT OR Apache-2.0"
 repository = "https://github.com/dtolnay/syn"
diff --git a/src/error.rs b/src/error.rs
index 1d612b82..4a34550f 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -7,7 +7,6 @@ use proc_macro2::{
 #[cfg(feature = "printing")]
 use quote::ToTokens;
 use std::fmt::{self, Debug, Display};
-use std::iter::FromIterator;
 use std::slice;
 use std::vec;
 
diff --git a/src/expr.rs b/src/expr.rs
index 92f1c64e..0a9c8861 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -924,7 +924,7 @@ ast_struct! {
 
 #[cfg(feature = "full")]
 ast_struct! {
-    /// One arm of a `match` expression: `0...10 => { return true; }`.
+    /// One arm of a `match` expression: `0..=10 => { return true; }`.
     ///
     /// As in:
     ///
@@ -932,7 +932,7 @@ ast_struct! {
     /// # fn f() -> bool {
     /// #     let n = 0;
     /// match n {
-    ///     0...10 => {
+    ///     0..=10 => {
     ///         return true;
     ///     }
     ///     // ...
diff --git a/src/lib.rs b/src/lib.rs
index 3d65512e..555d39bf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -94,9 +94,8 @@
 //! ```
 //!
 //! The [`heapsize`] example directory shows a complete working implementation
-//! of a derive macro. It works on any Rust compiler 1.31+. The example derives
-//! a `HeapSize` trait which computes an estimate of the amount of heap memory
-//! owned by a value.
+//! of a derive macro. The example derives a `HeapSize` trait which computes an
+//! estimate of the amount of heap memory owned by a value.
 //!
 //! [`heapsize`]: https://github.com/dtolnay/syn/tree/master/examples/heapsize
 //!
@@ -930,7 +929,7 @@ pub fn parse_str<T: parse::Parse>(s: &str) -> Result<T> {
 /// use std::fs::File;
 /// use std::io::Read;
 ///
-/// fn run() -> Result<(), Box<Error>> {
+/// fn run() -> Result<(), Box<dyn Error>> {
 ///     let mut file = File::open("path/to/code.rs")?;
 ///     let mut content = String::new();
 ///     file.read_to_string(&mut content)?;
diff --git a/src/path.rs b/src/path.rs
index adddcbff..369af385 100644
--- a/src/path.rs
+++ b/src/path.rs
@@ -521,7 +521,6 @@ pub mod parsing {
         /// ```
         /// use proc_macro2::TokenStream;
         /// use syn::{Attribute, Error, Meta, Result};
-        /// # use std::iter::FromIterator;
         ///
         /// fn get_serde_meta_item(attr: &Attribute) -> Result<Option<&TokenStream>> {
         ///     if attr.path().is_ident("serde") {
diff --git a/src/punctuated.rs b/src/punctuated.rs
index 9891b382..97b8217c 100644
--- a/src/punctuated.rs
+++ b/src/punctuated.rs
@@ -26,7 +26,6 @@ use std::fmt::{self, Debug};
 use std::hash::{Hash, Hasher};
 #[cfg(any(feature = "full", feature = "derive"))]
 use std::iter;
-use std::iter::FromIterator;
 use std::ops::{Index, IndexMut};
 use std::option;
 use std::slice;


Test patch:
diff --git a/tests/crates/Cargo.toml b/tests/crates/Cargo.toml
index 9db7dcef..7bd6cddd 100644
--- a/tests/crates/Cargo.toml
+++ b/tests/crates/Cargo.toml
@@ -2,7 +2,7 @@
 name = "syn-parse-crates"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [[bin]]
diff --git a/tests/features/Cargo.toml b/tests/features/Cargo.toml
index 7f7c8032..22c71992 100644
--- a/tests/features/Cargo.toml
+++ b/tests/features/Cargo.toml
@@ -2,7 +2,7 @@
 name = "syn-test-suite"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [lib]
diff --git a/tests/features/macro/Cargo.toml b/tests/features/macro/Cargo.toml
index ccdf06cf..4d1f6916 100644
--- a/tests/features/macro/Cargo.toml
+++ b/tests/features/macro/Cargo.toml
@@ -2,7 +2,7 @@
 name = "syn-test-suite-feature-check"
 version = "0.0.0"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
-edition = "2018"
+edition = "2021"
 publish = false
 
 [lib]
diff --git a/tests/test_expr.rs b/tests/test_expr.rs
index dbed4cf0..3776f043 100644
--- a/tests/test_expr.rs
+++ b/tests/test_expr.rs
@@ -3,7 +3,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
 use quote::quote;
-use std::iter::FromIterator;
 use syn::{Expr, ExprRange};
 
 #[test]
diff --git a/tests/test_grouping.rs b/tests/test_grouping.rs
index 9eb7eee9..0f6ec498 100644
--- a/tests/test_grouping.rs
+++ b/tests/test_grouping.rs
@@ -2,7 +2,6 @@
 mod macros;
 
 use proc_macro2::{Delimiter, Group, Literal, Punct, Spacing, TokenStream, TokenTree};
-use std::iter::FromIterator;
 use syn::Expr;
 
 #[test]
diff --git a/tests/test_item.rs b/tests/test_item.rs
index 91c9f70e..ac152261 100644
--- a/tests/test_item.rs
+++ b/tests/test_item.rs
@@ -3,7 +3,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
 use quote::quote;
-use std::iter::FromIterator;
 use syn::{Item, ItemTrait};
 
 #[test]
diff --git a/tests/test_lit.rs b/tests/test_lit.rs
index ebe077c6..6bf04135 100644
--- a/tests/test_lit.rs
+++ b/tests/test_lit.rs
@@ -5,7 +5,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, Literal, Span, TokenStream, TokenTree};
 use quote::ToTokens;
-use std::iter::FromIterator;
 use std::str::FromStr;
 use syn::{Lit, LitFloat, LitInt, LitStr};
 
diff --git a/tests/test_parse_buffer.rs b/tests/test_parse_buffer.rs
index cc23e9ba..f2ca59c7 100644
--- a/tests/test_parse_buffer.rs
+++ b/tests/test_parse_buffer.rs
@@ -1,7 +1,6 @@
 #![allow(clippy::non_ascii_literal)]
 
 use proc_macro2::{Delimiter, Group, Punct, Spacing, TokenStream, TokenTree};
-use std::iter::FromIterator;
 use syn::parse::{discouraged::Speculative, Parse, ParseStream, Parser, Result};
 use syn::{parenthesized, Token};
 
diff --git a/tests/test_pat.rs b/tests/test_pat.rs
index c1e51273..944235a9 100644
--- a/tests/test_pat.rs
+++ b/tests/test_pat.rs
@@ -3,7 +3,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
 use quote::quote;
-use std::iter::FromIterator;
 use syn::parse::Parser;
 use syn::{Item, Pat, Stmt};
 
diff --git a/tests/test_path.rs b/tests/test_path.rs
index c732eff7..837b2161 100644
--- a/tests/test_path.rs
+++ b/tests/test_path.rs
@@ -3,7 +3,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
 use quote::{quote, ToTokens};
-use std::iter::FromIterator;
 use syn::{parse_quote, Expr, Type, TypePath};
 
 #[test]
diff --git a/tests/test_stmt.rs b/tests/test_stmt.rs
index 4595c04c..09ab54ff 100644
--- a/tests/test_stmt.rs
+++ b/tests/test_stmt.rs
@@ -5,7 +5,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
 use quote::quote;
-use std::iter::FromIterator;
 use syn::Stmt;
 
 #[test]
diff --git a/tests/test_ty.rs b/tests/test_ty.rs
index 335cafa2..a8d7b943 100644
--- a/tests/test_ty.rs
+++ b/tests/test_ty.rs
@@ -3,7 +3,6 @@ mod macros;
 
 use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
 use quote::quote;
-use std::iter::FromIterator;
 use syn::Type;
 
 #[test]
diff --git a/tests/test_visibility.rs b/tests/test_visibility.rs
index 7b2c00ba..7a48a6ec 100644
--- a/tests/test_visibility.rs
+++ b/tests/test_visibility.rs
@@ -2,7 +2,6 @@
 mod macros;
 
 use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
-use std::iter::FromIterator;
 use syn::parse::{Parse, ParseStream};
 use syn::{DeriveInput, Result, Visibility};