Skip to content

Commit d91e310

Browse files
committed
Don't use literal info from the original source when pretty printing expanded ASTs.
1 parent 571d866 commit d91e310

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

src/fuzzer/fuzzer.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ fn check_variants_T<T: copy>(
274274
crate2,
275275
filename,
276276
io::str_reader(""), a,
277-
pprust::no_ann())});
277+
pprust::no_ann(),
278+
false)});
278279
alt cx.mode {
279280
tm_converge {
280281
check_roundtrip_convergence(str3, 1u);
@@ -422,11 +423,12 @@ fn parse_and_print(code: @str) -> str {
422423
filename, code, []/~, sess);
423424
io::with_str_reader(*code) { |rdr|
424425
as_str({|a|pprust::print_crate(sess.cm,
425-
sess.span_diagnostic,
426-
crate,
427-
filename,
428-
rdr, a,
429-
pprust::no_ann())})
426+
sess.span_diagnostic,
427+
crate,
428+
filename,
429+
rdr, a,
430+
pprust::no_ann(),
431+
false)})
430432
}
431433
}
432434

@@ -566,11 +568,12 @@ fn check_variants(files: [str]/~, cx: context) {
566568
io::with_str_reader(*s) { |rdr|
567569
#error("%s",
568570
as_str({|a|pprust::print_crate(sess.cm,
569-
sess.span_diagnostic,
570-
crate,
571-
file,
572-
rdr, a,
573-
pprust::no_ann())}));
571+
sess.span_diagnostic,
572+
crate,
573+
file,
574+
rdr, a,
575+
pprust::no_ann(),
576+
false)}));
574577
}
575578
check_variants_of_ast(*crate, sess.cm, file, cx);
576579
}

src/libsyntax/print/pprust.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,17 @@ const default_columns: uint = 78u;
6464
// copy forward.
6565
fn print_crate(cm: codemap, span_diagnostic: diagnostic::span_handler,
6666
crate: @ast::crate, filename: str, in: io::reader,
67-
out: io::writer, ann: pp_ann) {
67+
out: io::writer, ann: pp_ann, is_expanded: bool) {
6868
let r = comments::gather_comments_and_literals(span_diagnostic,
6969
filename, in);
7070
let s =
7171
@{s: pp::mk_printer(out, default_columns),
7272
cm: some(cm),
7373
comments: some(r.cmnts),
74-
literals: some(r.lits),
74+
// If the code is post expansion, don't use the table of
75+
// literals, since it doesn't correspond with the literals
76+
// in the AST anymore.
77+
literals: if is_expanded { none } else { some(r.lits) },
7578
mut cur_cmnt: 0u,
7679
mut cur_lit: 0u,
7780
boxes: dvec(),

src/rustc/driver/driver.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,22 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
310310
};
311311
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
312312

313-
let mut ann: pprust::pp_ann = pprust::no_ann();
314-
alt ppm {
313+
let ann = alt ppm {
315314
ppm_typed {
316-
ann = {pre: ann_paren_for_expr,
317-
post: {|a|ann_typed_post(option::get(tcx), a)}};
315+
{pre: ann_paren_for_expr,
316+
post: {|a|ann_typed_post(option::get(tcx), a)}}
318317
}
319318
ppm_identified | ppm_expanded_identified {
320-
ann = {pre: ann_paren_for_expr, post: ann_identified_post};
319+
{pre: ann_paren_for_expr, post: ann_identified_post}
321320
}
322-
ppm_expanded | ppm_normal {}
323-
}
321+
ppm_expanded | ppm_normal { pprust::no_ann() }
322+
};
323+
let is_expanded = upto != cu_parse;
324324
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
325325
io::with_str_reader(*src) { |rdr|
326326
pprust::print_crate(sess.codemap, sess.span_diagnostic, crate,
327327
source_name(input),
328-
rdr, io::stdout(), ann);
328+
rdr, io::stdout(), ann, is_expanded);
329329
}
330330
}
331331

0 commit comments

Comments
 (0)