Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/librustdoc/html/macro_expansion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use rustc_ast::visit::{Visitor, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt, walk_ty};
use rustc_ast::{Crate, Expr, Item, Pat, Stmt, Ty};
use rustc_ast::visit::{
AssocCtxt, Visitor, walk_assoc_item, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt,
walk_ty,
};
use rustc_ast::{AssocItem, Crate, Expr, Item, Pat, Stmt, Ty};
use rustc_data_structures::fx::FxHashMap;
use rustc_span::source_map::SourceMap;
use rustc_span::{BytePos, Span};
Expand Down Expand Up @@ -161,4 +164,14 @@ impl<'ast> Visitor<'ast> for ExpandedCodeVisitor<'ast> {
walk_ty(self, ty);
}
}

fn visit_assoc_item(&mut self, item: &'ast AssocItem, ctxt: AssocCtxt) -> Self::Result {
if item.span.from_expansion() {
self.handle_new_span(item.span, || {
rustc_ast_pretty::pprust::assoc_item_to_string(item)
});
} else {
walk_assoc_item(self, item, ctxt);
}
}
}
24 changes: 24 additions & 0 deletions tests/rustdoc-html/macro-expansion/assoc-items-decl-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Ensure assoc items work for decl macros.
// Regression test for <https://github.com/rust-lang/rust/issues/156075>.

//@ compile-flags: -Zunstable-options --generate-macro-expansion

#![crate_name = "foo"]
#![feature(decl_macro)]

//@ has 'src/foo/assoc-items-decl-macro.rs.html'

pub macro first() {
type P1 = bool;
fn u1() {}
}

trait C1 {
type P1;
fn u1();
}

impl C1 for u32 {
//@ matches - '//*[@class="expansion"]/*[@class="expanded"]' 'type P1 = bool;\nfn u1\(\) {}'
first!();
}
25 changes: 25 additions & 0 deletions tests/rustdoc-html/macro-expansion/assoc-items-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Ensure assoc items work for macro rules.
// Regression test for <https://github.com/rust-lang/rust/issues/156075>.

//@ compile-flags: -Zunstable-options --generate-macro-expansion

#![crate_name = "foo"]

//@ has 'src/foo/assoc-items-macro.rs.html'

macro_rules! first {
() => {
type P1 = bool;
fn u1() {}
}
}

trait C1 {
type P1;
fn u1();
}

impl C1 for u32 {
//@ matches - '//*[@class="expansion"]/*[@class="expanded"]' 'type P1 = bool;\nfn u1\(\) {}'
first!();
}
Loading