Skip to content

Commit e0f3cf9

Browse files
authored
Unrolled build for rust-lang#126531
Rollup merge of rust-lang#126531 - slanterns:error_provider, r=workingjubilee Add codegen test for `Request::provide_*` Codegen before & after rust-lang#126242: https://gist.github.com/slanterns/3789ee36f59ed834e1a6bd4677b68ed4. Also adjust an outdated comment since `tag_id` is no longer attached to `TaggedOption` via `Erased`, but stored next to it in `Tagged` under the new implementation. My first time writing FileCheck xD. Correct me if there is anything that should be amended. r? libs
2 parents e794b0f + 51d9546 commit e0f3cf9

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

library/core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ pub(crate) mod tags {
928928
/// An `Option` with a type tag `I`.
929929
///
930930
/// Since this struct implements `Erased`, the type can be erased to make a dynamically typed
931-
/// option. The type can be checked dynamically using `Erased::tag_id` and since this is statically
931+
/// option. The type can be checked dynamically using `Tagged::tag_id` and since this is statically
932932
/// checked for the concrete type, there is some degree of type safety.
933933
#[repr(transparent)]
934934
pub(crate) struct TaggedOption<'a, I: tags::Type<'a>>(pub Option<I::Reified>);

tests/codegen/error-provide.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Codegen test for #126242
2+
3+
//@ compile-flags: -O
4+
#![crate_type = "lib"]
5+
#![feature(error_generic_member_access)]
6+
use std::error::Request;
7+
use std::fmt;
8+
9+
#[derive(Debug)]
10+
struct MyBacktrace1 {}
11+
12+
#[derive(Debug)]
13+
struct MyBacktrace2 {}
14+
15+
#[derive(Debug)]
16+
struct MyBacktrace3 {}
17+
18+
#[derive(Debug)]
19+
struct MyError {
20+
backtrace1: MyBacktrace1,
21+
backtrace2: MyBacktrace2,
22+
backtrace3: MyBacktrace3,
23+
other: MyBacktrace3,
24+
}
25+
26+
impl fmt::Display for MyError {
27+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28+
write!(f, "Example Error")
29+
}
30+
}
31+
32+
impl std::error::Error for MyError {
33+
// CHECK-LABEL: @provide
34+
#[no_mangle]
35+
fn provide<'a>(&'a self, request: &mut Request<'a>) {
36+
// LLVM should be able to optimize multiple .provide_* calls into a switch table
37+
// and eliminate redundant ones, rather than compare one-by-one.
38+
39+
// CHECK-NEXT: start:
40+
// CHECK-NEXT: %[[SCRUTINEE:[^ ]+]] = load i64, ptr
41+
// CHECK-NEXT: switch i64 %[[SCRUTINEE]], label %{{.*}} [
42+
// CHECK-COUNT-3: i64 {{.*}}, label %{{.*}}
43+
// CHECK-NEXT: ]
44+
request
45+
.provide_ref::<MyBacktrace1>(&self.backtrace1)
46+
.provide_ref::<MyBacktrace3>(&self.other)
47+
.provide_ref::<MyBacktrace2>(&self.backtrace2)
48+
.provide_ref::<MyBacktrace3>(&self.backtrace3);
49+
}
50+
}

0 commit comments

Comments
 (0)