mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
rustdoc: handle macro expansions in types
This commit is contained in:
@@ -33,6 +33,9 @@ pub fn where_bound_predicate_to_string(where_bound_predicate: &ast::WhereBoundPr
|
||||
State::new().where_bound_predicate_to_string(where_bound_predicate)
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `pat.kind` is `PatKind::Missing`.
|
||||
pub fn pat_to_string(pat: &ast::Pat) -> String {
|
||||
State::new().pat_to_string(pat)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use rustc_ast::visit::{Visitor, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt};
|
||||
use rustc_ast::{Crate, Expr, Item, Pat, Stmt};
|
||||
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_data_structures::fx::FxHashMap;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::{BytePos, Span};
|
||||
@@ -153,4 +153,12 @@ fn visit_pat(&mut self, pat: &'ast Pat) {
|
||||
walk_pat(self, pat);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'ast Ty) {
|
||||
if ty.span.from_expansion() {
|
||||
self.handle_new_span(ty.span, || rustc_ast_pretty::pprust::ty_to_string(ty));
|
||||
} else {
|
||||
walk_ty(self, ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Ensure macro invocations at type position are expanded correctly
|
||||
|
||||
//@ compile-flags: -Zunstable-options --generate-macro-expansion
|
||||
|
||||
#![crate_name = "foo"]
|
||||
|
||||
//@ has 'src/foo/type-macro-expansion.rs.html'
|
||||
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
fn(())
|
||||
};
|
||||
($_arg:expr) => {
|
||||
[(); 1]
|
||||
};
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
//@ has - '//*[@class="expansion"]/*[@class="original"]/*[@class="macro"]' 'foo!'
|
||||
//@ has - '//*[@class="expansion"]/*[@class="original"]' 'foo!()'
|
||||
//@ has - '//*[@class="expansion"]/*[@class="expanded"]' 'fn(())'
|
||||
let _: foo!();
|
||||
//@ has - '//*[@class="expansion"]/*[@class="original"]/*[@class="macro"]' 'foo!'
|
||||
//@ has - '//*[@class="expansion"]/*[@class="original"]' 'foo!(42)'
|
||||
//@ has - '//*[@class="expansion"]/*[@class="expanded"]' '[(); 1]'
|
||||
let _: foo!(42);
|
||||
}
|
||||
Reference in New Issue
Block a user