Skip to content

Unsized types in required trait methods #134475

@ionicmc-rs

Description

@ionicmc-rs

so this issue is a follow up for #134422 (closed as not planned) to suggest making a lint instead.

What the issue talked about

Rust does not check for T: Sized in required trait methods

trait Foo {
    fn bar(self: Self, x: str);
}

The above code compiles, even though Self and str are both ?Sized

this makes the trait unimplementable

impl Foo for [u8] {
    fn bar(self: Self, x: str) {}
}

Produces:

The size for values of type `[u8]` cannot be known at compile time
The size for values of type `str` cannot be known at compile time

For more information please see the RFC

Meta

for anyone who cares, here is rustc --version --verbose

rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Here is the RFC

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions