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

Projecting <Type as Trait>::N should check that N is part of Trait #22731

Closed
pnkfelix opened this issue Feb 23, 2015 · 6 comments
Closed

Projecting <Type as Trait>::N should check that N is part of Trait #22731

pnkfelix opened this issue Feb 23, 2015 · 6 comments
Assignees
Labels
A-trait-system Area: Trait system A-type-system Area: Type system

Comments

@pnkfelix
Copy link
Member

spawned off of #21259

test case

use std::default::Default;

trait Impled { fn f(&self) {} }
trait Vr: Impled {
    type Y: Default + Par<<Self as Impled>::Noexist>; fn g(&self) {}
}
trait Par<X:Default> {
    fn h(&self) -> (X, String) { (Default::default(), format!("Par::h")) }
}

struct S1;
impl Impled for S1 {}
impl Vr for S1 { type Y = (); }
impl Par<()> for () { }

fn main() {
    let y: <S1 as Vr>::Y = Default::default();
    let (_, s) = Par::h(&y);
    println!("{}", s);
}

The above code should be rejected by the compiler, because <Self as Impled>::Noexist is not a well-formed projection of an associated item. Instead, it currently runs.


(This bug is not quite as bad as it might seem, since one easily runs into problems if one actually attempts to program generically with this trait and associated item, as shown in the below modification to the last three lines above. This new program is correctly rejected by the compiler, though perhaps with messages that are ... subpar:)

fn foo<V:Vr>(v: V) {
    let y: <V as Vr>::Y = Default::default();
    let (_, s) = Par::h(&y);
    println!("{}", s);
}
fn main() {
    foo(S1);
}

Transcript of error output:

../src/test/compile-fail/issue-21259-e.rs:18:18: 18:24 error: the trait `core::marker::Sized` is not implemented for the type `<V as Impled>::Noexist` [E0277]
../src/test/compile-fail/issue-21259-e.rs:18     let (_, s) = Par::h(&y);
                                                              ^~~~~~
../src/test/compile-fail/issue-21259-e.rs:18:18: 18:24 note: `<V as Impled>::Noexist` does not have a constant size known at compile-time
../src/test/compile-fail/issue-21259-e.rs:18     let (_, s) = Par::h(&y);
                                                              ^~~~~~
../src/test/compile-fail/issue-21259-e.rs:18:18: 18:24 error: the trait `core::default::Default` is not implemented for the type `<V as Impled>::Noexist` [E0277]
../src/test/compile-fail/issue-21259-e.rs:18     let (_, s) = Par::h(&y);
                                                              ^~~~~~
error: aborting due to 2 previous errors
@pnkfelix pnkfelix self-assigned this Feb 23, 2015
@pnkfelix
Copy link
Member Author

see also #19883 , which fixed a very similar bug, but presumably did so in a much more roundabout manner than what I am attempting.


update: Oh I see, someone thought the issue was fixed because they started seeing failures on the particular test case that had been filed, and so they just added tests codifying those (strange) error messages.

@pnkfelix
Copy link
Member Author

This should be fixed by #22172. But I want to port the regression tests over from #22759.

@steveklabnik steveklabnik added A-type-system Area: Type system A-trait-system Area: Trait system labels Feb 25, 2015
@bluss
Copy link
Member

bluss commented May 25, 2015

I think this is fixed, I see

<anon>:5:27: 5:52 error: use of undeclared associated type `Impled::Noexist`
<anon>:5     type Y: Default + Par<<Self as Impled>::Noexist>; fn g(&self) {}
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~

👍

@pnkfelix
Copy link
Member Author

And at this point I do not know what regression tests my earlier comment was referencing; there are not any such tests on #22759 ...

@pnkfelix pnkfelix reopened this May 26, 2015
@pnkfelix
Copy link
Member Author

Hmm, maybe I meant to reference #21259 and just mistyped? Or maybe I meant to refer to this issue itself? Reopened so that I'll attempt to put in the corresponding tests.

@arielb1
Copy link
Contributor

arielb1 commented Jul 7, 2015

This is fixed & tested.

@arielb1 arielb1 closed this as completed Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system A-type-system Area: Type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants