Skip to content

Commit 8ef535e

Browse files
committed
Point out the type of more expressions on bad ?
1 parent e565eee commit 8ef535e

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -961,14 +961,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
961961
let Some(typeck) = &self.typeck_results else {
962962
return false;
963963
};
964-
let Some((ObligationCauseCode::QuestionMark, Some(y))) =
965-
obligation.cause.code().parent_with_predicate()
966-
else {
964+
let ObligationCauseCode::QuestionMark = obligation.cause.code().peel_derives() else {
967965
return false;
968966
};
969-
if !self.tcx.is_diagnostic_item(sym::FromResidual, y.def_id()) {
970-
return false;
971-
}
972967
let self_ty = trait_pred.skip_binder().self_ty();
973968
let found_ty = trait_pred.skip_binder().trait_ref.args.get(1).and_then(|a| a.as_type());
974969

tests/ui/try-trait/bad-question-mark-on-trait-object.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn foo() -> Result<(), Box<dyn std::error::Error>> { //~ NOTE required `E: std::
77
//~| NOTE the trait `std::error::Error` is not implemented for `E`
88
//~| NOTE the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
99
//~| NOTE required for `Box<dyn std::error::Error>` to implement `From<E>`
10+
//~| NOTE this has type `Result<_, E>`
1011
//~| NOTE in this expansion
1112
//~| NOTE in this expansion
1213
//~| NOTE in this expansion

tests/ui/try-trait/bad-question-mark-on-trait-object.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ error[E0277]: `?` couldn't convert the error: `E: std::error::Error` is not sati
44
LL | fn foo() -> Result<(), Box<dyn std::error::Error>> {
55
| -------------------------------------- required `E: std::error::Error` because of this
66
LL | Ok(bar()?)
7-
| ^ the trait `std::error::Error` is not implemented for `E`
7+
| -----^ the trait `std::error::Error` is not implemented for `E`
8+
| |
9+
| this has type `Result<_, E>`
810
|
911
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
1012
= note: required for `Box<dyn std::error::Error>` to implement `From<E>`
1113

1214
error[E0277]: `?` couldn't convert the error to `X`
13-
--> $DIR/bad-question-mark-on-trait-object.rs:15:13
15+
--> $DIR/bad-question-mark-on-trait-object.rs:16:13
1416
|
1517
LL | fn bat() -> Result<(), X> {
1618
| ------------- expected `X` because of this

0 commit comments

Comments
 (0)