Skip to content
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

Confusing error when using type that doesn't conform to Sync due to a field that doesn't conform #24130

Closed
lilyball opened this issue Apr 6, 2015 · 2 comments

Comments

@lilyball
Copy link
Contributor

lilyball commented Apr 6, 2015

When a type doesn't conform to Sync because it contains a field that doesn't conform, the error message yielded when trying to use that type where Sync is required is confusing. It talks about the type of the field itself, without actually mentioning that this is a field of the type in question, but it flags the point where the type is used rather than the field definition.

Example:

trait Trait {
    fn _foo(&self) {}
}

struct Foo {
    foo: Box<Trait+Send>
}

fn assert_is_sync<T: Sync>() {}

fn main() {
    assert_is_sync::<Foo>();
}

prints

unnamed.rs:12:5: 12:26 error: the trait `core::marker::Sync` is not implemented for the type `Trait + Send` [E0277]
unnamed.rs:12     assert_is_sync::<Foo>();
                  ^~~~~~~~~~~~~~~~~~~~~
unnamed.rs:12:5: 12:26 note: `Trait + Send` cannot be shared between threads safely
unnamed.rs:12     assert_is_sync::<Foo>();
                  ^~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

The only way to understand this error is to know that Foo contains a field whose type includes Trait + Send and correctly guess this means that Foo does not conform to Send.

@ftxqxd
Copy link
Contributor

ftxqxd commented Apr 7, 2015

I think this is a dupe of #21793.

@lilyball
Copy link
Contributor Author

lilyball commented Apr 7, 2015

Yep, you're right.

@lilyball lilyball closed this as completed Apr 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants