diff options
| author | Michael Howell <michael@notriddle.com> | 2024-03-29 12:31:34 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2024-03-29 13:31:35 -0700 |
| commit | 98642da6a9dda39e711b7f3520b0b6d40c1cd043 (patch) | |
| tree | bc3834326dc016ab7bb22636218b753f03c8aaf1 /compiler/rustc_builtin_macros/src/source_util.rs | |
| parent | d74804636fa57e80d1e213fa9d2d65b27216b515 (diff) | |
| download | rust-98642da6a9dda39e711b7f3520b0b6d40c1cd043.tar.gz rust-98642da6a9dda39e711b7f3520b0b6d40c1cd043.zip | |
rustdoc: point at span in `include_str!`-ed md file
Diffstat (limited to 'compiler/rustc_builtin_macros/src/source_util.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/source_util.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs index abcdfabcaed..51975568981 100644 --- a/compiler/rustc_builtin_macros/src/source_util.rs +++ b/compiler/rustc_builtin_macros/src/source_util.rs @@ -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) => { |
