Skip to content

Sema: an owned str from ?? / .unwrap_or is not auto-borrowed into a &str parameter ("cannot produce &str"); a call result is #1974

Closed

Description

@ehartford

Found while porting tools/debug_drop.w off the internal with_fs_* externs (#1865).

Spec: §3.8 (a &T parameter auto-references its argument: peek(x) when peek takes &T); D22 (Option, Result, ?? and eliminators are transparent to view origins — they do not change what the eliminated value is).

Repro (installed with v0.15.3.0, main 9307016):

use std.fs
fn peek(s: &str): s.len()
fn make() -> str: "abc".clone()
fn main:
    print(<arg>)
<arg> verdict
peek(make()) ok
peek(make() ++ "") ok
peek(read_file("x") ?? "") error: ?? expression of type str cannot produce &str
peek(read_file("x").unwrap_or("")) error: Result.unwrap_or expression of type str cannot produce &str

Expected: all four are an owned str temporary borrowed for the call, as the first two are. The parameter's expected &str appears to be pushed into the eliminator's arms (asking the Result[str, IoError] payload to be a &str) instead of auto-referencing the eliminator's owned result.

Workaround used: bind first: let source = read_file(p) ?? "" then peek(source) (tools/debug_drop.w on branch wave-build). The fix removes it.

Activity

  1. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main in c884c1c (stack #2001 → #2010, seed-driven battery GREEN on b932ef6, tree identical to main). Fixture coverage is in the stack's commits.

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