1+ // #![deny(rustc::untranslatable_diagnostic)]
2+ // #![deny(rustc::diagnostic_outside_of_impl)]
3+
14use std:: fmt:: { self , Display } ;
25use std:: iter;
36
@@ -10,6 +13,7 @@ use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty};
1013use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
1114use rustc_span:: { Span , DUMMY_SP } ;
1215
16+ use crate :: session_diagnostics:: RegionNameLables ;
1317use crate :: { nll:: ToRegionVid , universal_regions:: DefiningTy , MirBorrowckCtxt } ;
1418
1519/// A name for a particular region used in emitting diagnostics. This name could be a generated
@@ -133,48 +137,58 @@ impl RegionName {
133137 RegionNameHighlight :: MatchedAdtAndSegment ( span) ,
134138 _,
135139 ) => {
136- diag. span_label ( * span, format ! ( "let's call this `{ self}`" ) ) ;
140+ diag. subdiagnostic ( RegionNameLables :: NameRegion { span : * span, rg_name : self } ) ;
137141 }
138142 RegionNameSource :: AnonRegionFromArgument ( RegionNameHighlight :: Occluded (
139143 span,
140144 type_name,
141145 ) ) => {
142- diag. span_label (
143- * span,
144- format ! ( "lifetime `{self}` appears in the type {type_name}" ) ,
145- ) ;
146+ diag. subdiagnostic ( RegionNameLables :: LifetimeInType {
147+ span : * span,
148+ type_name : & type_name,
149+ rg_name : self ,
150+ } ) ;
146151 }
147152 RegionNameSource :: AnonRegionFromOutput (
148153 RegionNameHighlight :: Occluded ( span, type_name) ,
149154 mir_description,
150155 ) => {
151- diag. span_label (
152- * span,
153- format ! (
154- "return type{mir_description} `{ type_name}` contains a lifetime `{self}`"
155- ) ,
156- ) ;
156+ diag. subdiagnostic ( RegionNameLables :: LifetimeInReturned {
157+ span : * span,
158+ mir_description ,
159+ type_name : & type_name ,
160+ rg_name : self ,
161+ } ) ;
157162 }
158163 RegionNameSource :: AnonRegionFromUpvar ( span, upvar_name) => {
159- diag. span_label (
160- * span,
161- format ! ( "lifetime `{self}` appears in the type of `{upvar_name}`" ) ,
162- ) ;
164+ diag. subdiagnostic ( RegionNameLables :: LifetimeInTypeOf {
165+ span : * span,
166+ upvar_name : upvar_name. to_ident_string ( ) ,
167+ rg_name : self ,
168+ } ) ;
163169 }
164170 RegionNameSource :: AnonRegionFromOutput (
165171 RegionNameHighlight :: CannotMatchHirTy ( span, type_name) ,
166172 mir_description,
167173 ) => {
168- diag. span_label ( * span, format ! ( "return type{mir_description} is {type_name}" ) ) ;
174+ diag. subdiagnostic ( RegionNameLables :: ReturnTypeIsTpye {
175+ span : * span,
176+ mir_description,
177+ type_name : & type_name,
178+ } ) ;
169179 }
170180 RegionNameSource :: AnonRegionFromYieldTy ( span, type_name) => {
171- diag. span_label ( * span, format ! ( "yield type is {type_name}" ) ) ;
181+ diag. subdiagnostic ( RegionNameLables :: YieldTypeIsTpye {
182+ span : * span,
183+ type_name : & type_name,
184+ } ) ;
172185 }
173186 RegionNameSource :: AnonRegionFromImplSignature ( span, location) => {
174- diag. span_label (
175- * span,
176- format ! ( "lifetime `{self}` appears in the `impl`'s {location}" ) ,
177- ) ;
187+ diag. subdiagnostic ( RegionNameLables :: LifetimeInImpl {
188+ span : * span,
189+ rg_name : self ,
190+ location : & location,
191+ } ) ;
178192 }
179193 RegionNameSource :: Static => { }
180194 }
0 commit comments