@@ -19,6 +19,7 @@ pub struct OnUnimplementedDirective {
1919 pub label : Option < OnUnimplementedFormatString > ,
2020 pub note : Option < OnUnimplementedFormatString > ,
2121 pub enclosing_scope : Option < OnUnimplementedFormatString > ,
22+ pub append_const_msg : Option < Option < Symbol > > ,
2223}
2324
2425#[ derive( Default ) ]
@@ -27,6 +28,11 @@ pub struct OnUnimplementedNote {
2728 pub label : Option < String > ,
2829 pub note : Option < String > ,
2930 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 > > ,
3036}
3137
3238fn parse_error (
@@ -89,6 +95,7 @@ impl<'tcx> OnUnimplementedDirective {
8995 let mut note = None ;
9096 let mut enclosing_scope = None ;
9197 let mut subcommands = vec ! [ ] ;
98+ let mut append_const_msg = None ;
9299
93100 let parse_value = |value_str| {
94101 OnUnimplementedFormatString :: try_parse ( tcx, trait_def_id, value_str, span) . map ( Some )
@@ -131,6 +138,14 @@ impl<'tcx> OnUnimplementedDirective {
131138 }
132139 continue ;
133140 }
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+ }
134149 }
135150
136151 // nothing found
@@ -153,6 +168,7 @@ impl<'tcx> OnUnimplementedDirective {
153168 label,
154169 note,
155170 enclosing_scope,
171+ append_const_msg,
156172 } )
157173 }
158174 }
@@ -183,6 +199,7 @@ impl<'tcx> OnUnimplementedDirective {
183199 ) ?) ,
184200 note : None ,
185201 enclosing_scope : None ,
202+ append_const_msg : None ,
186203 } ) )
187204 } else {
188205 return Err ( ErrorReported ) ;
@@ -201,6 +218,7 @@ impl<'tcx> OnUnimplementedDirective {
201218 let mut label = None ;
202219 let mut note = None ;
203220 let mut enclosing_scope = None ;
221+ let mut append_const_msg = None ;
204222 info ! ( "evaluate({:?}, trait_ref={:?}, options={:?})" , self , trait_ref, options) ;
205223
206224 for command in self . subcommands . iter ( ) . chain ( Some ( self ) ) . rev ( ) {
@@ -235,6 +253,8 @@ impl<'tcx> OnUnimplementedDirective {
235253 if let Some ( ref enclosing_scope_) = command. enclosing_scope {
236254 enclosing_scope = Some ( enclosing_scope_. clone ( ) ) ;
237255 }
256+
257+ append_const_msg = command. append_const_msg . clone ( ) ;
238258 }
239259
240260 let options: FxHashMap < Symbol , String > =
@@ -244,6 +264,7 @@ impl<'tcx> OnUnimplementedDirective {
244264 message : message. map ( |m| m. format ( tcx, trait_ref, & options) ) ,
245265 note : note. map ( |n| n. format ( tcx, trait_ref, & options) ) ,
246266 enclosing_scope : enclosing_scope. map ( |e_s| e_s. format ( tcx, trait_ref, & options) ) ,
267+ append_const_msg,
247268 }
248269 }
249270}
0 commit comments