]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-14919.rs
Auto merge of #79113 - andjo403:raw_vec_ptr, r=m-ou-se
[rust.git] / src / test / ui / issues / issue-14919.rs
1 // run-pass
2 #![allow(unused_must_use)]
3 #![allow(dead_code)]
4 // pretty-expanded FIXME #23616
5
6 trait Matcher {
7     fn next_match(&mut self) -> Option<(usize, usize)>;
8 }
9
10 struct CharPredMatcher<'a, 'b> {
11     str: &'a str,
12     pred: Box<dyn FnMut(char) -> bool + 'b>,
13 }
14
15 impl<'a, 'b> Matcher for CharPredMatcher<'a, 'b> {
16     fn next_match(&mut self) -> Option<(usize, usize)> {
17         None
18     }
19 }
20
21 trait IntoMatcher<'a, T> {
22     fn into_matcher(self, _: &'a str) -> T;
23 }
24
25 impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b {
26     fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
27         CharPredMatcher {
28             str: s,
29             pred: Box::new(self),
30         }
31     }
32 }
33
34 struct MatchIndices<M> {
35     matcher: M
36 }
37
38 impl<M: Matcher> Iterator for MatchIndices<M> {
39     type Item = (usize, usize);
40
41     fn next(&mut self) -> Option<(usize, usize)> {
42         self.matcher.next_match()
43     }
44 }
45
46 fn match_indices<'a, M, T: IntoMatcher<'a, M>>(s: &'a str, from: T) -> MatchIndices<M> {
47     let string_matcher = from.into_matcher(s);
48     MatchIndices { matcher: string_matcher }
49 }
50
51 fn main() {
52     let s = "abcbdef";
53     match_indices(s, |c: char| c == 'b')
54         .collect::<Vec<_>>();
55 }