Skip to content

Commit 551a74d

Browse files
committed
Auto merge of #24932 - pnkfelix:fix-issue-24687, r=huonw
metdata: Fix zero-normalization of the pos of a `MultiByteChar` Fix #24687 The source byte/character mappings for every crate track the collection of multi-characters from its source files specially. When we import the source information for another file into the current compilation unit, we assign its byte-positions unique values by shifting them all by a fixed adjustment, tracked in the `start_pos` field. But when we pull out the source span information for one function from one crate and into our own crate, we need to re-normalize the byte positions: subtracting the old `start_pos` and adding the new `start_pos`. The `new_imported_filemap(..)` method handles adding the new `start_pos`, so all `creader` needs to do is re-normalize each `pos` to zero. It seems like it was indeed trying to do this, but it mistakenly added the old `start_pos` instead of subtracting it.
2 parents 26c7635 + 2ae82fc commit 551a74d

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn import_codemap(local_codemap: &codemap::CodeMap,
664664
.into_inner()
665665
.map_in_place(|mbc|
666666
codemap::MultiByteChar {
667-
pos: mbc.pos + start_pos,
667+
pos: mbc.pos - start_pos,
668668
bytes: mbc.bytes
669669
});
670670

src/test/auxiliary/issue24687_lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="lib"]
12+
13+
// This is a file that pulls in a separate file as a submodule, where
14+
// that separate file has many multi-byte characters, to try to
15+
// encourage the compiler to trip on them.
16+
17+
mod issue24687_mbcs_in_comments;
18+
19+
pub use issue24687_mbcs_in_comments::D;
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::fmt;
12+
13+
// This ia file with many multi-byte characters, to try to encourage
14+
// the compiler to trip on them. The Drop implementation below will
15+
// need to have its source location embedded into the debug info for
16+
// the output file.
17+
18+
// αααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααα
19+
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
20+
// γγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγγ
21+
// δδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδδ
22+
// εεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεεε
23+
24+
// ζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζζ
25+
// ηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηη
26+
// θθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθθ
27+
// ιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιιι
28+
// κκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκκ
29+
30+
pub struct D<X:fmt::Debug>(pub X);
31+
32+
impl<X:fmt::Debug> Drop for D<X> {
33+
fn drop(&mut self) {
34+
// λλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλλ
35+
println!("Dropping D({:?})", self.0);
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue24687_lib.rs
12+
13+
extern crate issue24687_lib as d;
14+
15+
fn main() {
16+
// Create a d, which has a destructor whose body will be trans'ed
17+
// into the generated code here, and thus the local debuginfo will
18+
// need references into the original source locations from
19+
// `importer` above.
20+
let _d = d::D("Hi");
21+
}

0 commit comments

Comments
 (0)