@@ -159,21 +159,24 @@ impl<'a> Translator<'a> {
159
159
Some ( node. syntax ( ) . text_range ( ) )
160
160
}
161
161
}
162
- pub fn emit_location < T : TrapClass > ( & mut self , label : Label < T > , node : & impl ast :: AstNode ) {
163
- if let Some ( ( start , end ) ) = self
164
- . text_range_for_node ( node)
162
+
163
+ fn location_for_node ( & mut self , node : & impl ast :: AstNode ) -> ( LineCol , LineCol ) {
164
+ self . text_range_for_node ( node)
165
165
. and_then ( |r| self . location ( r) )
166
- {
167
- self . trap . emit_location ( self . label , label, start, end)
168
- } else {
169
- self . emit_diagnostic (
166
+ . unwrap_or ( UNKNOWN_LOCATION )
167
+ }
168
+
169
+ pub fn emit_location < T : TrapClass > ( & mut self , label : Label < T > , node : & impl ast:: AstNode ) {
170
+ match self . location_for_node ( node) {
171
+ UNKNOWN_LOCATION => self . emit_diagnostic (
170
172
DiagnosticSeverity :: Debug ,
171
173
"locations" . to_owned ( ) ,
172
174
"missing location for AstNode" . to_owned ( ) ,
173
175
"missing location for AstNode" . to_owned ( ) ,
174
176
UNKNOWN_LOCATION ,
175
- ) ;
176
- }
177
+ ) ,
178
+ ( start, end) => self . trap . emit_location ( self . label , label, start, end) ,
179
+ } ;
177
180
}
178
181
pub fn emit_location_token (
179
182
& mut self ,
@@ -657,9 +660,19 @@ impl<'a> Translator<'a> {
657
660
let ExpandResult {
658
661
value : expanded, ..
659
662
} = semantics. expand_attr_macro ( node) ?;
660
- // TODO emit err?
661
663
self . emit_macro_expansion_parse_errors ( node, & expanded) ;
662
- let macro_items = ast:: MacroItems :: cast ( expanded) ?;
664
+ let macro_items = ast:: MacroItems :: cast ( expanded) . or_else ( || {
665
+ let message = "attribute macro expansion cannot be cast to MacroItems" . to_owned ( ) ;
666
+ let location = self . location_for_node ( node) ;
667
+ self . emit_diagnostic (
668
+ DiagnosticSeverity :: Warning ,
669
+ "item_expansion" . to_owned ( ) ,
670
+ message. clone ( ) ,
671
+ message,
672
+ location,
673
+ ) ;
674
+ None
675
+ } ) ?;
663
676
let expanded = self . emit_macro_items ( & macro_items) ?;
664
677
generated:: Item :: emit_attribute_macro_expansion ( label, expanded, & mut self . trap . writer ) ;
665
678
Some ( ( ) )
0 commit comments