Skip to content

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.

1 participant