Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f84856c

Browse files
committed
Give spans their parent item during lowering.
We only do this operation when incremental compilation is enabled. This avoids pessimizing the span handling for non-incremental compilation.
1 parent 6f782c4 commit f84856c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
422422
let if_kind = hir::ExprKind::If(new_cond, self.arena.alloc(then), Some(else_expr));
423423
let if_expr = self.expr(span, if_kind, ThinVec::new());
424424
let block = self.block_expr(self.arena.alloc(if_expr));
425-
hir::ExprKind::Loop(block, opt_label, hir::LoopSource::While, span.with_hi(cond.span.hi()))
425+
let span = self.lower_span(span.with_hi(cond.span.hi()));
426+
hir::ExprKind::Loop(block, opt_label, hir::LoopSource::While, span)
426427
}
427428

428429
/// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_output(<expr>) }`,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
718718
}
719719

720720
/// Intercept all spans entering HIR.
721-
/// For now we are not doing anything with the intercepted spans.
721+
/// Mark a span as relative to the current owning item.
722722
fn lower_span(&self, span: Span) -> Span {
723-
span
723+
if self.sess.opts.debugging_opts.incremental_relative_spans {
724+
span.with_parent(Some(self.current_hir_id_owner.0))
725+
} else {
726+
// Do not make spans relative when not using incremental compilation.
727+
span
728+
}
724729
}
725730

726731
fn lower_ident(&self, ident: Ident) -> Ident {

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,8 @@ options! {
11061106
incremental_info: bool = (false, parse_bool, [UNTRACKED],
11071107
"print high-level information about incremental reuse (or the lack thereof) \
11081108
(default: no)"),
1109+
incremental_relative_spans: bool = (false, parse_bool, [TRACKED],
1110+
"hash spans relative to their parent item for incr. comp. (default: no)"),
11091111
incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
11101112
"verify incr. comp. hashes of green query instances (default: no)"),
11111113
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],

0 commit comments

Comments
 (0)