Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack overflow in impl Writer for &mut Writer #17767

Closed
stepancheg opened this issue Oct 4, 2014 · 3 comments
Closed

stack overflow in impl Writer for &mut Writer #17767

stepancheg opened this issue Oct 4, 2014 · 3 comments

Comments

@stepancheg
Copy link
Contributor

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
@mahkoh
Copy link
Contributor

mahkoh commented Oct 4, 2014

Smaller:

use std::io;

fn main() {
    let ref mut w = &mut io::stdout() as &mut Writer;
    w.write([]);
}

@bkoropoff
Copy link
Contributor

Looks like a libstd bug:

impl<'a> Writer for &'a mut Writer+'a {
    #[inline]
    fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) }

    #[inline]
    fn flush(&mut self) -> IoResult<()> { self.flush() }
}

@stepancheg, could you file a separate issue for the internal compiler error?

@stepancheg
Copy link
Contributor Author

@bkoropoff #17771

@stepancheg stepancheg changed the title Incorrect stack overflow in generated code stack overflow in impl Writer for &mut Writer Oct 4, 2014
bkoropoff added a commit to bkoropoff/rust that referenced this issue Oct 4, 2014
bors added a commit that referenced this issue Oct 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants