Skip to content

Commit

Permalink
Implement root_cause using Iterator::last
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 14, 2024
1 parent 7706273 commit 5e9596f
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions eyre/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,7 @@ impl Report {
/// The root cause is the last error in the iterator produced by
/// [`chain()`][Report::chain].
pub fn root_cause(&self) -> &(dyn StdError + 'static) {
let mut chain = self.chain();
let mut root_cause = chain.next().unwrap();
for cause in chain {
root_cause = cause;
}
root_cause
self.chain().last().unwrap()
}

/// Returns true if `E` is the type held by this error object.
Expand Down

0 comments on commit 5e9596f

Please sign in to comment.