Skip to content

Commit fa3aeeb

Browse files
committed
implement SpanRange for DelimSpan and syn delimiter tokens
1 parent 47e52ac commit fa3aeeb

File tree

7 files changed

+61
-5
lines changed

7 files changed

+61
-5
lines changed

Diff for: .github/workflows/release.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- v[0-9]+.*
10+
11+
jobs:
12+
create-release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: taiki-e/create-gh-release-action@v1
17+
with:
18+
changelog: CHANGELOG.md
19+
branch: main
20+
token: ${{ secrets.GITHUB_TOKEN }}

Diff for: CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
<!-- ## [Unreleased] -->
7+
## [Unreleased]
8+
### Added
9+
- support for syn's `Brace`, `Paren`, `Bracket` to `span_range`
10+
- support for `DelimSpan` to `span_range`
11+
812
## [0.11.4] - 2024-08-25
913
- Updated `proc-macro-utils`
1014

Diff for: examples/macro/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ pub fn parse_quote_dummy_error_attribute(_: TokenStream, _: TokenStream) -> Resu
190190

191191
#[manyhow(item_as_dummy)]
192192
#[proc_macro_attribute]
193-
pub fn parse_quote_dummy_error_attribute_syn_result(_: TokenStream, _: TokenStream) -> syn::Result<syn::Ident> {
193+
pub fn parse_quote_dummy_error_attribute_syn_result(
194+
_: TokenStream,
195+
_: TokenStream,
196+
) -> syn::Result<syn::Ident> {
194197
bail!("error message")
195198
}
196199

Diff for: examples/no_macro/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ pub fn parse_quote_dummy_error_attribute(input: TokenStream, item: TokenStream)
183183
}
184184

185185
#[proc_macro_attribute]
186-
pub fn parse_quote_dummy_error_attribute_syn_result(input: TokenStream, item: TokenStream) -> TokenStream {
186+
pub fn parse_quote_dummy_error_attribute_syn_result(
187+
input: TokenStream,
188+
item: TokenStream,
189+
) -> TokenStream {
187190
attribute!(
188191
input,
189192
#[as_dummy]

Diff for: rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ unstable_features = true
1313
use_field_init_shorthand = true
1414
version = "Two"
1515
wrap_comments = true
16+
single_line_let_else_max_width=80

Diff for: src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ impl Error {
8484
/// Alternatively errors can also be "added":
8585
///
8686
/// ```
87-
/// use manyhow::{Error, error_message};
87+
/// use manyhow::{error_message, Error};
8888
/// let mut error = Error::from(error_message!("Hello Rust!"));
8989
/// error += error_message!("Hello 🦀!");
9090
/// # use manyhow::ToTokensError;
91-
/// # proc_macro_utils::assert_tokens!(error.into_token_stream(),
91+
/// # proc_macro_utils::assert_tokens!(error.into_token_stream(),
9292
/// # { ::core::compile_error!{"Hello Rust!"} ::core::compile_error!{"Hello 🦀!"} });
9393
/// ```
9494
pub fn push(&mut self, error: impl ToTokensError + 'static) {

Diff for: src/span_ranged.rs

+25
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ impl SpanRanged for proc_macro::TokenStream {
128128
}
129129
}
130130

131+
impl SpanRanged for proc_macro2::extra::DelimSpan {
132+
fn span_range(&self) -> Range<Span> {
133+
self.join().span_range()
134+
}
135+
}
136+
137+
#[cfg(feature = "syn2")]
138+
const _: () = {
139+
impl SpanRanged for syn2::token::Brace {
140+
fn span_range(&self) -> Range<Span> {
141+
self.span.span_range()
142+
}
143+
}
144+
impl SpanRanged for syn2::token::Bracket {
145+
fn span_range(&self) -> Range<Span> {
146+
self.span.span_range()
147+
}
148+
}
149+
impl SpanRanged for syn2::token::Paren {
150+
fn span_range(&self) -> Range<Span> {
151+
self.span.span_range()
152+
}
153+
}
154+
};
155+
131156
/// Implementation of [`SpanRanged`](SpanRanged)` for T: `[`ToTokens`]
132157
///
133158
/// This is necessary to put in a standalone function due to compiler

0 commit comments

Comments
 (0)