Skip to content

Cow<T> isn't Send, even if T and <T as ToOwned>::Owned are #22629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
renato-zannon opened this issue Feb 21, 2015 · 2 comments · Fixed by #22851
Closed

Cow<T> isn't Send, even if T and <T as ToOwned>::Owned are #22629

renato-zannon opened this issue Feb 21, 2015 · 2 comments · Fixed by #22851
Assignees
Labels
A-trait-system Area: Trait system

Comments

@renato-zannon
Copy link
Contributor

The following doesn't compile, but I believe it should:

use std::borrow::{ToOwned, Cow};

fn main() {
  assert_send(Cow::Borrowed("foo"));
}

fn assert_send<T: Send>(_: T) {}

Error:

cow.rs:4:3: 4:14 error: the trait `core::marker::Send` is not implemented for the type `<str as collections::borrow::ToOwned>::Owned` [E0277]
cow.rs:4   assert_send(Cow::Borrowed("foo"));
           ^~~~~~~~~~~
cow.rs:4:3: 4:14 note: `<str as collections::borrow::ToOwned>::Owned` cannot be sent between threads safely
cow.rs:4   assert_send(Cow::Borrowed("foo"));
           ^~~~~~~~~~~
error: aborting due to previous error

Even though <str as ToOwned>::Owned == String, and String: Send. In fact, this compiles:

assert_send("foo");
assert_send("foo".to_owned());

rustc 1.0.0-nightly (522d09dfe 2015-02-19) (built 2015-02-20)

@japaric
Copy link
Member

japaric commented Feb 21, 2015

Cow<'static, str> should be Send, because the old definition that didn't use assoc types was Send. Probably the code that detects builtin bounds wasn't updated to handle associated types. cc @nikomatsakis @flaper87

@kmcallister kmcallister added A-libs A-trait-system Area: Trait system labels Feb 21, 2015
@seanmonstar
Copy link
Contributor

This breaks us in hyper. For now, I'll have to manually impl Send for Request, knowing that it's safe.,,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants