]> git.lizzy.rs Git - rust.git/commitdiff
Give spans their parent item during lowering.
authorCamille GILLOT <gillot.camille@gmail.com>
Sun, 18 Apr 2021 19:28:23 +0000 (21:28 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Fri, 10 Sep 2021 18:18:36 +0000 (20:18 +0200)
We only do this operation when incremental compilation is enabled. This
avoids pessimizing the span handling for non-incremental compilation.

compiler/rustc_ast_lowering/src/expr.rs
compiler/rustc_ast_lowering/src/lib.rs
compiler/rustc_session/src/options.rs

index 16cd7a0bcdd394af214d0a0235fab976fb3c3636..7acb8412968f066b0e4f1bb1381654fb58e2c06b 100644 (file)
@@ -422,7 +422,8 @@ fn lower_expr_while_in_loop_scope(
         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>) }`,
index 9edc30ceb199e5874bacb7ea3ad0ec17fba0e841..8d731d7a57895fa2a448de1f0b71e6c3636598a0 100644 (file)
@@ -718,9 +718,14 @@ fn with_anonymous_lifetime_mode<R>(
     }
 
     /// 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 {
index 9a1be40558ccb3ca03796f97f6381065301b455e..447be84b5a70ad601ce65247dacd6db006826851 100644 (file)
@@ -1106,6 +1106,8 @@ mod parse {
     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],