You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
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
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
Sema/Codegen: a Box[dyn T] parameter takes a Box[C] of any implemento…
test: #1847's and #1854's behavior tests pin drop order and count in …