diff --git a/crates/test-ui/src/hack.rs b/crates/test-ui/src/hack.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/crates/test-ui/src/hack.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/crates/test-ui/src/main.rs b/crates/test-ui/src/main.rs index dcce08f5b..48a310999 100644 --- a/crates/test-ui/src/main.rs +++ b/crates/test-ui/src/main.rs @@ -17,4 +17,12 @@ fn main() { .join("ui") .join("*.rs"); t.compile_fail(path); + // Make trybuild use `cargo build` instead of `cargo check` + // + // Workaround for https://github.com/dtolnay/trybuild/issues/241 + t.pass( + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("src") + .join("hack.rs"), + ); } diff --git a/crates/test-ui/ui/invalid_option_encode_impl.rs b/crates/test-ui/ui/invalid_option_encode_impl.rs index 8e5bbaf68..060512998 100644 --- a/crates/test-ui/ui/invalid_option_encode_impl.rs +++ b/crates/test-ui/ui/invalid_option_encode_impl.rs @@ -1,5 +1,5 @@ //! Ensure that implementing `OptionEncode` wrongly results in an error -use objc2::encode::{Encode, Encoding, OptionEncode, RefEncode}; +use objc2::encode::{Encode, Encoding, OptionEncode}; #[repr(transparent)] struct MyType(usize); @@ -8,19 +8,8 @@ unsafe impl Encode for MyType { const ENCODING: Encoding = usize::ENCODING; } -unsafe impl RefEncode for MyType { - const ENCODING_REF: Encoding = usize::ENCODING_REF; -} - unsafe impl OptionEncode for MyType {} fn main() { assert_eq!(>::ENCODING, MyType::ENCODING); - assert_eq!(>::ENCODING_REF, MyType::ENCODING_REF); - - // TODO: trybuild runs with `cargo check`, which doesn't catch all const - // errors. - const TODO: () = { - panic!("todo"); - }; } diff --git a/crates/test-ui/ui/invalid_option_encode_impl.stderr b/crates/test-ui/ui/invalid_option_encode_impl.stderr index 24772f4ca..9edbd7d11 100644 --- a/crates/test-ui/ui/invalid_option_encode_impl.stderr +++ b/crates/test-ui/ui/invalid_option_encode_impl.stderr @@ -1,7 +1,21 @@ -error[E0080]: evaluation of constant value failed - --> ui/invalid_option_encode_impl.rs +error[E0080]: evaluation of ` as objc2::Encode>::ENCODING` failed + --> $WORKSPACE/crates/objc2/src/encode/mod.rs | - | panic!("todo"); - | ^^^^^^^^^^^^^^ the evaluated program panicked at 'todo', $DIR/ui/invalid_option_encode_impl.rs:24:9 + | panic!("invalid OptionEncode + Encode implementation"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid OptionEncode + Encode implementation', $WORKSPACE/crates/objc2/src/encode/mod.rs:276:13 | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant used + --> ui/invalid_option_encode_impl.rs + | + | assert_eq!(>::ENCODING, MyType::ENCODING); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +note: erroneous constant used + --> ui/invalid_option_encode_impl.rs + | + | assert_eq!(>::ENCODING, MyType::ENCODING); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/invalid_option_encode_impl_ref.rs b/crates/test-ui/ui/invalid_option_encode_impl_ref.rs new file mode 100644 index 000000000..2b0574124 --- /dev/null +++ b/crates/test-ui/ui/invalid_option_encode_impl_ref.rs @@ -0,0 +1,15 @@ +//! Ensure that implementing `OptionEncode` wrongly results in an error +use objc2::encode::{Encoding, OptionEncode, RefEncode}; + +#[repr(transparent)] +struct MyType(usize); + +unsafe impl RefEncode for MyType { + const ENCODING_REF: Encoding = usize::ENCODING_REF; +} + +unsafe impl OptionEncode for MyType {} + +fn main() { + assert_eq!(>::ENCODING_REF, MyType::ENCODING_REF); +} diff --git a/crates/test-ui/ui/invalid_option_encode_impl_ref.stderr b/crates/test-ui/ui/invalid_option_encode_impl_ref.stderr new file mode 100644 index 000000000..4b44c1dca --- /dev/null +++ b/crates/test-ui/ui/invalid_option_encode_impl_ref.stderr @@ -0,0 +1,21 @@ +error[E0080]: evaluation of ` as objc2::RefEncode>::ENCODING_REF` failed + --> $WORKSPACE/crates/objc2/src/encode/mod.rs + | + | panic!("invalid OptionEncode + RefEncode implementation"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid OptionEncode + RefEncode implementation', $WORKSPACE/crates/objc2/src/encode/mod.rs:286:13 + | + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant used + --> ui/invalid_option_encode_impl_ref.rs + | + | assert_eq!(>::ENCODING_REF, MyType::ENCODING_REF); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +note: erroneous constant used + --> ui/invalid_option_encode_impl_ref.rs + | + | assert_eq!(>::ENCODING_REF, MyType::ENCODING_REF); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)