Skip to content

Add a note that ! can only be coerced to sized types #1815

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

Closed
wants to merge 1 commit into from

Conversation

WaffleLapkin
Copy link
Member

This commit is dated 2025-02-02, I accidentally found it while looking for something else lol.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 7, 2025
* `!` to any `T`
* `!` to any `T` which is `Sized`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you happen to have an example of something that would work but for this?

@WaffleLapkin
Copy link
Member Author

Checking again, it doesn't seem like this restriction is present in rustc (anymore?). Indeed this program (using incomplete features though!) compiles:

#![feature(unsized_locals)]

fn main() {
    let x: [()] = panic!();
    f(&x);
}

fn f(_: &[()]) {}

In practice though you can't make code that would do this coercion, simply because all coercion sites require sized types.

@WaffleLapkin WaffleLapkin deleted the never-sized branch May 9, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: The marked PR is awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants