@@ -205,6 +205,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
205
205
self . note_obligation_cause_code (
206
206
& mut err,
207
207
& obligation. predicate ,
208
+ obligation. param_env ,
208
209
obligation. cause . code ( ) ,
209
210
& mut vec ! [ ] ,
210
211
& mut Default :: default ( ) ,
@@ -288,7 +289,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
288
289
match bound_predicate. skip_binder ( ) {
289
290
ty:: PredicateKind :: Trait ( trait_predicate) => {
290
291
let trait_predicate = bound_predicate. rebind ( trait_predicate) ;
291
- let trait_predicate = self . resolve_vars_if_possible ( trait_predicate) ;
292
+ let mut trait_predicate = self . resolve_vars_if_possible ( trait_predicate) ;
293
+
294
+ trait_predicate. remap_constness_diag ( obligation. param_env ) ;
295
+ let predicate_is_const = ty:: BoundConstness :: ConstIfConst
296
+ == trait_predicate. skip_binder ( ) . constness ;
292
297
293
298
if self . tcx . sess . has_errors ( ) && trait_predicate. references_error ( ) {
294
299
return ;
@@ -332,11 +337,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
332
337
span,
333
338
E0277 ,
334
339
"{}" ,
335
- message. unwrap_or_else( || format!(
336
- "the trait bound `{}` is not satisfied{}" ,
337
- trait_ref. without_const( ) . to_predicate( tcx) ,
338
- post_message,
339
- ) )
340
+ ( !predicate_is_const) . then( || message) . flatten( ) . unwrap_or_else(
341
+ || format!(
342
+ "the trait bound `{}` is not satisfied{}" ,
343
+ trait_predicate, post_message,
344
+ )
345
+ )
340
346
) ;
341
347
342
348
if is_try_conversion {
@@ -384,15 +390,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
384
390
format ! (
385
391
"{}the trait `{}` is not implemented for `{}`" ,
386
392
pre_message,
387
- trait_ref . print_only_trait_path ( ) ,
393
+ trait_predicate . print_modifiers_and_trait_path ( ) ,
388
394
trait_ref. skip_binder( ) . self_ty( ) ,
389
395
)
390
396
} ;
391
397
392
398
if self . suggest_add_reference_to_arg (
393
399
& obligation,
394
400
& mut err,
395
- & trait_ref ,
401
+ trait_predicate ,
396
402
have_alt_message,
397
403
) {
398
404
self . note_obligation_cause ( & mut err, & obligation) ;
@@ -435,18 +441,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
435
441
err. span_label ( enclosing_scope_span, s. as_str ( ) ) ;
436
442
}
437
443
438
- self . suggest_dereferences ( & obligation, & mut err, trait_ref) ;
439
- self . suggest_fn_call ( & obligation, & mut err, trait_ref) ;
440
- self . suggest_remove_reference ( & obligation, & mut err, trait_ref) ;
441
- self . suggest_semicolon_removal ( & obligation, & mut err, span, trait_ref) ;
444
+ self . suggest_dereferences ( & obligation, & mut err, trait_predicate) ;
445
+ self . suggest_fn_call ( & obligation, & mut err, trait_predicate) ;
446
+ self . suggest_remove_reference ( & obligation, & mut err, trait_predicate) ;
447
+ self . suggest_semicolon_removal (
448
+ & obligation,
449
+ & mut err,
450
+ span,
451
+ trait_predicate,
452
+ ) ;
442
453
self . note_version_mismatch ( & mut err, & trait_ref) ;
443
454
self . suggest_remove_await ( & obligation, & mut err) ;
444
455
445
456
if Some ( trait_ref. def_id ( ) ) == tcx. lang_items ( ) . try_trait ( ) {
446
- self . suggest_await_before_try ( & mut err, & obligation, trait_ref, span) ;
457
+ self . suggest_await_before_try (
458
+ & mut err,
459
+ & obligation,
460
+ trait_predicate,
461
+ span,
462
+ ) ;
447
463
}
448
464
449
- if self . suggest_impl_trait ( & mut err, span, & obligation, trait_ref ) {
465
+ if self . suggest_impl_trait ( & mut err, span, & obligation, trait_predicate ) {
450
466
err. emit ( ) ;
451
467
return ;
452
468
}
@@ -494,7 +510,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
494
510
// which is somewhat confusing.
495
511
self . suggest_restricting_param_bound (
496
512
& mut err,
497
- trait_ref ,
513
+ trait_predicate ,
498
514
obligation. cause . body_id ,
499
515
) ;
500
516
} else if !have_alt_message {
@@ -506,7 +522,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
506
522
// Changing mutability doesn't make a difference to whether we have
507
523
// an `Unsize` impl (Fixes ICE in #71036)
508
524
if !is_unsize {
509
- self . suggest_change_mut ( & obligation, & mut err, trait_ref ) ;
525
+ self . suggest_change_mut ( & obligation, & mut err, trait_predicate ) ;
510
526
}
511
527
512
528
// If this error is due to `!: Trait` not implemented but `(): Trait` is
@@ -1121,7 +1137,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
1121
1137
fn mk_trait_obligation_with_new_self_ty (
1122
1138
& self ,
1123
1139
param_env : ty:: ParamEnv < ' tcx > ,
1124
- trait_ref : ty:: PolyTraitRef < ' tcx > ,
1140
+ trait_ref : ty:: PolyTraitPredicate < ' tcx > ,
1125
1141
new_self_ty : Ty < ' tcx > ,
1126
1142
) -> PredicateObligation < ' tcx > ;
1127
1143
@@ -1540,7 +1556,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1540
1556
) -> Option < ( String , Option < Span > ) > {
1541
1557
match code {
1542
1558
ObligationCauseCode :: BuiltinDerivedObligation ( data) => {
1543
- let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
1559
+ let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_pred ) ;
1544
1560
match self . get_parent_trait_ref ( & data. parent_code ) {
1545
1561
Some ( t) => Some ( t) ,
1546
1562
None => {
@@ -1593,21 +1609,20 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1593
1609
fn mk_trait_obligation_with_new_self_ty (
1594
1610
& self ,
1595
1611
param_env : ty:: ParamEnv < ' tcx > ,
1596
- trait_ref : ty:: PolyTraitRef < ' tcx > ,
1612
+ trait_ref : ty:: PolyTraitPredicate < ' tcx > ,
1597
1613
new_self_ty : Ty < ' tcx > ,
1598
1614
) -> PredicateObligation < ' tcx > {
1599
1615
assert ! ( !new_self_ty. has_escaping_bound_vars( ) ) ;
1600
1616
1601
- let trait_ref = trait_ref. map_bound_ref ( |tr| ty:: TraitRef {
1602
- substs : self . tcx . mk_substs_trait ( new_self_ty, & tr. substs [ 1 ..] ) ,
1617
+ let trait_pred = trait_ref. map_bound_ref ( |tr| ty:: TraitPredicate {
1618
+ trait_ref : ty:: TraitRef {
1619
+ substs : self . tcx . mk_substs_trait ( new_self_ty, & tr. trait_ref . substs [ 1 ..] ) ,
1620
+ ..tr. trait_ref
1621
+ } ,
1603
1622
..* tr
1604
1623
} ) ;
1605
1624
1606
- Obligation :: new (
1607
- ObligationCause :: dummy ( ) ,
1608
- param_env,
1609
- trait_ref. without_const ( ) . to_predicate ( self . tcx ) ,
1610
- )
1625
+ Obligation :: new ( ObligationCause :: dummy ( ) , param_env, trait_pred. to_predicate ( self . tcx ) )
1611
1626
}
1612
1627
1613
1628
#[ instrument( skip( self ) , level = "debug" ) ]
@@ -2008,6 +2023,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
2008
2023
self . note_obligation_cause_code (
2009
2024
err,
2010
2025
& obligation. predicate ,
2026
+ obligation. param_env ,
2011
2027
obligation. cause . code ( ) ,
2012
2028
& mut vec ! [ ] ,
2013
2029
& mut Default :: default ( ) ,
@@ -2155,7 +2171,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
2155
2171
cause_code : & ObligationCauseCode < ' tcx > ,
2156
2172
) -> bool {
2157
2173
if let ObligationCauseCode :: BuiltinDerivedObligation ( ref data) = cause_code {
2158
- let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
2174
+ let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_pred ) ;
2159
2175
let self_ty = parent_trait_ref. skip_binder ( ) . self_ty ( ) ;
2160
2176
if obligated_types. iter ( ) . any ( |ot| ot == & self_ty) {
2161
2177
return true ;
0 commit comments