]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/move-errors.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / nll / move-errors.rs
1 // Copyright 2018 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 #![allow(unused)]
12 #![feature(nll)]
13
14 struct A(String);
15 struct C(D);
16
17 fn suggest_remove_deref() {
18     let a = &A("".to_string());
19     let b = *a;
20     //~^ ERROR
21 }
22
23 fn suggest_borrow() {
24     let a = [A("".to_string())];
25     let b = a[0];
26     //~^ ERROR
27 }
28
29 fn suggest_borrow2() {
30     let mut a = A("".to_string());
31     let r = &&mut a;
32     let s = **r;
33     //~^ ERROR
34 }
35
36 fn suggest_borrow3() {
37     use std::rc::Rc;
38     let mut a = A("".to_string());
39     let r = Rc::new(a);
40     let s = *r;
41     //~^ ERROR
42 }
43
44 fn suggest_borrow4() {
45     let a = [A("".to_string())][0];
46     //~^ ERROR
47 }
48
49 fn suggest_borrow5() {
50     let a = &A("".to_string());
51     let A(s) = *a;
52     //~^ ERROR
53 }
54
55 fn suggest_ref() {
56     let c = C(D(String::new()));
57     let C(D(s)) = c;
58     //~^ ERROR
59 }
60
61 fn suggest_nothing() {
62     let a = &A("".to_string());
63     let b;
64     b = *a;
65     //~^ ERROR
66 }
67
68 enum B {
69     V(String),
70     U(D),
71 }
72
73 struct D(String);
74
75 impl Drop for D {
76     fn drop(&mut self) {}
77 }
78
79 struct F(String, String);
80
81 impl Drop for F {
82     fn drop(&mut self) {}
83 }
84
85 fn probably_suggest_borrow() {
86     let x = [B::V(String::new())];
87     match x[0] {
88     //~^ ERROR
89         B::U(d) => (),
90         B::V(s) => (),
91     }
92 }
93
94 fn have_to_suggest_ref() {
95     let x = B::V(String::new());
96     match x {
97     //~^ ERROR
98         B::V(s) => drop(s),
99         B::U(D(s)) => (),
100     };
101 }
102
103 fn two_separate_errors() {
104     let x = (D(String::new()), &String::new());
105     match x {
106     //~^ ERROR
107     //~^^ ERROR
108         (D(s), &t) => (),
109         _ => (),
110     }
111 }
112
113 fn have_to_suggest_double_ref() {
114     let x = F(String::new(), String::new());
115     match x {
116     //~^ ERROR
117         F(s, mut t) => (),
118         _ => (),
119     }
120 }
121
122 fn double_binding(x: &Result<String, String>) {
123     match *x {
124     //~^ ERROR
125         Ok(s) | Err(s) => (),
126     }
127 }
128
129 fn main() {
130 }