diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 9851749be3765..cd2efb4c74728 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -10,27 +10,27 @@
// The Rust abstract syntax tree.
-pub use self::UnsafeSource::*;
pub use self::GenericArgs::*;
+pub use self::UnsafeSource::*;
pub use symbol::{Ident, Symbol as Name};
pub use util::parser::ExprPrecedence;
-use syntax_pos::{Span, DUMMY_SP};
-use source_map::{dummy_spanned, respan, Spanned};
-use rustc_target::spec::abi::Abi;
use ext::hygiene::{Mark, SyntaxContext};
use print::pprust;
use ptr::P;
use rustc_data_structures::indexed_vec;
use rustc_data_structures::indexed_vec::Idx;
-use symbol::{Symbol, keywords};
-use ThinVec;
+use rustc_target::spec::abi::Abi;
+use source_map::{dummy_spanned, respan, Spanned};
+use symbol::{keywords, Symbol};
+use syntax_pos::{Span, DUMMY_SP};
use tokenstream::{ThinTokenStream, TokenStream};
+use ThinVec;
-use serialize::{self, Encoder, Decoder};
-use std::fmt;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
+use serialize::{self, Decoder, Encoder};
+use std::fmt;
use std::u32;
pub use rustc_target::abi::FloatTy;
@@ -54,7 +54,12 @@ pub struct Lifetime {
impl fmt::Debug for Lifetime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "lifetime({}: {})", self.id, pprust::lifetime_to_string(self))
+ write!(
+ f,
+ "lifetime({}: {})",
+ self.id,
+ pprust::lifetime_to_string(self)
+ )
}
}
@@ -94,7 +99,10 @@ impl Path {
// convert a span and an identifier to the corresponding
// 1-segment path
pub fn from_ident(ident: Ident) -> Path {
- Path { segments: vec![PathSegment::from_ident(ident)], span: ident.span }
+ Path {
+ segments: vec![PathSegment::from_ident(ident)],
+ span: ident.span,
+ }
}
// Make a "crate root" segment for this path unless it already has it
@@ -284,7 +292,7 @@ pub enum TraitBoundModifier {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum GenericBound {
Trait(PolyTraitRef, TraitBoundModifier),
- Outlives(Lifetime)
+ Outlives(Lifetime),
}
impl GenericBound {
@@ -304,7 +312,7 @@ pub enum GenericParamKind {
Lifetime,
Type {
default: Option
>,
- }
+ },
}
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
@@ -328,7 +336,7 @@ pub struct Generics {
impl Default for Generics {
/// Creates an instance of `Generics`.
- fn default() -> Generics {
+ fn default() -> Generics {
Generics {
params: Vec::new(),
where_clause: WhereClause {
@@ -458,7 +466,7 @@ pub enum MetaItemKind {
/// Name value meta item.
///
/// E.g. `feature = "foo"` as in `#[feature = "foo"]`
- NameValue(Lit)
+ NameValue(Lit),
}
/// A Block (`{ .. }`).
@@ -492,14 +500,17 @@ impl Pat {
pub(super) fn to_ty(&self) -> Option
> {
let node = match &self.node {
PatKind::Wild => TyKind::Infer,
- PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None) =>
- TyKind::Path(None, Path::from_ident(*ident)),
+ PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None) => {
+ TyKind::Path(None, Path::from_ident(*ident))
+ }
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
PatKind::Mac(mac) => TyKind::Mac(mac.clone()),
- PatKind::Ref(pat, mutbl) =>
- pat.to_ty().map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?,
- PatKind::Slice(pats, None, _) if pats.len() == 1 =>
- pats[0].to_ty().map(TyKind::Slice)?,
+ PatKind::Ref(pat, mutbl) => pat
+ .to_ty()
+ .map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?,
+ PatKind::Slice(pats, None, _) if pats.len() == 1 => {
+ pats[0].to_ty().map(TyKind::Slice)?
+ }
PatKind::Tuple(pats, None) => {
let mut tys = Vec::with_capacity(pats.len());
// FIXME(#48994) - could just be collected into an Option
@@ -511,11 +522,16 @@ impl Pat {
_ => return None,
};
- Some(P(Ty { node, id: self.id, span: self.span }))
+ Some(P(Ty {
+ node,
+ id: self.id,
+ span: self.span,
+ }))
}
pub fn walk(&self, it: &mut F) -> bool
- where F: FnMut(&Pat) -> bool
+ where
+ F: FnMut(&Pat) -> bool,
{
if !it(self) {
return false;
@@ -523,28 +539,22 @@ impl Pat {
match self.node {
PatKind::Ident(_, _, Some(ref p)) => p.walk(it),
- PatKind::Struct(_, ref fields, _) => {
- fields.iter().all(|field| field.node.pat.walk(it))
- }
+ PatKind::Struct(_, ref fields, _) => fields.iter().all(|field| field.node.pat.walk(it)),
PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
s.iter().all(|p| p.walk(it))
}
- PatKind::Box(ref s) | PatKind::Ref(ref s, _) | PatKind::Paren(ref s) => {
- s.walk(it)
- }
+ PatKind::Box(ref s) | PatKind::Ref(ref s, _) | PatKind::Paren(ref s) => s.walk(it),
PatKind::Slice(ref before, ref slice, ref after) => {
- before.iter().all(|p| p.walk(it)) &&
- slice.iter().all(|p| p.walk(it)) &&
- after.iter().all(|p| p.walk(it))
- }
- PatKind::Wild |
- PatKind::Lit(_) |
- PatKind::Range(..) |
- PatKind::Ident(..) |
- PatKind::Path(..) |
- PatKind::Mac(_) => {
- true
+ before.iter().all(|p| p.walk(it))
+ && slice.iter().all(|p| p.walk(it))
+ && after.iter().all(|p| p.walk(it))
}
+ PatKind::Wild
+ | PatKind::Lit(_)
+ | PatKind::Range(..)
+ | PatKind::Ident(..)
+ | PatKind::Path(..)
+ | PatKind::Mac(_) => true,
}
}
}
@@ -623,13 +633,15 @@ pub enum PatKind {
/// `[a, b, ..i, y, z]` is represented as:
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
Slice(Vec>, Option
>, Vec
>),
- /// Parentheses in patters used for grouping, i.e. `(PAT)`.
+ /// Parentheses in patterns used for grouping, i.e. `(PAT)`.
Paren(P),
/// A macro pattern; pre-expansion
Mac(Mac),
}
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy)]
+#[derive(
+ Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy,
+)]
pub enum Mutability {
Mutable,
Immutable,
@@ -702,25 +714,22 @@ impl BinOpKind {
pub fn lazy(&self) -> bool {
match *self {
BinOpKind::And | BinOpKind::Or => true,
- _ => false
+ _ => false,
}
}
pub fn is_shift(&self) -> bool {
match *self {
BinOpKind::Shl | BinOpKind::Shr => true,
- _ => false
+ _ => false,
}
}
pub fn is_comparison(&self) -> bool {
use self::BinOpKind::*;
match *self {
- Eq | Lt | Le | Ne | Gt | Ge =>
- true,
- And | Or | Add | Sub | Mul | Div | Rem |
- BitXor | BitAnd | BitOr | Shl | Shr =>
- false,
+ Eq | Lt | Le | Ne | Gt | Ge => true,
+ And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
}
}
@@ -772,9 +781,9 @@ impl Stmt {
pub fn add_trailing_semicolon(mut self) -> Self {
self.node = match self.node {
StmtKind::Expr(expr) => StmtKind::Semi(expr),
- StmtKind::Mac(mac) => StmtKind::Mac(mac.map(|(mac, _style, attrs)| {
- (mac, MacStmtStyle::Semicolon, attrs)
- })),
+ StmtKind::Mac(mac) => {
+ StmtKind::Mac(mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)))
+ }
node => node,
};
self
@@ -797,11 +806,15 @@ impl Stmt {
impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "stmt({}: {})", self.id.to_string(), pprust::stmt_to_string(self))
+ write!(
+ f,
+ "stmt({}: {})",
+ self.id.to_string(),
+ pprust::stmt_to_string(self)
+ )
}
}
-
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub enum StmtKind {
/// A local (let) binding.
@@ -900,14 +913,13 @@ pub struct AnonConst {
pub value: P,
}
-
/// An expression
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct Expr {
pub id: NodeId,
pub node: ExprKind,
pub span: Span,
- pub attrs: ThinVec
+ pub attrs: ThinVec,
}
impl Expr {
@@ -937,9 +949,10 @@ impl Expr {
fn to_bound(&self) -> Option {
match &self.node {
- ExprKind::Path(None, path) =>
- Some(GenericBound::Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span),
- TraitBoundModifier::None)),
+ ExprKind::Path(None, path) => Some(GenericBound::Trait(
+ PolyTraitRef::new(Vec::new(), path.clone(), self.span),
+ TraitBoundModifier::None,
+ )),
_ => None,
}
}
@@ -949,26 +962,35 @@ impl Expr {
ExprKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
ExprKind::Mac(mac) => TyKind::Mac(mac.clone()),
ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?,
- ExprKind::AddrOf(mutbl, expr) =>
- expr.to_ty().map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?,
- ExprKind::Repeat(expr, expr_len) =>
- expr.to_ty().map(|ty| TyKind::Array(ty, expr_len.clone()))?,
- ExprKind::Array(exprs) if exprs.len() == 1 =>
- exprs[0].to_ty().map(TyKind::Slice)?,
+ ExprKind::AddrOf(mutbl, expr) => expr
+ .to_ty()
+ .map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?,
+ ExprKind::Repeat(expr, expr_len) => {
+ expr.to_ty().map(|ty| TyKind::Array(ty, expr_len.clone()))?
+ }
+ ExprKind::Array(exprs) if exprs.len() == 1 => exprs[0].to_ty().map(TyKind::Slice)?,
ExprKind::Tup(exprs) => {
- let tys = exprs.iter().map(|expr| expr.to_ty()).collect::