@@ -606,17 +606,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
606
606
// don't show type `_`
607
607
err. span_label ( span, format ! ( "this expression has type `{}`" , ty) ) ;
608
608
}
609
- if let Some ( ty:: error:: ExpectedFound { found, .. } ) = exp_found {
610
- if ty. is_box ( ) && ty. boxed_ty ( ) == found {
611
- if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
612
- err. span_suggestion (
613
- span,
614
- "consider dereferencing the boxed value" ,
615
- format ! ( "*{}" , snippet) ,
616
- Applicability :: MachineApplicable ,
617
- ) ;
618
- }
619
- }
609
+ if let Some ( ty:: error:: ExpectedFound { found, .. } ) = exp_found
610
+ && ty. is_box ( ) && ty. boxed_ty ( ) == found
611
+ && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
612
+ {
613
+ err. span_suggestion (
614
+ span,
615
+ "consider dereferencing the boxed value" ,
616
+ format ! ( "*{}" , snippet) ,
617
+ Applicability :: MachineApplicable ,
618
+ ) ;
620
619
}
621
620
}
622
621
ObligationCauseCode :: Pattern { origin_expr : false , span : Some ( span) , .. } => {
@@ -1748,13 +1747,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1748
1747
self . check_and_note_conflicting_crates ( diag, terr) ;
1749
1748
self . tcx . note_and_explain_type_err ( diag, terr, cause, span, body_owner_def_id. to_def_id ( ) ) ;
1750
1749
1751
- if let Some ( ValuePairs :: PolyTraitRefs ( exp_found) ) = values {
1752
- if let ty:: Closure ( def_id, _) = exp_found. expected . skip_binder ( ) . self_ty ( ) . kind ( ) {
1753
- if let Some ( def_id) = def_id. as_local ( ) {
1754
- let span = self . tcx . def_span ( def_id) ;
1755
- diag. span_note ( span, "this closure does not fulfill the lifetime requirements" ) ;
1756
- }
1757
- }
1750
+ if let Some ( ValuePairs :: PolyTraitRefs ( exp_found) ) = values
1751
+ && let ty:: Closure ( def_id, _) = exp_found. expected . skip_binder ( ) . self_ty ( ) . kind ( )
1752
+ && let Some ( def_id) = def_id. as_local ( )
1753
+ {
1754
+ let span = self . tcx . def_span ( def_id) ;
1755
+ diag. span_note ( span, "this closure does not fulfill the lifetime requirements" ) ;
1758
1756
}
1759
1757
1760
1758
// It reads better to have the error origin as the final
@@ -2046,19 +2044,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2046
2044
// containing a single character, perhaps the user meant to write `'c'` to
2047
2045
// specify a character literal (issue #92479)
2048
2046
( ty:: Char , ty:: Ref ( _, r, _) ) if r. is_str ( ) => {
2049
- if let Ok ( code) = self . tcx . sess ( ) . source_map ( ) . span_to_snippet ( span) {
2050
- if let Some ( code) =
2051
- code. strip_prefix ( '"' ) . and_then ( |s| s. strip_suffix ( '"' ) )
2052
- {
2053
- if code. chars ( ) . count ( ) == 1 {
2054
- err. span_suggestion (
2055
- span,
2056
- "if you meant to write a `char` literal, use single quotes" ,
2057
- format ! ( "'{}'" , code) ,
2058
- Applicability :: MachineApplicable ,
2059
- ) ;
2060
- }
2061
- }
2047
+ if let Ok ( code) = self . tcx . sess ( ) . source_map ( ) . span_to_snippet ( span)
2048
+ && let Some ( code) = code. strip_prefix ( '"' ) . and_then ( |s| s. strip_suffix ( '"' ) )
2049
+ && code. chars ( ) . count ( ) == 1
2050
+ {
2051
+ err. span_suggestion (
2052
+ span,
2053
+ "if you meant to write a `char` literal, use single quotes" ,
2054
+ format ! ( "'{}'" , code) ,
2055
+ Applicability :: MachineApplicable ,
2056
+ ) ;
2062
2057
}
2063
2058
}
2064
2059
// If a string was expected and the found expression is a character literal,
@@ -2080,18 +2075,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2080
2075
_ => { }
2081
2076
}
2082
2077
}
2083
- if let MatchExpressionArm ( box MatchExpressionArmCause { source, .. } ) =
2084
- * trace. cause . code ( )
2078
+ let code = trace. cause . code ( ) ;
2079
+ if let & MatchExpressionArm ( box MatchExpressionArmCause { source, .. } ) = code
2080
+ && let hir:: MatchSource :: TryDesugar = source
2081
+ && let Some ( ( expected_ty, found_ty) ) = self . values_str ( trace. values )
2085
2082
{
2086
- if let hir:: MatchSource :: TryDesugar = source {
2087
- if let Some ( ( expected_ty, found_ty) ) = self . values_str ( trace. values ) {
2088
- err. note ( & format ! (
2089
- "`?` operator cannot convert from `{}` to `{}`" ,
2090
- found_ty. content( ) ,
2091
- expected_ty. content( ) ,
2092
- ) ) ;
2093
- }
2094
- }
2083
+ err. note ( & format ! (
2084
+ "`?` operator cannot convert from `{}` to `{}`" ,
2085
+ found_ty. content( ) ,
2086
+ expected_ty. content( ) ,
2087
+ ) ) ;
2095
2088
}
2096
2089
err
2097
2090
}
0 commit comments