-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add collapse_debug field to fmt.rs, in order to fix location informat…
…ion (#207)
- Loading branch information
1 parent
d819259
commit 7dc3aae
Showing
3 changed files
with
58 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)*) => { | ||
{ | ||
|
@@ -37,6 +18,7 @@ macro_rules! assert { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! assert_eq { | ||
($($x:tt)*) => { | ||
{ | ||
|
@@ -48,6 +30,7 @@ macro_rules! assert_eq { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! assert_ne { | ||
($($x:tt)*) => { | ||
{ | ||
|
@@ -59,6 +42,7 @@ macro_rules! assert_ne { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! debug_assert { | ||
($($x:tt)*) => { | ||
{ | ||
|
@@ -70,6 +54,7 @@ macro_rules! debug_assert { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! debug_assert_eq { | ||
($($x:tt)*) => { | ||
{ | ||
|
@@ -81,6 +66,7 @@ macro_rules! debug_assert_eq { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! debug_assert_ne { | ||
($($x:tt)*) => { | ||
{ | ||
|
@@ -92,6 +78,7 @@ macro_rules! debug_assert_ne { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! todo { | ||
($($x:tt)*) => { | ||
{ | ||
|
@@ -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)*) => { | ||
{ | ||
|
@@ -125,6 +118,7 @@ macro_rules! panic { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! trace { | ||
($s:literal $(, $x:expr)* $(,)?) => { | ||
{ | ||
|
@@ -138,6 +132,7 @@ macro_rules! trace { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! debug { | ||
($s:literal $(, $x:expr)* $(,)?) => { | ||
{ | ||
|
@@ -151,6 +146,7 @@ macro_rules! debug { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! info { | ||
($s:literal $(, $x:expr)* $(,)?) => { | ||
{ | ||
|
@@ -164,6 +160,7 @@ macro_rules! info { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! warn { | ||
($s:literal $(, $x:expr)* $(,)?) => { | ||
{ | ||
|
@@ -177,6 +174,7 @@ macro_rules! warn { | |
}; | ||
} | ||
|
||
#[collapse_debuginfo(yes)] | ||
macro_rules! error { | ||
($s:literal $(, $x:expr)* $(,)?) => { | ||
{ | ||
|
@@ -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) { | ||
|
@@ -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 GitHub Actions / clippypub(crate) struct inside private module
|
||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[toolchain] | ||
channel = "1.75" | ||
channel = "1.79" | ||
components = ["clippy"] |