@@ -216,7 +216,7 @@ impl<'a> Translator<'a> {
216216 if let Some ( semantics) = self . semantics . as_ref ( ) {
217217 let file_range = semantics. original_range ( node. syntax ( ) ) ;
218218 let file_id = self . file_id ?;
219- if file_id. file_id ( semantics . db ) == file_range. file_id {
219+ if file_id == file_range. file_id {
220220 Some ( file_range. range )
221221 } else {
222222 None
@@ -370,20 +370,18 @@ impl<'a> Translator<'a> {
370370 if let Some ( value) = semantics
371371 . hir_file_for ( expanded)
372372 . macro_file ( )
373- . and_then ( |macro_file| {
374- semantics
375- . db
376- . parse_macro_expansion_error ( macro_file. macro_call_id )
377- } )
373+ . and_then ( |macro_call_id| semantics. db . parse_macro_expansion_error ( macro_call_id) )
378374 {
379375 if let Some ( err) = & value. err {
380376 let error = err. render_to_string ( semantics. db ) ;
381-
382- if err. span ( ) . anchor . file_id == semantics. hir_file_for ( node. syntax ( ) ) {
377+ let hir_file_id = semantics. hir_file_for ( node. syntax ( ) ) ;
378+ if Some ( err. span ( ) . anchor . file_id . file_id ( ) )
379+ == hir_file_id. file_id ( ) . map ( |f| f. file_id ( semantics. db ) )
380+ {
383381 let location = err. span ( ) . range
384382 + semantics
385383 . db
386- . ast_id_map ( err . span ( ) . anchor . file_id . into ( ) )
384+ . ast_id_map ( hir_file_id )
387385 . get_erased ( err. span ( ) . anchor . ast_id )
388386 . text_range ( )
389387 . start ( ) ;
@@ -435,10 +433,10 @@ impl<'a> Translator<'a> {
435433 . as_ref ( )
436434 . and_then ( |s| s. expand_macro_call ( mcall) )
437435 {
438- self . emit_macro_expansion_parse_errors ( mcall, & expanded) ;
436+ self . emit_macro_expansion_parse_errors ( mcall, & expanded. value ) ;
439437 let expand_to = ra_ap_hir_expand:: ExpandTo :: from_call_site ( mcall) ;
440438 let kind = expanded. kind ( ) ;
441- if let Some ( value) = self . emit_expanded_as ( expand_to, expanded) {
439+ if let Some ( value) = self . emit_expanded_as ( expand_to, expanded. value ) {
442440 generated:: MacroCall :: emit_macro_call_expansion (
443441 label,
444442 value,
@@ -741,11 +739,11 @@ impl<'a> Translator<'a> {
741739 ) {
742740 // work around a bug in rust-analyzer AST generation machinery
743741 // this code was inspired by rust-analyzer's own workaround for this:
744- // https://github.com/rust-lang/rust-analyzer/blob/1f86729f29ea50e8491a1516422df4fd3d1277b0 /crates/syntax/src/ast/node_ext.rs#L268-L277
745- if item . l_angle_token ( ) . is_some ( ) {
742+ // https://github.com/rust-lang/rust-analyzer/blob/a642aa8023be11d6bc027fc6a68c71c2f3fc7f72 /crates/syntax/src/ast/node_ext.rs#L290-L297
743+ if let Some ( anchor ) = item . type_anchor ( ) {
746744 // <T> or <T as Trait>
747745 // T is any TypeRef, Trait has to be a PathType
748- let mut type_refs = item
746+ let mut type_refs = anchor
749747 . syntax ( )
750748 . children ( )
751749 . filter ( |node| ast:: Type :: can_cast ( node. kind ( ) ) ) ;
@@ -763,6 +761,13 @@ impl<'a> Translator<'a> {
763761 {
764762 generated:: PathSegment :: emit_trait_type_repr ( label, t, & mut self . trap . writer )
765763 }
764+ // moreover as we're skipping emission of TypeAnchor, we need to attach its comments to
765+ // this path segment
766+ self . emit_tokens (
767+ & anchor,
768+ label. into ( ) ,
769+ anchor. syntax ( ) . children_with_tokens ( ) ,
770+ ) ;
766771 }
767772 }
768773
@@ -821,8 +826,8 @@ impl<'a> Translator<'a> {
821826 let ExpandResult {
822827 value : expanded, ..
823828 } = self . semantics . and_then ( |s| s. expand_attr_macro ( node) ) ?;
824- self . emit_macro_expansion_parse_errors ( node, & expanded) ;
825- let macro_items = ast:: MacroItems :: cast ( expanded) . or_else ( || {
829+ self . emit_macro_expansion_parse_errors ( node, & expanded. value ) ;
830+ let macro_items = ast:: MacroItems :: cast ( expanded. value ) . or_else ( || {
826831 let message = "attribute macro expansion cannot be cast to MacroItems" . to_owned ( ) ;
827832 let location = self . location_for_node ( node) ;
828833 self . emit_diagnostic (
0 commit comments