]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / compile-fail / lifetime-inference-give-expl-lifetime-param-2.rs
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 // ignore-tidy-linelength
12
13 use std::ops::Range;
14
15 trait Itble<'r, T, I: Iterator<Item=T>> { fn iter(&'r self) -> I; }
16
17 impl<'r> Itble<'r, usize, Range<usize>> for (usize, usize) {
18 fn iter(&'r self) -> Range<usize> {
19 let &(min, max) = self;
20 min..max
21 }
22 }
23
24 fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool {
25 //~^ HELP: consider using an explicit lifetime parameter as shown: fn check<'r, I: Iterator<Item = usize>, T: Itble<'r, usize, I>>(cont: &'r T)
26 let cont_iter = cont.iter(); //~ ERROR: cannot infer
27 let result = cont_iter.fold(Some(0), |state, val| {
28 state.map_or(None, |mask| {
29 let bit = 1 << val;
30 if mask & bit == 0 {Some(mask|bit)} else {None}
31 })
32 });
33 result.is_some()
34 }
35
36 fn main() {}