Update Rust crate syn to v2
This MR contains the following updates:
Package | Type | Update | Change |
---|---|---|---|
syn | dependencies | major |
1.0 -> 2.0
|
Release Notes
dtolnay/syn (syn)
v2.0.87
- Add
Cursor::any_group
(#1777) - Add
Expr::peek
(#1778) - Improve syntax support for enum discriminant expressions in non-"full" mode (#1779)
v2.0.86
- Support peeking the end of a parse stream (#1689)
- Allow
parse_quote!
to produce Vec<Attribute> (#1775)
v2.0.85
- Preserve extern static unsafety in ForeignItem::Verbatim (#1773)
v2.0.84
- Parse safe and explicitly unsafe extern items (#1768, https://github.com/rust-lang/rust/issues/123743, https://github.com/rust-lang/rfcs/pull/3484)
- Parse self captures:
impl Sized + use<Self>
(#1772)
v2.0.83
- Documentation improvements
v2.0.82
- Provide
Parse
impls for PreciseCapture and CapturedParam (#1757, #1758) - Support parsing
unsafe
attributes (#1759) - Add Fold and VisitMut methods for Vec<Attribute> (#1762)
v2.0.81
- Add TypeParamBound::PreciseCapture to represent precise capture syntax
impl Trait + use<'a, T>
(#1752, #1753, #1754)
v2.0.80
- Add
Expr::RawAddr
(#1743) - Reject precise captures and ~const in inappropriate syntax positions (#1747)
- Reject trait bound containing only precise capture (#1748)
v2.0.79
- Fix infinite loop on parsing chained ranges (#1741)
- Fix panic in parsing
use
items containing absolute paths (#1742)
v2.0.78
- Fix infinite loop on chained comparison (#1739)
v2.0.77
- Support parsing
Expr::Tuple
in non-"full" mode (#1727)
v2.0.76
- Enforce that tail call
become
keyword is followed by an expression (#1725)
v2.0.75
- Automatically fill in missing turbofish when printing ExprPath and other paths in expression position (#1722)
v2.0.74
- Fix "temporary is dropped and runs the destructor for type `impl Iterator`" regression affecting certain use of
Generics
iterator methods (#1719)
v2.0.73
- Support parsing unnamed C varargs within function pointer types (#1711)
- Improve synthesized error message on unexpected tokens at the end of the expected contents of a delimited group (#1713)
- Support parsing unstable tail call syntax (#1714, https://github.com/rust-lang/rust/issues/112788)
- Add
Fields::members
iterator (#1716, thanks @Fancyflame)
v2.0.72
- Parse
use<'a, T>
precise capturing bounds (#1707, thanks @compiler-errors)
v2.0.71
- Do not require mutable borrow in Punctuated::get() (#1706, thanks @lemunozm)
v2.0.70
- Improve parenthesization of closures, jumps, ranges, chained comparisons, and let (#1694, #1695, #1698, #1699, #1700)
v2.0.69
- Correctly parenthesize labeled loops inside a break value (#1692)
- Add
Punctuated::get
andget_mut
(#1693)
v2.0.68
- Improve panic location when
parse_quote!
parses invalid syntax (#1690, thanks @stepancheg) - More efficient peek implementation for
Group
andLifetime
(#1687)
v2.0.67
- Produce more accurate error message locations for errors located at the end of a nested group (#1679, #1680)
- Support peeking
LitCStr
in ParseStream::peek (#1682)
v2.0.66
- Allow braced structs when parsing ExprLet (#1671)
v2.0.65
v2.0.64
- Support using ParseBuffer across
catch_unwind
(#1646) - Validate that the expression in a let-else ends in brace as required by rustc (#1648, #1649)
- Legalize invalid const generic arguments by wrapping in braces (#1654, #1655)
- Fix some expression precedence edge cases involving
break
andreturn
in loop headers (#1656) - Always print closure bodies with a brace when the closure has an explicit return type (#1658)
- Automatically insert necessary parentheses in ToTokens for Expr when required by expression precedence (#1659)
- Support struct literal syntax in match guard expressions (#1662)
v2.0.63
- Parse and print long if-else-if chains without reliance on deep recursion to avoid overflowing stack (#1644, #1645)
v2.0.62
v2.0.61
- Check for legal binding name in the ident of Pat::Ident (#1627)
- Resolve unexpected_cfgs warning (#1635)
v2.0.60
- Improve how None-delimited groups are counted by
peek
(#1625)
v2.0.59
- Parse
c"…"
andcr"…"
C-string literal syntax asLit::CStr
(#1502)
v2.0.58
- Support
$
incustom_punctuation!
macro (#1611)
v2.0.57
- Eliminate dependency on
quote
when built with default-features disabled and the "proc-macro" feature enabled (#1608, thanks @BD103)
v2.0.56
- Apply RUSTC_WORKSPACE_WRAPPER when deciding whether to run nightly-only tests (#1605)
v2.0.55
- Restore compatibility with rustc 1.56 through 1.59 (#1603)
v2.0.54
- Fix dead code warning in generated code when using
custom_keyword!
with syn's "printing" feature disabled (#1602)
v2.0.53
- Implement Copy, Clone, and ToTokens for syn::parse::Nothing (#1597)
v2.0.52
- Add an expression parser that uses match-arm's boundary rules (#1593)
v2.0.51
- Resolve non_local_definitions warnings in generated code under rustc 1.78-nightly
v2.0.50
- Fix unused_imports warnings when compiled by rustc 1.78
v2.0.49
- Improve error location when parsing from an empty string literal using
LitStr::parse
(#1590)
v2.0.48
- Improve error message on unexpected token after
else
(#1578)
v2.0.47
- Improve error messages related to proc_macro::LexError (#1575)
v2.0.46
- Update proc-macro2 to fix caching issue when using a rustc-wrapper such as sccache
v2.0.45
- Parse unsupported expressions in enum discriminants of
DeriveInput
asExpr::Verbatim
in non-"full" mode, instead of error (#1513) - Support parsing
PatType
withparse_quote!
(#1573)
v2.0.44
- Documentation improvements
v2.0.43
- Insert trailing comma if not already present when printing a 1-tuple in pattern position (#1553)
v2.0.42
- Documentation improvements
v2.0.41
- Support parsing syn::Field in
parse_quote!
(#1548)
v2.0.40
- Fix some edge cases of handling None-delimited groups in expression parser (#1539, #1541, #1542, #1543, #1544, #1545)
v2.0.39
- Fix parsing of return expression in match guards (#1528)
- Improve error message on labeled loop as value expression for break (#1531)
v2.0.38
- Fix "method 'peek' has an incompatible type for trait" error when defining
bool
as a custom keyword (#1518, thanks @Vanille-N)
v2.0.37
- Work around incorrect future compatibility warning in rustc 1.74.0-nightly
v2.0.36
- Restore compatibility with
--generate-link-to-definition
documentation builds (#1514)
v2.0.35
v2.0.34
- Documentation improvements
v2.0.33
- Special handling for the
(/*ERROR*/)
placeholder that rustc uses for macros that fail to expand
v2.0.32
- Add
Path::require_ident
accessor (#1496, thanks @Fancyflame)
v2.0.31
- Parse generics and where-clause on const items (https://github.com/rust-lang/rust/issues/113521)
v2.0.30
- Parse unnamed struct/union type syntax (https://github.com/rust-lang/rust/issues/49804)
v2.0.29
- Partially work around rust-analyzer bug (https://github.com/rust-lang/rust-analyzer/issues/9911)
v2.0.28
- Fix inconsistency between full and non-full expression parse errors (#1491)
v2.0.27
- Documentation improvements (thanks @GuillaumeGomez)
v2.0.26
- Implement
Spanned
forQSelf
(#1465)
v2.0.25
- Support single identifier as unbraced const generic argument (#1483)
- Produce error message when LitStr::parse is used on a suffixed string literal (#1484)
v2.0.24
- Fix duplication of braces around const generic argument in non-full mode (#1482)
v2.0.23
- Preserve attributes on verbatim Item in statement position (#1476)
- Support generic_const_exprs where-clauses such as
where [(); { T::COUNT }]:
in non-"full" mode (#1478)
v2.0.22
- Parse
c"…"
c-string literals (tracking issue: https://github.com/rust-lang/rust/issues/105723)
v2.0.21
- Fix value computed by
LitByteStr::value
in the case of a cooked byte string literal containing form feed or vertical tab characters following an escaped newline (#1474)
v2.0.20
- Documentation improvements
v2.0.19
- Improve rendering of compile errors within 2015-edition code calling a 2018+ edition proc macro (#1467, thanks @danielhenrymantilla)
v2.0.18
- Permit empty attr in syn::meta::parser (#1460)
v2.0.17
- Enable proc_macro support on wasm targets (#1459)
v2.0.16
- Parse
builtin #
syntax as Expr::Verbatim (https://github.com/rust-lang/rust/issues/110680, #1454)
v2.0.15
- Ensure
Type::Tuple
of length 1 prints as a tuple even if trailing comma is not provided in the Punctuated (#1444, thanks @Fancyflame)
v2.0.14
- Add Punctuated::pop_punct() (#1442, thanks @programmerjake)
v2.0.13
v2.0.12
- Refer to
compile_error!
by absolute path in token stream produced by syn::Error::to_compile_error (#1431, thanks @smoelius)
v2.0.11
- Improve error message on empty parens inside parse_nested_meta (#1428)
v2.0.10
- Fix visibility being parsed incorrectly on macro invocations inside of a trait
v2.0.9
- Disallow
type
items in an extern block, trait, or module from being markeddefault
- Disallow ImplItemFn from having an omitted function body, as in
impl T { fn f(&self); }
— omitted function bodies are allowed by TraitItemFn, but inimpl
blocks this syntax is now parsed as ImplItem::Verbatim rather than ImplItem::Fn
v2.0.8
- Treat
try
keyword as 2015-edition identifier in definition of try macro (#1422)
v2.0.7
- Fix parsing of
mut self
inside of Type::BareFn
v2.0.6
- Improve error message on missing ';' between statements (#1419)
- Keep non-brace macro invocations in trailing expr position as Expr::Macro (#1420)
v2.0.5
- Expose
ExprMacro
data structure even whenfeatures="full"
is not used (#1417)
v2.0.4
v2.0.3
- Expose
ExprGroup
data structure even whenfeatures="full"
is not used (#1412)
v2.0.2
- Documentation improvements
v2.0.1
- Add methods on syn::Meta for reporting error on an incorrect kind of attribute (#1409)
v2.0.0
This release contains a batch of syntax tree improvements to incorporate ongoing Rust language development from the past 3.5 years since syn 1.
It never seems like an ideal time to finalize a syntax tree design, considering the frankly alarming number of syntax-disrupting language features currently in flight: keyword generics, restrictions, capabilities and contexts, conditional constness, new varieties of literals, dyn revamp such as explicitly dyn-safe traits and dyn-star, expression syntax in various phases of being added or being torn out (const blocks, try blocks, raw references), auto traits and negative impls, generalizations to higher rank trait bounds, async closures and static async trait methods, postfix keywords, pattern types, return type notation, unsafe attributes, …
The plan continues to be the same as laid out originally in the 1.0.0 release announcement:
Be aware that the underlying Rust language will continue to evolve. Syn is able to accommodate most kinds of Rust grammar changes via the nonexhaustive enums and
Verbatim
variants in the syntax tree, but we will plan to put out new major versions on a 12 to 24 month cadence to incorporate ongoing language changes as needed.
If anything, the takeaway from the 3.5 year longevity of syn 1 is that this period was tamer from a language development perspective than anticipated, but that is unlikely to last and I think around 24 months is still the correct cadence to expect between releases going forward.
Breaking changes
- Minimum required Rust version is raised from rustc 1.31 to 1.56.
Expressions
-
Support for
box expr
syntax has been deleted, as it has been deleted recently from rustc. -
Support for type ascription syntax
expr: Type
in expression position has been deleted. -
Support for unstable
&raw const expr
raw-pointer reference syntax has been deleted. -
The representation of generic arguments has been unified between method calls and non-method paths into a single
GenericArgument
type, which supersedes the previousGenericMethodArgument
andMethodTurbofish
. -
Generic arguments now distinguish between associated types (
AssocType
) and associated constant values (AssocConst
). Previously these would be parsed ambiguously asBinding
. -
The binary assignment operators in
BinOp
have been renamed to align with the naming used by the standard library'score::ops
module's traits. For exampleBinOp::AddEq
is now calledBinOp::AddAssign
. -
Expr::Struct
struct construction expressions now support structs which are a variant of an enum associated type of a trait, as in<Type as Trait>::Assoc::Variant { ... }
, which has recently been added to Rust. -
Expr::Range
now follows thestart
andend
naming used by the standard library'sRangeBounds
trait, rather thanfrom
/to
orlo
/hi
. -
Expr::AssignOp
has been merged intoExpr::Binary
, which now represents both non-assignment and assignment binary operators. -
Stricter parsing of ranges. None of the following are valid expressions, but were previously accepted by syn:
..=
,lo..=
,...
,...hi
,lo...
,lo...hi
. -
Expr::Closure
now includes a representation forfor<...>
lifetimes.
Statements
-
Variants
Stmt::Expr
(tail-position expression without trailing semicolon) andStmt::Semi
(non-tail expression with trailing semicolon) have been combined intoStmt::Expr
with the optional semicolon represented byOption<Token![;]>
. -
The syntax tree for
Stmt::Local
has been extended to handlelet
/else
syntax. -
Macros in statement position are now uniformly parsed as
Stmt::Macro
. Previously these would be disambiguated toStmt::Item
, although it was ambiguous whether a macro in statement position would expand to an item (likethread_local! { ... }
) vs an expression (likeprintln! { ... }
).
Patterns
-
Pattern parsing for all the different syntactic positions in which patterns are allowed has been split into
Pat::parse_single
(for function- and closure-argument position, where top-level|
is not allowed),Pat::parse_multi
(where|
is allowed) andPat::parse_multi_with_leading_vert
(for the pattern of match arms, which allow an optional leading|
). Previously only a singleparse
behavior was supported and behaved like the newparse_single
. -
The
Pat
syntax tree now shares more common data structures with theExpr
syntax tree where possible, such as for literals, paths, macros, and ranges in pattern position. -
Parsing of struct field patterns does a better job rejecting bogus syntax such as
Struct { 0 asdf }
andStruct { ref mut 0: asdf }
, which were previously incorrectly accepted. -
Pat::Range
now supports one-sided ranges by representing the start and end bound of the range byOption<Expr>
. -
Pat::Struct
keeps track of attributes on the optional..
"rest" part of the pattern, as inlet Struct { x, #[cfg(any())] .. } = _;
. -
Parsing unary negation now enforces that only literal patterns can be unarily negated. For example
-self::CONST
and-const { 0i32 }
are not valid syntax in pattern position. -
Pat::TupleStruct
no longer wraps a value of typePatTuple
but represents that information in its fields directly. -
A single parenthesized pattern without trailing comma inside the parentheses is no longer considered a
Pat::Tuple
, it will be parsed asPat::Paren
. -
One-sided range patterns are no longer allowed inside of slice patterns.
[lo..]
and[..=hi]
are not considered valid pattern syntax by Rust.
Items
-
Typed
self
in a method signature, such asself: Pin<&mut Self>
, will now be parsed asFnArg::Receiver
. This meansself
, whether with or without an explicit type, is always treated as aReceiver
. Previously only the&self
and&mut self
shorthand receivers were parsed asReceiver
. -
TraitItem::Method
andImplItem::Method
have been renamed toTraitItem::Fn
andImplItem::Fn
, as they do not necessarily represent methods if the function signature contains noself
. -
Item::Macro2
has been deleted as "macros 2.0" syntax is no longer considered on track for stabilization. -
Various item kinds now hold
Generics
which didn't used to have them. -
The variadic argument of an extern function signature can now be given an optional parameter name.
-
WherePredicate::Eq
is no longer supported. -
Visibility::Crate
is no longer supported. This syntax has been removed from rustc. -
Public visibility is now represented by a single
Token![pub]
token rather than the oldVisPublic
struct. -
LifetimeDef
is now calledLifetimeParam
. This name makes more sense in the context of theGenericParam
enum (which also includesTypeParam
andConstParam
), and is the name that the Rust Reference uses. -
Modules and extern blocks (
Item::Mod
andItem::ForeignMod
) can now be markedunsafe
.
Attributes
-
The syntax tree for
Attribute
has been redesigned. The new API better accommodates attributes which mix structured and unstructured content at different levels of nesting. -
AttributeArgs
has been removed. UsePunctuated<Meta, Token![,]>
. -
For parsing attribute contents,
parse_meta()
is superseded by a new parsing library calledsyn::meta
, and theparse_nested_meta
method onAttribute
.
Tokens
-
In string literals, the handling of non-ASCII whitespace after trailing
\
now matches what is implemented by rustc. Space, horizontal tab, line feed, and carriage return are the only 4 whitespace characters which are supposed to be stripped from the beginning of the next line. -
The delimiter tokens
syn::token::Paren
,Bracket
, andBrace
now store 2 spans (the open and close punctuation separately) rather than just 1. Use.join()
to obtain a singleSpan
spanning the whole group. -
Keyword construction now requires a single span; an array of 1 span is no longer accepted. Use
Token![trait](span)
instead ofToken![trait]([span])
. -
Some token types have been renamed to conform with terminology used by the Rust Reference. These are
Add
->Plus
,Bang
->Not
,Colon2
->PathSep
,Div
->Slash
,Dot2
->DotDot
,Dot3
->DotDotDot
,Rem
->Percent
, andSub
->Minus
.
More
-
Several enums have been made
#[non_exhaustive]
in anticipation of upcoming language changes. This includesWherePredicate
,Lit
, andGenericArgument
. -
The
impl Extend<Pair<T, P>> for Punctuated<T, P>
now requiresP: Default
and will push a default punctuation between the pre-existing elements and the new ones, if there is not already a trailing punctuation. Previously it would panic in this situation. -
ParseStream::parse_terminated
now takes a peek-style punctuation argument instead of turbofish. Replaceinput.parse_terminated::<_, Token![,]>(Thing::parse)
withinput.parse_terminated(Thing::parse, Token![,])
.
Configuration
-
If you want to rebase/retry this MR, check this box
This MR has been generated by Renovate Bot.