diff options
author | Aleksey Kladov <[email protected]> | 2021-06-18 21:28:37 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-18 21:28:37 +0100 |
commit | 181184a350046a460441209fd34821c2c796b066 (patch) | |
tree | 14e572eacf0feffd45250156c373d0148b78ee93 /crates/ide_assists | |
parent | 89a0e58393de0ae39fc1f33a33cec87bc084a9f1 (diff) |
minor: use minicore
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/replace_if_let_with_match.rs | 66 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/replace_unwrap_with_match.rs | 53 |
2 files changed, 43 insertions, 76 deletions
diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs index 9404aa26d..f37aa0d53 100644 --- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs | |||
@@ -262,9 +262,7 @@ impl VariantData { | |||
262 | check_assist( | 262 | check_assist( |
263 | replace_if_let_with_match, | 263 | replace_if_let_with_match, |
264 | r#" | 264 | r#" |
265 | enum Option<T> { Some(T), None } | 265 | //- minicore: option |
266 | use Option::*; | ||
267 | |||
268 | fn foo(x: Option<i32>) { | 266 | fn foo(x: Option<i32>) { |
269 | $0if let Some(x) = x { | 267 | $0if let Some(x) = x { |
270 | println!("{}", x) | 268 | println!("{}", x) |
@@ -272,18 +270,15 @@ fn foo(x: Option<i32>) { | |||
272 | println!("none") | 270 | println!("none") |
273 | } | 271 | } |
274 | } | 272 | } |
275 | "#, | 273 | "#, |
276 | r#" | 274 | r#" |
277 | enum Option<T> { Some(T), None } | ||
278 | use Option::*; | ||
279 | |||
280 | fn foo(x: Option<i32>) { | 275 | fn foo(x: Option<i32>) { |
281 | match x { | 276 | match x { |
282 | Some(x) => println!("{}", x), | 277 | Some(x) => println!("{}", x), |
283 | None => println!("none"), | 278 | None => println!("none"), |
284 | } | 279 | } |
285 | } | 280 | } |
286 | "#, | 281 | "#, |
287 | ); | 282 | ); |
288 | } | 283 | } |
289 | 284 | ||
@@ -292,9 +287,7 @@ fn foo(x: Option<i32>) { | |||
292 | check_assist( | 287 | check_assist( |
293 | replace_if_let_with_match, | 288 | replace_if_let_with_match, |
294 | r#" | 289 | r#" |
295 | enum Option<T> { Some(T), None } | 290 | //- minicore: option |
296 | use Option::*; | ||
297 | |||
298 | fn foo(x: Option<i32>) { | 291 | fn foo(x: Option<i32>) { |
299 | $0if let None = x { | 292 | $0if let None = x { |
300 | println!("none") | 293 | println!("none") |
@@ -302,18 +295,15 @@ fn foo(x: Option<i32>) { | |||
302 | println!("some") | 295 | println!("some") |
303 | } | 296 | } |
304 | } | 297 | } |
305 | "#, | 298 | "#, |
306 | r#" | 299 | r#" |
307 | enum Option<T> { Some(T), None } | ||
308 | use Option::*; | ||
309 | |||
310 | fn foo(x: Option<i32>) { | 300 | fn foo(x: Option<i32>) { |
311 | match x { | 301 | match x { |
312 | None => println!("none"), | 302 | None => println!("none"), |
313 | Some(_) => println!("some"), | 303 | Some(_) => println!("some"), |
314 | } | 304 | } |
315 | } | 305 | } |
316 | "#, | 306 | "#, |
317 | ); | 307 | ); |
318 | } | 308 | } |
319 | 309 | ||
@@ -322,9 +312,7 @@ fn foo(x: Option<i32>) { | |||
322 | check_assist( | 312 | check_assist( |
323 | replace_if_let_with_match, | 313 | replace_if_let_with_match, |
324 | r#" | 314 | r#" |
325 | enum Result<T, E> { Ok(T), Err(E) } | 315 | //- minicore: result |
326 | use Result::*; | ||
327 | |||
328 | fn foo(x: Result<i32, ()>) { | 316 | fn foo(x: Result<i32, ()>) { |
329 | $0if let Ok(x) = x { | 317 | $0if let Ok(x) = x { |
330 | println!("{}", x) | 318 | println!("{}", x) |
@@ -332,18 +320,15 @@ fn foo(x: Result<i32, ()>) { | |||
332 | println!("none") | 320 | println!("none") |
333 | } | 321 | } |
334 | } | 322 | } |
335 | "#, | 323 | "#, |
336 | r#" | 324 | r#" |
337 | enum Result<T, E> { Ok(T), Err(E) } | ||
338 | use Result::*; | ||
339 | |||
340 | fn foo(x: Result<i32, ()>) { | 325 | fn foo(x: Result<i32, ()>) { |
341 | match x { | 326 | match x { |
342 | Ok(x) => println!("{}", x), | 327 | Ok(x) => println!("{}", x), |
343 | Err(_) => println!("none"), | 328 | Err(_) => println!("none"), |
344 | } | 329 | } |
345 | } | 330 | } |
346 | "#, | 331 | "#, |
347 | ); | 332 | ); |
348 | } | 333 | } |
349 | 334 | ||
@@ -352,9 +337,7 @@ fn foo(x: Result<i32, ()>) { | |||
352 | check_assist( | 337 | check_assist( |
353 | replace_if_let_with_match, | 338 | replace_if_let_with_match, |
354 | r#" | 339 | r#" |
355 | enum Result<T, E> { Ok(T), Err(E) } | 340 | //- minicore: result |
356 | use Result::*; | ||
357 | |||
358 | fn foo(x: Result<i32, ()>) { | 341 | fn foo(x: Result<i32, ()>) { |
359 | $0if let Err(x) = x { | 342 | $0if let Err(x) = x { |
360 | println!("{}", x) | 343 | println!("{}", x) |
@@ -362,18 +345,15 @@ fn foo(x: Result<i32, ()>) { | |||
362 | println!("ok") | 345 | println!("ok") |
363 | } | 346 | } |
364 | } | 347 | } |
365 | "#, | 348 | "#, |
366 | r#" | 349 | r#" |
367 | enum Result<T, E> { Ok(T), Err(E) } | ||
368 | use Result::*; | ||
369 | |||
370 | fn foo(x: Result<i32, ()>) { | 350 | fn foo(x: Result<i32, ()>) { |
371 | match x { | 351 | match x { |
372 | Err(x) => println!("{}", x), | 352 | Err(x) => println!("{}", x), |
373 | Ok(_) => println!("ok"), | 353 | Ok(_) => println!("ok"), |
374 | } | 354 | } |
375 | } | 355 | } |
376 | "#, | 356 | "#, |
377 | ); | 357 | ); |
378 | } | 358 | } |
379 | 359 | ||
@@ -488,20 +468,15 @@ impl VariantData { | |||
488 | check_assist( | 468 | check_assist( |
489 | replace_match_with_if_let, | 469 | replace_match_with_if_let, |
490 | r#" | 470 | r#" |
491 | enum Option<T> { Some(T), None } | 471 | //- minicore: option |
492 | use Option::*; | ||
493 | |||
494 | fn foo(x: Option<i32>) { | 472 | fn foo(x: Option<i32>) { |
495 | $0match x { | 473 | $0match x { |
496 | Some(x) => println!("{}", x), | 474 | Some(x) => println!("{}", x), |
497 | None => println!("none"), | 475 | None => println!("none"), |
498 | } | 476 | } |
499 | } | 477 | } |
500 | "#, | 478 | "#, |
501 | r#" | 479 | r#" |
502 | enum Option<T> { Some(T), None } | ||
503 | use Option::*; | ||
504 | |||
505 | fn foo(x: Option<i32>) { | 480 | fn foo(x: Option<i32>) { |
506 | if let Some(x) = x { | 481 | if let Some(x) = x { |
507 | println!("{}", x) | 482 | println!("{}", x) |
@@ -509,7 +484,7 @@ fn foo(x: Option<i32>) { | |||
509 | println!("none") | 484 | println!("none") |
510 | } | 485 | } |
511 | } | 486 | } |
512 | "#, | 487 | "#, |
513 | ); | 488 | ); |
514 | } | 489 | } |
515 | 490 | ||
@@ -518,20 +493,15 @@ fn foo(x: Option<i32>) { | |||
518 | check_assist( | 493 | check_assist( |
519 | replace_match_with_if_let, | 494 | replace_match_with_if_let, |
520 | r#" | 495 | r#" |
521 | enum Result<T, E> { Ok(T), Err(E) } | 496 | //- minicore: result |
522 | use Result::*; | ||
523 | |||
524 | fn foo(x: Result<i32, ()>) { | 497 | fn foo(x: Result<i32, ()>) { |
525 | $0match x { | 498 | $0match x { |
526 | Ok(x) => println!("{}", x), | 499 | Ok(x) => println!("{}", x), |
527 | Err(_) => println!("none"), | 500 | Err(_) => println!("none"), |
528 | } | 501 | } |
529 | } | 502 | } |
530 | "#, | 503 | "#, |
531 | r#" | 504 | r#" |
532 | enum Result<T, E> { Ok(T), Err(E) } | ||
533 | use Result::*; | ||
534 | |||
535 | fn foo(x: Result<i32, ()>) { | 505 | fn foo(x: Result<i32, ()>) { |
536 | if let Ok(x) = x { | 506 | if let Ok(x) = x { |
537 | println!("{}", x) | 507 | println!("{}", x) |
@@ -539,7 +509,7 @@ fn foo(x: Result<i32, ()>) { | |||
539 | println!("none") | 509 | println!("none") |
540 | } | 510 | } |
541 | } | 511 | } |
542 | "#, | 512 | "#, |
543 | ); | 513 | ); |
544 | } | 514 | } |
545 | 515 | ||
diff --git a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs index a3bfa221c..7e57353c6 100644 --- a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs | |||
@@ -97,25 +97,24 @@ mod tests { | |||
97 | fn test_replace_result_unwrap_with_match() { | 97 | fn test_replace_result_unwrap_with_match() { |
98 | check_assist( | 98 | check_assist( |
99 | replace_unwrap_with_match, | 99 | replace_unwrap_with_match, |
100 | r" | 100 | r#" |
101 | enum Result<T, E> { Ok(T), Err(E) } | 101 | //- minicore: result |
102 | fn i<T>(a: T) -> T { a } | 102 | fn i<T>(a: T) -> T { a } |
103 | fn main() { | 103 | fn main() { |
104 | let x: Result<i32, i32> = Result::Ok(92); | 104 | let x: Result<i32, i32> = Ok(92); |
105 | let y = i(x).$0unwrap(); | 105 | let y = i(x).$0unwrap(); |
106 | } | 106 | } |
107 | ", | 107 | "#, |
108 | r" | 108 | r#" |
109 | enum Result<T, E> { Ok(T), Err(E) } | ||
110 | fn i<T>(a: T) -> T { a } | 109 | fn i<T>(a: T) -> T { a } |
111 | fn main() { | 110 | fn main() { |
112 | let x: Result<i32, i32> = Result::Ok(92); | 111 | let x: Result<i32, i32> = Ok(92); |
113 | let y = match i(x) { | 112 | let y = match i(x) { |
114 | Ok(it) => it, | 113 | Ok(it) => it, |
115 | $0_ => unreachable!(), | 114 | $0_ => unreachable!(), |
116 | }; | 115 | }; |
117 | } | 116 | } |
118 | ", | 117 | "#, |
119 | ) | 118 | ) |
120 | } | 119 | } |
121 | 120 | ||
@@ -123,25 +122,24 @@ fn main() { | |||
123 | fn test_replace_option_unwrap_with_match() { | 122 | fn test_replace_option_unwrap_with_match() { |
124 | check_assist( | 123 | check_assist( |
125 | replace_unwrap_with_match, | 124 | replace_unwrap_with_match, |
126 | r" | 125 | r#" |
127 | enum Option<T> { Some(T), None } | 126 | //- minicore: option |
128 | fn i<T>(a: T) -> T { a } | 127 | fn i<T>(a: T) -> T { a } |
129 | fn main() { | 128 | fn main() { |
130 | let x = Option::Some(92); | 129 | let x = Some(92); |
131 | let y = i(x).$0unwrap(); | 130 | let y = i(x).$0unwrap(); |
132 | } | 131 | } |
133 | ", | 132 | "#, |
134 | r" | 133 | r#" |
135 | enum Option<T> { Some(T), None } | ||
136 | fn i<T>(a: T) -> T { a } | 134 | fn i<T>(a: T) -> T { a } |
137 | fn main() { | 135 | fn main() { |
138 | let x = Option::Some(92); | 136 | let x = Some(92); |
139 | let y = match i(x) { | 137 | let y = match i(x) { |
140 | Some(it) => it, | 138 | Some(it) => it, |
141 | $0_ => unreachable!(), | 139 | $0_ => unreachable!(), |
142 | }; | 140 | }; |
143 | } | 141 | } |
144 | ", | 142 | "#, |
145 | ); | 143 | ); |
146 | } | 144 | } |
147 | 145 | ||
@@ -149,25 +147,24 @@ fn main() { | |||
149 | fn test_replace_result_unwrap_with_match_chaining() { | 147 | fn test_replace_result_unwrap_with_match_chaining() { |
150 | check_assist( | 148 | check_assist( |
151 | replace_unwrap_with_match, | 149 | replace_unwrap_with_match, |
152 | r" | 150 | r#" |
153 | enum Result<T, E> { Ok(T), Err(E) } | 151 | //- minicore: result |
154 | fn i<T>(a: T) -> T { a } | 152 | fn i<T>(a: T) -> T { a } |
155 | fn main() { | 153 | fn main() { |
156 | let x: Result<i32, i32> = Result::Ok(92); | 154 | let x: Result<i32, i32> = Ok(92); |
157 | let y = i(x).$0unwrap().count_zeroes(); | 155 | let y = i(x).$0unwrap().count_zeroes(); |
158 | } | 156 | } |
159 | ", | 157 | "#, |
160 | r" | 158 | r#" |
161 | enum Result<T, E> { Ok(T), Err(E) } | ||
162 | fn i<T>(a: T) -> T { a } | 159 | fn i<T>(a: T) -> T { a } |
163 | fn main() { | 160 | fn main() { |
164 | let x: Result<i32, i32> = Result::Ok(92); | 161 | let x: Result<i32, i32> = Ok(92); |
165 | let y = match i(x) { | 162 | let y = match i(x) { |
166 | Ok(it) => it, | 163 | Ok(it) => it, |
167 | $0_ => unreachable!(), | 164 | $0_ => unreachable!(), |
168 | }.count_zeroes(); | 165 | }.count_zeroes(); |
169 | } | 166 | } |
170 | ", | 167 | "#, |
171 | ) | 168 | ) |
172 | } | 169 | } |
173 | 170 | ||
@@ -175,14 +172,14 @@ fn main() { | |||
175 | fn replace_unwrap_with_match_target() { | 172 | fn replace_unwrap_with_match_target() { |
176 | check_assist_target( | 173 | check_assist_target( |
177 | replace_unwrap_with_match, | 174 | replace_unwrap_with_match, |
178 | r" | 175 | r#" |
179 | enum Option<T> { Some(T), None } | 176 | //- minicore: option |
180 | fn i<T>(a: T) -> T { a } | 177 | fn i<T>(a: T) -> T { a } |
181 | fn main() { | 178 | fn main() { |
182 | let x = Option::Some(92); | 179 | let x = Some(92); |
183 | let y = i(x).$0unwrap(); | 180 | let y = i(x).$0unwrap(); |
184 | } | 181 | } |
185 | ", | 182 | "#, |
186 | r"i(x).unwrap()", | 183 | r"i(x).unwrap()", |
187 | ); | 184 | ); |
188 | } | 185 | } |