Skip to content

RPITIT forces Self: Sized upon all other methods in a given trait. #115464

Closed
@AhoyISki

Description

@AhoyISki

I tried this code:

#![feature(return_position_impl_trait_in_trait)]

fn main() {
    let vec: Vec<Box<dyn Trait>> = Vec::new();

    for i in vec {
        i.fn_2();
    }
}

trait OtherTrait {}

trait Trait {
    fn fn_1(&self) -> impl OtherTrait
    where
        Self: Sized;

    fn fn_2(&self) -> bool;
}

I expected to see this happen: Successful compilation, since fn_2 does not require that Self: Sized, which is the case in vec.

Instead, this happened: I got the following compiler error:

error[E0277]: the size for values of type `dyn Trait<bool>` cannot be known at compilation time
 --> src/main.rs:7:11
  |
7 |         i.fn_2();
  |           ^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `dyn Trait<bool>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rust-testing` (bin "rust-testing") due to previous error

Even though fn_2 does not require that Self: Sized. I'm not really sure that this is the intended behavior of this feature, since changing impl OtherTrait to any concrete type would allow this to compile just fine.

Meta

rustc --version --verbose:

rustc 1.74.0-nightly (35e416303 2023-09-01)
binary: rustc
commit-hash: 35e416303e6591a71ef6a91e006c602d2def3968
commit-date: 2023-09-01
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions