Skip to content

Commit 9ae83c7

Browse files
authored
Merge pull request Nullus157#4 from Nemo157/impl-trait
Fix usage with impl trait returning functions
2 parents 9348b56 + aa15f07 commit 9ae83c7

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "culpa"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
edition = "2018"
55
license = "MIT OR Apache-2.0"
66

@@ -10,6 +10,6 @@ keywords = ["error-handling", "exceptions"]
1010

1111
[dependencies.culpa-macros]
1212
path = "macros"
13-
version = "=1.0.0"
13+
version = "=1.0.1"
1414

1515
[workspace]

macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "culpa-macros"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
edition = "2018"
55
license = "MIT OR Apache-2.0"
66

macros/src/throws.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use crate::Args;
1313
pub struct Throws {
1414
args: Args,
1515
outer_fn: bool,
16-
return_type: Box<syn::Type>,
16+
return_type: syn::Type,
1717
}
1818

1919
impl Throws {
2020
pub fn new(args: Args) -> Throws {
2121
Throws {
2222
args,
2323
outer_fn: true,
24-
return_type: Box::new(syn::parse_quote!(())),
24+
return_type: syn::parse_quote!(()),
2525
}
2626
}
2727

@@ -112,7 +112,16 @@ impl Fold for Throws {
112112
}
113113
let return_type = self.args.ret(i);
114114
let syn::ReturnType::Type(_, ty) = &return_type else { unreachable!() };
115-
self.return_type = ty.clone();
115+
struct ImplTraitToInfer;
116+
impl Fold for ImplTraitToInfer {
117+
fn fold_type(&mut self, i: syn::Type) -> syn::Type {
118+
match i {
119+
syn::Type::ImplTrait(_) => syn::Type::Infer(syn::parse_quote!(_)),
120+
i => syn::fold::fold_type(self, i),
121+
}
122+
}
123+
}
124+
self.return_type = ImplTraitToInfer.fold_type(ty.as_ref().clone());
116125
return_type
117126
}
118127

tests/throws.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ pub fn let_else(a: Option<u8>) -> u8 {
135135
a
136136
}
137137

138+
#[throws]
139+
pub fn impl_trait() -> impl std::fmt::Debug {}
140+
138141
#[throws(i32)]
139142
#[deny(unreachable_code)]
140143
pub fn unreachable() {

0 commit comments

Comments
 (0)