use syntax::abi::Abi;
use syntax::ast;
use syntax::codemap::{CodeMap, Spanned};
+use syntax::parse::ParseSess;
use syntax::parse::lexer::comments;
use syntax::print::pp::{self, break_offset, word, space, hardbreak};
use syntax::print::pp::{Breaks, eof};
use syntax::ptr::P;
use syntax::symbol::keywords;
use syntax_pos::{self, BytePos};
-use errors;
use hir;
-use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
+use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier, RangeEnd};
+use std::cell::Cell;
use std::io::{self, Write, Read};
pub enum AnnNode<'a> {
/// it can scan the input text for comments and literals to
/// copy forward.
pub fn print_crate<'a>(cm: &'a CodeMap,
- span_diagnostic: &errors::Handler,
+ sess: &ParseSess,
krate: &hir::Crate,
filename: String,
input: &mut Read,
ann: &'a PpAnn,
is_expanded: bool)
-> io::Result<()> {
- let mut s = State::new_from_input(cm, span_diagnostic, filename, input,
- out, ann, is_expanded);
+ let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
// When printing the AST, we sometimes need to inject `#[no_std]` here.
// Since you can't compile the HIR, it's not necessary.
impl<'a> State<'a> {
pub fn new_from_input(cm: &'a CodeMap,
- span_diagnostic: &errors::Handler,
+ sess: &ParseSess,
filename: String,
input: &mut Read,
out: Box<Write + 'a>,
ann: &'a PpAnn,
is_expanded: bool)
-> State<'a> {
- let (cmnts, lits) = comments::gather_comments_and_literals(span_diagnostic,
- filename,
- input);
+ let (cmnts, lits) = comments::gather_comments_and_literals(sess, filename, input);
State::new(cm,
out,
Ok(())
}
- pub fn print_opt_lifetime(&mut self, lifetime: &Option<hir::Lifetime>) -> io::Result<()> {
- if let Some(l) = *lifetime {
- self.print_lifetime(&l)?;
+ pub fn print_opt_lifetime(&mut self, lifetime: &hir::Lifetime) -> io::Result<()> {
+ if !lifetime.is_elided() {
+ self.print_lifetime(lifetime)?;
self.nbsp()?;
}
Ok(())
parameters: &hir::PathParameters,
colons_before_params: bool)
-> io::Result<()> {
- if parameters.is_empty() {
- let infer_types = match *parameters {
- hir::AngleBracketedParameters(ref data) => data.infer_types,
- hir::ParenthesizedParameters(_) => false
- };
-
- // FIXME(eddyb) See the comment below about infer_types.
- if !(infer_types && false) {
- return Ok(());
- }
- }
-
- if colons_before_params {
- word(&mut self.s, "::")?
- }
-
match *parameters {
hir::AngleBracketedParameters(ref data) => {
- word(&mut self.s, "<")?;
+ let start = if colons_before_params { "::<" } else { "<" };
+ let empty = Cell::new(true);
+ let start_or_comma = |this: &mut Self| {
+ if empty.get() {
+ empty.set(false);
+ word(&mut this.s, start)
+ } else {
+ this.word_space(",")
+ }
+ };
- let mut comma = false;
- for lifetime in &data.lifetimes {
- if comma {
- self.word_space(",")?
+ if !data.lifetimes.iter().all(|lt| lt.is_elided()) {
+ for lifetime in &data.lifetimes {
+ start_or_comma(self)?;
+ self.print_lifetime(lifetime)?;
}
- self.print_lifetime(lifetime)?;
- comma = true;
}
if !data.types.is_empty() {
- if comma {
- self.word_space(",")?
- }
+ start_or_comma(self)?;
self.commasep(Inconsistent, &data.types, |s, ty| s.print_type(&ty))?;
- comma = true;
}
// FIXME(eddyb) This would leak into error messages, e.g.:
// "non-exhaustive patterns: `Some::<..>(_)` not covered".
if data.infer_types && false {
- if comma {
- self.word_space(",")?
- }
+ start_or_comma(self)?;
word(&mut self.s, "..")?;
- comma = true;
}
for binding in data.bindings.iter() {
- if comma {
- self.word_space(",")?
- }
+ start_or_comma(self)?;
self.print_name(binding.name)?;
space(&mut self.s)?;
self.word_space("=")?;
self.print_type(&binding.ty)?;
- comma = true;
}
- word(&mut self.s, ">")?
+ if !empty.get() {
+ word(&mut self.s, ">")?
+ }
}
hir::ParenthesizedParameters(ref data) => {
self.print_pat(&inner)?;
}
PatKind::Lit(ref e) => self.print_expr(&e)?,
- PatKind::Range(ref begin, ref end) => {
+ PatKind::Range(ref begin, ref end, ref end_kind) => {
self.print_expr(&begin)?;
space(&mut self.s)?;
- word(&mut self.s, "...")?;
+ match *end_kind {
+ RangeEnd::Included => word(&mut self.s, "...")?,
+ RangeEnd::Excluded => word(&mut self.s, "..")?,
+ }
self.print_expr(&end)?;
}
PatKind::Slice(ref before, ref slice, ref after) => {