Skip to content

Commit

Permalink
add codegen test for Error::provide
Browse files Browse the repository at this point in the history
  • Loading branch information
slanterns committed Jun 15, 2024
1 parent 6cce488 commit b17bcc0
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/codegen/error-provide.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//@ 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,

Check failure on line 34 in tests/codegen/error-provide.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

line longer than 100 chars
// rather than compare one-by-one.

// CHECK: switch {{i32|i64}} %{{.*}}, label %{{.*}} [
// CHECK-COUNT-3: {{i32|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);
}
}

0 comments on commit b17bcc0

Please sign in to comment.