Skip to content

A Box[dyn T] parameter accepts no argument, and a &dyn T cannot be forwarded to a &dyn T parameter (§3.9, §11.3) #1854

Closed

Description

@ehartford

Spec

§3.9 (implicit trait object coercion) and §11.3 (Box[dyn Trait], &dyn Trait).

Repro (main at 355c20b)

use std.box.Box
trait Held:
    fn held(self: &Self) -> i32
type R { id: i32 }
impl Held for R:
    fn held(self: &Self) -> i32: self.id
fn eat(x: Box[dyn Held]): print(f"ate {x.held()}")
fn peek(x: &dyn Held): print(f"peek {x.held()}")
fn relay(x: &dyn Held): peek(x)
fn main:
    eat(Box.new(R { id: 1 }))                     // type 'Box' does not implement trait 'Held' required for dyn parameter
    let a: Box[dyn Held] = Box.new(R { id: 2 })
    eat(a)                                        // same
    relay(&R { id: 3 })                           // peek(x): argument cannot be converted to dyn trait object

A Box[dyn T] parameter accepts no argument at all, and a &dyn T value cannot be forwarded to another &dyn T parameter.

Cause

SemaCheck check_dyn_trait_call_compat asks whether the argument's type implements the trait. For a Box[C] that type is Box, not C. An argument that already is the parameter's trait object has no concrete type at all. Once Sema accepted a Box[C] argument, codegen's call path could not build it either ("cannot lower argument 1 to dyn trait 'Held'").

Found by the consume_call/boxdyn and consume_cond_*/boxdyn cells that #1847 adds to tools/drop_audit.w (COMPILE-FAIL on base).

Activity

  1. added
    bug
    on Sep 28, 2026
  2. added 2 commits that reference this issue on Sep 29, 2026
    2237929
    5744df8
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions