diff options
| author | bors <bors@rust-lang.org> | 2024-01-09 00:04:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-09 00:04:47 +0000 |
| commit | d6affcf520091fd0f48df1a2b6bfcb9ef48e0f40 (patch) | |
| tree | bc0d6b63f03d0e2a2dc0bfc3f4618548ba4a11b8 /compiler/rustc_span/src | |
| parent | ca663b06c5492ac2dde5e53cd11579fa8e4d68bd (diff) | |
| parent | 1c9e862a3eae36ee390b915efb737f999cb4b425 (diff) | |
| download | rust-d6affcf520091fd0f48df1a2b6bfcb9ef48e0f40.tar.gz rust-d6affcf520091fd0f48df1a2b6bfcb9ef48e0f40.zip | |
Auto merge of #119754 - matthiaskrgr:rollup-7cht4m5, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #118903 (Improved support of collapse_debuginfo attribute for macros.) - #119033 (coverage: `llvm-cov` expects column numbers to be bytes, not code points) - #119598 (Fix a typo in core::ops::Deref's doc) - #119660 (remove an unnecessary stderr-per-bitwidth) - #119663 (tests: Normalize `\r\n` to `\n` in some run-make tests) - #119681 (coverage: Anonymize line numbers in branch views) - #119704 (Fix two variable binding issues in lint let_underscore) - #119725 (Add helper for when we want to know if an item has a host param) - #119738 (Add `riscv32imafc-esp-espidf` tier 3 target for the ESP32-P4.) - #119740 (Remove crossbeam-channel) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/hygiene.rs | 34 | ||||
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 7 |
2 files changed, 33 insertions, 8 deletions
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 6a15961ee20..d03965b539c 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -445,18 +445,46 @@ impl HygieneData { } fn walk_chain(&self, mut span: Span, to: SyntaxContext) -> Span { + let orig_span = span; debug!("walk_chain({:?}, {:?})", span, to); debug!("walk_chain: span ctxt = {:?}", span.ctxt()); - while span.from_expansion() && span.ctxt() != to { + while span.ctxt() != to && span.from_expansion() { let outer_expn = self.outer_expn(span.ctxt()); debug!("walk_chain({:?}): outer_expn={:?}", span, outer_expn); let expn_data = self.expn_data(outer_expn); debug!("walk_chain({:?}): expn_data={:?}", span, expn_data); span = expn_data.call_site; } + debug!("walk_chain: for span {:?} >>> return span = {:?}", orig_span, span); span } + // We need to walk up and update return span if we meet macro instantiation to be collapsed + fn walk_chain_collapsed( + &self, + mut span: Span, + to: Span, + collapse_debuginfo_enabled: bool, + ) -> Span { + let orig_span = span; + let mut ret_span = span; + + debug!("walk_chain_collapsed({:?}, {:?})", span, to); + debug!("walk_chain_collapsed: span ctxt = {:?}", span.ctxt()); + while !span.eq_ctxt(to) && span.from_expansion() { + let outer_expn = self.outer_expn(span.ctxt()); + debug!("walk_chain_collapsed({:?}): outer_expn={:?}", span, outer_expn); + let expn_data = self.expn_data(outer_expn); + debug!("walk_chain_collapsed({:?}): expn_data={:?}", span, expn_data); + span = expn_data.call_site; + if !collapse_debuginfo_enabled || expn_data.collapse_debuginfo { + ret_span = span; + } + } + debug!("walk_chain_collapsed: for span {:?} >>> return span = {:?}", orig_span, ret_span); + ret_span + } + fn adjust(&self, ctxt: &mut SyntaxContext, expn_id: ExpnId) -> Option<ExpnId> { let mut scope = None; while !self.is_descendant_of(expn_id, self.outer_expn(*ctxt)) { @@ -573,6 +601,10 @@ pub fn walk_chain(span: Span, to: SyntaxContext) -> Span { HygieneData::with(|data| data.walk_chain(span, to)) } +pub fn walk_chain_collapsed(span: Span, to: Span, collapse_debuginfo_enabled: bool) -> Span { + HygieneData::with(|hdata| hdata.walk_chain_collapsed(span, to, collapse_debuginfo_enabled)) +} + pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) { // The new contexts that need updating are at the end of the list and have `$crate` as a name. let (len, to_update) = HygieneData::with(|data| { diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index bac0802241d..4235293823c 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -567,13 +567,6 @@ impl Span { !self.ctxt().is_root() } - /// Returns `true` if `span` originates in a macro's expansion where debuginfo should be - /// collapsed. - pub fn in_macro_expansion_with_collapse_debuginfo(self) -> bool { - let outer_expn = self.ctxt().outer_expn_data(); - matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo - } - /// 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, _)) |
