about summary refs log tree commit diff
path: root/compiler/rustc_span/src/lib.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-22 19:40:13 +0000
committerbors <bors@rust-lang.org>2021-09-22 19:40:13 +0000
commit308dffd25cb55bbb4a1fbee9822cf82c6a5d012d (patch)
tree73d3e17944183d82799540460c59c291baba211a /compiler/rustc_span/src/lib.rs
parentcfff31bc833070a00578bd6178160aeed56f28ba (diff)
parent26c783811858dca1ac37d7ee113e0bd13891420a (diff)
Auto merge of #89179 - the8472:rollup-moxrtaj, r=the8472
Rollup of 8 pull requests

Successful merges:

 - #89036 (Fix missing `no_global_oom_handling` cfg-gating)
 - #89041 (Work around invalid DWARF bugs for fat LTO)
 - #89046 ("Fix" an overflow in byte position math)
 - #89127 (Re-enable the `src/test/debuginfo/mutex.rs` test on Windows)
 - #89133 (Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0`)
 - #89162 (rustc_index: Add some map-like APIs to `IndexVec`)
 - #89164 (Document `--show-type-layout` in the rustdoc book)
 - #89170 (Disable the leak sanitizer on Macos aarch64 for now)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src/lib.rs')
-rw-r--r--compiler/rustc_span/src/lib.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 9c5469f635f..032ae73bbf3 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -25,6 +25,9 @@
 #[macro_use]
 extern crate rustc_macros;
 
+#[macro_use]
+extern crate tracing;
+
 use rustc_data_structures::AtomicRef;
 use rustc_macros::HashStable_Generic;
 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
@@ -782,13 +785,30 @@ impl Span {
     ///     ^^^^^^^^^^^^^^^^^
     /// ```
     pub fn until(self, end: Span) -> Span {
-        let span = self.data();
-        let end = end.data();
+        // Most of this function's body is copied from `to`.
+        // We can't just do `self.to(end.shrink_to_lo())`,
+        // because to also does some magic where it uses min/max so
+        // it can handle overlapping spans. Some advanced mis-use of
+        // `until` with different ctxts makes this visible.
+        let span_data = self.data();
+        let end_data = end.data();
+        // FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
+        // Return the macro span on its own to avoid weird diagnostic output. It is preferable to
+        // have an incomplete span than a completely nonsensical one.
+        if span_data.ctxt != end_data.ctxt {
+            if span_data.ctxt == SyntaxContext::root() {
+                return end;
+            } else if end_data.ctxt == SyntaxContext::root() {
+                return self;
+            }
+            // Both spans fall within a macro.
+            // FIXME(estebank): check if it is the *same* macro.
+        }
         Span::new(
-            span.lo,
-            end.lo,
-            if end.ctxt == SyntaxContext::root() { end.ctxt } else { span.ctxt },
-            if span.parent == end.parent { span.parent } else { None },
+            span_data.lo,
+            end_data.lo,
+            if end_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
+            if span_data.parent == end_data.parent { span_data.parent } else { None },
         )
     }