Skip to content

Trait object allowed to escape its lifetime #14285

Closed
@brandonw

Description

@brandonw

Updated description

This code should be rejected from the compiler, but it is not:

trait Foo {}

struct A;

impl Foo for A {}

impl Drop for A {
    fn drop(&mut self) { println!("dropping"); }
}

struct B<'a>(&'a Foo);

fn foo<'a>(a: &Foo) -> B<'a> { B(a) }

fn main() {
    let _test = foo(&A);
    println!("test");
}

Original Issue

Crash when reading from stdin

Depending on whether you let the compiler infer traits for you or not, you can make a program reading input from stdin crash in a couple different ways.

Repro here: https://gist.github.com/brandonw/3a3d040b7c6213740794

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