@@ -856,7 +856,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
856
856
. regions ( )
857
857
. map ( |lifetime| {
858
858
let s = lifetime. to_string ( ) ;
859
- if s. is_empty ( ) { "'_" . to_string ( ) } else { s }
859
+ if s. is_empty ( ) {
860
+ "'_" . to_string ( )
861
+ } else {
862
+ s
863
+ }
860
864
} )
861
865
. collect :: < Vec < _ > > ( )
862
866
. join ( ", " ) ;
@@ -1175,7 +1179,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1175
1179
1176
1180
fn lifetime_display ( lifetime : Region < ' _ > ) -> String {
1177
1181
let s = lifetime. to_string ( ) ;
1178
- if s. is_empty ( ) { "'_" . to_string ( ) } else { s }
1182
+ if s. is_empty ( ) {
1183
+ "'_" . to_string ( )
1184
+ } else {
1185
+ s
1186
+ }
1179
1187
}
1180
1188
// At one point we'd like to elide all lifetimes here, they are irrelevant for
1181
1189
// all diagnostics that use this output
@@ -1449,7 +1457,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1449
1457
swap_secondary_and_primary : bool ,
1450
1458
) {
1451
1459
let span = cause. span ( self . tcx ) ;
1452
- debug ! ( "note_type_err cause={:?} values={:?}, terr={:?}" , cause, values, terr) ;
1453
1460
1454
1461
// For some types of errors, expected-found does not make
1455
1462
// sense, so just ignore the values we were given.
@@ -1581,11 +1588,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1581
1588
}
1582
1589
}
1583
1590
1584
- debug ! ( "note_type_err(diag={:?})" , diag) ;
1585
1591
enum Mismatch < ' a > {
1586
1592
Variable ( ty:: error:: ExpectedFound < Ty < ' a > > ) ,
1587
1593
Fixed ( & ' static str ) ,
1588
1594
}
1595
+
1589
1596
let ( expected_found, exp_found, is_simple_error) = match values {
1590
1597
None => ( None , Mismatch :: Fixed ( "type" ) , false ) ,
1591
1598
Some ( values) => {
@@ -1652,6 +1659,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1652
1659
}
1653
1660
}
1654
1661
} ;
1662
+
1655
1663
if let Some ( ( expected, found) ) = expected_found {
1656
1664
let ( expected_label, found_label, exp_found) = match exp_found {
1657
1665
Mismatch :: Variable ( ef) => (
@@ -1705,6 +1713,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1705
1713
( TypeError :: ObjectUnsafeCoercion ( _) , _) => {
1706
1714
diag. note_unsuccessful_coercion ( found, expected) ;
1707
1715
}
1716
+ ( TypeError :: ConstMismatchTooGeneric ( _, Some ( sugg) ) , _) => {
1717
+ if !is_simple_error {
1718
+ let found =
1719
+ DiagnosticStyledString :: highlighted ( format ! ( "{}" , sugg. clone( ) ) ) ;
1720
+
1721
+ diag. note_expected_found (
1722
+ & expected_label,
1723
+ expected,
1724
+ & "type" . to_string ( ) ,
1725
+ found,
1726
+ ) ;
1727
+ }
1728
+ }
1708
1729
( _, _) => {
1709
1730
debug ! (
1710
1731
"note_type_err: exp_found={:?}, expected={:?} found={:?}" ,
@@ -1716,10 +1737,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1716
1737
}
1717
1738
}
1718
1739
}
1740
+
1719
1741
let exp_found = match exp_found {
1720
1742
Mismatch :: Variable ( exp_found) => Some ( exp_found) ,
1721
1743
Mismatch :: Fixed ( _) => None ,
1722
1744
} ;
1745
+
1723
1746
let exp_found = match terr {
1724
1747
// `terr` has more accurate type information than `exp_found` in match expressions.
1725
1748
ty:: error:: TypeError :: Sorts ( terr)
@@ -1730,6 +1753,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1730
1753
_ => exp_found,
1731
1754
} ;
1732
1755
debug ! ( "exp_found {:?} terr {:?} cause.code {:?}" , exp_found, terr, cause. code( ) ) ;
1756
+
1733
1757
if let Some ( exp_found) = exp_found {
1734
1758
let should_suggest_fixes = if let ObligationCauseCode :: Pattern { root_ty, .. } =
1735
1759
cause. code ( )
@@ -1756,6 +1780,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1756
1780
self . tcx . hir ( ) . opt_local_def_id ( cause. body_id ) . unwrap_or_else ( || {
1757
1781
self . tcx . hir ( ) . body_owner_def_id ( hir:: BodyId { hir_id : cause. body_id } )
1758
1782
} ) ;
1783
+
1759
1784
self . check_and_note_conflicting_crates ( diag, terr) ;
1760
1785
self . tcx . note_and_explain_type_err ( diag, terr, cause, span, body_owner_def_id. to_def_id ( ) ) ;
1761
1786
@@ -2021,10 +2046,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2021
2046
) -> DiagnosticBuilder < ' tcx > {
2022
2047
use crate :: traits:: ObligationCauseCode :: MatchExpressionArm ;
2023
2048
2024
- debug ! ( "report_and_explain_type_error(trace={:?}, terr={:?})" , trace, terr) ;
2025
-
2026
2049
let span = trace. cause . span ( self . tcx ) ;
2027
2050
let failure_code = trace. cause . as_failure_code ( terr) ;
2051
+
2028
2052
let mut diag = match failure_code {
2029
2053
FailureCode :: Error0038 ( did) => {
2030
2054
let violations = self . tcx . object_safety_violations ( did) ;
@@ -2038,9 +2062,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2038
2062
}
2039
2063
FailureCode :: Error0308 ( failure_str) => {
2040
2064
let mut err = struct_span_err ! ( self . tcx. sess, span, E0308 , "{}" , failure_str) ;
2065
+
2041
2066
if let ValuePairs :: Types ( ty:: error:: ExpectedFound { expected, found } ) =
2042
2067
trace. values
2043
2068
{
2069
+ debug ! ( ?expected, ?found) ;
2070
+
2044
2071
// If a tuple of length one was expected and the found expression has
2045
2072
// parentheses around it, perhaps the user meant to write `(expr,)` to
2046
2073
// build a tuple (issue #86100)
0 commit comments