Skip to content

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

Closed
@Pzixel

Description

@Pzixel

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.

Metadata

Metadata

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions