From 435ca16f4fa7bd47c16de693054be5cba5fd4ebb Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 3 Oct 2013 00:15:54 -0700 Subject: [PATCH] Close out #9155 Add a test to make sure it works and switch a private struct over to a newtype. Closes #9155 --- src/libstd/rt/io/buffered.rs | 22 +++++++++------------- src/test/auxiliary/issue_9155.rs | 17 +++++++++++++++++ src/test/run-pass/issue_9155.rs | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/test/auxiliary/issue_9155.rs create mode 100644 src/test/run-pass/issue_9155.rs diff --git a/src/libstd/rt/io/buffered.rs b/src/libstd/rt/io/buffered.rs index 3e801f28991..a8cf8151499 100644 --- a/src/libstd/rt/io/buffered.rs +++ b/src/libstd/rt/io/buffered.rs @@ -187,25 +187,21 @@ impl Decorator for BufferedWriter { } } -// FIXME #9155 this should be a newtype struct -struct InternalBufferedWriter { - inner: BufferedWriter -} +struct InternalBufferedWriter(BufferedWriter); impl Reader for InternalBufferedWriter { fn read(&mut self, buf: &mut [u8]) -> Option { - self.inner.inner.read(buf) + self.inner.read(buf) } fn eof(&mut self) -> bool { - self.inner.inner.eof() + self.inner.eof() } } /// Wraps a Stream and buffers input and output to and from it /// /// Note that `BufferedStream` will NOT flush its output buffer when dropped. -// FIXME #9155 this should be a newtype struct pub struct BufferedStream { priv inner: BufferedReader> } @@ -214,7 +210,7 @@ impl BufferedStream { pub fn with_capacities(reader_cap: uint, writer_cap: uint, inner: S) -> BufferedStream { let writer = BufferedWriter::with_capacity(writer_cap, inner); - let internal_writer = InternalBufferedWriter { inner: writer }; + let internal_writer = InternalBufferedWriter(writer); let reader = BufferedReader::with_capacity(reader_cap, internal_writer); BufferedStream { inner: reader } @@ -238,25 +234,25 @@ impl Reader for BufferedStream { impl Writer for BufferedStream { fn write(&mut self, buf: &[u8]) { - self.inner.inner.inner.write(buf) + self.inner.inner.write(buf) } fn flush(&mut self) { - self.inner.inner.inner.flush() + self.inner.inner.flush() } } impl Decorator for BufferedStream { fn inner(self) -> S { - self.inner.inner.inner.inner() + self.inner.inner.inner() } fn inner_ref<'a>(&'a self) -> &'a S { - self.inner.inner.inner.inner_ref() + self.inner.inner.inner_ref() } fn inner_mut_ref<'a>(&'a mut self) -> &'a mut S { - self.inner.inner.inner.inner_mut_ref() + self.inner.inner.inner_mut_ref() } } diff --git a/src/test/auxiliary/issue_9155.rs b/src/test/auxiliary/issue_9155.rs new file mode 100644 index 00000000000..486eb8fd6f6 --- /dev/null +++ b/src/test/auxiliary/issue_9155.rs @@ -0,0 +1,17 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub struct Foo(T); + +impl Foo { + pub fn new(t: T) -> Foo { + Foo(t) + } +} diff --git a/src/test/run-pass/issue_9155.rs b/src/test/run-pass/issue_9155.rs new file mode 100644 index 00000000000..ba92a0c7b1f --- /dev/null +++ b/src/test/run-pass/issue_9155.rs @@ -0,0 +1,20 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_9155.rs +// xfail-fast windows doesn't like the aux-build + +extern mod issue_9155; + +struct Baz; + +fn main() { + issue_9155::Foo::new(Baz); +}