| 1 | use synrust-analyzer cargo syn 2.0.119 crate/::spannedrust-analyzer cargo syn 2.0.119 spanned/::Spannedrust-analyzer cargo syn 2.0.119 spanned/Spanned#; |
| 2 | |
| 3 | use superrust-analyzer cargo blanket 0.4.0 crate/::utilsrust-analyzer cargo blanket 0.4.0 utils/::{prepend_function_pathrust-analyzer cargo blanket 0.4.0 utils/prepend_function_path()., signature_to_function_callrust-analyzer cargo blanket 0.4.0 utils/signature_to_function_call().}; |
| 4 | |
| 5 | /// Update the method declarations of `trait_` to use default implementation from `default` module. |
| 6 | pub fn defer_trait_methodsrust-analyzer cargo blanket 0.4.0 default/defer_trait_methods().( |
| 7 | mut trait_: synrust-analyzer cargo syn 2.0.119 crate/::ItemTraitrust-analyzer cargo syn 2.0.119 item/ItemTrait#, |
| 8 | default: synrust-analyzer cargo syn 2.0.119 crate/::Pathrust-analyzer cargo syn 2.0.119 path/Path#, |
| 9 | ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<synrust-analyzer cargo syn 2.0.119 crate/::ItemTraitrust-analyzer cargo syn 2.0.119 item/ItemTrait#> { |
| 10 | for item in trait_.itemsrust-analyzer cargo syn 2.0.119 item/ItemTrait#items..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() { |
| 11 | if let synrust-analyzer cargo syn 2.0.119 crate/::TraitItemrust-analyzer cargo syn 2.0.119 item/TraitItem#::Fnrust-analyzer cargo syn 2.0.119 item/TraitItem#Fn#(ref mut m) = item { |
| 12 | // check no default implementation was provided for the current |
| 13 | // trait method |
| 14 | if m.defaultrust-analyzer cargo syn 2.0.119 item/TraitItemFn#default..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 15 | let msg = "method should not have default implementation if using #[blanket(default = \"...\")]"; |
| 16 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.119 crate/::Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().(item.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), msg)); |
| 17 | } |
| 18 | // update the declaration to include a default implementation |
| 19 | // deferring the method call to a function call in the `default_mod` |
| 20 | // module |
| 21 | let mut call = signature_to_function_callrust-analyzer cargo blanket 0.4.0 utils/signature_to_function_call().(&m.sigrust-analyzer cargo syn 2.0.119 item/TraitItemFn#sig.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 22 | prepend_function_pathrust-analyzer cargo blanket 0.4.0 utils/prepend_function_path().(&mut call, default.clonerust-analyzer cargo syn 2.0.119 gen/clone/impl#[`crate::Path`][Clone]clone().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 23 | m.defaultrust-analyzer cargo syn 2.0.119 item/TraitItemFn#default. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(synrust-analyzer cargo syn 2.0.119 crate/::Blockrust-analyzer cargo syn 2.0.119 stmt/Block# { |
| 24 | brace_tokenrust-analyzer cargo syn 2.0.119 stmt/Block#brace_token.: synrust-analyzer cargo syn 2.0.119 crate/::tokenrust-analyzer cargo syn 2.0.119 token/::Bracerust-analyzer cargo syn 2.0.119 token/Brace#::defaultrust-analyzer cargo syn 2.0.119 token/impl#[Brace][Default]default().(), |
| 25 | stmtsrust-analyzer cargo syn 2.0.119 stmt/Block#stmts.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt#::Exprrust-analyzer cargo syn 2.0.119 stmt/Stmt#Expr#(synrust-analyzer cargo syn 2.0.119 crate/::Exprrust-analyzer cargo syn 2.0.119 expr/Expr#::Callrust-analyzer cargo syn 2.0.119 expr/Expr#Call#(call), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)], |
| 26 | }); |
| 27 | } |
| 28 | } |
| 29 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(trait_) |
| 30 | } |