1
+ // #![deny(rustc::untranslatable_diagnostic)]
2
+ // #![deny(rustc::diagnostic_outside_of_impl)]
3
+
1
4
use std:: fmt:: { self , Display } ;
2
5
use std:: iter;
3
6
@@ -10,6 +13,7 @@ use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty};
10
13
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
11
14
use rustc_span:: { Span , DUMMY_SP } ;
12
15
16
+ use crate :: session_diagnostics:: RegionNameLables ;
13
17
use crate :: { nll:: ToRegionVid , universal_regions:: DefiningTy , MirBorrowckCtxt } ;
14
18
15
19
/// A name for a particular region used in emitting diagnostics. This name could be a generated
@@ -133,48 +137,58 @@ impl RegionName {
133
137
RegionNameHighlight :: MatchedAdtAndSegment ( span) ,
134
138
_,
135
139
) => {
136
- diag. span_label ( * span, format ! ( "let's call this `{ self}`" ) ) ;
140
+ diag. subdiagnostic ( RegionNameLables :: NameRegion { span : * span, rg_name : self } ) ;
137
141
}
138
142
RegionNameSource :: AnonRegionFromArgument ( RegionNameHighlight :: Occluded (
139
143
span,
140
144
type_name,
141
145
) ) => {
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
+ } ) ;
146
151
}
147
152
RegionNameSource :: AnonRegionFromOutput (
148
153
RegionNameHighlight :: Occluded ( span, type_name) ,
149
154
mir_description,
150
155
) => {
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
+ } ) ;
157
162
}
158
163
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
+ } ) ;
163
169
}
164
170
RegionNameSource :: AnonRegionFromOutput (
165
171
RegionNameHighlight :: CannotMatchHirTy ( span, type_name) ,
166
172
mir_description,
167
173
) => {
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
+ } ) ;
169
179
}
170
180
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
+ } ) ;
172
185
}
173
186
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
+ } ) ;
178
192
}
179
193
RegionNameSource :: Static => { }
180
194
}
0 commit comments