diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-04-18 21:28:23 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-09-10 20:18:36 +0200 |
| commit | f84856cbb0bcba3fae1a74a7e913e1a42d7144f0 (patch) | |
| tree | 4b8dacedfd9944ab86052327b2a4345ccad20402 | |
| parent | 6f782c4e114c2913d5f3e8034664852e7b36452a (diff) | |
| download | rust-f84856cbb0bcba3fae1a74a7e913e1a42d7144f0.tar.gz rust-f84856cbb0bcba3fae1a74a7e913e1a42d7144f0.zip | |
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.
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_session/src/options.rs | 2 |
3 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 16cd7a0bcdd..7acb8412968 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -422,7 +422,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let if_kind = hir::ExprKind::If(new_cond, self.arena.alloc(then), Some(else_expr)); let if_expr = self.expr(span, if_kind, ThinVec::new()); let block = self.block_expr(self.arena.alloc(if_expr)); - hir::ExprKind::Loop(block, opt_label, hir::LoopSource::While, span.with_hi(cond.span.hi())) + let span = self.lower_span(span.with_hi(cond.span.hi())); + hir::ExprKind::Loop(block, opt_label, hir::LoopSource::While, span) } /// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_output(<expr>) }`, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 9edc30ceb19..8d731d7a578 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -718,9 +718,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } /// Intercept all spans entering HIR. - /// For now we are not doing anything with the intercepted spans. + /// Mark a span as relative to the current owning item. fn lower_span(&self, span: Span) -> Span { - span + if self.sess.opts.debugging_opts.incremental_relative_spans { + span.with_parent(Some(self.current_hir_id_owner.0)) + } else { + // Do not make spans relative when not using incremental compilation. + span + } } fn lower_ident(&self, ident: Ident) -> Ident { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 9a1be40558c..447be84b5a7 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1106,6 +1106,8 @@ options! { incremental_info: bool = (false, parse_bool, [UNTRACKED], "print high-level information about incremental reuse (or the lack thereof) \ (default: no)"), + incremental_relative_spans: bool = (false, parse_bool, [TRACKED], + "hash spans relative to their parent item for incr. comp. (default: no)"), incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED], "verify incr. comp. hashes of green query instances (default: no)"), inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED], |
