@@ -174,7 +174,7 @@ impl<'a> Translator<'a> {
174
174
if let Some ( semantics) = self . semantics . as_ref ( ) {
175
175
let file_range = semantics. original_range ( node. syntax ( ) ) ;
176
176
let file_id = self . file_id ?;
177
- if file_id. file_id ( semantics . db ) == file_range. file_id {
177
+ if file_id == file_range. file_id {
178
178
Some ( file_range. range )
179
179
} else {
180
180
None
@@ -298,20 +298,18 @@ impl<'a> Translator<'a> {
298
298
if let Some ( value) = semantics
299
299
. hir_file_for ( expanded)
300
300
. macro_file ( )
301
- . and_then ( |macro_file| {
302
- semantics
303
- . db
304
- . parse_macro_expansion_error ( macro_file. macro_call_id )
305
- } )
301
+ . and_then ( |macro_call_id| semantics. db . parse_macro_expansion_error ( macro_call_id) )
306
302
{
307
303
if let Some ( err) = & value. err {
308
304
let error = err. render_to_string ( semantics. db ) ;
309
-
310
- if err. span ( ) . anchor . file_id == semantics. hir_file_for ( node. syntax ( ) ) {
305
+ let hir_file_id = semantics. hir_file_for ( node. syntax ( ) ) ;
306
+ if Some ( err. span ( ) . anchor . file_id . file_id ( ) )
307
+ == hir_file_id. file_id ( ) . map ( |f| f. file_id ( semantics. db ) )
308
+ {
311
309
let location = err. span ( ) . range
312
310
+ semantics
313
311
. db
314
- . ast_id_map ( err . span ( ) . anchor . file_id . into ( ) )
312
+ . ast_id_map ( hir_file_id )
315
313
. get_erased ( err. span ( ) . anchor . ast_id )
316
314
. text_range ( )
317
315
. start ( ) ;
@@ -363,10 +361,10 @@ impl<'a> Translator<'a> {
363
361
. as_ref ( )
364
362
. and_then ( |s| s. expand_macro_call ( mcall) )
365
363
{
366
- self . emit_macro_expansion_parse_errors ( mcall, & expanded) ;
364
+ self . emit_macro_expansion_parse_errors ( mcall, & expanded. value ) ;
367
365
let expand_to = ra_ap_hir_expand:: ExpandTo :: from_call_site ( mcall) ;
368
366
let kind = expanded. kind ( ) ;
369
- if let Some ( value) = self . emit_expanded_as ( expand_to, expanded) {
367
+ if let Some ( value) = self . emit_expanded_as ( expand_to, expanded. value ) {
370
368
generated:: MacroCall :: emit_macro_call_expansion (
371
369
label,
372
370
value,
@@ -669,11 +667,11 @@ impl<'a> Translator<'a> {
669
667
) {
670
668
// work around a bug in rust-analyzer AST generation machinery
671
669
// this code was inspired by rust-analyzer's own workaround for this:
672
- // https://github.com/rust-lang/rust-analyzer/blob/1f86729f29ea50e8491a1516422df4fd3d1277b0 /crates/syntax/src/ast/node_ext.rs#L268-L277
673
- if item . l_angle_token ( ) . is_some ( ) {
670
+ // https://github.com/rust-lang/rust-analyzer/blob/a642aa8023be11d6bc027fc6a68c71c2f3fc7f72 /crates/syntax/src/ast/node_ext.rs#L290-L297
671
+ if let Some ( anchor ) = item . type_anchor ( ) {
674
672
// <T> or <T as Trait>
675
673
// T is any TypeRef, Trait has to be a PathType
676
- let mut type_refs = item
674
+ let mut type_refs = anchor
677
675
. syntax ( )
678
676
. children ( )
679
677
. filter ( |node| ast:: Type :: can_cast ( node. kind ( ) ) ) ;
@@ -691,6 +689,13 @@ impl<'a> Translator<'a> {
691
689
{
692
690
generated:: PathSegment :: emit_trait_type_repr ( label, t, & mut self . trap . writer )
693
691
}
692
+ // moreover as we're skipping emission of TypeAnchor, we need to attach its comments to
693
+ // this path segment
694
+ self . emit_tokens (
695
+ & anchor,
696
+ label. into ( ) ,
697
+ anchor. syntax ( ) . children_with_tokens ( ) ,
698
+ ) ;
694
699
}
695
700
}
696
701
@@ -743,9 +748,9 @@ impl<'a> Translator<'a> {
743
748
}
744
749
let ExpandResult {
745
750
value : expanded, ..
746
- } = semantics. expand_attr_macro ( node) ?;
747
- self . emit_macro_expansion_parse_errors ( node, & expanded) ;
748
- let macro_items = ast:: MacroItems :: cast ( expanded) . or_else ( || {
751
+ } = self . semantics . and_then ( |s| s . expand_attr_macro ( node) ) ?;
752
+ self . emit_macro_expansion_parse_errors ( node, & expanded. value ) ;
753
+ let macro_items = ast:: MacroItems :: cast ( expanded. value ) . or_else ( || {
749
754
let message = "attribute macro expansion cannot be cast to MacroItems" . to_owned ( ) ;
750
755
let location = self . location_for_node ( node) ;
751
756
self . emit_diagnostic (
0 commit comments