fix: remove unused source span
This commit is contained in:
parent
5d04477ea8
commit
40a3ca1189
2 changed files with 15 additions and 43 deletions
|
|
@ -2779,46 +2779,12 @@ fn render_call_locations<W: fmt::Write>(
|
|||
let needs_expansion = line_max - line_min > NUM_VISIBLE_LINES;
|
||||
let locations_encoded = serde_json::to_string(&line_ranges).unwrap();
|
||||
|
||||
let source_map = tcx.sess.source_map();
|
||||
let files = source_map.files();
|
||||
let local = tcx.sess.local_crate_source_file().unwrap();
|
||||
|
||||
let get_file_start_pos = || {
|
||||
let crate_src = local.clone().into_local_path()?;
|
||||
let abs_crate_src = crate_src.canonicalize().ok()?;
|
||||
let crate_root = abs_crate_src.parent()?.parent()?;
|
||||
let rel_path = path.strip_prefix(crate_root).ok()?;
|
||||
files
|
||||
.iter()
|
||||
.find(|file| match &file.name {
|
||||
FileName::Real(real) => real.local_path().map_or(false, |p| p == rel_path),
|
||||
_ => false,
|
||||
})
|
||||
.map(|file| file.start_pos)
|
||||
};
|
||||
|
||||
// Look for the example file in the source map if it exists, otherwise
|
||||
// return a span to the local crate's source file
|
||||
let Some(file_span) = get_file_start_pos()
|
||||
.or_else(|| {
|
||||
files
|
||||
.iter()
|
||||
.find(|file| match &file.name {
|
||||
FileName::Real(file_name) => file_name == &local,
|
||||
_ => false,
|
||||
})
|
||||
.map(|file| file.start_pos)
|
||||
})
|
||||
.map(|start_pos| {
|
||||
rustc_span::Span::with_root_ctxt(
|
||||
start_pos + BytePos(byte_min),
|
||||
start_pos + BytePos(byte_max),
|
||||
)
|
||||
})
|
||||
else {
|
||||
// if the fallback span can't be built, don't render the code for this example
|
||||
return false;
|
||||
};
|
||||
// For scraped examples, we don't need a real span from the SourceMap.
|
||||
// The URL is already provided in ScrapedInfo, and sources::print_src
|
||||
// will use that directly. We use DUMMY_SP as a placeholder.
|
||||
// Note: DUMMY_SP is safe here because href_from_span won't be called
|
||||
// for scraped examples.
|
||||
let file_span = rustc_span::DUMMY_SP;
|
||||
|
||||
let mut decoration_info = FxIndexMap::default();
|
||||
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
|
||||
|
|
|
|||
|
|
@ -344,9 +344,15 @@ pub(crate) fn print_src(
|
|||
lines += line_info.start_line as usize;
|
||||
}
|
||||
let code = fmt::from_fn(move |fmt| {
|
||||
let current_href = context
|
||||
.href_from_span(clean::Span::new(file_span), false)
|
||||
.expect("only local crates should have sources emitted");
|
||||
// For scraped examples, use the URL from ScrapedInfo directly.
|
||||
// For regular sources, derive it from the span.
|
||||
let current_href = if let SourceContext::Embedded(info) = source_context {
|
||||
info.url.to_string()
|
||||
} else {
|
||||
context
|
||||
.href_from_span(clean::Span::new(file_span), false)
|
||||
.expect("only local crates should have sources emitted")
|
||||
};
|
||||
highlight::write_code(
|
||||
fmt,
|
||||
s,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue