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

Rust treat Self as dynamic when it shouldn't #63593

Closed
Pzixel opened this issue Aug 15, 2019 · 1 comment · Fixed by #61812
Closed

Rust treat Self as dynamic when it shouldn't #63593

Pzixel opened this issue Aug 15, 2019 · 1 comment · Fixed by #61812
Assignees
Labels
A-associated-items Area: Associated items such as associated types and consts. A-traits Area: Trait system C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Pzixel
Copy link

Pzixel commented Aug 15, 2019

Here is a sample code:

trait Inner<S> {}

trait MyTrait {
    fn something<I: Inner<Self>>(i: I);
}

Which fails to compile with

error[E0277]: the size for values of type Self cannot be known at compilation time
--> src/lib.rs:4:5
|
4 | fn something<I: Inner>(i: I);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time

OTOH if we add a special This associated type then we are completely fine:

#![feature(associated_type_defaults)]

trait Inner<S> {}

trait MyTrait {
    type This = Self;
    fn something<I: Inner<Self::This>>(i: I);
}

It looks like an undesirable behavior.

@jonas-schievink
Copy link
Contributor

That this fails to compile is intended. Unlike type parameters, traits do not have a default : Sized bound, so Self in traits has an unknown size.

The issue with associated type defaults might be fixed by #61812, I'll check that later.

@jonas-schievink jonas-schievink added A-associated-items Area: Associated items such as associated types and consts. A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 15, 2019
@jonas-schievink jonas-schievink added the F-associated_type_defaults `#![feature(associated_type_defaults)]` label Aug 29, 2019
@jonas-schievink jonas-schievink self-assigned this Aug 29, 2019
@jonas-schievink jonas-schievink added the requires-nightly This issue requires a nightly compiler in some way. label Jan 4, 2020
@bors bors closed this as completed in 3a0d106 Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. A-traits Area: Trait system C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants