Skip to content

Commit a48a28a

Browse files
bors[bot]korken89
andauthored
Merge #74
74: Better errors for malformed local expressions r=AfoHT a=korken89 Co-authored-by: Emil Fresk <[email protected]>
2 parents 3cfe8df + 7c45100 commit a48a28a

10 files changed

+92
-2
lines changed

CHANGELOG.md

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

1414
### Fixed
1515

16+
- Better errors for malformed `local` expressions
1617
- Use swatinem rust-cache for GHA CI
1718
- Cryptic error message when writing `#[monotonic]`
1819

src/parse/util.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
201201

202202
(name, ty, cfgs, attrs)
203203
}
204-
_ => return Err(parse::Error::new(e.span(), "not a type")),
204+
e => return Err(parse::Error::new(e.span(), "malformed, expected a type")),
205205
};
206206

207207
let expr = e.right; // Expr
@@ -217,7 +217,12 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
217217
)
218218
}
219219

220-
_ => return err,
220+
expr => {
221+
return Err(parse::Error::new(
222+
expr.span(),
223+
"malformed, exptected 'IDENT: TYPE = EXPR'",
224+
))
225+
}
221226
};
222227

223228
resources.insert(name, local);

ui/local-malformed-1.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
3+
#[mock::app]
4+
mod app {
5+
#[shared]
6+
struct Shared {}
7+
8+
#[local]
9+
struct Local {}
10+
11+
#[task(local = [a:])]
12+
fn foo(_: foo::Context) {}
13+
14+
#[init]
15+
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {}
16+
}

ui/local-malformed-1.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: unexpected end of input, expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime
2+
--> ui/local-malformed-1.rs:11:23
3+
|
4+
11 | #[task(local = [a:])]
5+
| ^

ui/local-malformed-2.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
3+
#[mock::app]
4+
mod app {
5+
#[shared]
6+
struct Shared {}
7+
8+
#[local]
9+
struct Local {}
10+
11+
#[task(local = [a: u32])]
12+
fn foo(_: foo::Context) {}
13+
14+
#[init]
15+
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {}
16+
}

ui/local-malformed-2.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: malformed, exptected 'IDENT: TYPE = EXPR'
2+
--> ui/local-malformed-2.rs:11:21
3+
|
4+
11 | #[task(local = [a: u32])]
5+
| ^

ui/local-malformed-3.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
3+
#[mock::app]
4+
mod app {
5+
#[shared]
6+
struct Shared {}
7+
8+
#[local]
9+
struct Local {}
10+
11+
#[task(local = [a: u32 =])]
12+
fn foo(_: foo::Context) {}
13+
14+
#[init]
15+
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {}
16+
}

ui/local-malformed-3.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: unexpected end of input, expected expression
2+
--> ui/local-malformed-3.rs:11:29
3+
|
4+
11 | #[task(local = [a: u32 =])]
5+
| ^

ui/local-malformed-4.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
3+
#[mock::app]
4+
mod app {
5+
#[shared]
6+
struct Shared {}
7+
8+
#[local]
9+
struct Local {}
10+
11+
#[task(local = [a = u32])]
12+
fn foo(_: foo::Context) {}
13+
14+
#[init]
15+
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {}
16+
}

ui/local-malformed-4.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: malformed, expected a type
2+
--> ui/local-malformed-4.rs:11:21
3+
|
4+
11 | #[task(local = [a = u32])]
5+
| ^

0 commit comments

Comments
 (0)