Skip to content

Commit df89fd2

Browse files
committed
Auto merge of #91752 - yaahc:track-caller-result, r=cuviper
Readd track_caller to Result::from_residual This is a followup on #87401 in and an attempt to move the issue towards resolution. As part of the overhaul of the Try trait we removed the ability for errors to grab location information during propagation via `?` with the builtin `std::result::Result`. The previously linked issue has a fair bit of discussion into the reasons for and against the usage of `#[track_caller]` on the `FromResidual` impl on `Result` that I will do my best to summarize. --- ### For - #87401 (comment): Difficulties with using non `std::result::Result` like types - #87401 (comment): Inconsistency with functionality provided for recoverable (Result) and non-recoverable errors (panic), where panic provides a location and Result does not, pushing some users towards using panic ### Against - #84277 (comment): concern that this will bloat callers that never use this data --- Personally, I want to quantify the performance / bloat impact of re-adding this attribute, and fully evaluate the pros and cons before deciding if I need to switch `eyre` to have a custom `Result` type, which would also mean I need `try_trait_v2` to be stabilized, cc `@scottmcm.` If the performance impact is minor enough in the general case I think I would prefer that the default `Result` type has the ability to track location information for consistency with `panic` error reporting, and leave it to applications that need particularly high performance to handle the micro optimizations of introducing their own efficient custom Result type or matching manually. Alternatively, I wonder if the performance penalty on code that doesn't use the location information on `FromResidual` could be mitigated via new optimizations.
2 parents 195e931 + 94307e2 commit df89fd2

4 files changed

+4
-3
lines changed

Diff for: library/core/src/result.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,7 @@ impl<T, E, F: ~const From<E>> const ops::FromResidual<Result<convert::Infallible
19701970
for Result<T, F>
19711971
{
19721972
#[inline]
1973+
#[track_caller]
19731974
fn from_residual(residual: Result<convert::Infallible, E>) -> Self {
19741975
match residual {
19751976
Err(e) => Err(From::from(e)),

Diff for: src/test/mir-opt/separate_const_switch.identity.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
scope 1 {
1616
debug residual => _6; // in scope 1 at $DIR/separate_const_switch.rs:29:9: 29:10
1717
scope 2 {
18-
scope 8 (inlined <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
18+
scope 8 (inlined #[track_caller] <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
1919
debug residual => _8; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
2020
let _16: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
2121
let mut _17: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10

Diff for: src/test/mir-opt/separate_const_switch.identity.PreCodegen.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn identity(_1: Result<i32, i32>) -> Result<i32, i32> {
1212
scope 1 {
1313
debug residual => _5; // in scope 1 at $DIR/separate_const_switch.rs:29:9: 29:10
1414
scope 2 {
15-
scope 8 (inlined <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
15+
scope 8 (inlined #[track_caller] <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
1616
debug residual => _6; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
1717
let _14: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
1818
let mut _15: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10

Diff for: src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
scope 1 {
1616
debug residual => _6; // in scope 1 at $DIR/separate_const_switch.rs:29:9: 29:10
1717
scope 2 {
18-
scope 8 (inlined <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
18+
scope 8 (inlined #[track_caller] <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
1919
debug residual => _8; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
2020
let _16: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
2121
let mut _17: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10

0 commit comments

Comments
 (0)