diff options
| author | bors <bors@rust-lang.org> | 2024-06-17 04:01:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-17 04:01:54 +0000 |
| commit | fd7eefc2753e867053a1c567a7b504ae308e3f85 (patch) | |
| tree | 9102bb2ec2d52d0799ec0fe03a6f58ad2b90d3b0 /tests/codegen | |
| parent | e794b0f8557c187b5909d889aa35071f81e0a4cc (diff) | |
| parent | d92aa567b9846e1ad4e275da7ea74b8a7c5add55 (diff) | |
| download | rust-fd7eefc2753e867053a1c567a7b504ae308e3f85.tar.gz rust-fd7eefc2753e867053a1c567a7b504ae308e3f85.zip | |
Auto merge of #126569 - jieyouxu:rollup-1uvkb2y, r=jieyouxu
Rollup of 8 pull requests Successful merges: - #125258 (Resolve elided lifetimes in assoc const to static if no other lifetimes are in scope) - #126250 (docs(change): Don't mention a Cargo 2024 edition change for 1.79) - #126288 (doc: Added commas where needed) - #126346 (export std::os::fd module on HermitOS) - #126468 (div_euclid, rem_euclid: clarify/extend documentation) - #126531 (Add codegen test for `Request::provide_*`) - #126535 (coverage: Arrange span extraction/refinement as a series of passes) - #126538 (coverage: Several small improvements to graph code) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/error-provide.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/codegen/error-provide.rs b/tests/codegen/error-provide.rs new file mode 100644 index 00000000000..68dd383e5cc --- /dev/null +++ b/tests/codegen/error-provide.rs @@ -0,0 +1,50 @@ +// Codegen test for #126242 + +//@ compile-flags: -O +#![crate_type = "lib"] +#![feature(error_generic_member_access)] +use std::error::Request; +use std::fmt; + +#[derive(Debug)] +struct MyBacktrace1 {} + +#[derive(Debug)] +struct MyBacktrace2 {} + +#[derive(Debug)] +struct MyBacktrace3 {} + +#[derive(Debug)] +struct MyError { + backtrace1: MyBacktrace1, + backtrace2: MyBacktrace2, + backtrace3: MyBacktrace3, + other: MyBacktrace3, +} + +impl fmt::Display for MyError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Example Error") + } +} + +impl std::error::Error for MyError { + // CHECK-LABEL: @provide + #[no_mangle] + fn provide<'a>(&'a self, request: &mut Request<'a>) { + // LLVM should be able to optimize multiple .provide_* calls into a switch table + // and eliminate redundant ones, rather than compare one-by-one. + + // CHECK-NEXT: start: + // CHECK-NEXT: %[[SCRUTINEE:[^ ]+]] = load i64, ptr + // CHECK-NEXT: switch i64 %[[SCRUTINEE]], label %{{.*}} [ + // CHECK-COUNT-3: i64 {{.*}}, label %{{.*}} + // CHECK-NEXT: ] + request + .provide_ref::<MyBacktrace1>(&self.backtrace1) + .provide_ref::<MyBacktrace3>(&self.other) + .provide_ref::<MyBacktrace2>(&self.backtrace2) + .provide_ref::<MyBacktrace3>(&self.backtrace3); + } +} |
