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

object-safe traits can have associated types with unchecked bounds #27675

Open
arielb1 opened this Issue Aug 11, 2015 · 4 comments

Comments

Projects
None yet
6 participants
@arielb1
Copy link
Contributor

arielb1 commented Aug 11, 2015

STR

trait Foo { type Assoc: PartialEq<Box<Self>>; }
impl Foo for u32 { type Assoc = Box<u32>; }

fn foo<T: Foo+?Sized>(u: Box<T>, v: T::Assoc) -> bool {
    &v == &u
}

fn main() {
    let bar: Box<Foo<Assoc=Box<u32>>> = Box::new(4);
    foo(bar, Box::new(5));
}

Result

<anon>:5:5: 5:13 error: internal compiler error: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<Box<u32> as core::cmp::PartialEq<Box<Foo<Assoc=Box<u32>> + 'static>>>)),depth=1),Unimplemented)]` fulfilling during trans

I guess this should be banned.

cc @nikomatsakis

@arielb1

This comment has been minimized.

Copy link
Contributor Author

arielb1 commented Aug 11, 2015

Related:

use std::fmt;

trait Foo {
    type Assoc: 'static;
}

fn foo<T: Foo+?Sized>(t: T::Assoc) -> Box<fmt::Display+'static>
        where T::Assoc: fmt::Display {
    Box::new(t)
}

fn wat() -> Box<fmt::Display+'static> {
    let x = 42;
    foo::<Foo<Assoc=&u32>>(&x)
}

fn main() {
    println!("{}", wat());
}
@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Aug 11, 2015

Interesting. I agree that it should be illegal and we should amend WF relations for object types to check that the bindings cover the requirements of the trait -- the RFC was incomplete on this topic.

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jan 21, 2016

The example from the first comment (#27675 (comment)) is actually scarier than the original bug description; at least, I usually can think "oh, an ICE, well that might just be something that won't actually ever compile"; but the first comment is showing code that is indeed a case of "wat"!

@arielb1 arielb1 changed the title object-safe traits can have associated types with Self-containing bounds object-safe traits can have associated types with unchecked bounds Jan 21, 2016

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jul 7, 2016

triage: P-medium

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.