Skip to content

Commit

Permalink
style: Resolve clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Jan 31, 2021
1 parent d3549f7 commit e3c1721
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 79 deletions.
21 changes: 5 additions & 16 deletions src/format/diagnostic.rs
Expand Up @@ -9,21 +9,20 @@ type CowStr<'a> = borrow::Cow<'a, str>;
/// The error code associated to this diagnostic.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct DiagnosticCode<'a> {
/// The code itself.
#[serde(borrow)]
pub code: CowStr<'a>,
/// An explanation for the code
#[serde(borrow)]
pub explanation: Option<CowStr<'a>>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// A line of code associated with the Diagnostic
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct DiagnosticSpanLine<'a> {
/// The line of code associated with the error
#[serde(borrow)]
Expand All @@ -32,14 +31,12 @@ pub struct DiagnosticSpanLine<'a> {
pub highlight_start: usize,
/// End of the section of the line to highlight. 1-based, character offset in self.text
pub highlight_end: usize,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Macro expansion information associated with a diagnostic.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct DiagnosticSpanMacroExpansion<'a> {
/// span where macro was applied to generate this code; note that
/// this may itself derive from a macro (if
Expand All @@ -54,15 +51,12 @@ pub struct DiagnosticSpanMacroExpansion<'a> {
/// span where macro was defined (if known)
#[serde(borrow)]
pub def_site_span: Option<DiagnosticSpan<'a>>,

#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// A section of the source code associated with a Diagnostic
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct DiagnosticSpan<'a> {
/// The file name this diagnostic comes from.
#[serde(borrow)]
Expand Down Expand Up @@ -97,9 +91,6 @@ pub struct DiagnosticSpan<'a> {
/// Macro invocations that created the code at this span, if any.
#[serde(borrow)]
pub expansion: Option<Box<DiagnosticSpanMacroExpansion<'a>>>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Whether a suggestion can be safely applied.
Expand All @@ -124,6 +115,7 @@ pub enum Applicability {
/// A diagnostic message generated by rustc
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Diagnostic<'a> {
/// The error message of this diagnostic.
#[serde(borrow)]
Expand All @@ -142,9 +134,6 @@ pub struct Diagnostic<'a> {
/// The message as rustc would render it
#[serde(borrow)]
pub rendered: Option<CowStr<'a>>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// The diagnostic level
Expand Down
22 changes: 6 additions & 16 deletions src/format/mod.rs
Expand Up @@ -33,6 +33,7 @@ pub enum Message<'a> {
/// A compiler-generated file.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Artifact<'a> {
/// The workspace member this artifact belongs to
#[serde(borrow)]
Expand All @@ -55,14 +56,12 @@ pub struct Artifact<'a> {
pub executable: Option<CowPath<'a>>,
/// If true, then the files were already generated
pub fresh: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// A single target (lib, bin, example, ...) provided by a crate
#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Target<'a> {
/// Name as given in the `Cargo.toml` or generated from the file name
#[serde(borrow)]
Expand Down Expand Up @@ -92,9 +91,6 @@ pub struct Target<'a> {
#[serde(default = "edition_default")]
#[serde(borrow)]
pub edition: CowStr<'a>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

fn edition_default() -> CowStr<'static> {
Expand All @@ -116,6 +112,7 @@ pub struct WorkspaceMember<'a> {
/// target.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ArtifactProfile<'a> {
/// Optimization level. Possible values are 0-3, s or z.
#[serde(borrow)]
Expand All @@ -129,14 +126,12 @@ pub struct ArtifactProfile<'a> {
pub overflow_checks: bool,
/// Whether this profile is a test
pub test: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Message left by the compiler
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct FromCompiler<'a> {
/// The workspace member this message belongs to
#[serde(borrow)]
Expand All @@ -147,14 +142,12 @@ pub struct FromCompiler<'a> {
/// The message the compiler sent.
#[serde(borrow)]
pub message: diagnostic::Diagnostic<'a>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Output of a Build Script execution.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct BuildScript<'a> {
/// The workspace member this build script execution belongs to
#[serde(borrow)]
Expand All @@ -175,9 +168,6 @@ pub struct BuildScript<'a> {
/// The environment variables to add to the compilation
#[serde(borrow)]
pub env: Vec<(CowStr<'a>, CowStr<'a>)>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

#[cfg(not(feature = "print"))]
Expand Down Expand Up @@ -225,7 +215,7 @@ pub(crate) fn log_message(msg: &Message<'_>) {
.rendered
.as_ref()
.map(|s| s.as_ref())
.unwrap_or(comp.message.message.as_ref());
.unwrap_or_else(|| comp.message.message.as_ref());
match comp.message.level {
diagnostic::DiagnosticLevel::Ice => println!("{}", content),
diagnostic::DiagnosticLevel::Error => println!("{}", content),
Expand Down
42 changes: 10 additions & 32 deletions src/format/test.rs
Expand Up @@ -42,16 +42,15 @@ pub enum Suite {

/// Suite-started event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct SuiteStarted {
/// Number of test cases in the suite.
pub test_count: usize,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Suite-finished successfully event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct SuiteOk {
/// Cases that passed.
pub passed: usize,
Expand All @@ -65,13 +64,11 @@ pub struct SuiteOk {
pub measured: usize,
/// Cases filtered out by caller.
pub filtered_out: usize,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Suite-finished with failure event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct SuiteFailed {
/// Cases that passed.
pub passed: usize,
Expand All @@ -85,9 +82,6 @@ pub struct SuiteFailed {
pub measured: usize,
/// Cases filtered out by caller.
pub filtered_out: usize,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Test case event.
Expand Down Expand Up @@ -115,70 +109,59 @@ pub enum Test {

/// Case-started event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct TestStarted {
/// Test case name.
pub name: String,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Case-finished successfully event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct TestOk {
/// Test case name.
pub name: String,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Case-finished with failure event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct TestFailed {
/// Test case name.
pub name: String,
/// Test's stdout
pub stdout: Option<String>,
/// Test failure mssage
pub message: Option<String>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Case-ignored event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct TestIgnored {
/// Test case name.
pub name: String,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Case-allowed-failure event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct TestAllowedFailured {
/// Test case name.
pub name: String,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Case-timeout event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct TestTimeout {
/// Test case name.
pub name: String,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// Benchmark event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct Bench {
/// Benchmark name.
pub name: String,
Expand All @@ -188,17 +171,12 @@ pub struct Bench {
pub deviation: usize,
/// Mb/s
pub mib_per_second: Option<usize>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

#[cfg(test)]
mod tests {
use super::*;

use serde_json;

#[test]
fn suite_started() {
let input = r#"{ "type": "suite", "event": "started", "test_count": 10 }"#;
Expand Down
3 changes: 0 additions & 3 deletions src/msg.rs
Expand Up @@ -3,9 +3,6 @@ use std::io::BufRead;
use std::io::Read;
use std::process;

use serde;
use serde_json;

use crate::error::*;
use crate::format;

Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Expand Up @@ -114,7 +114,7 @@ fn extract_bin<'a>(msg: &'a format::Message<'_>, desired_kind: &str) -> Option<&
&& art.target.crate_types == ["bin"]
&& art.target.kind == [desired_kind]
{
Some(art.filenames.iter().next().expect("files must exist"))
Some(art.filenames.get(0).expect("files must exist"))
} else {
None
}
Expand Down
8 changes: 3 additions & 5 deletions src/test.rs
Expand Up @@ -148,21 +148,19 @@ impl CargoTest {
}
}

fn extract_bin<'a>(msg: &'a format::Message<'_>) -> Option<CargoTest> {
fn extract_bin(msg: &format::Message<'_>) -> Option<CargoTest> {
match msg {
format::Message::CompilerArtifact(art) => {
if art.profile.test {
let bin_path = art
.filenames
.iter()
.next()
.get(0)
.expect("files must exist")
.to_path_buf();
let kind = art
.target
.kind
.iter()
.next()
.get(0)
.expect("kind must exist")
.as_ref()
.to_owned();
Expand Down
3 changes: 0 additions & 3 deletions tests/build.rs
@@ -1,6 +1,3 @@
use assert_fs;
use escargot;

fn test_fixture(name: &str) {
let temp = assert_fs::TempDir::new().unwrap();

Expand Down
3 changes: 0 additions & 3 deletions tests/run.rs
@@ -1,6 +1,3 @@
use assert_fs;
use escargot;

fn test_fixture(name: &str) {
let temp = assert_fs::TempDir::new().unwrap();

Expand Down

0 comments on commit e3c1721

Please sign in to comment.