Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
1
->2
Release Notes
dtolnay/syn
v2.0.8
Compare Source
try
keyword as 2015-edition identifier in definition of try macro (#1422)v2.0.7
Compare Source
mut self
inside of Type::BareFnv2.0.6
Compare Source
v2.0.5
Compare Source
ExprMacro
data structure even whenfeatures="full"
is not used (#1417)v2.0.4
Compare Source
v2.0.3
Compare Source
ExprGroup
data structure even whenfeatures="full"
is not used (#1412)v2.0.2
Compare Source
v2.0.1
Compare Source
v2.0.0
Compare Source
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:
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.
[API documentation for 2.0]
Breaking changes
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![,])
.v1.0.109
Compare Source
v1.0.108
Compare Source
LitStr::value
(#1381, thanks @ModProg)v1.0.107
Compare Source
-Zrustdoc-scrape-examples
on docs.rs for nowv1.0.106
Compare Source
v1.0.105
Compare Source
dyn
andimpl
type syntax (#1245)v1.0.104
Compare Source
PathArguments::is_none()
v1.0.103
Compare Source
PartialOrd
forCursor
(#1236, #1237, thanks @CAD97)v1.0.102
Compare Source
TokenBuffer
(#1223, thanks @CAD97)v1.0.101
Compare Source
v1.0.100
Compare Source
for<> || -> T {…}
(#1212, https://github.com/rust-lang/rust/issues/97362)dyn*
provisional syntax (#1213, https://github.com/rust-lang/rust/issues/91611)Struct { #[attr] .. }
(#1214)static async
andstatic async move
closures (#1215, https://github.com/rust-lang/rust/issues/62290)v1.0.99
Compare Source
v1.0.98
Compare Source
v1.0.97
Compare Source
v1.0.96
Compare Source
punct_mut()
method onsyn::punctuated::Pair
to returnOption<&mut P>
(#1183)v1.0.95
Compare Source
v1.0.94
Compare Source
v1.0.93
Compare Source
Some
means something unusual in the expression namespace of the scope wherecustom_keyword
is invoked (#1171, thanks @zakarumych)v1.0.92
Compare Source
v1.0.91
Compare Source
v1.0.90
Compare Source
Update recommended exhaustive matching idiom to use
non_exhaustive_omitted_patterns
lint:v1.0.89
Compare Source
mut self
in a bare fn type (#1148)v1.0.88
Compare Source
..
pattern in pattern oflet
(#1136)for<…>
lifetime introducer on closures (#1135)Nothing
(#1144)v1.0.87
Compare Source
v1.0.86
Compare Source
v1.0.85
Compare Source
token()
method to each variant of syn::Lit to expose the underlying token representation with original formattingv1.0.84
Compare Source
parse_quote_spanned!
macro which is a combinationparse_quote!
+quote_spanned!
v1.0.83
Compare Source
impl <Thing<>>::Trait for Type {}
(#1109)#[attr] let pat = val else { return }
(#1110)v1.0.82
Compare Source
::
disambiguator:Fn::() -> !
(#1096)v1.0.81
Compare Source
v1.0.80
Compare Source
~const
syntax in where-clauses (#1083, tracking issue https://github.com/rust-lang/rust/issues/67792)v1.0.79
Compare Source
+
indyn Trait
syntax, including bare (non-dyn
) pre-2018 trait object syntax (#1075, #1077, #1078, #1079, #1080, #1081)v1.0.78
Compare Source
+
in the bounds ofimpl Trait
type (#1073)v1.0.77
Compare Source
v1.0.76
Compare Source
let
–else
syntax (#1050, #1057)<E>::V {..}
(#1058, #1059)v1.0.75
Compare Source
v1.0.74
Compare Source
for<'a> dyn Trait<'a>
syntax; the correct representation isdyn for<'a> Trait<'a>
(#1042)v1.0.73
Compare Source
v1.0.72
Compare Source
v1.0.71
Compare Source
v1.0.70
Compare Source
|| .. .method()
(#1019)v1.0.69
Compare Source
v1.0.68
Compare Source
LexError
on conversion tosyn::Error
(#1006)v1.0.67
Compare Source
v1.0.66
Compare Source
full
mode (#978)v1.0.65
Compare Source
v1.0.64
Compare Source
clippy::expl_impl_clone_on_copy
pedantic lint in downstream custom token types (#976)v1.0.63
Compare Source
v1.0.62
Compare Source
v1.0.61
Compare Source
Punctuated
API (#970, thanks @osa1)Lifetime::span
andLifetime::set_span
accessors (#971)v1.0.60
Compare Source
Provide an idiom for testing exhaustiveness of pattern matches on
Expr
,Type
,Pat
,Item
,ForeignItem
,TraitItem
, andImplItem
(#694)The above is the only supported idiom for exhaustive matching of those enum. Do not write anything differently as it is not supported.
The conditional compilation on match-arms lets us fail your tests but not break your library when adding a variant. You will be notified by a test failure when a variant is added, so that you can add code to handle it, but your library will continue to compile and work for downstream users in the interim.
v1.0.59
Compare Source
v1.0.58
Compare Source
Allow literals to parse as a const generic path argument even without "full" feature enabled (#951)
v1.0.57
Compare Source
const fn
(#949)v1.0.56
Compare Source
Error::into_compile_error
v1.0.55
Compare Source
T<$ty>
(#944, #945)v1.0.54
Compare Source
impl
items with macro metavariable in the trait path:impl $trait for Type {...}
(#942)v1.0.53
Compare Source
impl !Trait {...}
syntax (#936)v1.0.52
Compare Source
unsafe extern
block syntax (#918)unsafe mod
syntax (#919)const {...}
block syntax (#921)v1.0.51
Compare Source
v1.0.50
Compare Source
doc(cfg(...))
on feature gated APIs for docs.rs-rendered documentation (#925)v1.0.48
Compare Source
v1.0.47
Compare Source
v1.0.46
Compare Source
#[derive(::serde::Serialize)]
(#909)v1.0.45
Compare Source
v1.0.44
Compare Source
v1.0.43
Compare Source
v1.0.42
Compare Source
v1.0.41
Compare Source
.
in a field access position, e.g.let _ = obj.-0.9E999999
(#895, thanks @sameer)parse_macro_input!
with a Parser function rather than type having a Parse impl (#896, thanks @sbrocket)v1.0.40
Compare Source
9e99e999
(#893)v1.0.39
Compare Source
v1.0.38
Compare Source
v1.0.37
Compare Source
Handle shebang in a way that matches rustc 1.46+ (#876, https://github.com/rust-lang/rust/pull/71487, https://github.com/rust-lang/rust/pull/73596)
Accept
tuple.0. 0
as a tuple indexing expression (#877)v1.0.36
Compare Source
v1.0.35
Compare Source
v1.0.34
Compare Source
v1.0.33
Compare Source
tuple.0.0
as an indexing expression (https://github.com/rust-lang/rust/pull/71322)Parse
impls for optional of proc-macro2 types:Option<TokenTree>
,Option<Punct>
,Option<Literal>
,Option<Group>
v1.0.32
Compare Source
v1.0.31
Compare Source
Add
Expr::parse_without_eager_brace
to parse expressions in ambiguous syntactic position.Rust grammar has an ambiguity where braces sometimes turn a path expression into a struct initialization and sometimes do not. In the following code, the expression
S {}
is one expression. Presumably there is an empty structstruct S {}
defined somewhere which it is instantiating.We would want to parse the above using
Expr::parse
after the=
token.But in the following,
S {}
is not a struct init expression.For that reason we would want to parse if-conditions using
Expr::parse_without_eager_brace
after theif
token. Same for similar syntactic positions such as the condition expr after awhile
token or the expr at the top of amatch
.The Rust grammar's choices around which way this ambiguity is resolved at various syntactic positions is fairly arbitrary. Really either parse behavior could work in most positions, and language designers just decide each case based on which is more likely to be what the programmer had in mind most of the time.
Note the grammar ambiguity on trailing braces is distinct from precedence and is not captured by assigning a precedence level to the braced struct init expr in relation to other operators. This can be illustrated by
return 0..S {}
vsmatch 0..S {}
. The former parses asreturn (0..(S {}))
implying tighter precedence for struct init than..
, while the latter parses asmatch (0..S) {}
implying tighter precedence for..
than struct init, a contradiction.v1.0.30
Compare Source
$struct {}
where $struct:ident (#842)v1.0.29
Compare Source
$macro!()
(#838)$seg<'a>
(#839)v1.0.28
Compare Source
v1.0.27
Compare Source
$fn(...)
(#833)v1.0.26
Compare Source
$first::rest
(https://github.com/rust-lang/rust/issues/72608, #832)v1.0.25
Compare Source
?const
trait bounds (#767)extern::
paths which were removed from nightly in January 2019 (#825, https://github.com/rust-lang/rust/pull/57572)Punctuated::clear
, analogous to Vec::clear (#828)v1.0.24
Compare Source
mut self
receiver in function pointer type (#812, #814)v1.0.23
Compare Source
Thanks @taiki-e for all of these.
v1.0.22
Compare Source
br#"..."#suffix
,b'?'suffix
,'?'suffix
(#799, #800)v1.0.21
Compare Source
v1.0.20
Compare Source
syn::Macro::parse_body
is triggered past the last token of the macro body (#791)v1.0.19
Compare Source
v1.0.18
Compare Source
v1.0.17
Compare Source
syn::Lit
indefault-features = false
modev1.0.16
Compare Source
&raw
raw reference operator (https://github.com/rust-lang/rust/issues/64490) to require explicitly specified constness,&raw mut
or&raw const
v1.0.15
Compare Source
Punctuated::first_mut
to return a mut reference to the first sequence elementv1.0.14
Compare Source
v1.0.13
Compare Source
v1.0.12
Compare Source
fn f(x: u8, &self)
v1.0.11
Compare Source
Implement quote::IdentFragment for syn::Member and syn::Index so that spans are preserved when using these types in quote's
format_ident!
macrov1.0.10
Compare Source
Hash
andEq
impls for syn::Member even without "extra-traits" feature enabled, as this type is commonly useful in a hashsetv1.0.9
Compare Source
crate
(#720, #723, thanks @mystor)v1.0.8
Compare Source
v1.0.7
Compare Source
Add a receiver getter to syn::Signature (#714, thanks @mystor)
v1.0.6
Compare Source
v1.0.5
Compare Source
v1.0.4
Compare Source
v1.0.3
Compare Source
Path::get_ident
(#696, thanks @infinity0)v1.0.2
Compare Source
v1.0.1
Compare Source
LitInt::base10_parse
to produce error that has the right span when parsing literal digitsConfiguration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.