Skip to content

Commit

Permalink
fix(trace): wacky lifetime issues with writers (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Jan 21, 2024
1 parent 2f72a91 commit f578d5f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
18 changes: 9 additions & 9 deletions hal-x86_64/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'a> Lock<'a> {
}
}

impl<'a, B> Lock<'a, B> {
impl<B> Lock<'_, B> {
/// Set the serial port's baud rate for this `Lock`.
///
/// When the `Lock` is dropped, the baud rate will be set to the previous value.
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<'a, B> Lock<'a, B> {
}
}

impl<'a> io::Read for Lock<'a, Blocking> {
impl io::Read for Lock<'_, Blocking> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
for byte in buf.iter_mut() {
*byte = self.inner.read_blocking();
Expand All @@ -290,7 +290,7 @@ impl<'a> io::Read for Lock<'a, Blocking> {
}
}

impl<'a> io::Read for Lock<'a, Nonblocking> {
impl io::Read for Lock<'_, Nonblocking> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
for byte in buf.iter_mut() {
*byte = self.inner.read_nonblocking()?;
Expand All @@ -299,7 +299,7 @@ impl<'a> io::Read for Lock<'a, Nonblocking> {
}
}

impl<'a> io::Write for Lock<'a, Blocking> {
impl io::Write for Lock<'_, Blocking> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
for &byte in buf.iter() {
self.inner.write_blocking(byte)
Expand All @@ -313,7 +313,7 @@ impl<'a> io::Write for Lock<'a, Blocking> {
}
}

impl<'a> fmt::Write for Lock<'a, Blocking> {
impl fmt::Write for Lock<'_, Blocking> {
fn write_str(&mut self, s: &str) -> fmt::Result {
for byte in s.bytes() {
self.inner.write_blocking(byte)
Expand All @@ -322,7 +322,7 @@ impl<'a> fmt::Write for Lock<'a, Blocking> {
}
}

impl<'a> io::Write for Lock<'a, Nonblocking> {
impl io::Write for Lock<'_, Nonblocking> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
for &byte in buf.iter() {
self.inner.write_nonblocking(byte)?;
Expand All @@ -336,7 +336,7 @@ impl<'a> io::Write for Lock<'a, Nonblocking> {
}
}

impl<'a> LockInner<'a> {
impl LockInner<'_> {
#[inline(always)]
fn is_write_ready(&self) -> bool {
self.inner.is_write_ready()
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<'a> LockInner<'a> {
}
}

impl<'a> Drop for LockInner<'a> {
impl Drop for LockInner<'_> {
fn drop(&mut self) {
if let Some(divisor) = self.prev_divisor {
// Disable IRQs.
Expand All @@ -385,7 +385,7 @@ impl<'a> Drop for LockInner<'a> {
}
}

impl<'a> mycelium_trace::writer::MakeWriter<'a> for &'static Port {
impl<'a> mycelium_trace::writer::MakeWriter<'a> for &Port {
type Writer = Lock<'a, Blocking>;
fn make_writer(&'a self) -> Self::Writer {
self.lock()
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ impl BootInfo for BootloaderApiBootInfo {
let com1 = AnsiEscapes::new(com1);
com1.with_filter(serial_filter as for<'a, 'b> fn(&'a tracing::Metadata<'b>) -> bool)
});
Subscriber::display_only(display_writer).with_serial(serial)
Subscriber::<_, Option<FilteredSerial>>::display_only(display_writer)
.with_serial(serial)
});

Some(tracing::Dispatch::from_static(collector))
}

Expand Down
2 changes: 1 addition & 1 deletion trace/src/embedded_graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const fn unpack_point(u: u64) -> Point {
Point { x, y }
}

impl<'mk, D> fmt::Write for TextWriter<'mk, D>
impl<D> fmt::Write for TextWriter<'_, D>
where
D: Draw,
{
Expand Down
24 changes: 14 additions & 10 deletions trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ struct Visitor<'writer, W> {

impl<D> Default for Subscriber<D>
where
for<'a> D: MakeWriter<'a>,
for<'a> D: MakeWriter<'a> + 'static,
for<'a> <D as MakeWriter<'a>>::Writer: SetColor,
D: Default,
{
fn default() -> Self {
Expand All @@ -92,8 +93,10 @@ const _ACTUAL_ID_BITS: u64 = !(SERIAL_BIT | VGA_BIT);
impl<D, S> Subscriber<D, S> {
pub fn display_only(display: D) -> Self
where
for<'a> D: MakeWriter<'a>,
for<'a> S: MakeWriter<'a>,
for<'a> D: MakeWriter<'a> + 'static,
// for<'a> <D as MakeWriter<'a>>::Writer: SetColor,
for<'a> S: MakeWriter<'a> + 'static,
// for<'a> <S as MakeWriter<'a>>::Writer: SetColor,
S: Default,
{
Self {
Expand All @@ -103,9 +106,10 @@ impl<D, S> Subscriber<D, S> {
}
}

pub fn with_serial(self, port: S) -> Subscriber<D, S>
pub fn with_serial<S2>(self, port: S2) -> Subscriber<D, S2>
where
for<'a> S: MakeWriter<'a>,
for<'a> S2: MakeWriter<'a> + 'static,
// for<'a> <S2 as MakeWriter<'a>>::Writer: SetColor,
{
Subscriber {
serial: Output::new(port, Self::SERIAL_INDENT_CFG),
Expand Down Expand Up @@ -139,12 +143,12 @@ impl<D, S> Subscriber<D, S> {
}
}

impl<D, S, DW, SW> tracing_core::Collect for Subscriber<D, S>
impl<D, S> tracing_core::Collect for Subscriber<D, S>
where
for<'a> D: MakeWriter<'a, Writer = DW> + 'static,
DW: Write + SetColor,
for<'a> S: MakeWriter<'a, Writer = SW> + 'static,
SW: Write + SetColor,
for<'a> D: MakeWriter<'a> + 'static,
for<'a> <D as MakeWriter<'a>>::Writer: SetColor,
for<'a> S: MakeWriter<'a> + 'static,
for<'a> <S as MakeWriter<'a>>::Writer: SetColor,
{
fn enabled(&self, meta: &Metadata) -> bool {
self.display.enabled(meta) || self.serial.enabled(meta)
Expand Down

0 comments on commit f578d5f

Please sign in to comment.