]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-21400.rs
Rollup merge of #91518 - luojia65:rustdoc-riscv-arch, r=GuillaumeGomez
[rust.git] / src / test / ui / issues / issue-21400.rs
1 // run-pass
2 // Regression test for #21400 which itself was extracted from
3 // stackoverflow.com/questions/28031155/is-my-borrow-checker-drunk/28031580
4
5 fn main() {
6     let mut t = Test;
7     assert_eq!(t.method1("one"), Ok(1));
8     assert_eq!(t.method2("two"), Ok(2));
9     assert_eq!(t.test(), Ok(2));
10 }
11
12 struct Test;
13
14 impl Test {
15     fn method1(&mut self, _arg: &str) -> Result<usize, &str> {
16         Ok(1)
17     }
18
19     fn method2(self: &mut Test, _arg: &str) -> Result<usize, &str> {
20         Ok(2)
21     }
22
23     fn test(self: &mut Test) -> Result<usize, &str> {
24         let s = format!("abcde");
25         // (Originally, this invocation of method2 was saying that `s`
26         // does not live long enough.)
27         let data = match self.method2(&*s) {
28             Ok(r) => r,
29             Err(e) => return Err(e)
30         };
31         Ok(data)
32     }
33 }
34
35 // Below is a closer match for the original test that was failing to compile
36
37 pub struct GitConnect;
38
39 impl GitConnect {
40     fn command(self: &mut GitConnect, _s: &str) -> Result<Vec<Vec<u8>>, &str> {
41         unimplemented!()
42     }
43
44     pub fn git_upload_pack(self: &mut GitConnect) -> Result<String, &str> {
45         let c = format!("git-upload-pack");
46
47         let mut out = String::new();
48         let data = self.command(&c)?;
49
50         for line in data.iter() {
51             out.push_str(&format!("{:?}", line));
52         }
53
54         Ok(out)
55     }
56 }