aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r--crates/ide_assists/src/handlers/fill_match_arms.rs11
-rw-r--r--crates/ide_assists/src/handlers/replace_if_let_with_match.rs66
-rw-r--r--crates/ide_assists/src/handlers/replace_unwrap_with_match.rs53
3 files changed, 46 insertions, 84 deletions
diff --git a/crates/ide_assists/src/handlers/fill_match_arms.rs b/crates/ide_assists/src/handlers/fill_match_arms.rs
index cd0f6dba9..318faa0fc 100644
--- a/crates/ide_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ide_assists/src/handlers/fill_match_arms.rs
@@ -481,26 +481,21 @@ fn main() {
481 check_assist( 481 check_assist(
482 fill_match_arms, 482 fill_match_arms,
483 r#" 483 r#"
484enum Option<T> { Some(T), None } 484//- minicore: option
485use Option::*;
486
487fn main() { 485fn main() {
488 match None$0 { 486 match None$0 {
489 None => {} 487 None => {}
490 } 488 }
491} 489}
492 "#, 490"#,
493 r#" 491 r#"
494enum Option<T> { Some(T), None }
495use Option::*;
496
497fn main() { 492fn main() {
498 match None { 493 match None {
499 None => {} 494 None => {}
500 Some(${0:_}) => todo!(), 495 Some(${0:_}) => todo!(),
501 } 496 }
502} 497}
503 "#, 498"#,
504 ); 499 );
505 } 500 }
506 501
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#"
265enum Option<T> { Some(T), None } 265//- minicore: option
266use Option::*;
267
268fn foo(x: Option<i32>) { 266fn 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#"
277enum Option<T> { Some(T), None }
278use Option::*;
279
280fn foo(x: Option<i32>) { 275fn 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#"
295enum Option<T> { Some(T), None } 290//- minicore: option
296use Option::*;
297
298fn foo(x: Option<i32>) { 291fn 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#"
307enum Option<T> { Some(T), None }
308use Option::*;
309
310fn foo(x: Option<i32>) { 300fn 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#"
325enum Result<T, E> { Ok(T), Err(E) } 315//- minicore: result
326use Result::*;
327
328fn foo(x: Result<i32, ()>) { 316fn 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#"
337enum Result<T, E> { Ok(T), Err(E) }
338use Result::*;
339
340fn foo(x: Result<i32, ()>) { 325fn 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#"
355enum Result<T, E> { Ok(T), Err(E) } 340//- minicore: result
356use Result::*;
357
358fn foo(x: Result<i32, ()>) { 341fn 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#"
367enum Result<T, E> { Ok(T), Err(E) }
368use Result::*;
369
370fn foo(x: Result<i32, ()>) { 350fn 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#"
491enum Option<T> { Some(T), None } 471//- minicore: option
492use Option::*;
493
494fn foo(x: Option<i32>) { 472fn 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#"
502enum Option<T> { Some(T), None }
503use Option::*;
504
505fn foo(x: Option<i32>) { 480fn 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#"
521enum Result<T, E> { Ok(T), Err(E) } 496//- minicore: result
522use Result::*;
523
524fn foo(x: Result<i32, ()>) { 497fn 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#"
532enum Result<T, E> { Ok(T), Err(E) }
533use Result::*;
534
535fn foo(x: Result<i32, ()>) { 505fn 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#"
101enum Result<T, E> { Ok(T), Err(E) } 101//- minicore: result
102fn i<T>(a: T) -> T { a } 102fn i<T>(a: T) -> T { a }
103fn main() { 103fn 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#"
109enum Result<T, E> { Ok(T), Err(E) }
110fn i<T>(a: T) -> T { a } 109fn i<T>(a: T) -> T { a }
111fn main() { 110fn 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#"
127enum Option<T> { Some(T), None } 126//- minicore: option
128fn i<T>(a: T) -> T { a } 127fn i<T>(a: T) -> T { a }
129fn main() { 128fn 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#"
135enum Option<T> { Some(T), None }
136fn i<T>(a: T) -> T { a } 134fn i<T>(a: T) -> T { a }
137fn main() { 135fn 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#"
153enum Result<T, E> { Ok(T), Err(E) } 151//- minicore: result
154fn i<T>(a: T) -> T { a } 152fn i<T>(a: T) -> T { a }
155fn main() { 153fn 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#"
161enum Result<T, E> { Ok(T), Err(E) }
162fn i<T>(a: T) -> T { a } 159fn i<T>(a: T) -> T { a }
163fn main() { 160fn 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#"
179enum Option<T> { Some(T), None } 176//- minicore: option
180fn i<T>(a: T) -> T { a } 177fn i<T>(a: T) -> T { a }
181fn main() { 178fn 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 }