Skip to content

Commit e364ccb

Browse files
authored
Unrolled build for #156587
Rollup merge of #156587 - GuillaumeGomez:assoc-items-macro-expansion, r=Urgau Correctly handle associated items in rustdoc macro expansion Fixes #156075. The bug was simply that it didn't cover associated items. r? @Urgau
2 parents d7f14d3 + 899be9f commit e364ccb

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

src/librustdoc/html/macro_expansion.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use rustc_ast::visit::{Visitor, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt, walk_ty};
2-
use rustc_ast::{Crate, Expr, Item, Pat, Stmt, Ty};
1+
use rustc_ast::visit::{
2+
AssocCtxt, Visitor, walk_assoc_item, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt,
3+
walk_ty,
4+
};
5+
use rustc_ast::{AssocItem, Crate, Expr, Item, Pat, Stmt, Ty};
36
use rustc_data_structures::fx::FxHashMap;
47
use rustc_span::source_map::SourceMap;
58
use rustc_span::{BytePos, Span};
@@ -161,4 +164,14 @@ impl<'ast> Visitor<'ast> for ExpandedCodeVisitor<'ast> {
161164
walk_ty(self, ty);
162165
}
163166
}
167+
168+
fn visit_assoc_item(&mut self, item: &'ast AssocItem, ctxt: AssocCtxt) -> Self::Result {
169+
if item.span.from_expansion() {
170+
self.handle_new_span(item.span, || {
171+
rustc_ast_pretty::pprust::assoc_item_to_string(item)
172+
});
173+
} else {
174+
walk_assoc_item(self, item, ctxt);
175+
}
176+
}
164177
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Ensure assoc items work for decl macros.
2+
// Regression test for <https://github.com/rust-lang/rust/issues/156075>.
3+
4+
//@ compile-flags: -Zunstable-options --generate-macro-expansion
5+
6+
#![crate_name = "foo"]
7+
#![feature(decl_macro)]
8+
9+
//@ has 'src/foo/assoc-items-decl-macro.rs.html'
10+
11+
pub macro first() {
12+
type P1 = bool;
13+
fn u1() {}
14+
}
15+
16+
trait C1 {
17+
type P1;
18+
fn u1();
19+
}
20+
21+
impl C1 for u32 {
22+
//@ matches - '//*[@class="expansion"]/*[@class="expanded"]' 'type P1 = bool;\nfn u1\(\) {}'
23+
first!();
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Ensure assoc items work for macro rules.
2+
// Regression test for <https://github.com/rust-lang/rust/issues/156075>.
3+
4+
//@ compile-flags: -Zunstable-options --generate-macro-expansion
5+
6+
#![crate_name = "foo"]
7+
8+
//@ has 'src/foo/assoc-items-macro.rs.html'
9+
10+
macro_rules! first {
11+
() => {
12+
type P1 = bool;
13+
fn u1() {}
14+
}
15+
}
16+
17+
trait C1 {
18+
type P1;
19+
fn u1();
20+
}
21+
22+
impl C1 for u32 {
23+
//@ matches - '//*[@class="expansion"]/*[@class="expanded"]' 'type P1 = bool;\nfn u1\(\) {}'
24+
first!();
25+
}

0 commit comments

Comments
 (0)