proptest/arbitrary/_core/
cell.rs

1//-
2// Copyright 2017, 2018 The proptest developers
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! Arbitrary implementations for `std::cell`.
11
12use core::cell::{BorrowError, BorrowMutError, Cell, RefCell, UnsafeCell};
13
14wrap_from!([Copy] Cell);
15wrap_from!(RefCell);
16wrap_from!(UnsafeCell);
17
18lazy_just!(BorrowError, || {
19    // False positive:
20    #[cfg_attr(clippy, allow(let_and_return))]
21    {
22        let _rc = RefCell::new(());
23        let _bm = _rc.borrow_mut();
24        let _tb = _rc.try_borrow();
25        let ret = _rc.try_borrow().expect_err("reborrowed RefCell");
26        ret
27    }
28});
29lazy_just!(BorrowMutError, || {
30    // False positive:
31    #[cfg_attr(clippy, allow(let_and_return))]
32    {
33        let _rc = RefCell::new(());
34        let _bm = _rc.borrow_mut();
35        let _tb = _rc.try_borrow();
36        let ret = _rc.try_borrow_mut().expect_err("reborrowed RefCell");
37        ret
38    }
39});
40
41#[cfg(test)]
42mod test {
43    no_panic_test!(
44        cell => Cell<u8>,
45        ref_cell => RefCell<u8>,
46        unsafe_cell => UnsafeCell<u8>
47    );
48}