Repository navigation
Tracking Issue for error_generic_member_access #99301
Description
Activity
- addedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Jul 15, 2022 - added a commit that references this issue
on Sep 4, 2022 Hello from dtolnay/thiserror#185. I noticed it can be problematic for macros that
ProviderandErrorboth have a method namedprovide. I know this has been the case for other traits (DisplayandDebugboth have afmtmethod, for example) but one thing that makes the situation worse forprovideis that we're commonly forced to rely on deref in order to call it, so fully-qualified method call syntax is not suitable to resolve the ambiguity:-
In the case of
Display, macros can writecore::fmt::Display::fmt(&$thing, formatter)and that will always work, because even if$thingis something likeBox<dyn Display>, there is animpl<T> Display for Box<T> where T: Display + ?Sizedwhich makes it work. -
However in the case of
Error, writingcore::error::Error::provide(&$thing, demand)is less good than$thing.provide(demand)because there is noimpl<E> Error for Box<E> where E: Error + ?Sized. If$thingisBox<dyn Error + Send + Sync + 'static>, oranyhow::Error, these things rely on the deref done implicitly by.provide(demand)in order to deref todyn Error + Send + Sync + 'static, which calling fully qualifiedcore::error::Error::providewill not do. -
The situation gets worse as other traits in the ecosystem follow the lead of
Errorand possibly add their ownprovidemethod. Maybe it's not so common thatProviderandErrorwould be both in scope at the same time, but are we confident thatErrorand arbitrary other ecosystem trait won't be?
Two proposals:
-
There should be
impl Provider for Box<dyn Error + …>in the standard library. This makescore::any::Provider::provide(&$thing, demand)accommodate more cases, but still not as good as having a deref. -
Is there someone who might be interested in pursuing a "fully qualified method call but with deref/autoref" RFC? The syntax
thing.core::any::Provider::provide(demand)has been suggested for this in the past, and would eliminate the difficulty for macros that want a deref or autoref but also need to be robust to multiple traits having the same method name.
Reacted by Sergey Ivanov, Qyriad, Js2xxx, robinhundt, JonasJebing, Charles Hall, Colton Donnelly, Armin Ronacher, Amaan Qureshi, Philipp Schuster and 11 more-
I agree, that
a "fully qualified method call but with deref/autoref" RFC
would be great.
An immediate remedy would also be to renameError::provide.
Theerror_generic_member_accessRFC and thedyno/provide_anyRFC were already usingError::provide_contextinstead ofError::providein their examples.
I'd gladly create a PR to change the name if there are no objections.Reacted by Caleb Jamison- added a commit that references this issue
on Nov 4, 2022 Not sure if this has been proposed before, but maybe an alternative to "fully qualified method call but with deref/autoref" could be that, in case of an ambiguity, trait method resolution favors traits that were introduced in inner scopes.
Currently, the following code doesn't compile:
fn foo(x: u32, formatter: &mut core::fmt::Formatter) { use core::fmt::{Display, Debug}; { // Imagine this block was generated by a macro that only needs `Display` but not `Debug`. use core::fmt::Display; // currently leads to a warning: "the item `Display` is imported redundantly" x.fmt(formatter); // currently leads to an error: "multiple `fmt` found" } }
The proposal would be to allow the above code, and to resolve
x.fmt(formatter)tocore::fmt::Display::fmt(&x, formatter)sinceDisplaywasused in a strictly narrower scope thanDebug.I don't think this would change any behavior in code that currently compiles since it would only disambiguate cases that are currently ambiguous. And it would allow macro authors to simply introduce a new scope and
useany traits that their macros will need (this wouldn't leak any identifies to the outer scope since, already today, thoseuses are scoped to the inner block).Reacted by Teoh Han Hui- added a commit that references this issue
on Jan 31, 2023 An easier solution would be to rename
Error::provide. At one point it wasprovide_contextand we should be able to find some other name for it.Reacted by Tim Diekmann, Bilal Mahmoud, Caleb Jamison and jynFor what it's worth,
provide_contextfeels like a good name for this method to me.Sure it's longer but it's more clear that it's about the error providing some sort of context to a user that comes from the concrete error type.
Whereas a plain
providehad me thinking "provide what?".Reacted by Sergey Ivanov and jynAn immediate remedy would also be to rename Error::provide.
The error_generic_member_access RFC and the dyno/provide_any RFC were already using Error::provide_context instead of Error::provide in their examples.
I'd gladly create a PR to change the name if there are no objections.@JonasJebing that sounds great! do you have time to follow up on that? :)
FYI for anyone subscribed to this issue hasn't been following #96024 or #113464 - I have volunteered to take on this issue to see what i can do to help push the generic member access work forward.
Next steps for this issue include:
- assign it to myself using rustbot
- @yaahc is it possible for you to give me edit permissions for the description on this issue so i can keep the steps/history section updated? or should i just ping you whenever i need it updated? or maybe it would be simpler to open a new tracking issue?
- gathering all lingering TODOs and feedback from Tracking Issue for Provider API #96024, making sure it is all captured in this issue
- close Tracking Issue for Provider API #96024
- open PR to RFCs repo to remove the
provide_anyfeature aka https://github.com/rust-lang/rfcs/blob/master/text/3192-dyno.md - update my other PR to replace all instances of the
provide_anyfeature name - open PR for
thiserrorto incorporate removal of theProvidertrait, use that PR branch in core/any: remove Provider trait, rename Demand to Request #113464 to update the dependencies for nightly rustfmt and rust-analyzer. I left some thoughts on a merge strategy between rust and thiserror in my PR
Reacted by stormshield-gt- assign it to myself using rustbot
@rustbot claim
- @yaahc is it possible for you to give me edit permissions for the description on this issue so i can keep the steps/history section updated? or should i just ping you whenever i need it updated? or maybe it would be simpler to open a new tracking issue?
Not that I know of. The only way I can think of is via team membership since I think permissions are set up so that team members can usually edit any comments in the repo, for instance, I can edit your reply in this issue for whatever reason...
Feel free to just ping me (zulip works best), I'll start by grabbing the next steps you added and vendoring them into the top level comment.
Edit: alright, I've gone ahead and edited the todolist on the issue. Not sure if the provide_context rename is still relevant, lmk either way.
197 remaining items
Load more actionsI've been made aware that there is an open RFC for trait-to-trait casts, and I would like to know the opinion of @rust-lang/lang as to how likely it is to be accepted/implemented.
Nobody in the libs-api team really likes the provider API and we would much prefer if there was a language-level solution to the problem of extracting arbitrary data out of a
dyn Error.If it's frustrated, better not have it, we already deal with all kinds of fault of C for so many years 👍
Reacted by Jake Goulding and Yonggang Luo- addedI-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langLang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang
on Feb 25, 2026 - removedfinished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
on Feb 25, 2026 RFC 3885 was discussed in the lang meeting and there was a lot of enthusiasm for it. As I've said before, the libs-api team strongly prefers language-level trait object casting to the provider API. However this fundamentally requires that someone put the work in to actually implement this feature. If anyone is interested then they should say so on the RFC thread.
In the meantime I will cancel the FCP since we have a better alternative solution in sight.
@rfcbot cancel
@Amanieu proposal cancelled.
- removedproposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.
on Feb 26, 2026 For what it's worth, @arielb1 brought up a concern in zulip the other day is how a language level solution would interact generics+
&dyn Error(and I think generally any error wrapping types that masquerade as their wrapped error).#t-libs > Pushing error_generic_member_access forward @ 💬
To give a gist, if you have a function that takes an
E: Errorgeneric type and you pass in a&dyn Errorthat has already been erased then attempt to extract some context such as a Backtrace by casting theE: Errortype to some accessor trait you'd likely get None since&dyn Erroror any equivalent wrapper wouldn't necessarily or may not be able to implement the accessor traits implemented on the underlying erased error.This isn't necessarily a hard blocker IMO. I like the argument that this may be a positive pressure in that it discourages proxying error types, and it shouldn't break intertrait casts on subsequent source errors in the chain of errors. Also, notably it shouldn't affect the likes of
Box<dyn Error>andanyhow/eyregiven that they do not themselves implement theErrortrait.Provider avoids this by allowing proxying types to directly invoke the provide impl of their wrapped errors.
Either way though I think this is an important factor to consider when deciding which approach to prefer.
Reacted by Sergey Ivanov- addedI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.and removedI-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langLang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang
on Mar 4, 2026 - addedT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.and removedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on Aug 12, 2026
View all comments
Feature gate:
#![feature(error_generic_member_access)]This is a tracking issue for the generic member access API on the error trait, which generalizes the pattern of
fn source(&self) -> Option<&dyn Error>andfn backtrace(&self) -> Option<&Backtrace>intofn request_ref::<T>(&self) -> Option<&T>Public API
Steps / History
Now tracked by @waynr in #99301 (comment)
Unresolved Questions