Skip to content

Commit adea799

Browse files
committed
Remove unneeded allow attributes for pool macros.
1 parent 7bb2f71 commit adea799

File tree

5 files changed

+164
-191
lines changed

5 files changed

+164
-191
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2525
### Fixed
2626

2727
- Fixed clippy lints.
28-
- Fixed `{arc,box,object}_pool!` emitting clippy lints for `CamelCase` and `SNAKE_CASE`.
28+
- Fixed `{arc,box,object}_pool!` emitting clippy lints.
2929
- Fixed the list of implemented data structures in the crate docs, by adding `Deque`,
3030
`HistoryBuffer` and `SortedLinkedList` to the list.
3131

src/pool.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
//!
2020
//! - test program:
2121
//!
22-
//! ``` no_run
22+
//! ```no_run
2323
//! use heapless::box_pool;
2424
//!
25-
//! box_pool!(P: ()); // or `arc_pool!` or `object_pool!`
25+
//! box_pool!(MyBoxPool: ()); // or `arc_pool!` or `object_pool!`
2626
//!
2727
//! bkpt();
28-
//! let res = P.alloc(());
28+
//! let res = MyBoxPool.alloc(());
2929
//! bkpt();
3030
//!
3131
//! if let Ok(boxed) = res {

src/pool/arc.rs

+52-61
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
//! ```
66
//! use heapless::{arc_pool, pool::arc::{Arc, ArcBlock}};
77
//!
8-
//! arc_pool!(P: u128);
8+
//! arc_pool!(MyArcPool: u128);
99
//!
1010
//! // cannot allocate without first giving memory blocks to the pool
11-
//! assert!(P.alloc(42).is_err());
11+
//! assert!(MyArcPool.alloc(42).is_err());
1212
//!
1313
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
1414
//! let block: &'static mut ArcBlock<u128> = unsafe {
15-
//! static mut B: ArcBlock<u128> = ArcBlock::new();
16-
//! &mut B
15+
//! static mut BLOCK: ArcBlock<u128> = ArcBlock::new();
16+
//! &mut BLOCK
1717
//! };
1818
//!
19-
//! P.manage(block);
19+
//! MyArcPool.manage(block);
2020
//!
21-
//! let arc = P.alloc(1).unwrap();
21+
//! let arc = MyArcPool.alloc(1).unwrap();
2222
//!
2323
//! // number of smart pointers is limited to the number of blocks managed by the pool
24-
//! let res = P.alloc(2);
24+
//! let res = MyArcPool.alloc(2);
2525
//! assert!(res.is_err());
2626
//!
2727
//! // but cloning does not consume an `ArcBlock`
@@ -34,7 +34,7 @@
3434
//! drop(arc); // release memory
3535
//!
3636
//! // it's now possible to allocate a new `Arc` smart pointer
37-
//! let res = P.alloc(3);
37+
//! let res = MyArcPool.alloc(3);
3838
//!
3939
//! assert!(res.is_ok());
4040
//! ```
@@ -47,7 +47,7 @@
4747
//! ```
4848
//! use heapless::{arc_pool, pool::arc::ArcBlock};
4949
//!
50-
//! arc_pool!(P: u128);
50+
//! arc_pool!(MyArcPool: u128);
5151
//!
5252
//! const POOL_CAPACITY: usize = 8;
5353
//!
@@ -58,7 +58,7 @@
5858
//! };
5959
//!
6060
//! for block in blocks {
61-
//! P.manage(block);
61+
//! MyArcPool.manage(block);
6262
//! }
6363
//! ```
6464
@@ -83,18 +83,16 @@ use super::treiber::{NonNullPtr, Stack, UnionNode};
8383
#[macro_export]
8484
macro_rules! arc_pool {
8585
($name:ident: $data_type:ty) => {
86-
#[allow(non_camel_case_types)]
8786
pub struct $name;
8887

8988
impl $crate::pool::arc::ArcPool for $name {
9089
type Data = $data_type;
9190

9291
fn singleton() -> &'static $crate::pool::arc::ArcPoolImpl<$data_type> {
93-
#[allow(non_upper_case_globals)]
94-
static $name: $crate::pool::arc::ArcPoolImpl<$data_type> =
92+
static POOL: $crate::pool::arc::ArcPoolImpl<$data_type> =
9593
$crate::pool::arc::ArcPoolImpl::new();
9694

97-
&$name
95+
&POOL
9896
}
9997
}
10098

@@ -386,67 +384,67 @@ mod tests {
386384

387385
#[test]
388386
fn cannot_alloc_if_empty() {
389-
arc_pool!(P: i32);
387+
arc_pool!(MyArcPool: i32);
390388

391-
assert_eq!(Err(42), P.alloc(42),);
389+
assert_eq!(Err(42), MyArcPool.alloc(42),);
392390
}
393391

394392
#[test]
395393
fn can_alloc_if_manages_one_block() {
396-
arc_pool!(P: i32);
394+
arc_pool!(MyArcPool: i32);
397395

398396
let block = unsafe {
399-
static mut B: ArcBlock<i32> = ArcBlock::new();
400-
&mut B
397+
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
398+
&mut BLOCK
401399
};
402-
P.manage(block);
400+
MyArcPool.manage(block);
403401

404-
assert_eq!(42, *P.alloc(42).unwrap());
402+
assert_eq!(42, *MyArcPool.alloc(42).unwrap());
405403
}
406404

407405
#[test]
408406
fn alloc_drop_alloc() {
409-
arc_pool!(P: i32);
407+
arc_pool!(MyArcPool: i32);
410408

411409
let block = unsafe {
412-
static mut B: ArcBlock<i32> = ArcBlock::new();
413-
&mut B
410+
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
411+
&mut BLOCK
414412
};
415-
P.manage(block);
413+
MyArcPool.manage(block);
416414

417-
let arc = P.alloc(1).unwrap();
415+
let arc = MyArcPool.alloc(1).unwrap();
418416

419417
drop(arc);
420418

421-
assert_eq!(2, *P.alloc(2).unwrap());
419+
assert_eq!(2, *MyArcPool.alloc(2).unwrap());
422420
}
423421

424422
#[test]
425423
fn strong_count_starts_at_one() {
426-
arc_pool!(P: i32);
424+
arc_pool!(MyArcPool: i32);
427425

428426
let block = unsafe {
429-
static mut B: ArcBlock<i32> = ArcBlock::new();
430-
&mut B
427+
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
428+
&mut BLOCK
431429
};
432-
P.manage(block);
430+
MyArcPool.manage(block);
433431

434-
let arc = P.alloc(1).ok().unwrap();
432+
let arc = MyArcPool.alloc(1).ok().unwrap();
435433

436434
assert_eq!(1, arc.inner().strong.load(Ordering::Relaxed));
437435
}
438436

439437
#[test]
440438
fn clone_increases_strong_count() {
441-
arc_pool!(P: i32);
439+
arc_pool!(MyArcPool: i32);
442440

443441
let block = unsafe {
444-
static mut B: ArcBlock<i32> = ArcBlock::new();
445-
&mut B
442+
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
443+
&mut BLOCK
446444
};
447-
P.manage(block);
445+
MyArcPool.manage(block);
448446

449-
let arc = P.alloc(1).ok().unwrap();
447+
let arc = MyArcPool.alloc(1).ok().unwrap();
450448

451449
let before = arc.inner().strong.load(Ordering::Relaxed);
452450

@@ -459,15 +457,15 @@ mod tests {
459457

460458
#[test]
461459
fn drop_decreases_strong_count() {
462-
arc_pool!(P: i32);
460+
arc_pool!(MyArcPool: i32);
463461

464462
let block = unsafe {
465-
static mut B: ArcBlock<i32> = ArcBlock::new();
466-
&mut B
463+
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
464+
&mut BLOCK
467465
};
468-
P.manage(block);
466+
MyArcPool.manage(block);
469467

470-
let arc = P.alloc(1).ok().unwrap();
468+
let arc = MyArcPool.alloc(1).ok().unwrap();
471469
let arc2 = arc.clone();
472470

473471
let before = arc.inner().strong.load(Ordering::Relaxed);
@@ -482,23 +480,23 @@ mod tests {
482480
fn runs_destructor_exactly_once_when_strong_count_reaches_zero() {
483481
static COUNT: AtomicUsize = AtomicUsize::new(0);
484482

485-
pub struct S;
483+
pub struct MyStruct;
486484

487-
impl Drop for S {
485+
impl Drop for MyStruct {
488486
fn drop(&mut self) {
489487
COUNT.fetch_add(1, Ordering::Relaxed);
490488
}
491489
}
492490

493-
arc_pool!(P: S);
491+
arc_pool!(MyArcPool: MyStruct);
494492

495493
let block = unsafe {
496-
static mut B: ArcBlock<S> = ArcBlock::new();
497-
&mut B
494+
static mut BLOCK: ArcBlock<MyStruct> = ArcBlock::new();
495+
&mut BLOCK
498496
};
499-
P.manage(block);
497+
MyArcPool.manage(block);
500498

501-
let arc = P.alloc(S).ok().unwrap();
499+
let arc = MyArcPool.alloc(MyStruct).ok().unwrap();
502500

503501
assert_eq!(0, COUNT.load(Ordering::Relaxed));
504502

@@ -512,24 +510,17 @@ mod tests {
512510
#[repr(align(4096))]
513511
pub struct Zst4096;
514512

515-
arc_pool!(P: Zst4096);
513+
arc_pool!(MyArcPool: Zst4096);
516514

517515
let block = unsafe {
518-
static mut B: ArcBlock<Zst4096> = ArcBlock::new();
519-
&mut B
516+
static mut BLOCK: ArcBlock<Zst4096> = ArcBlock::new();
517+
&mut BLOCK
520518
};
521-
P.manage(block);
519+
MyArcPool.manage(block);
522520

523-
let arc = P.alloc(Zst4096).ok().unwrap();
521+
let arc = MyArcPool.alloc(Zst4096).ok().unwrap();
524522

525523
let raw = &*arc as *const Zst4096;
526524
assert_eq!(0, raw as usize % 4096);
527525
}
528-
529-
#[test]
530-
fn arc_pool_case() {
531-
// https://github.com/rust-embedded/heapless/issues/411
532-
arc_pool!(CamelCaseType: u128);
533-
arc_pool!(SCREAMING_SNAKE_CASE_TYPE: u128);
534-
}
535526
}

0 commit comments

Comments
 (0)