Skip to content

Commit 9d71bf6

Browse files
nikomatsakischrisvittal
authored andcommitted
add some more positive tests
It'd be good to have a positive test for each case where it is allowed, I should think.
1 parent 6f9fb91 commit 9d71bf6

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017 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+
#![feature(universal_impl_trait)]
12+
13+
fn hrtb(f: impl Fn(&u32) -> u32) -> u32 {
14+
f(&22) + f(&44)
15+
}
16+
17+
fn main() {
18+
let sum = hrtb(|x| x * 2);
19+
assert_eq!(sum, 22*2 + 44*2);
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017 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+
#![feature(universal_impl_trait)]
12+
13+
fn hrtb(f: impl for<'a> Fn(&'a u32) -> &'a u32) -> u32 {
14+
f(&22) + f(&44)
15+
}
16+
17+
fn main() {
18+
let sum = hrtb(|x| x);
19+
assert_eq!(sum, 22 + 44);
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2017 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+
#![feature(universal_impl_trait)]
12+
use std::fmt::Display;
13+
14+
fn check_display_eq(iter: &Vec<impl Display>) {
15+
let mut collected = String::new();
16+
for it in iter {
17+
let disp = format!("{} ", it);
18+
collected.push_str(&disp);
19+
}
20+
assert_eq!("0 3 27 823 4891 1 0", collected.trim());
21+
}
22+
23+
fn main() {
24+
let i32_list_vec = vec![0i32, 3, 27, 823, 4891, 1, 0];
25+
let u32_list_vec = vec![0u32, 3, 27, 823, 4891, 1, 0];
26+
let str_list_vec = vec!["0", "3", "27", "823", "4891", "1", "0"];
27+
28+
check_display_eq(&i32_list_vec);
29+
check_display_eq(&u32_list_vec);
30+
check_display_eq(&str_list_vec);
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 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+
#![feature(universal_impl_trait)]
12+
13+
use std::fmt::Debug;
14+
15+
trait InTraitDefnParameters {
16+
fn in_parameters(_: impl Debug) -> String;
17+
}
18+
19+
impl InTraitDefnParameters for () {
20+
fn in_parameters(v: impl Debug) -> String {
21+
format!("() + {:?}", v)
22+
}
23+
}
24+
25+
fn main() {
26+
let s = <() as InTraitDefnParameters>::in_parameters(22);
27+
assert_eq!(s, "() + 22");
28+
}

0 commit comments

Comments
 (0)