@@ -104,38 +104,30 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
104104 pub ( crate ) fn cannot_uniquely_borrow_by_one_closure (
105105 & self ,
106106 new_loan_span : Span ,
107- container_name : & str ,
107+ is_generator : bool ,
108108 desc_new : & str ,
109109 opt_via : & str ,
110110 old_loan_span : Span ,
111111 noun_old : & str ,
112112 old_opt_via : & str ,
113113 previous_end_span : Option < Span > ,
114114 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
115- let mut err = struct_span_err ! (
116- self ,
115+ self . infcx . tcx . sess . create_err ( crate :: session_diagnostics:: ClosureUniquelyBorrowErr {
117116 new_loan_span,
118- E0500 ,
119- "closure requires unique access to {} but {} is already borrowed{}" ,
117+ is_generator,
120118 desc_new,
119+ opt_via,
120+ old_loan_span,
121121 noun_old,
122122 old_opt_via,
123- ) ;
124- err. span_label (
125- new_loan_span,
126- format ! ( "{} construction occurs here{}" , container_name, opt_via) ,
127- ) ;
128- err. span_label ( old_loan_span, format ! ( "borrow occurs here{}" , old_opt_via) ) ;
129- if let Some ( previous_end_span) = previous_end_span {
130- err. span_label ( previous_end_span, "borrow ends here" ) ;
131- }
132- err
123+ previous_end_span,
124+ } )
133125 }
134126
135127 pub ( crate ) fn cannot_reborrow_already_uniquely_borrowed (
136128 & self ,
137129 new_loan_span : Span ,
138- container_name : & str ,
130+ is_generator : & str ,
139131 desc_new : & str ,
140132 opt_via : & str ,
141133 kind_new : & str ,
@@ -144,27 +136,17 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
144136 previous_end_span : Option < Span > ,
145137 second_borrow_desc : & str ,
146138 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
147- let mut err = struct_span_err ! (
148- self ,
139+ self . infcx . tcx . sess . create_err ( crate :: session_diagnostics:: ClosureReBorrowErr {
149140 new_loan_span,
150- E0501 ,
151- "cannot borrow {}{} as {} because previous closure requires unique access" ,
141+ is_generator,
152142 desc_new,
153143 opt_via,
154144 kind_new,
155- ) ;
156- err. span_label (
157- new_loan_span,
158- format ! ( "{}borrow occurs here{}" , second_borrow_desc, opt_via) ,
159- ) ;
160- err. span_label (
161145 old_loan_span,
162- format ! ( "{} construction occurs here{}" , container_name, old_opt_via) ,
163- ) ;
164- if let Some ( previous_end_span) = previous_end_span {
165- err. span_label ( previous_end_span, "borrow from closure ends here" ) ;
166- }
167- err
146+ old_opt_via,
147+ previous_end_span,
148+ second_borrow_desc,
149+ } )
168150 }
169151
170152 pub ( crate ) fn cannot_reborrow_already_borrowed (
0 commit comments