@@ -202,6 +202,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
202
202
& obligation. cause . code ,
203
203
& mut vec ! [ ] ,
204
204
& mut Default :: default ( ) ,
205
+ None ,
205
206
) ;
206
207
207
208
err. emit ( ) ;
@@ -232,6 +233,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
232
233
) {
233
234
let tcx = self . tcx ;
234
235
let span = obligation. cause . span ;
236
+ let mut obligation_note = None ;
235
237
236
238
let mut err = match * error {
237
239
SelectionError :: Unimplemented => {
@@ -321,7 +323,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
321
323
ident,
322
324
..
323
325
} ) ) => {
324
- err . note (
326
+ obligation_note = Some (
325
327
"associated types introduce an implicit `Sized` \
326
328
obligation",
327
329
) ;
@@ -349,7 +351,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
349
351
kind : hir:: ImplItemKind :: TyAlias ( _) ,
350
352
..
351
353
} ) ) => {
352
- err . note (
354
+ obligation_note = Some (
353
355
"associated types on `impl` blocks for types, have an \
354
356
implicit mandatory `Sized` obligation; associated \
355
357
types from `trait`s can be relaxed to `?Sized`",
@@ -358,7 +360,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
358
360
_ => {
359
361
// This is (likely?) a type parameter. The suggestion is handled
360
362
// in `rustc_middle/src/ty/diagnostics.rs`.
361
- err . note (
363
+ obligation_note = Some (
362
364
"type parameters introduce an implicit `Sized` \
363
365
obligation",
364
366
) ;
@@ -423,7 +425,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
423
425
points_at_arg,
424
426
have_alt_message,
425
427
) {
426
- self . note_obligation_cause ( & mut err, obligation) ;
428
+ self . note_obligation_cause ( & mut err, obligation, obligation_note ) ;
427
429
err. emit ( ) ;
428
430
return ;
429
431
}
@@ -852,7 +854,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
852
854
}
853
855
} ;
854
856
855
- self . note_obligation_cause ( & mut err, obligation) ;
857
+ self . note_obligation_cause ( & mut err, obligation, obligation_note ) ;
856
858
self . point_at_returns_when_relevant ( & mut err, & obligation) ;
857
859
858
860
err. emit ( ) ;
@@ -1135,6 +1137,7 @@ trait InferCtxtPrivExt<'tcx> {
1135
1137
& self ,
1136
1138
err : & mut DiagnosticBuilder < ' tcx > ,
1137
1139
obligation : & PredicateObligation < ' tcx > ,
1140
+ note : Option < & str > ,
1138
1141
) ;
1139
1142
1140
1143
fn suggest_unsized_bound_if_applicable (
@@ -1355,7 +1358,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1355
1358
_ => None ,
1356
1359
} ;
1357
1360
self . note_type_err ( & mut diag, & obligation. cause , secondary_span, values, err, true ) ;
1358
- self . note_obligation_cause ( & mut diag, obligation) ;
1361
+ self . note_obligation_cause ( & mut diag, obligation, None ) ;
1359
1362
diag. emit ( ) ;
1360
1363
}
1361
1364
} ) ;
@@ -1764,7 +1767,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1764
1767
err
1765
1768
}
1766
1769
} ;
1767
- self . note_obligation_cause ( & mut err, obligation) ;
1770
+ self . note_obligation_cause ( & mut err, obligation, None ) ;
1768
1771
err. emit ( ) ;
1769
1772
}
1770
1773
@@ -1828,6 +1831,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1828
1831
& self ,
1829
1832
err : & mut DiagnosticBuilder < ' tcx > ,
1830
1833
obligation : & PredicateObligation < ' tcx > ,
1834
+ note : Option < & str > ,
1831
1835
) {
1832
1836
// First, attempt to add note to this error with an async-await-specific
1833
1837
// message, and fall back to regular note otherwise.
@@ -1838,6 +1842,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1838
1842
& obligation. cause . code ,
1839
1843
& mut vec ! [ ] ,
1840
1844
& mut Default :: default ( ) ,
1845
+ note,
1841
1846
) ;
1842
1847
self . suggest_unsized_bound_if_applicable ( err, obligation) ;
1843
1848
}
0 commit comments