Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix or allow all clippy warnings #361

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions firmware/defmt-rtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,11 @@ impl Channel {
if cursor + len > SIZE {
// split memcpy
let pivot = SIZE - cursor;
ptr::copy_nonoverlapping(
bytes.as_ptr(),
self.buffer.add(cursor.into()),
pivot.into(),
);
ptr::copy_nonoverlapping(
bytes.as_ptr().add(pivot.into()),
self.buffer,
(len - pivot).into(),
);
ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), pivot);
ptr::copy_nonoverlapping(bytes.as_ptr().add(pivot), self.buffer, len - pivot);
} else {
// single memcpy
ptr::copy_nonoverlapping(
bytes.as_ptr(),
self.buffer.add(cursor.into()),
len.into(),
);
ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), len);
}
}
self.write
Expand All @@ -167,23 +155,11 @@ impl Channel {
if cursor + len > SIZE {
// split memcpy
let pivot = SIZE - cursor;
ptr::copy_nonoverlapping(
bytes.as_ptr(),
self.buffer.add(cursor.into()),
pivot.into(),
);
ptr::copy_nonoverlapping(
bytes.as_ptr().add(pivot.into()),
self.buffer,
(len - pivot).into(),
);
ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), pivot);
ptr::copy_nonoverlapping(bytes.as_ptr().add(pivot), self.buffer, len - pivot);
} else {
// single memcpy
ptr::copy_nonoverlapping(
bytes.as_ptr(),
self.buffer.add(cursor.into()),
len.into(),
);
ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), len);
}
}
self.write
Expand Down
4 changes: 2 additions & 2 deletions firmware/qemu/src/bin/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use defmt_semihosting as _; // global logger
#[entry]
fn main() -> ! {
let answer = 42;
let foo: u32 = match answer {
let value: u32 = match answer {
1 => 123,
2 => 456,
_ => defmt::panic!("The answer is {=?}", answer),
};
defmt::panic!("should never get here {=?}", foo);
defmt::panic!("should never get here {=?}", value);
}

// like `panic-semihosting` but doesn't print to stdout (that would corrupt the defmt stream)
Expand Down
1 change: 1 addition & 0 deletions src/leb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// LEB128-encodes a `usize` value into `buf`.
///
/// This handles 32-bit and 64-bit `usize`.
#[allow(clippy::needless_range_loop)]
pub(crate) fn leb64(x: usize, buf: &mut [u8; 10]) -> usize {
let mut low = x as u32;
// Shift by 16 twice, to avoid a panic/error when shifting a 32-bit usize by 32 bits.
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub struct Formatter<'a> {
impl InternalFormatter {
/// Only for testing
#[cfg(feature = "unstable-test")]
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
bytes: vec![],
Expand Down Expand Up @@ -621,11 +622,19 @@ mod test_only {
#[doc(hidden)]
impl super::InternalFormatter {
/// Implementation detail
///
/// # Safety
///
/// This is always safe to call and will panic. It only exists to match the non-test API.
pub unsafe fn from_raw(_: NonNull<dyn Write>) -> Self {
unreachable!()
}

/// Implementation detail
///
/// # Safety
///
/// This is always safe to call and will panic. It only exists to match the non-test API.
pub unsafe fn into_raw(self) -> NonNull<dyn Write> {
unreachable!()
}
Expand Down
24 changes: 12 additions & 12 deletions tests/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn check_format_implementation(val: &(impl Format + ?Sized), expected_encoding:
#[test]
fn write() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(g, "The answer is {=u8}", 42);
Expand All @@ -70,7 +70,7 @@ fn write() {
]
);

let ref mut f2 = InternalFormatter::new();
let f2 = &mut InternalFormatter::new();
let g2 = Formatter { inner: f2 };
write!(g2, "The answer is {=?}", 42u8);
assert_eq!(
Expand All @@ -86,7 +86,7 @@ fn write() {
#[test]
fn booleans_max_num_bool_flags() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(
Expand All @@ -106,7 +106,7 @@ fn booleans_max_num_bool_flags() {
#[test]
fn booleans_less_than_max_num_bool_flags() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(
Expand All @@ -126,7 +126,7 @@ fn booleans_less_than_max_num_bool_flags() {
#[test]
fn booleans_more_than_max_num_bool_flags() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(g, "encode 9 bools {=bool} {=bool} {=bool} {=bool} {=bool} {=bool} {=bool} {=bool} {=bool} {=bool}",
Expand All @@ -144,7 +144,7 @@ fn booleans_more_than_max_num_bool_flags() {
#[test]
fn booleans_mixed() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(
Expand All @@ -165,7 +165,7 @@ fn booleans_mixed() {
#[test]
fn booleans_mixed_no_trailing_bool() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(g, "encode mixed bools {=bool} {=u8}", false, 42);
Expand All @@ -181,7 +181,7 @@ fn booleans_mixed_no_trailing_bool() {
#[test]
fn bitfields_mixed() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(
Expand All @@ -203,7 +203,7 @@ fn bitfields_mixed() {
#[test]
fn bitfields_across_octets() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(g, "bitfields {0=0..7} {0=9..14}", 0b0110_0011_1101_0010u16);
Expand All @@ -220,7 +220,7 @@ fn bitfields_across_octets() {
#[test]
fn bitfields_truncate_lower() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(
Expand All @@ -240,7 +240,7 @@ fn bitfields_truncate_lower() {
#[test]
fn bitfields_assert_range_exclusive() {
let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(g, "bitfields {0=6..8}", 0b1010_0101u8,);
Expand Down Expand Up @@ -280,7 +280,7 @@ fn boolean_struct_mixed() {
}

let index = fetch_string_index();
let ref mut f = InternalFormatter::new();
let f = &mut InternalFormatter::new();
let g = Formatter { inner: f };

write!(
Expand Down