Skip to content

Commit d398eb7

Browse files
committed
auto merge of #16419 : huonw/rust/pretty-expanded-hygiene, r=pnkfelix
Different Identifiers and Names can have identical textual representations, but different internal representations, due to the macro hygiene machinery (syntax contexts and gensyms). This provides a way to see these internals by compiling with `--pretty expanded,hygiene`. This is useful for debugging & hacking on macros (e.g. diagnosing #15750 likely would've been faster with this functionality). E.g. ```rust #![feature(macro_rules)] // minimal junk #![no_std] macro_rules! foo { ($x: ident) => { y + $x } } fn bar() { foo!(x) } ``` ```rust #![feature(macro_rules)] // minimal junk #![no_std] fn bar /* 61#0 */() { y /* 60#2 */ + x /* 58#3 */ } ```
2 parents 43c26e6 + 32e4371 commit d398eb7

File tree

8 files changed

+685
-558
lines changed

8 files changed

+685
-558
lines changed

src/librustc/driver/driver.rs

Lines changed: 1 addition & 516 deletions
Large diffs are not rendered by default.

src/librustc/driver/mod.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use getopts;
3333
pub mod driver;
3434
pub mod session;
3535
pub mod config;
36+
pub mod pretty;
3637

3738

3839
pub fn main_args(args: &[String]) -> int {
@@ -96,11 +97,11 @@ fn run_compiler(args: &[String]) {
9697
let ofile = matches.opt_str("o").map(|o| Path::new(o));
9798

9899
let pretty = matches.opt_default("pretty", "normal").map(|a| {
99-
parse_pretty(&sess, a.as_slice())
100+
pretty::parse_pretty(&sess, a.as_slice())
100101
});
101102
match pretty {
102103
Some((ppm, opt_uii)) => {
103-
driver::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
104+
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
104105
return;
105106
}
106107
None => {/* continue */ }
@@ -384,43 +385,6 @@ fn print_crate_info(sess: &Session,
384385
}
385386
}
386387

387-
#[deriving(PartialEq, Show)]
388-
pub enum PpSourceMode {
389-
PpmNormal,
390-
PpmExpanded,
391-
PpmTyped,
392-
PpmIdentified,
393-
PpmExpandedIdentified,
394-
}
395-
396-
#[deriving(PartialEq, Show)]
397-
pub enum PpMode {
398-
PpmSource(PpSourceMode),
399-
PpmFlowGraph,
400-
}
401-
402-
fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<driver::UserIdentifiedItem>) {
403-
let mut split = name.splitn(1, '=');
404-
let first = split.next().unwrap();
405-
let opt_second = split.next();
406-
let first = match first {
407-
"normal" => PpmSource(PpmNormal),
408-
"expanded" => PpmSource(PpmExpanded),
409-
"typed" => PpmSource(PpmTyped),
410-
"expanded,identified" => PpmSource(PpmExpandedIdentified),
411-
"identified" => PpmSource(PpmIdentified),
412-
"flowgraph" => PpmFlowGraph,
413-
_ => {
414-
sess.fatal(format!(
415-
"argument to `pretty` must be one of `normal`, \
416-
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
417-
or `expanded,identified`; got {}", name).as_slice());
418-
}
419-
};
420-
let opt_second = opt_second.and_then::<driver::UserIdentifiedItem>(from_str);
421-
(first, opt_second)
422-
}
423-
424388
fn parse_crate_attrs(sess: &Session, input: &Input) ->
425389
Vec<ast::Attribute> {
426390
let result = match *input {

0 commit comments

Comments
 (0)