From 9675488ef9480365c2d26e23bfd649128037880f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 31 Dec 2014 12:38:53 -0500 Subject: [PATCH] Add tests for two random issues that seem to be fixed on this branch. Fixes #20346. Fixes #20371. --- .../associated-types-issue-20346.rs | 46 +++++++++++++++++++ .../run-pass/associated-types-issue-20371.rs | 17 +++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/compile-fail/associated-types-issue-20346.rs create mode 100644 src/test/run-pass/associated-types-issue-20371.rs diff --git a/src/test/compile-fail/associated-types-issue-20346.rs b/src/test/compile-fail/associated-types-issue-20346.rs new file mode 100644 index 00000000000..255b8a25a4c --- /dev/null +++ b/src/test/compile-fail/associated-types-issue-20346.rs @@ -0,0 +1,46 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we reliably check the value of the associated type. + +#![crate_type = "lib"] +#![feature(associated_types)] +#![no_implicit_prelude] + +use std::option::Option::{None, Some, mod}; +use std::vec::Vec; + +trait Iterator { + type Item; + + fn next(&mut self) -> Option; +} + +fn is_iterator_of>(_: &I) {} + +struct Adapter { + iter: I, + found_none: bool, +} + +impl Iterator for Adapter where I: Iterator> { + type Item = T; + + fn next(&mut self) -> Option { + loop {} + } +} + +fn test_adapter>>(it: I) { + is_iterator_of::, _>(&it); // Sanity check + let adapter = Adapter { iter: it, found_none: false }; + is_iterator_of::(&adapter); // OK + is_iterator_of::, _>(&adapter); //~ ERROR type mismatch +} diff --git a/src/test/run-pass/associated-types-issue-20371.rs b/src/test/run-pass/associated-types-issue-20371.rs new file mode 100644 index 00000000000..a6fb2b9e2ea --- /dev/null +++ b/src/test/run-pass/associated-types-issue-20371.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we are able to have an impl that defines an associated type +// before the actual trait. + +#![feature(associated_types)] +impl X for f64 { type Y = int; } +trait X {type Y; } +fn main() {}