diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-05-31 18:48:20 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-06-06 19:51:23 -0400 |
| commit | 3fecd10428bbefd162a75512acb807dd65dcb1dd (patch) | |
| tree | 8cfc414d8da2068c60750a40a6fa965871b9dbe4 | |
| parent | bc5eb7d98c9ef2ede97f1cb533936ab8210d49a4 (diff) | |
| download | rust-3fecd10428bbefd162a75512acb807dd65dcb1dd.tar.gz rust-3fecd10428bbefd162a75512acb807dd65dcb1dd.zip | |
Add missing test case for contravariant trait matching
| -rw-r--r-- | src/test/run-pass/trait-contravariant-self.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/run-pass/trait-contravariant-self.rs b/src/test/run-pass/trait-contravariant-self.rs new file mode 100644 index 00000000000..1576c646286 --- /dev/null +++ b/src/test/run-pass/trait-contravariant-self.rs @@ -0,0 +1,37 @@ +// Copyright 2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This is an interesting test case. We have a trait (Bar) that is +// implemented for a `Box<Foo>` object (note: no bounds). And then we +// have a `Box<Foo:Send>` object. The impl for `Box<Foo>` is applicable +// to `Box<Foo:Send>` because: +// +// 1. The trait Bar is contravariant w/r/t Self because `Self` appears +// only in argument position. +// 2. The impl provides `Bar for Box<Foo>` +// 3. The fn `wants_bar()` requires `Bar for Box<Foo:Send>`. +// 4. `Bar for Box<Foo> <: Bar for Box<Foo:Send>` because +// `Box<Foo:Send> <: Box<Foo>`. + +trait Foo { } +struct SFoo; +impl Foo for SFoo { } + +trait Bar { fn dummy(&self); } +impl Bar for Box<Foo> { fn dummy(&self) { } } + +fn wants_bar<B:Bar>(b: &B) { } + +fn main() { + let x: Box<Foo:Send> = (box SFoo); + wants_bar(&x); +} + + |
