Skip to content

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

Closed
WaffleLapkin wants to merge 1 commit into
rust-lang:masterfrom
WaffleLapkin:never-sized
Closed

Add a note that ! can only be coerced to sized types#1815
WaffleLapkin wants to merge 1 commit into
rust-lang:masterfrom
WaffleLapkin:never-sized

Conversation

@WaffleLapkin
Copy link
Copy Markdown
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
Comment thread src/type-coercions.md

r[coerce.types.never]
* `!` to any `T`
* `!` to any `T` which is `Sized`
Copy link
Copy Markdown
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
Copy Markdown
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