@@ -205,6 +205,52 @@ pub trait Error: Debug + Display {
205205 /// assert!(request_ref::<MyLittleTeaPot>(dyn_error).is_none());
206206 /// }
207207 /// ```
208+ ///
209+ /// # Implementation Conventions
210+ ///
211+ /// <div class="warning">
212+ ///
213+ /// **We recommend implementors avoid delegating implementations of `provide` to source error
214+ /// implementations.**
215+ ///
216+ /// This method should expose context from the current piece of the source chain only, not from
217+ /// sources. Delegating `provide` implementations cause the same context to be provided by
218+ /// multiple errors in the chain of sources which can cause unintended duplication of
219+ /// information in error reports or require heuristics to deduplicate.
220+ ///
221+ /// In otherwords, the following implementation pattern for `provide` is discouraged and should
222+ /// not be used for Error types exposed in public APIs to third parties.
223+ ///
224+ /// </div>
225+ ///
226+ /// ```rust
227+ /// # #![feature(error_generic_member_access)]
228+ /// # use core::fmt;
229+ /// # use core::error::{request_ref, Request};
230+ /// # #[derive(Debug)]
231+ /// struct MyError {
232+ /// source: Error,
233+ /// }
234+ /// # #[derive(Debug)]
235+ /// # struct Error;
236+ /// # impl fmt::Display for Error {
237+ /// # fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
238+ /// # write!(f, "Example Source Error")
239+ /// # }
240+ /// # }
241+ /// # impl fmt::Display for MyError {
242+ /// # fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
243+ /// # write!(f, "Example Error")
244+ /// # }
245+ /// # }
246+ /// # impl std::error::Error for Error { }
247+ ///
248+ /// impl std::error::Error for MyError {
249+ /// fn provide<'a>(&'a self, request: &mut Request<'a>) {
250+ /// self.source.provide(request)
251+ /// }
252+ /// }
253+ /// ```
208254 #[ unstable( feature = "error_generic_member_access" , issue = "99301" ) ]
209255 #[ allow( unused_variables) ]
210256 fn provide < ' a > ( & ' a self , request : & mut Request < ' a > ) { }
0 commit comments