Skip to content

Commit

Permalink
Merge #324
Browse files Browse the repository at this point in the history
324: Fix clippy lints r=japaric a=Sh3Rm4n



Co-authored-by: Fabian Viöl <f.vioel@googlemail.com>
  • Loading branch information
bors[bot] and Sh3Rm4n authored Jan 7, 2021
2 parents e162a6f + 02488d8 commit 4e8e127
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 51 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,37 @@ jobs:
cargo check --target thumbv6m-none-eabi --features print-defmt
cargo check --target thumbv6m-none-eabi --features print-rtt
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: clippy
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: >
--workspace
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

mdbook:
strategy:
matrix:
Expand Down
65 changes: 30 additions & 35 deletions decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ pub fn check_version(version: &str) -> Result<(), String> {

impl Kind {
fn of(version: &str) -> Kind {
if version.contains('.') {
// "0.1"
Kind::Semver
} else if version.parse::<u64>().is_ok() {
// "1"
if version.contains('.') || version.parse::<u64>().is_ok() {
// "1" or "0.1"
Kind::Semver
} else {
// "e739d0ac703dfa629a159be329e8c62a1c3ed206" (should be)
Expand Down Expand Up @@ -175,7 +172,7 @@ impl Table {
}

fn _get(&self, index: usize) -> Result<(Option<Level>, &str), ()> {
let entry = self.entries.get(&index).ok_or_else(|| ())?;
let entry = self.entries.get(&index).ok_or(())?;
Ok((entry.string.tag.to_level(), &entry.string.string))
}

Expand All @@ -193,7 +190,7 @@ impl Table {
}
}

pub fn indices<'s>(&'s self) -> impl Iterator<Item = usize> + 's {
pub fn indices(&self) -> impl Iterator<Item = usize> + '_ {
self.entries.iter().filter_map(move |(idx, entry)| {
if entry.string.tag.to_level().is_some() {
Some(*idx)
Expand All @@ -208,7 +205,7 @@ impl Table {
}

/// Iterates over the raw symbols of the table entries
pub fn raw_symbols<'s>(&'s self) -> impl Iterator<Item = &'s str> + 's {
pub fn raw_symbols(&self) -> impl Iterator<Item = &str> + '_ {
self.entries.values().map(|s| &*s.raw_symbol)
}
}
Expand Down Expand Up @@ -304,6 +301,7 @@ impl fmt::Display for DisplayFrame<'_> {
struct Bool(AtomicBool);

impl Bool {
#[allow(clippy::declare_interior_mutable_const)]
const FALSE: Self = Self(AtomicBool::new(false));

fn set(&self, value: bool) {
Expand Down Expand Up @@ -443,7 +441,7 @@ pub fn decode<'t>(
/// Note that this will not change the Bitfield params in place, i.e. if `params` was sorted before
/// a call to this function, it won't be afterwards.
fn merge_bitfields(params: &mut Vec<Parameter>) {
if params.len() == 0 {
if params.is_empty() {
return;
}

Expand All @@ -454,18 +452,17 @@ fn merge_bitfields(params: &mut Vec<Parameter>) {
for index in 0..=max_index {
let mut bitfields_with_index = params
.iter()
.filter(|param| match (param.index, &param.ty) {
(i, Type::BitField(_)) if i == index => true,
_ => false,
})
.filter(
|param| matches!((param.index, &param.ty), (i, Type::BitField(_)) if i == index),
)
.peekable();

if bitfields_with_index.peek().is_some() {
let (smallest, largest) = get_max_bitfield_range(bitfields_with_index).unwrap();

// create new merged bitfield for this index
merged_bitfields.push(Parameter {
index: index,
index,
ty: Type::BitField(Range {
start: smallest,
end: largest,
Expand Down Expand Up @@ -565,7 +562,7 @@ impl<'t, 'b> Decoder<'t, 'b> {
}

fn get_variant(&mut self, format: &'t str) -> Result<&'t str, DecodeError> {
assert!(format.contains("|"));
assert!(format.contains('|'));
// NOTE nesting of enums, like "A|B(C|D)" is not possible; indirection is
// required: "A|B({:?})" where "{:?}" -> "C|D"
let num_variants = format.chars().filter(|c| *c == '|').count();
Expand Down Expand Up @@ -644,27 +641,25 @@ impl<'t, 'b> Decoder<'t, 'b> {
}
}
}
} else if is_first {
let mut old =
mem::replace(&mut self.format_list, Some(FormatList::Build { formats }));
let args = self.decode_format(format)?;
mem::swap(&mut self.format_list, &mut old);
formats = match old {
Some(FormatList::Build { formats, .. }) => formats,
_ => unreachable!(),
};
args
} else {
if is_first {
let mut old =
mem::replace(&mut self.format_list, Some(FormatList::Build { formats }));
let args = self.decode_format(format)?;
mem::swap(&mut self.format_list, &mut old);
formats = match old {
Some(FormatList::Build { formats, .. }) => formats,
_ => unreachable!(),
};
args
} else {
let formats = formats.clone();
let old = mem::replace(
&mut self.format_list,
Some(FormatList::Use { formats, cursor: 0 }),
);
let args = self.decode_format(format)?;
self.format_list = old;
args
}
let formats = formats.clone();
let old = mem::replace(
&mut self.format_list,
Some(FormatList::Use { formats, cursor: 0 }),
);
let args = self.decode_format(format)?;
self.format_list = old;
args
};

elements.push(FormatSliceElement { format, args });
Expand Down
2 changes: 1 addition & 1 deletion firmware/qemu/src/bin/assert-eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use defmt_semihosting as _; // global logger

#[entry]
fn main() -> ! {
defmt::assert_eq!({1 + 1}, { 2 });
defmt::assert_eq!({ 1 + 1 }, { 2 });

let x = 42;
defmt::debug_assert_eq!(x - 1, x + 1, "dev");
Expand Down
2 changes: 1 addition & 1 deletion firmware/qemu/src/bin/assert-ne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use defmt_semihosting as _; // global logger

#[entry]
fn main() -> ! {
defmt::assert_ne!({1 + 1}, { 3 });
defmt::assert_ne!({ 1 + 1 }, { 3 });

let x = 42;
defmt::debug_assert_ne!(x, x, "dev");
Expand Down
2 changes: 1 addition & 1 deletion firmware/qemu/src/bin/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use defmt_semihosting as _; // global logger

#[entry]
fn main() -> ! {
defmt::assert!({1 + 1} == { 2 });
defmt::assert!({ 1 + 1 } == { 2 });

let dev = false;
let release = false;
Expand Down
2 changes: 1 addition & 1 deletion firmware/qemu/src/bin/defmt-test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![no_std]
#![no_main]

use defmt_semihosting as _; // global logger
use core::u8::MAX;
use defmt_semihosting as _; // global logger

#[defmt_test::tests]
mod tests {
Expand Down
15 changes: 6 additions & 9 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ pub fn panic_handler(args: TokenStream, input: TokenStream) -> TokenStream {

let rety_is_ok = match &f.sig.output {
ReturnType::Default => false,
ReturnType::Type(_, ty) => match &**ty {
Type::Never(_) => true,
_ => false,
},
ReturnType::Type(_, ty) => matches!(&**ty, Type::Never(_)),
};

let ident = &f.sig.ident;
Expand Down Expand Up @@ -397,7 +394,7 @@ fn fields(
if named {
format.push_str(" {{ ");
} else {
format.push_str("(");
format.push('(');
}
let mut first = true;
for (i, f) in fs.iter().enumerate() {
Expand Down Expand Up @@ -440,7 +437,7 @@ fn fields(
if named {
format.push_str(" }}");
} else {
format.push_str(")");
format.push(')');
}
}
}
Expand Down Expand Up @@ -998,10 +995,10 @@ pub fn write(ts: TokenStream) -> TokenStream {
}
};

let args = write
let args: Vec<_> = write
.rest
.map(|(_, exprs)| exprs.into_iter().collect())
.unwrap_or(vec![]);
.unwrap_or_default();

let (pats, exprs) = match Codegen::new(&fragments, args.len(), write.litstr.span()) {
Ok(cg) => (cg.pats, cg.exprs),
Expand Down Expand Up @@ -1076,7 +1073,7 @@ struct Codegen {
}

impl Codegen {
fn new(fragments: &Vec<Fragment<'_>>, num_args: usize, span: Span2) -> parse::Result<Self> {
fn new(fragments: &[Fragment<'_>], num_args: usize, span: Span2) -> parse::Result<Self> {
let parsed_params = fragments
.iter()
.filter_map(|frag| match frag {
Expand Down
4 changes: 3 additions & 1 deletion parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ fn parse_param(mut input: &str, mode: ParserMode) -> Result<Param, Cow<'static,

// First, optional argument index.
let mut index = None;
let index_end = input.find(|c: char| !c.is_digit(10)).unwrap_or_else(|| input.len());
let index_end = input
.find(|c: char| !c.is_digit(10))
.unwrap_or_else(|| input.len());

if index_end != 0 {
index = Some(
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ where

/// `Debug2Format` constructor
#[allow(non_snake_case)]
pub fn Debug2Format<'a, N>(value: &'a dyn fmt::Debug) -> Debug2Format<'a, N>
pub fn Debug2Format<N>(value: &dyn fmt::Debug) -> Debug2Format<N>
where
N: ArrayLength<u8>,
{
Expand Down Expand Up @@ -788,7 +788,7 @@ where

/// `Display2Format` constructor.
#[allow(non_snake_case)]
pub fn Display2Format<'a, N>(value: &'a dyn fmt::Display) -> Display2Format<'a, N>
pub fn Display2Format<N>(value: &dyn fmt::Display) -> Display2Format<N>
where
N: ArrayLength<u8>,
{
Expand Down

0 comments on commit 4e8e127

Please sign in to comment.