mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
ui tests added
This commit is contained in:
parent
6c3d94d73b
commit
fbd7fe9a08
17 changed files with 229 additions and 227 deletions
24
ui/lockall_borrow_shared.rs
Normal file
24
ui/lockall_borrow_shared.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#![no_main]
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
#[shared]
|
||||
struct Shared {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
(Shared { a: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(shared = [a])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
c.shared.lock(|_| {
|
||||
c.shared.lock(|_| {}); // borrow error
|
||||
});
|
||||
}
|
||||
}
|
||||
25
ui/lockall_borrow_shared.stderr
Normal file
25
ui/lockall_borrow_shared.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error[E0499]: cannot borrow `c.shared` as mutable more than once at a time
|
||||
--> ui/lockall_borrow_shared.rs:20:9
|
||||
|
|
||||
20 | c.shared.lock(|_| {
|
||||
| ^ ---- --- first mutable borrow occurs here
|
||||
| | |
|
||||
| _________| first borrow later used by call
|
||||
| |
|
||||
21 | | c.shared.lock(|_| {}); // borrow error
|
||||
| | -------- first borrow occurs due to use of `c` in closure
|
||||
22 | | });
|
||||
| |__________^ second mutable borrow occurs here
|
||||
|
||||
error[E0499]: cannot borrow `c` as mutable more than once at a time
|
||||
--> ui/lockall_borrow_shared.rs:20:23
|
||||
|
|
||||
20 | c.shared.lock(|_| {
|
||||
| - ---- ^^^ second mutable borrow occurs here
|
||||
| | |
|
||||
| _________| first borrow later used by call
|
||||
| |
|
||||
21 | | c.shared.lock(|_| {}); // borrow error
|
||||
| | -------- second borrow occurs due to use of `c` in closure
|
||||
22 | | });
|
||||
| |__________- first mutable borrow occurs here
|
||||
24
ui/lockall_borrow_shared_a.rs
Normal file
24
ui/lockall_borrow_shared_a.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#![no_main]
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
#[shared]
|
||||
struct Shared {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
(Shared { a: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(shared = [a])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
c.shared.lock(|_| {
|
||||
c.shared.a.lock(|_| {}); // borrow error
|
||||
});
|
||||
}
|
||||
}
|
||||
25
ui/lockall_borrow_shared_a.stderr
Normal file
25
ui/lockall_borrow_shared_a.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error[E0499]: cannot borrow `c.shared` as mutable more than once at a time
|
||||
--> ui/lockall_borrow_shared_a.rs:20:9
|
||||
|
|
||||
20 | c.shared.lock(|_| {
|
||||
| ^ ---- --- first mutable borrow occurs here
|
||||
| | |
|
||||
| _________| first borrow later used by call
|
||||
| |
|
||||
21 | | c.shared.a.lock(|_| {}); // borrow error
|
||||
| | ---------- first borrow occurs due to use of `c` in closure
|
||||
22 | | });
|
||||
| |__________^ second mutable borrow occurs here
|
||||
|
||||
error[E0499]: cannot borrow `c` as mutable more than once at a time
|
||||
--> ui/lockall_borrow_shared_a.rs:20:23
|
||||
|
|
||||
20 | c.shared.lock(|_| {
|
||||
| - ---- ^^^ second mutable borrow occurs here
|
||||
| | |
|
||||
| _________| first borrow later used by call
|
||||
| |
|
||||
21 | | c.shared.a.lock(|_| {}); // borrow error
|
||||
| | ---------- second borrow occurs due to use of `c` in closure
|
||||
22 | | });
|
||||
| |__________- first mutable borrow occurs here
|
||||
22
ui/lockall_lifetime.rs
Normal file
22
ui/lockall_lifetime.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#![no_main]
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
#[shared]
|
||||
struct Shared {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
(Shared { a: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(shared = [a])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
let _ = c.shared.lock(|s| s); // lifetime
|
||||
}
|
||||
}
|
||||
8
ui/lockall_lifetime.stderr
Normal file
8
ui/lockall_lifetime.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: lifetime may not live long enough
|
||||
--> ui/lockall_lifetime.rs:20:35
|
||||
|
|
||||
20 | let _ = c.shared.lock(|s| s); // lifetime
|
||||
| -- ^ returning this value requires that `'1` must outlive `'2`
|
||||
| ||
|
||||
| |return type of closure is &'2 mut __rtic_internal_fooShared
|
||||
| has type `&'1 mut __rtic_internal_fooShared`
|
||||
31
ui/lockall_lifetime_destruct_field.rs
Normal file
31
ui/lockall_lifetime_destruct_field.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//! examples/lockall_soundness.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
#[shared]
|
||||
struct Shared {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
(Shared { a: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(shared = [a])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
let _ = c.shared.lock(|foo::Shared { a }| {
|
||||
a // lifetime
|
||||
});
|
||||
}
|
||||
}
|
||||
9
ui/lockall_lifetime_destruct_field.stderr
Normal file
9
ui/lockall_lifetime_destruct_field.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error: lifetime may not live long enough
|
||||
--> ui/lockall_lifetime_destruct_field.rs:28:13
|
||||
|
|
||||
27 | let _ = c.shared.lock(|foo::Shared { a }| {
|
||||
| ------------------ return type of closure is &'2 mut &mut u32
|
||||
| |
|
||||
| has type `&'1 mut __rtic_internal_fooShared`
|
||||
28 | a // lifetime
|
||||
| ^ returning this value requires that `'1` must outlive `'2`
|
||||
22
ui/lockall_lifetime_reborrow.rs
Normal file
22
ui/lockall_lifetime_reborrow.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#![no_main]
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
#[shared]
|
||||
struct Shared {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
(Shared { a: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(shared = [a])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
let _ = c.shared.lock(|s| &mut *s.a); // lifetime
|
||||
}
|
||||
}
|
||||
8
ui/lockall_lifetime_reborrow.stderr
Normal file
8
ui/lockall_lifetime_reborrow.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: lifetime may not live long enough
|
||||
--> ui/lockall_lifetime_reborrow.rs:20:35
|
||||
|
|
||||
20 | let _ = c.shared.lock(|s| &mut *s.a); // lifetime
|
||||
| -- ^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
|
||||
| ||
|
||||
| |return type of closure is &'2 mut u32
|
||||
| has type `&'1 mut __rtic_internal_fooShared`
|
||||
24
ui/lockall_move_out_field.rs
Normal file
24
ui/lockall_move_out_field.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#![no_main]
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
#[shared]
|
||||
struct Shared {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared { a: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(shared = [a])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
let _ = c.shared.lock(|s| s.a);
|
||||
}
|
||||
}
|
||||
5
ui/lockall_move_out_field.stderr
Normal file
5
ui/lockall_move_out_field.stderr
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error[E0507]: cannot move out of `s.a` which is behind a mutable reference
|
||||
--> ui/lockall_move_out_field.rs:22:35
|
||||
|
|
||||
22 | let _ = c.shared.lock(|s| s.a);
|
||||
| ^^^ move occurs because `s.a` has type `&mut u32`, which does not implement the `Copy` trait
|
||||
Loading…
Add table
Add a link
Reference in a new issue