Skip to content

Commit b1c04fe

Browse files
authored
Merge pull request #495 from madsmtm/trybuild-actually-build
Catch `trybuild` errors during monomorphization as well
2 parents 94d8ac1 + 3c9f8b8 commit b1c04fe

File tree

6 files changed

+64
-16
lines changed

6 files changed

+64
-16
lines changed

crates/test-ui/src/hack.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

crates/test-ui/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ fn main() {
1717
.join("ui")
1818
.join("*.rs");
1919
t.compile_fail(path);
20+
// Make trybuild use `cargo build` instead of `cargo check`
21+
//
22+
// Workaround for https://github.com/dtolnay/trybuild/issues/241
23+
t.pass(
24+
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
25+
.join("src")
26+
.join("hack.rs"),
27+
);
2028
}
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Ensure that implementing `OptionEncode` wrongly results in an error
2-
use objc2::encode::{Encode, Encoding, OptionEncode, RefEncode};
2+
use objc2::encode::{Encode, Encoding, OptionEncode};
33

44
#[repr(transparent)]
55
struct MyType(usize);
@@ -8,19 +8,8 @@ unsafe impl Encode for MyType {
88
const ENCODING: Encoding = usize::ENCODING;
99
}
1010

11-
unsafe impl RefEncode for MyType {
12-
const ENCODING_REF: Encoding = usize::ENCODING_REF;
13-
}
14-
1511
unsafe impl OptionEncode for MyType {}
1612

1713
fn main() {
1814
assert_eq!(<Option<MyType>>::ENCODING, MyType::ENCODING);
19-
assert_eq!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);
20-
21-
// TODO: trybuild runs with `cargo check`, which doesn't catch all const
22-
// errors.
23-
const TODO: () = {
24-
panic!("todo");
25-
};
2615
}
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
error[E0080]: evaluation of constant value failed
2-
--> ui/invalid_option_encode_impl.rs
1+
error[E0080]: evaluation of `<std::option::Option<MyType> as objc2::Encode>::ENCODING` failed
2+
--> $WORKSPACE/crates/objc2/src/encode/mod.rs
33
|
4-
| panic!("todo");
5-
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'todo', $DIR/ui/invalid_option_encode_impl.rs:24:9
4+
| panic!("invalid OptionEncode + Encode implementation");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid OptionEncode + Encode implementation', $WORKSPACE/crates/objc2/src/encode/mod.rs:276:13
66
|
77
= 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)
8+
9+
note: erroneous constant used
10+
--> ui/invalid_option_encode_impl.rs
11+
|
12+
| assert_eq!(<Option<MyType>>::ENCODING, MyType::ENCODING);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
note: erroneous constant used
16+
--> ui/invalid_option_encode_impl.rs
17+
|
18+
| assert_eq!(<Option<MyType>>::ENCODING, MyType::ENCODING);
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Ensure that implementing `OptionEncode` wrongly results in an error
2+
use objc2::encode::{Encoding, OptionEncode, RefEncode};
3+
4+
#[repr(transparent)]
5+
struct MyType(usize);
6+
7+
unsafe impl RefEncode for MyType {
8+
const ENCODING_REF: Encoding = usize::ENCODING_REF;
9+
}
10+
11+
unsafe impl OptionEncode for MyType {}
12+
13+
fn main() {
14+
assert_eq!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0080]: evaluation of `<std::option::Option<MyType> as objc2::RefEncode>::ENCODING_REF` failed
2+
--> $WORKSPACE/crates/objc2/src/encode/mod.rs
3+
|
4+
| panic!("invalid OptionEncode + RefEncode implementation");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'invalid OptionEncode + RefEncode implementation', $WORKSPACE/crates/objc2/src/encode/mod.rs:286:13
6+
|
7+
= 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)
8+
9+
note: erroneous constant used
10+
--> ui/invalid_option_encode_impl_ref.rs
11+
|
12+
| assert_eq!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
note: erroneous constant used
16+
--> ui/invalid_option_encode_impl_ref.rs
17+
|
18+
| assert_eq!(<Option<MyType>>::ENCODING_REF, MyType::ENCODING_REF);
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)