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

Support builtin bounds on associated types and make them Sized by default #17921

Closed
kennytm opened this Issue Oct 10, 2014 · 6 comments

Comments

Projects
None yet
5 participants
@kennytm
Copy link
Member

kennytm commented Oct 10, 2014

(Moved from http://discuss.rust-lang.org/t/make-associated-types-sized-by-default/615)

Currently this program:

#![feature(associated_types)]
trait A {
    type T;
    fn foo(&self) -> <Self as A>::T;
    fn bar(&self) -> <Self as A>::T { self.foo() }
}
fn main() {}

Fails to compile as:

1.rs:5:39: 5:49 error: cannot move a value of type T: the size of T cannot be statically determined [E0161]
1.rs:5     fn bar(&self) -> <Self as A>::T { self.foo() }
                                             ^~~~~~~~~~

According to RFC 59 we should be able to fix it by (currently unimplemented)

trait A {
    type T : Sized;
    ...
}

But,

  1. Shouldn't associated types be Sized by default? As associated types are to be used to replace "output" type parameters, it is more convenient to be Sized.

  2. If associated types are Sized by default, what should be the syntax then if we want to allow unsized associated types? The generic spelling currently suggests something like

    type Sized? T;
    
@aturon

This comment has been minimized.

Copy link
Member

aturon commented Oct 10, 2014

@aturon aturon added the I-nominated label Oct 12, 2014

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Oct 12, 2014

Nominating. Associated types are planned to be un-feature-gated by 1.0, and this change is not backwards-compatible.

Assuming that we keep our current rules/syntax for generics and unsized types, I think we need to take both of the suggestions in this issue to ensure consistency with the rest of the language.

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Oct 12, 2014

Agreed on both suggestions.

@alexcrichton alexcrichton referenced this issue Oct 16, 2014

Closed

Implement associated items #17307

23 of 26 tasks complete
@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Oct 16, 2014

Assigning P-backcompat-lang, 1.0.

@pnkfelix pnkfelix added this to the 1.0 milestone Oct 16, 2014

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 29, 2014

I'm sort of working on this

@nikomatsakis nikomatsakis changed the title Make associated types Sized by default Support builtin bounds on associated types and make them Sized by default Oct 29, 2014

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 29, 2014

I updated the title to reflect the full work involved in this issue. I am targeting this as supporting builtin bounds like Sized or Copy, which is mildly easier than the general case. See #18178 for the general case.

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.