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

Can create trait objects with self-containing bounds #38604

Closed
arielb1 opened this issue Dec 25, 2016 · 2 comments
Closed

Can create trait objects with self-containing bounds #38604

arielb1 opened this issue Dec 25, 2016 · 2 comments
Labels
I-needs-decision Issue: In need of a decision. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Dec 25, 2016

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.

@arielb1 arielb1 added A-amusing I-needs-decision Issue: In need of a decision. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 25, 2016
@nikomatsakis
Copy link
Contributor

Discussed in compiler team meeting. This is also an @rust-lang/lang thing, so cc @rust-lang/lang. It does seem like it'd be better to make any trait that references Self in bounds as being not object-safe, as much as a precautionary measure as anything else, but we decided to first run a crater run and measure impact in any case. @arielb1 has a branch that can be adapted.

@nikomatsakis nikomatsakis added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed I-nominated labels Dec 29, 2016
@aturon
Copy link
Member

aturon commented Jan 1, 2017

I agree with taking this conservative step.

@bors bors closed this as completed in c85fb19 Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-needs-decision Issue: In need of a decision. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants