Skip to content

Commit 15dd0a5

Browse files
committed
rollup merge of #21385: nick29581/save-fix2
r? @huonw
2 parents 341e858 + 9ba9966 commit 15dd0a5

File tree

7 files changed

+499
-122
lines changed

7 files changed

+499
-122
lines changed

src/librustc_trans/save/mod.rs

Lines changed: 97 additions & 70 deletions
Large diffs are not rendered by default.

src/librustc_trans/save/recorder.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ impl Recorder {
5050
pub struct FmtStrs<'a> {
5151
pub recorder: Box<Recorder>,
5252
span: SpanUtils<'a>,
53-
krate: String,
5453
}
5554

5655
macro_rules! s { ($e:expr) => { format!("{}", $e) }}
@@ -63,7 +62,7 @@ macro_rules! svec {
6362
})
6463
}
6564

66-
#[derive(Copy,Debug)]
65+
#[derive(Copy, Debug, Eq, PartialEq)]
6766
pub enum Row {
6867
Variable,
6968
Enum,
@@ -92,11 +91,10 @@ pub enum Row {
9291
}
9392

9493
impl<'a> FmtStrs<'a> {
95-
pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>, krate: String) -> FmtStrs<'a> {
94+
pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>) -> FmtStrs<'a> {
9695
FmtStrs {
9796
recorder: rec,
9897
span: span,
99-
krate: krate,
10098
}
10199
}
102100

@@ -177,16 +175,7 @@ impl<'a> FmtStrs<'a> {
177175
});
178176

179177
let pairs = fields.iter().zip(values);
180-
let strs = pairs.map(|(f, v)| format!(",{},\"{}\"", f, escape(
181-
if *f == "qualname" && v.len() > 0 {
182-
let mut n = self.krate.clone();
183-
n.push_str("::");
184-
n.push_str(v);
185-
n
186-
} else {
187-
String::from_str(v)
188-
}
189-
)));
178+
let strs = pairs.map(|(f, v)| format!(",{},\"{}\"", f, escape(String::from_str(v))));
190179
Some(strs.fold(String::new(), |mut s, ss| {
191180
s.push_str(&ss[]);
192181
s
@@ -507,13 +496,13 @@ impl<'a> FmtStrs<'a> {
507496
}
508497

509498
pub fn extern_crate_str(&mut self,
510-
span: Span,
511-
sub_span: Option<Span>,
512-
id: NodeId,
513-
cnum: ast::CrateNum,
514-
name: &str,
515-
loc: &str,
516-
parent: NodeId) {
499+
span: Span,
500+
sub_span: Option<Span>,
501+
id: NodeId,
502+
cnum: ast::CrateNum,
503+
name: &str,
504+
loc: &str,
505+
parent: NodeId) {
517506
self.check_and_record(ExternCrate,
518507
span,
519508
sub_span,

src/librustc_trans/save/span_utils.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a> SpanUtils<'a> {
3737
let lo_pos_byte = self.sess.codemap().lookup_byte_offset(span.lo).pos;
3838
let hi_pos_byte = self.sess.codemap().lookup_byte_offset(span.hi).pos;
3939

40-
format!("file_name,{},file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\
40+
format!("file_name,\"{}\",file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\
4141
file_line_end,{},file_col_end,{},extent_end,{},extent_end_bytes,{}",
4242
lo_loc.file.name,
4343
lo_loc.line, lo_loc.col.to_usize(), lo_pos.to_usize(), lo_pos_byte.to_usize(),
@@ -205,6 +205,7 @@ impl<'a> SpanUtils<'a> {
205205
bracket_count += match prev.tok {
206206
token::Lt => 1,
207207
token::Gt => -1,
208+
token::BinOp(token::Shl) => 2,
208209
token::BinOp(token::Shr) => -2,
209210
_ => 0
210211
};
@@ -296,13 +297,25 @@ impl<'a> SpanUtils<'a> {
296297
pub fn sub_span_after_keyword(&self,
297298
span: Span,
298299
keyword: keywords::Keyword) -> Option<Span> {
300+
self.sub_span_after(span, |t| t.is_keyword(keyword))
301+
}
302+
303+
pub fn sub_span_after_token(&self,
304+
span: Span,
305+
tok: Token) -> Option<Span> {
306+
self.sub_span_after(span, |t| t == tok)
307+
}
308+
309+
fn sub_span_after<F: Fn(Token) -> bool>(&self,
310+
span: Span,
311+
f: F) -> Option<Span> {
299312
let mut toks = self.retokenise_span(span);
300313
loop {
301314
let ts = toks.real_token();
302315
if ts.tok == token::Eof {
303316
return None;
304317
}
305-
if ts.tok.is_keyword(keyword) {
318+
if f(ts.tok) {
306319
let ts = toks.real_token();
307320
if ts.tok == token::Eof {
308321
return None
@@ -313,6 +326,7 @@ impl<'a> SpanUtils<'a> {
313326
}
314327
}
315328

329+
316330
// Returns a list of the spans of idents in a patch.
317331
// E.g., For foo::bar<x,t>::baz, we return [foo, bar, baz] (well, their spans)
318332
pub fn spans_for_path_segments(&self, path: &ast::Path) -> Vec<Span> {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
// sub-module in the same directory as the main crate file
12+
13+
pub struct SameStruct {
14+
pub name: String
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
pub fn hello(x: isize) {
12+
println!("macro {} :-(", x);
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
// sub-module in a sub-directory
12+
13+
use sub::sub2 as msalias;
14+
use sub::sub2;
15+
use std::io::stdio::println;
16+
17+
static yy: usize = 25us;
18+
19+
mod sub {
20+
pub mod sub2 {
21+
use std::io::stdio::println;
22+
pub mod sub3 {
23+
use std::io::stdio::println;
24+
pub fn hello() {
25+
println("hello from module 3");
26+
}
27+
}
28+
pub fn hello() {
29+
println("hello from a module");
30+
}
31+
32+
pub struct nested_struct {
33+
pub field2: u32,
34+
}
35+
}
36+
}
37+
38+
pub struct SubStruct {
39+
pub name: String
40+
}

0 commit comments

Comments
 (0)