nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: dtolnay/thiserror
Pull request #366 (2024-11-05 22:03:36)

Allow error(transparent) inside an enum that has error("...")
I cannot tell why this was disallowed originally. Probably just buggy implementation logic.


Patch:
diff --git a/impl/src/ast.rs b/impl/src/ast.rs
index a56b358..5cbae38 100644
--- a/impl/src/ast.rs
+++ b/impl/src/ast.rs
@@ -91,14 +91,13 @@ impl<'a> Enum<'a> {
             .iter()
             .map(|node| {
                 let mut variant = Variant::from_syn(node, &scope)?;
-                if let display @ None = &mut variant.attrs.display {
-                    display.clone_from(&attrs.display);
+                if variant.attrs.display.is_none() && variant.attrs.transparent.is_none() {
+                    variant.attrs.display.clone_from(&attrs.display);
+                    variant.attrs.transparent = attrs.transparent;
                 }
                 if let Some(display) = &mut variant.attrs.display {
                     let container = ContainerKind::from_variant(node);
                     display.expand_shorthand(&variant.fields, container)?;
-                } else if variant.attrs.transparent.is_none() {
-                    variant.attrs.transparent = attrs.transparent;
                 }
                 Ok(variant)
             })


Test patch:
diff --git a/tests/test_transparent.rs b/tests/test_transparent.rs
index 6f3c03e..ee30f5b 100644
--- a/tests/test_transparent.rs
+++ b/tests/test_transparent.rs
@@ -45,6 +45,24 @@ fn test_transparent_enum() {
     assert_eq!("inner", error.source().unwrap().to_string());
 }
 
+#[test]
+fn test_transparent_enum_with_default_message() {
+    #[derive(Error, Debug)]
+    #[error("this failed: {0}_{1}")]
+    enum Error {
+        This(i32, i32),
+        #[error(transparent)]
+        Other(anyhow::Error),
+    }
+
+    let error = Error::This(-1, -1);
+    assert_eq!("this failed: -1_-1", error.to_string());
+
+    let error = Error::Other(anyhow!("inner").context("outer"));
+    assert_eq!("outer", error.to_string());
+    assert_eq!("inner", error.source().unwrap().to_string());
+}
+
 #[test]
 fn test_anyhow() {
     #[derive(Error, Debug)]
Repository: dtolnay/thiserror
Pull request #375 (2024-11-08 17:20:13)

Support dynamically sized field in error


Patch:
diff --git a/src/display.rs b/src/display.rs
index 7ccdd81..7b2bf1c 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -13,7 +13,7 @@ pub trait AsDisplay<'a>: Sealed {
 
 impl<'a, T> AsDisplay<'a> for &T
 where
-    T: Display + 'a,
+    T: Display + ?Sized + 'a,
 {
     type Target = &'a T;
 
@@ -44,7 +44,7 @@ impl<'a> AsDisplay<'a> for PathBuf {
 
 #[doc(hidden)]
 pub trait Sealed {}
-impl<T: Display> Sealed for &T {}
+impl<T: Display + ?Sized> Sealed for &T {}
 #[cfg(feature = "std")]
 impl Sealed for Path {}
 #[cfg(feature = "std")]


Test patch:
diff --git a/tests/test_path.rs b/tests/test_path.rs
index f054077..16881ae 100644
--- a/tests/test_path.rs
+++ b/tests/test_path.rs
@@ -22,6 +22,13 @@ enum EnumPathBuf {
     Read(PathBuf),
 }
 
+#[derive(Error, Debug)]
+#[error("{tail}")]
+pub struct UnsizedError {
+    pub head: i32,
+    pub tail: str,
+}
+
 fn assert<T: Display>(expected: &str, value: T) {
     assert_eq!(expected, value.to_string());
 }
Repository: dtolnay/thiserror
Pull request #377 (2024-11-08 17:48:20)

Support generic types that need multiple bounds


Patch:
diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs
index 36300e5..6dfdccf 100644
--- a/impl/src/fmt.rs
+++ b/impl/src/fmt.rs
@@ -99,10 +99,6 @@ impl Display<'_> {
                 formatvar = IdentUnraw::new(format_ident!("_{}", formatvar.to_string()));
             }
             out += &formatvar.to_string();
-            if !macro_named_args.insert(member.clone()) {
-                // Already added to scope by a previous use.
-                continue;
-            }
             let local = formatvar.to_local();
             let mut binding_value = ToTokens::into_token_stream(match &member {
                 MemberUnraw::Unnamed(index) => format_ident!("_{}", index),
@@ -142,7 +138,11 @@ impl Display<'_> {
                     }
                 );
             }
-            bindings.push((local, binding_value));
+            if macro_named_args.insert(member) {
+                bindings.push((local, binding_value));
+            } else {
+                // Already added to bindings by a previous use.
+            }
         }
 
         out += read;


Test patch:
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index 4d49edf..36f1181 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -172,3 +172,15 @@ fn test_no_bound_on_named_fmt() {
     let error = Error { thing: DebugOnly };
     assert_eq!(error.to_string(), "...");
 }
+
+#[test]
+fn test_multiple_bound() {
+    #[derive(Error, Debug)]
+    #[error("0x{thing:x} 0x{thing:X}")]
+    pub struct Error<T> {
+        thing: T,
+    }
+
+    let error = Error { thing: 0xFFi32 };
+    assert_eq!(error.to_string(), "0xff 0xFF");
+}
Repository: scylladb/scylla-rust-driver
Pull request #526 (2022-08-22 10:14:28)

tracing: Get list of nodes from  TracingInfo
Adds a simple getter which allows to get the list of nodes involved in a traced query.

## Pre-review checklist
<!--
    Make sure you took care of the issues on the list.
    Put 'x' into those boxes which apply.
    You can also create the PR now and click on all relevant checkboxes.
    See CONTRIBUTING.md for more details.
-->

- [x] I have split my patch into logically separate commits.
- [x] All commit messages clearly explain what they change and why.
- [x] I added relevant tests for new features and bug fixes.
- [x] All commits compile, pass static checks and pass test.
- [x] PR description sums up the changes and reasons why they should be introduced.
- [x] I added appropriate `Fixes:` annotations to PR description.



Patch:
diff --git a/scylla/src/tracing.rs b/scylla/src/tracing.rs
index 63822b23..dbdff599 100644
--- a/scylla/src/tracing.rs
+++ b/scylla/src/tracing.rs
@@ -1,4 +1,5 @@
 use crate::statement::Consistency;
+use itertools::Itertools;
 use std::collections::HashMap;
 use std::net::IpAddr;
 use std::num::NonZeroU32;
@@ -48,6 +49,17 @@ pub struct GetTracingConfig {
     pub consistency: Consistency,
 }
 
+impl TracingInfo {
+    /// Returns a list of unique nodes involved in the query
+    pub fn nodes(&self) -> Vec<IpAddr> {
+        self.events
+            .iter()
+            .filter_map(|e| e.source)
+            .unique()
+            .collect()
+    }
+}
+
 impl Default for GetTracingConfig {
     fn default() -> GetTracingConfig {
         GetTracingConfig {


Test patch:
diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs
index 5c1248ee..c875dd97 100644
--- a/scylla/src/transport/session_test.rs
+++ b/scylla/src/transport/session_test.rs
@@ -919,6 +919,7 @@ async fn test_get_tracing_info(session: &Session, ks: String) {
     // Getting tracing info from session using this uuid works
     let tracing_info: TracingInfo = session.get_tracing_info(&tracing_id).await.unwrap();
     assert!(!tracing_info.events.is_empty());
+    assert!(!tracing_info.nodes().is_empty());
 }
 
 async fn test_tracing_query_iter(session: &Session, ks: String) {
Repository: scylladb/scylla-rust-driver
Pull request #790 (2023-08-19 10:28:36)

value: implement serialize for u8 slices
Implement `Value` for `u8` slices to allow deriving `ValueList` for structs with `&[u8]` fields.

## Pre-review checklist

<!--
    Make sure you took care of the issues on the list.
    Put 'x' into those boxes which apply.
    You can also create the PR now and click on all relevant checkboxes.
    See CONTRIBUTING.md for more details.
-->

- [x] I have split my patch into logically separate commits.
- [x] All commit messages clearly explain what they change and why.
- [x] I added relevant tests for new features and bug fixes.
- [x] All commits compile, pass static checks and pass test.
- [x] PR description sums up the changes and reasons why they should be introduced.
- [ ] I have provided docstrings for the public items that I want to introduce.
- [ ] I have adjusted the documentation in `./docs/source/`.
- [ ] I added appropriate `Fixes:` annotations to PR description.



Patch:
diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs
index 9cc482c2..9e927be3 100644
--- a/scylla-cql/src/frame/value.rs
+++ b/scylla-cql/src/frame/value.rs
@@ -504,6 +504,12 @@ impl Value for &str {
 }
 
 impl Value for Vec<u8> {
+    fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
+        <&[u8] as Value>::serialize(&self.as_slice(), buf)
+    }
+}
+
+impl Value for &[u8] {
     fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
         let val_len: i32 = self.len().try_into().map_err(|_| ValueTooBig)?;
         buf.put_i32(val_len);


Test patch:
diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs
index 95641464..f7e48036 100644
--- a/scylla-cql/src/frame/value_tests.rs
+++ b/scylla-cql/src/frame/value_tests.rs
@@ -35,6 +35,12 @@ fn u8_array_serialization() {
     assert_eq!(serialized(val), vec![0, 0, 0, 4, 1, 1, 1, 1]);
 }
 
+#[test]
+fn u8_slice_serialization() {
+    let val = vec![1u8, 1, 1, 1];
+    assert_eq!(serialized(val.as_slice()), vec![0, 0, 0, 4, 1, 1, 1, 1]);
+}
+
 #[test]
 fn naive_date_serialization() {
     // 1970-01-31 is 2^31