Skip to content

Commit

Permalink
Auto merge of rust-lang#91752 - yaahc:track-caller-result, r=cuviper
Browse files Browse the repository at this point in the history
Readd track_caller to Result::from_residual

This is a followup on rust-lang#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

- rust-lang#87401 (comment): Difficulties with using non `std::result::Result` like types
- rust-lang#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

- rust-lang#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.
  • Loading branch information
bors committed Dec 15, 2021
2 parents 195e931 + 94307e2 commit df89fd2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,7 @@ impl<T, E, F: ~const From<E>> const ops::FromResidual<Result<convert::Infallible
for Result<T, F>
{
#[inline]
#[track_caller]
fn from_residual(residual: Result<convert::Infallible, E>) -> Self {
match residual {
Err(e) => Err(From::from(e)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
scope 1 {
debug residual => _6; // in scope 1 at $DIR/separate_const_switch.rs:29:9: 29:10
scope 2 {
scope 8 (inlined <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
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
debug residual => _8; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
let _16: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
let mut _17: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn identity(_1: Result<i32, i32>) -> Result<i32, i32> {
scope 1 {
debug residual => _5; // in scope 1 at $DIR/separate_const_switch.rs:29:9: 29:10
scope 2 {
scope 8 (inlined <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
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
debug residual => _6; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
let _14: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
let mut _15: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
scope 1 {
debug residual => _6; // in scope 1 at $DIR/separate_const_switch.rs:29:9: 29:10
scope 2 {
scope 8 (inlined <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) { // at $DIR/separate_const_switch.rs:29:8: 29:10
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
debug residual => _8; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
let _16: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
let mut _17: i32; // in scope 8 at $DIR/separate_const_switch.rs:29:8: 29:10
Expand Down

0 comments on commit df89fd2

Please sign in to comment.