]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-21400.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / run-pass / issue-21400.rs
1 // Copyright 2015 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 // Regression test for #21400 which itself was extracted from
12 // stackoverflow.com/questions/28031155/is-my-borrow-checker-drunk/28031580
13
14 #![feature(question_mark)]
15
16 fn main() {
17 let mut t = Test;
18 assert_eq!(t.method1("one"), Ok(1));
19 assert_eq!(t.method2("two"), Ok(2));
20 assert_eq!(t.test(), Ok(2));
21 }
22
23 struct Test;
24
25 impl Test {
26 fn method1(&mut self, _arg: &str) -> Result<usize, &str> {
27 Ok(1)
28 }
29
30 fn method2(self: &mut Test, _arg: &str) -> Result<usize, &str> {
31 Ok(2)
32 }
33
34 fn test(self: &mut Test) -> Result<usize, &str> {
35 let s = format!("abcde");
36 // (Originally, this invocation of method2 was saying that `s`
37 // does not live long enough.)
38 let data = match self.method2(&*s) {
39 Ok(r) => r,
40 Err(e) => return Err(e)
41 };
42 Ok(data)
43 }
44 }
45
46 // Below is a closer match for the original test that was failing to compile
47
48 pub struct GitConnect;
49
50 impl GitConnect {
51 fn command(self: &mut GitConnect, _s: &str) -> Result<Vec<Vec<u8>>, &str> {
52 unimplemented!()
53 }
54
55 pub fn git_upload_pack(self: &mut GitConnect) -> Result<String, &str> {
56 let c = format!("git-upload-pack");
57
58 let mut out = String::new();
59 let data = self.command(&c)?;
60
61 for line in data.iter() {
62 out.push_str(&format!("{:?}", line));
63 }
64
65 Ok(out)
66 }
67 }
68