8000 Fixed cryptic monotonic error · rtic-rs/rtic-syntax@0c0975a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c0975a

Browse files
committed
Fixed cryptic monotonic error
1 parent d2cb900 commit 0c0975a

File tree

8 files changed

+40
-14
lines changed

8 files changed

+40
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1414
### Fixed
1515

1616
- Use swatinem rust-cache for GHA CI
17+
- Cryptic error message when writing `#[monotonic]`
1718

1819
## [v1.0.0] - 2021-12-25
1920

src/parse.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ mod util;
99

1010
use proc_macro2::TokenStream as TokenStream2;
1111
use syn::{
12-
braced, parenthesized,
12+
braced,
13+
group::parse_parens,
14+
parenthesized,
1315
parse::{self, Parse, ParseStream, Parser},
1416
token::Brace,
15-
Ident, Item, LitBool, LitInt, Token,
17+
Ident, Item, LitBool, LitInt, Path, Token,
1618
};
1719

1820
use crate::{
@@ -368,14 +370,22 @@ fn task_args(
368370
.parse2(tokens)
369371
}
370372

371-
fn monotonic_args(tokens: TokenStream2) -> parse::Result<MonotonicArgs> {
373+
fn monotonic_args(path: Path, tokens: TokenStream2) -> parse::Result<MonotonicArgs> {
372374
(|input: ParseStream<'_>| -> parse::Result<MonotonicArgs> {
373375
let mut binds = None;
374376
let mut priority = None;
375377
let mut default = None;
376378

377-
let content;
378-
parenthesized!(content in input);
379+
let content = match parse_parens(input) {
380+
Ok(parens) => parens.content,
381+
Err(_) => {
382+
return Err(parse::Error::new(
383+
path.segments.first().unwrap().ident.span(),
384+
"expected opening ( in #[monotonic( ... )]",
385+
));
386+
}
387+
};
388+
379389
if !content.is_empty() {
380390
loop {
381391
// Parse identifier name
@@ -450,6 +460,7 @@ fn monotonic_args(tokens: TokenStream2) -> parse::Result<MonotonicArgs> {
450460
let _: Token![,] = content.parse()?;
451461
}
452462
}
463+
453464
let binds = if let Some(r) = binds {
454465
r
455466
} else {

src/parse/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl App {
457457
if monotonics.contains_key(&type_item.ident) {
458458
return Err(parse::Error::new(
459459
span,
460-
"`#[monotonic]` on a specific type must appear at most once",
460+
"`#[monotonic(...)]` on a specific type must appear at most once",
461461
));
462462
}
463463

@@ -470,7 +470,8 @@ impl App {
470470

471471
check_monotonic(&*type_item.ty)?;
472472

473-
let args = MonotonicArgs::parse(type_item.attrs.remove(pos).tokens)?;
473+
let m = type_item.attrs.remove(pos);
474+
let args = MonotonicArgs::parse(m)?;
474475

475476
check_binding(&args.binds)?;
476477

src/parse/monotonic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use proc_macro2::Span;
2-
use proc_macro2::TokenStream as TokenStream2;
2+
use syn::Attribute;
33
use syn::{parse, spanned::Spanned, ItemType, Visibility};
44

55
use crate::parse::util::FilterAttrs;
@@ -9,8 +9,8 @@ use crate::{
99
};
1010

1111
impl MonotonicArgs {
12-
pub(crate) fn parse(tokens: TokenStream2) -> parse::Result<Self> {
13-
crate::parse::monotonic_args(tokens)
12+
pub(crate) fn parse(attr: Attribute) -> parse::Result<Self> {
13+
crate::parse::monotonic_args(attr.path, attr.tokens)
1414
}
1515
}
1616

ui/monotonic-double.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error: `#[monotonic]` on a specific type must appear at most once
2-
--> $DIR/monotonic-double.rs:9:10
1+
error: `#[monotonic(...)]` on a specific type must appear at most once
2+
--> ui/monotonic-double.rs:9:10
33
|
44
9 | type Fast = hal::Tim1Monotonic;
55
| ^^^^

ui/monotonic-name-collision.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error: `#[monotonic]` on a specific type must appear at most once
2-
--> $DIR/monotonic-name-collision.rs:9:10
1+
error: `#[monotonic(...)]` on a specific type must appear at most once
2+
--> ui/monotonic-name-collision.rs:9:10
33
|
44
9 | type Fast1 = hal::Tim2Monotonic;
55
| ^^^^^

ui/monotonic-no-paran.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_main]
2+
3+
#[mock::app]
4+
mod app {
5+
#[monotonic]
6+
type Fast = hal::Tim1Monotonic;
7+
}
8+

ui/monotonic-no-paran.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: expected opening ( in #[monotonic( ... )]
2+
--> ui/monotonic-no-paran.rs:5:7
3+
|
4+
5 | #[monotonic]
5+
| ^^^^^^^^^

0 commit comments

Comments
 (0)
0