Skip to content

Some(place) passed where Option[&T] is expected moves the place instead of borrowing it #1627

Closed

Description

@ehartford

Found by Modeled C stage 12b (#1618) while rendering a nullable callback's userdata as Option[&U].

Minimal repro (with run):

type Ctx { n: i32 }
fn h(ud: Option[&Ctx]) -> i32: match ud:
    Some(u) => u.n
    None => -1
fn main:
    let ctx = Ctx { n: 40 }
    print(h(Some(ctx)))
    print(ctx.n)

Expected: h(Some(ctx)) borrows ctx (the parameter type is Option[&Ctx]; a &T demand on a place borrows, §3.8 auto-referencing, D22), or is refused. Actual: it compiles, and the next line is error: use of moved value on ctx — the Some(ctx) against an expected Option[&Ctx] recorded a move of ctx while producing a reference. The same happens for let z: Option[&Ctx] = Some(ctx). Some(&ctx) works.

The stage 12b fixtures spell Some(&ctx); once this is fixed, Some(ctx) is the spelling with no ceremony.

Activity

  1. added a commit that references this issue on Sep 27, 2026
    682b77a
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions