about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJorge Aparicio <japaricious@gmail.com>2016-03-22 17:58:45 -0500
committerJorge Aparicio <japaricious@gmail.com>2016-03-22 22:03:54 -0500
commit2628f3cc8f91a52d9dcc800afb6c4a7dc0c785e0 (patch)
tree218a69ade6504638f42db4f4c855cbd15d29cb73 /src/libsyntax
parentbd71d11a8f75b9957489c795a1551a0cd489eca3 (diff)
downloadrust-2628f3cc8f91a52d9dcc800afb6c4a7dc0c785e0.tar.gz
rust-2628f3cc8f91a52d9dcc800afb6c4a7dc0c785e0.zip
fix alignment
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs130
-rw-r--r--src/libsyntax/errors/emitter.rs24
-rw-r--r--src/libsyntax/parse/parser.rs41
-rw-r--r--src/libsyntax/print/pprust.rs76
4 files changed, 133 insertions, 138 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index a12016418c6..804ca6705ec 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -530,51 +530,51 @@ impl Encodable for FileMap {
             s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s))?;
             s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s))?;
             s.emit_struct_field("lines", 3, |s| {
-                    let lines = self.lines.borrow();
-                    // store the length
-                    s.emit_u32(lines.len() as u32)?;
-
-                    if !lines.is_empty() {
-                        // In order to preserve some space, we exploit the fact that
-                        // the lines list is sorted and individual lines are
-                        // probably not that long. Because of that we can store lines
-                        // as a difference list, using as little space as possible
-                        // for the differences.
-                        let max_line_length = if lines.len() == 1 {
-                            0
-                        } else {
-                            lines.windows(2)
-                                 .map(|w| w[1] - w[0])
-                                 .map(|bp| bp.to_usize())
-                                 .max()
-                                 .unwrap()
-                        };
-
-                        let bytes_per_diff: u8 = match max_line_length {
-                            0 ... 0xFF => 1,
-                            0x100 ... 0xFFFF => 2,
-                            _ => 4
-                        };
-
-                        // Encode the number of bytes used per diff.
-                        bytes_per_diff.encode(s)?;
-
-                        // Encode the first element.
-                        lines[0].encode(s)?;
-
-                        let diff_iter = (&lines[..]).windows(2)
-                                                    .map(|w| (w[1] - w[0]));
-
-                        match bytes_per_diff {
-                            1 => for diff in diff_iter { (diff.0 as u8).encode(s)? },
-                            2 => for diff in diff_iter { (diff.0 as u16).encode(s)? },
-                            4 => for diff in diff_iter { diff.0.encode(s)? },
-                            _ => unreachable!()
-                        }
+                let lines = self.lines.borrow();
+                // store the length
+                s.emit_u32(lines.len() as u32)?;
+
+                if !lines.is_empty() {
+                    // In order to preserve some space, we exploit the fact that
+                    // the lines list is sorted and individual lines are
+                    // probably not that long. Because of that we can store lines
+                    // as a difference list, using as little space as possible
+                    // for the differences.
+                    let max_line_length = if lines.len() == 1 {
+                        0
+                    } else {
+                        lines.windows(2)
+                             .map(|w| w[1] - w[0])
+                             .map(|bp| bp.to_usize())
+                             .max()
+                             .unwrap()
+                    };
+
+                    let bytes_per_diff: u8 = match max_line_length {
+                        0 ... 0xFF => 1,
+                        0x100 ... 0xFFFF => 2,
+                        _ => 4
+                    };
+
+                    // Encode the number of bytes used per diff.
+                    bytes_per_diff.encode(s)?;
+
+                    // Encode the first element.
+                    lines[0].encode(s)?;
+
+                    let diff_iter = (&lines[..]).windows(2)
+                                                .map(|w| (w[1] - w[0]));
+
+                    match bytes_per_diff {
+                        1 => for diff in diff_iter { (diff.0 as u8).encode(s)? },
+                        2 => for diff in diff_iter { (diff.0 as u16).encode(s)? },
+                        4 => for diff in diff_iter { diff.0.encode(s)? },
+                        _ => unreachable!()
                     }
+                }
 
-                    Ok(())
-                })?;
+                Ok(())
+            })?;
             s.emit_struct_field("multibyte_chars", 4, |s| {
                 (*self.multibyte_chars.borrow()).encode(s)
             })
@@ -590,33 +590,33 @@ impl Decodable for FileMap {
             let start_pos: BytePos = d.read_struct_field("start_pos", 1, |d| Decodable::decode(d))?;
             let end_pos: BytePos = d.read_struct_field("end_pos", 2, |d| Decodable::decode(d))?;
             let lines: Vec<BytePos> = d.read_struct_field("lines", 3, |d| {
-                    let num_lines: u32 = Decodable::decode(d)?;
-                    let mut lines = Vec::with_capacity(num_lines as usize);
+                let num_lines: u32 = Decodable::decode(d)?;
+                let mut lines = Vec::with_capacity(num_lines as usize);
+
+                if num_lines > 0 {
+                    // Read the number of bytes used per diff.
+                    let bytes_per_diff: u8 = Decodable::decode(d)?;
+
+                    // Read the first element.
+                    let mut line_start: BytePos = Decodable::decode(d)?;
+                    lines.push(line_start);
+
+                    for _ in 1..num_lines {
+                        let diff = match bytes_per_diff {
+                            1 => d.read_u8()? as u32,
+                            2 => d.read_u16()? as u32,
+                            4 => d.read_u32()?,
+                            _ => unreachable!()
+                        };
 
-                    if num_lines > 0 {
-                        // Read the number of bytes used per diff.
-                        let bytes_per_diff: u8 = Decodable::decode(d)?;
+                        line_start = line_start + BytePos(diff);
 
-                        // Read the first element.
-                        let mut line_start: BytePos = Decodable::decode(d)?;
                         lines.push(line_start);
-
-                        for _ in 1..num_lines {
-                            let diff = match bytes_per_diff {
-                                1 => d.read_u8()? as u32,
-                                2 => d.read_u16()? as u32,
-                                4 => d.read_u32()?,
-                                _ => unreachable!()
-                            };
-
-                            line_start = line_start + BytePos(diff);
-
-                            lines.push(line_start);
-                        }
                     }
+                }
 
-                    Ok(lines)
-                })?;
+                Ok(lines)
+            })?;
             let multibyte_chars: Vec<MultiByteChar> =
                 d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?;
             Ok(FileMap {
diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs
index c846b1866a7..61fdc8453d8 100644
--- a/src/libsyntax/errors/emitter.rs
+++ b/src/libsyntax/errors/emitter.rs
@@ -208,8 +208,8 @@ impl EmitterWriter {
             if let Some(_) = self.registry.as_ref()
                                           .and_then(|registry| registry.find_description(code)) {
                 print_diagnostic(&mut self.dst, &ss[..], Help,
-                                      &format!("run `rustc --explain {}` to see a \
-                                               detailed explanation", code), None)?;
+                                 &format!("run `rustc --explain {}` to see a \
+                                           detailed explanation", code), None)?;
             }
         }
         Ok(())
@@ -234,13 +234,13 @@ impl EmitterWriter {
         let mut lines = complete.lines();
         for line in lines.by_ref().take(MAX_HIGHLIGHT_LINES) {
             write!(&mut self.dst, "{0}:{1:2$} {3}\n",
-                        fm.name, "", max_digits, line)?;
+                   fm.name, "", max_digits, line)?;
         }
 
         // if we elided some lines, add an ellipsis
         if let Some(_) = lines.next() {
             write!(&mut self.dst, "{0:1$} {0:2$} ...\n",
-                        "", fm.name.len(), max_digits)?;
+                   "", fm.name.len(), max_digits)?;
         }
 
         Ok(())
@@ -424,15 +424,15 @@ impl EmitterWriter {
             // Print offending code-line
             remaining_err_lines -= 1;
             write!(&mut self.dst, "{}:{:>width$} {}\n",
-                        fm.name,
-                        line.line_index + 1,
-                        cur_line_str,
-                        width=digits)?;
+                   fm.name,
+                   line.line_index + 1,
+                   cur_line_str,
+                   width=digits)?;
 
             if s.len() > skip {
                 // Render the spans we assembled previously (if any).
                 println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()),
-                                           "{}", s)?;
+                                      "{}", s)?;
             }
 
             if !overflowed_buf.is_empty() {
@@ -561,13 +561,13 @@ impl EmitterWriter {
 
             // Print offending code-lines
             write!(&mut self.dst, "{}:{:>width$} {}\n", fm.name,
-                        line.line_index + 1, line_str, width=digits)?;
+                   line.line_index + 1, line_str, width=digits)?;
             remaining_err_lines -= 1;
 
             if s.len() > skip {
                 // Render the spans we assembled previously (if any)
                 println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()),
-                                           "{}", s)?;
+                                      "{}", s)?;
             }
             prev_line_index = line.line_index;
         }
@@ -642,7 +642,7 @@ fn print_diagnostic(dst: &mut Destination,
     }
 
     print_maybe_styled!(dst, term::Attr::ForegroundColor(lvl.color()),
-                             "{}: ", lvl.to_string())?;
+                        "{}: ", lvl.to_string())?;
     print_maybe_styled!(dst, term::Attr::Bold, "{}", msg)?;
 
     if let Some(code) = code {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 827f3331753..a1adc99055f 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -834,7 +834,7 @@ impl<'a> Parser<'a> {
         F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
     {
         let (result, returned) = self.parse_seq_to_before_gt_or_return(sep,
-                                                    |p| Ok(Some(f(p)?)))?;
+                                                                       |p| Ok(Some(f(p)?)))?;
         assert!(!returned);
         return Ok(result);
     }
@@ -1476,8 +1476,8 @@ impl<'a> Parser<'a> {
                 self.bump();
                 let delim = self.expect_open_delim()?;
                 let tts = self.parse_seq_to_end(&token::CloseDelim(delim),
-                                                     SeqSep::none(),
-                                                     |p| p.parse_token_tree())?;
+                                                SeqSep::none(),
+                                                |p| p.parse_token_tree())?;
                 let hi = self.span.hi;
                 TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }))
             } else {
@@ -2225,7 +2225,7 @@ impl<'a> Parser<'a> {
                             &token::CloseDelim(token::Bracket),
                             SeqSep::trailing_allowed(token::Comma),
                             |p| Ok(p.parse_expr()?)
-                                )?;
+                        )?;
                         let mut exprs = vec!(first_expr);
                         exprs.extend(remaining_exprs);
                         ex = ExprKind::Vec(exprs);
@@ -2610,8 +2610,8 @@ impl<'a> Parser<'a> {
 
                     let dot_pos = self.last_span.hi;
                     e = self.parse_dot_suffix(special_idents::invalid,
-                                                   mk_sp(dot_pos, dot_pos),
-                                                   e, lo)?;
+                                              mk_sp(dot_pos, dot_pos),
+                                              e, lo)?;
                   }
                 }
                 continue;
@@ -3267,7 +3267,7 @@ impl<'a> Parser<'a> {
         let match_span = self.last_span;
         let lo = self.last_span.lo;
         let discriminant = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL,
-                                                    None)?;
+                                               None)?;
         if let Err(mut e) = self.commit_expr_expecting(&discriminant,
                                                        token::OpenDelim(token::Brace)) {
             if self.token == token::Token::Semi {
@@ -3612,8 +3612,9 @@ impl<'a> Parser<'a> {
                         let path = ident_to_path(ident_span, ident);
                         self.bump();
                         let delim = self.expect_open_delim()?;
-                        let tts = self.parse_seq_to_end(&token::CloseDelim(delim),
-                                SeqSep::none(), |p| p.parse_token_tree())?;
+                        let tts = self.parse_seq_to_end(
+                            &token::CloseDelim(delim),
+                            SeqSep::none(), |p| p.parse_token_tree())?;
                         let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT };
                         pat = PatKind::Mac(codemap::Spanned {node: mac,
                                                        span: mk_sp(lo, self.last_span.hi)});
@@ -3670,10 +3671,10 @@ impl<'a> Parser<'a> {
                             pat = PatKind::TupleStruct(path, None);
                         } else {
                             let args = self.parse_enum_variant_seq(
-                                    &token::OpenDelim(token::Paren),
-                                    &token::CloseDelim(token::Paren),
-                                    SeqSep::trailing_allowed(token::Comma),
-                                    |p| p.parse_pat())?;
+                                &token::OpenDelim(token::Paren),
+                                &token::CloseDelim(token::Paren),
+                                SeqSep::trailing_allowed(token::Comma),
+                                |p| p.parse_pat())?;
                             pat = PatKind::TupleStruct(path, Some(args));
                         }
                       }
@@ -3963,7 +3964,7 @@ impl<'a> Parser<'a> {
             // FIXME: Bad copy of attrs
             let restrictions = self.restrictions | Restrictions::NO_NONINLINE_MOD;
             match self.with_res(restrictions,
-                                     |this| this.parse_item_(attrs.clone(), false, true))? {
+                                |this| this.parse_item_(attrs.clone(), false, true))? {
                 Some(i) => {
                     let hi = i.span.hi;
                     let decl = P(spanned(lo, hi, DeclKind::Item(i)));
@@ -4941,8 +4942,8 @@ impl<'a> Parser<'a> {
             // eat a matched-delimiter token tree:
             let delim = self.expect_open_delim()?;
             let tts = self.parse_seq_to_end(&token::CloseDelim(delim),
-                                                 SeqSep::none(),
-                                                 |p| p.parse_token_tree())?;
+                                            SeqSep::none(),
+                                            |p| p.parse_token_tree())?;
             let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT };
             let m: ast::Mac = codemap::Spanned { node: m_,
                                                 span: mk_sp(lo,
@@ -5409,8 +5410,8 @@ impl<'a> Parser<'a> {
                     id_sp: Span)
                     -> PResult<'a, (ast::ItemKind, Vec<ast::Attribute> )> {
         let ModulePathSuccess { path, owns_directory } = self.submod_path(id,
-                                                                               outer_attrs,
-                                                                               id_sp)?;
+                                                                          outer_attrs,
+                                                                          id_sp)?;
 
         self.eval_src_mod_from_path(path,
                                     owns_directory,
@@ -5993,8 +5994,8 @@ impl<'a> Parser<'a> {
             // eat a matched-delimiter token tree:
             let delim = self.expect_open_delim()?;
             let tts = self.parse_seq_to_end(&token::CloseDelim(delim),
-                                                 SeqSep::none(),
-                                                 |p| p.parse_token_tree())?;
+                                            SeqSep::none(),
+                                            |p| p.parse_token_tree())?;
             // single-variant-enum... :
             let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT };
             let m: ast::Mac = codemap::Spanned { node: m,
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 9a3400025a8..5b06eb026d6 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -388,7 +388,7 @@ pub fn fun_to_string(decl: &ast::FnDecl,
     to_string(|s| {
         s.head("")?;
         s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name),
-                        generics, opt_explicit_self, ast::Visibility::Inherited)?;
+                   generics, opt_explicit_self, ast::Visibility::Inherited)?;
         s.end()?; // Close the head box
         s.end() // Close the outer box
     })
@@ -779,8 +779,8 @@ pub trait PrintState<'a> {
                 word(self.writer(), &name)?;
                 self.popen()?;
                 self.commasep(Consistent,
-                                   &items[..],
-                                   |s, i| s.print_meta_item(&i))?;
+                              &items[..],
+                              |s, i| s.print_meta_item(&i))?;
                 self.pclose()?;
             }
         }
@@ -915,7 +915,7 @@ impl<'a> State<'a> {
             if i < len {
                 word(&mut self.s, ",")?;
                 self.maybe_print_trailing_comment(get_span(elt),
-                                                    Some(get_span(&elts[i]).hi))?;
+                                                  Some(get_span(&elts[i]).hi))?;
                 self.space_if_not_bol()?;
             }
         }
@@ -979,7 +979,7 @@ impl<'a> State<'a> {
             ast::TyKind::Tup(ref elts) => {
                 self.popen()?;
                 self.commasep(Inconsistent, &elts[..],
-                                   |s, ty| s.print_type(&ty))?;
+                              |s, ty| s.print_type(&ty))?;
                 if elts.len() == 1 {
                     word(&mut self.s, ",")?;
                 }
@@ -1000,11 +1000,11 @@ impl<'a> State<'a> {
                     },
                 };
                 self.print_ty_fn(f.abi,
-                                      f.unsafety,
-                                      &f.decl,
-                                      None,
-                                      &generics,
-                                      None)?;
+                                 f.unsafety,
+                                 &f.decl,
+                                 None,
+                                 &generics,
+                                 None)?;
             }
             ast::TyKind::Path(None, ref path) => {
                 self.print_path(path, false, 0)?;
@@ -1050,16 +1050,15 @@ impl<'a> State<'a> {
             ast::ForeignItemKind::Fn(ref decl, ref generics) => {
                 self.head("")?;
                 self.print_fn(decl, ast::Unsafety::Normal,
-                                   ast::Constness::NotConst,
-                                   Abi::Rust, Some(item.ident),
-                                   generics, None, item.vis)?;
+                              ast::Constness::NotConst,
+                              Abi::Rust, Some(item.ident),
+                              generics, None, item.vis)?;
                 self.end()?; // end head-ibox
                 word(&mut self.s, ";")?;
                 self.end() // end the outer fn box
             }
             ast::ForeignItemKind::Static(ref t, m) => {
-                self.head(&visibility_qualified(item.vis,
-                                                    "static"))?;
+                self.head(&visibility_qualified(item.vis, "static"))?;
                 if m {
                     self.word_space("mut")?;
                 }
@@ -1119,8 +1118,7 @@ impl<'a> State<'a> {
         self.ann.pre(self, NodeItem(item))?;
         match item.node {
             ast::ItemKind::ExternCrate(ref optional_path) => {
-                self.head(&visibility_qualified(item.vis,
-                                                     "extern crate"))?;
+                self.head(&visibility_qualified(item.vis, "extern crate"))?;
                 if let Some(p) = *optional_path {
                     let val = p.as_str();
                     if val.contains("-") {
@@ -1138,16 +1136,14 @@ impl<'a> State<'a> {
                 self.end()?; // end outer head-block
             }
             ast::ItemKind::Use(ref vp) => {
-                self.head(&visibility_qualified(item.vis,
-                                                     "use"))?;
+                self.head(&visibility_qualified(item.vis, "use"))?;
                 self.print_view_path(&vp)?;
                 word(&mut self.s, ";")?;
                 self.end()?; // end inner head-block
                 self.end()?; // end outer head-block
             }
             ast::ItemKind::Static(ref ty, m, ref expr) => {
-                self.head(&visibility_qualified(item.vis,
-                                                    "static"))?;
+                self.head(&visibility_qualified(item.vis, "static"))?;
                 if m == ast::Mutability::Mutable {
                     self.word_space("mut")?;
                 }
@@ -1163,8 +1159,7 @@ impl<'a> State<'a> {
                 self.end()?; // end the outer cbox
             }
             ast::ItemKind::Const(ref ty, ref expr) => {
-                self.head(&visibility_qualified(item.vis,
-                                                    "const"))?;
+                self.head(&visibility_qualified(item.vis, "const"))?;
                 self.print_ident(item.ident)?;
                 self.word_space(":")?;
                 self.print_type(&ty)?;
@@ -1192,8 +1187,7 @@ impl<'a> State<'a> {
                 self.print_block_with_attrs(&body, &item.attrs)?;
             }
             ast::ItemKind::Mod(ref _mod) => {
-                self.head(&visibility_qualified(item.vis,
-                                                    "mod"))?;
+                self.head(&visibility_qualified(item.vis, "mod"))?;
                 self.print_ident(item.ident)?;
                 self.nbsp()?;
                 self.bopen()?;
@@ -1555,8 +1549,8 @@ impl<'a> State<'a> {
         match ti.node {
             ast::TraitItemKind::Const(ref ty, ref default) => {
                 self.print_associated_const(ti.ident, &ty,
-                                                 default.as_ref().map(|expr| &**expr),
-                                                 ast::Visibility::Inherited)?;
+                                            default.as_ref().map(|expr| &**expr),
+                                            ast::Visibility::Inherited)?;
             }
             ast::TraitItemKind::Method(ref sig, ref body) => {
                 if body.is_some() {
@@ -1572,7 +1566,7 @@ impl<'a> State<'a> {
             }
             ast::TraitItemKind::Type(ref bounds, ref default) => {
                 self.print_associated_type(ti.ident, Some(bounds),
-                                                default.as_ref().map(|ty| &**ty))?;
+                                           default.as_ref().map(|ty| &**ty))?;
             }
         }
         self.ann.post(self, NodeSubItem(ti.id))
@@ -1923,7 +1917,7 @@ impl<'a> State<'a> {
         if !tys.is_empty() {
             word(&mut self.s, "::<")?;
             self.commasep(Inconsistent, tys,
-                               |s, ty| s.print_type(&ty))?;
+                          |s, ty| s.print_type(&ty))?;
             word(&mut self.s, ">")?;
         }
         self.print_call_post(base_args)
@@ -2223,7 +2217,7 @@ impl<'a> State<'a> {
                     match out.constraint.slice_shift_char() {
                         Some(('=', operand)) if out.is_rw => {
                             s.print_string(&format!("+{}", operand),
-                                                ast::StrStyle::Cooked)?
+                                           ast::StrStyle::Cooked)?
                         }
                         _ => s.print_string(&out.constraint, ast::StrStyle::Cooked)?
                     }
@@ -2267,10 +2261,10 @@ impl<'a> State<'a> {
                     space(&mut self.s)?;
                     self.word_space(":")?;
                     self.commasep(Inconsistent, &options,
-                                       |s, &co| {
-                        s.print_string(co, ast::StrStyle::Cooked)?;
-                        Ok(())
-                    })?;
+                                  |s, &co| {
+                                      s.print_string(co, ast::StrStyle::Cooked)?;
+                                      Ok(())
+                                  })?;
                 }
 
                 self.pclose()?;
@@ -3037,13 +3031,13 @@ impl<'a> State<'a> {
             },
         };
         self.print_fn(decl,
-                           unsafety,
-                           ast::Constness::NotConst,
-                           abi,
-                           name,
-                           &generics,
-                           opt_explicit_self,
-                           ast::Visibility::Inherited)?;
+                      unsafety,
+                      ast::Constness::NotConst,
+                      abi,
+                      name,
+                      &generics,
+                      opt_explicit_self,
+                      ast::Visibility::Inherited)?;
         self.end()
     }