-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Loop evaluating Cow<'a, T>: Sized in recursive structure #23714
Comments
I believe that @nikomatsakis recently made a change that detected overflow, that may be related (I don't recall the details offhand). |
I think #23707 might be related |
so yes I think this is a dup of #23707 but the error was being swallowed somewhere |
and I think #23707 is a dup of an older issue too :) |
sorry I'm not sure if this is a dup of #23707 specifically; I was thinking of another issue |
Any progress here? I'm running into this as well. |
Nominating for discussion at compiler team meeting. |
assigning P-medium |
This produces "error: overflow evaluating the requirement use std::borrow::ToOwned;
enum Foo {
Bar,
Baz { cow: Result<&'static Foo, <Foo as ToOwned>::Owned> }
}
impl ToOwned for Foo {
type Owned = Box<Foo>;
fn to_owned(&self) -> Box<Foo> { loop {} }
} However, this works: use std::borrow::Borrow;
pub trait ToOwned {
type Owned: Borrow<Self>;
fn to_owned(&self) -> Self::Owned;
}
enum Foo {
Bar,
Baz { cow: Result<&'static Foo, <Foo as ToOwned>::Owned> }
}
impl ToOwned for Foo {
type Owned = Box<Foo>;
fn to_owned(&self) -> Box<Foo> { loop {} }
} Does this have to do with coherence cross-crate interactions? |
Both of @eddyb's examples compile now, while the code in the OP still fails. |
Triage: OP's code produces
|
FWIW the issues I had with this in jonas-schievink/xml-rpc-rs#10 are still very much there |
Minimized example: trait MyToOwned {
type Owned;
}
// This has an implicit `T: Sized` bound
impl<'a, T> MyToOwned for &'a T {
type Owned = ();
}
struct MyCow<B: MyToOwned + ?Sized> {
_owned: <B as MyToOwned>::Owned,
}
struct Test {
_f: MyCow<&'static Test>,
} Adding I do not think this should be an error, since |
Interestingly this is accepted: trait MyToOwned {
type Owned;
}
// This has an implicit `T: Sized` bound
impl<'a, T> MyToOwned for &'a T {
type Owned = ();
}
struct MyCow<O, B: MyToOwned<Owned = O> + ?Sized> {
_owned: (O, B),
}
struct Test {
_f: MyCow<<&'static Test as MyToOwned>::Owned, &'static Test>,
} |
Ran into this today with some code very similar to the original example. Reduced version below: (Rust Playground) use std::borrow::Cow;
struct Element {
children: Cow<'static, [Element]>,
} I believe this should be accepted because the The error message is initially pretty confusing because
It's definitely an issue with the traits because this version that just uses simple types directly compiles with no issues: (Rust Playground) enum Array<'a, T> {
Borrowed(&'a [T]),
Owned(Vec<T>),
}
struct Element {
children: Array<'static, Element>,
} Something like this is probably a reasonable workaround for anyone else running into something similar. |
@sunjay's example is exactly what I had when I ran into this issue. Writing my own cow array is not feasible because you not only need to define your own data type, but also all the operations, which is too much for me :( |
Triage: According to #129541 (comment) this has been fixed by accident. Now we just need a regression test(s) to close this issue. |
Triage: This should actually be covered by the test added via https://github.com/rust-lang/rust/pull/133473/files which belongs as another issue. Closing as obsolete. |
The example causes the checker to loop with build
rustc 1.0.0-dev (81938ec58 2015-03-25) (built 2015-03-25)
:It does still work using the Rust playpen here. I'm not sure if something changed in the API or if it's a bug or something else. The docs show
ToOwned::Owned: Sized
so the requirement should be satisfied. /cc @aturonThe text was updated successfully, but these errors were encountered: