mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-25 08:14:12 +00:00
spirt_passes/diagnostics: also recover zombie Span
s from their own attrs.
This commit is contained in:
parent
0557036fb1
commit
7d99248b29
@ -199,9 +199,8 @@ enum IntraFuncUseOrigin {
|
|||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UseOrigin<'_> {
|
impl SpanRegenerator<'_> {
|
||||||
fn to_rustc_span(&self, cx: &Context, span_regen: &mut SpanRegenerator<'_>) -> Option<Span> {
|
fn spirt_attrs_to_rustc_span(&mut self, cx: &Context, attrs: AttrSet) -> Option<Span> {
|
||||||
let from_attrs = |attrs: AttrSet, span_regen: &mut SpanRegenerator<'_>| {
|
|
||||||
let attrs_def = &cx[attrs];
|
let attrs_def = &cx[attrs];
|
||||||
attrs_def
|
attrs_def
|
||||||
.attrs
|
.attrs
|
||||||
@ -211,7 +210,7 @@ impl UseOrigin<'_> {
|
|||||||
file_path,
|
file_path,
|
||||||
line,
|
line,
|
||||||
col,
|
col,
|
||||||
} => span_regen.src_loc_to_rustc(SrcLocDecoration {
|
} => self.src_loc_to_rustc(SrcLocDecoration {
|
||||||
file_name: &cx[file_path.0],
|
file_name: &cx[file_path.0],
|
||||||
line_start: line,
|
line_start: line,
|
||||||
line_end: line,
|
line_end: line,
|
||||||
@ -221,19 +220,24 @@ impl UseOrigin<'_> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
span_regen.src_loc_to_rustc(
|
self.src_loc_to_rustc(
|
||||||
try_decode_custom_decoration::<SrcLocDecoration<'_>>(attrs_def)?.decode(),
|
try_decode_custom_decoration::<SrcLocDecoration<'_>>(attrs_def)?.decode(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UseOrigin<'_> {
|
||||||
|
fn to_rustc_span(&self, cx: &Context, span_regen: &mut SpanRegenerator<'_>) -> Option<Span> {
|
||||||
match *self {
|
match *self {
|
||||||
Self::Global { attrs, .. } => from_attrs(attrs, span_regen),
|
Self::Global { attrs, .. } => span_regen.spirt_attrs_to_rustc_span(cx, attrs),
|
||||||
Self::IntraFunc {
|
Self::IntraFunc {
|
||||||
func_attrs,
|
func_attrs,
|
||||||
last_debug_src_loc_inst,
|
last_debug_src_loc_inst,
|
||||||
inst_attrs,
|
inst_attrs,
|
||||||
..
|
..
|
||||||
} => from_attrs(inst_attrs, span_regen)
|
} => span_regen
|
||||||
|
.spirt_attrs_to_rustc_span(cx, inst_attrs)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
let debug_inst_def = last_debug_src_loc_inst?;
|
let debug_inst_def = last_debug_src_loc_inst?;
|
||||||
|
|
||||||
@ -291,7 +295,7 @@ impl UseOrigin<'_> {
|
|||||||
col_end: const_u32(col_end),
|
col_end: const_u32(col_end),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.or_else(|| from_attrs(func_attrs, span_regen)),
|
.or_else(|| span_regen.spirt_attrs_to_rustc_span(cx, func_attrs)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,6 +396,13 @@ impl DiagnosticReporter<'_> {
|
|||||||
let ZombieDecoration { reason } = zombie.decode();
|
let ZombieDecoration { reason } = zombie.decode();
|
||||||
let def_span = current_def
|
let def_span = current_def
|
||||||
.and_then(|def| def.to_rustc_span(self.cx, &mut self.span_regen))
|
.and_then(|def| def.to_rustc_span(self.cx, &mut self.span_regen))
|
||||||
|
.or_else(|| {
|
||||||
|
// If there's no clear source for the span, try to get
|
||||||
|
// it from the same attrs as the zombie, which could
|
||||||
|
// be missing from `use_stack` in some edge cases
|
||||||
|
// (such as zombied function parameters).
|
||||||
|
self.span_regen.spirt_attrs_to_rustc_span(self.cx, attrs)
|
||||||
|
})
|
||||||
.unwrap_or(DUMMY_SP);
|
.unwrap_or(DUMMY_SP);
|
||||||
let mut err = self.sess.struct_span_err(def_span, reason);
|
let mut err = self.sess.struct_span_err(def_span, reason);
|
||||||
for use_origin in use_stack_for_def.iter().rev() {
|
for use_origin in use_stack_for_def.iter().rev() {
|
||||||
|
Loading…
Reference in New Issue
Block a user