Add const and unsafe block suport to bsn! macro#24336
Open
loreball wants to merge 2 commits into
Open
Conversation
amtep
reviewed
May 18, 2026
| let braced = braced_tokens(input)?; | ||
|
|
||
| BsnValue::Expr(quote! {#unsafe_token {#braced}}) | ||
| } else if input.peek(Token![async]) && input.peek2(Brace) { |
Contributor
There was a problem hiding this comment.
Given the difficulties you noted with supporting async blocks, it may be better to leave this out until it's supported
You can't really make it work properly without limits.
The problem is that async futures produce unnamable types.
You'd have to box them but the `.into()` call we use doesn't
work for that.
```rust
fn what_we_do() -> Box<dyn Future<Output = ()>> {
{async {}}.into()
}
// This wouldn't be generic over the container though
fn what_we_need_to_do() -> Box<dyn Future<Output = ()>> {
Box::new({async {}})
}
```
Contributor
Author
|
I've ripped out support for async blocks. More detailed reasoning is in the commit description but tl;dr there's just no way to type a struct field that would make it work. If somebody really needs it they can do |
amtep
approved these changes
May 18, 2026
kfc35
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Closes #24121
Solution
Add
const,unsafeandasyncblock support to bsn expressions.Testing
I've added a compile test for
constandunsafeblocks. I couldn't figure out how to test or even use the async blocks. The macro needs to construct a struct that holds a future, butasyncblocks produce voldemort (unnameable) types. UsingBox<dyn Future>fixes this problem but then you run into the problem that the struct needs to be clone-able and have a default value.asyncblock futures have neither of those properties.Showcase
The
bsn!macro now supportsconstandunsafeblocks.