@@ -14,6 +14,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
14
14
use rustc_hir:: intravisit:: Visitor ;
15
15
use rustc_hir:: { self as hir, LangItem , Node } ;
16
16
use rustc_infer:: infer:: { InferOk , TypeTrace } ;
17
+ use rustc_infer:: traits:: solve:: Goal ;
17
18
use rustc_middle:: traits:: SignatureMismatchData ;
18
19
use rustc_middle:: traits:: select:: OverflowError ;
19
20
use rustc_middle:: ty:: abstract_const:: NotConstEvaluatable ;
@@ -930,7 +931,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
930
931
) ) = arg. kind
931
932
&& let Node :: Pat ( pat) = self . tcx . hir_node ( * hir_id)
932
933
&& let Some ( ( preds, guar) ) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
933
- && preds. contains ( & obligation. predicate )
934
+ && preds. contains ( & obligation. as_goal ( ) )
934
935
{
935
936
return Err ( * guar) ;
936
937
}
@@ -1292,6 +1293,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1292
1293
impl < ' a , ' tcx > TypeErrCtxt < ' a , ' tcx > {
1293
1294
fn can_match_trait (
1294
1295
& self ,
1296
+ param_env : ty:: ParamEnv < ' tcx > ,
1295
1297
goal : ty:: TraitPredicate < ' tcx > ,
1296
1298
assumption : ty:: PolyTraitPredicate < ' tcx > ,
1297
1299
) -> bool {
@@ -1306,11 +1308,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1306
1308
assumption,
1307
1309
) ;
1308
1310
1309
- self . can_eq ( ty :: ParamEnv :: empty ( ) , goal. trait_ref , trait_assumption. trait_ref )
1311
+ self . can_eq ( param_env , goal. trait_ref , trait_assumption. trait_ref )
1310
1312
}
1311
1313
1312
1314
fn can_match_projection (
1313
1315
& self ,
1316
+ param_env : ty:: ParamEnv < ' tcx > ,
1314
1317
goal : ty:: ProjectionPredicate < ' tcx > ,
1315
1318
assumption : ty:: PolyProjectionPredicate < ' tcx > ,
1316
1319
) -> bool {
@@ -1320,7 +1323,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1320
1323
assumption,
1321
1324
) ;
1322
1325
1323
- let param_env = ty:: ParamEnv :: empty ( ) ;
1324
1326
self . can_eq ( param_env, goal. projection_term , assumption. projection_term )
1325
1327
&& self . can_eq ( param_env, goal. term , assumption. term )
1326
1328
}
@@ -1330,24 +1332,32 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1330
1332
#[ instrument( level = "debug" , skip( self ) , ret) ]
1331
1333
pub ( super ) fn error_implies (
1332
1334
& self ,
1333
- cond : ty:: Predicate < ' tcx > ,
1334
- error : ty:: Predicate < ' tcx > ,
1335
+ cond : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
1336
+ error : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
1335
1337
) -> bool {
1336
1338
if cond == error {
1337
1339
return true ;
1338
1340
}
1339
1341
1340
- if let Some ( error) = error. as_trait_clause ( ) {
1342
+ // FIXME: We could be smarter about this, i.e. if cond's param-env is a
1343
+ // subset of error's param-env. This only matters when binders will carry
1344
+ // predicates though, and obviously only matters for error reporting.
1345
+ if cond. param_env != error. param_env {
1346
+ return false ;
1347
+ }
1348
+ let param_env = error. param_env ;
1349
+
1350
+ if let Some ( error) = error. predicate . as_trait_clause ( ) {
1341
1351
self . enter_forall ( error, |error| {
1342
- elaborate ( self . tcx , std:: iter:: once ( cond) )
1352
+ elaborate ( self . tcx , std:: iter:: once ( cond. predicate ) )
1343
1353
. filter_map ( |implied| implied. as_trait_clause ( ) )
1344
- . any ( |implied| self . can_match_trait ( error, implied) )
1354
+ . any ( |implied| self . can_match_trait ( param_env , error, implied) )
1345
1355
} )
1346
- } else if let Some ( error) = error. as_projection_clause ( ) {
1356
+ } else if let Some ( error) = error. predicate . as_projection_clause ( ) {
1347
1357
self . enter_forall ( error, |error| {
1348
- elaborate ( self . tcx , std:: iter:: once ( cond) )
1358
+ elaborate ( self . tcx , std:: iter:: once ( cond. predicate ) )
1349
1359
. filter_map ( |implied| implied. as_projection_clause ( ) )
1350
- . any ( |implied| self . can_match_projection ( error, implied) )
1360
+ . any ( |implied| self . can_match_projection ( param_env , error, implied) )
1351
1361
} )
1352
1362
} else {
1353
1363
false
0 commit comments