Skip to content

Commit ce538b2

Browse files
bors[bot]m-ou-se
andauthored
Merge #175
175: Enable the missing_inline_in_public_items clippy lint. r=jonas-schievink a=m-ou-se This adds `#![deny(clippy::missing_inline_in_public_items)]` to make sure all functions in this crate are marked `#[inline]`, unless they are explicitly marked with `#[allow(clippy::missing_inline_in_public_items)]`. Only three functions in this crate are not `#[inline]`: - `write_words` - `write_all` - `write_aligned` Additionally, the derived `Debug` impl's also have a non-inline implementations. This unfortunately means that the allow attribute also needs to added to any types deriving `Debug`. See also #171 and #174 (comment). Co-authored-by: Mara Bos <[email protected]>
2 parents 3607c6c + 3eebbfc commit ce538b2

File tree

9 files changed

+31
-0
lines changed

9 files changed

+31
-0
lines changed

src/itm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use aligned::{Aligned, A4};
99
use crate::peripheral::itm::Stim;
1010

1111
// NOTE assumes that `bytes` is 32-bit aligned
12+
#[allow(clippy::missing_inline_in_public_items)]
1213
unsafe fn write_words(stim: &mut Stim, bytes: &[u32]) {
1314
let mut p = bytes.as_ptr();
1415
for _ in 0..bytes.len() {
@@ -30,6 +31,7 @@ impl<'p> fmt::Write for Port<'p> {
3031

3132
/// Writes a `buffer` to the ITM `port`
3233
#[allow(clippy::cast_ptr_alignment)]
34+
#[allow(clippy::missing_inline_in_public_items)]
3335
#[allow(clippy::transmute_ptr_to_ptr)]
3436
pub fn write_all(port: &mut Stim, buffer: &[u8]) {
3537
unsafe {
@@ -90,6 +92,7 @@ pub fn write_all(port: &mut Stim, buffer: &[u8]) {
9092
/// itm::write_aligned(&itm.stim[0], &Aligned(*b"Hello, world!\n"));
9193
/// ```
9294
#[allow(clippy::cast_ptr_alignment)]
95+
#[allow(clippy::missing_inline_in_public_items)]
9396
#[allow(clippy::transmute_ptr_to_ptr)]
9497
pub fn write_aligned(port: &mut Stim, buffer: &Aligned<A4, [u8]>) {
9598
unsafe {

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@
3535
#![allow(clippy::identity_op)]
3636
#![allow(clippy::missing_safety_doc)]
3737

38+
// This makes clippy warn about public functions which are not #[inline].
39+
//
40+
// Almost all functions in this crate result in trivial or even no assembly.
41+
// These functions should be #[inline].
42+
//
43+
// If you do add a function that's not supposed to be #[inline], you can add
44+
// #[allow(clippy::missing_inline_in_public_items)] in front of it to add an
45+
// exception to clippy's rules.
46+
//
47+
// This should be done in case of:
48+
// - A function containing non-trivial logic (such as itm::write_all); or
49+
// - A generated #[derive(Debug)] function (in which case the attribute needs
50+
// to be applied to the struct).
51+
#![deny(clippy::missing_inline_in_public_items)]
52+
3853
extern crate aligned;
3954
extern crate bare_metal;
4055
extern crate volatile_register;

src/peripheral/cpuid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub struct RegisterBlock {
6666

6767
/// Type of cache to select on CSSELR writes.
6868
#[cfg(not(armv6m))]
69+
#[allow(clippy::missing_inline_in_public_items)]
6970
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7071
pub enum CsselrCacheType {
7172
/// Select DCache or unified cache

src/peripheral/scb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub struct RegisterBlock {
9797

9898
/// FPU access mode
9999
#[cfg(has_fpu)]
100+
#[allow(clippy::missing_inline_in_public_items)]
100101
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
101102
pub enum FpuAccessMode {
102103
/// FPU is not accessible
@@ -193,6 +194,7 @@ impl SCB {
193194
}
194195

195196
/// Processor core exceptions (internal interrupts)
197+
#[allow(clippy::missing_inline_in_public_items)]
196198
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
197199
pub enum Exception {
198200
/// Non maskable interrupt
@@ -258,6 +260,7 @@ impl Exception {
258260
}
259261

260262
/// Active exception number
263+
#[allow(clippy::missing_inline_in_public_items)]
261264
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
262265
pub enum VectActive {
263266
/// Thread mode
@@ -725,6 +728,7 @@ impl SCB {
725728
}
726729

727730
/// System handlers, exceptions with configurable priority
731+
#[allow(clippy::missing_inline_in_public_items)]
728732
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
729733
pub enum SystemHandler {
730734
// NonMaskableInt, // priority is fixed

src/peripheral/syst.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct RegisterBlock {
1818
}
1919

2020
/// SysTick clock source
21+
#[allow(clippy::missing_inline_in_public_items)]
2122
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2223
pub enum SystClkSource {
2324
/// Core-provided clock

src/register/apsr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Application Program Status Register
22
33
/// Application Program Status Register
4+
#[allow(clippy::missing_inline_in_public_items)]
45
#[derive(Clone, Copy, Debug)]
56
pub struct Apsr {
67
bits: u32,

src/register/control.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Control register
22
33
/// Control register
4+
#[allow(clippy::missing_inline_in_public_items)]
45
#[derive(Clone, Copy, Debug)]
56
pub struct Control {
67
bits: u32,
@@ -81,6 +82,7 @@ impl Control {
8182
}
8283

8384
/// Thread mode privilege level
85+
#[allow(clippy::missing_inline_in_public_items)]
8486
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8587
pub enum Npriv {
8688
/// Privileged
@@ -104,6 +106,7 @@ impl Npriv {
104106
}
105107

106108
/// Currently active stack pointer
109+
#[allow(clippy::missing_inline_in_public_items)]
107110
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
108111
pub enum Spsel {
109112
/// MSP is the current stack pointer
@@ -127,6 +130,7 @@ impl Spsel {
127130
}
128131

129132
/// Whether context floating-point is currently active
133+
#[allow(clippy::missing_inline_in_public_items)]
130134
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
131135
pub enum Fpca {
132136
/// Floating-point context active.

src/register/faultmask.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Fault Mask Register
22
33
/// All exceptions are ...
4+
#[allow(clippy::missing_inline_in_public_items)]
45
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
56
pub enum Faultmask {
67
/// Active

src/register/primask.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Priority mask register
22
33
/// All exceptions with configurable priority are ...
4+
#[allow(clippy::missing_inline_in_public_items)]
45
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
56
pub enum Primask {
67
/// Active

0 commit comments

Comments
 (0)