diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 7d8f7fcefe639..13235cf6f6483 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1236,8 +1236,9 @@ pub fn rustc_optgroups() -> Vec { valid types are any of the types for `--pretty`, as well as: `flowgraph=` (graphviz formatted flowgraph for node), `everybody_loops` (all function bodies replaced with `loop {}`), - `hir` (the HIR), `hir,identified`, or - `hir,typed` (HIR with types for each node).", + `hir` (the HIR), `hir,identified`, + `hir,typed` (HIR with types for each node), or + `ast` (pretty-printed internal AST).", "TYPE"), // new options here should **not** use the `_ubnr` functions, all new diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 3c8a529bdaee8..5c284baf44942 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -81,6 +81,7 @@ pub enum PpMode { PpmFlowGraph(PpFlowGraphMode), PpmMir, PpmMirCFG, + PpmAST, } impl PpMode { @@ -90,6 +91,8 @@ impl PpMode { PpmSource(PpmEveryBodyLoops) | PpmSource(PpmIdentified) => opt_uii.is_some(), + PpmAST => false, + PpmSource(PpmExpanded) | PpmSource(PpmExpandedIdentified) | PpmSource(PpmExpandedHygiene) | @@ -130,6 +133,7 @@ pub fn parse_pretty(sess: &Session, ("mir-cfg", true) => PpmMirCFG, ("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default), ("flowgraph,unlabelled", true) => PpmFlowGraph(PpFlowGraphMode::UnlabelledEdges), + ("ast", true) => PpmAST, _ => { if extended { sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \ @@ -831,24 +835,26 @@ pub fn print_after_parsing(sess: &Session, let mut rdr = &*src; let mut out = Vec::new(); - if let PpmSource(s) = ppm { - // Silently ignores an identified node. - let out: &mut Write = &mut out; - s.call_with_pp_support(sess, None, box out, |annotation, out| { - debug!("pretty printing source code {:?}", s); - let sess = annotation.sess(); - pprust::print_crate(sess.codemap(), - &sess.parse_sess, - krate, - src_name.to_string(), - &mut rdr, - out, - annotation.pp_ann(), - false) - }) - .unwrap() - } else { - unreachable!(); + match ppm { + PpmSource(s) => { + // Silently ignores an identified node. + let out: &mut Write = &mut out; + s.call_with_pp_support(sess, None, box out, |annotation, out| { + debug!("pretty printing source code {:?}", s); + let sess = annotation.sess(); + pprust::print_crate(sess.codemap(), + &sess.parse_sess, + krate, + src_name.to_string(), + &mut rdr, + out, + annotation.pp_ann(), + false) + }) + .unwrap() + } + PpmAST => write!(out, "{:#?}", krate).unwrap(), + _ => unreachable!(), }; write_output(out, ofile);