Skip to content

Commit

Permalink
test: Verify auto-traits for core types
Browse files Browse the repository at this point in the history
By checking these types, we'll get some other types for free, like
`Command` verifying `Arg`.

This was inspired by #3876
  • Loading branch information
epage committed Jun 28, 2022
1 parent a05f4d3 commit 3c4e684
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ trycmd = { version = "0.13", default-features = false, features = ["color-auto",
humantime = "2"
snapbox = "0.2.9"
shlex = "1.1.0"
static_assertions = "1.1.0"

[[example]]
name = "demo"
Expand Down
5 changes: 5 additions & 0 deletions src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5107,3 +5107,8 @@ where
_ => None,
}
}

#[test]
fn check_auto_traits() {
static_assertions::assert_impl_all!(Command: Send, Sync, Unpin);
}
11 changes: 3 additions & 8 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,7 @@ impl Display for Backtrace {
}
}

#[cfg(test)]
mod tests {
/// Check `clap::Error` impls Send and Sync.
mod clap_error_impl_send_sync {
use crate::Error;
trait Foo: std::error::Error + Send + Sync + 'static {}
impl Foo for Error {}
}
#[test]
fn check_auto_traits() {
static_assertions::assert_impl_all!(Error: Send, Sync, Unpin);
}
11 changes: 11 additions & 0 deletions src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@ impl std::fmt::Display for MatchesError {
}
}
}

#[test]
fn check_auto_traits() {
static_assertions::assert_impl_all!(
MatchesError: Send,
Sync,
std::panic::RefUnwindSafe,
std::panic::UnwindSafe,
Unpin
);
}
5 changes: 5 additions & 0 deletions src/parser/matches/arg_matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,11 @@ fn unwrap_os_string_arg<'v>(id: &Id, value: &'v AnyValue) -> &'v OsStr {
mod tests {
use super::*;

#[test]
fn check_auto_traits() {
static_assertions::assert_impl_all!(ArgMatches: Send, Sync, Unpin);
}

#[test]
fn test_default_values() {
#![allow(deprecated)]
Expand Down
2 changes: 1 addition & 1 deletion tests/derive_ui/next/tuple_struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ error[E0599]: no function or associated item named `parse` found for struct `Opt
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following traits define an item `parse`, perhaps you need to implement one of them:
candidate #1: `StructOpt`
candidate #1: `Parser`
candidate #2: `TypedValueParser`

0 comments on commit 3c4e684

Please sign in to comment.