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

Loop evaluating Cow<'a, T>: Sized in recursive structure #23714

Open
freebroccolo opened this Issue Mar 25, 2015 · 11 comments

Comments

Projects
None yet
10 participants
@freebroccolo
Copy link
Contributor

freebroccolo commented Mar 25, 2015

The example causes the checker to loop with build rustc 1.0.0-dev (81938ec58 2015-03-25) (built 2015-03-25):

src/lib.rs:1:1: 1:1 error: overflow evaluating the requirement `collections::borrow::Cow<'static, Foo> : core::marker::Sized` [E0275]

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 @aturon

use std::borrow::*;

enum Foo {
    Bar,
    Baz { cow: Cow<'static, Foo> }
}

impl ToOwned for Foo {
    type Owned = Box<Foo>;
    fn to_owned(&self) -> Box<Foo> {
        let res = match self {
            &Foo::Bar => {
                Foo::Bar
            },
            &Foo::Baz { ref cow } => {
                Foo::Baz { cow: cow.to_owned() }
            }
        };
        Box::new(res)
    }
}

impl Borrow<Foo> for Box<Foo> {
    fn borrow(&self) -> &Foo {
        &**self
    }
}
@aturon

This comment has been minimized.

Copy link
Member

aturon commented Mar 25, 2015

I believe that @nikomatsakis recently made a change that detected overflow, that may be related (I don't recall the details offhand).

@freebroccolo

This comment has been minimized.

Copy link
Contributor Author

freebroccolo commented Mar 26, 2015

I haven't pinpointed the commit which causes the issue but it is somewhere within 1be8fcb..c5c3de0.

@mitchmindtree

This comment has been minimized.

Copy link
Contributor

mitchmindtree commented Mar 26, 2015

I think #23707 might be related

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 26, 2015

so yes I think this is a dup of #23707 but the error was being swallowed somewhere

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 26, 2015

and I think #23707 is a dup of an older issue too :)

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 26, 2015

sorry I'm not sure if this is a dup of #23707 specifically; I was thinking of another issue

@jmgrosen

This comment has been minimized.

Copy link
Contributor

jmgrosen commented Jun 10, 2016

Any progress here? I'm running into this as well.

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Jun 10, 2016

Nominating for discussion at compiler team meeting.

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jun 23, 2016

assigning P-medium

@pnkfelix pnkfelix added P-medium and removed I-nominated labels Jun 23, 2016

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Jun 23, 2016

This produces "error: overflow evaluating the requirement Foo: std::marker::Sized [E0275]":

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?

@jonas-schievink

This comment has been minimized.

Copy link
Member

jonas-schievink commented Feb 16, 2017

Both of @eddyb's examples compile now, while the code in the OP still fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.