about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs7
-rw-r--r--tests/ui/try-trait/bad-question-mark-on-trait-object.rs1
-rw-r--r--tests/ui/try-trait/bad-question-mark-on-trait-object.stderr6
3 files changed, 6 insertions, 8 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
index 133d8a88de3..4004fdd073c 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
@@ -961,14 +961,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
         let Some(typeck) = &self.typeck_results else {
             return false;
         };
-        let Some((ObligationCauseCode::QuestionMark, Some(y))) =
-            obligation.cause.code().parent_with_predicate()
-        else {
+        let ObligationCauseCode::QuestionMark = obligation.cause.code().peel_derives() else {
             return false;
         };
-        if !self.tcx.is_diagnostic_item(sym::FromResidual, y.def_id()) {
-            return false;
-        }
         let self_ty = trait_pred.skip_binder().self_ty();
         let found_ty = trait_pred.skip_binder().trait_ref.args.get(1).and_then(|a| a.as_type());
 
diff --git a/tests/ui/try-trait/bad-question-mark-on-trait-object.rs b/tests/ui/try-trait/bad-question-mark-on-trait-object.rs
index f319610cb3a..9efac78b3d7 100644
--- a/tests/ui/try-trait/bad-question-mark-on-trait-object.rs
+++ b/tests/ui/try-trait/bad-question-mark-on-trait-object.rs
@@ -7,6 +7,7 @@ fn foo() -> Result<(), Box<dyn std::error::Error>> { //~ NOTE required `E: std::
     //~| NOTE the trait `std::error::Error` is not implemented for `E`
     //~| NOTE the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
     //~| NOTE required for `Box<dyn std::error::Error>` to implement `From<E>`
+    //~| NOTE this has type `Result<_, E>`
     //~| NOTE in this expansion
     //~| NOTE in this expansion
     //~| NOTE in this expansion
diff --git a/tests/ui/try-trait/bad-question-mark-on-trait-object.stderr b/tests/ui/try-trait/bad-question-mark-on-trait-object.stderr
index 4e7cd1e2889..adebc16915d 100644
--- a/tests/ui/try-trait/bad-question-mark-on-trait-object.stderr
+++ b/tests/ui/try-trait/bad-question-mark-on-trait-object.stderr
@@ -4,13 +4,15 @@ error[E0277]: `?` couldn't convert the error: `E: std::error::Error` is not sati
 LL | fn foo() -> Result<(), Box<dyn std::error::Error>> {
    |             -------------------------------------- required `E: std::error::Error` because of this
 LL |     Ok(bar()?)
-   |             ^ the trait `std::error::Error` is not implemented for `E`
+   |        -----^ the trait `std::error::Error` is not implemented for `E`
+   |        |
+   |        this has type `Result<_, E>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = note: required for `Box<dyn std::error::Error>` to implement `From<E>`
 
 error[E0277]: `?` couldn't convert the error to `X`
-  --> $DIR/bad-question-mark-on-trait-object.rs:15:13
+  --> $DIR/bad-question-mark-on-trait-object.rs:16:13
    |
 LL | fn bat() -> Result<(), X> {
    |             ------------- expected `X` because of this