Skip to content

Unsized return types are allowed on trait associated function declarations #109270

Open
@Vlad-Shcherbina

Description

@Vlad-Shcherbina

I tried this code:

trait MyTrait {
    fn f() -> [u8];  // Ok, but it shouldn't be
}

impl MyTrait for () {
    fn f() -> [u8] {  // Compilation error, as expected
        todo!()
    }
}

I expect the line marked with "Ok" to cause compilation error, because the return type is unsized.
It's better to produce diagnostics early, without waiting until somebody tries to implement this trait (which would be impossible anyway).

Instead, this happens: the compiler allows to declare the associated function f(), and only complains when I try to implement it for a concrete type.

I did a quick search in the issue tracker and it looks like it's maybe similar to #82633.

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (7b4f48927 2023-03-12)
binary: rustc
commit-hash: 7b4f48927dce585f747a58083b45ab62b9d73a53
commit-date: 2023-03-12
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-discussionCategory: Discussion or questions that doesn't represent real issues.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions