Point out the type of more expressions on bad ?

This commit is contained in:
Esteban Küber 2025-02-20 19:07:39 +00:00
parent e565eeed78
commit 8ef535e03d
3 changed files with 6 additions and 8 deletions

View file

@ -961,14 +961,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let Some(typeck) = &self.typeck_results else { let Some(typeck) = &self.typeck_results else {
return false; return false;
}; };
let Some((ObligationCauseCode::QuestionMark, Some(y))) = let ObligationCauseCode::QuestionMark = obligation.cause.code().peel_derives() else {
obligation.cause.code().parent_with_predicate()
else {
return false; 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 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()); let found_ty = trait_pred.skip_binder().trait_ref.args.get(1).and_then(|a| a.as_type());

View file

@ -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 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 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 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 //~| NOTE in this expansion
//~| NOTE in this expansion //~| NOTE in this expansion

View file

@ -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>> { LL | fn foo() -> Result<(), Box<dyn std::error::Error>> {
| -------------------------------------- required `E: std::error::Error` because of this | -------------------------------------- required `E: std::error::Error` because of this
LL | Ok(bar()?) 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: 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: required for `Box<dyn std::error::Error>` to implement `From<E>`
error[E0277]: `?` couldn't convert the error to `X` 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> { LL | fn bat() -> Result<(), X> {
| ------------- expected `X` because of this | ------------- expected `X` because of this