]> git.proxmox.com Git - rustc.git/blame - src/test/ui/traits/to-str.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / traits / to-str.rs
CommitLineData
b7449926
XL
1// run-pass
2#![allow(non_camel_case_types)]
223e47cc 3
223e47cc
LB
4
5trait to_str {
1a4d82fc 6 fn to_string_(&self) -> String;
223e47cc
LB
7}
8
c34b1796 9impl to_str for isize {
1a4d82fc 10 fn to_string_(&self) -> String { self.to_string() }
223e47cc
LB
11}
12
1a4d82fc
JJ
13impl<T:to_str> to_str for Vec<T> {
14 fn to_string_(&self) -> String {
15 format!("[{}]",
16 self.iter()
17 .map(|e| e.to_string_())
18 .collect::<Vec<String>>()
c1a9b12d 19 .join(", "))
223e47cc
LB
20 }
21}
22
23pub fn main() {
62682a34 24 assert_eq!(1.to_string_(), "1".to_string());
c30ab7b3 25 assert_eq!((vec![2, 3, 4]).to_string_(), "[2, 3, 4]".to_string());
223e47cc 26
1a4d82fc
JJ
27 fn indirect<T:to_str>(x: T) -> String {
28 format!("{}!", x.to_string_())
223e47cc 29 }
c30ab7b3 30 assert_eq!(indirect(vec![10, 20]), "[10, 20]!".to_string());
223e47cc 31
1a4d82fc 32 fn indirect2<T:to_str>(x: T) -> String {
223e47cc
LB
33 indirect(x)
34 }
c30ab7b3 35 assert_eq!(indirect2(vec![1]), "[1]!".to_string());
223e47cc 36}