@@ -1971,6 +1971,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1971
1971
trace : TypeTrace < ' tcx > ,
1972
1972
terr : & TypeError < ' tcx > ,
1973
1973
) -> DiagnosticBuilder < ' tcx > {
1974
+ use crate :: traits:: ObligationCauseCode :: MatchExpressionArm ;
1975
+
1974
1976
debug ! ( "report_and_explain_type_error(trace={:?}, terr={:?})" , trace, terr) ;
1975
1977
1976
1978
let span = trace. cause . span ( self . tcx ) ;
@@ -2013,6 +2015,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2013
2015
_ => { }
2014
2016
}
2015
2017
}
2018
+ if let MatchExpressionArm ( box MatchExpressionArmCause { source, .. } ) =
2019
+ trace. cause . code
2020
+ {
2021
+ if let hir:: MatchSource :: TryDesugar = source {
2022
+ if let Some ( ( expected_ty, found_ty) ) = self . values_str ( trace. values ) {
2023
+ err. note ( & format ! (
2024
+ "`?` operator cannot convert from `{}` to `{}`" ,
2025
+ found_ty. content( ) ,
2026
+ expected_ty. content( ) ,
2027
+ ) ) ;
2028
+ }
2029
+ }
2030
+ }
2016
2031
err
2017
2032
}
2018
2033
FailureCode :: Error0644 ( failure_str) => {
@@ -2585,9 +2600,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
2585
2600
CompareImplTypeObligation { .. } => Error0308 ( "type not compatible with trait" ) ,
2586
2601
MatchExpressionArm ( box MatchExpressionArmCause { source, .. } ) => {
2587
2602
Error0308 ( match source {
2588
- hir:: MatchSource :: TryDesugar => {
2589
- "try expression alternatives have incompatible types"
2590
- }
2603
+ hir:: MatchSource :: TryDesugar => "`?` operator has incompatible types" ,
2591
2604
_ => "`match` arms have incompatible types" ,
2592
2605
} )
2593
2606
}
0 commit comments