Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch trybuild errors during monomorphization as well #495

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/test-ui/src/hack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
8 changes: 8 additions & 0 deletions crates/test-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
);
}
13 changes: 1 addition & 12 deletions crates/test-ui/ui/invalid_option_encode_impl.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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!(<Option<MyType>>::ENCODING, MyType::ENCODING);
assert_eq!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);

// TODO: trybuild runs with `cargo check`, which doesn't catch all const
// errors.
const TODO: () = {
panic!("todo");
};
}
22 changes: 18 additions & 4 deletions crates/test-ui/ui/invalid_option_encode_impl.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
error[E0080]: evaluation of constant value failed
--> ui/invalid_option_encode_impl.rs
error[E0080]: evaluation of `<std::option::Option<MyType> 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!(<Option<MyType>>::ENCODING, MyType::ENCODING);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

note: erroneous constant used
--> ui/invalid_option_encode_impl.rs
|
| assert_eq!(<Option<MyType>>::ENCODING, MyType::ENCODING);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
15 changes: 15 additions & 0 deletions crates/test-ui/ui/invalid_option_encode_impl_ref.rs
Original file line number Diff line number Diff line change
@@ -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!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);
}
21 changes: 21 additions & 0 deletions crates/test-ui/ui/invalid_option_encode_impl_ref.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0080]: evaluation of `<std::option::Option<MyType> 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!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: erroneous constant used
--> ui/invalid_option_encode_impl_ref.rs
|
| assert_eq!(<Option<MyType>>::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)