nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: dtolnay/syn
Pull request #1772 (2024-10-23 20:56:50)

Parse self captures: `impl Sized + use<Self>`


Patch:
diff --git a/src/generics.rs b/src/generics.rs
index 74618482..1e8fccf0 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -1046,13 +1046,16 @@ pub(crate) mod parsing {
             let mut params = Punctuated::new();
             loop {
                 let lookahead = input.lookahead1();
-                params.push_value(if lookahead.peek(Lifetime) || lookahead.peek(Ident) {
-                    input.parse::<CapturedParam>()?
-                } else if lookahead.peek(Token![>]) {
-                    break;
-                } else {
-                    return Err(lookahead.error());
-                });
+                params.push_value(
+                    if lookahead.peek(Lifetime) || lookahead.peek(Ident) || input.peek(Token![Self])
+                    {
+                        input.parse::<CapturedParam>()?
+                    } else if lookahead.peek(Token![>]) {
+                        break;
+                    } else {
+                        return Err(lookahead.error());
+                    },
+                );
                 let lookahead = input.lookahead1();
                 params.push_punct(if lookahead.peek(Token![,]) {
                     input.parse::<Token![,]>()?
@@ -1079,8 +1082,8 @@ pub(crate) mod parsing {
             let lookahead = input.lookahead1();
             if lookahead.peek(Lifetime) {
                 input.parse().map(CapturedParam::Lifetime)
-            } else if lookahead.peek(Ident) {
-                input.parse().map(CapturedParam::Ident)
+            } else if lookahead.peek(Ident) || input.peek(Token![Self]) {
+                input.call(Ident::parse_any).map(CapturedParam::Ident)
             } else {
                 Err(lookahead.error())
             }


Test patch:
diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs
index 93f0c32e..96f039cb 100644
--- a/tests/repo/mod.rs
+++ b/tests/repo/mod.rs
@@ -19,9 +19,6 @@ const REVISION: &str = "86d69c705a552236a622eee3fdea94bf13c5f102";
 
 #[rustfmt::skip]
 static EXCLUDE_FILES: &[&str] = &[
-    // TODO: self capture: `impl Sized + use<Self>`
-    "tests/ui/impl-trait/precise-capturing/self-capture.rs",
-
     // TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait`
     // https://github.com/dtolnay/syn/issues/1435
     "src/tools/rustfmt/tests/source/issue_5721.rs",
Repository: dtolnay/syn
Pull request #1786 (2024-11-29 21:20:02)

Fix parenthesization of field expressions in function calls
`(thing.field)()` is not equivalent to `thing.field()`.

But `(thing.0)()` and `thing.0()` _are_ equivalent.


Patch:
diff --git a/src/expr.rs b/src/expr.rs
index f68f6322..545b43df 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1036,6 +1036,16 @@ impl IdentFragment for Member {
     }
 }
 
+#[cfg(any(feature = "parsing", feature = "printing"))]
+impl Member {
+    pub(crate) fn is_named(&self) -> bool {
+        match self {
+            Member::Named(_) => true,
+            Member::Unnamed(_) => false,
+        }
+    }
+}
+
 ast_struct! {
     /// The index of an unnamed tuple struct field.
     #[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
@@ -3021,15 +3031,6 @@ pub(crate) mod parsing {
         Ok(!trailing_dot)
     }
 
-    impl Member {
-        pub(crate) fn is_named(&self) -> bool {
-            match self {
-                Member::Named(_) => true,
-                Member::Unnamed(_) => false,
-            }
-        }
-    }
-
     #[cfg(feature = "full")]
     #[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
     impl Parse for PointerMutability {
@@ -3405,22 +3406,17 @@ pub(crate) mod printing {
     fn print_expr_call(e: &ExprCall, tokens: &mut TokenStream, fixup: FixupContext) {
         outer_attrs_to_tokens(&e.attrs, tokens);
 
-        let call_precedence = if let Expr::Field(_) = &*e.func {
-            Precedence::MIN
-        } else {
-            Precedence::Unambiguous
-        };
         let func_fixup = fixup.leftmost_subexpression_with_begin_operator(
             #[cfg(feature = "full")]
             true,
             false,
         );
-        print_subexpression(
-            &e.func,
-            func_fixup.leading_precedence(&e.func) < call_precedence,
-            tokens,
-            func_fixup,
-        );
+        let needs_group = if let Expr::Field(func) = &*e.func {
+            func.member.is_named()
+        } else {
+            func_fixup.leading_precedence(&e.func) < Precedence::Unambiguous
+        };
+        print_subexpression(&e.func, needs_group, tokens, func_fixup);
 
         e.paren_token.surround(tokens, |tokens| {
             e.args.to_tokens(tokens);


Test patch:
diff --git a/tests/test_expr.rs b/tests/test_expr.rs
index 6dd87622..03ebd1db 100644
--- a/tests/test_expr.rs
+++ b/tests/test_expr.rs
@@ -703,6 +703,7 @@ fn test_fixup() {
         quote! { (1 < 2) == (3 < 4) },
         quote! { { (let _ = ()) } },
         quote! { (#[attr] thing).field },
+        quote! { (self.f)() },
     ] {
         let original: Expr = syn::parse2(tokens).unwrap();
Repository: dtolnay/syn
Pull request #1798 (2024-12-26 05:23:12)

Fix parenthesization of jumps in ranges
Previously, the syntax tree for `(return)..=return` (with paren flattened away) would get incorrectly turned into `return ..=return` which means a different thing.


Patch:
diff --git a/src/expr.rs b/src/expr.rs
index 4939078a..961f308d 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -3752,11 +3752,12 @@ pub(crate) mod printing {
     fn print_expr_range(e: &ExprRange, tokens: &mut TokenStream, fixup: FixupContext) {
         outer_attrs_to_tokens(&e.attrs, tokens);
         if let Some(start) = &e.start {
+            let start_fixup = fixup.leftmost_subexpression_with_begin_operator(true, false);
             print_subexpression(
                 start,
-                Precedence::of(start) <= Precedence::Range,
+                start_fixup.leading_precedence(start) <= Precedence::Range,
                 tokens,
-                fixup.leftmost_subexpression(),
+                start_fixup,
             );
         }
         e.limits.to_tokens(tokens);
diff --git a/src/fixup.rs b/src/fixup.rs
index 58ed9e73..fb1c4218 100644
--- a/src/fixup.rs
+++ b/src/fixup.rs
@@ -323,7 +323,7 @@ impl FixupContext {
                 _ => {}
             }
         }
-        self.precedence(expr)
+        self.leading_precedence(expr)
     }
 
     fn precedence(self, expr: &Expr) -> Precedence {


Test patch:
diff --git a/tests/test_expr.rs b/tests/test_expr.rs
index 03ebd1db..6d5d4f87 100644
--- a/tests/test_expr.rs
+++ b/tests/test_expr.rs
@@ -704,6 +704,8 @@ fn test_fixup() {
         quote! { { (let _ = ()) } },
         quote! { (#[attr] thing).field },
         quote! { (self.f)() },
+        quote! { (return)..=return },
+        quote! { 1 + (return)..=1 + return },
     ] {
         let original: Expr = syn::parse2(tokens).unwrap();
Repository: dtolnay/thiserror
Pull request #41 (2019-11-19 03:15:22)

aserror: support Send + !Sync errors too
---
Maybe there's no need for this and I should just add `+ Sync` to my bounds as well?


Patch:
diff --git a/src/aserror.rs b/src/aserror.rs
index 67e8506..8290296 100644
--- a/src/aserror.rs
+++ b/src/aserror.rs
@@ -18,6 +18,13 @@ impl AsDynError for dyn Error + 'static {
     }
 }
 
+impl AsDynError for dyn Error + Send + 'static {
+    #[inline]
+    fn as_dyn_error(&self) -> &(dyn Error + 'static) {
+        self
+    }
+}
+
 impl AsDynError for dyn Error + Send + Sync + 'static {
     #[inline]
     fn as_dyn_error(&self) -> &(dyn Error + 'static) {


Test patch:
diff --git a/tests/test_source.rs b/tests/test_source.rs
index ab96113..83c3f77 100644
--- a/tests/test_source.rs
+++ b/tests/test_source.rs
@@ -1,4 +1,4 @@
-use std::error::Error as _;
+use std::error::Error;
 use std::io;
 use thiserror::Error;
 
@@ -16,6 +16,13 @@ pub struct ExplicitSource {
     io: io::Error,
 }
 
+#[derive(Error, Debug)]
+#[error("boxed source")]
+pub struct BoxedSource {
+    #[source]
+    source: Box<dyn Error + Send + 'static>,
+}
+
 #[test]
 fn test_implicit_source() {
     let io = io::Error::new(io::ErrorKind::Other, "oh no!");
@@ -32,3 +39,11 @@ fn test_explicit_source() {
     };
     error.source().unwrap().downcast_ref::<io::Error>().unwrap();
 }
+
+#[test]
+fn test_boxed_source() {
+    let io = io::Error::new(io::ErrorKind::Other, "oh no!");
+    let _error = BoxedSource {
+        source: Box::new(io),
+    };
+}
Repository: dtolnay/thiserror
Pull request #109 (2020-11-04 00:43:49)

Fix keyword as fmt argument
The standard library's format macros allow keyword named argument, as in `format_args!("{type}", type = 1)`. These were previously crashing thiserror.

```console
error: proc-macro derive panicked
   --> tests/test_display.rs:269:14
    |
269 |     #[derive(Error, Debug)]
    |              ^^^^^
    |
    = help: message: called `Result::unwrap()` on an `Err` value: Error("expected identifier")
```


Patch:
diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs
index d435a80..e12e94b 100644
--- a/impl/src/fmt.rs
+++ b/impl/src/fmt.rs
@@ -102,7 +102,7 @@ fn explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
     while !input.is_empty() {
         if input.peek(Token![,]) && input.peek2(Ident::peek_any) && input.peek3(Token![=]) {
             input.parse::<Token![,]>()?;
-            let ident: Ident = input.parse()?;
+            let ident = input.call(Ident::parse_any)?;
             input.parse::<Token![=]>()?;
             named_args.insert(ident);
         } else {
@@ -143,5 +143,5 @@ fn take_ident(read: &mut &str) -> Ident {
             }
         }
     }
-    syn::parse_str(&ident).unwrap()
+    Ident::parse_any.parse_str(&ident).unwrap()
 }


Test patch:
diff --git a/tests/test_display.rs b/tests/test_display.rs
index 769da5c..949d9ed 100644
--- a/tests/test_display.rs
+++ b/tests/test_display.rs
@@ -263,3 +263,12 @@ fn test_raw_conflict() {
 
     assert("braced raw error: T, U", Error::Braced { r#func: "T" });
 }
+
+#[test]
+fn test_keyword() {
+    #[derive(Error, Debug)]
+    #[error("error: {type}", type = 1)]
+    struct Error;
+
+    assert("error: 1", Error);
+}