Skip to content

Commit

Permalink
fix(derive): fix compiles when using quoted rtype form
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Sep 12, 2024
1 parent 104ad8f commit 8c36d6b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ members = [
]

[workspace.package]
license = "MIT OR Apache-2.0"
repository = "https://github.com/actix/actix"
edition = "2021"
rust-version = "1.72"

Expand Down
4 changes: 4 additions & 0 deletions actix-derive/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 0.6.2

- Fix compile failures when using quoted rtype (i.e., `#[rtype("()")]`) form.

## 0.6.1

- Update `syn` dependency to `2`.
Expand Down
8 changes: 4 additions & 4 deletions actix-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "actix_derive"
version = "0.6.1"
version = "0.6.2"
authors = [
"Callym <[email protected]>",
"Nikolay Kim <[email protected]>",
"Rob Ede <[email protected]>",
]
description = "Derive macros for `actix` actors"
keywords = ["actix", "actors", "derive", "macro"]
repository = "https://github.com/actix/actix"
license = "MIT OR Apache-2.0"
license.workspace = true
repository.workspace = true
edition.workspace = true
rust-version.workspace = true

Expand All @@ -27,4 +27,4 @@ proc-macro2 = "1"
[dev-dependencies]
actix = "0.13"
trybuild = "1"
rustversion = "1"
rustversion-msrv = "0.100"
4 changes: 2 additions & 2 deletions actix-derive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<!-- prettier-ignore-start -->

[![crates.io](https://img.shields.io/crates/v/actix-derive?label=latest)](https://crates.io/crates/actix-derive)
[![Documentation](https://docs.rs/actix-derive/badge.svg?version=0.6.1)](https://docs.rs/actix-derive/0.6.1)
[![Documentation](https://docs.rs/actix-derive/badge.svg?version=0.6.2)](https://docs.rs/actix-derive/0.6.2)
![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.68+-ab6000.svg)
![License](https://img.shields.io/crates/l/actix-derive.svg)
[![Dependency Status](https://deps.rs/crate/actix/0.6.1/status.svg)](https://deps.rs/crate/actix/0.6.1)
[![Dependency Status](https://deps.rs/crate/actix/0.6.2/status.svg)](https://deps.rs/crate/actix/0.6.2)

<!-- prettier-ignore-end -->

Expand Down
24 changes: 13 additions & 11 deletions actix-derive/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ fn get_attribute_type_multiple(
ast: &syn::DeriveInput,
name: &str,
) -> syn::Result<Vec<Option<syn::Type>>> {
let attr = ast
.attrs
.iter()
.find_map(|attr| {
if attr.path().is_ident(name) {
attr.parse_args().ok()
} else {
None
}
})
let mut target_attrs = ast.attrs.iter().filter(|attr| attr.path().is_ident(name));

if let Some(Ok(typ)) = target_attrs
.clone()
.find_map(|attr| attr.parse_args::<syn::LitStr>().ok())
.map(|lit_str| lit_str.parse::<syn::Type>())
{
return Ok(vec![Some(typ)]);
}

let attr = target_attrs
.find_map(|attr| attr.parse_args().ok())
.ok_or_else(|| {
syn::Error::new(Span::call_site(), format!("Expect an attribute `{name}`"))
syn::Error::new(Span::call_site(), format!("Expected an attribute `{name}`"))
})?;

match attr {
Expand Down
2 changes: 1 addition & 1 deletion actix-derive/tests/trybuild.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Proc macro compile tests.
///
/// Only run on MSRV to ensure stable compile errors.
#[rustversion::stable(1.68)]
#[rustversion_msrv::msrv]
#[test]
fn compile_macros() {
let t = trybuild::TestCases::new();
Expand Down
4 changes: 4 additions & 0 deletions actix-derive/tests/trybuild/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ struct Sum(usize, usize);
#[rtype(Added)]
struct SumBareType(usize, usize);

#[derive(Message)]
#[rtype("()")]
struct UnitReturnInString;

#[derive(Default)]
struct Adder;

Expand Down
2 changes: 2 additions & 0 deletions actix/tests/test_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ fn test_address_hash() {
let addr0 = MyActor(count0).start();
let addr01 = addr0.clone();

#[allow(clippy::mutable_key_type)]
let mut addresses = HashSet::new();

addresses.insert(addr0.clone());
addresses.insert(addr01.clone());

Expand Down
11 changes: 11 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ msrv := ```
```
msrv_rustup := "+" + msrv

# Format project.
[group("lint")]
fmt:
cargo +nightly fmt
fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch npx -y prettier --write

# Run Clippy over workspace.
[group("lint")]
clippy:
cargo clippy --workspace --all-targets --all-features

# Downgrade dev-dependencies necessary to run MSRV checks/tests.
[private]
downgrade-for-msrv:
Expand Down

0 comments on commit 8c36d6b

Please sign in to comment.