diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-12-07 00:10:05 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-07 00:10:05 +0900 |
| commit | c85284ec58f353c9df7615f9f130f65572a3f639 (patch) | |
| tree | 12e3e839878ae783d2fcae5ee47c2f24ea61bd9d /src/test/codegen | |
| parent | d1397db3f3e0010a2a2ce9efedc9903907143319 (diff) | |
| parent | f5bd94768a5ca901eb7555a4c3fd4d3005c1ad76 (diff) | |
| download | rust-c85284ec58f353c9df7615f9f130f65572a3f639.tar.gz rust-c85284ec58f353c9df7615f9f130f65572a3f639.zip | |
Rollup merge of #67054 - RalfJung:set-discriminant-unreachable, r=oli-obk
codegen "unreachable" for invalid SetDiscriminant Follow-up from https://github.com/rust-lang/rust/pull/66960. I also realized I don't understand our policy for using `abort` vs `unreachable`. AFAIK `abort` is safe to call and just aborts the process, while `unreachable` is UB. But sometimes we use both, like here https://github.com/rust-lang/rust/blob/d825e35ee8325146e6c175a4c61bcb645b347d5e/src/librustc_codegen_ssa/mir/block.rs#L827-L828 and here https://github.com/rust-lang/rust/blob/d825e35ee8325146e6c175a4c61bcb645b347d5e/src/librustc_codegen_ssa/mir/block.rs#L264-L265 The second case is even more confusing because that looks like an unreachable `return` to me, so why would we codegen a safe abort there? r? @eddyb Cc @oli-obk
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/set-discriminant-invalid.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/codegen/set-discriminant-invalid.rs b/src/test/codegen/set-discriminant-invalid.rs new file mode 100644 index 00000000000..d9614f062b7 --- /dev/null +++ b/src/test/codegen/set-discriminant-invalid.rs @@ -0,0 +1,43 @@ +// compile-flags: -C opt-level=0 +#![crate_type = "lib"] + +pub enum ApiError {} +#[allow(dead_code)] +pub struct TokioError { + b: bool, +} +pub enum Error { + Api { + source: ApiError, + }, + Ethereum, + Tokio { + source: TokioError, + }, +} +struct Api; +impl IntoError<Error> for Api +{ + type Source = ApiError; + // CHECK-LABEL: @into_error + // CHECK: llvm.trap() + // Also check the next two instructions to make sure we do not match against `trap` + // elsewhere in the code. + // CHECK-NEXT: load + // CHECK-NEXT: ret + #[no_mangle] + fn into_error(self, error: Self::Source) -> Error { + Error::Api { + source: (|v| v)(error), + } + } +} + +pub trait IntoError<E> +{ + /// The underlying error + type Source; + + /// Combine the information to produce the error + fn into_error(self, source: Self::Source) -> E; +} |
