Skip to content

Commit

Permalink
fix(rustup): workaround rustlang bug
Browse files Browse the repository at this point in the history
Due to rust-lang/rust#22252, r-value
temporaries outlive the lifetimes of variables bound with let
statements in a function body. Because of this, device.rs fails to
compile against newer rustc nightlies.

This implements a simple workaround that binds the result of the match
in `request_code` to a local variable before returning it. This allows
it to have the same lifetime as `req` in one of the previous let
bindings.
  • Loading branch information
worr committed May 11, 2015
1 parent 0a62d04 commit 47b68cf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ impl<C> DeviceFlow<C>
.collect::<String>()
.as_ref())]);

match self.client.borrow_mut().post(FlowType::Device.as_ref())
// note: works around bug in rustlang
// https://github.com/rust-lang/rust/issues/22252
let ret = match self.client.borrow_mut().post(FlowType::Device.as_ref())
.header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
.body(&*req)
.send() {
Expand Down Expand Up @@ -237,7 +239,9 @@ impl<C> DeviceFlow<C>
self.id = client_id.to_string();
Ok(pi)
}
}
};

ret
}

/// If the first call is successful, this method may be called.
Expand Down Expand Up @@ -394,4 +398,4 @@ pub mod tests {
// As our mock has only 3 items, we would panic on this call
assert_eq!(flow.poll_token().unwrap(), Some(t));
}
}
}

0 comments on commit 47b68cf

Please sign in to comment.