summaryrefslogtreecommitdiffstats
path: root/src/test/ui/array-slice-vec/rcvr-borrowed-to-slice.rs
blob: 17cf7e335b9a96b68a017231240dc1cc1f7345b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// run-pass

#![allow(non_camel_case_types)]

trait sum {
    fn sum_(self) -> isize;
}

// Note: impl on a slice
impl<'a> sum for &'a [isize] {
    fn sum_(self) -> isize {
        self.iter().fold(0, |a, &b| a + b)
    }
}

fn call_sum(x: &[isize]) -> isize { x.sum_() }

pub fn main() {
    let x = vec![1, 2, 3];
    let y = call_sum(&x);
    println!("y=={}", y);
    assert_eq!(y, 6);

    let x = vec![1, 2, 3];
    let y = x.sum_();
    println!("y=={}", y);
    assert_eq!(y, 6);

    let x = vec![1, 2, 3];
    let y = x.sum_();
    println!("y=={}", y);
    assert_eq!(y, 6);
}