Skip to content

Can create trait objects with self-containing bounds #38604

Closed
@arielb1

Description

@arielb1

Meta

rustc 1.15.0-nightly (71c06a56a 2016-12-18)

STR

trait Q<T:?Sized> {}
trait Foo where u32: Q<Self> {
    fn foo(&self);
}

impl Q<()> for u32 {}
impl Foo for () {
    fn foo(&self) {
        println!("foo!");
    }
}

fn main() {
    let _f: Box<Foo> = Box::new(());
}

Expected Result

Box<Foo> is not well-formed, because u32: Q<Foo> does not hold.

Actual Result

Code compiles.

This does not seem to cause any trouble, but is a potential future-compatibility hazard if we start elaborating these bounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-needs-decisionIssue: In need of a decision.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions