@@ -22,18 +22,15 @@ pub struct OnUnimplementedDirective {
2222 pub message : Option < OnUnimplementedFormatString > ,
2323 pub label : Option < OnUnimplementedFormatString > ,
2424 pub note : Option < OnUnimplementedFormatString > ,
25+ pub enclosing_scope : Option < OnUnimplementedFormatString > ,
2526}
2627
28+ #[ derive( Default ) ]
2729pub struct OnUnimplementedNote {
2830 pub message : Option < String > ,
2931 pub label : Option < String > ,
3032 pub note : Option < String > ,
31- }
32-
33- impl OnUnimplementedNote {
34- pub fn empty ( ) -> Self {
35- OnUnimplementedNote { message : None , label : None , note : None }
36- }
33+ pub enclosing_scope : Option < String > ,
3734}
3835
3936fn parse_error (
@@ -85,24 +82,33 @@ impl<'tcx> OnUnimplementedDirective {
8582 let mut message = None ;
8683 let mut label = None ;
8784 let mut note = None ;
85+ let mut enclosing_scope = None ;
8886 let mut subcommands = vec ! [ ] ;
87+
88+ let parse_value = |value_str| {
89+ OnUnimplementedFormatString :: try_parse ( tcx, trait_def_id, value_str, span)
90+ . map ( Some )
91+ } ;
92+
8993 for item in item_iter {
9094 if item. check_name ( sym:: message) && message. is_none ( ) {
9195 if let Some ( message_) = item. value_str ( ) {
92- message = Some ( OnUnimplementedFormatString :: try_parse (
93- tcx, trait_def_id, message_, span) ?) ;
96+ message = parse_value ( message_) ?;
9497 continue ;
9598 }
9699 } else if item. check_name ( sym:: label) && label. is_none ( ) {
97100 if let Some ( label_) = item. value_str ( ) {
98- label = Some ( OnUnimplementedFormatString :: try_parse (
99- tcx, trait_def_id, label_, span) ?) ;
101+ label = parse_value ( label_) ?;
100102 continue ;
101103 }
102104 } else if item. check_name ( sym:: note) && note. is_none ( ) {
103105 if let Some ( note_) = item. value_str ( ) {
104- note = Some ( OnUnimplementedFormatString :: try_parse (
105- tcx, trait_def_id, note_, span) ?) ;
106+ note = parse_value ( note_) ?;
107+ continue ;
108+ }
109+ } else if item. check_name ( sym:: enclosing_scope) && enclosing_scope. is_none ( ) {
110+ if let Some ( enclosing_scope_) = item. value_str ( ) {
111+ enclosing_scope = parse_value ( enclosing_scope_) ?;
106112 continue ;
107113 }
108114 } else if item. check_name ( sym:: on) && is_root &&
@@ -130,7 +136,14 @@ impl<'tcx> OnUnimplementedDirective {
130136 if errored {
131137 Err ( ErrorReported )
132138 } else {
133- Ok ( OnUnimplementedDirective { condition, message, label, subcommands, note } )
139+ Ok ( OnUnimplementedDirective {
140+ condition,
141+ subcommands,
142+ message,
143+ label,
144+ note,
145+ enclosing_scope
146+ } )
134147 }
135148 }
136149
@@ -157,6 +170,7 @@ impl<'tcx> OnUnimplementedDirective {
157170 label : Some ( OnUnimplementedFormatString :: try_parse (
158171 tcx, trait_def_id, value, attr. span ) ?) ,
159172 note : None ,
173+ enclosing_scope : None ,
160174 } ) )
161175 } else {
162176 return Err ( ErrorReported ) ;
@@ -174,6 +188,7 @@ impl<'tcx> OnUnimplementedDirective {
174188 let mut message = None ;
175189 let mut label = None ;
176190 let mut note = None ;
191+ let mut enclosing_scope = None ;
177192 info ! ( "evaluate({:?}, trait_ref={:?}, options={:?})" , self , trait_ref, options) ;
178193
179194 for command in self . subcommands . iter ( ) . chain ( Some ( self ) ) . rev ( ) {
@@ -202,6 +217,10 @@ impl<'tcx> OnUnimplementedDirective {
202217 if let Some ( ref note_) = command. note {
203218 note = Some ( note_. clone ( ) ) ;
204219 }
220+
221+ if let Some ( ref enclosing_scope_) = command. enclosing_scope {
222+ enclosing_scope = Some ( enclosing_scope_. clone ( ) ) ;
223+ }
205224 }
206225
207226 let options: FxHashMap < Symbol , String > = options. into_iter ( )
@@ -211,6 +230,7 @@ impl<'tcx> OnUnimplementedDirective {
211230 label : label. map ( |l| l. format ( tcx, trait_ref, & options) ) ,
212231 message : message. map ( |m| m. format ( tcx, trait_ref, & options) ) ,
213232 note : note. map ( |n| n. format ( tcx, trait_ref, & options) ) ,
233+ enclosing_scope : enclosing_scope. map ( |e_s| e_s. format ( tcx, trait_ref, & options) ) ,
214234 }
215235 }
216236}
0 commit comments