]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/auto-ref-slice-plus-ref.rs
auto merge of #19448 : japaric/rust/binops-by-value, r=nikomatsakis
[rust.git] / src / test / run-pass / auto-ref-slice-plus-ref.rs
1 // Copyright 2012 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 // Testing that method lookup automatically both borrows vectors to slices
12 // and also references them to create the &self pointer
13
14
15 trait MyIter {
16     fn test_imm(&self);
17 }
18
19 impl<'a> MyIter for &'a [int] {
20     fn test_imm(&self) { assert_eq!(self[0], 1) }
21 }
22
23 impl<'a> MyIter for &'a str {
24     fn test_imm(&self) { assert_eq!(*self, "test") }
25 }
26
27 pub fn main() {
28     ([1]).test_imm();
29     (vec!(1)).as_slice().test_imm();
30     (&[1]).test_imm();
31     ("test").test_imm();
32     ("test").test_imm();
33
34     // FIXME: Other types of mutable vecs don't currently exist
35
36     // NB: We don't do this double autoreffing for &mut self because that would
37     // allow creating a mutable pointer to a temporary, which would be a source
38     // of confusion
39 }