Skip to content

Commit

Permalink
feat(diagnostic): fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lquerel committed Apr 24, 2024
1 parent 92ac117 commit ca69fbe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
2 changes: 2 additions & 0 deletions crates/weaver_common/allowed-external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# This is used with cargo-check-external-types to reduce the surface area of downstream crates from
# the public API. Ideally this can have a few exceptions as possible.
allowed_external_types = [
"miette::protocol::Diagnostic",
"miette::eyreish::Report",
]
18 changes: 9 additions & 9 deletions crates/weaver_common/examples/diag_service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

//!
//! An example that demonstrates how to use the diagnostic service.
use crate::DiagnosticMessages::{MyAdvice, MyError, MyMessage, MyWarning};
use crate::DiagnosticMessages::{AnAdvice, Message, MyError, TheWarning};
use miette::{Diagnostic, NamedSource, SourceSpan};
use thiserror::Error;
use weaver_common::diag::channel::DiagChannel;
Expand Down Expand Up @@ -35,7 +35,7 @@ enum DiagnosticMessages {
url(docsrs),
help("try doing it better next time?")
)]
MyAdvice {
AnAdvice {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand All @@ -52,7 +52,7 @@ enum DiagnosticMessages {
url(docsrs),
help("try doing it better next time?")
)]
MyWarning {
TheWarning {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand All @@ -68,7 +68,7 @@ enum DiagnosticMessages {
url(docsrs),
help("try doing it better next time?")
)]
MyMessage {
Message {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand All @@ -90,21 +90,21 @@ fn main() {
}

fn app_code(diag_channel: &DiagChannel) {
let src = "source\n text\n here".to_string();
let src = "source\n text\n here".to_owned();

diag_channel.report(MyError {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(MyAdvice {
diag_channel.report(AnAdvice {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(MyWarning {
diag_channel.report(TheWarning {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(MyMessage {
diag_channel.report(Message {
src: NamedSource::new("bad_file.rs", src),
bad_bit: (9, 4).into(),
});
Expand Down
4 changes: 4 additions & 0 deletions crates/weaver_common/src/diag/consumer/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

//! A consumer that writes diagnostic messages to the console as plain text.
#![allow(clippy::print_stdout)]
#![allow(clippy::print_stderr)]

use crate::diag::consumer::DiagMessageConsumer;
use crate::diag::SystemMessage;
use std::sync::mpsc;
Expand All @@ -13,6 +16,7 @@ pub struct ConsoleDiagMessageConsumer {

impl ConsoleDiagMessageConsumer {
/// Creates a new console consumer.
#[must_use]
pub fn new(stdout_lock: bool) -> Self {
Self { stdout_lock }
}
Expand Down
29 changes: 15 additions & 14 deletions crates/weaver_common/src/diag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl DiagService {
}

/// Returns a channel for reporting diagnostic reports.
#[must_use]
pub fn channel(&self) -> DiagChannel {
DiagChannel::new(self.sender.clone())
}
Expand Down Expand Up @@ -86,7 +87,7 @@ mod tests {
url(docsrs),
help("try doing it better next time?")
)]
MyError {
Error {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand All @@ -103,7 +104,7 @@ mod tests {
url(docsrs),
help("try doing it better next time?")
)]
MyAdvice {
Advice {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand All @@ -120,7 +121,7 @@ mod tests {
url(docsrs),
help("try doing it better next time?")
)]
MyWarning {
Warning {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand All @@ -136,7 +137,7 @@ mod tests {
url(docsrs),
help("try doing it better next time?")
)]
MyMessage {
Message {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
Expand Down Expand Up @@ -173,21 +174,21 @@ mod tests {

/// This function represent a single threaded application that reports a diagnostic message.
fn single_thread_app(diag_channel: &DiagChannel) {
let src = "source\n text\n here".to_string();
let src = "source\n text\n here".to_owned();

diag_channel.report(DiagMessages::MyError {
diag_channel.report(DiagMessages::Error {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(DiagMessages::MyAdvice {
diag_channel.report(DiagMessages::Advice {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(DiagMessages::MyWarning {
diag_channel.report(DiagMessages::Warning {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(DiagMessages::MyMessage {
diag_channel.report(DiagMessages::Message {
src: NamedSource::new("bad_file.rs", src),
bad_bit: (9, 4).into(),
});
Expand All @@ -200,21 +201,21 @@ mod tests {
let diag_channel = diag_channel.clone();

_ = thread::spawn(move || {
let src = "source\n text\n here".to_string();
let src = "source\n text\n here".to_owned();

diag_channel.report(DiagMessages::MyError {
diag_channel.report(DiagMessages::Error {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(DiagMessages::MyAdvice {
diag_channel.report(DiagMessages::Advice {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(DiagMessages::MyWarning {
diag_channel.report(DiagMessages::Warning {
src: NamedSource::new("bad_file.rs", src.clone()),
bad_bit: (9, 4).into(),
});
diag_channel.report(DiagMessages::MyMessage {
diag_channel.report(DiagMessages::Message {
src: NamedSource::new("bad_file.rs", src),
bad_bit: (9, 4).into(),
});
Expand Down

0 comments on commit ca69fbe

Please sign in to comment.