From 05e3248a7974f55b64f75a2483b37ff8c001a4ff Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 25 Jun 2014 18:18:13 -0700 Subject: librustc: Match trait self types exactly. This can break code that looked like: impl Foo for Box { fn f(&self) { ... } } let x: Box = ...; x.f(); Change such code to: impl Foo for Box { fn f(&self) { ... } } let x: Box = ...; x.f(); That is, upcast before calling methods. This is a conservative solution to #5781. A more proper treatment (see the xfail'd `trait-contravariant-self.rs`) would take variance into account. This change fixes the soundness hole. Some library changes had to be made to make this work. In particular, `Box` is no longer showable, and only `Box` is showable. Eventually, this restriction can be lifted; for now, it does not prove too onerous, because `Any` is only used for propagating the result of task failure. This patch also adds a test for the variance inference work in #12828, which accidentally landed as part of DST. Closes #5781. [breaking-change] --- src/libstd/io/comm_adapters.rs | 5 ++++- src/libstd/task.rs | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index c03fbf302d7..cd5887b7add 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -183,7 +183,10 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; - let got = task::try(proc() { rx.recv() }).unwrap(); + let got = match task::try(proc() { rx.recv() }) { + Ok(got) => got, + Err(_) => fail!(), + }; assert_eq!(wanted, got); match writer.write_u8(1) { diff --git a/src/libstd/task.rs b/src/libstd/task.rs index dad241002f8..8ccded6681b 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -630,9 +630,11 @@ mod test { let mut reader = ChanReader::new(rx); let stdout = ChanWriter::new(tx); - TaskBuilder::new().stdout(box stdout as Box).try(proc() { - print!("Hello, world!"); - }).unwrap(); + let r = TaskBuilder::new().stdout(box stdout as Box) + .try(proc() { + print!("Hello, world!"); + }); + assert!(r.is_ok()); let output = reader.read_to_str().unwrap(); assert_eq!(output, "Hello, world!".to_string()); -- cgit 1.4.1-3-g733a5