@@ -213,7 +213,9 @@ impl Struct {
213213 // continue;
214214 // }
215215 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+ } ;
217219
218220 acc. add_group (
219221 & GroupLabel ( "Delegate trait impl for field..." . to_owned ( ) ) ,
@@ -237,7 +239,7 @@ fn generate_impl(
237239 field_ty : & ast:: Type ,
238240 field_name : & String ,
239241 delegee : & Delegee ,
240- ) -> ast:: Impl {
242+ ) -> Option < ast:: Impl > {
241243 let delegate: ast:: Impl ;
242244 let source: ast:: Impl ;
243245 let genpar: Option < ast:: GenericParamList > ;
@@ -247,7 +249,7 @@ fn generate_impl(
247249
248250 match delegee {
249251 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 ( ) ) ? ;
251253 let source: ast:: Trait = in_file. value ;
252254
253255 delegate = make:: impl_trait (
@@ -293,15 +295,15 @@ fn generate_impl(
293295 None => { }
294296 } ;
295297
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 ( ) ) ? ;
298300
299301 let transform =
300302 PathTransform :: trait_impl ( & target, & source, delegee. 0 , delegate. clone ( ) ) ;
301303 transform. apply ( & delegate. syntax ( ) ) ;
302304 }
303305 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 ( ) ) ? ;
305307 source = in_file. value ;
306308 delegate = make:: impl_trait (
307309 delegee. 0 . is_unsafe ( db) ,
@@ -341,16 +343,16 @@ fn generate_impl(
341343 }
342344 } ) ;
343345
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 ( ) ) ? ;
346348
347349 let transform =
348350 PathTransform :: trait_impl ( & target, & source, delegee. 0 , delegate. clone ( ) ) ;
349351 transform. apply ( & delegate. syntax ( ) ) ;
350352 }
351353 }
352354
353- delegate
355+ Some ( delegate)
354356}
355357
356358fn process_assoc_item (
@@ -359,19 +361,19 @@ fn process_assoc_item(
359361 base_name : & str ,
360362) -> Option < ast:: AssocItem > {
361363 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) ,
364366 AssocItem :: MacroCall ( _) => {
365367 // FIXME : Handle MacroCall case.
366- // return Some( macro_assoc_item(mac, qual_path_ty));
368+ // macro_assoc_item(mac, qual_path_ty)
367369 None
368370 }
369- AssocItem :: TypeAlias ( ta) => Some ( ty_assoc_item ( ta, qual_path_ty) ) ,
371+ AssocItem :: TypeAlias ( ta) => ty_assoc_item ( ta, qual_path_ty) ,
370372 }
371373}
372374
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 ( ) ) ;
375377
376378 // We want rhs of the const assignment to be a qualified path
377379 // 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
380382 // FIXME : We can't rely on `make::path_qualified` for now but it would be nice to replace the following with it.
381383 // make::path_qualified(qual_path_ty, path_expr_segment.as_single_segment().unwrap());
382384 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 ( ) ;
390388
391- AssocItem :: Const ( inner)
389+ Some ( AssocItem :: Const ( inner) )
392390}
393391
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 ( ) ) ;
396398 let qualpath = qualpath ( qual_path_ty, path_expr_segment) ;
397399
398400 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) -
415417 if param_count > 0 {
416418 // Add SelfParam and a TOKEN::COMMA
417419 ted:: insert_all (
418- Position :: after ( args. l_paren_token ( ) . unwrap ( ) ) ,
420+ Position :: after ( args. l_paren_token ( ) ? ) ,
419421 vec ! [
420422 NodeOrToken :: Node ( tail_expr_self. syntax( ) . clone_for_update( ) ) ,
421423 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) -
425427 } else {
426428 // Add SelfParam only
427429 ted:: insert (
428- Position :: after ( args. l_paren_token ( ) . unwrap ( ) ) ,
430+ Position :: after ( args. l_paren_token ( ) ? ) ,
429431 NodeOrToken :: Node ( tail_expr_self. syntax ( ) . clone_for_update ( ) ) ,
430432 ) ;
431433 }
@@ -444,10 +446,10 @@ fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -
444446 let body = make:: block_expr ( vec ! [ ] , Some ( call) ) . clone_for_update ( ) ;
445447 let func = make:: fn_ (
446448 item. visibility ( ) ,
447- item. name ( ) . unwrap ( ) ,
449+ item. name ( ) ? ,
448450 item. generic_param_list ( ) ,
449451 item. where_clause ( ) ,
450- item. param_list ( ) . unwrap ( ) ,
452+ item. param_list ( ) ? ,
451453 body,
452454 item. ret_type ( ) ,
453455 item. async_token ( ) . is_some ( ) ,
@@ -456,14 +458,14 @@ fn func_assoc_item(item: syntax::ast::Fn, qual_path_ty: Path, base_name: &str) -
456458 )
457459 . clone_for_update ( ) ;
458460
459- AssocItem :: Fn ( func. indent ( edit:: IndentLevel ( 1 ) ) . clone_for_update ( ) )
461+ Some ( AssocItem :: Fn ( func. indent ( edit:: IndentLevel ( 1 ) ) . clone_for_update ( ) ) )
460462}
461463
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 ( ) ) ;
464466 let qualpath = qualpath ( qual_path_ty, path_expr_segment) ;
465467 let ty = make:: ty_path ( qualpath) ;
466- let ident = item. name ( ) . unwrap ( ) . to_string ( ) ;
468+ let ident = item. name ( ) ? . to_string ( ) ;
467469
468470 let alias = make:: ty_alias (
469471 ident. as_str ( ) ,
@@ -474,7 +476,7 @@ fn ty_assoc_item(item: syntax::ast::TypeAlias, qual_path_ty: Path) -> AssocItem
474476 )
475477 . clone_for_update ( ) ;
476478
477- AssocItem :: TypeAlias ( alias)
479+ Some ( AssocItem :: TypeAlias ( alias) )
478480}
479481
480482fn qualpath ( qual_path_ty : ast:: Path , path_expr_seg : ast:: Path ) -> ast:: Path {
0 commit comments