@@ -75,6 +75,7 @@ use crate::errors::{ObligationCauseFailureCode, TypeErrorAdditionalDiags};
75
75
use crate :: infer;
76
76
use crate :: infer:: relate:: { self , RelateResult , TypeRelation } ;
77
77
use crate :: infer:: { InferCtxt , TypeTrace , ValuePairs } ;
78
+ use crate :: solve:: deeply_normalize_for_diagnostics;
78
79
use crate :: traits:: {
79
80
IfExpressionCause , MatchExpressionArmCause , ObligationCause , ObligationCauseCode ,
80
81
} ;
@@ -145,21 +146,31 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
145
146
pub fn report_mismatched_types (
146
147
& self ,
147
148
cause : & ObligationCause < ' tcx > ,
149
+ param_env : ty:: ParamEnv < ' tcx > ,
148
150
expected : Ty < ' tcx > ,
149
151
actual : Ty < ' tcx > ,
150
152
err : TypeError < ' tcx > ,
151
153
) -> Diag < ' a > {
152
- self . report_and_explain_type_error ( TypeTrace :: types ( cause, true , expected, actual) , err)
154
+ self . report_and_explain_type_error (
155
+ TypeTrace :: types ( cause, true , expected, actual) ,
156
+ param_env,
157
+ err,
158
+ )
153
159
}
154
160
155
161
pub fn report_mismatched_consts (
156
162
& self ,
157
163
cause : & ObligationCause < ' tcx > ,
164
+ param_env : ty:: ParamEnv < ' tcx > ,
158
165
expected : ty:: Const < ' tcx > ,
159
166
actual : ty:: Const < ' tcx > ,
160
167
err : TypeError < ' tcx > ,
161
168
) -> Diag < ' a > {
162
- self . report_and_explain_type_error ( TypeTrace :: consts ( cause, true , expected, actual) , err)
169
+ self . report_and_explain_type_error (
170
+ TypeTrace :: consts ( cause, true , expected, actual) ,
171
+ param_env,
172
+ err,
173
+ )
163
174
}
164
175
165
176
pub fn get_impl_future_output_ty ( & self , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
@@ -1136,7 +1147,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1136
1147
diag : & mut Diag < ' _ > ,
1137
1148
cause : & ObligationCause < ' tcx > ,
1138
1149
secondary_span : Option < ( Span , Cow < ' static , str > ) > ,
1139
- mut values : Option < ValuePairs < ' tcx > > ,
1150
+ mut values : Option < ( ValuePairs < ' tcx > , ty :: ParamEnv < ' tcx > ) > ,
1140
1151
terr : TypeError < ' tcx > ,
1141
1152
swap_secondary_and_primary : bool ,
1142
1153
prefer_label : bool ,
@@ -1245,7 +1256,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1245
1256
}
1246
1257
let ( expected_found, exp_found, is_simple_error, values) = match values {
1247
1258
None => ( None , Mismatch :: Fixed ( "type" ) , false , None ) ,
1248
- Some ( values) => {
1259
+ Some ( ( values, _param_env ) ) => {
1249
1260
let values = self . resolve_vars_if_possible ( values) ;
1250
1261
let ( is_simple_error, exp_found) = match values {
1251
1262
ValuePairs :: Terms ( ExpectedFound { expected, found } ) => {
@@ -1777,6 +1788,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1777
1788
pub fn report_and_explain_type_error (
1778
1789
& self ,
1779
1790
trace : TypeTrace < ' tcx > ,
1791
+ param_env : ty:: ParamEnv < ' tcx > ,
1780
1792
terr : TypeError < ' tcx > ,
1781
1793
) -> Diag < ' a > {
1782
1794
debug ! ( "report_and_explain_type_error(trace={:?}, terr={:?})" , trace, terr) ;
@@ -1788,7 +1800,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1788
1800
self . type_error_additional_suggestions ( & trace, terr) ,
1789
1801
) ;
1790
1802
let mut diag = self . dcx ( ) . create_err ( failure_code) ;
1791
- self . note_type_err ( & mut diag, & trace. cause , None , Some ( trace. values ) , terr, false , false ) ;
1803
+ self . note_type_err (
1804
+ & mut diag,
1805
+ & trace. cause ,
1806
+ None ,
1807
+ Some ( ( trace. values , param_env) ) ,
1808
+ terr,
1809
+ false ,
1810
+ false ,
1811
+ ) ;
1792
1812
diag
1793
1813
}
1794
1814
0 commit comments