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

Cow trait bound without ToOwned produces odd "core::marker::Sized is not implemented" #31691

Closed
comex opened this issue Feb 16, 2016 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@comex
Copy link
Contributor

comex commented Feb 16, 2016

Incorrect code, because Cow requires ToOwned on its parameter:

fn into_cow<'a, T: ?Sized, S: Into<Cow<'a, T>>>(s: S) -> Cow<'a, T> {
    s.into()
}

Fixed:

fn into_cow<'a, T: ?Sized + ToOwned, S: Into<Cow<'a, T>>>(s: S) -> Cow<'a, T>
                          ^^^^^^^^^

Makes sense, but rustc's error for the first version is odd:

exectool.rs:46:1: 48:2 error: the trait `core::marker::Sized` is not implemented for the type `T` [E0277]
exectool.rs:46 fn into_cow<'a, T: ?Sized, S: Into<Cow<'a, T>>>(s: S) -> Cow<'a, T> {
exectool.rs:47     s.into()
exectool.rs:48 }
exectool.rs:46:1: 48:2 help: run `rustc --explain E0277` to see a detailed explanation
exectool.rs:46:1: 48:2 note: `T` does not have a constant size known at compile-time
exectool.rs:46:1: 48:2 note: required by `core::convert::Into`

Into doesn't require T to be Sized, and indeed in the Cow case it usually isn't.

If I remove the ?Sized from T, I get the trait core::clone::Clone is not implemented for the type T; stable produces this error for the original version too, along with the Sized error. On IRC, aatch suggested this was might be caused by impl<T: Clone> ToOwned for T. While Clone would be a sufficient bound due to that impl, it isn't necessary even for sized types, so that error too is misleading.

@Aatch Aatch added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 16, 2016
@Aatch
Copy link
Contributor

Aatch commented Feb 16, 2016

Related: #30976

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 24, 2017
@Mark-Simulacrum
Copy link
Member

Seems like a duplicate of #64088 essentially

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants