Skip to content

Difficulty creating &mut Trait #8248

Closed
Closed
@alexcrichton

Description

@alexcrichton

This test case:

trait A {}
struct B;
impl A for B {}

fn foo(_: &mut A) {
}

fn main() {
    let mut b = B;
    foo(&mut b as &mut A);
}

fails with

foo.rs:10:8: 10:14 error: borrowed value does not live long enough
foo.rs:10     foo(&mut b as &mut A);
                  ^~~~~~
note: borrowed pointer must be valid for the static lifetime...
foo.rs:8:10: 11:1 note: ...but borrowed value is only valid for the block at 8:10
foo.rs:8 fn main() {
foo.rs:9     let mut b = B;
foo.rs:10     foo(&mut b as &mut A);
foo.rs:11 }
error: aborting due to previous error

cc @msullivan

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions