Repository: seanmonstar/reqwest (language: rust)

Issue:
v0.11.4 compile error wasm target
I get compile error if trying to use reqwest v0.11.4. Build succeeds with reqwest v0.11.3.

> error[E0277]: the trait bound `Form: Clone` is not satisfied
  --> /home/test/.cargo/registry/src/github.com-1ecc6299db9ec823/reqwest-0.11.4/src/wasm/body.rs:24:15
   |
24 |     Multipart(Form),
   |               ^^^^ the trait `Clone` is not implemented for `Form`
   |
   = note: required by `clone`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)


Cargo.toml

`
[dependencies.reqwest]
version = "=0.11.4"
default-features = true
features = ["json", "multipart"]
`

Reproduced with rustc versions:
`
rustc 1.55.0-nightly (e6b4c252e 2021-06-25)
`
`
rustc 1.53.0 (53cb7b09b 2021-06-17)
`

Build command:
`
cargo build --target wasm32-unknown-unknown
`


Discussion / hints:
Ah yikes, thanks for the report! It's probably this [line](https://github.com/seanmonstar/reqwest/commit/c4388fcff9401d23169c6731901457e89039bf53#diff-799fa801c7c923109a69c3c5cfcc2b5812d7f4fcd6a3dcd2ccab1cfec90e4fe8R20) that was recently added. We should remove that `derive`, and change that `clone` method to a `try_clone` that matches on the inner type.

Do you want to try to make a PR with that fix?

Fix patch:
diff --git a/src/wasm/body.rs b/src/wasm/body.rs
index d67f510ee..f261e394a 100644
--- a/src/wasm/body.rs
+++ b/src/wasm/body.rs
@@ -17,7 +17,6 @@ pub struct Body {
     inner: Inner,
 }
 
-#[derive(Clone)]
 enum Inner {
     Bytes(Bytes),
     #[cfg(feature = "multipart")]
@@ -58,9 +57,13 @@ impl Body {
         }
     }
 
-    pub(crate) fn clone(&self) -> Body {
-        Self {
-            inner: self.inner.clone(),
+    pub(crate) fn try_clone(&self) -> Option<Body> {
+        match &self.inner {
+            Inner::Bytes(bytes) => Some(Self {
+                inner: Inner::Bytes(bytes.clone()),
+            }),
+            #[cfg(feature = "multipart")]
+            Inner::Multipart(_) => None,
         }
     }
 }
diff --git a/src/wasm/request.rs b/src/wasm/request.rs
index 40bb37bac..9b36d573a 100644
--- a/src/wasm/request.rs
+++ b/src/wasm/request.rs
@@ -92,14 +92,18 @@ impl Request {
 
     /// Attempts to clone the `Request`.
     ///
-    /// None is returned if a body is which can not be cloned. This method
-    /// currently always returns `Some`, but that may change in the future.
+    /// None is returned if a body is which can not be cloned.
     pub fn try_clone(&self) -> Option<Request> {
+        let body = match self.body.as_ref() {
+            Some(ref body) => Some(body.try_clone()?),
+            None => None,
+        };
+
         Some(Self {
             method: self.method.clone(),
             url: self.url.clone(),
             headers: self.headers.clone(),
-            body: self.body.as_ref().map(|body| body.clone()),
+            body,
             cors: self.cors,
             credentials: self.credentials.clone(),
         })
@@ -353,8 +357,7 @@ impl RequestBuilder {
 
     /// Attempt to clone the RequestBuilder.
     ///
-    /// `None` is returned if the RequestBuilder can not be cloned. This method
-    /// currently always returns `Some`, but that may change in the future.
+    /// `None` is returned if the RequestBuilder can not be cloned.
     ///
     /// # Examples
     ///


Test patch: