Skip to content

Commit

Permalink
Mark more test types as deliberately unused
Browse files Browse the repository at this point in the history
A chunk of our tests work by "does the procedural macro produce code
that compiles?" which means we don't need to *use* the
structs/enums/variants.

Did catch one bug though!
  • Loading branch information
shepmaster committed Apr 3, 2024
1 parent 073cc38 commit 7c70468
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions compatibility-tests/provider-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,12 @@ mod doctests {
user_id: UserId,
},

Logout {
_Logout {
#[snafu(provide)]
user_id: UserId,
},

NetworkUnreachable {
_NetworkUnreachable {
source: std::io::Error,
},
}
Expand Down
6 changes: 3 additions & 3 deletions tests/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ type AnotherError = Box<dyn std::error::Error>;
#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("Invalid user {user_id}:\n{backtrace}"))]
InvalidUser {
_InvalidUser {
user_id: i32,
backtrace: Backtrace,
},

WithSource {
_WithSource {
source: AnotherError,
backtrace: Backtrace,
},

WithSourceAndOtherInfo {
_WithSourceAndOtherInfo {
user_id: i32,
source: AnotherError,
backtrace: Backtrace,
Expand Down
2 changes: 1 addition & 1 deletion tests/display-shorthand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn supports_shorthand_formatting() {

#[test]
fn supports_positional_and_shorthand_formatting() {
let error = OnlyShorthandArgumentsSnafu {
let error = PositionalAndShorthandArgumentsSnafu {
id: 42,
name: "Anna",
}
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum Error {
Stronger { stronger: &'static str },

#[doc(hidden)]
Hidden,
_Hidden,
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum LeafError {
#[snafu(display("User ID {user_id} is invalid"))]
InvalidUser { user_id: i32 },
#[snafu(display("no user available"))]
MissingUser,
_MissingUser,
}

#[derive(Debug, Clone, Snafu, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions tests/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod bounds {
#[derive(Debug, Snafu)]
enum Error<T: Display> {
#[snafu(display("Boom: {value}"))]
Boom { value: T },
_Boom { value: T },

#[snafu(whatever, display("{message}"))]
Whatever {
Expand Down Expand Up @@ -94,7 +94,7 @@ mod bounds {
T: Display,
{
#[snafu(display("Boom: {value}"))]
Boom { value: T },
_Boom { value: T },

#[snafu(whatever, display("{message}"))]
Whatever {
Expand Down
8 changes: 5 additions & 3 deletions tests/generics_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ mod default_with_lifetime {
S: std::error::Error + AsErrorSource,
{
#[snafu(display("Boom: {value}"))]
Boom {
_Boom {
value: T,
name: &'a str,
},
WithSource {

_WithSource {
source: S,
},
Empty,

_Empty,
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions tests/name-conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ mod std {}
mod snafu {}

#[derive(Debug, Snafu)]
enum VariantNamedNone {
enum _VariantNamedNone {
#[snafu(context(suffix(false)))]
None,
}

#[derive(Debug, Snafu)]
enum VariantNamedSome<T> {
enum _VariantNamedSome<T> {
Some { value: T },
}

#[derive(Debug, Snafu)]
enum VariantNamedOk<T> {
enum _VariantNamedOk<T> {
Ok { value: T },
}

#[derive(Debug, Snafu)]
enum VariantNamedErr<T> {
enum _VariantNamedErr<T> {
Err { value: T },
}

fn _using_ensure() -> Result<u8, VariantNamedNone> {
fn _using_ensure() -> Result<u8, _VariantNamedNone> {
ensure!(false, None);
Ok(0)
}
6 changes: 3 additions & 3 deletions tests/no_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use snafu::prelude::*;

#[derive(Debug, Snafu)]
enum AlphaError {
AlphaDummy,
_AlphaDummy,
}

#[derive(Debug, Snafu)]
enum BetaError {
BetaDummy,
_BetaDummy,
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -67,7 +67,7 @@ mod with_bounds {

#[derive(Debug, Snafu)]
enum GenericError<T, U = i32> {
Something { things: T, other: U },
_Something { things: T, other: U },
}

#[derive(Debug, Snafu)]
Expand Down
8 changes: 4 additions & 4 deletions tests/send_between_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ enum InnerError {

#[derive(Debug, Snafu)]
enum Error {
Leaf {
_Leaf {
name: String,
},

Wrapper {
source: InnerError,
},

BoxedWrapper {
_BoxedWrapper {
source: Box<InnerError>,
},

BoxedTraitObjectSend {
_BoxedTraitObjectSend {
source: Box<dyn std::error::Error + Send + 'static>,
},

BoxedTraitObjectSendSync {
_BoxedTraitObjectSendSync {
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/source_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use snafu::prelude::*;

#[derive(Debug, Snafu)]
enum InnerError {
Boom,
_Boom,
}

fn inner() -> Result<(), InnerError> {
Expand Down
2 changes: 1 addition & 1 deletion tests/structs/single_use_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use snafu::prelude::*;
#[test]
fn an_error_with_generic_lifetimes_does_not_trigger_the_lint() {
#[derive(Debug, Snafu)]
struct Error<'id> {
struct _Error<'id> {
to: &'id u32,
}
}
2 changes: 1 addition & 1 deletion tests/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod with_bounds {

#[derive(Debug, Snafu)]
enum GenericError<T, U = i32> {
Something { things: T, other: U },
_Something { things: T, other: U },
}

#[derive(Debug, Snafu)]
Expand Down
4 changes: 3 additions & 1 deletion tests/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ mod outer {
PubCrate {
id: i32,
},

#[snafu(visibility(pub(in crate::outer)))]
PubInPath {
id: i32,
},

#[snafu(visibility)]
Private {
_Private {
id: i32,
},
}
Expand Down

0 comments on commit 7c70468

Please sign in to comment.