Skip to content

Unsized types in required trait methods #134475

Open

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 18, 2024
  2. ionicmc-rs commented on Dec 18, 2024

    @ionicmc-rs
    Author
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Dec 18, 2024
  4. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    A-dyn-traitArea: trait objects, vtable layout
    T-langRelevant to the language team
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    and removed
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 18, 2024
  5. changed the title [-]Unsized receiver in traits[/-] [+]Unsized types in required trait methods[/+] on Dec 18, 2024
  6. added
    needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.
    on Dec 18, 2024
  7. ionicmc-rs commented on Dec 18, 2024

    @ionicmc-rs
    ContributorAuthor

    i will make an rfc as the label suggests

  8. ionicmc-rs commented on Dec 18, 2024

    @ionicmc-rs
    ContributorAuthor

    here is the rfc

  9. ionicmc-rs commented on Dec 18, 2024

    @ionicmc-rs
    Author
  10. rustbot commented on Dec 18, 2024

    @rustbot
  11. ionicmc-rs commented on Dec 18, 2024

    @ionicmc-rs
    Author
  12. workingjubilee commented on Dec 18, 2024

    @workingjubilee
  13. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Dec 19, 2024
  14. ionicmc-rs commented on Dec 19, 2024

    @ionicmc-rs
    Author
  15. ionicmc-rs commented on Dec 20, 2024

    @ionicmc-rs
    ContributorAuthor

    The RFC may not be accepted, but this issue is mildly severe, so can someone come up with a solution

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-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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions