Skip to content

Commit 9675488

Browse files
committed
Add tests for two random issues that seem to be fixed on this branch.
Fixes #20346. Fixes #20371.
1 parent 6cb425d commit 9675488

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we reliably check the value of the associated type.
12+
13+
#![crate_type = "lib"]
14+
#![feature(associated_types)]
15+
#![no_implicit_prelude]
16+
17+
use std::option::Option::{None, Some, mod};
18+
use std::vec::Vec;
19+
20+
trait Iterator {
21+
type Item;
22+
23+
fn next(&mut self) -> Option<Self::Item>;
24+
}
25+
26+
fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
27+
28+
struct Adapter<I> {
29+
iter: I,
30+
found_none: bool,
31+
}
32+
33+
impl<T, I> Iterator for Adapter<I> where I: Iterator<Item=Option<T>> {
34+
type Item = T;
35+
36+
fn next(&mut self) -> Option<T> {
37+
loop {}
38+
}
39+
}
40+
41+
fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
42+
is_iterator_of::<Option<T>, _>(&it); // Sanity check
43+
let adapter = Adapter { iter: it, found_none: false };
44+
is_iterator_of::<T, _>(&adapter); // OK
45+
is_iterator_of::<Option<T>, _>(&adapter); //~ ERROR type mismatch
46+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we are able to have an impl that defines an associated type
12+
// before the actual trait.
13+
14+
#![feature(associated_types)]
15+
impl X for f64 { type Y = int; }
16+
trait X {type Y; }
17+
fn main() {}

0 commit comments

Comments
 (0)