diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-01-07 13:57:42 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-01-07 20:26:20 -0500 |
| commit | 55c6a68f1184eefb9e475b5f58272931688d2bc9 (patch) | |
| tree | 2b25ba3cc6e0744c7e4c70d6cbe0d723379975dd /src | |
| parent | 4dd368b90a8d53af1ce582ec45d03a70d8fe2051 (diff) | |
| download | rust-55c6a68f1184eefb9e475b5f58272931688d2bc9.tar.gz rust-55c6a68f1184eefb9e475b5f58272931688d2bc9.zip | |
Add rather involved run-pass test case.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/run-pass/associated-types-ref-from-struct.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/run-pass/associated-types-ref-from-struct.rs b/src/test/run-pass/associated-types-ref-from-struct.rs new file mode 100644 index 00000000000..3c7cc7c4975 --- /dev/null +++ b/src/test/run-pass/associated-types-ref-from-struct.rs @@ -0,0 +1,62 @@ +// 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. + +// Test associated type references in structure fields. + +trait Test { + type V; + + fn test(&self, value: &Self::V) -> bool; +} + +/////////////////////////////////////////////////////////////////////////// + +struct TesterPair<T:Test> { + tester: T, + value: T::V, +} + +impl<T:Test> TesterPair<T> { + fn new(tester: T, value: T::V) -> TesterPair<T> { + TesterPair { tester: tester, value: value } + } + + fn test(&self) -> bool { + self.tester.test(&self.value) + } +} + +/////////////////////////////////////////////////////////////////////////// + +struct EqU32(u32); +impl Test for EqU32 { + type V = u32; + + fn test(&self, value: &u32) -> bool { + self.0 == *value + } +} + +struct EqI32(i32); +impl Test for EqI32 { + type V = i32; + + fn test(&self, value: &i32) -> bool { + self.0 == *value + } +} + +fn main() { + let tester = TesterPair::new(EqU32(22), 23); + tester.test(); + + let tester = TesterPair::new(EqI32(22), 23); + tester.test(); +} |
