Skip to content

Commit

Permalink
Add collapse_debug field to fmt.rs, in order to fix location informat…
Browse files Browse the repository at this point in the history
…ion (#207)
  • Loading branch information
MathiasKoch authored Jun 26, 2024
1 parent d819259 commit 7dc3aae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This workspace uses `cargo-release` to do workspace releases to crates.io. It ca

## About

- Minimum rustc version 1.52
- Minimum rustc version 1.79
- Tested and built using stable toolchain

## Supported Crates
Expand Down
85 changes: 56 additions & 29 deletions atat/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
// MIT License

// Copyright (c) 2020 Dario Nieuwenhuis <[email protected]>

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#![macro_use]
#![allow(unused_macros)]
#![allow(unused)]

use core::fmt::{Debug, Display, LowerHex};

#[cfg(all(feature = "defmt", feature = "log"))]
compile_error!("You may not enable both `defmt` and `log` features.");

#[collapse_debuginfo(yes)]
macro_rules! assert {
($($x:tt)*) => {
{
Expand All @@ -37,6 +18,7 @@ macro_rules! assert {
};
}

#[collapse_debuginfo(yes)]
macro_rules! assert_eq {
($($x:tt)*) => {
{
Expand All @@ -48,6 +30,7 @@ macro_rules! assert_eq {
};
}

#[collapse_debuginfo(yes)]
macro_rules! assert_ne {
($($x:tt)*) => {
{
Expand All @@ -59,6 +42,7 @@ macro_rules! assert_ne {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug_assert {
($($x:tt)*) => {
{
Expand All @@ -70,6 +54,7 @@ macro_rules! debug_assert {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug_assert_eq {
($($x:tt)*) => {
{
Expand All @@ -81,6 +66,7 @@ macro_rules! debug_assert_eq {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug_assert_ne {
($($x:tt)*) => {
{
Expand All @@ -92,6 +78,7 @@ macro_rules! debug_assert_ne {
};
}

#[collapse_debuginfo(yes)]
macro_rules! todo {
($($x:tt)*) => {
{
Expand All @@ -103,17 +90,23 @@ macro_rules! todo {
};
}

#[cfg(not(feature = "defmt"))]
#[collapse_debuginfo(yes)]
macro_rules! unreachable {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt"))]
::core::unreachable!($($x)*);
#[cfg(feature = "defmt")]
::defmt::unreachable!($($x)*);
}
::core::unreachable!($($x)*)
};
}

#[cfg(feature = "defmt")]
#[collapse_debuginfo(yes)]
macro_rules! unreachable {
($($x:tt)*) => {
::defmt::unreachable!($($x)*)
};
}

#[collapse_debuginfo(yes)]
macro_rules! panic {
($($x:tt)*) => {
{
Expand All @@ -125,6 +118,7 @@ macro_rules! panic {
};
}

#[collapse_debuginfo(yes)]
macro_rules! trace {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -138,6 +132,7 @@ macro_rules! trace {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -151,6 +146,7 @@ macro_rules! debug {
};
}

#[collapse_debuginfo(yes)]
macro_rules! info {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -164,6 +160,7 @@ macro_rules! info {
};
}

#[collapse_debuginfo(yes)]
macro_rules! warn {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -177,6 +174,7 @@ macro_rules! warn {
};
}

#[collapse_debuginfo(yes)]
macro_rules! error {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -191,13 +189,15 @@ macro_rules! error {
}

#[cfg(feature = "defmt")]
#[collapse_debuginfo(yes)]
macro_rules! unwrap {
($($x:tt)*) => {
::defmt::unwrap!($($x)*)
};
}

#[cfg(not(feature = "defmt"))]
#[collapse_debuginfo(yes)]
macro_rules! unwrap {
($arg:expr) => {
match $crate::fmt::Try::into_result($arg) {
Expand Down Expand Up @@ -245,3 +245,30 @@ impl<T, E> Try for Result<T, E> {
self
}
}

pub(crate) struct Bytes<'a>(pub &'a [u8]);

Check warning on line 249 in atat/src/fmt.rs

View workflow job for this annotation

GitHub Actions / clippy

pub(crate) struct inside private module

warning: pub(crate) struct inside private module --> atat/src/fmt.rs:249:1 | 249 | pub(crate) struct Bytes<'a>(pub &'a [u8]); | ----------^^^^^^^^^^^^^ | | | help: consider using: `pub` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate = note: `-W clippy::redundant-pub-crate` implied by `-W clippy::nursery` = help: to override `-W clippy::nursery` add `#[allow(clippy::redundant_pub_crate)]`

impl<'a> Debug for Bytes<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#02x?}", self.0)
}
}

impl<'a> Display for Bytes<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#02x?}", self.0)
}
}

impl<'a> LowerHex for Bytes<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#02x?}", self.0)
}
}

#[cfg(feature = "defmt")]
impl<'a> defmt::Format for Bytes<'a> {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "{:02x}", self.0)
}
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.75"
channel = "1.79"
components = ["clippy"]

0 comments on commit 7dc3aae

Please sign in to comment.