Skip to content

Commit f74f38a

Browse files
Update syn requirement from 1.0.107 to 2.0.48 (#881)
* Update syn requirement from 1.0.107 to 2.0.48 Updates the requirements on [syn](https://github.com/dtolnay/syn) to permit the latest version. - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](dtolnay/syn@1.0.107...2.0.48) --- updated-dependencies: - dependency-name: syn dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * rtic-macros: attr.path -> attr.path() * rtic-macros: tokens -> parse_args() Fix parsing of InitArgs, IdleArgs, *Args Including HardwareTaskArgs, SoftwareTaskArgs * rtic-macros: Rename content to input As syn2 removes the surrounding parenthesis as part of parse_args() the distinction between input and content is redundant * rtic-macros: Handle removal of Expr::Type Manually parse local_resources With type ascription de-RFCd syn2 dropped Expr::Type * rtic-macros: Syn upgrade CHANGELOG * rtic-macro: Retain most old errors as they were Spans are not equal, but good enough * rtic-macros: syn2 changed some error messages Additionally some spans were not retained with the manual parsing workaround * rtic-macros: clippy fixes --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Henrik Tjäder <[email protected]>
1 parent c630657 commit f74f38a

File tree

12 files changed

+182
-121
lines changed

12 files changed

+182
-121
lines changed

rtic-macros/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
1111

1212
- Unstable ESP32-C3 support.
1313

14+
### Changed
15+
16+
- Upgraded from syn 1.x to syn 2.x
17+
1418
## [v2.0.1] - 2023-07-25
1519

1620
### Added

rtic-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ indexmap = "2.0.0"
4646
proc-macro2 = "1.0.49"
4747
proc-macro-error = "1.0.4"
4848
quote = "1.0.23"
49-
syn = { version = "1.0.107", features = ["extra-traits", "full"] }
49+
syn = { version = "2.0.48", features = ["extra-traits", "full"] }
5050

5151
[dev-dependencies]
5252
trybuild = "1.0.73"

rtic-macros/src/codegen/local_resources.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ pub fn codegen(app: &App, _analysis: &Analysis) -> TokenStream2 {
1919

2020
// late resources in `util::link_section_uninit`
2121
// unless user specifies custom link section
22-
let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) {
22+
let section = if attrs
23+
.iter()
24+
.any(|attr| attr.path().is_ident("link_section"))
25+
{
2326
None
2427
} else {
2528
Some(util::link_section_uninit())

rtic-macros/src/codegen/shared_resources.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
1919

2020
// late resources in `util::link_section_uninit`
2121
// unless user specifies custom link section
22-
let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) {
22+
let section = if attrs
23+
.iter()
24+
.any(|attr| attr.path().is_ident("link_section"))
25+
{
2326
None
2427
} else {
2528
Some(util::link_section_uninit())

rtic-macros/src/syntax/parse.rs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod util;
88

99
use proc_macro2::TokenStream as TokenStream2;
1010
use syn::{
11-
braced, parenthesized,
11+
braced,
1212
parse::{self, Parse, ParseStream, Parser},
1313
token::Brace,
1414
Ident, Item, LitInt, Token,
@@ -70,15 +70,12 @@ fn init_args(tokens: TokenStream2) -> parse::Result<InitArgs> {
7070

7171
let mut local_resources = None;
7272

73-
let content;
74-
parenthesized!(content in input);
75-
76-
if !content.is_empty() {
73+
if !input.is_empty() {
7774
loop {
7875
// Parse identifier name
79-
let ident: Ident = content.parse()?;
76+
let ident: Ident = input.parse()?;
8077
// Handle equal sign
81-
let _: Token![=] = content.parse()?;
78+
let _: Token![=] = input.parse()?;
8279

8380
match &*ident.to_string() {
8481
"local" => {
@@ -89,18 +86,18 @@ fn init_args(tokens: TokenStream2) -> parse::Result<InitArgs> {
8986
));
9087
}
9188

92-
local_resources = Some(util::parse_local_resources(&content)?);
89+
local_resources = Some(util::parse_local_resources(input)?);
9390
}
9491
_ => {
9592
return Err(parse::Error::new(ident.span(), "unexpected argument"));
9693
}
9794
}
9895

99-
if content.is_empty() {
96+
if input.is_empty() {
10097
break;
10198
}
10299
// Handle comma: ,
103-
let _: Token![,] = content.parse()?;
100+
let _: Token![,] = input.parse()?;
104101
}
105102
}
106103

@@ -131,14 +128,12 @@ fn idle_args(tokens: TokenStream2) -> parse::Result<IdleArgs> {
131128
let mut shared_resources = None;
132129
let mut local_resources = None;
133130

134-
let content;
135-
parenthesized!(content in input);
136-
if !content.is_empty() {
131+
if !input.is_empty() {
137132
loop {
138133
// Parse identifier name
139-
let ident: Ident = content.parse()?;
134+
let ident: Ident = input.parse()?;
140135
// Handle equal sign
141-
let _: Token![=] = content.parse()?;
136+
let _: Token![=] = input.parse()?;
142137

143138
match &*ident.to_string() {
144139
"shared" => {
@@ -149,7 +144,7 @@ fn idle_args(tokens: TokenStream2) -> parse::Result<IdleArgs> {
149144
));
150145
}
151146

152-
shared_resources = Some(util::parse_shared_resources(&content)?);
147+
shared_resources = Some(util::parse_shared_resources(input)?);
153148
}
154149

155150
"local" => {
@@ -160,19 +155,19 @@ fn idle_args(tokens: TokenStream2) -> parse::Result<IdleArgs> {
160155
));
161156
}
162157

163-
local_resources = Some(util::parse_local_resources(&content)?);
158+
local_resources = Some(util::parse_local_resources(input)?);
164159
}
165160

166161
_ => {
167162
return Err(parse::Error::new(ident.span(), "unexpected argument"));
168163
}
169164
}
170-
if content.is_empty() {
165+
if input.is_empty() {
171166
break;
172167
}
173168

174169
// Handle comma: ,
175-
let _: Token![,] = content.parse()?;
170+
let _: Token![,] = input.parse()?;
176171
}
177172
}
178173

@@ -196,19 +191,17 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
196191
let mut local_resources = None;
197192
let mut prio_span = None;
198193

199-
let content;
200-
parenthesized!(content in input);
201194
loop {
202-
if content.is_empty() {
195+
if input.is_empty() {
203196
break;
204197
}
205198

206199
// Parse identifier name
207-
let ident: Ident = content.parse()?;
200+
let ident: Ident = input.parse()?;
208201
let ident_s = ident.to_string();
209202

210203
// Handle equal sign
211-
let _: Token![=] = content.parse()?;
204+
let _: Token![=] = input.parse()?;
212205

213206
match &*ident_s {
214207
"binds" => {
@@ -220,7 +213,7 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
220213
}
221214

222215
// Parse identifier name
223-
let ident = content.parse()?;
216+
let ident = input.parse()?;
224217

225218
binds = Some(ident);
226219
}
@@ -234,7 +227,7 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
234227
}
235228

236229
// #lit
237-
let lit: LitInt = content.parse()?;
230+
let lit: LitInt = input.parse()?;
238231

239232
if !lit.suffix().is_empty() {
240233
return Err(parse::Error::new(
@@ -263,7 +256,7 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
263256
));
264257
}
265258

266-
shared_resources = Some(util::parse_shared_resources(&content)?);
259+
shared_resources = Some(util::parse_shared_resources(input)?);
267260
}
268261

269262
"local" => {
@@ -274,20 +267,20 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
274267
));
275268
}
276269

277-
local_resources = Some(util::parse_local_resources(&content)?);
270+
local_resources = Some(util::parse_local_resources(input)?);
278271
}
279272

280273
_ => {
281274
return Err(parse::Error::new(ident.span(), "unexpected argument"));
282275
}
283276
}
284277

285-
if content.is_empty() {
278+
if input.is_empty() {
286279
break;
287280
}
288281

289282
// Handle comma: ,
290-
let _: Token![,] = content.parse()?;
283+
let _: Token![,] = input.parse()?;
291284
}
292285
let shared_resources = shared_resources.unwrap_or_default();
293286
let local_resources = local_resources.unwrap_or_default();

rtic-macros/src/syntax/parse/app.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ impl App {
198198
.iter()
199199
.position(|attr| util::attr_eq(attr, "init"))
200200
{
201-
let args = InitArgs::parse(item.attrs.remove(pos).tokens)?;
201+
let args = InitArgs::parse(
202+
item.attrs.remove(pos).parse_args().unwrap_or_default(),
203+
)?;
202204

203205
// If an init function already exists, error
204206
if init.is_some() {
@@ -216,7 +218,9 @@ impl App {
216218
.iter()
217219
.position(|attr| util::attr_eq(attr, "idle"))
218220
{
219-
let args = IdleArgs::parse(item.attrs.remove(pos).tokens)?;
221+
let args = IdleArgs::parse(
222+
item.attrs.remove(pos).parse_args().unwrap_or_default(),
223+
)?;
220224

221225
// If an idle function already exists, error
222226
if idle.is_some() {
@@ -243,7 +247,9 @@ impl App {
243247
));
244248
}
245249

246-
match syntax_parse::task_args(item.attrs.remove(pos).tokens)? {
250+
match syntax_parse::task_args(
251+
item.attrs.remove(pos).parse_args().unwrap_or_default(),
252+
)? {
247253
Either::Left(args) => {
248254
check_binding(&args.binds)?;
249255
check_ident(&item.sig.ident)?;
@@ -369,8 +375,9 @@ impl App {
369375
.iter()
370376
.position(|attr| util::attr_eq(attr, "init"))
371377
{
372-
let args = InitArgs::parse(item.attrs.remove(pos).tokens)?;
373-
378+
let args = InitArgs::parse(
379+
item.attrs.remove(pos).parse_args().unwrap_or_default(),
380+
)?;
374381
// If an init function already exists, error
375382
if init.is_some() {
376383
return Err(parse::Error::new(
@@ -387,7 +394,9 @@ impl App {
387394
.iter()
388395
.position(|attr| util::attr_eq(attr, "idle"))
389396
{
390-
let args = IdleArgs::parse(item.attrs.remove(pos).tokens)?;
397+
let args = IdleArgs::parse(
398+
item.attrs.remove(pos).parse_args().unwrap_or_default(),
399+
)?;
391400

392401
// If an idle function already exists, error
393402
if idle.is_some() {
@@ -421,7 +430,9 @@ impl App {
421430
));
422431
}
423432

424-
match syntax_parse::task_args(item.attrs.remove(pos).tokens)? {
433+
match syntax_parse::task_args(
434+
item.attrs.remove(pos).parse_args().unwrap_or_default(),
435+
)? {
425436
Either::Left(args) => {
426437
check_binding(&args.binds)?;
427438
check_ident(&item.sig.ident)?;

rtic-macros/src/syntax/parse/init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use proc_macro2::TokenStream as TokenStream2;
2-
1+
use crate::syntax::TokenStream2;
32
use syn::{parse, ForeignItemFn, ItemFn, Stmt};
43

54
use crate::syntax::{

0 commit comments

Comments
 (0)