@@ -202,6 +202,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
202202 & obligation. cause . code ,
203203 & mut vec ! [ ] ,
204204 & mut Default :: default ( ) ,
205+ None ,
205206 ) ;
206207
207208 err. emit ( ) ;
@@ -232,6 +233,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
232233 ) {
233234 let tcx = self . tcx ;
234235 let span = obligation. cause . span ;
236+ let mut obligation_note = None ;
235237
236238 let mut err = match * error {
237239 SelectionError :: Unimplemented => {
@@ -321,7 +323,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
321323 ident,
322324 ..
323325 } ) ) => {
324- err . note (
326+ obligation_note = Some (
325327 "associated types introduce an implicit `Sized` \
326328 obligation",
327329 ) ;
@@ -349,7 +351,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
349351 kind : hir:: ImplItemKind :: TyAlias ( _) ,
350352 ..
351353 } ) ) => {
352- err . note (
354+ obligation_note = Some (
353355 "associated types on `impl` blocks for types, have an \
354356 implicit mandatory `Sized` obligation; associated \
355357 types from `trait`s can be relaxed to `?Sized`",
@@ -358,7 +360,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
358360 _ => {
359361 // This is (likely?) a type parameter. The suggestion is handled
360362 // in `rustc_middle/src/ty/diagnostics.rs`.
361- err . note (
363+ obligation_note = Some (
362364 "type parameters introduce an implicit `Sized` \
363365 obligation",
364366 ) ;
@@ -423,7 +425,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
423425 points_at_arg,
424426 have_alt_message,
425427 ) {
426- self . note_obligation_cause ( & mut err, obligation) ;
428+ self . note_obligation_cause ( & mut err, obligation, obligation_note ) ;
427429 err. emit ( ) ;
428430 return ;
429431 }
@@ -852,7 +854,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
852854 }
853855 } ;
854856
855- self . note_obligation_cause ( & mut err, obligation) ;
857+ self . note_obligation_cause ( & mut err, obligation, obligation_note ) ;
856858 self . point_at_returns_when_relevant ( & mut err, & obligation) ;
857859
858860 err. emit ( ) ;
@@ -1135,6 +1137,7 @@ trait InferCtxtPrivExt<'tcx> {
11351137 & self ,
11361138 err : & mut DiagnosticBuilder < ' tcx > ,
11371139 obligation : & PredicateObligation < ' tcx > ,
1140+ note : Option < & str > ,
11381141 ) ;
11391142
11401143 fn suggest_unsized_bound_if_applicable (
@@ -1355,7 +1358,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13551358 _ => None ,
13561359 } ;
13571360 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 ) ;
13591362 diag. emit ( ) ;
13601363 }
13611364 } ) ;
@@ -1764,7 +1767,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17641767 err
17651768 }
17661769 } ;
1767- self . note_obligation_cause ( & mut err, obligation) ;
1770+ self . note_obligation_cause ( & mut err, obligation, None ) ;
17681771 err. emit ( ) ;
17691772 }
17701773
@@ -1828,6 +1831,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
18281831 & self ,
18291832 err : & mut DiagnosticBuilder < ' tcx > ,
18301833 obligation : & PredicateObligation < ' tcx > ,
1834+ note : Option < & str > ,
18311835 ) {
18321836 // First, attempt to add note to this error with an async-await-specific
18331837 // message, and fall back to regular note otherwise.
@@ -1838,6 +1842,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
18381842 & obligation. cause . code ,
18391843 & mut vec ! [ ] ,
18401844 & mut Default :: default ( ) ,
1845+ note,
18411846 ) ;
18421847 self . suggest_unsized_bound_if_applicable ( err, obligation) ;
18431848 }
0 commit comments