@@ -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 > > {
@@ -1133,7 +1144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1133
1144
diag : & mut Diag < ' _ > ,
1134
1145
cause : & ObligationCause < ' tcx > ,
1135
1146
secondary_span : Option < ( Span , Cow < ' static , str > , bool ) > ,
1136
- mut values : Option < ValuePairs < ' tcx > > ,
1147
+ mut values : Option < ty :: ParamEnvAnd < ' tcx , ValuePairs < ' tcx > > > ,
1137
1148
terr : TypeError < ' tcx > ,
1138
1149
prefer_label : bool ,
1139
1150
) {
@@ -1241,8 +1252,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1241
1252
}
1242
1253
let ( expected_found, exp_found, is_simple_error, values) = match values {
1243
1254
None => ( None , Mismatch :: Fixed ( "type" ) , false , None ) ,
1244
- Some ( values) => {
1245
- let values = self . resolve_vars_if_possible ( values) ;
1255
+ Some ( ty :: ParamEnvAnd { param_env : _ , value : values } ) => {
1256
+ let mut values = self . resolve_vars_if_possible ( values) ;
1246
1257
let ( is_simple_error, exp_found) = match values {
1247
1258
ValuePairs :: Terms ( ExpectedFound { expected, found } ) => {
1248
1259
match ( expected. unpack ( ) , found. unpack ( ) ) {
@@ -1773,6 +1784,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1773
1784
pub fn report_and_explain_type_error (
1774
1785
& self ,
1775
1786
trace : TypeTrace < ' tcx > ,
1787
+ param_env : ty:: ParamEnv < ' tcx > ,
1776
1788
terr : TypeError < ' tcx > ,
1777
1789
) -> Diag < ' a > {
1778
1790
debug ! ( "report_and_explain_type_error(trace={:?}, terr={:?})" , trace, terr) ;
@@ -1784,7 +1796,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1784
1796
self . type_error_additional_suggestions ( & trace, terr) ,
1785
1797
) ;
1786
1798
let mut diag = self . dcx ( ) . create_err ( failure_code) ;
1787
- self . note_type_err ( & mut diag, & trace. cause , None , Some ( trace. values ) , terr, false ) ;
1799
+ self . note_type_err (
1800
+ & mut diag,
1801
+ & trace. cause ,
1802
+ None ,
1803
+ Some ( param_env. and ( trace. values ) ) ,
1804
+ terr,
1805
+ false ,
1806
+ ) ;
1788
1807
diag
1789
1808
}
1790
1809
0 commit comments