Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dtolnay/syn
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.0.72
Choose a base ref
...
head repository: dtolnay/syn
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.0.73
Choose a head ref

Commits on Jul 21, 2024

  1. Copy the full SHA
    431784b View commit details

Commits on Jul 22, 2024

  1. Copy the full SHA
    bed7604 View commit details
  2. Merge pull request #1712 from dtolnay/unnamedvariadic

    Parse unnamed variadic args inside function pointer types
    dtolnay authored Jul 22, 2024
    Copy the full SHA
    698eb9f View commit details
  3. Copy the full SHA
    71930e9 View commit details
  4. Merge pull request #1713 from dtolnay/expectedend

    Include expected close delimiter in unexpected token message
    dtolnay authored Jul 22, 2024
    Copy the full SHA
    4132a0c View commit details
  5. Parse explicit tail calls

    dtolnay committed Jul 22, 2024
    Copy the full SHA
    07f4b37 View commit details
  6. Merge pull request #1714 from dtolnay/become

    Parse explicit tail calls
    dtolnay authored Jul 22, 2024
    Copy the full SHA
    a397d0b View commit details

Commits on Jul 25, 2024

  1. Copy the full SHA
    4f30613 View commit details

Commits on Jul 26, 2024

  1. Copy the full SHA
    94d74d5 View commit details

Commits on Aug 9, 2024

  1. Add Fields::iter_member

    Fancyflame committed Aug 9, 2024
    Copy the full SHA
    5e3c70d View commit details
  2. fix Fields::iter_member doesn't compile

    the span of unnamed field member will fallback to `Span::call_site` if `Spanned` trait is not available
    Fancyflame committed Aug 9, 2024
    Copy the full SHA
    fec821f View commit details

Commits on Aug 11, 2024

  1. Merge pull request #1716 from Fancyflame/master

    Add `Fields::iter_member`
    dtolnay authored Aug 11, 2024
    Copy the full SHA
    8b68c06 View commit details
  2. Rename Fields::iter_member to members()

    The new name is consistent with other iteration initiation methods in
    the standard library and ecosystem like .pairs() and .keys() and
    .values() and .components().
    dtolnay committed Aug 11, 2024
    Copy the full SHA
    d94d5b0 View commit details
  3. Copy the full SHA
    321839c View commit details
  4. Copy the full SHA
    e8a9292 View commit details
  5. Delete needless cfg from Fields::members

    The whole crate::data module and Fields enum are only available under
    this cfg. There is no need to additionally mark the method.
    dtolnay committed Aug 11, 2024
    Copy the full SHA
    6df0c8a View commit details
  6. Copy the full SHA
    c66df45 View commit details
  7. Copy the full SHA
    ecc7ae8 View commit details
  8. Handwrite iterator Clone impl in FIelds::members

    Derive is avoided in syn for compile time reasons.
    dtolnay committed Aug 11, 2024
    Copy the full SHA
    2b80352 View commit details
  9. Increment members counter regardless of whether field is unnamed

    Syn would never parse a Fields containing a mix of named and unnamed
    fields, but if such a Fields is constructed in another way, it makes
    more sense for members() to produce the index for the unnamed field's
    position in the entire list.
    dtolnay committed Aug 11, 2024
    Copy the full SHA
    9d00ef5 View commit details
  10. Touch up PR 1716

    dtolnay committed Aug 11, 2024
    Copy the full SHA
    ac9e1dd View commit details
  11. Copy the full SHA
    e5e9927 View commit details
  12. Copy the full SHA
    0e33aa7 View commit details
  13. Copy the full SHA
    a482734 View commit details
  14. Copy the full SHA
    64b0dc8 View commit details
  15. Copy the full SHA
    2afdc12 View commit details
  16. Copy the full SHA
    8cdb5c7 View commit details
  17. Release 2.0.73

    dtolnay committed Aug 11, 2024
    Copy the full SHA
    b5a5a8c View commit details
Showing with 295 additions and 241 deletions.
  1. +1 −1 Cargo.toml
  2. +10 −0 src/buffer.rs
  3. +77 −1 src/data.rs
  4. +2 −2 src/discouraged.rs
  5. +12 −0 src/expr.rs
  6. +141 −182 src/generics.rs
  7. +1 −1 src/lib.rs
  8. +28 −13 src/parse.rs
  9. +1 −1 src/ty.rs
  10. +1 −1 syn.json
  11. +8 −0 tests/common/eq.rs
  12. +0 −20 tests/repo/mod.rs
  13. +13 −19 tests/test_precedence.rs
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "syn"
version = "2.0.72"
version = "2.0.73"
authors = ["David Tolnay <dtolnay@gmail.com>"]
categories = ["development-tools::procedural-macro-helpers", "parser-implementations"]
description = "Parser for Rust source code"
10 changes: 10 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -364,6 +364,16 @@ impl<'a> Cursor<'a> {

Some(unsafe { Cursor::create(self.ptr.add(len), self.scope) })
}

pub(crate) fn scope_delimiter(self) -> Delimiter {
match unsafe { &*self.scope } {
Entry::End(_, offset) => match unsafe { &*self.scope.offset(*offset) } {
Entry::Group(group, _) => group.delimiter(),
_ => Delimiter::None,
},
_ => unreachable!(),
}
}
}

impl<'a> Copy for Cursor<'a> {}
78 changes: 77 additions & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::attr::Attribute;
use crate::expr::Expr;
use crate::expr::{Expr, Index, Member};
use crate::ident::Ident;
use crate::punctuated::{self, Punctuated};
use crate::restriction::{FieldMutability, Visibility};
@@ -104,6 +104,82 @@ impl Fields {
Fields::Unnamed(f) => f.unnamed.is_empty(),
}
}

/// Get an iterator over the fields of a struct or variant as [`Member`]s.
/// This iterator can be used to iterate over a named or unnamed struct or
/// variant's fields uniformly.
///
/// # Example
///
/// The following is a simplistic [`Clone`] derive for structs. (A more
/// complete implementation would additionally want to infer trait bounds on
/// the generic type parameters.)
///
/// ```
/// # use quote::quote;
/// #
/// fn derive_clone(input: &syn::ItemStruct) -> proc_macro2::TokenStream {
/// let ident = &input.ident;
/// let members = input.fields.members();
/// let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
/// quote! {
/// impl #impl_generics Clone for #ident #ty_generics #where_clause {
/// fn clone(&self) -> Self {
/// Self {
/// #(#members: self.#members.clone()),*
/// }
/// }
/// }
/// }
/// }
/// ```
///
/// For structs with named fields, it produces an expression like `Self { a:
/// self.a.clone() }`. For structs with unnamed fields, `Self { 0:
/// self.0.clone() }`. And for unit structs, `Self {}`.
pub fn members(&self) -> impl Iterator<Item = Member> + Clone + '_ {
struct Members<'a> {
fields: punctuated::Iter<'a, Field>,
index: u32,
}

impl<'a> Iterator for Members<'a> {
type Item = Member;

fn next(&mut self) -> Option<Self::Item> {
let field = self.fields.next()?;
let member = match &field.ident {
Some(ident) => Member::Named(ident.clone()),
None => {
#[cfg(all(feature = "parsing", feature = "printing"))]
let span = crate::spanned::Spanned::span(&field.ty);
#[cfg(not(all(feature = "parsing", feature = "printing")))]
let span = proc_macro2::Span::call_site();
Member::Unnamed(Index {
index: self.index,
span,
})
}
};
self.index += 1;
Some(member)
}
}

impl<'a> Clone for Members<'a> {
fn clone(&self) -> Self {
Members {
fields: self.fields.clone(),
index: self.index,
}
}
}

Members {
fields: self.iter(),
index: 0,
}
}
}

impl IntoIterator for Fields {
4 changes: 2 additions & 2 deletions src/discouraged.rs
Original file line number Diff line number Diff line change
@@ -175,8 +175,8 @@ impl<'a> Speculative for ParseBuffer<'a> {
if !Rc::ptr_eq(&self_unexp, &fork_unexp) {
match (fork_sp, self_sp) {
// Unexpected set on the fork, but not on `self`, copy it over.
(Some(span), None) => {
self_unexp.set(Unexpected::Some(span));
(Some((span, delimiter)), None) => {
self_unexp.set(Unexpected::Some(span, delimiter));
}
// Unexpected unset. Use chain to propagate errors from fork.
(None, None) => {
12 changes: 12 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
@@ -1741,6 +1741,8 @@ pub(crate) mod parsing {
input.parse().map(Expr::Continue)
} else if input.peek(Token![return]) {
input.parse().map(Expr::Return)
} else if input.peek(Token![become]) {
expr_become(input)
} else if input.peek(token::Bracket) {
array_or_repeat(input)
} else if input.peek(Token![let]) {
@@ -2393,6 +2395,16 @@ pub(crate) mod parsing {
}
}

#[cfg(feature = "full")]
fn expr_become(input: ParseStream) -> Result<Expr> {
let begin = input.fork();
input.parse::<Token![become]>()?;
if can_begin_expr(input) {
input.parse::<Expr>()?;
}
Ok(Expr::Verbatim(verbatim::between(&begin, input)))
}

#[cfg(feature = "full")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for ExprTryBlock {
Loading