Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage with impl trait returning functions #4

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "culpa"
version = "1.0.0"
version = "1.0.1"
edition = "2018"
license = "MIT OR Apache-2.0"

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

[dependencies.culpa-macros]
path = "macros"
version = "=1.0.0"
version = "=1.0.1"

[workspace]
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "culpa-macros"
version = "1.0.0"
version = "1.0.1"
edition = "2018"
license = "MIT OR Apache-2.0"

Expand Down
15 changes: 12 additions & 3 deletions macros/src/throws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use crate::Args;
pub struct Throws {
args: Args,
outer_fn: bool,
return_type: Box<syn::Type>,
return_type: syn::Type,
}

impl Throws {
pub fn new(args: Args) -> Throws {
Throws {
args,
outer_fn: true,
return_type: Box::new(syn::parse_quote!(())),
return_type: syn::parse_quote!(()),
}
}

Expand Down Expand Up @@ -112,7 +112,16 @@ impl Fold for Throws {
}
let return_type = self.args.ret(i);
let syn::ReturnType::Type(_, ty) = &return_type else { unreachable!() };
self.return_type = ty.clone();
struct ImplTraitToInfer;
impl Fold for ImplTraitToInfer {
fn fold_type(&mut self, i: syn::Type) -> syn::Type {
match i {
syn::Type::ImplTrait(_) => syn::Type::Infer(syn::parse_quote!(_)),
i => syn::fold::fold_type(self, i),
}
}
}
self.return_type = ImplTraitToInfer.fold_type(ty.as_ref().clone());
return_type
}

Expand Down
3 changes: 3 additions & 0 deletions tests/throws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ pub fn let_else(a: Option<u8>) -> u8 {
a
}

#[throws]
pub fn impl_trait() -> impl std::fmt::Debug {}

#[throws(i32)]
#[deny(unreachable_code)]
pub fn unreachable() {
Expand Down
Loading