mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Add tests for two random issues that seem to be fixed on this branch.
Fixes #20346. Fixes #20371.
This commit is contained in:
parent
6cb425d964
commit
9675488ef9
46
src/test/compile-fail/associated-types-issue-20346.rs
Normal file
46
src/test/compile-fail/associated-types-issue-20346.rs
Normal file
@ -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 <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 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<Self::Item>;
|
||||
}
|
||||
|
||||
fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
|
||||
|
||||
struct Adapter<I> {
|
||||
iter: I,
|
||||
found_none: bool,
|
||||
}
|
||||
|
||||
impl<T, I> Iterator for Adapter<I> where I: Iterator<Item=Option<T>> {
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<T> {
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
|
||||
is_iterator_of::<Option<T>, _>(&it); // Sanity check
|
||||
let adapter = Adapter { iter: it, found_none: false };
|
||||
is_iterator_of::<T, _>(&adapter); // OK
|
||||
is_iterator_of::<Option<T>, _>(&adapter); //~ ERROR type mismatch
|
||||
}
|
17
src/test/run-pass/associated-types-issue-20371.rs
Normal file
17
src/test/run-pass/associated-types-issue-20371.rs
Normal file
@ -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 <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 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() {}
|
Loading…
Reference in New Issue
Block a user