Skip to content

where Self: Sized on trait method doesn't work as expected when implementing for unsized types. #57900

Description

@crlf0710

I've got this code

trait Foo {
    fn bar(&self) -> Self where Self: Sized;
}

impl Foo for str {
//    fn bar(&self) -> Self { unimplemented!() }
}

the error is:

error[E0046]: not all trait items implemented, missing: `bar`
 --> src/lib.rs:5:1

However, since str is not Sized, i don't think bar needs to be implemented. if i remove the "//", i'll got:

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/lib.rs:6:22

So although this trait fits object safety rules, i still can't implement it for unsized types.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamT-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