Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant Backtrace provide_ref from ContextError #281

Merged
merged 2 commits into from Oct 21, 2022

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Oct 20, 2022

Back when this line was added in 46d3d2c, it was necessary in order for the following program to successfully obtain the requested backtrace:

#![feature(error_generic_member_access)]

use anyhow::anyhow;
use std::backtrace::Backtrace;

fn main() {
    let error = anyhow!("...").context("...");
    (&*error).request_ref::<Backtrace>().unwrap();
}

However #268 made it redundant, as now self.error.provide(demand) has become a call to:

anyhow/src/error.rs

Lines 534 to 536 in cccc785

fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
unsafe { ErrorImpl::provide(self.inner.by_ref(), demand) }
}

which calls:

anyhow/src/error.rs

Lines 911 to 916 in cccc785

unsafe fn provide<'a>(this: Ref<'a, Self>, demand: &mut Demand<'a>) {
if let Some(backtrace) = &this.deref().backtrace {
demand.provide_ref(backtrace);
}
Self::error(this).provide(demand);
}

@dtolnay dtolnay merged commit 6874b52 into master Oct 21, 2022
@dtolnay dtolnay deleted the redundantprovide branch October 21, 2022 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant