]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/option_if_let_else.stderr
New upstream version 1.59.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / option_if_let_else.stderr
1 error: use Option::map_or instead of an if let/else
2 --> $DIR/option_if_let_else.rs:6:5
3 |
4 LL | / if let Some(x) = string {
5 LL | | (true, x)
6 LL | | } else {
7 LL | | (false, "hello")
8 LL | | }
9 | |_____^ help: try: `string.map_or((false, "hello"), |x| (true, x))`
10 |
11 = note: `-D clippy::option-if-let-else` implied by `-D warnings`
12
13 error: use Option::map_or instead of an if let/else
14 --> $DIR/option_if_let_else.rs:24:13
15 |
16 LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
17 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
18
19 error: use Option::map_or instead of an if let/else
20 --> $DIR/option_if_let_else.rs:25:13
21 |
22 LL | let _ = if let Some(s) = &num { s } else { &0 };
23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
24
25 error: use Option::map_or instead of an if let/else
26 --> $DIR/option_if_let_else.rs:26:13
27 |
28 LL | let _ = if let Some(s) = &mut num {
29 | _____________^
30 LL | | *s += 1;
31 LL | | s
32 LL | | } else {
33 LL | | &mut 0
34 LL | | };
35 | |_____^
36 |
37 help: try
38 |
39 LL ~ let _ = num.as_mut().map_or(&mut 0, |s| {
40 LL + *s += 1;
41 LL + s
42 LL ~ });
43 |
44
45 error: use Option::map_or instead of an if let/else
46 --> $DIR/option_if_let_else.rs:32:13
47 |
48 LL | let _ = if let Some(ref s) = num { s } else { &0 };
49 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
50
51 error: use Option::map_or instead of an if let/else
52 --> $DIR/option_if_let_else.rs:33:13
53 |
54 LL | let _ = if let Some(mut s) = num {
55 | _____________^
56 LL | | s += 1;
57 LL | | s
58 LL | | } else {
59 LL | | 0
60 LL | | };
61 | |_____^
62 |
63 help: try
64 |
65 LL ~ let _ = num.map_or(0, |mut s| {
66 LL + s += 1;
67 LL + s
68 LL ~ });
69 |
70
71 error: use Option::map_or instead of an if let/else
72 --> $DIR/option_if_let_else.rs:39:13
73 |
74 LL | let _ = if let Some(ref mut s) = num {
75 | _____________^
76 LL | | *s += 1;
77 LL | | s
78 LL | | } else {
79 LL | | &mut 0
80 LL | | };
81 | |_____^
82 |
83 help: try
84 |
85 LL ~ let _ = num.as_mut().map_or(&mut 0, |s| {
86 LL + *s += 1;
87 LL + s
88 LL ~ });
89 |
90
91 error: use Option::map_or instead of an if let/else
92 --> $DIR/option_if_let_else.rs:48:5
93 |
94 LL | / if let Some(x) = arg {
95 LL | | let y = x * x;
96 LL | | y * y
97 LL | | } else {
98 LL | | 13
99 LL | | }
100 | |_____^
101 |
102 help: try
103 |
104 LL ~ arg.map_or(13, |x| {
105 LL + let y = x * x;
106 LL + y * y
107 LL + })
108 |
109
110 error: use Option::map_or_else instead of an if let/else
111 --> $DIR/option_if_let_else.rs:61:13
112 |
113 LL | let _ = if let Some(x) = arg {
114 | _____________^
115 LL | | x
116 LL | | } else {
117 LL | | // map_or_else must be suggested
118 LL | | side_effect()
119 LL | | };
120 | |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
121
122 error: use Option::map_or_else instead of an if let/else
123 --> $DIR/option_if_let_else.rs:70:13
124 |
125 LL | let _ = if let Some(x) = arg {
126 | _____________^
127 LL | | x * x * x * x
128 LL | | } else {
129 LL | | let mut y = 1;
130 ... |
131 LL | | y
132 LL | | };
133 | |_____^
134 |
135 help: try
136 |
137 LL ~ let _ = arg.map_or_else(|| {
138 LL + let mut y = 1;
139 LL + y = (y + 2 / y) / 2;
140 LL + y = (y + 2 / y) / 2;
141 LL + y
142 LL ~ }, |x| x * x * x * x);
143 |
144
145 error: use Option::map_or_else instead of an if let/else
146 --> $DIR/option_if_let_else.rs:103:13
147 |
148 LL | / if let Some(idx) = s.find('.') {
149 LL | | vec![s[..idx].to_string(), s[idx..].to_string()]
150 LL | | } else {
151 LL | | vec![s.to_string()]
152 LL | | }
153 | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])`
154
155 error: use Option::map_or instead of an if let/else
156 --> $DIR/option_if_let_else.rs:127:13
157 |
158 LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
159 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
160
161 error: use Option::map_or instead of an if let/else
162 --> $DIR/option_if_let_else.rs:136:13
163 |
164 LL | let _ = if let Some(x) = Some(0) {
165 | _____________^
166 LL | | loop {
167 LL | | if x == 0 {
168 LL | | break x;
169 ... |
170 LL | | 0
171 LL | | };
172 | |_____^
173 |
174 help: try
175 |
176 LL ~ let _ = Some(0).map_or(0, |x| loop {
177 LL + if x == 0 {
178 LL + break x;
179 LL + }
180 LL ~ });
181 |
182
183 error: use Option::map_or instead of an if let/else
184 --> $DIR/option_if_let_else.rs:164:13
185 |
186 LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
187 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
188
189 error: use Option::map_or instead of an if let/else
190 --> $DIR/option_if_let_else.rs:168:13
191 |
192 LL | let _ = if let Some(x) = Some(0) {
193 | _____________^
194 LL | | let s = s;
195 LL | | s.len() + x
196 LL | | } else {
197 LL | | 1
198 LL | | };
199 | |_____^
200 |
201 help: try
202 |
203 LL ~ let _ = Some(0).map_or(1, |x| {
204 LL + let s = s;
205 LL + s.len() + x
206 LL ~ });
207 |
208
209 error: aborting due to 15 previous errors
210