Skip to content

Unsized types in required trait methods #134475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ionicmc-rs opened this issue Dec 18, 2024 · 9 comments
Open

Unsized types in required trait methods #134475

ionicmc-rs opened this issue Dec 18, 2024 · 9 comments
Labels
A-dyn-trait Area: trait objects, vtable layout A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. T-lang Relevant to the language team T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@ionicmc-rs
Copy link
Contributor

ionicmc-rs commented Dec 18, 2024

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 18, 2024
@ionicmc-rs

This comment has been minimized.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 18, 2024
@fmease fmease added C-feature-request Category: A feature request, i.e: not implemented / a PR. A-dyn-trait Area: trait objects, vtable layout T-lang Relevant to the language team A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 18, 2024
@ionicmc-rs ionicmc-rs changed the title Unsized receiver in traits Unsized types in required trait methods Dec 18, 2024
@jieyouxu jieyouxu added the needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. label Dec 18, 2024
@ionicmc-rs
Copy link
Contributor Author

i will make an rfc as the label suggests

@ionicmc-rs
Copy link
Contributor Author

here is the rfc

@ionicmc-rs

This comment has been minimized.

@rustbot

This comment has been minimized.

@ionicmc-rs

This comment has been minimized.

@workingjubilee

This comment has been minimized.

@jieyouxu jieyouxu added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Dec 19, 2024
@ionicmc-rs

This comment has been minimized.

@ionicmc-rs
Copy link
Contributor Author

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
Labels
A-dyn-trait Area: trait objects, vtable layout A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. T-lang Relevant to the language team T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants