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 · Fixed by #18506
Closed

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

kennytm opened this issue Oct 10, 2014 · 6 comments · Fixed by #18506
Milestone

Comments

@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
Copy link
Member

aturon commented Oct 10, 2014

@aturon
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
Copy link
Member

nrc commented Oct 12, 2014

Agreed on both suggestions.

@pnkfelix
Copy link
Member

Assigning P-backcompat-lang, 1.0.

@pnkfelix pnkfelix added this to the 1.0 milestone Oct 16, 2014
@nikomatsakis
Copy link
Contributor

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
Copy link
Contributor

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.

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
fix: Panic when a TAIT exists in a RPIT

Fixes  rust-lang#17921

When there is a TAIT inside of a RPIT like;

```rust
trait Foo {}
type Bar = impl Foo;
fn foo<A>() -> impl Future<Output = Bar> { .. }
```

while inferencing `fn foo`, `insert_inference_vars_for_impl_trait` tries to substitute impl trait bounds of `Bar`, i.e. `Implemented(Foo)` with RPITs `placeholders`, and this causes panic

https://github.com/rust-lang/rust-analyzer/blob/fa003262474185fd62168379500fe906b331824b/crates/hir-ty/src/infer.rs#L903-L905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants