@@ -213,7 +213,9 @@ impl Struct {
213
213
// continue;
214
214
// }
215
215
let signature = delegee.signature(db);
216
- let delegate = generate_impl(ctx, self, &field.ty, &field.name, delegee);
216
+ let Some(delegate) = generate_impl(ctx, self, &field.ty, &field.name, delegee) else {
217
+ continue;
218
+ };
217
219
218
220
acc.add_group(
219
221
&GroupLabel("Delegate trait impl for field...".to_owned()),
@@ -237,7 +239,7 @@ fn generate_impl(
237
239
field_ty: &ast::Type,
238
240
field_name: &String,
239
241
delegee: &Delegee,
240
- ) -> ast::Impl {
242
+ ) -> Option< ast::Impl> {
241
243
let delegate: ast::Impl;
242
244
let source: ast::Impl;
243
245
let genpar: Option<ast::GenericParamList>;
@@ -247,7 +249,7 @@ fn generate_impl(
247
249
248
250
match delegee {
249
251
Delegee::Bound(delegee) => {
250
- let in_file = ctx.sema.source(delegee.0.to_owned()).unwrap() ;
252
+ let in_file = ctx.sema.source(delegee.0.to_owned())? ;
251
253
let source: ast::Trait = in_file.value;
252
254
253
255
delegate = make::impl_trait(
@@ -293,15 +295,15 @@ fn generate_impl(
293
295
None => {}
294
296
};
295
297
296
- let target = ctx.sema.scope(strukt.strukt.syntax()).unwrap() ;
297
- let source = ctx.sema.scope(source.syntax()).unwrap() ;
298
+ let target = ctx.sema.scope(strukt.strukt.syntax())? ;
299
+ let source = ctx.sema.scope(source.syntax())? ;
298
300
299
301
let transform =
300
302
PathTransform::trait_impl(&target, &source, delegee.0, delegate.clone());
301
303
transform.apply(&delegate.syntax());
302
304
}
303
305
Delegee::Impls(delegee) => {
304
- let in_file = ctx.sema.source(delegee.1.to_owned()).unwrap() ;
306
+ let in_file = ctx.sema.source(delegee.1.to_owned())? ;
305
307
source = in_file.value;
306
308
delegate = make::impl_trait(
307
309
delegee.0.is_unsafe(db),
@@ -341,16 +343,16 @@ fn generate_impl(
341
343
}
342
344
});
343
345
344
- let target = ctx.sema.scope(strukt.strukt.syntax()).unwrap() ;
345
- let source = ctx.sema.scope(source.syntax()).unwrap() ;
346
+ let target = ctx.sema.scope(strukt.strukt.syntax())? ;
347
+ let source = ctx.sema.scope(source.syntax())? ;
346
348
347
349
let transform =
348
350
PathTransform::trait_impl(&target, &source, delegee.0, delegate.clone());
349
351
transform.apply(&delegate.syntax());
350
352
}
351
353
}
352
354
353
- delegate
355
+ Some( delegate)
354
356
}
355
357
356
358
fn process_assoc_item(
@@ -359,19 +361,19 @@ fn process_assoc_item(
359
361
base_name: &str,
360
362
) -> Option<ast::AssocItem> {
361
363
match item {
362
- AssocItem::Const(c) => Some( const_assoc_item(c, qual_path_ty) ),
363
- AssocItem::Fn(f) => Some( func_assoc_item(f, qual_path_ty, base_name) ),
364
+ AssocItem::Const(c) => const_assoc_item(c, qual_path_ty),
365
+ AssocItem::Fn(f) => func_assoc_item(f, qual_path_ty, base_name),
364
366
AssocItem::MacroCall(_) => {
365
367
// FIXME : Handle MacroCall case.
366
- // return Some( macro_assoc_item(mac, qual_path_ty));
368
+ // macro_assoc_item(mac, qual_path_ty)
367
369
None
368
370
}
369
- AssocItem::TypeAlias(ta) => Some( ty_assoc_item(ta, qual_path_ty) ),
371
+ AssocItem::TypeAlias(ta) => ty_assoc_item(ta, qual_path_ty),
370
372
}
371
373
}
372
374
373
- fn const_assoc_item(item: syntax::ast::Const, qual_path_ty: ast::Path) -> AssocItem {
374
- let path_expr_segment = make::path_from_text(item.name().unwrap() .to_string().as_str());
375
+ fn const_assoc_item(item: syntax::ast::Const, qual_path_ty: ast::Path) -> Option< AssocItem> {
376
+ let path_expr_segment = make::path_from_text(item.name()? .to_string().as_str());
375
377
376
378
// We want rhs of the const assignment to be a qualified path
377
379
// The general case for const assigment can be found [here](`https://doc.rust-lang.org/reference/items/constant-items.html`)
@@ -380,19 +382,19 @@ fn const_assoc_item(item: syntax::ast::Const, qual_path_ty: ast::Path) -> AssocI
380
382
// FIXME : We can't rely on `make::path_qualified` for now but it would be nice to replace the following with it.
381
383
// make::path_qualified(qual_path_ty, path_expr_segment.as_single_segment().unwrap());
382
384
let qualpath = qualpath(qual_path_ty, path_expr_segment);
383
- let inner = make::item_const(
384
- item.visibility(),
385
- item.name().unwrap(),
386
- item.ty().unwrap(),
387
- make::expr_path(qualpath),
388
- )
389
- .clone_for_update();
385
+ let inner =
386
+ make::item_const(item.visibility(), item.name()?, item.ty()?, make::expr_path(qualpath))
387
+ .clone_for_update();
390
388
391
- AssocItem::Const(inner)
389
+ Some( AssocItem::Const(inner) )
392
390
}
393
391
394
- fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -> AssocItem {
395
- let path_expr_segment = make::path_from_text(item.name().unwrap().to_string().as_str());
392
+ fn func_assoc_item(
393
+ item: syntax::ast::Fn,
394
+ qual_path_ty: Path,
395
+ base_name: &str,
396
+ ) -> Option<AssocItem> {
397
+ let path_expr_segment = make::path_from_text(item.name()?.to_string().as_str());
396
398
let qualpath = qualpath(qual_path_ty, path_expr_segment);
397
399
398
400
let call = match item.param_list() {
@@ -415,7 +417,7 @@ fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -
415
417
if param_count > 0 {
416
418
// Add SelfParam and a TOKEN::COMMA
417
419
ted::insert_all(
418
- Position::after(args.l_paren_token().unwrap() ),
420
+ Position::after(args.l_paren_token()? ),
419
421
vec![
420
422
NodeOrToken::Node(tail_expr_self.syntax().clone_for_update()),
421
423
NodeOrToken::Token(make::token(SyntaxKind::WHITESPACE)),
@@ -425,7 +427,7 @@ fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -
425
427
} else {
426
428
// Add SelfParam only
427
429
ted::insert(
428
- Position::after(args.l_paren_token().unwrap() ),
430
+ Position::after(args.l_paren_token()? ),
429
431
NodeOrToken::Node(tail_expr_self.syntax().clone_for_update()),
430
432
);
431
433
}
@@ -444,10 +446,10 @@ fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -
444
446
let body = make::block_expr(vec![], Some(call)).clone_for_update();
445
447
let func = make::fn_(
446
448
item.visibility(),
447
- item.name().unwrap() ,
449
+ item.name()? ,
448
450
item.generic_param_list(),
449
451
item.where_clause(),
450
- item.param_list().unwrap() ,
452
+ item.param_list()? ,
451
453
body,
452
454
item.ret_type(),
453
455
item.async_token().is_some(),
@@ -456,14 +458,14 @@ fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -
456
458
)
457
459
.clone_for_update();
458
460
459
- AssocItem::Fn(func.indent(edit::IndentLevel(1)).clone_for_update())
461
+ Some( AssocItem::Fn(func.indent(edit::IndentLevel(1)).clone_for_update() ))
460
462
}
461
463
462
- fn ty_assoc_item(item: syntax::ast::TypeAlias, qual_path_ty: Path) -> AssocItem {
463
- let path_expr_segment = make::path_from_text(item.name().unwrap() .to_string().as_str());
464
+ fn ty_assoc_item(item: syntax::ast::TypeAlias, qual_path_ty: Path) -> Option< AssocItem> {
465
+ let path_expr_segment = make::path_from_text(item.name()? .to_string().as_str());
464
466
let qualpath = qualpath(qual_path_ty, path_expr_segment);
465
467
let ty = make::ty_path(qualpath);
466
- let ident = item.name().unwrap() .to_string();
468
+ let ident = item.name()? .to_string();
467
469
468
470
let alias = make::ty_alias(
469
471
ident.as_str(),
@@ -474,7 +476,7 @@ fn ty_assoc_item(item: syntax::ast::TypeAlias, qual_path_ty: Path) -> AssocItem
474
476
)
475
477
.clone_for_update();
476
478
477
- AssocItem::TypeAlias(alias)
479
+ Some( AssocItem::TypeAlias(alias) )
478
480
}
479
481
480
482
fn qualpath(qual_path_ty: ast::Path, path_expr_seg: ast::Path) -> ast::Path {
0 commit comments