Skip to content

stack overflow in impl Writer for &mut Writer #17767

Closed
@stepancheg

Description

@stepancheg

Code:

use std::io;

struct Bar<'a> {
    writer: Option<&'a mut Writer + 'a>,
}

fn foo<'a>(mut bar: Bar<'a>) {
    match bar.writer {
        Some(ref mut w) => { w.write([]); },
        _ => {},
    }
}

fn main() {
    foo(Bar {
        writer: Some(&mut io::stdout() as &mut Writer),
    })
}

Compile, run, result is

task '<main>' has overflowed its stack

Sorry, cannot find smaller example to reproduce the problem.

$ rustc --version
rustc 0.12.0-nightly (136ab3c6b 2014-10-04 00:17:04 +0000)
$ uname -a
Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Similar code, internal compiler error:

use std::io;

struct Bar<'a> {
    writer: Option<&'a mut Writer + 'a>,
}

fn baz(_: &mut Writer) {
}

fn foo<'a>(mut bar: Bar<'a>) {
    baz(bar.writer.as_mut().unwrap());
}

fn main() {
    foo(Bar {
        writer: Some(&mut io::stdout() as &mut Writer),
    })
}
error: internal compiler error: trying to take the sizing type of std::io::Writer+'a, an unsized type

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