rust-lang / rust-lang/rust

Irrefutable bindings don't work for references to !

Open
#158,949 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Irrefutable bindings are great. I love that this works:

fn foo() {
    fn always_ok() -> Result<(), !> {
        Ok(())
    }

    let Ok(_) = always_ok();
}

Sadly, this doesn't work:

fn bar() {
    fn always_ok(_: &()) -> Result<(), &!> {
        Ok(())
    }

    let Ok(_) = always_ok(&());
}

It would be nice if it did. I think it is sound for it to do so—because you can never create !, you can never create a valid reference to !.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Rust examples from the issue and compare how irrefutable bindings treat Result<(), !> with Result<(), &!>. Investigate the compiler's handling of references to the never type; done means the second example is accepted while preserving soundness.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.