diff options
| author | bors <bors@rust-lang.org> | 2021-03-19 15:38:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-03-19 15:38:57 +0000 |
| commit | 9f4bc3ead43a57783d8abea2fa6931a6736f3490 (patch) | |
| tree | ea7f9020ead403b250e25b49007cbc9043c9ec21 /compiler/rustc_span/src/source_map | |
| parent | b97fd3e5a1545ab02e18c52e7f3d2e78a5c960bf (diff) | |
| parent | 99f411d4385f654cfffb5126725414da8b99e211 (diff) | |
| download | rust-9f4bc3ead43a57783d8abea2fa6931a6736f3490.tar.gz rust-9f4bc3ead43a57783d8abea2fa6931a6736f3490.zip | |
Auto merge of #83301 - Dylan-DPC:rollup-x1yzvhm, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - #82500 (Reuse `std::sys::unsupported::pipe` on `hermit`) - #82759 (Remove unwrap_none/expect_none from compiler/.) - #82846 (rustdoc: allow list syntax for #[doc(alias)] attributes) - #82892 (Clarify docs for Read::read's return value) - #83179 (Extend `proc_macro_back_compat` lint to `actix-web`) - #83197 (Move some test-only code to test files) - #83208 (Fix gitattibutes for old git versions) - #83215 (Deprecate std::os::haiku::raw, which accidentally wasn't deprecated) - #83230 (Remove unnecessary `forward_inner_docs` hack) - #83236 (Upgrade memmap to memmap2) - #83270 (Fix typo/inaccuracy in the documentation of Iterator::skip_while) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src/source_map')
| -rw-r--r-- | compiler/rustc_span/src/source_map/tests.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/source_map/tests.rs b/compiler/rustc_span/src/source_map/tests.rs index 0aca677248b..7d814f1d82c 100644 --- a/compiler/rustc_span/src/source_map/tests.rs +++ b/compiler/rustc_span/src/source_map/tests.rs @@ -10,6 +10,50 @@ fn init_source_map() -> SourceMap { sm } +impl SourceMap { + /// Returns `Some(span)`, a union of the LHS and RHS span. The LHS must precede the RHS. If + /// there are gaps between LHS and RHS, the resulting union will cross these gaps. + /// For this to work, + /// + /// * the syntax contexts of both spans much match, + /// * the LHS span needs to end on the same line the RHS span begins, + /// * the LHS span must start at or before the RHS span. + fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span> { + // Ensure we're at the same expansion ID. + if sp_lhs.ctxt() != sp_rhs.ctxt() { + return None; + } + + let lhs_end = match self.lookup_line(sp_lhs.hi()) { + Ok(x) => x, + Err(_) => return None, + }; + let rhs_begin = match self.lookup_line(sp_rhs.lo()) { + Ok(x) => x, + Err(_) => return None, + }; + + // If we must cross lines to merge, don't merge. + if lhs_end.line != rhs_begin.line { + return None; + } + + // Ensure these follow the expected order and that we don't overlap. + if (sp_lhs.lo() <= sp_rhs.lo()) && (sp_lhs.hi() <= sp_rhs.lo()) { + Some(sp_lhs.to(sp_rhs)) + } else { + None + } + } + + /// Converts an absolute `BytePos` to a `CharPos` relative to the `SourceFile`. + fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos { + let idx = self.lookup_source_file_idx(bpos); + let sf = &(*self.files.borrow().source_files)[idx]; + sf.bytepos_to_file_charpos(bpos) + } +} + /// Tests `lookup_byte_offset`. #[test] fn t3() { |
