Avoid unnecessary rustc_span::DUMMY_SP usage.

In some cases `DUMMY_SP` is already imported. In other cases this commit
adds the necessary import, in files where `DUMMY_SP` is used more than
once.
This commit is contained in:
Nicholas Nethercote 2024-03-06 16:39:02 +11:00
parent 63f70b3d10
commit 27374a0214
13 changed files with 35 additions and 53 deletions

View file

@ -408,7 +408,7 @@ impl Item {
pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span {
span_of_fragments(&self.attrs.doc_strings)
.unwrap_or_else(|| self.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner()))
.unwrap_or_else(|| self.span(tcx).map_or(DUMMY_SP, |span| span.inner()))
}
/// Combine all doc strings into a single value handling indentation and newlines as needed.

View file

@ -56,7 +56,7 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_session::RustcVersion;
use rustc_span::{
symbol::{sym, Symbol},
BytePos, FileName, RealFileName,
BytePos, FileName, RealFileName, DUMMY_SP,
};
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
@ -2414,7 +2414,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
let contents = match fs::read_to_string(&path) {
Ok(contents) => contents,
Err(err) => {
let span = item.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner());
let span = item.span(tcx).map_or(DUMMY_SP, |span| span.inner());
tcx.dcx().span_err(span, format!("failed to read file {}: {err}", path.display()));
return false;
}
@ -2495,7 +2495,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
file.start_pos + BytePos(byte_max),
))
})()
.unwrap_or(rustc_span::DUMMY_SP);
.unwrap_or(DUMMY_SP);
let mut decoration_info = FxHashMap::default();
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);