@@ -174,7 +174,7 @@ impl<'a> Translator<'a> {
174174 if let Some ( semantics) = self . semantics . as_ref ( ) {
175175 let file_range = semantics. original_range ( node. syntax ( ) ) ;
176176 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 {
178178 Some ( file_range. range )
179179 } else {
180180 None
@@ -298,20 +298,18 @@ impl<'a> Translator<'a> {
298298 if let Some ( value) = semantics
299299 . hir_file_for ( expanded)
300300 . 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) )
306302 {
307303 if let Some ( err) = & value. err {
308304 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+ {
311309 let location = err. span ( ) . range
312310 + semantics
313311 . db
314- . ast_id_map ( err . span ( ) . anchor . file_id . into ( ) )
312+ . ast_id_map ( hir_file_id )
315313 . get_erased ( err. span ( ) . anchor . ast_id )
316314 . text_range ( )
317315 . start ( ) ;
@@ -363,10 +361,10 @@ impl<'a> Translator<'a> {
363361 . as_ref ( )
364362 . and_then ( |s| s. expand_macro_call ( mcall) )
365363 {
366- self . emit_macro_expansion_parse_errors ( mcall, & expanded) ;
364+ self . emit_macro_expansion_parse_errors ( mcall, & expanded. value ) ;
367365 let expand_to = ra_ap_hir_expand:: ExpandTo :: from_call_site ( mcall) ;
368366 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 ) {
370368 generated:: MacroCall :: emit_macro_call_expansion (
371369 label,
372370 value,
@@ -669,11 +667,11 @@ impl<'a> Translator<'a> {
669667 ) {
670668 // work around a bug in rust-analyzer AST generation machinery
671669 // 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 ( ) {
674672 // <T> or <T as Trait>
675673 // T is any TypeRef, Trait has to be a PathType
676- let mut type_refs = item
674+ let mut type_refs = anchor
677675 . syntax ( )
678676 . children ( )
679677 . filter ( |node| ast:: Type :: can_cast ( node. kind ( ) ) ) ;
@@ -691,6 +689,13 @@ impl<'a> Translator<'a> {
691689 {
692690 generated:: PathSegment :: emit_trait_type_repr ( label, t, & mut self . trap . writer )
693691 }
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+ ) ;
694699 }
695700 }
696701
@@ -743,9 +748,9 @@ impl<'a> Translator<'a> {
743748 }
744749 let ExpandResult {
745750 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 ( || {
749754 let message = "attribute macro expansion cannot be cast to MacroItems" . to_owned ( ) ;
750755 let location = self . location_for_node ( node) ;
751756 self . emit_diagnostic (
0 commit comments