@@ -22,18 +22,15 @@ pub struct OnUnimplementedDirective {
22
22
pub message : Option < OnUnimplementedFormatString > ,
23
23
pub label : Option < OnUnimplementedFormatString > ,
24
24
pub note : Option < OnUnimplementedFormatString > ,
25
+ pub enclosing_scope : Option < OnUnimplementedFormatString > ,
25
26
}
26
27
28
+ #[ derive( Default ) ]
27
29
pub struct OnUnimplementedNote {
28
30
pub message : Option < String > ,
29
31
pub label : Option < String > ,
30
32
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 > ,
37
34
}
38
35
39
36
fn parse_error (
@@ -85,24 +82,33 @@ impl<'tcx> OnUnimplementedDirective {
85
82
let mut message = None ;
86
83
let mut label = None ;
87
84
let mut note = None ;
85
+ let mut enclosing_scope = None ;
88
86
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
+
89
93
for item in item_iter {
90
94
if item. check_name ( sym:: message) && message. is_none ( ) {
91
95
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_) ?;
94
97
continue ;
95
98
}
96
99
} else if item. check_name ( sym:: label) && label. is_none ( ) {
97
100
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_) ?;
100
102
continue ;
101
103
}
102
104
} else if item. check_name ( sym:: note) && note. is_none ( ) {
103
105
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_) ?;
106
112
continue ;
107
113
}
108
114
} else if item. check_name ( sym:: on) && is_root &&
@@ -130,7 +136,14 @@ impl<'tcx> OnUnimplementedDirective {
130
136
if errored {
131
137
Err ( ErrorReported )
132
138
} 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
+ } )
134
147
}
135
148
}
136
149
@@ -157,6 +170,7 @@ impl<'tcx> OnUnimplementedDirective {
157
170
label : Some ( OnUnimplementedFormatString :: try_parse (
158
171
tcx, trait_def_id, value, attr. span ) ?) ,
159
172
note : None ,
173
+ enclosing_scope : None ,
160
174
} ) )
161
175
} else {
162
176
return Err ( ErrorReported ) ;
@@ -174,6 +188,7 @@ impl<'tcx> OnUnimplementedDirective {
174
188
let mut message = None ;
175
189
let mut label = None ;
176
190
let mut note = None ;
191
+ let mut enclosing_scope = None ;
177
192
info ! ( "evaluate({:?}, trait_ref={:?}, options={:?})" , self , trait_ref, options) ;
178
193
179
194
for command in self . subcommands . iter ( ) . chain ( Some ( self ) ) . rev ( ) {
@@ -202,6 +217,10 @@ impl<'tcx> OnUnimplementedDirective {
202
217
if let Some ( ref note_) = command. note {
203
218
note = Some ( note_. clone ( ) ) ;
204
219
}
220
+
221
+ if let Some ( ref enclosing_scope_) = command. enclosing_scope {
222
+ enclosing_scope = Some ( enclosing_scope_. clone ( ) ) ;
223
+ }
205
224
}
206
225
207
226
let options: FxHashMap < Symbol , String > = options. into_iter ( )
@@ -211,6 +230,7 @@ impl<'tcx> OnUnimplementedDirective {
211
230
label : label. map ( |l| l. format ( tcx, trait_ref, & options) ) ,
212
231
message : message. map ( |m| m. format ( tcx, trait_ref, & options) ) ,
213
232
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) ) ,
214
234
}
215
235
}
216
236
}
0 commit comments