rustdoc: point at span in include_str!
-ed md file
This commit is contained in:
parent
d74804636f
commit
98642da6a9
10 changed files with 121 additions and 42 deletions
|
@ -196,10 +196,10 @@ pub fn expand_include_str(
|
|||
Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
|
||||
};
|
||||
ExpandResult::Ready(match load_binary_file(cx, path.as_str().as_ref(), sp, path_span) {
|
||||
Ok(bytes) => match std::str::from_utf8(&bytes) {
|
||||
Ok((bytes, bsp)) => match std::str::from_utf8(&bytes) {
|
||||
Ok(src) => {
|
||||
let interned_src = Symbol::intern(src);
|
||||
MacEager::expr(cx.expr_str(sp, interned_src))
|
||||
MacEager::expr(cx.expr_str(cx.with_def_site_ctxt(bsp), interned_src))
|
||||
}
|
||||
Err(_) => {
|
||||
let guar = cx.dcx().span_err(sp, format!("`{path}` wasn't a utf-8 file"));
|
||||
|
@ -225,7 +225,9 @@ pub fn expand_include_bytes(
|
|||
Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
|
||||
};
|
||||
ExpandResult::Ready(match load_binary_file(cx, path.as_str().as_ref(), sp, path_span) {
|
||||
Ok(bytes) => {
|
||||
Ok((bytes, _bsp)) => {
|
||||
// Don't care about getting the span for the raw bytes,
|
||||
// because the console can't really show them anyway.
|
||||
let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes));
|
||||
MacEager::expr(expr)
|
||||
}
|
||||
|
@ -238,7 +240,7 @@ fn load_binary_file(
|
|||
original_path: &Path,
|
||||
macro_span: Span,
|
||||
path_span: Span,
|
||||
) -> Result<Lrc<[u8]>, Box<dyn MacResult>> {
|
||||
) -> Result<(Lrc<[u8]>, Span), Box<dyn MacResult>> {
|
||||
let resolved_path = match resolve_path(&cx.sess, original_path, macro_span) {
|
||||
Ok(path) => path,
|
||||
Err(err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue