1
Fork 0

Auto merge of #103071 - wesleywiser:fix_inlined_line_numbers, r=davidtwco

Fix line numbers for MIR inlined code

`should_collapse_debuginfo` detects if the specified span is part of a
macro expansion however it does this by checking if the span is anything
other than a normal (non-expanded) kind, then the span sequence is
walked backwards to the root span.

This doesn't work when the MIR inliner inlines code as it creates spans
with expansion information set to `ExprKind::Inlined` and results in the
line number being attributed to the inline callsite rather than the
normal line number of the inlined code.

Fixes #103068
This commit is contained in:
bors 2022-10-28 16:27:56 +00:00
commit 77e7b74ad5
3 changed files with 35 additions and 2 deletions

View file

@ -558,7 +558,7 @@ impl Span {
self.data_untracked().is_dummy()
}
/// Returns `true` if this span comes from a macro or desugaring.
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
#[inline]
pub fn from_expansion(self) -> bool {
self.ctxt() != SyntaxContext::root()
@ -571,6 +571,12 @@ impl Span {
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
}
/// Returns `true` if this span comes from MIR inlining.
pub fn is_inlined(self) -> bool {
let outer_expn = self.ctxt().outer_expn_data();
matches!(outer_expn.kind, ExpnKind::Inlined)
}
/// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(self) -> bool {
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))