diff --git a/src/format/diagnostic.rs b/src/format/diagnostic.rs index 553b4d4..717b9d8 100644 --- a/src/format/diagnostic.rs +++ b/src/format/diagnostic.rs @@ -9,6 +9,7 @@ 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)] @@ -16,14 +17,12 @@ pub struct DiagnosticCode<'a> { /// An explanation for the code #[serde(borrow)] pub explanation: Option>, - #[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)] @@ -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 @@ -54,15 +51,12 @@ pub struct DiagnosticSpanMacroExpansion<'a> { /// span where macro was defined (if known) #[serde(borrow)] pub def_site_span: Option>, - - #[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)] @@ -97,9 +91,6 @@ pub struct DiagnosticSpan<'a> { /// Macro invocations that created the code at this span, if any. #[serde(borrow)] pub expansion: Option>>, - #[doc(hidden)] - #[serde(skip)] - __do_not_match_exhaustively: (), } /// Whether a suggestion can be safely applied. @@ -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)] @@ -142,9 +134,6 @@ pub struct Diagnostic<'a> { /// The message as rustc would render it #[serde(borrow)] pub rendered: Option>, - #[doc(hidden)] - #[serde(skip)] - __do_not_match_exhaustively: (), } /// The diagnostic level diff --git a/src/format/mod.rs b/src/format/mod.rs index efc16a5..11b143f 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -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)] @@ -55,14 +56,12 @@ pub struct Artifact<'a> { pub executable: Option>, /// 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)] @@ -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> { @@ -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)] @@ -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)] @@ -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)] @@ -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"))] @@ -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), diff --git a/src/format/test.rs b/src/format/test.rs index 1e8e2cf..b8cd5b3 100644 --- a/src/format/test.rs +++ b/src/format/test.rs @@ -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, @@ -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, @@ -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. @@ -115,26 +109,23 @@ 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, @@ -142,43 +133,35 @@ pub struct TestFailed { pub stdout: Option, /// Test failure mssage pub message: Option, - #[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, @@ -188,17 +171,12 @@ pub struct Bench { pub deviation: usize, /// Mb/s pub mib_per_second: Option, - #[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 }"#; diff --git a/src/msg.rs b/src/msg.rs index ec2dbe5..5387f03 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -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; diff --git a/src/run.rs b/src/run.rs index 515e60c..da73e84 100644 --- a/src/run.rs +++ b/src/run.rs @@ -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 } diff --git a/src/test.rs b/src/test.rs index 023a008..dd6f4dc 100644 --- a/src/test.rs +++ b/src/test.rs @@ -148,21 +148,19 @@ impl CargoTest { } } -fn extract_bin<'a>(msg: &'a format::Message<'_>) -> Option { +fn extract_bin(msg: &format::Message<'_>) -> Option { 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(); diff --git a/tests/build.rs b/tests/build.rs index 2a5b2df..0572532 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -1,6 +1,3 @@ -use assert_fs; -use escargot; - fn test_fixture(name: &str) { let temp = assert_fs::TempDir::new().unwrap(); diff --git a/tests/run.rs b/tests/run.rs index 83243be..c1dbdc5 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -1,6 +1,3 @@ -use assert_fs; -use escargot; - fn test_fixture(name: &str) { let temp = assert_fs::TempDir::new().unwrap();