@@ -19,6 +19,7 @@ pub struct OnUnimplementedDirective {
19
19
pub label : Option < OnUnimplementedFormatString > ,
20
20
pub note : Option < OnUnimplementedFormatString > ,
21
21
pub enclosing_scope : Option < OnUnimplementedFormatString > ,
22
+ pub append_const_msg : Option < Option < Symbol > > ,
22
23
}
23
24
24
25
#[ derive( Default ) ]
@@ -27,6 +28,11 @@ pub struct OnUnimplementedNote {
27
28
pub label : Option < String > ,
28
29
pub note : Option < String > ,
29
30
pub enclosing_scope : Option < String > ,
31
+ /// Append a message for `~const Trait` errors. `None` means not requested and
32
+ /// should fallback to a generic message, `Some(None)` suggests using the default
33
+ /// appended message, `Some(Some(s))` suggests use the `s` message instead of the
34
+ /// default one..
35
+ pub append_const_msg : Option < Option < Symbol > > ,
30
36
}
31
37
32
38
fn parse_error (
@@ -89,6 +95,7 @@ impl<'tcx> OnUnimplementedDirective {
89
95
let mut note = None ;
90
96
let mut enclosing_scope = None ;
91
97
let mut subcommands = vec ! [ ] ;
98
+ let mut append_const_msg = None ;
92
99
93
100
let parse_value = |value_str| {
94
101
OnUnimplementedFormatString :: try_parse ( tcx, trait_def_id, value_str, span) . map ( Some )
@@ -131,6 +138,14 @@ impl<'tcx> OnUnimplementedDirective {
131
138
}
132
139
continue ;
133
140
}
141
+ } else if item. has_name ( sym:: append_const_msg) && append_const_msg. is_none ( ) {
142
+ if let Some ( msg) = item. value_str ( ) {
143
+ append_const_msg = Some ( Some ( msg) ) ;
144
+ continue ;
145
+ } else if item. is_word ( ) {
146
+ append_const_msg = Some ( None ) ;
147
+ continue ;
148
+ }
134
149
}
135
150
136
151
// nothing found
@@ -153,6 +168,7 @@ impl<'tcx> OnUnimplementedDirective {
153
168
label,
154
169
note,
155
170
enclosing_scope,
171
+ append_const_msg,
156
172
} )
157
173
}
158
174
}
@@ -183,6 +199,7 @@ impl<'tcx> OnUnimplementedDirective {
183
199
) ?) ,
184
200
note : None ,
185
201
enclosing_scope : None ,
202
+ append_const_msg : None ,
186
203
} ) )
187
204
} else {
188
205
return Err ( ErrorReported ) ;
@@ -201,6 +218,7 @@ impl<'tcx> OnUnimplementedDirective {
201
218
let mut label = None ;
202
219
let mut note = None ;
203
220
let mut enclosing_scope = None ;
221
+ let mut append_const_msg = None ;
204
222
info ! ( "evaluate({:?}, trait_ref={:?}, options={:?})" , self , trait_ref, options) ;
205
223
206
224
for command in self . subcommands . iter ( ) . chain ( Some ( self ) ) . rev ( ) {
@@ -235,6 +253,8 @@ impl<'tcx> OnUnimplementedDirective {
235
253
if let Some ( ref enclosing_scope_) = command. enclosing_scope {
236
254
enclosing_scope = Some ( enclosing_scope_. clone ( ) ) ;
237
255
}
256
+
257
+ append_const_msg = command. append_const_msg . clone ( ) ;
238
258
}
239
259
240
260
let options: FxHashMap < Symbol , String > =
@@ -244,6 +264,7 @@ impl<'tcx> OnUnimplementedDirective {
244
264
message : message. map ( |m| m. format ( tcx, trait_ref, & options) ) ,
245
265
note : note. map ( |n| n. format ( tcx, trait_ref, & options) ) ,
246
266
enclosing_scope : enclosing_scope. map ( |e_s| e_s. format ( tcx, trait_ref, & options) ) ,
267
+ append_const_msg,
247
268
}
248
269
}
249
270
}
0 commit comments