#![feature(prelude_import, thread_local, target_thread_local, target_thread_local)]
#![feature(cfg_target_thread_local)]
#![no_std]
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! The Rust parser and macro expander.
//!
//! # Note
//!
//! This API is completely unstable and subject to change.
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url =
"https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/",
test(attr(deny(warnings))))]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std as std;
extern crate term;
extern crate libc;
#[macro_use]
extern crate log;
#[macro_use]
extern crate bitflags;
extern crate rustc_serialize;
// used by deriving
extern crate rustc_serialize as serialize;
extern crate unicode_xid;
// A variant of 'try!' that panics on an Err. This is used as a crutch on the
// way towards a non-panic!-prone parser. It should be used for fatal parsing
// errors; eventually we plan to convert all code using panictry to just use
// normal try.
// Exported for syntax_ext, not meant for general use.
pub mod util {
#[prelude_import]
use std::prelude::v1::*;
pub mod interner {
//! An "interner" is a data structure that associates values with usize tags and
//! allows bidirectional lookup; i.e. given a value, one can easily find the
//! type, and vice versa.
#[prelude_import]
use std::prelude::v1::*;
use ast::Name;
use std::borrow::Borrow;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
use std::ops::Deref;
use std::rc::Rc;
pub struct Interner<T> {
map: RefCell<HashMap<T, Name>>,
vect: RefCell<Vec<T>>,
}
impl <T: Eq + Hash + Clone + 'static> Interner<T> {
pub fn new() -> Interner<T> {
Interner{map: RefCell::new(HashMap::new()),
vect: RefCell::new(Vec::new()),}
}
pub fn prefill(init: &[T]) -> Interner<T> {
let rv = Interner::new();
for v in init { rv.intern((*v).clone()); }
rv
}
pub fn intern(&self, val: T) -> Name {
let mut map = self.map.borrow_mut();
match (*map).get(&val) {
Some(&idx) => return idx,
None => (),
}
let mut vect = self.vect.borrow_mut();
let new_idx = Name((*vect).len() as u32);
(*map).insert(val.clone(), new_idx);
(*vect).push(val);
new_idx
}
pub fn gensym(&self, val: T) -> Name {
let mut vect = self.vect.borrow_mut();
let new_idx = Name((*vect).len() as u32);
(*vect).push(val);
new_idx
}
pub fn get(&self, idx: Name) -> T {
let vect = self.vect.borrow();
(*vect)[idx.0 as usize].clone()
}
pub fn len(&self) -> usize {
let vect = self.vect.borrow();
(*vect).len()
}
pub fn find<Q: ?Sized>(&self, val: &Q) -> Option<Name> where
T: Borrow<Q>, Q: Eq + Hash {
let map = self.map.borrow();
match (*map).get(val) { Some(v) => Some(*v), None => None, }
}
pub fn clear(&self) {
*self.map.borrow_mut() = HashMap::new();
*self.vect.borrow_mut() = Vec::new();
}
}
pub struct RcStr {
string: Rc<String>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for RcStr {
#[inline]
fn partial_cmp(&self, __arg_0: &RcStr)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &RcStr) -> bool {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &RcStr) -> bool {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &RcStr) -> bool {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &RcStr) -> bool {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for RcStr {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match *self {
RcStr { string: ref __self_0_0 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for RcStr {
#[inline]
fn eq(&self, __arg_0: &RcStr) -> bool {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &RcStr) -> bool {
match *__arg_0 {
RcStr { string: ref __self_1_0 } =>
match *self {
RcStr { string: ref __self_0_0 } =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for RcStr {
#[inline]
fn clone(&self) -> RcStr {
match *self {
RcStr { string: ref __self_0_0 } =>
RcStr{string:
::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
impl RcStr {
pub fn new(string: &str) -> RcStr {
RcStr{string: Rc::new(string.to_string()),}
}
}
impl Eq for RcStr { }
impl Ord for RcStr {
fn cmp(&self, other: &RcStr) -> Ordering {
self[..].cmp(&other[..])
}
}
impl fmt::Debug for RcStr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::fmt::Debug;
self[..].fmt(f)
}
}
impl fmt::Display for RcStr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::fmt::Display;
self[..].fmt(f)
}
}
impl Borrow<str> for RcStr {
fn borrow(&self) -> &str { &self.string[..] }
}
impl Deref for RcStr {
type
Target
=
str;
fn deref(&self) -> &str { &self.string[..] }
}
/// A StrInterner differs from Interner<String> in that it accepts
/// &str rather than RcStr, resulting in less allocation.
pub struct StrInterner {
map: RefCell<HashMap<RcStr, Name>>,
vect: RefCell<Vec<RcStr>>,
}
/// When traits can extend traits, we should extend index<Name,T> to get []
impl StrInterner {
pub fn new() -> StrInterner {
StrInterner{map: RefCell::new(HashMap::new()),
vect: RefCell::new(Vec::new()),}
}
pub fn prefill(init: &[&str]) -> StrInterner {
let rv = StrInterner::new();
for &v in init { rv.intern(v); }
rv
}
pub fn intern(&self, val: &str) -> Name {
let mut map = self.map.borrow_mut();
match map.get(val) { Some(&idx) => return idx, None => (), }
let new_idx = Name(self.len() as u32);
let val = RcStr::new(val);
map.insert(val.clone(), new_idx);
self.vect.borrow_mut().push(val);
new_idx
}
pub fn gensym(&self, val: &str) -> Name {
let new_idx = Name(self.len() as u32);
self.vect.borrow_mut().push(RcStr::new(val));
new_idx
}
/// Create a gensym with the same name as an existing
/// entry.
pub fn gensym_copy(&self, idx: Name) -> Name {
let new_idx = Name(self.len() as u32);
let mut vect = self.vect.borrow_mut();
let existing = (*vect)[idx.0 as usize].clone();
vect.push(existing);
new_idx
}
pub fn get(&self, idx: Name) -> RcStr {
(*self.vect.borrow())[idx.0 as usize].clone()
}
pub fn len(&self) -> usize { self.vect.borrow().len() }
pub fn find<Q: ?Sized>(&self, val: &Q) -> Option<Name> where
RcStr: Borrow<Q>, Q: Eq + Hash {
match (*self.map.borrow()).get(val) {
Some(v) => Some(*v),
None => None,
}
}
pub fn clear(&self) {
*self.map.borrow_mut() = HashMap::new();
*self.vect.borrow_mut() = Vec::new();
}
pub fn reset(&self, other: StrInterner) {
*self.map.borrow_mut() = other.map.into_inner();
*self.vect.borrow_mut() = other.vect.into_inner();
}
}
}
pub mod lev_distance {
#[prelude_import]
use std::prelude::v1::*;
use ast::Name;
use std::cmp;
use parse::token::InternedString;
/// To find the Levenshtein distance between two strings
pub fn lev_distance(a: &str, b: &str) -> usize {
if a.is_empty() {
return b.chars().count();
} else if b.is_empty() { return a.chars().count(); }
let mut dcol: Vec<_> = (0..b.len() + 1).collect();
let mut t_last = 0;
for (i, sc) in a.chars().enumerate() {
let mut current = i;
dcol[0] = current + 1;
for (j, tc) in b.chars().enumerate() {
let next = dcol[j + 1];
if sc == tc {
dcol[j + 1] = current;
} else {
dcol[j + 1] = cmp::min(current, next);
dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1;
}
current = next;
t_last = j;
}
}
dcol[t_last + 1]
}
/// To find the best match for a given string from an iterator of names
/// As a loose rule to avoid the obviously incorrect suggestions, it takes
/// an optional limit for the maximum allowable edit distance, which defaults
/// to one-third of the given word
pub fn find_best_match_for_name<'a,
T>(iter_names: T, lookup: &str,
dist: Option<usize>)
-> Option<InternedString> where T: Iterator<Item = &'a Name> {
let max_dist =
dist.map_or_else(|| cmp::max(lookup.len(), 3) / 3, |d| d);
let it =
iter_names.filter_map(|name| {
let dist =
lev_distance(lookup,
&name.as_str());
match dist <= max_dist {
true => Some((name.as_str(), dist)),
false => None,
} });
min_by_key(it, |&(_, val)| val).map(|(s, _)| s)
}
fn min_by_key<I, B: Ord, F>(it: I, f: F) -> Option<I::Item> where
I: Iterator, F: FnMut(&I::Item) -> B {
select_fold1(it, f, |x_p, _, y_p, _| x_p > y_p).map(|(_, x)| x)
}
/// Select an element from an iterator based on the given projection
/// and "comparison" function.
///
/// This is an idiosyncratic helper to try to factor out the
/// commonalities of {max,min}{,_by}. In particular, this avoids
/// having to implement optimizations several times.
#[inline]
fn select_fold1<I, B, FProj,
FCmp>(mut it: I, mut f_proj: FProj, mut f_cmp: FCmp)
-> Option<(B, I::Item)> where I: Iterator, FProj: FnMut(&I::Item) ->
B, FCmp: FnMut(&B, &I::Item, &B, &I::Item) -> bool {
it.next().map(|mut sel| { let mut sel_p = f_proj(&sel);
for x in it {
let x_p = f_proj(&x);
if f_cmp(&sel_p, &sel, &x_p, &x) {
sel = x;
sel_p = x_p;
}
} (sel_p, sel) })
}
}
pub mod node_count {
#[prelude_import]
use std::prelude::v1::*;
use visit::*;
use ast::*;
use codemap::Span;
pub struct NodeCounter {
pub count: usize,
}
impl NodeCounter {
pub fn new() -> NodeCounter { NodeCounter{count: 0,} }
}
impl <'v> Visitor<'v> for NodeCounter {
fn visit_ident(&mut self, span: Span, ident: Ident) {
self.count += 1;
walk_ident(self, span, ident);
}
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) {
self.count += 1;
walk_mod(self, m)
}
fn visit_foreign_item(&mut self, i: &'v ForeignItem) {
self.count += 1;
walk_foreign_item(self, i)
}
fn visit_item(&mut self, i: &'v Item) {
self.count += 1;
walk_item(self, i)
}
fn visit_local(&mut self, l: &'v Local) {
self.count += 1;
walk_local(self, l)
}
fn visit_block(&mut self, b: &'v Block) {
self.count += 1;
walk_block(self, b)
}
fn visit_stmt(&mut self, s: &'v Stmt) {
self.count += 1;
walk_stmt(self, s)
}
fn visit_arm(&mut self, a: &'v Arm) {
self.count += 1;
walk_arm(self, a)
}
fn visit_pat(&mut self, p: &'v Pat) {
self.count += 1;
walk_pat(self, p)
}
fn visit_decl(&mut self, d: &'v Decl) {
self.count += 1;
walk_decl(self, d)
}
fn visit_expr(&mut self, ex: &'v Expr) {
self.count += 1;
walk_expr(self, ex)
}
fn visit_ty(&mut self, t: &'v Ty) {
self.count += 1;
walk_ty(self, t)
}
fn visit_generics(&mut self, g: &'v Generics) {
self.count += 1;
walk_generics(self, g)
}
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl,
b: &'v Block, s: Span, _: NodeId) {
self.count += 1;
walk_fn(self, fk, fd, b, s)
}
fn visit_trait_item(&mut self, ti: &'v TraitItem) {
self.count += 1;
walk_trait_item(self, ti)
}
fn visit_impl_item(&mut self, ii: &'v ImplItem) {
self.count += 1;
walk_impl_item(self, ii)
}
fn visit_trait_ref(&mut self, t: &'v TraitRef) {
self.count += 1;
walk_trait_ref(self, t)
}
fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) {
self.count += 1;
walk_ty_param_bound(self, bounds)
}
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef,
m: &'v TraitBoundModifier) {
self.count += 1;
walk_poly_trait_ref(self, t, m)
}
fn visit_variant_data(&mut self, s: &'v VariantData, _: Ident,
_: &'v Generics, _: NodeId, _: Span) {
self.count += 1;
walk_struct_def(self, s)
}
fn visit_struct_field(&mut self, s: &'v StructField) {
self.count += 1;
walk_struct_field(self, s)
}
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef,
generics: &'v Generics, item_id: NodeId,
_: Span) {
self.count += 1;
walk_enum_def(self, enum_definition, generics, item_id)
}
fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics,
item_id: NodeId) {
self.count += 1;
walk_variant(self, v, g, item_id)
}
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
self.count += 1;
walk_lifetime(self, lifetime)
}
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
self.count += 1;
walk_lifetime_def(self, lifetime)
}
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
self.count += 1;
walk_explicit_self(self, es)
}
fn visit_mac(&mut self, _mac: &'v Mac) {
self.count += 1;
walk_mac(self, _mac)
}
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
self.count += 1;
walk_path(self, path)
}
fn visit_path_list_item(&mut self, prefix: &'v Path,
item: &'v PathListItem) {
self.count += 1;
walk_path_list_item(self, prefix, item)
}
fn visit_path_parameters(&mut self, path_span: Span,
path_parameters: &'v PathParameters) {
self.count += 1;
walk_path_parameters(self, path_span, path_parameters)
}
fn visit_assoc_type_binding(&mut self,
type_binding: &'v TypeBinding) {
self.count += 1;
walk_assoc_type_binding(self, type_binding)
}
fn visit_attribute(&mut self, _attr: &'v Attribute) {
self.count += 1;
}
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
self.count += 1;
walk_macro_def(self, macro_def)
}
}
}
pub mod parser {
#[prelude_import]
use std::prelude::v1::*;
use parse::token::{Token, BinOpToken, keywords};
use ast;
/// Associative operator with precedence.
///
/// This is the enum which specifies operator precedence and fixity to the parser.
pub enum AssocOp {
/// `+`
Add,
/// `-`
Subtract,
/// `*`
Multiply,
/// `/`
Divide,
/// `%`
Modulus,
/// `&&`
LAnd,
/// `||`
LOr,
/// `^`
BitXor,
/// `&`
BitAnd,
/// `|`
BitOr,
/// `<<`
ShiftLeft,
/// `>>`
ShiftRight,
/// `==`
Equal,
/// `<`
Less,
/// `<=`
LessEqual,
/// `!=`
NotEqual,
/// `>`
Greater,
/// `>=`
GreaterEqual,
/// `=`
Assign,
/// `<-`
Inplace,
/// `?=` where ? is one of the BinOpToken
AssignOp(BinOpToken),
/// `as`
As,
/// `..` range
DotDot,
/// `:`
Colon,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for AssocOp {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&AssocOp::Add,) => { }
(&AssocOp::Subtract,) => { }
(&AssocOp::Multiply,) => { }
(&AssocOp::Divide,) => { }
(&AssocOp::Modulus,) => { }
(&AssocOp::LAnd,) => { }
(&AssocOp::LOr,) => { }
(&AssocOp::BitXor,) => { }
(&AssocOp::BitAnd,) => { }
(&AssocOp::BitOr,) => { }
(&AssocOp::ShiftLeft,) => { }
(&AssocOp::ShiftRight,) => { }
(&AssocOp::Equal,) => { }
(&AssocOp::Less,) => { }
(&AssocOp::LessEqual,) => { }
(&AssocOp::NotEqual,) => { }
(&AssocOp::Greater,) => { }
(&AssocOp::GreaterEqual,) => { }
(&AssocOp::Assign,) => { }
(&AssocOp::Inplace,) => { }
(&AssocOp::AssignOp(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&AssocOp::As,) => { }
(&AssocOp::DotDot,) => { }
(&AssocOp::Colon,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AssocOp {
#[inline]
fn eq(&self, __arg_0: &AssocOp) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AssocOp::Add, &AssocOp::Add) => true,
(&AssocOp::Subtract, &AssocOp::Subtract) => true,
(&AssocOp::Multiply, &AssocOp::Multiply) => true,
(&AssocOp::Divide, &AssocOp::Divide) => true,
(&AssocOp::Modulus, &AssocOp::Modulus) => true,
(&AssocOp::LAnd, &AssocOp::LAnd) => true,
(&AssocOp::LOr, &AssocOp::LOr) => true,
(&AssocOp::BitXor, &AssocOp::BitXor) => true,
(&AssocOp::BitAnd, &AssocOp::BitAnd) => true,
(&AssocOp::BitOr, &AssocOp::BitOr) => true,
(&AssocOp::ShiftLeft, &AssocOp::ShiftLeft) =>
true,
(&AssocOp::ShiftRight, &AssocOp::ShiftRight) =>
true,
(&AssocOp::Equal, &AssocOp::Equal) => true,
(&AssocOp::Less, &AssocOp::Less) => true,
(&AssocOp::LessEqual, &AssocOp::LessEqual) =>
true,
(&AssocOp::NotEqual, &AssocOp::NotEqual) => true,
(&AssocOp::Greater, &AssocOp::Greater) => true,
(&AssocOp::GreaterEqual, &AssocOp::GreaterEqual)
=> true,
(&AssocOp::Assign, &AssocOp::Assign) => true,
(&AssocOp::Inplace, &AssocOp::Inplace) => true,
(&AssocOp::AssignOp(ref __self_0),
&AssocOp::AssignOp(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&AssocOp::As, &AssocOp::As) => true,
(&AssocOp::DotDot, &AssocOp::DotDot) => true,
(&AssocOp::Colon, &AssocOp::Colon) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &AssocOp) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AssocOp::Add, &AssocOp::Add) => false,
(&AssocOp::Subtract, &AssocOp::Subtract) => false,
(&AssocOp::Multiply, &AssocOp::Multiply) => false,
(&AssocOp::Divide, &AssocOp::Divide) => false,
(&AssocOp::Modulus, &AssocOp::Modulus) => false,
(&AssocOp::LAnd, &AssocOp::LAnd) => false,
(&AssocOp::LOr, &AssocOp::LOr) => false,
(&AssocOp::BitXor, &AssocOp::BitXor) => false,
(&AssocOp::BitAnd, &AssocOp::BitAnd) => false,
(&AssocOp::BitOr, &AssocOp::BitOr) => false,
(&AssocOp::ShiftLeft, &AssocOp::ShiftLeft) =>
false,
(&AssocOp::ShiftRight, &AssocOp::ShiftRight) =>
false,
(&AssocOp::Equal, &AssocOp::Equal) => false,
(&AssocOp::Less, &AssocOp::Less) => false,
(&AssocOp::LessEqual, &AssocOp::LessEqual) =>
false,
(&AssocOp::NotEqual, &AssocOp::NotEqual) => false,
(&AssocOp::Greater, &AssocOp::Greater) => false,
(&AssocOp::GreaterEqual, &AssocOp::GreaterEqual)
=> false,
(&AssocOp::Assign, &AssocOp::Assign) => false,
(&AssocOp::Inplace, &AssocOp::Inplace) => false,
(&AssocOp::AssignOp(ref __self_0),
&AssocOp::AssignOp(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&AssocOp::As, &AssocOp::As) => false,
(&AssocOp::DotDot, &AssocOp::DotDot) => false,
(&AssocOp::Colon, &AssocOp::Colon) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AssocOp {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&AssocOp::Add,) => {
let mut builder = __arg_0.debug_tuple("Add");
builder.finish()
}
(&AssocOp::Subtract,) => {
let mut builder = __arg_0.debug_tuple("Subtract");
builder.finish()
}
(&AssocOp::Multiply,) => {
let mut builder = __arg_0.debug_tuple("Multiply");
builder.finish()
}
(&AssocOp::Divide,) => {
let mut builder = __arg_0.debug_tuple("Divide");
builder.finish()
}
(&AssocOp::Modulus,) => {
let mut builder = __arg_0.debug_tuple("Modulus");
builder.finish()
}
(&AssocOp::LAnd,) => {
let mut builder = __arg_0.debug_tuple("LAnd");
builder.finish()
}
(&AssocOp::LOr,) => {
let mut builder = __arg_0.debug_tuple("LOr");
builder.finish()
}
(&AssocOp::BitXor,) => {
let mut builder = __arg_0.debug_tuple("BitXor");
builder.finish()
}
(&AssocOp::BitAnd,) => {
let mut builder = __arg_0.debug_tuple("BitAnd");
builder.finish()
}
(&AssocOp::BitOr,) => {
let mut builder = __arg_0.debug_tuple("BitOr");
builder.finish()
}
(&AssocOp::ShiftLeft,) => {
let mut builder = __arg_0.debug_tuple("ShiftLeft");
builder.finish()
}
(&AssocOp::ShiftRight,) => {
let mut builder = __arg_0.debug_tuple("ShiftRight");
builder.finish()
}
(&AssocOp::Equal,) => {
let mut builder = __arg_0.debug_tuple("Equal");
builder.finish()
}
(&AssocOp::Less,) => {
let mut builder = __arg_0.debug_tuple("Less");
builder.finish()
}
(&AssocOp::LessEqual,) => {
let mut builder = __arg_0.debug_tuple("LessEqual");
builder.finish()
}
(&AssocOp::NotEqual,) => {
let mut builder = __arg_0.debug_tuple("NotEqual");
builder.finish()
}
(&AssocOp::Greater,) => {
let mut builder = __arg_0.debug_tuple("Greater");
builder.finish()
}
(&AssocOp::GreaterEqual,) => {
let mut builder = __arg_0.debug_tuple("GreaterEqual");
builder.finish()
}
(&AssocOp::Assign,) => {
let mut builder = __arg_0.debug_tuple("Assign");
builder.finish()
}
(&AssocOp::Inplace,) => {
let mut builder = __arg_0.debug_tuple("Inplace");
builder.finish()
}
(&AssocOp::AssignOp(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("AssignOp");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&AssocOp::As,) => {
let mut builder = __arg_0.debug_tuple("As");
builder.finish()
}
(&AssocOp::DotDot,) => {
let mut builder = __arg_0.debug_tuple("DotDot");
builder.finish()
}
(&AssocOp::Colon,) => {
let mut builder = __arg_0.debug_tuple("Colon");
builder.finish()
}
}
}
}
pub enum Fixity {
/// The operator is left-associative
Left,
/// The operator is right-associative
Right,
/// The operator is not associative
None,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Fixity {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Fixity::Left,) => { }
(&Fixity::Right,) => { }
(&Fixity::None,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Fixity {
#[inline]
fn eq(&self, __arg_0: &Fixity) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Fixity::Left, &Fixity::Left) => true,
(&Fixity::Right, &Fixity::Right) => true,
(&Fixity::None, &Fixity::None) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Fixity) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Fixity::Left, &Fixity::Left) => false,
(&Fixity::Right, &Fixity::Right) => false,
(&Fixity::None, &Fixity::None) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Fixity {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Fixity::Left,) => {
let mut builder = __arg_0.debug_tuple("Left");
builder.finish()
}
(&Fixity::Right,) => {
let mut builder = __arg_0.debug_tuple("Right");
builder.finish()
}
(&Fixity::None,) => {
let mut builder = __arg_0.debug_tuple("None");
builder.finish()
}
}
}
}
impl AssocOp {
/// Create a new AssocOP from a token
pub fn from_token(t: &Token) -> Option<AssocOp> {
use self::AssocOp::*;
match *t {
Token::BinOpEq(k) => Some(AssignOp(k)),
Token::LArrow => Some(Inplace),
Token::Eq => Some(Assign),
Token::BinOp(BinOpToken::Star) => Some(Multiply),
Token::BinOp(BinOpToken::Slash) => Some(Divide),
Token::BinOp(BinOpToken::Percent) => Some(Modulus),
Token::BinOp(BinOpToken::Plus) => Some(Add),
Token::BinOp(BinOpToken::Minus) => Some(Subtract),
Token::BinOp(BinOpToken::Shl) => Some(ShiftLeft),
Token::BinOp(BinOpToken::Shr) => Some(ShiftRight),
Token::BinOp(BinOpToken::And) => Some(BitAnd),
Token::BinOp(BinOpToken::Caret) => Some(BitXor),
Token::BinOp(BinOpToken::Or) => Some(BitOr),
Token::Lt => Some(Less),
Token::Le => Some(LessEqual),
Token::Ge => Some(GreaterEqual),
Token::Gt => Some(Greater),
Token::EqEq => Some(Equal),
Token::Ne => Some(NotEqual),
Token::AndAnd => Some(LAnd),
Token::OrOr => Some(LOr),
Token::DotDot => Some(DotDot),
Token::Colon => Some(Colon),
_ if t.is_keyword(keywords::As) => Some(As),
_ => None,
}
}
/// Create a new AssocOp from ast::BinOp_.
pub fn from_ast_binop(op: ast::BinOp_) -> Self {
use self::AssocOp::*;
match op {
ast::BiLt => Less,
ast::BiGt => Greater,
ast::BiLe => LessEqual,
ast::BiGe => GreaterEqual,
ast::BiEq => Equal,
ast::BiNe => NotEqual,
ast::BiMul => Multiply,
ast::BiDiv => Divide,
ast::BiRem => Modulus,
ast::BiAdd => Add,
ast::BiSub => Subtract,
ast::BiShl => ShiftLeft,
ast::BiShr => ShiftRight,
ast::BiBitAnd => BitAnd,
ast::BiBitXor => BitXor,
ast::BiBitOr => BitOr,
ast::BiAnd => LAnd,
ast::BiOr => LOr,
}
}
/// Gets the precedence of this operator
pub fn precedence(&self) -> usize {
use self::AssocOp::*;
match *self {
As | Colon => 14,
Multiply | Divide | Modulus => 13,
Add | Subtract => 12,
ShiftLeft | ShiftRight => 11,
BitAnd => 10,
BitXor => 9,
BitOr => 8,
Less | Greater | LessEqual | GreaterEqual | Equal |
NotEqual => 7,
LAnd => 6,
LOr => 5,
DotDot => 4,
Inplace => 3,
Assign | AssignOp(_) => 2,
}
}
/// Gets the fixity of this operator
pub fn fixity(&self) -> Fixity {
use self::AssocOp::*;
match *self {
Inplace | Assign | AssignOp(_) => Fixity::Right,
As | Multiply | Divide | Modulus | Add | Subtract |
ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | Less |
Greater | LessEqual | GreaterEqual | Equal | NotEqual |
LAnd | LOr | Colon => Fixity::Left,
DotDot => Fixity::None,
}
}
pub fn is_comparison(&self) -> bool {
use self::AssocOp::*;
match *self {
Less | Greater | LessEqual | GreaterEqual | Equal |
NotEqual => true,
Inplace | Assign | AssignOp(_) | As | Multiply | Divide |
Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd
| BitXor | BitOr | LAnd | LOr | DotDot | Colon => false,
}
}
pub fn is_assign_like(&self) -> bool {
use self::AssocOp::*;
match *self {
Assign | AssignOp(_) | Inplace => true,
Less | Greater | LessEqual | GreaterEqual | Equal |
NotEqual | As | Multiply | Divide | Modulus | Add |
Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor |
BitOr | LAnd | LOr | DotDot | Colon => false,
}
}
pub fn to_ast_binop(&self) -> Option<ast::BinOp_> {
use self::AssocOp::*;
match *self {
Less => Some(ast::BiLt),
Greater => Some(ast::BiGt),
LessEqual => Some(ast::BiLe),
GreaterEqual => Some(ast::BiGe),
Equal => Some(ast::BiEq),
NotEqual => Some(ast::BiNe),
Multiply => Some(ast::BiMul),
Divide => Some(ast::BiDiv),
Modulus => Some(ast::BiRem),
Add => Some(ast::BiAdd),
Subtract => Some(ast::BiSub),
ShiftLeft => Some(ast::BiShl),
ShiftRight => Some(ast::BiShr),
BitAnd => Some(ast::BiBitAnd),
BitXor => Some(ast::BiBitXor),
BitOr => Some(ast::BiBitOr),
LAnd => Some(ast::BiAnd),
LOr => Some(ast::BiOr),
Inplace | Assign | AssignOp(_) | As | DotDot | Colon =>
None,
}
}
}
}
pub mod small_vector {
#[prelude_import]
use std::prelude::v1::*;
use self::SmallVectorRepr::*;
use self::IntoIterRepr::*;
use std::iter::{IntoIterator, FromIterator};
use std::mem;
use std::slice;
use std::vec;
use util::move_map::MoveMap;
/// A vector type optimized for cases where the size is almost always 0 or 1
pub struct SmallVector<T> {
repr: SmallVectorRepr<T>,
}
enum SmallVectorRepr<T> { Zero, One(T), Many(Vec<T>), }
impl <T> FromIterator<T> for SmallVector<T> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I)
-> SmallVector<T> {
let mut v = SmallVector::zero();
v.extend(iter);
v
}
}
impl <T> Extend<T> for SmallVector<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
for val in iter { self.push(val); }
}
}
impl <T> SmallVector<T> {
pub fn zero() -> SmallVector<T> { SmallVector{repr: Zero,} }
pub fn one(v: T) -> SmallVector<T> { SmallVector{repr: One(v),} }
pub fn many(vs: Vec<T>) -> SmallVector<T> {
SmallVector{repr: Many(vs),}
}
pub fn as_slice(&self) -> &[T] {
match self.repr {
Zero => { let result: &[T] = &[]; result }
One(ref v) => { unsafe { slice::from_raw_parts(v, 1) } }
Many(ref vs) => vs,
}
}
pub fn pop(&mut self) -> Option<T> {
match self.repr {
Zero => None,
One(..) => {
let one = mem::replace(&mut self.repr, Zero);
match one {
One(v1) => Some(v1),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/util/small_vector.rs",
81u32);
&_FILE_LINE
})
}
}
}
}
Many(ref mut vs) => vs.pop(),
}
}
pub fn push(&mut self, v: T) {
match self.repr {
Zero => self.repr = One(v),
One(..) => {
let one = mem::replace(&mut self.repr, Zero);
match one {
One(v1) =>
mem::replace(&mut self.repr,
Many(<[_]>::into_vec(::std::boxed::Box::new([v1,
v])))),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/util/small_vector.rs",
95u32);
&_FILE_LINE
})
}
}
};
}
Many(ref mut vs) => vs.push(v),
}
}
pub fn push_all(&mut self, other: SmallVector<T>) {
for v in other.into_iter() { self.push(v); }
}
pub fn get(&self, idx: usize) -> &T {
match self.repr {
One(ref v) if idx == 0 => v,
Many(ref vs) => &vs[idx],
_ => {
::std::rt::begin_unwind("out of bounds access",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/util/small_vector.rs",
112u32);
&_FILE_LINE
})
}
}
}
pub fn expect_one(self, err: &'static str) -> T {
match self.repr {
One(v) => v,
Many(v) => {
if v.len() == 1 {
v.into_iter().next().unwrap()
} else {
{
::std::rt::begin_unwind(err,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/util/small_vector.rs",
123u32);
&_FILE_LINE
})
}
}
}
_ => {
::std::rt::begin_unwind(err,
{
static _FILE_LINE:
(&'static str, u32)
=
("src/util/small_vector.rs",
126u32);
&_FILE_LINE
})
}
}
}
pub fn len(&self) -> usize {
match self.repr {
Zero => 0,
One(..) => 1,
Many(ref vals) => vals.len(),
}
}
pub fn is_empty(&self) -> bool { self.len() == 0 }
}
impl <T> IntoIterator for SmallVector<T> {
type
Item
=
T;
type
IntoIter
=
IntoIter<T>;
fn into_iter(self) -> Self::IntoIter {
let repr =
match self.repr {
Zero => ZeroIterator,
One(v) => OneIterator(v),
Many(vs) => ManyIterator(vs.into_iter()),
};
IntoIter{repr: repr,}
}
}
pub struct IntoIter<T> {
repr: IntoIterRepr<T>,
}
enum IntoIterRepr<T> {
ZeroIterator,
OneIterator(T),
ManyIterator(vec::IntoIter<T>),
}
impl <T> Iterator for IntoIter<T> {
type
Item
=
T;
fn next(&mut self) -> Option<T> {
match self.repr {
ZeroIterator => None,
OneIterator(..) => {
let mut replacement = ZeroIterator;
mem::swap(&mut self.repr, &mut replacement);
match replacement {
OneIterator(v) => Some(v),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/util/small_vector.rs",
175u32);
&_FILE_LINE
})
}
}
}
}
ManyIterator(ref mut inner) => inner.next(),
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
match self.repr {
ZeroIterator => (0, Some(0)),
OneIterator(..) => (1, Some(1)),
ManyIterator(ref inner) => inner.size_hint(),
}
}
}
impl <T> MoveMap<T> for SmallVector<T> {
fn move_flat_map<F, I>(self, mut f: F) -> Self where F: FnMut(T)
-> I, I: IntoIterator<Item = T> {
match self.repr {
Zero => Self::zero(),
One(v) => f(v).into_iter().collect(),
Many(vs) => SmallVector{repr: Many(vs.move_flat_map(f)),},
}
}
}
}
pub mod move_map {
#[prelude_import]
use std::prelude::v1::*;
use std::ptr;
pub trait MoveMap<T>: Sized {
fn move_map<F>(self, mut f: F) -> Self where F: FnMut(T) -> T {
self.move_flat_map(|e| Some(f(e)))
}
fn move_flat_map<F, I>(self, f: F)
-> Self
where
F: FnMut(T)
->
I,
I: IntoIterator<Item
=
T>;
}
impl <T> MoveMap<T> for Vec<T> {
fn move_flat_map<F, I>(mut self, mut f: F) -> Self where
F: FnMut(T) -> I, I: IntoIterator<Item = T> {
let mut read_i = 0;
let mut write_i = 0;
unsafe {
let mut old_len = self.len();
self.set_len(0);
while read_i < old_len {
let e = ptr::read(self.get_unchecked(read_i));
let mut iter = f(e).into_iter();
read_i += 1;
while let Some(e) = iter.next() {
if write_i < read_i {
ptr::write(self.get_unchecked_mut(write_i),
e);
write_i += 1;
} else {
self.set_len(old_len);
self.insert(write_i, e);
old_len = self.len();
self.set_len(0);
read_i += 1;
write_i += 1;
}
}
}
self.set_len(write_i);
}
self
}
}
impl <T> MoveMap<T> for ::ptr::P<[T]> {
fn move_flat_map<F, I>(self, f: F) -> Self where F: FnMut(T) -> I,
I: IntoIterator<Item = T> {
::ptr::P::from_vec(self.into_vec().move_flat_map(f))
}
}
}
}
pub mod diagnostics {
#[prelude_import]
use std::prelude::v1::*;
pub mod macros {
#[prelude_import]
use std::prelude::v1::*;
}
pub mod plugin {
#[prelude_import]
use std::prelude::v1::*;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::env;
use ast;
use ast::{Ident, Name, TokenTree};
use codemap::Span;
use ext::base::{ExtCtxt, MacEager, MacResult};
use ext::build::AstBuilder;
use parse::token;
use ptr::P;
use util::small_vector::SmallVector;
use diagnostics::metadata::output_metadata;
const MAX_DESCRIPTION_WIDTH: usize = 80;
static REGISTERED_DIAGNOSTICS:
::std::thread::LocalKey<RefCell<ErrorMap>> =
{
fn __init() -> RefCell<ErrorMap> {
{ RefCell::new(BTreeMap::new()) }
}
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<RefCell<ErrorMap>>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY:
::std::thread::__ElfLocalKeyInner<RefCell<ErrorMap>>
=
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
/// Error information type.
pub struct ErrorInfo {
pub description: Option<Name>,
pub use_site: Option<Span>,
}
/// Mapping from error codes to metadata.
pub type ErrorMap = BTreeMap<Name, ErrorInfo>;
fn with_registered_diagnostics<T, F>(f: F) -> T where
F: FnOnce(&mut ErrorMap) -> T {
REGISTERED_DIAGNOSTICS.with(move |slot| {
f(&mut *slot.borrow_mut()) })
}
pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt, span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+ 'cx> {
let code =
match (token_tree.len(), token_tree.get(0)) {
(1, Some(&TokenTree::Token(_, token::Ident(code, _)))) =>
code,
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/diagnostics/plugin.rs",
58u32);
&_FILE_LINE
})
}
}
};
with_registered_diagnostics(|diagnostics| {
match diagnostics.get_mut(&code.name)
{
Some(&mut ErrorInfo {
description: _,
use_site: Some(previous_span)
}) => {
ecx.struct_span_warn(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["diagnostic code ",
" already used"];
__STATIC_FMTSTR
},
&match (&code,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).span_note(previous_span,
"previous invocation").emit();
}
Some(ref mut info) => {
info.use_site = Some(span);
}
None => {
ecx.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["used diagnostic code ",
" not registered"];
__STATIC_FMTSTR
},
&match (&code,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
} });
MacEager::expr(ecx.expr_tuple(span, Vec::new()))
}
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+ 'cx> {
let (code, description) =
match (token_tree.len(), token_tree.get(0), token_tree.get(1),
token_tree.get(2)) {
(1, Some(&TokenTree::Token(_, token::Ident(ref code, _))),
None, None) => {
(code, None)
}
(3, Some(&TokenTree::Token(_, token::Ident(ref code, _))),
Some(&TokenTree::Token(_, token::Comma)),
Some(&TokenTree::Token(_,
token::Literal(token::StrRaw(description,
_),
None)))) => {
(code, Some(description))
}
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/diagnostics/plugin.rs",
103u32);
&_FILE_LINE
})
}
}
};
description.map(|raw_msg| { let msg = raw_msg.as_str();
if !msg.starts_with("\n") || !msg.ends_with("\n")
{
ecx.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["description for error code ",
" doesn\'t start and end with a newline"];
__STATIC_FMTSTR
},
&match (&code,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
let is_url =
|l: &str|
l.starts_with('[') && l.contains("]:") &&
l.contains("http");
if msg.lines().any(|line|
line.len() >
MAX_DESCRIPTION_WIDTH
&& !is_url(line)) {
ecx.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["description for error code ",
" contains a line longer than ",
" characters.\nif you\'re inserting a long URL use the footnote style to bypass this check."];
__STATIC_FMTSTR
},
&match (&code,
&MAX_DESCRIPTION_WIDTH)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
} });
with_registered_diagnostics(|diagnostics| {
let info =
ErrorInfo{description:
description,
use_site: None,};
if diagnostics.insert(code.name,
info).is_some()
{
ecx.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["diagnostic code ",
" already registered"];
__STATIC_FMTSTR
},
&match (&code,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
} });
let sym =
Ident::with_empty_ctxt(token::gensym(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["__register_diagnostic_"];
__STATIC_FMTSTR
},
&match (&code,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))));
MacEager::items(SmallVector::many(<[_]>::into_vec(::std::boxed::Box::new([ecx.item_mod(span,
span,
sym,
Vec::new(),
Vec::new())]))))
}
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+ 'cx> {
{
match (&(token_tree.len()), &(3)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["assertion failed: `(left == right)` (left: `",
"`, right: `",
"`)"];
__STATIC_FMTSTR
},
&match (&left_val,
&right_val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/diagnostics/plugin.rs",
159u32);
&_FILE_LINE
})
}
}
}
}
};
let (crate_name, name) =
match (&token_tree[0], &token_tree[2]) {
(&TokenTree::Token(_, token::Ident(ref crate_name, _)),
&TokenTree::Token(_, token::Ident(ref name, _))) =>
(*&crate_name, name),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/diagnostics/plugin.rs",
167u32);
&_FILE_LINE
})
}
}
};
let target_triple =
env::var("CFG_COMPILER_HOST_TRIPLE").ok().expect("unable to determine target arch from $CFG_COMPILER_HOST_TRIPLE");
with_registered_diagnostics(|diagnostics| {
if let Err(e) =
output_metadata(ecx,
&target_triple,
&crate_name.name.as_str(),
&diagnostics) {
ecx.span_bug(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["error writing metadata for triple `",
"` and crate `",
"`, error: ",
", cause: "];
__STATIC_FMTSTR
},
&match (&target_triple,
&crate_name,
&e.description(),
&e.cause())
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Debug::fmt)],
})));
} });
let (count, expr) =
with_registered_diagnostics(|diagnostics| {
let descriptions:
Vec<P<ast::Expr>> =
diagnostics.iter().filter_map(|(code,
info)|
{
info.description.map(|description|
{
ecx.expr_tuple(span,
<[_]>::into_vec(::std::boxed::Box::new([ecx.expr_str(span,
code.as_str()),
ecx.expr_str(span,
description.as_str())])))
})
}).collect();
(descriptions.len(),
ecx.expr_vec(span, descriptions))
});
let static_ = ecx.lifetime(span, ecx.name_of("\'static"));
let ty_str =
ecx.ty_rptr(span, ecx.ty_ident(span, ecx.ident_of("str")),
Some(static_), ast::MutImmutable);
let ty =
ecx.ty(span,
ast::TyFixedLengthVec(ecx.ty(span,
ast::TyTup(<[_]>::into_vec(::std::boxed::Box::new([ty_str.clone(),
ty_str])))),
ecx.expr_usize(span, count)));
MacEager::items(SmallVector::many(<[_]>::into_vec(::std::boxed::Box::new([P(ast::Item{ident:
name.clone(),
attrs:
Vec::new(),
id:
ast::DUMMY_NODE_ID,
node:
ast::ItemConst(ty,
expr),
vis:
ast::Public,
span:
span,})]))))
}
}
pub mod registry {
#[prelude_import]
use std::prelude::v1::*;
use std::collections::HashMap;
pub struct Registry {
descriptions: HashMap<&'static str, &'static str>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Registry {
#[inline]
fn clone(&self) -> Registry {
match *self {
Registry { descriptions: ref __self_0_0 } =>
Registry{descriptions:
::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
impl Registry {
pub fn new(descriptions: &[(&'static str, &'static str)])
-> Registry {
Registry{descriptions:
descriptions.iter().cloned().collect(),}
}
pub fn find_description(&self, code: &str)
-> Option<&'static str> {
self.descriptions.get(code).cloned()
}
}
}
pub mod metadata {
//! This module contains utilities for outputting metadata for diagnostic errors.
//!
//! Each set of errors is mapped to a metadata file by a name, which is
//! currently always a crate name.
#[prelude_import]
use std::prelude::v1::*;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::fs::{remove_file, create_dir_all, File};
use std::io::Write;
use std::error::Error;
use rustc_serialize::json::as_json;
use codemap::Span;
use ext::base::ExtCtxt;
use diagnostics::plugin::{ErrorMap, ErrorInfo};
const ERROR_METADATA_PREFIX: &'static str = "tmp/extended-errors";
/// JSON encodable/decodable version of `ErrorInfo`.
pub struct ErrorMetadata {
pub description: Option<String>,
pub use_site: Option<ErrorLocation>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ErrorMetadata {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ErrorMetadata {
description: ref __self_0_0, use_site: ref __self_0_1 } =>
__arg_0.emit_struct("ErrorMetadata", 2usize, |_e| -> _ {
match _e.emit_struct_field("description",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("use_site",
1usize,
|_e| -> _
{
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ErrorMetadata {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ErrorMetadata, __D::Error> {
__arg_0.read_struct("ErrorMetadata", 2usize, |_d| -> _ {
::std::result::Result::Ok(ErrorMetadata{description:
match _d.read_struct_field("description",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
use_site:
match _d.read_struct_field("use_site",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ErrorMetadata {
#[inline]
fn eq(&self, __arg_0: &ErrorMetadata) -> bool {
match *__arg_0 {
ErrorMetadata {
description: ref __self_1_0, use_site: ref __self_1_1 } =>
match *self {
ErrorMetadata {
description: ref __self_0_0, use_site: ref __self_0_1
} =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ErrorMetadata) -> bool {
match *__arg_0 {
ErrorMetadata {
description: ref __self_1_0, use_site: ref __self_1_1 } =>
match *self {
ErrorMetadata {
description: ref __self_0_0, use_site: ref __self_0_1
} =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
/// Mapping from error codes to metadata that can be (de)serialized.
pub type ErrorMetadataMap = BTreeMap<String, ErrorMetadata>;
/// JSON encodable error location type with filename and line number.
pub struct ErrorLocation {
pub filename: String,
pub line: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ErrorLocation {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ErrorLocation {
filename: ref __self_0_0, line: ref __self_0_1 } =>
__arg_0.emit_struct("ErrorLocation", 2usize, |_e| -> _ {
match _e.emit_struct_field("filename",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("line",
1usize,
|_e| -> _
{
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ErrorLocation {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ErrorLocation, __D::Error> {
__arg_0.read_struct("ErrorLocation", 2usize, |_d| -> _ {
::std::result::Result::Ok(ErrorLocation{filename:
match _d.read_struct_field("filename",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
line:
match _d.read_struct_field("line",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ErrorLocation {
#[inline]
fn eq(&self, __arg_0: &ErrorLocation) -> bool {
match *__arg_0 {
ErrorLocation {
filename: ref __self_1_0, line: ref __self_1_1 } =>
match *self {
ErrorLocation {
filename: ref __self_0_0, line: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ErrorLocation) -> bool {
match *__arg_0 {
ErrorLocation {
filename: ref __self_1_0, line: ref __self_1_1 } =>
match *self {
ErrorLocation {
filename: ref __self_0_0, line: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
impl ErrorLocation {
/// Create an error location from a span.
pub fn from_span(ecx: &ExtCtxt, sp: Span) -> ErrorLocation {
let loc = ecx.codemap().lookup_char_pos_adj(sp.lo);
ErrorLocation{filename: loc.filename, line: loc.line,}
}
}
/// Get the directory where metadata for a given `prefix` should be stored.
///
/// See `output_metadata`.
pub fn get_metadata_dir(prefix: &str) -> PathBuf {
PathBuf::from(ERROR_METADATA_PREFIX).join(prefix)
}
/// Map `name` to a path in the given directory: <directory>/<name>.json
fn get_metadata_path(directory: PathBuf, name: &str) -> PathBuf {
directory.join(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
".json"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
/// Write metadata for the errors in `err_map` to disk, to a file corresponding to `prefix/name`.
///
/// For our current purposes the prefix is the target architecture and the name is a crate name.
/// If an error occurs steps will be taken to ensure that no file is created.
pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str,
err_map: &ErrorMap) -> Result<(), Box<Error>> {
let metadata_dir = get_metadata_dir(prefix);
match create_dir_all(&metadata_dir) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let metadata_path = get_metadata_path(metadata_dir, name);
let mut metadata_file =
match File::create(&metadata_path) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let json_map =
err_map.iter().map(|(k, &ErrorInfo { description, use_site })|
{ let key = k.as_str().to_string();
let value =
ErrorMetadata{description:
description.map(|n|
n.as_str().to_string()),
use_site:
use_site.map(|sp|
ErrorLocation::from_span(ecx,
sp)),};
(key, value)
}).collect::<ErrorMetadataMap>();
let result =
&mut metadata_file.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&as_json(&json_map),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
if result.is_err() {
match remove_file(&metadata_path) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(match result {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
}
}
}
pub mod errors {
#[prelude_import]
use std::prelude::v1::*;
pub use errors::emitter::ColorConfig;
use self::Level::*;
use self::RenderSpan::*;
use codemap::{self, Span};
use diagnostics;
use errors::emitter::{Emitter, EmitterWriter};
use std::cell::{RefCell, Cell};
use std::{error, fmt};
use std::io::prelude::*;
use std::rc::Rc;
use term;
pub mod emitter {
#[prelude_import]
use std::prelude::v1::*;
use self::Destination::*;
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
use diagnostics;
use errors::{Level, RenderSpan, DiagnosticBuilder};
use errors::RenderSpan::*;
use errors::Level::*;
use std::{cmp, fmt};
use std::io::prelude::*;
use std::io;
use std::rc::Rc;
use term;
pub trait Emitter {
fn emit(&mut self, span: Option<Span>, msg: &str,
code: Option<&str>, lvl: Level);
fn custom_emit(&mut self, sp: RenderSpan, msg: &str, lvl: Level);
/// Emit a structured diagnostic.
fn emit_struct(&mut self, db: &DiagnosticBuilder) {
self.emit(db.span, &db.message,
db.code.as_ref().map(|s| &**s), db.level);
for child in &db.children {
match child.render_span {
Some(ref sp) =>
self.custom_emit(sp.clone(), &child.message,
child.level),
None =>
self.emit(child.span, &child.message, None,
child.level),
}
}
}
}
/// maximum number of lines we will print for each error; arbitrary.
const MAX_LINES: usize = 6;
pub enum ColorConfig { Auto, Always, Never, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ColorConfig { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ColorConfig {
#[inline]
fn clone(&self) -> ColorConfig {
match (&*self,) {
(&ColorConfig::Auto,) => ColorConfig::Auto,
(&ColorConfig::Always,) => ColorConfig::Always,
(&ColorConfig::Never,) => ColorConfig::Never,
}
}
}
impl ColorConfig {
fn use_color(&self) -> bool {
match *self {
ColorConfig::Always => true,
ColorConfig::Never => false,
ColorConfig::Auto => stderr_isatty(),
}
}
}
/// A basic emitter for when we don't have access to a codemap or registry. Used
/// for reporting very early errors, etc.
pub struct BasicEmitter {
dst: Destination,
}
impl Emitter for BasicEmitter {
fn emit(&mut self, sp: Option<Span>, msg: &str,
code: Option<&str>, lvl: Level) {
if !sp.is_none() {
{
::std::rt::begin_unwind("BasicEmitter can\'t handle spans",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/emitter.rs",
75u32);
&_FILE_LINE
})
}
};
if let Err(e) =
print_diagnostic(&mut self.dst, "", lvl, msg, code) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["failed to print diagnostics: "];
__STATIC_FMTSTR
},
&match (&e,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/errors/emitter.rs",
77u32);
&_FILE_LINE
})
};
}
}
fn custom_emit(&mut self, _: RenderSpan, _: &str, _: Level) {
{
::std::rt::begin_unwind("BasicEmitter can\'t handle custom_emit",
{
static _FILE_LINE:
(&'static str, u32) =
("src/errors/emitter.rs",
83u32);
&_FILE_LINE
})
};
}
}
impl BasicEmitter {
pub fn stderr(color_config: ColorConfig) -> BasicEmitter {
if color_config.use_color() {
let dst = Destination::from_stderr();
BasicEmitter{dst: dst,}
} else { BasicEmitter{dst: Raw(Box::new(io::stderr())),} }
}
}
pub struct EmitterWriter {
dst: Destination,
registry: Option<diagnostics::registry::Registry>,
cm: Rc<codemap::CodeMap>,
}
impl Emitter for EmitterWriter {
fn emit(&mut self, sp: Option<Span>, msg: &str,
code: Option<&str>, lvl: Level) {
let error =
match sp {
Some(COMMAND_LINE_SP) =>
self.emit_(FileLine(COMMAND_LINE_SP), msg, code, lvl),
Some(sp) => self.emit_(FullSpan(sp), msg, code, lvl),
None =>
print_diagnostic(&mut self.dst, "", lvl, msg, code),
};
if let Err(e) = error {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["failed to print diagnostics: "];
__STATIC_FMTSTR
},
&match (&e,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/errors/emitter.rs",
117u32);
&_FILE_LINE
})
};
}
}
fn custom_emit(&mut self, sp: RenderSpan, msg: &str, lvl: Level) {
if let Err(e) = self.emit_(sp, msg, None, lvl) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["failed to print diagnostics: "];
__STATIC_FMTSTR
},
&match (&e,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/errors/emitter.rs",
126u32);
&_FILE_LINE
})
};
}
}
}
impl EmitterWriter {
pub fn stderr(color_config: ColorConfig,
registry: Option<diagnostics::registry::Registry>,
code_map: Rc<codemap::CodeMap>) -> EmitterWriter {
if color_config.use_color() {
let dst = Destination::from_stderr();
EmitterWriter{dst: dst, registry: registry, cm: code_map,}
} else {
EmitterWriter{dst: Raw(Box::new(io::stderr())),
registry: registry,
cm: code_map,}
}
}
pub fn new(dst: Box<Write+ Send>,
registry: Option<diagnostics::registry::Registry>,
code_map: Rc<codemap::CodeMap>) -> EmitterWriter {
EmitterWriter{dst: Raw(dst),
registry: registry,
cm: code_map,}
}
fn emit_(&mut self, rsp: RenderSpan, msg: &str,
code: Option<&str>, lvl: Level) -> io::Result<()> {
let sp = rsp.span();
let ss =
if sp.expn_id == COMMAND_LINE_EXPN {
"<command line option>".to_string()
} else if let EndSpan(_) = rsp {
let span_end =
Span{lo: sp.hi, hi: sp.hi, expn_id: sp.expn_id,};
self.cm.span_to_string(span_end)
} else { self.cm.span_to_string(sp) };
match print_diagnostic(&mut self.dst, &ss[..], lvl, msg, code)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match rsp {
FullSpan(_) => {
let lines = self.cm.span_to_lines(sp);
match self.highlight_lines(sp, lvl, lines) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_macro_backtrace(sp) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
EndSpan(_) => {
let lines = self.cm.span_to_lines(sp);
match self.end_highlight_lines(sp, lvl, lines) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_macro_backtrace(sp) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Suggestion(_, ref suggestion) => {
match self.highlight_suggestion(sp, suggestion) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_macro_backtrace(sp) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
FileLine(..) => { }
}
match code {
Some(code) =>
match self.registry.as_ref().and_then(|registry|
registry.find_description(code))
{
Some(_) => {
match print_diagnostic(&mut self.dst, &ss[..],
Help,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["run `rustc --explain ",
"` to see a detailed explanation"];
__STATIC_FMTSTR
},
&match (&code,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
None => (),
},
None => (),
}
Ok(())
}
fn highlight_suggestion(&mut self, sp: Span, suggestion: &str)
-> io::Result<()> {
let lines = self.cm.span_to_lines(sp).unwrap();
if !!lines.lines.is_empty() {
{
::std::rt::begin_unwind("assertion failed: !lines.lines.is_empty()",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/emitter.rs",
227u32);
&_FILE_LINE
})
}
};
let fm = &lines.file;
let first_line = &lines.lines[0];
let prefix =
fm.get_line(first_line.line_index).map(|l|
&l[..first_line.start_col.0]).unwrap_or("");
let last_line = lines.lines.last().unwrap();
let suffix =
fm.get_line(last_line.line_index).map(|l|
&l[last_line.end_col.0..]).unwrap_or("");
let complete =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"",
""];
__STATIC_FMTSTR
},
&match (&prefix,
&suggestion,
&suffix)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}));
let fm = &*lines.file;
let mut lines = complete.lines();
for (line, line_index) in
lines.by_ref().take(MAX_LINES).zip(first_line.line_index..)
{
let elided_line_num =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&(line_index
+
1),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" ",
"\n"];
__STATIC_FMTSTR
},
&match (&fm.name,
&"",
&elided_line_num.len(),
&line)
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::from_usize(__arg2),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Param(2usize),},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(3usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if lines.next().is_some() {
let elided_line_num =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&(first_line.line_index
+
MAX_LINES
+
1),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" ",
" ...\n"];
__STATIC_FMTSTR
},
&match (&"",
&fm.name.len(),
&elided_line_num.len())
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::from_usize(__arg1),
::std::fmt::ArgumentV1::from_usize(__arg2)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Param(1usize),},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Param(2usize),},}];
__STATIC_FMTARGS
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
fn highlight_lines(&mut self, sp: Span, lvl: Level,
lines: codemap::FileLinesResult)
-> io::Result<()> {
let lines =
match lines {
Ok(lines) => lines,
Err(_) => {
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["(internal compiler error: unprintable span)\n"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
return Ok(());
}
};
let fm = &*lines.file;
let line_strings: Option<Vec<&str>> =
lines.lines.iter().map(|info|
fm.get_line(info.line_index)).collect();
let line_strings =
match line_strings {
None => { return Ok(()); }
Some(line_strings) => line_strings,
};
let all_lines = lines.lines.len();
let display_lines = cmp::min(all_lines, MAX_LINES);
let display_line_infos = &lines.lines[..display_lines];
let display_line_strings = &line_strings[..display_lines];
if !(display_line_infos.len() > 0) {
{
::std::rt::begin_unwind("assertion failed: display_line_infos.len() > 0",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/emitter.rs",
300u32);
&_FILE_LINE
})
}
};
let mut max_line_num =
display_line_infos[display_line_infos.len() -
1].line_index + 1;
let mut digits = 0;
while max_line_num > 0 { max_line_num /= 10; digits += 1; }
for (line_info, line) in
display_line_infos.iter().zip(display_line_strings) {
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" ",
"\n"];
__STATIC_FMTSTR
},
&match (&fm.name,
&(line_info.line_index
+
1),
&line,
&digits)
{
(__arg0,
__arg1,
__arg2,
__argwidth)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::from_usize(__argwidth)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::Next,
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::Next,
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Right,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Param(3usize),},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::Next,
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if display_lines < all_lines {
let last_line_index =
display_line_infos.last().unwrap().line_index;
let s =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" "];
__STATIC_FMTSTR
},
&match (&fm.name,
&(last_line_index
+
1))
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"...\n"];
__STATIC_FMTSTR
},
&match (&"",
&s.len())
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::from_usize(__arg1)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Param(1usize),},}];
__STATIC_FMTARGS
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if lines.lines.len() == 1 {
let lo = self.cm.lookup_char_pos(sp.lo);
let mut digits = 0;
let mut num = (lines.lines[0].line_index + 1) / 10;
while num > 0 { num /= 10; digits += 1; }
let mut s = String::new();
let skip = fm.name.chars().count() + digits + 3;
for _ in 0..skip { s.push(' '); }
if let Some(orig) = fm.get_line(lines.lines[0].line_index)
{
let mut col = skip;
let mut lastc = ' ';
let mut iter = orig.chars().enumerate();
for (pos, ch) in iter.by_ref() {
lastc = ch;
if pos >= lo.col.to_usize() { break ; }
match ch {
'\t' => { col += 8 - col % 8; s.push('\t'); }
_ => { col += 1; s.push(' '); }
}
}
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut s = String::from("^");
let count =
match lastc { '\t' => 8 - col % 8, _ => 1, };
col += count;
s.extend(::std::iter::repeat('~').take(count));
let hi = self.cm.lookup_char_pos(sp.hi);
if hi.col != lo.col {
for (pos, ch) in iter {
if pos >= hi.col.to_usize() { break ; }
let count =
match ch { '\t' => 8 - col % 8, _ => 1, };
col += count;
s.extend(::std::iter::repeat('~').take(count));
}
}
if s.len() > 1 { s.pop(); }
match &mut self.dst.print_maybe_styled(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
term::Attr::ForegroundColor(lvl.color()),
true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
Ok(())
}
/// Here are the differences between this and the normal `highlight_lines`:
/// `end_highlight_lines` will always put arrow on the last byte of the
/// span (instead of the first byte). Also, when the span is too long (more
/// than 6 lines), `end_highlight_lines` will print the first line, then
/// dot dot dot, then last line, whereas `highlight_lines` prints the first
/// six lines.
#[allow(deprecated)]
fn end_highlight_lines(&mut self, sp: Span, lvl: Level,
lines: codemap::FileLinesResult)
-> io::Result<()> {
let lines =
match lines {
Ok(lines) => lines,
Err(_) => {
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["(internal compiler error: unprintable span)\n"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
return Ok(());
}
};
let fm = &*lines.file;
let lines = &lines.lines[..];
if lines.len() > MAX_LINES {
if let Some(line) = fm.get_line(lines[0].line_index) {
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" ",
"\n"];
__STATIC_FMTSTR
},
&match (&fm.name,
&(lines[0].line_index
+
1),
&line)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["...\n"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_line_index = lines[lines.len() - 1].line_index;
if let Some(last_line) = fm.get_line(last_line_index) {
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" ",
"\n"];
__STATIC_FMTSTR
},
&match (&fm.name,
&(last_line_index
+
1),
&last_line)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
} else {
for line_info in lines {
if let Some(line) = fm.get_line(line_info.line_index)
{
match &mut self.dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" ",
"\n"];
__STATIC_FMTSTR
},
&match (&fm.name,
&(line_info.line_index
+
1),
&line)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
let last_line_start =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
" "];
__STATIC_FMTSTR
},
&match (&fm.name,
&(lines[lines.len()
-
1].line_index
+
1))
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
let hi = self.cm.lookup_char_pos(sp.hi);
let skip = last_line_start.chars().count();
let mut s = String::new();
for _ in 0..skip { s.push(' '); }
if let Some(orig) = fm.get_line(lines[0].line_index) {
let iter = orig.chars().enumerate();
for (pos, ch) in iter {
if pos >= hi.col.to_usize() - 1 { break ; }
match ch { '\t' => s.push('\t'), _ => s.push(' '), }
}
}
s.push('^');
&mut self.dst.print_maybe_styled(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
term::Attr::ForegroundColor(lvl.color()),
true)
}
fn print_macro_backtrace(&mut self, sp: Span) -> io::Result<()> {
let mut last_span = codemap::DUMMY_SP;
let mut span = sp;
loop {
let span_name_span =
self.cm.with_expn_info(span.expn_id, |expn_info| {
expn_info.map(|ei| {
let (pre, post) =
match ei.callee.format
{
codemap::MacroAttribute(..)
=>
("#[",
"]"),
codemap::MacroBang(..)
=>
("",
"!"),
};
let macro_decl_name =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["in this expansion of ",
"",
""];
__STATIC_FMTSTR
},
&match (&pre,
&ei.callee.name(),
&post)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}));
let def_site_span =
ei.callee.span;
(ei.call_site,
macro_decl_name,
def_site_span)
}) });
let (macro_decl_name, def_site_span) =
match span_name_span {
None => break ,
Some((sp, macro_decl_name, def_site_span)) => {
span = sp;
(macro_decl_name, def_site_span)
}
};
if span != last_span {
let mut diag_string = macro_decl_name;
if let Some(def_site_span) = def_site_span {
diag_string.push_str(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[" (defined in ",
")"];
__STATIC_FMTSTR
},
&match (&self.cm.span_to_filename(def_site_span),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
let snippet = self.cm.span_to_string(span);
match print_diagnostic(&mut self.dst, &snippet, Note,
&diag_string, None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
last_span = span;
}
Ok(())
}
}
fn print_diagnostic(dst: &mut Destination, topic: &str, lvl: Level,
msg: &str, code: Option<&str>) -> io::Result<()> {
if !topic.is_empty() {
match dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" "];
__STATIC_FMTSTR
},
&match (&topic,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match dst.print_maybe_styled(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
": "];
__STATIC_FMTSTR
},
&match (&lvl.to_string(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
term::Attr::ForegroundColor(lvl.color()),
false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match dst.print_maybe_styled(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&msg,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
term::Attr::Bold, false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match code {
Some(code) => {
let style =
term::Attr::ForegroundColor(term::color::BRIGHT_MAGENTA);
match dst.print_maybe_styled(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[" [",
"]"];
__STATIC_FMTSTR
},
&match (&code.clone(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
style, false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
None => (),
}
match dst.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\n"];
__STATIC_FMTSTR
},
&match () {
() => [],
})) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(())
}
#[cfg(unix)]
fn stderr_isatty() -> bool {
use libc;
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
}
enum Destination {
Terminal(Box<term::StderrTerminal>),
Raw(Box<Write+ Send>),
}
impl Destination {
fn from_stderr() -> Destination {
match term::stderr() {
Some(t) => Terminal(t),
None => Raw(Box::new(io::stderr())),
}
}
fn print_maybe_styled(&mut self, args: fmt::Arguments,
color: term::Attr,
print_newline_at_end: bool)
-> io::Result<()> {
match *self {
Terminal(ref mut t) => {
match t.attr(color) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match t.write_fmt(args) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match t.reset() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if print_newline_at_end {
t.write_all(b"\n")
} else { Ok(()) }
}
Raw(ref mut w) => {
match w.write_fmt(args) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if print_newline_at_end {
w.write_all(b"\n")
} else { Ok(()) }
}
}
}
}
impl Write for Destination {
fn write(&mut self, bytes: &[u8]) -> io::Result<usize> {
match *self {
Terminal(ref mut t) => t.write(bytes),
Raw(ref mut w) => w.write(bytes),
}
}
fn flush(&mut self) -> io::Result<()> {
match *self {
Terminal(ref mut t) => t.flush(),
Raw(ref mut w) => w.flush(),
}
}
}
}
pub enum RenderSpan {
/// A FullSpan renders with both with an initial line for the
/// message, prefixed by file:linenum, followed by a summary of
/// the source code covered by the span.
FullSpan(Span),
/// Similar to a FullSpan, but the cited position is the end of
/// the span, instead of the start. Used, at least, for telling
/// compiletest/runtest to look at the last line of the span
/// (since `end_highlight_lines` displays an arrow to the end
/// of the span).
EndSpan(Span),
/// A suggestion renders with both with an initial line for the
/// message, prefixed by file:linenum, followed by a summary
/// of hypothetical source code, where the `String` is spliced
/// into the lines in place of the code covered by the span.
Suggestion(Span, String),
/// A FileLine renders with just a line for the message prefixed
/// by file:linenum.
FileLine(Span),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for RenderSpan {
#[inline]
fn clone(&self) -> RenderSpan {
match (&*self,) {
(&RenderSpan::FullSpan(ref __self_0),) =>
RenderSpan::FullSpan(::std::clone::Clone::clone(&(*__self_0))),
(&RenderSpan::EndSpan(ref __self_0),) =>
RenderSpan::EndSpan(::std::clone::Clone::clone(&(*__self_0))),
(&RenderSpan::Suggestion(ref __self_0, ref __self_1),) =>
RenderSpan::Suggestion(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&RenderSpan::FileLine(ref __self_0),) =>
RenderSpan::FileLine(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl RenderSpan {
fn span(&self) -> Span {
match *self {
FullSpan(s) | Suggestion(s, _) | EndSpan(s) | FileLine(s) =>
s,
}
}
}
/// Used as a return value to signify a fatal error occurred. (It is also
/// used as the argument to panic at the moment, but that will eventually
/// not be true.)
#[must_use]
pub struct FatalError;
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for FatalError {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
FatalError => {
let mut builder = __arg_0.debug_tuple("FatalError");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for FatalError {
#[inline]
fn clone(&self) -> FatalError {
match *self { FatalError => FatalError, }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for FatalError { }
impl fmt::Display for FatalError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parser fatal error"];
__STATIC_FMTSTR
},
&match () {
() => [],
}))
}
}
impl error::Error for FatalError {
fn description(&self) -> &str {
"The parser has encountered a fatal error"
}
}
/// Signifies that the compiler died with an explicit call to `.bug`
/// or `.span_bug` rather than a failed assertion, etc.
pub struct ExplicitBug;
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ExplicitBug {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ExplicitBug => {
let mut builder = __arg_0.debug_tuple("ExplicitBug");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ExplicitBug {
#[inline]
fn clone(&self) -> ExplicitBug {
match *self { ExplicitBug => ExplicitBug, }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ExplicitBug { }
impl fmt::Display for ExplicitBug {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parser internal bug"];
__STATIC_FMTSTR
},
&match () {
() => [],
}))
}
}
impl error::Error for ExplicitBug {
fn description(&self) -> &str {
"The parser has encountered an internal bug"
}
}
/// Used for emitting structured error messages and other diagnostic information.
#[must_use]
pub struct DiagnosticBuilder<'a> {
emitter: &'a RefCell<Box<Emitter>>,
level: Level,
message: String,
code: Option<String>,
span: Option<Span>,
children: Vec<SubDiagnostic>,
}
/// For example a note attached to an error.
struct SubDiagnostic {
level: Level,
message: String,
span: Option<Span>,
render_span: Option<RenderSpan>,
}
impl <'a> DiagnosticBuilder<'a> {
/// Emit the diagnostic.
pub fn emit(&mut self) {
if self.cancelled() { return; }
self.emitter.borrow_mut().emit_struct(&self);
self.cancel();
}
/// Cancel the diagnostic (a structured diagnostic must either be emitted or
/// cancelled or it will panic when dropped).
/// BEWARE: if this DiagnosticBuilder is an error, then creating it will
/// bump the error count on the Handler and cancelling it won't undo that.
/// If you want to decrement the error count you should use `Handler::cancel`.
pub fn cancel(&mut self) { self.level = Level::Cancelled; }
pub fn cancelled(&self) -> bool { self.level == Level::Cancelled }
pub fn is_fatal(&self) -> bool { self.level == Level::Fatal }
pub fn note(&mut self, msg: &str) -> &mut DiagnosticBuilder<'a> {
self.sub(Level::Note, msg, None, None);
self
}
pub fn span_note(&mut self, sp: Span, msg: &str)
-> &mut DiagnosticBuilder<'a> {
self.sub(Level::Note, msg, Some(sp), None);
self
}
pub fn help(&mut self, msg: &str) -> &mut DiagnosticBuilder<'a> {
self.sub(Level::Help, msg, None, None);
self
}
pub fn span_help(&mut self, sp: Span, msg: &str)
-> &mut DiagnosticBuilder<'a> {
self.sub(Level::Help, msg, Some(sp), None);
self
}
/// Prints out a message with a suggested edit of the code.
///
/// See `diagnostic::RenderSpan::Suggestion` for more information.
pub fn span_suggestion(&mut self, sp: Span, msg: &str,
suggestion: String)
-> &mut DiagnosticBuilder<'a> {
self.sub(Level::Help, msg, Some(sp),
Some(Suggestion(sp, suggestion)));
self
}
pub fn span_end_note(&mut self, sp: Span, msg: &str)
-> &mut DiagnosticBuilder<'a> {
self.sub(Level::Note, msg, Some(sp), Some(EndSpan(sp)));
self
}
pub fn fileline_note(&mut self, sp: Span, msg: &str)
-> &mut DiagnosticBuilder<'a> {
self.sub(Level::Note, msg, Some(sp), Some(FileLine(sp)));
self
}
pub fn fileline_help(&mut self, sp: Span, msg: &str)
-> &mut DiagnosticBuilder<'a> {
self.sub(Level::Help, msg, Some(sp), Some(FileLine(sp)));
self
}
pub fn span(&mut self, sp: Span) -> &mut Self {
self.span = Some(sp);
self
}
pub fn code(&mut self, s: String) -> &mut Self {
self.code = Some(s);
self
}
/// Convenience function for internal use, clients should use one of the
/// struct_* methods on Handler.
fn new(emitter: &'a RefCell<Box<Emitter>>, level: Level,
message: &str) -> DiagnosticBuilder<'a> {
DiagnosticBuilder{emitter: emitter,
level: level,
message: message.to_owned(),
code: None,
span: None,
children:
<[_]>::into_vec(::std::boxed::Box::new([])),}
}
/// Convenience function for internal use, clients should use one of the
/// public methods above.
fn sub(&mut self, level: Level, message: &str, span: Option<Span>,
render_span: Option<RenderSpan>) {
let sub =
SubDiagnostic{level: level,
message: message.to_owned(),
span: span,
render_span: render_span,};
self.children.push(sub);
}
}
impl <'a> fmt::Debug for DiagnosticBuilder<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.message.fmt(f)
}
}
/// Destructor bomb - a DiagnosticBuilder must be either emitted or cancelled or
/// we emit a bug.
impl <'a> Drop for DiagnosticBuilder<'a> {
fn drop(&mut self) {
if !self.cancelled() {
self.emitter.borrow_mut().emit(None,
"Error constructed but not emitted",
None, Bug);
{
{
::std::rt::begin_unwind("explicit panic",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/mod.rs",
261u32);
&_FILE_LINE
})
}
};
}
}
}
/// A handler deals with errors; certain errors
/// (fatal, bug, unimpl) may cause immediate exit,
/// others log errors for later reporting.
pub struct Handler {
err_count: Cell<usize>,
emit: RefCell<Box<Emitter>>,
pub can_emit_warnings: bool,
treat_err_as_bug: bool,
delayed_span_bug: RefCell<Option<(codemap::Span, String)>>,
}
impl Handler {
pub fn new(color_config: ColorConfig,
registry: Option<diagnostics::registry::Registry>,
can_emit_warnings: bool, treat_err_as_bug: bool,
cm: Rc<codemap::CodeMap>) -> Handler {
let emitter =
Box::new(EmitterWriter::stderr(color_config, registry, cm));
Handler::with_emitter(can_emit_warnings, treat_err_as_bug,
emitter)
}
pub fn with_emitter(can_emit_warnings: bool, treat_err_as_bug: bool,
e: Box<Emitter>) -> Handler {
Handler{err_count: Cell::new(0),
emit: RefCell::new(e),
can_emit_warnings: can_emit_warnings,
treat_err_as_bug: treat_err_as_bug,
delayed_span_bug: RefCell::new(None),}
}
pub fn struct_dummy<'a>(&'a self) -> DiagnosticBuilder<'a> {
DiagnosticBuilder::new(&self.emit, Level::Cancelled, "")
}
pub fn struct_span_warn<'a>(&'a self, sp: Span, msg: &str)
-> DiagnosticBuilder<'a> {
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Warning, msg);
result.span(sp);
if !self.can_emit_warnings { result.cancel(); }
result
}
pub fn struct_span_warn_with_code<'a>(&'a self, sp: Span, msg: &str,
code: &str)
-> DiagnosticBuilder<'a> {
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Warning, msg);
result.span(sp);
result.code(code.to_owned());
if !self.can_emit_warnings { result.cancel(); }
result
}
pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Warning, msg);
if !self.can_emit_warnings { result.cancel(); }
result
}
pub fn struct_span_err<'a>(&'a self, sp: Span, msg: &str)
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Error, msg);
result.span(sp);
result
}
pub fn struct_span_err_with_code<'a>(&'a self, sp: Span, msg: &str,
code: &str)
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Error, msg);
result.span(sp);
result.code(code.to_owned());
result
}
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
self.bump_err_count();
DiagnosticBuilder::new(&self.emit, Level::Error, msg)
}
pub fn struct_span_fatal<'a>(&'a self, sp: Span, msg: &str)
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Fatal, msg);
result.span(sp);
result
}
pub fn struct_span_fatal_with_code<'a>(&'a self, sp: Span, msg: &str,
code: &str)
-> DiagnosticBuilder<'a> {
self.bump_err_count();
let mut result =
DiagnosticBuilder::new(&self.emit, Level::Fatal, msg);
result.span(sp);
result.code(code.to_owned());
result
}
pub fn struct_fatal<'a>(&'a self, msg: &str)
-> DiagnosticBuilder<'a> {
self.bump_err_count();
DiagnosticBuilder::new(&self.emit, Level::Fatal, msg)
}
pub fn cancel(&mut self, err: &mut DiagnosticBuilder) {
if err.level == Level::Error || err.level == Level::Fatal {
if !self.has_errors() {
{
::std::rt::begin_unwind("assertion failed: self.has_errors()",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/mod.rs",
386u32);
&_FILE_LINE
})
}
};
self.err_count.set(self.err_count.get() + 1);
}
err.cancel();
}
pub fn span_fatal(&self, sp: Span, msg: &str) -> FatalError {
if self.treat_err_as_bug { self.span_bug(sp, msg); }
self.emit(Some(sp), msg, Fatal);
self.bump_err_count();
return FatalError;
}
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str)
-> FatalError {
if self.treat_err_as_bug { self.span_bug(sp, msg); }
self.emit_with_code(Some(sp), msg, code, Fatal);
self.bump_err_count();
return FatalError;
}
pub fn span_err(&self, sp: Span, msg: &str) {
if self.treat_err_as_bug { self.span_bug(sp, msg); }
self.emit(Some(sp), msg, Error);
self.bump_err_count();
}
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
if self.treat_err_as_bug { self.span_bug(sp, msg); }
self.emit_with_code(Some(sp), msg, code, Error);
self.bump_err_count();
}
pub fn span_warn(&self, sp: Span, msg: &str) {
self.emit(Some(sp), msg, Warning);
}
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
self.emit_with_code(Some(sp), msg, code, Warning);
}
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
self.emit(Some(sp), msg, Bug);
{
::std::rt::begin_unwind(ExplicitBug,
{
static _FILE_LINE:
(&'static str, u32) =
("src/errors/mod.rs", 430u32);
&_FILE_LINE
})
};
}
pub fn delay_span_bug(&self, sp: Span, msg: &str) {
let mut delayed = self.delayed_span_bug.borrow_mut();
*delayed = Some((sp, msg.to_string()));
}
pub fn span_bug_no_panic(&self, sp: Span, msg: &str) {
self.emit(Some(sp), msg, Bug);
self.bump_err_count();
}
pub fn span_note_without_error(&self, sp: Span, msg: &str) {
self.emit.borrow_mut().emit(Some(sp), msg, None, Note);
}
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
self.span_bug(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unimplemented "];
__STATIC_FMTSTR
},
&match (&msg,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
pub fn fatal(&self, msg: &str) -> FatalError {
if self.treat_err_as_bug { self.bug(msg); }
self.emit.borrow_mut().emit(None, msg, None, Fatal);
self.bump_err_count();
FatalError
}
pub fn err(&self, msg: &str) {
if self.treat_err_as_bug { self.bug(msg); }
self.emit.borrow_mut().emit(None, msg, None, Error);
self.bump_err_count();
}
pub fn warn(&self, msg: &str) {
self.emit.borrow_mut().emit(None, msg, None, Warning);
}
pub fn note_without_error(&self, msg: &str) {
self.emit.borrow_mut().emit(None, msg, None, Note);
}
pub fn bug(&self, msg: &str) -> ! {
self.emit.borrow_mut().emit(None, msg, None, Bug);
{
::std::rt::begin_unwind(ExplicitBug,
{
static _FILE_LINE:
(&'static str, u32) =
("src/errors/mod.rs", 469u32);
&_FILE_LINE
})
};
}
pub fn unimpl(&self, msg: &str) -> ! {
self.bug(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unimplemented "];
__STATIC_FMTSTR
},
&match (&msg,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
pub fn bump_err_count(&self) {
self.err_count.set(self.err_count.get() + 1);
}
pub fn err_count(&self) -> usize { self.err_count.get() }
pub fn has_errors(&self) -> bool { self.err_count.get() > 0 }
pub fn abort_if_errors(&self) {
let s;
match self.err_count.get() {
0 => {
let delayed_bug = self.delayed_span_bug.borrow();
match *delayed_bug {
Some((span, ref errmsg)) => {
self.span_bug(span, errmsg);
}
_ => { }
}
return;
}
1 => s = "aborting due to previous error".to_string(),
_ => {
s =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["aborting due to ",
" previous errors"];
__STATIC_FMTSTR
},
&match (&self.err_count.get(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
}
}
{
::std::rt::begin_unwind(self.fatal(&s),
{
static _FILE_LINE:
(&'static str, u32) =
("src/errors/mod.rs", 508u32);
&_FILE_LINE
})
};
}
pub fn emit(&self, sp: Option<Span>, msg: &str, lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().emit(sp, msg, None, lvl);
}
pub fn emit_with_code(&self, sp: Option<Span>, msg: &str, code: &str,
lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().emit(sp, msg, Some(code), lvl);
}
pub fn custom_emit(&self, sp: RenderSpan, msg: &str, lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().custom_emit(sp, msg, lvl);
}
}
pub enum Level { Bug, Fatal, Error, Warning, Note, Help, Cancelled, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Level {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Level::Bug,) => {
let mut builder = __arg_0.debug_tuple("Bug");
builder.finish()
}
(&Level::Fatal,) => {
let mut builder = __arg_0.debug_tuple("Fatal");
builder.finish()
}
(&Level::Error,) => {
let mut builder = __arg_0.debug_tuple("Error");
builder.finish()
}
(&Level::Warning,) => {
let mut builder = __arg_0.debug_tuple("Warning");
builder.finish()
}
(&Level::Note,) => {
let mut builder = __arg_0.debug_tuple("Note");
builder.finish()
}
(&Level::Help,) => {
let mut builder = __arg_0.debug_tuple("Help");
builder.finish()
}
(&Level::Cancelled,) => {
let mut builder = __arg_0.debug_tuple("Cancelled");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Level {
#[inline]
fn clone(&self) -> Level {
match (&*self,) {
(&Level::Bug,) => Level::Bug,
(&Level::Fatal,) => Level::Fatal,
(&Level::Error,) => Level::Error,
(&Level::Warning,) => Level::Warning,
(&Level::Note,) => Level::Note,
(&Level::Help,) => Level::Help,
(&Level::Cancelled,) => Level::Cancelled,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Level {
#[inline]
fn eq(&self, __arg_0: &Level) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Level::Bug, &Level::Bug) => true,
(&Level::Fatal, &Level::Fatal) => true,
(&Level::Error, &Level::Error) => true,
(&Level::Warning, &Level::Warning) => true,
(&Level::Note, &Level::Note) => true,
(&Level::Help, &Level::Help) => true,
(&Level::Cancelled, &Level::Cancelled) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Level) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Level::Bug, &Level::Bug) => false,
(&Level::Fatal, &Level::Fatal) => false,
(&Level::Error, &Level::Error) => false,
(&Level::Warning, &Level::Warning) => false,
(&Level::Note, &Level::Note) => false,
(&Level::Help, &Level::Help) => false,
(&Level::Cancelled, &Level::Cancelled) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Level { }
impl fmt::Display for Level {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::fmt::Display;
match *self {
Bug => "error: internal compiler error".fmt(f),
Fatal | Error => "error".fmt(f),
Warning => "warning".fmt(f),
Note => "note".fmt(f),
Help => "help".fmt(f),
Cancelled => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/mod.rs",
556u32);
&_FILE_LINE
})
}
}
}
}
}
impl Level {
fn color(self) -> term::color::Color {
match self {
Bug | Fatal | Error => term::color::BRIGHT_RED,
Warning => term::color::BRIGHT_YELLOW,
Note => term::color::BRIGHT_GREEN,
Help => term::color::BRIGHT_CYAN,
Cancelled => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/errors/mod.rs",
568u32);
&_FILE_LINE
})
}
}
}
}
}
pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where
M: FnOnce() -> String {
match opt { Some(t) => t, None => diag.bug(&msg()), }
}
}
pub mod syntax {
#[prelude_import]
use std::prelude::v1::*;
pub use ext;
pub use parse;
pub use ast;
}
pub mod abi {
#[prelude_import]
use std::prelude::v1::*;
pub use self::Os::*;
pub use self::Abi::*;
pub use self::Architecture::*;
pub use self::AbiArchitecture::*;
use std::fmt;
pub enum Os {
OsWindows,
OsMacos,
OsLinux,
OsAndroid,
OsFreebsd,
OsiOS,
OsDragonfly,
OsBitrig,
OsNetbsd,
OsOpenbsd,
OsNaCl,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Os {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Os::OsWindows,) => {
let mut builder = __arg_0.debug_tuple("OsWindows");
builder.finish()
}
(&Os::OsMacos,) => {
let mut builder = __arg_0.debug_tuple("OsMacos");
builder.finish()
}
(&Os::OsLinux,) => {
let mut builder = __arg_0.debug_tuple("OsLinux");
builder.finish()
}
(&Os::OsAndroid,) => {
let mut builder = __arg_0.debug_tuple("OsAndroid");
builder.finish()
}
(&Os::OsFreebsd,) => {
let mut builder = __arg_0.debug_tuple("OsFreebsd");
builder.finish()
}
(&Os::OsiOS,) => {
let mut builder = __arg_0.debug_tuple("OsiOS");
builder.finish()
}
(&Os::OsDragonfly,) => {
let mut builder = __arg_0.debug_tuple("OsDragonfly");
builder.finish()
}
(&Os::OsBitrig,) => {
let mut builder = __arg_0.debug_tuple("OsBitrig");
builder.finish()
}
(&Os::OsNetbsd,) => {
let mut builder = __arg_0.debug_tuple("OsNetbsd");
builder.finish()
}
(&Os::OsOpenbsd,) => {
let mut builder = __arg_0.debug_tuple("OsOpenbsd");
builder.finish()
}
(&Os::OsNaCl,) => {
let mut builder = __arg_0.debug_tuple("OsNaCl");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Os {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Os::OsWindows,) => { }
(&Os::OsMacos,) => { }
(&Os::OsLinux,) => { }
(&Os::OsAndroid,) => { }
(&Os::OsFreebsd,) => { }
(&Os::OsiOS,) => { }
(&Os::OsDragonfly,) => { }
(&Os::OsBitrig,) => { }
(&Os::OsNetbsd,) => { }
(&Os::OsOpenbsd,) => { }
(&Os::OsNaCl,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Os {
#[inline]
fn eq(&self, __arg_0: &Os) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Os::OsWindows, &Os::OsWindows) => true,
(&Os::OsMacos, &Os::OsMacos) => true,
(&Os::OsLinux, &Os::OsLinux) => true,
(&Os::OsAndroid, &Os::OsAndroid) => true,
(&Os::OsFreebsd, &Os::OsFreebsd) => true,
(&Os::OsiOS, &Os::OsiOS) => true,
(&Os::OsDragonfly, &Os::OsDragonfly) => true,
(&Os::OsBitrig, &Os::OsBitrig) => true,
(&Os::OsNetbsd, &Os::OsNetbsd) => true,
(&Os::OsOpenbsd, &Os::OsOpenbsd) => true,
(&Os::OsNaCl, &Os::OsNaCl) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Os) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Os::OsWindows, &Os::OsWindows) => false,
(&Os::OsMacos, &Os::OsMacos) => false,
(&Os::OsLinux, &Os::OsLinux) => false,
(&Os::OsAndroid, &Os::OsAndroid) => false,
(&Os::OsFreebsd, &Os::OsFreebsd) => false,
(&Os::OsiOS, &Os::OsiOS) => false,
(&Os::OsDragonfly, &Os::OsDragonfly) => false,
(&Os::OsBitrig, &Os::OsBitrig) => false,
(&Os::OsNetbsd, &Os::OsNetbsd) => false,
(&Os::OsOpenbsd, &Os::OsOpenbsd) => false,
(&Os::OsNaCl, &Os::OsNaCl) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Os {
#[inline]
fn clone(&self) -> Os {
match (&*self,) {
(&Os::OsWindows,) => Os::OsWindows,
(&Os::OsMacos,) => Os::OsMacos,
(&Os::OsLinux,) => Os::OsLinux,
(&Os::OsAndroid,) => Os::OsAndroid,
(&Os::OsFreebsd,) => Os::OsFreebsd,
(&Os::OsiOS,) => Os::OsiOS,
(&Os::OsDragonfly,) => Os::OsDragonfly,
(&Os::OsBitrig,) => Os::OsBitrig,
(&Os::OsNetbsd,) => Os::OsNetbsd,
(&Os::OsOpenbsd,) => Os::OsOpenbsd,
(&Os::OsNaCl,) => Os::OsNaCl,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Os { }
pub enum Abi {
Cdecl,
Stdcall,
Fastcall,
Aapcs,
Win64,
Rust,
C,
System,
RustIntrinsic,
RustCall,
PlatformIntrinsic,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Abi {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Abi::Cdecl,) => {
let mut builder = __arg_0.debug_tuple("Cdecl");
builder.finish()
}
(&Abi::Stdcall,) => {
let mut builder = __arg_0.debug_tuple("Stdcall");
builder.finish()
}
(&Abi::Fastcall,) => {
let mut builder = __arg_0.debug_tuple("Fastcall");
builder.finish()
}
(&Abi::Aapcs,) => {
let mut builder = __arg_0.debug_tuple("Aapcs");
builder.finish()
}
(&Abi::Win64,) => {
let mut builder = __arg_0.debug_tuple("Win64");
builder.finish()
}
(&Abi::Rust,) => {
let mut builder = __arg_0.debug_tuple("Rust");
builder.finish()
}
(&Abi::C,) => {
let mut builder = __arg_0.debug_tuple("C");
builder.finish()
}
(&Abi::System,) => {
let mut builder = __arg_0.debug_tuple("System");
builder.finish()
}
(&Abi::RustIntrinsic,) => {
let mut builder = __arg_0.debug_tuple("RustIntrinsic");
builder.finish()
}
(&Abi::RustCall,) => {
let mut builder = __arg_0.debug_tuple("RustCall");
builder.finish()
}
(&Abi::PlatformIntrinsic,) => {
let mut builder =
__arg_0.debug_tuple("PlatformIntrinsic");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Abi { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Abi {
#[inline]
fn clone(&self) -> Abi {
match (&*self,) {
(&Abi::Cdecl,) => Abi::Cdecl,
(&Abi::Stdcall,) => Abi::Stdcall,
(&Abi::Fastcall,) => Abi::Fastcall,
(&Abi::Aapcs,) => Abi::Aapcs,
(&Abi::Win64,) => Abi::Win64,
(&Abi::Rust,) => Abi::Rust,
(&Abi::C,) => Abi::C,
(&Abi::System,) => Abi::System,
(&Abi::RustIntrinsic,) => Abi::RustIntrinsic,
(&Abi::RustCall,) => Abi::RustCall,
(&Abi::PlatformIntrinsic,) => Abi::PlatformIntrinsic,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Abi {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Abi, __D::Error> {
__arg_0.read_enum("Abi", |_d| -> _ {
_d.read_enum_variant(&["Cdecl", "Stdcall",
"Fastcall", "Aapcs",
"Win64", "Rust", "C",
"System",
"RustIntrinsic",
"RustCall",
"PlatformIntrinsic"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Abi::Cdecl,
1usize
=>
Abi::Stdcall,
2usize
=>
Abi::Fastcall,
3usize
=>
Abi::Aapcs,
4usize
=>
Abi::Win64,
5usize
=>
Abi::Rust,
6usize
=>
Abi::C,
7usize
=>
Abi::System,
8usize
=>
Abi::RustIntrinsic,
9usize
=>
Abi::RustCall,
10usize
=>
Abi::PlatformIntrinsic,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/abi.rs",
33u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Abi {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Abi::Cdecl,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("Cdecl", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::Stdcall,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("Stdcall", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::Fastcall,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("Fastcall", 2usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::Aapcs,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("Aapcs", 3usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::Win64,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("Win64", 4usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::Rust,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("Rust", 5usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::C,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("C", 6usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::System,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("System", 7usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::RustIntrinsic,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("RustIntrinsic", 8usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::RustCall,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("RustCall", 9usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Abi::PlatformIntrinsic,) => {
let _e = __arg_0;
_e.emit_enum("Abi", |_e| -> _ {
_e.emit_enum_variant("PlatformIntrinsic",
10usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Abi {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Abi::Cdecl,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Abi::Stdcall,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&Abi::Fastcall,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
(&Abi::Aapcs,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&Abi::Win64,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
(&Abi::Rust,) => {
::std::hash::Hash::hash(&5usize, __arg_0);
}
(&Abi::C,) => { ::std::hash::Hash::hash(&6usize, __arg_0); }
(&Abi::System,) => {
::std::hash::Hash::hash(&7usize, __arg_0);
}
(&Abi::RustIntrinsic,) => {
::std::hash::Hash::hash(&8usize, __arg_0);
}
(&Abi::RustCall,) => {
::std::hash::Hash::hash(&9usize, __arg_0);
}
(&Abi::PlatformIntrinsic,) => {
::std::hash::Hash::hash(&10usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Abi {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Abi::Cdecl,) => { }
(&Abi::Stdcall,) => { }
(&Abi::Fastcall,) => { }
(&Abi::Aapcs,) => { }
(&Abi::Win64,) => { }
(&Abi::Rust,) => { }
(&Abi::C,) => { }
(&Abi::System,) => { }
(&Abi::RustIntrinsic,) => { }
(&Abi::RustCall,) => { }
(&Abi::PlatformIntrinsic,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Abi {
#[inline]
fn eq(&self, __arg_0: &Abi) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Abi::Cdecl, &Abi::Cdecl) => true,
(&Abi::Stdcall, &Abi::Stdcall) => true,
(&Abi::Fastcall, &Abi::Fastcall) => true,
(&Abi::Aapcs, &Abi::Aapcs) => true,
(&Abi::Win64, &Abi::Win64) => true,
(&Abi::Rust, &Abi::Rust) => true,
(&Abi::C, &Abi::C) => true,
(&Abi::System, &Abi::System) => true,
(&Abi::RustIntrinsic, &Abi::RustIntrinsic) => true,
(&Abi::RustCall, &Abi::RustCall) => true,
(&Abi::PlatformIntrinsic, &Abi::PlatformIntrinsic) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Abi) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Abi::Cdecl, &Abi::Cdecl) => false,
(&Abi::Stdcall, &Abi::Stdcall) => false,
(&Abi::Fastcall, &Abi::Fastcall) => false,
(&Abi::Aapcs, &Abi::Aapcs) => false,
(&Abi::Win64, &Abi::Win64) => false,
(&Abi::Rust, &Abi::Rust) => false,
(&Abi::C, &Abi::C) => false,
(&Abi::System, &Abi::System) => false,
(&Abi::RustIntrinsic, &Abi::RustIntrinsic) => false,
(&Abi::RustCall, &Abi::RustCall) => false,
(&Abi::PlatformIntrinsic, &Abi::PlatformIntrinsic) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[allow(non_camel_case_types)]
pub enum Architecture { X86, X86_64, Arm, Mips, Mipsel, }
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::fmt::Debug for Architecture {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Architecture::X86,) => {
let mut builder = __arg_0.debug_tuple("X86");
builder.finish()
}
(&Architecture::X86_64,) => {
let mut builder = __arg_0.debug_tuple("X86_64");
builder.finish()
}
(&Architecture::Arm,) => {
let mut builder = __arg_0.debug_tuple("Arm");
builder.finish()
}
(&Architecture::Mips,) => {
let mut builder = __arg_0.debug_tuple("Mips");
builder.finish()
}
(&Architecture::Mipsel,) => {
let mut builder = __arg_0.debug_tuple("Mipsel");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::cmp::PartialEq for Architecture {
#[inline]
fn eq(&self, __arg_0: &Architecture) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Architecture::X86, &Architecture::X86) => true,
(&Architecture::X86_64, &Architecture::X86_64) =>
true,
(&Architecture::Arm, &Architecture::Arm) => true,
(&Architecture::Mips, &Architecture::Mips) => true,
(&Architecture::Mipsel, &Architecture::Mipsel) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Architecture) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Architecture::X86, &Architecture::X86) => false,
(&Architecture::X86_64, &Architecture::X86_64) =>
false,
(&Architecture::Arm, &Architecture::Arm) => false,
(&Architecture::Mips, &Architecture::Mips) => false,
(&Architecture::Mipsel, &Architecture::Mipsel) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::clone::Clone for Architecture {
#[inline]
fn clone(&self) -> Architecture {
match (&*self,) {
(&Architecture::X86,) => Architecture::X86,
(&Architecture::X86_64,) => Architecture::X86_64,
(&Architecture::Arm,) => Architecture::Arm,
(&Architecture::Mips,) => Architecture::Mips,
(&Architecture::Mipsel,) => Architecture::Mipsel,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::marker::Copy for Architecture { }
pub struct AbiData {
abi: Abi,
name: &'static str,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AbiData {
#[inline]
fn clone(&self) -> AbiData {
match *self {
AbiData { abi: ref __self_0_0, name: ref __self_0_1 } =>
AbiData{abi: ::std::clone::Clone::clone(&(*__self_0_0)),
name: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AbiData { }
pub enum AbiArchitecture {
/// Not a real ABI (e.g., intrinsic)
RustArch,
/// An ABI that specifies cross-platform defaults (e.g., "C")
AllArch,
/// Multiple architectures (bitset)
Archs(u32),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AbiArchitecture {
#[inline]
fn clone(&self) -> AbiArchitecture {
match (&*self,) {
(&AbiArchitecture::RustArch,) => AbiArchitecture::RustArch,
(&AbiArchitecture::AllArch,) => AbiArchitecture::AllArch,
(&AbiArchitecture::Archs(ref __self_0),) =>
AbiArchitecture::Archs(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AbiArchitecture { }
#[allow(non_upper_case_globals)]
const AbiDatas: &'static [AbiData] =
&[AbiData{abi: Cdecl, name: "cdecl",},
AbiData{abi: Stdcall, name: "stdcall",},
AbiData{abi: Fastcall, name: "fastcall",},
AbiData{abi: Aapcs, name: "aapcs",},
AbiData{abi: Win64, name: "win64",},
AbiData{abi: Rust, name: "Rust",}, AbiData{abi: C, name: "C",},
AbiData{abi: System, name: "system",},
AbiData{abi: RustIntrinsic, name: "rust-intrinsic",},
AbiData{abi: RustCall, name: "rust-call",},
AbiData{abi: PlatformIntrinsic, name: "platform-intrinsic",}];
/// Returns the ABI with the given name (if any).
pub fn lookup(name: &str) -> Option<Abi> {
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
}
pub fn all_names() -> Vec<&'static str> {
AbiDatas.iter().map(|d| d.name).collect()
}
impl Abi {
#[inline]
pub fn index(&self) -> usize { *self as usize }
#[inline]
pub fn data(&self) -> &'static AbiData { &AbiDatas[self.index()] }
pub fn name(&self) -> &'static str { self.data().name }
}
impl fmt::Display for Abi {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\"", "\""];
__STATIC_FMTSTR
},
&match (&self.name(),) {
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
impl fmt::Display for Os {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
OsLinux => "linux".fmt(f),
OsWindows => "windows".fmt(f),
OsMacos => "macos".fmt(f),
OsiOS => "ios".fmt(f),
OsAndroid => "android".fmt(f),
OsFreebsd => "freebsd".fmt(f),
OsDragonfly => "dragonfly".fmt(f),
OsBitrig => "bitrig".fmt(f),
OsNetbsd => "netbsd".fmt(f),
OsOpenbsd => "openbsd".fmt(f),
OsNaCl => "nacl".fmt(f),
}
}
}
}
pub mod ast {
#[prelude_import]
use std::prelude::v1::*;
pub use self::BinOp_::*;
pub use self::BlockCheckMode::*;
pub use self::CaptureClause::*;
pub use self::Decl_::*;
pub use self::ExplicitSelf_::*;
pub use self::Expr_::*;
pub use self::FloatTy::*;
pub use self::FunctionRetTy::*;
pub use self::ForeignItem_::*;
pub use self::IntTy::*;
pub use self::Item_::*;
pub use self::KleeneOp::*;
pub use self::Lit_::*;
pub use self::LitIntType::*;
pub use self::MacStmtStyle::*;
pub use self::MetaItem_::*;
pub use self::Mutability::*;
pub use self::Pat_::*;
pub use self::PathListItem_::*;
pub use self::PrimTy::*;
pub use self::Sign::*;
pub use self::Stmt_::*;
pub use self::StrStyle::*;
pub use self::StructFieldKind::*;
pub use self::TraitItem_::*;
pub use self::Ty_::*;
pub use self::TyParamBound::*;
pub use self::UintTy::*;
pub use self::UnOp::*;
pub use self::UnsafeSource::*;
pub use self::ViewPath_::*;
pub use self::Visibility::*;
pub use self::PathParameters::*;
use attr::ThinAttributes;
use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
use abi::Abi;
use ext::base;
use ext::tt::macro_parser;
use parse::token::InternedString;
use parse::token;
use parse::lexer;
use parse::lexer::comments::{doc_comment_style,
strip_doc_comment_decoration};
use print::pprust;
use ptr::P;
use std::fmt;
use std::rc::Rc;
use std::borrow::Cow;
use std::hash::{Hash, Hasher};
use serialize::{Encodable, Decodable, Encoder, Decoder};
/// A name is a part of an identifier, representing a string or gensym. It's
/// the result of interning.
pub struct Name(pub u32);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Name {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Name(ref __self_0_0) => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Ord for Name {
#[inline]
fn cmp(&self, __arg_0: &Name) -> ::std::cmp::Ordering {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) => {
let __test =
::std::cmp::Ord::cmp(&(*__self_0_0),
&(*__self_1_0));
if __test == ::std::cmp::Ordering::Equal {
::std::cmp::Ordering::Equal
} else { __test }
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for Name {
#[inline]
fn partial_cmp(&self, __arg_0: &Name)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &Name) -> bool {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &Name) -> bool {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &Name) -> bool {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &Name) -> bool {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Name {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Name(ref __self_0_0) => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Name {
#[inline]
fn eq(&self, __arg_0: &Name) -> bool {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Name) -> bool {
match *__arg_0 {
Name(ref __self_1_0) =>
match *self {
Name(ref __self_0_0) =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Name { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Name {
#[inline]
fn clone(&self) -> Name {
match *self {
Name(ref __self_0_0) =>
Name(::std::clone::Clone::clone(&(*__self_0_0))),
}
}
}
/// A SyntaxContext represents a chain of macro-expandings
/// and renamings. Each macro expansion corresponds to
/// a fresh u32. This u32 is a reference to a table stored
pub struct SyntaxContext(pub u32);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for SyntaxContext {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<SyntaxContext, __D::Error> {
__arg_0.read_struct("SyntaxContext", 1usize, |_d| -> _ {
::std::result::Result::Ok(SyntaxContext(match _d.read_struct_field("_field0",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
})) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for SyntaxContext {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
SyntaxContext(ref __self_0_0) =>
__arg_0.emit_struct("SyntaxContext", 1usize, |_e| -> _ {
return _e.emit_struct_field("_field0",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for SyntaxContext {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
SyntaxContext(ref __self_0_0) => {
let mut builder = __arg_0.debug_tuple("SyntaxContext");
let _ = builder.field(&&(*__self_0_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for SyntaxContext {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
SyntaxContext(ref __self_0_0) => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for SyntaxContext {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
SyntaxContext(ref __self_0_0) => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for SyntaxContext {
#[inline]
fn eq(&self, __arg_0: &SyntaxContext) -> bool {
match *__arg_0 {
SyntaxContext(ref __self_1_0) =>
match *self {
SyntaxContext(ref __self_0_0) =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &SyntaxContext) -> bool {
match *__arg_0 {
SyntaxContext(ref __self_1_0) =>
match *self {
SyntaxContext(ref __self_0_0) =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for SyntaxContext { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for SyntaxContext {
#[inline]
fn clone(&self) -> SyntaxContext {
match *self {
SyntaxContext(ref __self_0_0) =>
SyntaxContext(::std::clone::Clone::clone(&(*__self_0_0))),
}
}
}
/// An identifier contains a Name (index into the interner
/// table) and a SyntaxContext to track renaming and
/// macro expansion per Flatt et al., "Macros That Work Together"
pub struct Ident {
pub name: Name,
pub ctxt: SyntaxContext,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Ident {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Ident { name: ref __self_0_0, ctxt: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Ident { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Ident {
#[inline]
fn clone(&self) -> Ident {
match *self {
Ident { name: ref __self_0_0, ctxt: ref __self_0_1 } =>
Ident{name: ::std::clone::Clone::clone(&(*__self_0_0)),
ctxt: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
impl Name {
pub fn as_str(self) -> token::InternedString {
token::InternedString::new_from_name(self)
}
}
impl fmt::Debug for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["", "(", ")"];
__STATIC_FMTSTR
},
&match (&self, &self.0)
{
(__arg0, __arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
}
impl fmt::Display for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.as_str(), f)
}
}
impl Encodable for Name {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_str(&self.as_str())
}
}
impl Decodable for Name {
fn decode<D: Decoder>(d: &mut D) -> Result<Name, D::Error> {
Ok(token::intern(&match d.read_str() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}[..]))
}
}
pub const EMPTY_CTXT: SyntaxContext = SyntaxContext(0);
impl Ident {
pub fn new(name: Name, ctxt: SyntaxContext) -> Ident {
Ident{name: name, ctxt: ctxt,}
}
pub fn with_empty_ctxt(name: Name) -> Ident {
Ident{name: name, ctxt: EMPTY_CTXT,}
}
}
impl PartialEq for Ident {
fn eq(&self, other: &Ident) -> bool {
if self.ctxt != other.ctxt {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["idents with different contexts are compared with operator `==`: ",
", ",
"."];
__STATIC_FMTSTR
},
&match (&self,
&other)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ast.rs",
149u32);
&_FILE_LINE
})
};
}
self.name == other.name
}
}
impl Hash for Ident {
fn hash<H: Hasher>(&self, state: &mut H) { self.name.hash(state) }
}
impl fmt::Debug for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["", "#"];
__STATIC_FMTSTR
},
&match (&self.name,
&self.ctxt.0) {
(__arg0, __arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
}
impl fmt::Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.name, f)
}
}
impl Encodable for Ident {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
self.name.encode(s)
}
}
impl Decodable for Ident {
fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
Ok(Ident::with_empty_ctxt(match Name::decode(d) {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
}
}
/// A mark represents a unique id associated with a macro expansion
pub type Mrk = u32;
pub struct Lifetime {
pub id: NodeId,
pub span: Span,
pub name: Name,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Lifetime { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Lifetime {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Lifetime {
id: ref __self_0_0, span: ref __self_0_1, name: ref __self_0_2
} => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Lifetime {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Lifetime, __D::Error> {
__arg_0.read_struct("Lifetime", 3usize, |_d| -> _ {
::std::result::Result::Ok(Lifetime{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
name:
match _d.read_struct_field("name",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Lifetime {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Lifetime {
id: ref __self_0_0, span: ref __self_0_1, name: ref __self_0_2
} =>
__arg_0.emit_struct("Lifetime", 3usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("name",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Lifetime {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Lifetime {
id: ref __self_0_0, span: ref __self_0_1, name: ref __self_0_2
} => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Lifetime {
#[inline]
fn eq(&self, __arg_0: &Lifetime) -> bool {
match *__arg_0 {
Lifetime {
id: ref __self_1_0, span: ref __self_1_1, name: ref __self_1_2
} =>
match *self {
Lifetime {
id: ref __self_0_0,
span: ref __self_0_1,
name: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Lifetime) -> bool {
match *__arg_0 {
Lifetime {
id: ref __self_1_0, span: ref __self_1_1, name: ref __self_1_2
} =>
match *self {
Lifetime {
id: ref __self_0_0,
span: ref __self_0_1,
name: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Lifetime {
#[inline]
fn clone(&self) -> Lifetime {
match *self {
Lifetime {
id: ref __self_0_0, span: ref __self_0_1, name: ref __self_0_2
} =>
Lifetime{id: ::std::clone::Clone::clone(&(*__self_0_0)),
span: ::std::clone::Clone::clone(&(*__self_0_1)),
name: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl fmt::Debug for Lifetime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["lifetime(",
": ", ")"];
__STATIC_FMTSTR
},
&match (&self.id,
&pprust::lifetime_to_string(self))
{
(__arg0, __arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
}
/// A lifetime definition, eg `'a: 'b+'c+'d`
pub struct LifetimeDef {
pub lifetime: Lifetime,
pub bounds: Vec<Lifetime>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for LifetimeDef {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
LifetimeDef { lifetime: ref __self_0_0, bounds: ref __self_0_1
} => {
let mut builder = __arg_0.debug_struct("LifetimeDef");
let _ = builder.field("lifetime", &&(*__self_0_0));
let _ = builder.field("bounds", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for LifetimeDef {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
LifetimeDef { lifetime: ref __self_0_0, bounds: ref __self_0_1
} => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for LifetimeDef {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<LifetimeDef, __D::Error> {
__arg_0.read_struct("LifetimeDef", 2usize, |_d| -> _ {
::std::result::Result::Ok(LifetimeDef{lifetime:
match _d.read_struct_field("lifetime",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bounds:
match _d.read_struct_field("bounds",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for LifetimeDef {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
LifetimeDef { lifetime: ref __self_0_0, bounds: ref __self_0_1
} =>
__arg_0.emit_struct("LifetimeDef", 2usize, |_e| -> _ {
match _e.emit_struct_field("lifetime",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("bounds",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for LifetimeDef {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
LifetimeDef { lifetime: ref __self_0_0, bounds: ref __self_0_1
} => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for LifetimeDef {
#[inline]
fn eq(&self, __arg_0: &LifetimeDef) -> bool {
match *__arg_0 {
LifetimeDef { lifetime: ref __self_1_0, bounds: ref __self_1_1
} =>
match *self {
LifetimeDef {
lifetime: ref __self_0_0, bounds: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &LifetimeDef) -> bool {
match *__arg_0 {
LifetimeDef { lifetime: ref __self_1_0, bounds: ref __self_1_1
} =>
match *self {
LifetimeDef {
lifetime: ref __self_0_0, bounds: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for LifetimeDef {
#[inline]
fn clone(&self) -> LifetimeDef {
match *self {
LifetimeDef { lifetime: ref __self_0_0, bounds: ref __self_0_1
} =>
LifetimeDef{lifetime:
::std::clone::Clone::clone(&(*__self_0_0)),
bounds:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
/// A "Path" is essentially Rust's notion of a name; for instance:
/// std::cmp::PartialEq . It's represented as a sequence of identifiers,
/// along with a bunch of supporting information.
pub struct Path {
pub span: Span,
/// A `::foo` path, is relative to the crate root rather than current
/// module (like paths in an import).
pub global: bool,
/// The segments in the path: the things separated by `::`.
pub segments: Vec<PathSegment>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Path {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Path {
span: ref __self_0_0,
global: ref __self_0_1,
segments: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Path {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Path, __D::Error> {
__arg_0.read_struct("Path", 3usize, |_d| -> _ {
::std::result::Result::Ok(Path{span:
match _d.read_struct_field("span",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
global:
match _d.read_struct_field("global",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
segments:
match _d.read_struct_field("segments",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Path {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Path {
span: ref __self_0_0,
global: ref __self_0_1,
segments: ref __self_0_2 } =>
__arg_0.emit_struct("Path", 3usize, |_e| -> _ {
match _e.emit_struct_field("span", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("global",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("segments",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Path {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Path {
span: ref __self_0_0,
global: ref __self_0_1,
segments: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Path {
#[inline]
fn eq(&self, __arg_0: &Path) -> bool {
match *__arg_0 {
Path {
span: ref __self_1_0,
global: ref __self_1_1,
segments: ref __self_1_2 } =>
match *self {
Path {
span: ref __self_0_0,
global: ref __self_0_1,
segments: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Path) -> bool {
match *__arg_0 {
Path {
span: ref __self_1_0,
global: ref __self_1_1,
segments: ref __self_1_2 } =>
match *self {
Path {
span: ref __self_0_0,
global: ref __self_0_1,
segments: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Path {
#[inline]
fn clone(&self) -> Path {
match *self {
Path {
span: ref __self_0_0,
global: ref __self_0_1,
segments: ref __self_0_2 } =>
Path{span: ::std::clone::Clone::clone(&(*__self_0_0)),
global: ::std::clone::Clone::clone(&(*__self_0_1)),
segments: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl fmt::Debug for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["path(", ")"];
__STATIC_FMTSTR
},
&match (&pprust::path_to_string(self),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
impl fmt::Display for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&pprust::path_to_string(self),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
/// A segment of a path: an identifier, an optional lifetime, and a set of
/// types.
pub struct PathSegment {
/// The identifier portion of this path segment.
pub identifier: Ident,
/// Type/lifetime parameters attached to this path. They come in
/// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
/// this is more than just simple syntactic sugar; the use of
/// parens affects the region binding rules, so we preserve the
/// distinction.
pub parameters: PathParameters,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for PathSegment {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("PathSegment");
let _ = builder.field("identifier", &&(*__self_0_0));
let _ = builder.field("parameters", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for PathSegment {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for PathSegment {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<PathSegment, __D::Error> {
__arg_0.read_struct("PathSegment", 2usize, |_d| -> _ {
::std::result::Result::Ok(PathSegment{identifier:
match _d.read_struct_field("identifier",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
parameters:
match _d.read_struct_field("parameters",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for PathSegment {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 } =>
__arg_0.emit_struct("PathSegment", 2usize, |_e| -> _ {
match _e.emit_struct_field("identifier",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("parameters",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for PathSegment {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for PathSegment {
#[inline]
fn eq(&self, __arg_0: &PathSegment) -> bool {
match *__arg_0 {
PathSegment {
identifier: ref __self_1_0, parameters: ref __self_1_1 } =>
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 }
=>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &PathSegment) -> bool {
match *__arg_0 {
PathSegment {
identifier: ref __self_1_0, parameters: ref __self_1_1 } =>
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 }
=>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PathSegment {
#[inline]
fn clone(&self) -> PathSegment {
match *self {
PathSegment {
identifier: ref __self_0_0, parameters: ref __self_0_1 } =>
PathSegment{identifier:
::std::clone::Clone::clone(&(*__self_0_0)),
parameters:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub enum PathParameters {
/// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>`
AngleBracketed(AngleBracketedParameterData),
/// The `(A,B)` and `C` in `Foo(A,B) -> C`
Parenthesized(ParenthesizedParameterData),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for PathParameters {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&PathParameters::AngleBracketed(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("AngleBracketed");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&PathParameters::Parenthesized(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Parenthesized");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for PathParameters {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&PathParameters::AngleBracketed(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&PathParameters::Parenthesized(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for PathParameters {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<PathParameters, __D::Error> {
__arg_0.read_enum("PathParameters", |_d| -> _ {
_d.read_enum_variant(&["AngleBracketed",
"Parenthesized"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
PathParameters::AngleBracketed(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
PathParameters::Parenthesized(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
250u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for PathParameters {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&PathParameters::AngleBracketed(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("PathParameters", |_e| -> _ {
_e.emit_enum_variant("AngleBracketed",
0usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&PathParameters::Parenthesized(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("PathParameters", |_e| -> _ {
_e.emit_enum_variant("Parenthesized", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for PathParameters {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&PathParameters::AngleBracketed(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&PathParameters::Parenthesized(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for PathParameters {
#[inline]
fn eq(&self, __arg_0: &PathParameters) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PathParameters::AngleBracketed(ref __self_0),
&PathParameters::AngleBracketed(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&PathParameters::Parenthesized(ref __self_0),
&PathParameters::Parenthesized(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &PathParameters) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PathParameters::AngleBracketed(ref __self_0),
&PathParameters::AngleBracketed(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&PathParameters::Parenthesized(ref __self_0),
&PathParameters::Parenthesized(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PathParameters {
#[inline]
fn clone(&self) -> PathParameters {
match (&*self,) {
(&PathParameters::AngleBracketed(ref __self_0),) =>
PathParameters::AngleBracketed(::std::clone::Clone::clone(&(*__self_0))),
(&PathParameters::Parenthesized(ref __self_0),) =>
PathParameters::Parenthesized(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl PathParameters {
pub fn none() -> PathParameters {
PathParameters::AngleBracketed(AngleBracketedParameterData{lifetimes:
Vec::new(),
types:
P::empty(),
bindings:
P::empty(),})
}
pub fn is_empty(&self) -> bool {
match *self {
PathParameters::AngleBracketed(ref data) => data.is_empty(),
PathParameters::Parenthesized(..) => false,
}
}
pub fn has_lifetimes(&self) -> bool {
match *self {
PathParameters::AngleBracketed(ref data) =>
!data.lifetimes.is_empty(),
PathParameters::Parenthesized(_) => false,
}
}
pub fn has_types(&self) -> bool {
match *self {
PathParameters::AngleBracketed(ref data) =>
!data.types.is_empty(),
PathParameters::Parenthesized(..) => true,
}
}
/// Returns the types that the user wrote. Note that these do not necessarily map to the type
/// parameters in the parenthesized case.
pub fn types(&self) -> Vec<&P<Ty>> {
match *self {
PathParameters::AngleBracketed(ref data) => {
data.types.iter().collect()
}
PathParameters::Parenthesized(ref data) => {
data.inputs.iter().chain(data.output.iter()).collect()
}
}
}
pub fn lifetimes(&self) -> Vec<&Lifetime> {
match *self {
PathParameters::AngleBracketed(ref data) => {
data.lifetimes.iter().collect()
}
PathParameters::Parenthesized(_) => { Vec::new() }
}
}
pub fn bindings(&self) -> Vec<&P<TypeBinding>> {
match *self {
PathParameters::AngleBracketed(ref data) => {
data.bindings.iter().collect()
}
PathParameters::Parenthesized(_) => { Vec::new() }
}
}
}
/// A path like `Foo<'a, T>`
pub struct AngleBracketedParameterData {
/// The lifetime parameters for this path segment.
pub lifetimes: Vec<Lifetime>,
/// The type parameters for this path segment, if present.
pub types: P<[P<Ty>]>,
/// Bindings (equality constraints) on associated types, if present.
/// e.g., `Foo<A=Bar>`.
pub bindings: P<[P<TypeBinding>]>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AngleBracketedParameterData {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } => {
let mut builder =
__arg_0.debug_struct("AngleBracketedParameterData");
let _ = builder.field("lifetimes", &&(*__self_0_0));
let _ = builder.field("types", &&(*__self_0_1));
let _ = builder.field("bindings", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for AngleBracketedParameterData {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for AngleBracketedParameterData {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<AngleBracketedParameterData, __D::Error> {
__arg_0.read_struct("AngleBracketedParameterData", 3usize,
|_d| -> _ {
::std::result::Result::Ok(AngleBracketedParameterData{lifetimes:
match _d.read_struct_field("lifetimes",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
types:
match _d.read_struct_field("types",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bindings:
match _d.read_struct_field("bindings",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for AngleBracketedParameterData {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } =>
__arg_0.emit_struct("AngleBracketedParameterData", 3usize,
|_e| -> _ {
match _e.emit_struct_field("lifetimes",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("types",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("bindings",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for AngleBracketedParameterData {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AngleBracketedParameterData {
#[inline]
fn eq(&self, __arg_0: &AngleBracketedParameterData) -> bool {
match *__arg_0 {
AngleBracketedParameterData {
lifetimes: ref __self_1_0,
types: ref __self_1_1,
bindings: ref __self_1_2 } =>
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &AngleBracketedParameterData) -> bool {
match *__arg_0 {
AngleBracketedParameterData {
lifetimes: ref __self_1_0,
types: ref __self_1_1,
bindings: ref __self_1_2 } =>
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AngleBracketedParameterData {
#[inline]
fn clone(&self) -> AngleBracketedParameterData {
match *self {
AngleBracketedParameterData {
lifetimes: ref __self_0_0,
types: ref __self_0_1,
bindings: ref __self_0_2 } =>
AngleBracketedParameterData{lifetimes:
::std::clone::Clone::clone(&(*__self_0_0)),
types:
::std::clone::Clone::clone(&(*__self_0_1)),
bindings:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl AngleBracketedParameterData {
fn is_empty(&self) -> bool {
self.lifetimes.is_empty() && self.types.is_empty() &&
self.bindings.is_empty()
}
}
/// A path like `Foo(A,B) -> C`
pub struct ParenthesizedParameterData {
/// Overall span
pub span: Span,
/// `(A,B)`
pub inputs: Vec<P<Ty>>,
/// `C`
pub output: Option<P<Ty>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ParenthesizedParameterData {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } => {
let mut builder =
__arg_0.debug_struct("ParenthesizedParameterData");
let _ = builder.field("span", &&(*__self_0_0));
let _ = builder.field("inputs", &&(*__self_0_1));
let _ = builder.field("output", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ParenthesizedParameterData {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ParenthesizedParameterData {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ParenthesizedParameterData, __D::Error> {
__arg_0.read_struct("ParenthesizedParameterData", 3usize,
|_d| -> _ {
::std::result::Result::Ok(ParenthesizedParameterData{span:
match _d.read_struct_field("span",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
inputs:
match _d.read_struct_field("inputs",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
output:
match _d.read_struct_field("output",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ParenthesizedParameterData {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } =>
__arg_0.emit_struct("ParenthesizedParameterData", 3usize,
|_e| -> _ {
match _e.emit_struct_field("span", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("inputs",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("output",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ParenthesizedParameterData {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ParenthesizedParameterData {
#[inline]
fn eq(&self, __arg_0: &ParenthesizedParameterData) -> bool {
match *__arg_0 {
ParenthesizedParameterData {
span: ref __self_1_0,
inputs: ref __self_1_1,
output: ref __self_1_2 } =>
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ParenthesizedParameterData) -> bool {
match *__arg_0 {
ParenthesizedParameterData {
span: ref __self_1_0,
inputs: ref __self_1_1,
output: ref __self_1_2 } =>
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ParenthesizedParameterData {
#[inline]
fn clone(&self) -> ParenthesizedParameterData {
match *self {
ParenthesizedParameterData {
span: ref __self_0_0,
inputs: ref __self_0_1,
output: ref __self_0_2 } =>
ParenthesizedParameterData{span:
::std::clone::Clone::clone(&(*__self_0_0)),
inputs:
::std::clone::Clone::clone(&(*__self_0_1)),
output:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub type CrateNum = u32;
pub type NodeId = u32;
/// Node id used to represent the root of the crate.
pub const CRATE_NODE_ID: NodeId = 0;
/// When parsing and doing expansions, we initially give all AST nodes this AST
/// node value. Then later, in the renumber pass, we renumber them to have
/// small, positive ids.
pub const DUMMY_NODE_ID: NodeId = !0;
pub trait NodeIdAssigner {
fn next_node_id(&self)
-> NodeId;
fn peek_node_id(&self)
-> NodeId;
}
/// The AST represents all type param bounds as types.
/// typeck::collect::compute_bounds matches these against
/// the "special" built-in traits (see middle::lang_items) and
/// detects Copy, Send and Sync.
pub enum TyParamBound {
TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
RegionTyParamBound(Lifetime),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TyParamBound {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),) => {
let mut builder =
__arg_0.debug_tuple("TraitTyParamBound");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&TyParamBound::RegionTyParamBound(ref __self_0),) => {
let mut builder =
__arg_0.debug_tuple("RegionTyParamBound");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TyParamBound {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&TyParamBound::RegionTyParamBound(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TyParamBound {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TyParamBound, __D::Error> {
__arg_0.read_enum("TyParamBound", |_d| -> _ {
_d.read_enum_variant(&["TraitTyParamBound",
"RegionTyParamBound"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
TyParamBound::TraitTyParamBound(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
TyParamBound::RegionTyParamBound(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
381u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TyParamBound {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("TyParamBound", |_e| -> _ {
_e.emit_enum_variant("TraitTyParamBound",
0usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&TyParamBound::RegionTyParamBound(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("TyParamBound", |_e| -> _ {
_e.emit_enum_variant("RegionTyParamBound",
1usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TyParamBound {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&TyParamBound::RegionTyParamBound(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TyParamBound {
#[inline]
fn eq(&self, __arg_0: &TyParamBound) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),
&TyParamBound::TraitTyParamBound(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&TyParamBound::RegionTyParamBound(ref __self_0),
&TyParamBound::RegionTyParamBound(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &TyParamBound) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),
&TyParamBound::TraitTyParamBound(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&TyParamBound::RegionTyParamBound(ref __self_0),
&TyParamBound::RegionTyParamBound(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TyParamBound {
#[inline]
fn clone(&self) -> TyParamBound {
match (&*self,) {
(&TyParamBound::TraitTyParamBound(ref __self_0,
ref __self_1),) =>
TyParamBound::TraitTyParamBound(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&TyParamBound::RegionTyParamBound(ref __self_0),) =>
TyParamBound::RegionTyParamBound(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
/// A modifier on a bound, currently this is only used for `?Sized`, where the
/// modifier is `Maybe`. Negative bounds should also be handled here.
pub enum TraitBoundModifier { None, Maybe, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TraitBoundModifier {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&TraitBoundModifier::None,) => {
let mut builder = __arg_0.debug_tuple("None");
builder.finish()
}
(&TraitBoundModifier::Maybe,) => {
let mut builder = __arg_0.debug_tuple("Maybe");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TraitBoundModifier {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&TraitBoundModifier::None,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&TraitBoundModifier::Maybe,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TraitBoundModifier {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TraitBoundModifier, __D::Error> {
__arg_0.read_enum("TraitBoundModifier", |_d| -> _ {
_d.read_enum_variant(&["None", "Maybe"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
TraitBoundModifier::None,
1usize
=>
TraitBoundModifier::Maybe,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
389u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TraitBoundModifier {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&TraitBoundModifier::None,) => {
let _e = __arg_0;
_e.emit_enum("TraitBoundModifier", |_e| -> _ {
_e.emit_enum_variant("None", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&TraitBoundModifier::Maybe,) => {
let _e = __arg_0;
_e.emit_enum("TraitBoundModifier", |_e| -> _ {
_e.emit_enum_variant("Maybe", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TraitBoundModifier {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&TraitBoundModifier::None,) => { }
(&TraitBoundModifier::Maybe,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TraitBoundModifier {
#[inline]
fn eq(&self, __arg_0: &TraitBoundModifier) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TraitBoundModifier::None, &TraitBoundModifier::None)
=> true,
(&TraitBoundModifier::Maybe,
&TraitBoundModifier::Maybe) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &TraitBoundModifier) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TraitBoundModifier::None, &TraitBoundModifier::None)
=> false,
(&TraitBoundModifier::Maybe,
&TraitBoundModifier::Maybe) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TraitBoundModifier {
#[inline]
fn clone(&self) -> TraitBoundModifier {
match (&*self,) {
(&TraitBoundModifier::None,) => TraitBoundModifier::None,
(&TraitBoundModifier::Maybe,) => TraitBoundModifier::Maybe,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for TraitBoundModifier { }
pub type TyParamBounds = P<[TyParamBound]>;
pub struct TyParam {
pub ident: Ident,
pub id: NodeId,
pub bounds: TyParamBounds,
pub default: Option<P<Ty>>,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TyParam {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } => {
let mut builder = __arg_0.debug_struct("TyParam");
let _ = builder.field("ident", &&(*__self_0_0));
let _ = builder.field("id", &&(*__self_0_1));
let _ = builder.field("bounds", &&(*__self_0_2));
let _ = builder.field("default", &&(*__self_0_3));
let _ = builder.field("span", &&(*__self_0_4));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TyParam {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TyParam {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TyParam, __D::Error> {
__arg_0.read_struct("TyParam", 5usize, |_d| -> _ {
::std::result::Result::Ok(TyParam{ident:
match _d.read_struct_field("ident",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bounds:
match _d.read_struct_field("bounds",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
default:
match _d.read_struct_field("default",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TyParam {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } =>
__arg_0.emit_struct("TyParam", 5usize, |_e| -> _ {
match _e.emit_struct_field("ident",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("bounds",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("default",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TyParam {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TyParam {
#[inline]
fn eq(&self, __arg_0: &TyParam) -> bool {
match *__arg_0 {
TyParam {
ident: ref __self_1_0,
id: ref __self_1_1,
bounds: ref __self_1_2,
default: ref __self_1_3,
span: ref __self_1_4 } =>
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4),
},
}
}
#[inline]
fn ne(&self, __arg_0: &TyParam) -> bool {
match *__arg_0 {
TyParam {
ident: ref __self_1_0,
id: ref __self_1_1,
bounds: ref __self_1_2,
default: ref __self_1_3,
span: ref __self_1_4 } =>
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TyParam {
#[inline]
fn clone(&self) -> TyParam {
match *self {
TyParam {
ident: ref __self_0_0,
id: ref __self_0_1,
bounds: ref __self_0_2,
default: ref __self_0_3,
span: ref __self_0_4 } =>
TyParam{ident: ::std::clone::Clone::clone(&(*__self_0_0)),
id: ::std::clone::Clone::clone(&(*__self_0_1)),
bounds: ::std::clone::Clone::clone(&(*__self_0_2)),
default: ::std::clone::Clone::clone(&(*__self_0_3)),
span: ::std::clone::Clone::clone(&(*__self_0_4)),},
}
}
}
/// Represents lifetimes and type parameters attached to a declaration
/// of a function, enum, trait, etc.
pub struct Generics {
pub lifetimes: Vec<LifetimeDef>,
pub ty_params: P<[TyParam]>,
pub where_clause: WhereClause,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Generics {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("Generics");
let _ = builder.field("lifetimes", &&(*__self_0_0));
let _ = builder.field("ty_params", &&(*__self_0_1));
let _ = builder.field("where_clause", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Generics {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Generics {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Generics, __D::Error> {
__arg_0.read_struct("Generics", 3usize, |_d| -> _ {
::std::result::Result::Ok(Generics{lifetimes:
match _d.read_struct_field("lifetimes",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ty_params:
match _d.read_struct_field("ty_params",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
where_clause:
match _d.read_struct_field("where_clause",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Generics {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } =>
__arg_0.emit_struct("Generics", 3usize, |_e| -> _ {
match _e.emit_struct_field("lifetimes",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ty_params",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("where_clause",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Generics {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Generics {
#[inline]
fn eq(&self, __arg_0: &Generics) -> bool {
match *__arg_0 {
Generics {
lifetimes: ref __self_1_0,
ty_params: ref __self_1_1,
where_clause: ref __self_1_2 } =>
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Generics) -> bool {
match *__arg_0 {
Generics {
lifetimes: ref __self_1_0,
ty_params: ref __self_1_1,
where_clause: ref __self_1_2 } =>
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Generics {
#[inline]
fn clone(&self) -> Generics {
match *self {
Generics {
lifetimes: ref __self_0_0,
ty_params: ref __self_0_1,
where_clause: ref __self_0_2 } =>
Generics{lifetimes:
::std::clone::Clone::clone(&(*__self_0_0)),
ty_params:
::std::clone::Clone::clone(&(*__self_0_1)),
where_clause:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl Generics {
pub fn is_lt_parameterized(&self) -> bool {
!self.lifetimes.is_empty()
}
pub fn is_type_parameterized(&self) -> bool {
!self.ty_params.is_empty()
}
pub fn is_parameterized(&self) -> bool {
self.is_lt_parameterized() || self.is_type_parameterized()
}
}
impl Default for Generics {
fn default() -> Generics {
Generics{lifetimes: Vec::new(),
ty_params: P::empty(),
where_clause:
WhereClause{id: DUMMY_NODE_ID,
predicates: Vec::new(),},}
}
}
/// A `where` clause in a definition
pub struct WhereClause {
pub id: NodeId,
pub predicates: Vec<WherePredicate>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for WhereClause {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
WhereClause { id: ref __self_0_0, predicates: ref __self_0_1 }
=> {
let mut builder = __arg_0.debug_struct("WhereClause");
let _ = builder.field("id", &&(*__self_0_0));
let _ = builder.field("predicates", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for WhereClause {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
WhereClause { id: ref __self_0_0, predicates: ref __self_0_1 }
=> {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for WhereClause {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<WhereClause, __D::Error> {
__arg_0.read_struct("WhereClause", 2usize, |_d| -> _ {
::std::result::Result::Ok(WhereClause{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
predicates:
match _d.read_struct_field("predicates",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for WhereClause {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
WhereClause { id: ref __self_0_0, predicates: ref __self_0_1 }
=>
__arg_0.emit_struct("WhereClause", 2usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("predicates",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for WhereClause {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
WhereClause { id: ref __self_0_0, predicates: ref __self_0_1 }
=> {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for WhereClause {
#[inline]
fn eq(&self, __arg_0: &WhereClause) -> bool {
match *__arg_0 {
WhereClause { id: ref __self_1_0, predicates: ref __self_1_1 }
=>
match *self {
WhereClause {
id: ref __self_0_0, predicates: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &WhereClause) -> bool {
match *__arg_0 {
WhereClause { id: ref __self_1_0, predicates: ref __self_1_1 }
=>
match *self {
WhereClause {
id: ref __self_0_0, predicates: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for WhereClause {
#[inline]
fn clone(&self) -> WhereClause {
match *self {
WhereClause { id: ref __self_0_0, predicates: ref __self_0_1 }
=>
WhereClause{id: ::std::clone::Clone::clone(&(*__self_0_0)),
predicates:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
/// A single predicate in a `where` clause
pub enum WherePredicate {
/// A type binding, e.g. `for<'c> Foo: Send+Clone+'c`
BoundPredicate(WhereBoundPredicate),
/// A lifetime predicate, e.g. `'a: 'b+'c`
RegionPredicate(WhereRegionPredicate),
/// An equality predicate (unsupported)
EqPredicate(WhereEqPredicate),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for WherePredicate {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&WherePredicate::BoundPredicate(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("BoundPredicate");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&WherePredicate::RegionPredicate(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("RegionPredicate");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&WherePredicate::EqPredicate(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("EqPredicate");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for WherePredicate {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&WherePredicate::BoundPredicate(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&WherePredicate::RegionPredicate(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&WherePredicate::EqPredicate(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for WherePredicate {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<WherePredicate, __D::Error> {
__arg_0.read_enum("WherePredicate", |_d| -> _ {
_d.read_enum_variant(&["BoundPredicate",
"RegionPredicate",
"EqPredicate"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
WherePredicate::BoundPredicate(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
WherePredicate::RegionPredicate(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
WherePredicate::EqPredicate(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
448u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for WherePredicate {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&WherePredicate::BoundPredicate(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("WherePredicate", |_e| -> _ {
_e.emit_enum_variant("BoundPredicate",
0usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&WherePredicate::RegionPredicate(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("WherePredicate", |_e| -> _ {
_e.emit_enum_variant("RegionPredicate",
1usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&WherePredicate::EqPredicate(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("WherePredicate", |_e| -> _ {
_e.emit_enum_variant("EqPredicate", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for WherePredicate {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&WherePredicate::BoundPredicate(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&WherePredicate::RegionPredicate(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&WherePredicate::EqPredicate(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for WherePredicate {
#[inline]
fn eq(&self, __arg_0: &WherePredicate) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&WherePredicate::BoundPredicate(ref __self_0),
&WherePredicate::BoundPredicate(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&WherePredicate::RegionPredicate(ref __self_0),
&WherePredicate::RegionPredicate(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&WherePredicate::EqPredicate(ref __self_0),
&WherePredicate::EqPredicate(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &WherePredicate) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&WherePredicate::BoundPredicate(ref __self_0),
&WherePredicate::BoundPredicate(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&WherePredicate::RegionPredicate(ref __self_0),
&WherePredicate::RegionPredicate(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&WherePredicate::EqPredicate(ref __self_0),
&WherePredicate::EqPredicate(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for WherePredicate {
#[inline]
fn clone(&self) -> WherePredicate {
match (&*self,) {
(&WherePredicate::BoundPredicate(ref __self_0),) =>
WherePredicate::BoundPredicate(::std::clone::Clone::clone(&(*__self_0))),
(&WherePredicate::RegionPredicate(ref __self_0),) =>
WherePredicate::RegionPredicate(::std::clone::Clone::clone(&(*__self_0))),
(&WherePredicate::EqPredicate(ref __self_0),) =>
WherePredicate::EqPredicate(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
/// A type bound, e.g. `for<'c> Foo: Send+Clone+'c`
pub struct WhereBoundPredicate {
pub span: Span,
/// Any lifetimes from a `for` binding
pub bound_lifetimes: Vec<LifetimeDef>,
/// The type being bounded
pub bounded_ty: P<Ty>,
/// Trait and lifetime bounds (`Clone+Send+'static`)
pub bounds: TyParamBounds,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for WhereBoundPredicate {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } => {
let mut builder =
__arg_0.debug_struct("WhereBoundPredicate");
let _ = builder.field("span", &&(*__self_0_0));
let _ = builder.field("bound_lifetimes", &&(*__self_0_1));
let _ = builder.field("bounded_ty", &&(*__self_0_2));
let _ = builder.field("bounds", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for WhereBoundPredicate {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for WhereBoundPredicate {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<WhereBoundPredicate, __D::Error> {
__arg_0.read_struct("WhereBoundPredicate", 4usize, |_d| -> _ {
::std::result::Result::Ok(WhereBoundPredicate{span:
match _d.read_struct_field("span",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bound_lifetimes:
match _d.read_struct_field("bound_lifetimes",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bounded_ty:
match _d.read_struct_field("bounded_ty",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bounds:
match _d.read_struct_field("bounds",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for WhereBoundPredicate {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } =>
__arg_0.emit_struct("WhereBoundPredicate", 4usize, |_e| -> _ {
match _e.emit_struct_field("span", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("bound_lifetimes",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("bounded_ty",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("bounds",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for WhereBoundPredicate {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for WhereBoundPredicate {
#[inline]
fn eq(&self, __arg_0: &WhereBoundPredicate) -> bool {
match *__arg_0 {
WhereBoundPredicate {
span: ref __self_1_0,
bound_lifetimes: ref __self_1_1,
bounded_ty: ref __self_1_2,
bounds: ref __self_1_3 } =>
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &WhereBoundPredicate) -> bool {
match *__arg_0 {
WhereBoundPredicate {
span: ref __self_1_0,
bound_lifetimes: ref __self_1_1,
bounded_ty: ref __self_1_2,
bounds: ref __self_1_3 } =>
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for WhereBoundPredicate {
#[inline]
fn clone(&self) -> WhereBoundPredicate {
match *self {
WhereBoundPredicate {
span: ref __self_0_0,
bound_lifetimes: ref __self_0_1,
bounded_ty: ref __self_0_2,
bounds: ref __self_0_3 } =>
WhereBoundPredicate{span:
::std::clone::Clone::clone(&(*__self_0_0)),
bound_lifetimes:
::std::clone::Clone::clone(&(*__self_0_1)),
bounded_ty:
::std::clone::Clone::clone(&(*__self_0_2)),
bounds:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
/// A lifetime predicate, e.g. `'a: 'b+'c`
pub struct WhereRegionPredicate {
pub span: Span,
pub lifetime: Lifetime,
pub bounds: Vec<Lifetime>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for WhereRegionPredicate {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } => {
let mut builder =
__arg_0.debug_struct("WhereRegionPredicate");
let _ = builder.field("span", &&(*__self_0_0));
let _ = builder.field("lifetime", &&(*__self_0_1));
let _ = builder.field("bounds", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for WhereRegionPredicate {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for WhereRegionPredicate {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<WhereRegionPredicate, __D::Error> {
__arg_0.read_struct("WhereRegionPredicate", 3usize, |_d| -> _ {
::std::result::Result::Ok(WhereRegionPredicate{span:
match _d.read_struct_field("span",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
lifetime:
match _d.read_struct_field("lifetime",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bounds:
match _d.read_struct_field("bounds",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for WhereRegionPredicate {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } =>
__arg_0.emit_struct("WhereRegionPredicate", 3usize,
|_e| -> _ {
match _e.emit_struct_field("span", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("lifetime",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("bounds",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for WhereRegionPredicate {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for WhereRegionPredicate {
#[inline]
fn eq(&self, __arg_0: &WhereRegionPredicate) -> bool {
match *__arg_0 {
WhereRegionPredicate {
span: ref __self_1_0,
lifetime: ref __self_1_1,
bounds: ref __self_1_2 } =>
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &WhereRegionPredicate) -> bool {
match *__arg_0 {
WhereRegionPredicate {
span: ref __self_1_0,
lifetime: ref __self_1_1,
bounds: ref __self_1_2 } =>
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for WhereRegionPredicate {
#[inline]
fn clone(&self) -> WhereRegionPredicate {
match *self {
WhereRegionPredicate {
span: ref __self_0_0,
lifetime: ref __self_0_1,
bounds: ref __self_0_2 } =>
WhereRegionPredicate{span:
::std::clone::Clone::clone(&(*__self_0_0)),
lifetime:
::std::clone::Clone::clone(&(*__self_0_1)),
bounds:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
/// An equality predicate (unsupported), e.g. `T=int`
pub struct WhereEqPredicate {
pub id: NodeId,
pub span: Span,
pub path: Path,
pub ty: P<Ty>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for WhereEqPredicate {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } => {
let mut builder =
__arg_0.debug_struct("WhereEqPredicate");
let _ = builder.field("id", &&(*__self_0_0));
let _ = builder.field("span", &&(*__self_0_1));
let _ = builder.field("path", &&(*__self_0_2));
let _ = builder.field("ty", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for WhereEqPredicate {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for WhereEqPredicate {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<WhereEqPredicate, __D::Error> {
__arg_0.read_struct("WhereEqPredicate", 4usize, |_d| -> _ {
::std::result::Result::Ok(WhereEqPredicate{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
path:
match _d.read_struct_field("path",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ty:
match _d.read_struct_field("ty",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for WhereEqPredicate {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } =>
__arg_0.emit_struct("WhereEqPredicate", 4usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("path", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("ty", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for WhereEqPredicate {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for WhereEqPredicate {
#[inline]
fn eq(&self, __arg_0: &WhereEqPredicate) -> bool {
match *__arg_0 {
WhereEqPredicate {
id: ref __self_1_0,
span: ref __self_1_1,
path: ref __self_1_2,
ty: ref __self_1_3 } =>
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &WhereEqPredicate) -> bool {
match *__arg_0 {
WhereEqPredicate {
id: ref __self_1_0,
span: ref __self_1_1,
path: ref __self_1_2,
ty: ref __self_1_3 } =>
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for WhereEqPredicate {
#[inline]
fn clone(&self) -> WhereEqPredicate {
match *self {
WhereEqPredicate {
id: ref __self_0_0,
span: ref __self_0_1,
path: ref __self_0_2,
ty: ref __self_0_3 } =>
WhereEqPredicate{id:
::std::clone::Clone::clone(&(*__self_0_0)),
span:
::std::clone::Clone::clone(&(*__self_0_1)),
path:
::std::clone::Clone::clone(&(*__self_0_2)),
ty:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
/// The set of MetaItems that define the compilation environment of the crate,
/// used to drive conditional compilation
pub type CrateConfig = Vec<P<MetaItem>>;
pub struct Crate {
pub module: Mod,
pub attrs: Vec<Attribute>,
pub config: CrateConfig,
pub span: Span,
pub exported_macros: Vec<MacroDef>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Crate {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } => {
let mut builder = __arg_0.debug_struct("Crate");
let _ = builder.field("module", &&(*__self_0_0));
let _ = builder.field("attrs", &&(*__self_0_1));
let _ = builder.field("config", &&(*__self_0_2));
let _ = builder.field("span", &&(*__self_0_3));
let _ = builder.field("exported_macros", &&(*__self_0_4));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Crate {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Crate {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Crate, __D::Error> {
__arg_0.read_struct("Crate", 5usize, |_d| -> _ {
::std::result::Result::Ok(Crate{module:
match _d.read_struct_field("module",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
config:
match _d.read_struct_field("config",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
exported_macros:
match _d.read_struct_field("exported_macros",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Crate {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } =>
__arg_0.emit_struct("Crate", 5usize, |_e| -> _ {
match _e.emit_struct_field("module",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("config",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("exported_macros",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Crate {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Crate {
#[inline]
fn eq(&self, __arg_0: &Crate) -> bool {
match *__arg_0 {
Crate {
module: ref __self_1_0,
attrs: ref __self_1_1,
config: ref __self_1_2,
span: ref __self_1_3,
exported_macros: ref __self_1_4 } =>
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Crate) -> bool {
match *__arg_0 {
Crate {
module: ref __self_1_0,
attrs: ref __self_1_1,
config: ref __self_1_2,
span: ref __self_1_3,
exported_macros: ref __self_1_4 } =>
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Crate {
#[inline]
fn clone(&self) -> Crate {
match *self {
Crate {
module: ref __self_0_0,
attrs: ref __self_0_1,
config: ref __self_0_2,
span: ref __self_0_3,
exported_macros: ref __self_0_4 } =>
Crate{module: ::std::clone::Clone::clone(&(*__self_0_0)),
attrs: ::std::clone::Clone::clone(&(*__self_0_1)),
config: ::std::clone::Clone::clone(&(*__self_0_2)),
span: ::std::clone::Clone::clone(&(*__self_0_3)),
exported_macros:
::std::clone::Clone::clone(&(*__self_0_4)),},
}
}
}
pub type MetaItem = Spanned<MetaItem_>;
pub enum MetaItem_ {
MetaWord(InternedString),
MetaList(InternedString, Vec<P<MetaItem>>),
MetaNameValue(InternedString, Lit),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for MetaItem_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&MetaItem_::MetaWord(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("MetaWord");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&MetaItem_::MetaList(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("MetaList");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&MetaItem_::MetaNameValue(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("MetaNameValue");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for MetaItem_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&MetaItem_::MetaWord(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&MetaItem_::MetaList(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&MetaItem_::MetaNameValue(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for MetaItem_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<MetaItem_, __D::Error> {
__arg_0.read_enum("MetaItem_", |_d| -> _ {
_d.read_enum_variant(&["MetaWord", "MetaList",
"MetaNameValue"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
MetaItem_::MetaWord(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
MetaItem_::MetaList(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
MetaItem_::MetaNameValue(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
502u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for MetaItem_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&MetaItem_::MetaWord(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("MetaItem_", |_e| -> _ {
_e.emit_enum_variant("MetaWord", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&MetaItem_::MetaList(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("MetaItem_", |_e| -> _ {
_e.emit_enum_variant("MetaList", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&MetaItem_::MetaNameValue(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("MetaItem_", |_e| -> _ {
_e.emit_enum_variant("MetaNameValue", 2usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MetaItem_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&MetaItem_::MetaWord(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&MetaItem_::MetaList(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&MetaItem_::MetaNameValue(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MetaItem_ {
#[inline]
fn clone(&self) -> MetaItem_ {
match (&*self,) {
(&MetaItem_::MetaWord(ref __self_0),) =>
MetaItem_::MetaWord(::std::clone::Clone::clone(&(*__self_0))),
(&MetaItem_::MetaList(ref __self_0, ref __self_1),) =>
MetaItem_::MetaList(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&MetaItem_::MetaNameValue(ref __self_0, ref __self_1),) =>
MetaItem_::MetaNameValue(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
impl PartialEq for MetaItem_ {
fn eq(&self, other: &MetaItem_) -> bool {
match *self {
MetaWord(ref ns) =>
match *other {
MetaWord(ref no) => (*ns) == (*no),
_ => false,
},
MetaNameValue(ref ns, ref vs) =>
match *other {
MetaNameValue(ref no, ref vo) => {
(*ns) == (*no) && vs.node == vo.node
}
_ => false,
},
MetaList(ref ns, ref miss) =>
match *other {
MetaList(ref no, ref miso) => {
ns == no &&
miss.iter().all(|mi|
miso.iter().any(|x|
x.node ==
mi.node))
}
_ => false,
},
}
}
}
pub struct Block {
/// Statements in a block
pub stmts: Vec<P<Stmt>>,
/// An expression at the end of the block
/// without a semicolon, if any
pub expr: Option<P<Expr>>,
pub id: NodeId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`
pub rules: BlockCheckMode,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Block {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } => {
let mut builder = __arg_0.debug_struct("Block");
let _ = builder.field("stmts", &&(*__self_0_0));
let _ = builder.field("expr", &&(*__self_0_1));
let _ = builder.field("id", &&(*__self_0_2));
let _ = builder.field("rules", &&(*__self_0_3));
let _ = builder.field("span", &&(*__self_0_4));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Block {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Block {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Block, __D::Error> {
__arg_0.read_struct("Block", 5usize, |_d| -> _ {
::std::result::Result::Ok(Block{stmts:
match _d.read_struct_field("stmts",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
expr:
match _d.read_struct_field("expr",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
rules:
match _d.read_struct_field("rules",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Block {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } =>
__arg_0.emit_struct("Block", 5usize, |_e| -> _ {
match _e.emit_struct_field("stmts",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("expr", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("rules",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Block {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Block {
#[inline]
fn eq(&self, __arg_0: &Block) -> bool {
match *__arg_0 {
Block {
stmts: ref __self_1_0,
expr: ref __self_1_1,
id: ref __self_1_2,
rules: ref __self_1_3,
span: ref __self_1_4 } =>
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Block) -> bool {
match *__arg_0 {
Block {
stmts: ref __self_1_0,
expr: ref __self_1_1,
id: ref __self_1_2,
rules: ref __self_1_3,
span: ref __self_1_4 } =>
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Block {
#[inline]
fn clone(&self) -> Block {
match *self {
Block {
stmts: ref __self_0_0,
expr: ref __self_0_1,
id: ref __self_0_2,
rules: ref __self_0_3,
span: ref __self_0_4 } =>
Block{stmts: ::std::clone::Clone::clone(&(*__self_0_0)),
expr: ::std::clone::Clone::clone(&(*__self_0_1)),
id: ::std::clone::Clone::clone(&(*__self_0_2)),
rules: ::std::clone::Clone::clone(&(*__self_0_3)),
span: ::std::clone::Clone::clone(&(*__self_0_4)),},
}
}
}
pub struct Pat {
pub id: NodeId,
pub node: Pat_,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Pat {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Pat {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Pat {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Pat, __D::Error> {
__arg_0.read_struct("Pat", 3usize, |_d| -> _ {
::std::result::Result::Ok(Pat{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Pat {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Pat {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} =>
__arg_0.emit_struct("Pat", 3usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Pat {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Pat {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Pat {
#[inline]
fn eq(&self, __arg_0: &Pat) -> bool {
match *__arg_0 {
Pat {
id: ref __self_1_0, node: ref __self_1_1, span: ref __self_1_2
} =>
match *self {
Pat {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Pat) -> bool {
match *__arg_0 {
Pat {
id: ref __self_1_0, node: ref __self_1_1, span: ref __self_1_2
} =>
match *self {
Pat {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Pat {
#[inline]
fn clone(&self) -> Pat {
match *self {
Pat {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} =>
Pat{id: ::std::clone::Clone::clone(&(*__self_0_0)),
node: ::std::clone::Clone::clone(&(*__self_0_1)),
span: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl fmt::Debug for Pat {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pat(", ": ",
")"];
__STATIC_FMTSTR
},
&match (&self.id,
&pprust::pat_to_string(self))
{
(__arg0, __arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
}
/// A single field in a struct pattern
///
/// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
/// are treated the same as` x: x, y: ref y, z: ref mut z`,
/// except is_shorthand is true
pub struct FieldPat {
/// The identifier for the field
pub ident: Ident,
/// The pattern the field is destructured to
pub pat: P<Pat>,
pub is_shorthand: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for FieldPat {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("FieldPat");
let _ = builder.field("ident", &&(*__self_0_0));
let _ = builder.field("pat", &&(*__self_0_1));
let _ = builder.field("is_shorthand", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for FieldPat {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for FieldPat {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<FieldPat, __D::Error> {
__arg_0.read_struct("FieldPat", 3usize, |_d| -> _ {
::std::result::Result::Ok(FieldPat{ident:
match _d.read_struct_field("ident",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
pat:
match _d.read_struct_field("pat",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
is_shorthand:
match _d.read_struct_field("is_shorthand",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for FieldPat {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } =>
__arg_0.emit_struct("FieldPat", 3usize, |_e| -> _ {
match _e.emit_struct_field("ident",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("pat", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("is_shorthand",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for FieldPat {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for FieldPat {
#[inline]
fn eq(&self, __arg_0: &FieldPat) -> bool {
match *__arg_0 {
FieldPat {
ident: ref __self_1_0,
pat: ref __self_1_1,
is_shorthand: ref __self_1_2 } =>
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &FieldPat) -> bool {
match *__arg_0 {
FieldPat {
ident: ref __self_1_0,
pat: ref __self_1_1,
is_shorthand: ref __self_1_2 } =>
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for FieldPat {
#[inline]
fn clone(&self) -> FieldPat {
match *self {
FieldPat {
ident: ref __self_0_0,
pat: ref __self_0_1,
is_shorthand: ref __self_0_2 } =>
FieldPat{ident: ::std::clone::Clone::clone(&(*__self_0_0)),
pat: ::std::clone::Clone::clone(&(*__self_0_1)),
is_shorthand:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub enum BindingMode { ByRef(Mutability), ByValue(Mutability), }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BindingMode { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for BindingMode {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&BindingMode::ByRef(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ByRef");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&BindingMode::ByValue(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ByValue");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for BindingMode {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&BindingMode::ByRef(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&BindingMode::ByValue(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for BindingMode {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<BindingMode, __D::Error> {
__arg_0.read_enum("BindingMode", |_d| -> _ {
_d.read_enum_variant(&["ByRef", "ByValue"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
BindingMode::ByRef(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
BindingMode::ByValue(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
574u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for BindingMode {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&BindingMode::ByRef(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("BindingMode", |_e| -> _ {
_e.emit_enum_variant("ByRef", 0usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&BindingMode::ByValue(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("BindingMode", |_e| -> _ {
_e.emit_enum_variant("ByValue", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for BindingMode {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&BindingMode::ByRef(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&BindingMode::ByValue(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for BindingMode {
#[inline]
fn eq(&self, __arg_0: &BindingMode) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BindingMode::ByRef(ref __self_0),
&BindingMode::ByRef(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&BindingMode::ByValue(ref __self_0),
&BindingMode::ByValue(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &BindingMode) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BindingMode::ByRef(ref __self_0),
&BindingMode::ByRef(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&BindingMode::ByValue(ref __self_0),
&BindingMode::ByValue(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BindingMode {
#[inline]
fn clone(&self) -> BindingMode {
match (&*self,) {
(&BindingMode::ByRef(ref __self_0),) =>
BindingMode::ByRef(::std::clone::Clone::clone(&(*__self_0))),
(&BindingMode::ByValue(ref __self_0),) =>
BindingMode::ByValue(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum Pat_ {
/// Represents a wildcard pattern (`_`)
PatWild,
/// A PatIdent may either be a new bound variable,
/// or a nullary enum (in which case the third field
/// is None).
///
/// In the nullary enum case, the parser can't determine
/// which it is. The resolver determines this, and
/// records this pattern's NodeId in an auxiliary
/// set (of "PatIdents that refer to nullary enums")
PatIdent(BindingMode, SpannedIdent, Option<P<Pat>>),
/// "None" means a `Variant(..)` pattern where we don't bind the fields to names.
PatEnum(Path, Option<Vec<P<Pat>>>),
/// An associated const named using the qualified path `<T>::CONST` or
/// `<T as Trait>::CONST`. Associated consts from inherent impls can be
/// referred to as simply `T::CONST`, in which case they will end up as
/// PatEnum, and the resolver will have to sort that out.
PatQPath(QSelf, Path),
/// Destructuring of a struct, e.g. `Foo {x, y, ..}`
/// The `bool` is `true` in the presence of a `..`
PatStruct(Path, Vec<Spanned<FieldPat>>, bool),
/// A tuple pattern `(a, b)`
PatTup(Vec<P<Pat>>),
/// A `box` pattern
PatBox(P<Pat>),
/// A reference pattern, e.g. `&mut (a, b)`
PatRegion(P<Pat>, Mutability),
/// A literal
PatLit(P<Expr>),
/// A range pattern, e.g. `1...2`
PatRange(P<Expr>, P<Expr>),
/// `[a, b, ..i, y, z]` is represented as:
/// `PatVec(box [a, b], Some(i), box [y, z])`
PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
/// A macro pattern; pre-expansion
PatMac(Mac),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Pat_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Pat_::PatWild,) => {
let mut builder = __arg_0.debug_tuple("PatWild");
builder.finish()
}
(&Pat_::PatIdent(ref __self_0, ref __self_1, ref __self_2),)
=> {
let mut builder = __arg_0.debug_tuple("PatIdent");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Pat_::PatEnum(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("PatEnum");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Pat_::PatQPath(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("PatQPath");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Pat_::PatStruct(ref __self_0, ref __self_1, ref __self_2),)
=> {
let mut builder = __arg_0.debug_tuple("PatStruct");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Pat_::PatTup(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("PatTup");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Pat_::PatBox(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("PatBox");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Pat_::PatRegion(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("PatRegion");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Pat_::PatLit(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("PatLit");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Pat_::PatRange(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("PatRange");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Pat_::PatVec(ref __self_0, ref __self_1, ref __self_2),) =>
{
let mut builder = __arg_0.debug_tuple("PatVec");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Pat_::PatMac(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("PatMac");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Pat_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Pat_::PatWild,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Pat_::PatIdent(ref __self_0, ref __self_1, ref __self_2),)
=> {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Pat_::PatEnum(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Pat_::PatQPath(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Pat_::PatStruct(ref __self_0, ref __self_1, ref __self_2),)
=> {
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Pat_::PatTup(ref __self_0),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Pat_::PatBox(ref __self_0),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Pat_::PatRegion(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Pat_::PatLit(ref __self_0),) => {
::std::hash::Hash::hash(&8usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Pat_::PatRange(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&9usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Pat_::PatVec(ref __self_0, ref __self_1, ref __self_2),) =>
{
::std::hash::Hash::hash(&10usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Pat_::PatMac(ref __self_0),) => {
::std::hash::Hash::hash(&11usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Pat_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Pat_, __D::Error> {
__arg_0.read_enum("Pat_", |_d| -> _ {
_d.read_enum_variant(&["PatWild", "PatIdent",
"PatEnum", "PatQPath",
"PatStruct", "PatTup",
"PatBox", "PatRegion",
"PatLit", "PatRange",
"PatVec", "PatMac"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Pat_::PatWild,
1usize
=>
Pat_::PatIdent(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Pat_::PatEnum(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Pat_::PatQPath(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Pat_::PatStruct(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Pat_::PatTup(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Pat_::PatBox(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Pat_::PatRegion(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
8usize
=>
Pat_::PatLit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
9usize
=>
Pat_::PatRange(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
10usize
=>
Pat_::PatVec(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
11usize
=>
Pat_::PatMac(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
580u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Pat_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Pat_::PatWild,) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatWild", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Pat_::PatIdent(ref __self_0, ref __self_1, ref __self_2),)
=> {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatIdent", 1usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Pat_::PatEnum(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatEnum", 2usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Pat_::PatQPath(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatQPath", 3usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Pat_::PatStruct(ref __self_0, ref __self_1, ref __self_2),)
=> {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatStruct", 4usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Pat_::PatTup(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatTup", 5usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Pat_::PatBox(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatBox", 6usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Pat_::PatRegion(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatRegion", 7usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Pat_::PatLit(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatLit", 8usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Pat_::PatRange(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatRange", 9usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Pat_::PatVec(ref __self_0, ref __self_1, ref __self_2),) =>
{
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatVec", 10usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Pat_::PatMac(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Pat_", |_e| -> _ {
_e.emit_enum_variant("PatMac", 11usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Pat_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Pat_::PatWild,) => { }
(&Pat_::PatIdent(ref __self_0, ref __self_1, ref __self_2),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Pat_::PatEnum(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Pat_::PatQPath(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Pat_::PatStruct(ref __self_0, ref __self_1, ref __self_2),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Pat_::PatTup(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Pat_::PatBox(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Pat_::PatRegion(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Pat_::PatLit(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Pat_::PatRange(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Pat_::PatVec(ref __self_0, ref __self_1, ref __self_2),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Pat_::PatMac(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Pat_ {
#[inline]
fn eq(&self, __arg_0: &Pat_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Pat_::PatWild, &Pat_::PatWild) => true,
(&Pat_::PatIdent(ref __self_0, ref __self_1,
ref __self_2),
&Pat_::PatIdent(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Pat_::PatEnum(ref __self_0, ref __self_1),
&Pat_::PatEnum(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Pat_::PatQPath(ref __self_0, ref __self_1),
&Pat_::PatQPath(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Pat_::PatStruct(ref __self_0, ref __self_1,
ref __self_2),
&Pat_::PatStruct(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Pat_::PatTup(ref __self_0),
&Pat_::PatTup(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Pat_::PatBox(ref __self_0),
&Pat_::PatBox(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Pat_::PatRegion(ref __self_0, ref __self_1),
&Pat_::PatRegion(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Pat_::PatLit(ref __self_0),
&Pat_::PatLit(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Pat_::PatRange(ref __self_0, ref __self_1),
&Pat_::PatRange(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Pat_::PatVec(ref __self_0, ref __self_1,
ref __self_2),
&Pat_::PatVec(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Pat_::PatMac(ref __self_0),
&Pat_::PatMac(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Pat_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Pat_::PatWild, &Pat_::PatWild) => false,
(&Pat_::PatIdent(ref __self_0, ref __self_1,
ref __self_2),
&Pat_::PatIdent(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Pat_::PatEnum(ref __self_0, ref __self_1),
&Pat_::PatEnum(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Pat_::PatQPath(ref __self_0, ref __self_1),
&Pat_::PatQPath(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Pat_::PatStruct(ref __self_0, ref __self_1,
ref __self_2),
&Pat_::PatStruct(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Pat_::PatTup(ref __self_0),
&Pat_::PatTup(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Pat_::PatBox(ref __self_0),
&Pat_::PatBox(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Pat_::PatRegion(ref __self_0, ref __self_1),
&Pat_::PatRegion(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Pat_::PatLit(ref __self_0),
&Pat_::PatLit(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Pat_::PatRange(ref __self_0, ref __self_1),
&Pat_::PatRange(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Pat_::PatVec(ref __self_0, ref __self_1,
ref __self_2),
&Pat_::PatVec(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Pat_::PatMac(ref __self_0),
&Pat_::PatMac(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Pat_ {
#[inline]
fn clone(&self) -> Pat_ {
match (&*self,) {
(&Pat_::PatWild,) => Pat_::PatWild,
(&Pat_::PatIdent(ref __self_0, ref __self_1, ref __self_2),)
=>
Pat_::PatIdent(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Pat_::PatEnum(ref __self_0, ref __self_1),) =>
Pat_::PatEnum(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Pat_::PatQPath(ref __self_0, ref __self_1),) =>
Pat_::PatQPath(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Pat_::PatStruct(ref __self_0, ref __self_1, ref __self_2),)
=>
Pat_::PatStruct(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Pat_::PatTup(ref __self_0),) =>
Pat_::PatTup(::std::clone::Clone::clone(&(*__self_0))),
(&Pat_::PatBox(ref __self_0),) =>
Pat_::PatBox(::std::clone::Clone::clone(&(*__self_0))),
(&Pat_::PatRegion(ref __self_0, ref __self_1),) =>
Pat_::PatRegion(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Pat_::PatLit(ref __self_0),) =>
Pat_::PatLit(::std::clone::Clone::clone(&(*__self_0))),
(&Pat_::PatRange(ref __self_0, ref __self_1),) =>
Pat_::PatRange(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Pat_::PatVec(ref __self_0, ref __self_1, ref __self_2),) =>
Pat_::PatVec(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Pat_::PatMac(ref __self_0),) =>
Pat_::PatMac(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum Mutability { MutMutable, MutImmutable, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Mutability { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Mutability {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Mutability::MutMutable,) => {
let mut builder = __arg_0.debug_tuple("MutMutable");
builder.finish()
}
(&Mutability::MutImmutable,) => {
let mut builder = __arg_0.debug_tuple("MutImmutable");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Mutability {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Mutability::MutMutable,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Mutability::MutImmutable,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Mutability {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Mutability, __D::Error> {
__arg_0.read_enum("Mutability", |_d| -> _ {
_d.read_enum_variant(&["MutMutable",
"MutImmutable"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Mutability::MutMutable,
1usize
=>
Mutability::MutImmutable,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
624u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Mutability {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Mutability::MutMutable,) => {
let _e = __arg_0;
_e.emit_enum("Mutability", |_e| -> _ {
_e.emit_enum_variant("MutMutable", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Mutability::MutImmutable,) => {
let _e = __arg_0;
_e.emit_enum("Mutability", |_e| -> _ {
_e.emit_enum_variant("MutImmutable", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Mutability {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Mutability::MutMutable,) => { }
(&Mutability::MutImmutable,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Mutability {
#[inline]
fn eq(&self, __arg_0: &Mutability) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Mutability::MutMutable, &Mutability::MutMutable) =>
true,
(&Mutability::MutImmutable, &Mutability::MutImmutable)
=> true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Mutability) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Mutability::MutMutable, &Mutability::MutMutable) =>
false,
(&Mutability::MutImmutable, &Mutability::MutImmutable)
=> false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Mutability {
#[inline]
fn clone(&self) -> Mutability {
match (&*self,) {
(&Mutability::MutMutable,) => Mutability::MutMutable,
(&Mutability::MutImmutable,) => Mutability::MutImmutable,
}
}
}
pub enum BinOp_ {
/// The `+` operator (addition)
BiAdd,
/// The `-` operator (subtraction)
BiSub,
/// The `*` operator (multiplication)
BiMul,
/// The `/` operator (division)
BiDiv,
/// The `%` operator (modulus)
BiRem,
/// The `&&` operator (logical and)
BiAnd,
/// The `||` operator (logical or)
BiOr,
/// The `^` operator (bitwise xor)
BiBitXor,
/// The `&` operator (bitwise and)
BiBitAnd,
/// The `|` operator (bitwise or)
BiBitOr,
/// The `<<` operator (shift left)
BiShl,
/// The `>>` operator (shift right)
BiShr,
/// The `==` operator (equality)
BiEq,
/// The `<` operator (less than)
BiLt,
/// The `<=` operator (less than or equal to)
BiLe,
/// The `!=` operator (not equal to)
BiNe,
/// The `>=` operator (greater than or equal to)
BiGe,
/// The `>` operator (greater than)
BiGt,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BinOp_ { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for BinOp_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&BinOp_::BiAdd,) => {
let mut builder = __arg_0.debug_tuple("BiAdd");
builder.finish()
}
(&BinOp_::BiSub,) => {
let mut builder = __arg_0.debug_tuple("BiSub");
builder.finish()
}
(&BinOp_::BiMul,) => {
let mut builder = __arg_0.debug_tuple("BiMul");
builder.finish()
}
(&BinOp_::BiDiv,) => {
let mut builder = __arg_0.debug_tuple("BiDiv");
builder.finish()
}
(&BinOp_::BiRem,) => {
let mut builder = __arg_0.debug_tuple("BiRem");
builder.finish()
}
(&BinOp_::BiAnd,) => {
let mut builder = __arg_0.debug_tuple("BiAnd");
builder.finish()
}
(&BinOp_::BiOr,) => {
let mut builder = __arg_0.debug_tuple("BiOr");
builder.finish()
}
(&BinOp_::BiBitXor,) => {
let mut builder = __arg_0.debug_tuple("BiBitXor");
builder.finish()
}
(&BinOp_::BiBitAnd,) => {
let mut builder = __arg_0.debug_tuple("BiBitAnd");
builder.finish()
}
(&BinOp_::BiBitOr,) => {
let mut builder = __arg_0.debug_tuple("BiBitOr");
builder.finish()
}
(&BinOp_::BiShl,) => {
let mut builder = __arg_0.debug_tuple("BiShl");
builder.finish()
}
(&BinOp_::BiShr,) => {
let mut builder = __arg_0.debug_tuple("BiShr");
builder.finish()
}
(&BinOp_::BiEq,) => {
let mut builder = __arg_0.debug_tuple("BiEq");
builder.finish()
}
(&BinOp_::BiLt,) => {
let mut builder = __arg_0.debug_tuple("BiLt");
builder.finish()
}
(&BinOp_::BiLe,) => {
let mut builder = __arg_0.debug_tuple("BiLe");
builder.finish()
}
(&BinOp_::BiNe,) => {
let mut builder = __arg_0.debug_tuple("BiNe");
builder.finish()
}
(&BinOp_::BiGe,) => {
let mut builder = __arg_0.debug_tuple("BiGe");
builder.finish()
}
(&BinOp_::BiGt,) => {
let mut builder = __arg_0.debug_tuple("BiGt");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for BinOp_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&BinOp_::BiAdd,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&BinOp_::BiSub,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&BinOp_::BiMul,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
(&BinOp_::BiDiv,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&BinOp_::BiRem,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
(&BinOp_::BiAnd,) => {
::std::hash::Hash::hash(&5usize, __arg_0);
}
(&BinOp_::BiOr,) => {
::std::hash::Hash::hash(&6usize, __arg_0);
}
(&BinOp_::BiBitXor,) => {
::std::hash::Hash::hash(&7usize, __arg_0);
}
(&BinOp_::BiBitAnd,) => {
::std::hash::Hash::hash(&8usize, __arg_0);
}
(&BinOp_::BiBitOr,) => {
::std::hash::Hash::hash(&9usize, __arg_0);
}
(&BinOp_::BiShl,) => {
::std::hash::Hash::hash(&10usize, __arg_0);
}
(&BinOp_::BiShr,) => {
::std::hash::Hash::hash(&11usize, __arg_0);
}
(&BinOp_::BiEq,) => {
::std::hash::Hash::hash(&12usize, __arg_0);
}
(&BinOp_::BiLt,) => {
::std::hash::Hash::hash(&13usize, __arg_0);
}
(&BinOp_::BiLe,) => {
::std::hash::Hash::hash(&14usize, __arg_0);
}
(&BinOp_::BiNe,) => {
::std::hash::Hash::hash(&15usize, __arg_0);
}
(&BinOp_::BiGe,) => {
::std::hash::Hash::hash(&16usize, __arg_0);
}
(&BinOp_::BiGt,) => {
::std::hash::Hash::hash(&17usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for BinOp_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<BinOp_, __D::Error> {
__arg_0.read_enum("BinOp_", |_d| -> _ {
_d.read_enum_variant(&["BiAdd", "BiSub",
"BiMul", "BiDiv",
"BiRem", "BiAnd", "BiOr",
"BiBitXor", "BiBitAnd",
"BiBitOr", "BiShl",
"BiShr", "BiEq", "BiLt",
"BiLe", "BiNe", "BiGe",
"BiGt"], |_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
BinOp_::BiAdd,
1usize
=>
BinOp_::BiSub,
2usize
=>
BinOp_::BiMul,
3usize
=>
BinOp_::BiDiv,
4usize
=>
BinOp_::BiRem,
5usize
=>
BinOp_::BiAnd,
6usize
=>
BinOp_::BiOr,
7usize
=>
BinOp_::BiBitXor,
8usize
=>
BinOp_::BiBitAnd,
9usize
=>
BinOp_::BiBitOr,
10usize
=>
BinOp_::BiShl,
11usize
=>
BinOp_::BiShr,
12usize
=>
BinOp_::BiEq,
13usize
=>
BinOp_::BiLt,
14usize
=>
BinOp_::BiLe,
15usize
=>
BinOp_::BiNe,
16usize
=>
BinOp_::BiGe,
17usize
=>
BinOp_::BiGt,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
630u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for BinOp_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&BinOp_::BiAdd,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiAdd", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiSub,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiSub", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiMul,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiMul", 2usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiDiv,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiDiv", 3usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiRem,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiRem", 4usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiAnd,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiAnd", 5usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiOr,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiOr", 6usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiBitXor,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiBitXor", 7usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiBitAnd,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiBitAnd", 8usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiBitOr,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiBitOr", 9usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiShl,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiShl", 10usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiShr,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiShr", 11usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiEq,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiEq", 12usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiLt,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiLt", 13usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiLe,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiLe", 14usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiNe,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiNe", 15usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiGe,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiGe", 16usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOp_::BiGt,) => {
let _e = __arg_0;
_e.emit_enum("BinOp_", |_e| -> _ {
_e.emit_enum_variant("BiGt", 17usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for BinOp_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&BinOp_::BiAdd,) => { }
(&BinOp_::BiSub,) => { }
(&BinOp_::BiMul,) => { }
(&BinOp_::BiDiv,) => { }
(&BinOp_::BiRem,) => { }
(&BinOp_::BiAnd,) => { }
(&BinOp_::BiOr,) => { }
(&BinOp_::BiBitXor,) => { }
(&BinOp_::BiBitAnd,) => { }
(&BinOp_::BiBitOr,) => { }
(&BinOp_::BiShl,) => { }
(&BinOp_::BiShr,) => { }
(&BinOp_::BiEq,) => { }
(&BinOp_::BiLt,) => { }
(&BinOp_::BiLe,) => { }
(&BinOp_::BiNe,) => { }
(&BinOp_::BiGe,) => { }
(&BinOp_::BiGt,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for BinOp_ {
#[inline]
fn eq(&self, __arg_0: &BinOp_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BinOp_::BiAdd, &BinOp_::BiAdd) => true,
(&BinOp_::BiSub, &BinOp_::BiSub) => true,
(&BinOp_::BiMul, &BinOp_::BiMul) => true,
(&BinOp_::BiDiv, &BinOp_::BiDiv) => true,
(&BinOp_::BiRem, &BinOp_::BiRem) => true,
(&BinOp_::BiAnd, &BinOp_::BiAnd) => true,
(&BinOp_::BiOr, &BinOp_::BiOr) => true,
(&BinOp_::BiBitXor, &BinOp_::BiBitXor) => true,
(&BinOp_::BiBitAnd, &BinOp_::BiBitAnd) => true,
(&BinOp_::BiBitOr, &BinOp_::BiBitOr) => true,
(&BinOp_::BiShl, &BinOp_::BiShl) => true,
(&BinOp_::BiShr, &BinOp_::BiShr) => true,
(&BinOp_::BiEq, &BinOp_::BiEq) => true,
(&BinOp_::BiLt, &BinOp_::BiLt) => true,
(&BinOp_::BiLe, &BinOp_::BiLe) => true,
(&BinOp_::BiNe, &BinOp_::BiNe) => true,
(&BinOp_::BiGe, &BinOp_::BiGe) => true,
(&BinOp_::BiGt, &BinOp_::BiGt) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &BinOp_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BinOp_::BiAdd, &BinOp_::BiAdd) => false,
(&BinOp_::BiSub, &BinOp_::BiSub) => false,
(&BinOp_::BiMul, &BinOp_::BiMul) => false,
(&BinOp_::BiDiv, &BinOp_::BiDiv) => false,
(&BinOp_::BiRem, &BinOp_::BiRem) => false,
(&BinOp_::BiAnd, &BinOp_::BiAnd) => false,
(&BinOp_::BiOr, &BinOp_::BiOr) => false,
(&BinOp_::BiBitXor, &BinOp_::BiBitXor) => false,
(&BinOp_::BiBitAnd, &BinOp_::BiBitAnd) => false,
(&BinOp_::BiBitOr, &BinOp_::BiBitOr) => false,
(&BinOp_::BiShl, &BinOp_::BiShl) => false,
(&BinOp_::BiShr, &BinOp_::BiShr) => false,
(&BinOp_::BiEq, &BinOp_::BiEq) => false,
(&BinOp_::BiLt, &BinOp_::BiLt) => false,
(&BinOp_::BiLe, &BinOp_::BiLe) => false,
(&BinOp_::BiNe, &BinOp_::BiNe) => false,
(&BinOp_::BiGe, &BinOp_::BiGe) => false,
(&BinOp_::BiGt, &BinOp_::BiGt) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BinOp_ {
#[inline]
fn clone(&self) -> BinOp_ {
match (&*self,) {
(&BinOp_::BiAdd,) => BinOp_::BiAdd,
(&BinOp_::BiSub,) => BinOp_::BiSub,
(&BinOp_::BiMul,) => BinOp_::BiMul,
(&BinOp_::BiDiv,) => BinOp_::BiDiv,
(&BinOp_::BiRem,) => BinOp_::BiRem,
(&BinOp_::BiAnd,) => BinOp_::BiAnd,
(&BinOp_::BiOr,) => BinOp_::BiOr,
(&BinOp_::BiBitXor,) => BinOp_::BiBitXor,
(&BinOp_::BiBitAnd,) => BinOp_::BiBitAnd,
(&BinOp_::BiBitOr,) => BinOp_::BiBitOr,
(&BinOp_::BiShl,) => BinOp_::BiShl,
(&BinOp_::BiShr,) => BinOp_::BiShr,
(&BinOp_::BiEq,) => BinOp_::BiEq,
(&BinOp_::BiLt,) => BinOp_::BiLt,
(&BinOp_::BiLe,) => BinOp_::BiLe,
(&BinOp_::BiNe,) => BinOp_::BiNe,
(&BinOp_::BiGe,) => BinOp_::BiGe,
(&BinOp_::BiGt,) => BinOp_::BiGt,
}
}
}
impl BinOp_ {
pub fn to_string(&self) -> &'static str {
match *self {
BiAdd => "+",
BiSub => "-",
BiMul => "*",
BiDiv => "/",
BiRem => "%",
BiAnd => "&&",
BiOr => "||",
BiBitXor => "^",
BiBitAnd => "&",
BiBitOr => "|",
BiShl => "<<",
BiShr => ">>",
BiEq => "==",
BiLt => "<",
BiLe => "<=",
BiNe => "!=",
BiGe => ">=",
BiGt => ">",
}
}
pub fn lazy(&self) -> bool {
match *self { BiAnd | BiOr => true, _ => false, }
}
pub fn is_shift(&self) -> bool {
match *self { BiShl | BiShr => true, _ => false, }
}
pub fn is_comparison(&self) -> bool {
match *self {
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem |
BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => false,
}
}
/// Returns `true` if the binary operator takes its arguments by value
pub fn is_by_value(&self) -> bool { !BinOp_::is_comparison(self) }
}
pub type BinOp = Spanned<BinOp_>;
pub enum UnOp {
/// The `*` operator for dereferencing
UnDeref,
/// The `!` operator for logical inversion
UnNot,
/// The `-` operator for negation
UnNeg,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for UnOp { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for UnOp {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&UnOp::UnDeref,) => {
let mut builder = __arg_0.debug_tuple("UnDeref");
builder.finish()
}
(&UnOp::UnNot,) => {
let mut builder = __arg_0.debug_tuple("UnNot");
builder.finish()
}
(&UnOp::UnNeg,) => {
let mut builder = __arg_0.debug_tuple("UnNeg");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for UnOp {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&UnOp::UnDeref,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&UnOp::UnNot,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&UnOp::UnNeg,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for UnOp {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<UnOp, __D::Error> {
__arg_0.read_enum("UnOp", |_d| -> _ {
_d.read_enum_variant(&["UnDeref", "UnNot",
"UnNeg"], |_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
UnOp::UnDeref,
1usize
=>
UnOp::UnNot,
2usize
=>
UnOp::UnNeg,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
723u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for UnOp {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&UnOp::UnDeref,) => {
let _e = __arg_0;
_e.emit_enum("UnOp", |_e| -> _ {
_e.emit_enum_variant("UnDeref", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UnOp::UnNot,) => {
let _e = __arg_0;
_e.emit_enum("UnOp", |_e| -> _ {
_e.emit_enum_variant("UnNot", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UnOp::UnNeg,) => {
let _e = __arg_0;
_e.emit_enum("UnOp", |_e| -> _ {
_e.emit_enum_variant("UnNeg", 2usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for UnOp {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&UnOp::UnDeref,) => { }
(&UnOp::UnNot,) => { }
(&UnOp::UnNeg,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for UnOp {
#[inline]
fn eq(&self, __arg_0: &UnOp) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&UnOp::UnDeref, &UnOp::UnDeref) => true,
(&UnOp::UnNot, &UnOp::UnNot) => true,
(&UnOp::UnNeg, &UnOp::UnNeg) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &UnOp) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&UnOp::UnDeref, &UnOp::UnDeref) => false,
(&UnOp::UnNot, &UnOp::UnNot) => false,
(&UnOp::UnNeg, &UnOp::UnNeg) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for UnOp {
#[inline]
fn clone(&self) -> UnOp {
match (&*self,) {
(&UnOp::UnDeref,) => UnOp::UnDeref,
(&UnOp::UnNot,) => UnOp::UnNot,
(&UnOp::UnNeg,) => UnOp::UnNeg,
}
}
}
impl UnOp {
/// Returns `true` if the unary operator takes its argument by value
pub fn is_by_value(u: UnOp) -> bool {
match u { UnNeg | UnNot => true, _ => false, }
}
pub fn to_string(op: UnOp) -> &'static str {
match op { UnDeref => "*", UnNot => "!", UnNeg => "-", }
}
}
/// A statement
pub type Stmt = Spanned<Stmt_>;
impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["stmt(", ": ",
")"];
__STATIC_FMTSTR
},
&match (&self.node.id().map_or(Cow::Borrowed("<macro>"),
|id|
Cow::Owned(id.to_string())),
&pprust::stmt_to_string(self))
{
(__arg0, __arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
}
pub enum Stmt_ {
/// Could be an item or a local (let) binding:
StmtDecl(P<Decl>, NodeId),
/// Expr without trailing semi-colon (must have unit type):
StmtExpr(P<Expr>, NodeId),
/// Expr with trailing semi-colon (may have any type):
StmtSemi(P<Expr>, NodeId),
StmtMac(P<Mac>, MacStmtStyle, ThinAttributes),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Stmt_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Stmt_::StmtDecl(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Stmt_::StmtExpr(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Stmt_::StmtSemi(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Stmt_::StmtMac(ref __self_0, ref __self_1, ref __self_2),)
=> {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Stmt_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Stmt_, __D::Error> {
__arg_0.read_enum("Stmt_", |_d| -> _ {
_d.read_enum_variant(&["StmtDecl", "StmtExpr",
"StmtSemi", "StmtMac"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Stmt_::StmtDecl(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Stmt_::StmtExpr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Stmt_::StmtSemi(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Stmt_::StmtMac(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
764u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Stmt_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Stmt_::StmtDecl(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Stmt_", |_e| -> _ {
_e.emit_enum_variant("StmtDecl", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Stmt_::StmtExpr(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Stmt_", |_e| -> _ {
_e.emit_enum_variant("StmtExpr", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Stmt_::StmtSemi(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Stmt_", |_e| -> _ {
_e.emit_enum_variant("StmtSemi", 2usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Stmt_::StmtMac(ref __self_0, ref __self_1, ref __self_2),)
=> {
let _e = __arg_0;
_e.emit_enum("Stmt_", |_e| -> _ {
_e.emit_enum_variant("StmtMac", 3usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Stmt_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Stmt_::StmtDecl(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Stmt_::StmtExpr(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Stmt_::StmtSemi(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Stmt_::StmtMac(ref __self_0, ref __self_1, ref __self_2),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Stmt_ {
#[inline]
fn eq(&self, __arg_0: &Stmt_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Stmt_::StmtDecl(ref __self_0, ref __self_1),
&Stmt_::StmtDecl(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Stmt_::StmtExpr(ref __self_0, ref __self_1),
&Stmt_::StmtExpr(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Stmt_::StmtSemi(ref __self_0, ref __self_1),
&Stmt_::StmtSemi(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Stmt_::StmtMac(ref __self_0, ref __self_1,
ref __self_2),
&Stmt_::StmtMac(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Stmt_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Stmt_::StmtDecl(ref __self_0, ref __self_1),
&Stmt_::StmtDecl(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Stmt_::StmtExpr(ref __self_0, ref __self_1),
&Stmt_::StmtExpr(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Stmt_::StmtSemi(ref __self_0, ref __self_1),
&Stmt_::StmtSemi(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Stmt_::StmtMac(ref __self_0, ref __self_1,
ref __self_2),
&Stmt_::StmtMac(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Stmt_ {
#[inline]
fn clone(&self) -> Stmt_ {
match (&*self,) {
(&Stmt_::StmtDecl(ref __self_0, ref __self_1),) =>
Stmt_::StmtDecl(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Stmt_::StmtExpr(ref __self_0, ref __self_1),) =>
Stmt_::StmtExpr(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Stmt_::StmtSemi(ref __self_0, ref __self_1),) =>
Stmt_::StmtSemi(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Stmt_::StmtMac(ref __self_0, ref __self_1, ref __self_2),)
=>
Stmt_::StmtMac(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
}
}
}
impl Stmt_ {
pub fn id(&self) -> Option<NodeId> {
match *self {
StmtDecl(_, id) => Some(id),
StmtExpr(_, id) => Some(id),
StmtSemi(_, id) => Some(id),
StmtMac(..) => None,
}
}
pub fn attrs(&self) -> &[Attribute] {
match *self {
StmtDecl(ref d, _) => d.attrs(),
StmtExpr(ref e, _) | StmtSemi(ref e, _) => e.attrs(),
StmtMac(_, _, Some(ref b)) => b,
StmtMac(_, _, None) => &[],
}
}
}
pub enum MacStmtStyle {
/// The macro statement had a trailing semicolon, e.g. `foo! { ... };`
/// `foo!(...);`, `foo![...];`
MacStmtWithSemicolon,
/// The macro statement had braces; e.g. foo! { ... }
MacStmtWithBraces,
/// The macro statement had parentheses or brackets and no semicolon; e.g.
/// `foo!(...)`. All of these will end up being converted into macro
/// expressions.
MacStmtWithoutBraces,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for MacStmtStyle {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&MacStmtStyle::MacStmtWithSemicolon,) => {
let mut builder =
__arg_0.debug_tuple("MacStmtWithSemicolon");
builder.finish()
}
(&MacStmtStyle::MacStmtWithBraces,) => {
let mut builder =
__arg_0.debug_tuple("MacStmtWithBraces");
builder.finish()
}
(&MacStmtStyle::MacStmtWithoutBraces,) => {
let mut builder =
__arg_0.debug_tuple("MacStmtWithoutBraces");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for MacStmtStyle {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&MacStmtStyle::MacStmtWithSemicolon,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&MacStmtStyle::MacStmtWithBraces,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&MacStmtStyle::MacStmtWithoutBraces,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for MacStmtStyle {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<MacStmtStyle, __D::Error> {
__arg_0.read_enum("MacStmtStyle", |_d| -> _ {
_d.read_enum_variant(&["MacStmtWithSemicolon",
"MacStmtWithBraces",
"MacStmtWithoutBraces"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
MacStmtStyle::MacStmtWithSemicolon,
1usize
=>
MacStmtStyle::MacStmtWithBraces,
2usize
=>
MacStmtStyle::MacStmtWithoutBraces,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
799u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for MacStmtStyle {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&MacStmtStyle::MacStmtWithSemicolon,) => {
let _e = __arg_0;
_e.emit_enum("MacStmtStyle", |_e| -> _ {
_e.emit_enum_variant("MacStmtWithSemicolon",
0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&MacStmtStyle::MacStmtWithBraces,) => {
let _e = __arg_0;
_e.emit_enum("MacStmtStyle", |_e| -> _ {
_e.emit_enum_variant("MacStmtWithBraces",
1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&MacStmtStyle::MacStmtWithoutBraces,) => {
let _e = __arg_0;
_e.emit_enum("MacStmtStyle", |_e| -> _ {
_e.emit_enum_variant("MacStmtWithoutBraces",
2usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MacStmtStyle {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&MacStmtStyle::MacStmtWithSemicolon,) => { }
(&MacStmtStyle::MacStmtWithBraces,) => { }
(&MacStmtStyle::MacStmtWithoutBraces,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for MacStmtStyle {
#[inline]
fn eq(&self, __arg_0: &MacStmtStyle) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&MacStmtStyle::MacStmtWithSemicolon,
&MacStmtStyle::MacStmtWithSemicolon) => true,
(&MacStmtStyle::MacStmtWithBraces,
&MacStmtStyle::MacStmtWithBraces) => true,
(&MacStmtStyle::MacStmtWithoutBraces,
&MacStmtStyle::MacStmtWithoutBraces) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &MacStmtStyle) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&MacStmtStyle::MacStmtWithSemicolon,
&MacStmtStyle::MacStmtWithSemicolon) => false,
(&MacStmtStyle::MacStmtWithBraces,
&MacStmtStyle::MacStmtWithBraces) => false,
(&MacStmtStyle::MacStmtWithoutBraces,
&MacStmtStyle::MacStmtWithoutBraces) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for MacStmtStyle { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MacStmtStyle {
#[inline]
fn clone(&self) -> MacStmtStyle {
match (&*self,) {
(&MacStmtStyle::MacStmtWithSemicolon,) =>
MacStmtStyle::MacStmtWithSemicolon,
(&MacStmtStyle::MacStmtWithBraces,) =>
MacStmtStyle::MacStmtWithBraces,
(&MacStmtStyle::MacStmtWithoutBraces,) =>
MacStmtStyle::MacStmtWithoutBraces,
}
}
}
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
pub struct Local {
pub pat: P<Pat>,
pub ty: Option<P<Ty>>,
/// Initializer expression to set the value, if any
pub init: Option<P<Expr>>,
pub id: NodeId,
pub span: Span,
pub attrs: ThinAttributes,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Local {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } => {
let mut builder = __arg_0.debug_struct("Local");
let _ = builder.field("pat", &&(*__self_0_0));
let _ = builder.field("ty", &&(*__self_0_1));
let _ = builder.field("init", &&(*__self_0_2));
let _ = builder.field("id", &&(*__self_0_3));
let _ = builder.field("span", &&(*__self_0_4));
let _ = builder.field("attrs", &&(*__self_0_5));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Local {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Local {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Local, __D::Error> {
__arg_0.read_struct("Local", 6usize, |_d| -> _ {
::std::result::Result::Ok(Local{pat:
match _d.read_struct_field("pat",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ty:
match _d.read_struct_field("ty",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
init:
match _d.read_struct_field("init",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Local {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } =>
__arg_0.emit_struct("Local", 6usize, |_e| -> _ {
match _e.emit_struct_field("pat", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ty", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("init", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("attrs",
5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Local {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Local {
#[inline]
fn eq(&self, __arg_0: &Local) -> bool {
match *__arg_0 {
Local {
pat: ref __self_1_0,
ty: ref __self_1_1,
init: ref __self_1_2,
id: ref __self_1_3,
span: ref __self_1_4,
attrs: ref __self_1_5 } =>
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Local) -> bool {
match *__arg_0 {
Local {
pat: ref __self_1_0,
ty: ref __self_1_1,
init: ref __self_1_2,
id: ref __self_1_3,
span: ref __self_1_4,
attrs: ref __self_1_5 } =>
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Local {
#[inline]
fn clone(&self) -> Local {
match *self {
Local {
pat: ref __self_0_0,
ty: ref __self_0_1,
init: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
attrs: ref __self_0_5 } =>
Local{pat: ::std::clone::Clone::clone(&(*__self_0_0)),
ty: ::std::clone::Clone::clone(&(*__self_0_1)),
init: ::std::clone::Clone::clone(&(*__self_0_2)),
id: ::std::clone::Clone::clone(&(*__self_0_3)),
span: ::std::clone::Clone::clone(&(*__self_0_4)),
attrs: ::std::clone::Clone::clone(&(*__self_0_5)),},
}
}
}
impl Local {
pub fn attrs(&self) -> &[Attribute] {
match self.attrs { Some(ref b) => b, None => &[], }
}
}
pub type Decl = Spanned<Decl_>;
pub enum Decl_ {
/// A local (let) binding:
DeclLocal(P<Local>),
/// An item binding:
DeclItem(P<Item>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Decl_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Decl_::DeclLocal(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("DeclLocal");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Decl_::DeclItem(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("DeclItem");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Decl_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Decl_::DeclLocal(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Decl_::DeclItem(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Decl_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Decl_, __D::Error> {
__arg_0.read_enum("Decl_", |_d| -> _ {
_d.read_enum_variant(&["DeclLocal", "DeclItem"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Decl_::DeclLocal(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Decl_::DeclItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
837u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Decl_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Decl_::DeclLocal(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Decl_", |_e| -> _ {
_e.emit_enum_variant("DeclLocal", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Decl_::DeclItem(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Decl_", |_e| -> _ {
_e.emit_enum_variant("DeclItem", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Decl_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Decl_::DeclLocal(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Decl_::DeclItem(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Decl_ {
#[inline]
fn eq(&self, __arg_0: &Decl_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Decl_::DeclLocal(ref __self_0),
&Decl_::DeclLocal(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Decl_::DeclItem(ref __self_0),
&Decl_::DeclItem(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Decl_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Decl_::DeclLocal(ref __self_0),
&Decl_::DeclLocal(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Decl_::DeclItem(ref __self_0),
&Decl_::DeclItem(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Decl_ {
#[inline]
fn clone(&self) -> Decl_ {
match (&*self,) {
(&Decl_::DeclLocal(ref __self_0),) =>
Decl_::DeclLocal(::std::clone::Clone::clone(&(*__self_0))),
(&Decl_::DeclItem(ref __self_0),) =>
Decl_::DeclItem(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl Decl {
pub fn attrs(&self) -> &[Attribute] {
match self.node {
DeclLocal(ref l) => l.attrs(),
DeclItem(ref i) => i.attrs(),
}
}
}
/// represents one arm of a 'match'
pub struct Arm {
pub attrs: Vec<Attribute>,
pub pats: Vec<P<Pat>>,
pub guard: Option<P<Expr>>,
pub body: P<Expr>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Arm {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("Arm");
let _ = builder.field("attrs", &&(*__self_0_0));
let _ = builder.field("pats", &&(*__self_0_1));
let _ = builder.field("guard", &&(*__self_0_2));
let _ = builder.field("body", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Arm {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Arm {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Arm, __D::Error> {
__arg_0.read_struct("Arm", 4usize, |_d| -> _ {
::std::result::Result::Ok(Arm{attrs:
match _d.read_struct_field("attrs",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
pats:
match _d.read_struct_field("pats",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
guard:
match _d.read_struct_field("guard",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
body:
match _d.read_struct_field("body",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Arm {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } =>
__arg_0.emit_struct("Arm", 4usize, |_e| -> _ {
match _e.emit_struct_field("attrs",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("pats", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("guard",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("body",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Arm {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Arm {
#[inline]
fn eq(&self, __arg_0: &Arm) -> bool {
match *__arg_0 {
Arm {
attrs: ref __self_1_0,
pats: ref __self_1_1,
guard: ref __self_1_2,
body: ref __self_1_3 } =>
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Arm) -> bool {
match *__arg_0 {
Arm {
attrs: ref __self_1_0,
pats: ref __self_1_1,
guard: ref __self_1_2,
body: ref __self_1_3 } =>
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Arm {
#[inline]
fn clone(&self) -> Arm {
match *self {
Arm {
attrs: ref __self_0_0,
pats: ref __self_0_1,
guard: ref __self_0_2,
body: ref __self_0_3 } =>
Arm{attrs: ::std::clone::Clone::clone(&(*__self_0_0)),
pats: ::std::clone::Clone::clone(&(*__self_0_1)),
guard: ::std::clone::Clone::clone(&(*__self_0_2)),
body: ::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
pub struct Field {
pub ident: SpannedIdent,
pub expr: P<Expr>,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Field {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("Field");
let _ = builder.field("ident", &&(*__self_0_0));
let _ = builder.field("expr", &&(*__self_0_1));
let _ = builder.field("span", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Field {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Field {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Field, __D::Error> {
__arg_0.read_struct("Field", 3usize, |_d| -> _ {
::std::result::Result::Ok(Field{ident:
match _d.read_struct_field("ident",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
expr:
match _d.read_struct_field("expr",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Field {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } =>
__arg_0.emit_struct("Field", 3usize, |_e| -> _ {
match _e.emit_struct_field("ident",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("expr", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Field {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Field {
#[inline]
fn eq(&self, __arg_0: &Field) -> bool {
match *__arg_0 {
Field {
ident: ref __self_1_0,
expr: ref __self_1_1,
span: ref __self_1_2 } =>
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Field) -> bool {
match *__arg_0 {
Field {
ident: ref __self_1_0,
expr: ref __self_1_1,
span: ref __self_1_2 } =>
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Field {
#[inline]
fn clone(&self) -> Field {
match *self {
Field {
ident: ref __self_0_0,
expr: ref __self_0_1,
span: ref __self_0_2 } =>
Field{ident: ::std::clone::Clone::clone(&(*__self_0_0)),
expr: ::std::clone::Clone::clone(&(*__self_0_1)),
span: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub type SpannedIdent = Spanned<Ident>;
pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BlockCheckMode { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for BlockCheckMode {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&BlockCheckMode::DefaultBlock,) => {
let mut builder = __arg_0.debug_tuple("DefaultBlock");
builder.finish()
}
(&BlockCheckMode::UnsafeBlock(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("UnsafeBlock");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for BlockCheckMode {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&BlockCheckMode::DefaultBlock,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&BlockCheckMode::UnsafeBlock(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for BlockCheckMode {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<BlockCheckMode, __D::Error> {
__arg_0.read_enum("BlockCheckMode", |_d| -> _ {
_d.read_enum_variant(&["DefaultBlock",
"UnsafeBlock"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
BlockCheckMode::DefaultBlock,
1usize
=>
BlockCheckMode::UnsafeBlock(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
872u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for BlockCheckMode {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&BlockCheckMode::DefaultBlock,) => {
let _e = __arg_0;
_e.emit_enum("BlockCheckMode", |_e| -> _ {
_e.emit_enum_variant("DefaultBlock", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BlockCheckMode::UnsafeBlock(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("BlockCheckMode", |_e| -> _ {
_e.emit_enum_variant("UnsafeBlock", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for BlockCheckMode {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&BlockCheckMode::DefaultBlock,) => { }
(&BlockCheckMode::UnsafeBlock(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for BlockCheckMode {
#[inline]
fn eq(&self, __arg_0: &BlockCheckMode) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BlockCheckMode::DefaultBlock,
&BlockCheckMode::DefaultBlock) => true,
(&BlockCheckMode::UnsafeBlock(ref __self_0),
&BlockCheckMode::UnsafeBlock(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &BlockCheckMode) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BlockCheckMode::DefaultBlock,
&BlockCheckMode::DefaultBlock) => false,
(&BlockCheckMode::UnsafeBlock(ref __self_0),
&BlockCheckMode::UnsafeBlock(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BlockCheckMode {
#[inline]
fn clone(&self) -> BlockCheckMode {
match (&*self,) {
(&BlockCheckMode::DefaultBlock,) =>
BlockCheckMode::DefaultBlock,
(&BlockCheckMode::UnsafeBlock(ref __self_0),) =>
BlockCheckMode::UnsafeBlock(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum UnsafeSource { CompilerGenerated, UserProvided, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for UnsafeSource { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for UnsafeSource {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&UnsafeSource::CompilerGenerated,) => {
let mut builder =
__arg_0.debug_tuple("CompilerGenerated");
builder.finish()
}
(&UnsafeSource::UserProvided,) => {
let mut builder = __arg_0.debug_tuple("UserProvided");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for UnsafeSource {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&UnsafeSource::CompilerGenerated,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&UnsafeSource::UserProvided,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for UnsafeSource {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<UnsafeSource, __D::Error> {
__arg_0.read_enum("UnsafeSource", |_d| -> _ {
_d.read_enum_variant(&["CompilerGenerated",
"UserProvided"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
UnsafeSource::CompilerGenerated,
1usize
=>
UnsafeSource::UserProvided,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
878u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for UnsafeSource {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&UnsafeSource::CompilerGenerated,) => {
let _e = __arg_0;
_e.emit_enum("UnsafeSource", |_e| -> _ {
_e.emit_enum_variant("CompilerGenerated",
0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UnsafeSource::UserProvided,) => {
let _e = __arg_0;
_e.emit_enum("UnsafeSource", |_e| -> _ {
_e.emit_enum_variant("UserProvided", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for UnsafeSource {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&UnsafeSource::CompilerGenerated,) => { }
(&UnsafeSource::UserProvided,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for UnsafeSource {
#[inline]
fn eq(&self, __arg_0: &UnsafeSource) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&UnsafeSource::CompilerGenerated,
&UnsafeSource::CompilerGenerated) => true,
(&UnsafeSource::UserProvided,
&UnsafeSource::UserProvided) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &UnsafeSource) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&UnsafeSource::CompilerGenerated,
&UnsafeSource::CompilerGenerated) => false,
(&UnsafeSource::UserProvided,
&UnsafeSource::UserProvided) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for UnsafeSource {
#[inline]
fn clone(&self) -> UnsafeSource {
match (&*self,) {
(&UnsafeSource::CompilerGenerated,) =>
UnsafeSource::CompilerGenerated,
(&UnsafeSource::UserProvided,) => UnsafeSource::UserProvided,
}
}
}
/// An expression
pub struct Expr {
pub id: NodeId,
pub node: Expr_,
pub span: Span,
pub attrs: ThinAttributes,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Expr {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Expr {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2,
attrs: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Expr {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Expr, __D::Error> {
__arg_0.read_struct("Expr", 4usize, |_d| -> _ {
::std::result::Result::Ok(Expr{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Expr {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Expr {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2,
attrs: ref __self_0_3 } =>
__arg_0.emit_struct("Expr", 4usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("attrs",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Expr {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Expr {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2,
attrs: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Expr {
#[inline]
fn eq(&self, __arg_0: &Expr) -> bool {
match *__arg_0 {
Expr {
id: ref __self_1_0,
node: ref __self_1_1,
span: ref __self_1_2,
attrs: ref __self_1_3 } =>
match *self {
Expr {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2,
attrs: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Expr) -> bool {
match *__arg_0 {
Expr {
id: ref __self_1_0,
node: ref __self_1_1,
span: ref __self_1_2,
attrs: ref __self_1_3 } =>
match *self {
Expr {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2,
attrs: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Expr {
#[inline]
fn clone(&self) -> Expr {
match *self {
Expr {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2,
attrs: ref __self_0_3 } =>
Expr{id: ::std::clone::Clone::clone(&(*__self_0_0)),
node: ::std::clone::Clone::clone(&(*__self_0_1)),
span: ::std::clone::Clone::clone(&(*__self_0_2)),
attrs: ::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
impl Expr {
pub fn attrs(&self) -> &[Attribute] {
match self.attrs { Some(ref b) => b, None => &[], }
}
}
impl fmt::Debug for Expr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expr(", ": ",
")"];
__STATIC_FMTSTR
},
&match (&self.id,
&pprust::expr_to_string(self))
{
(__arg0, __arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
}
pub enum Expr_ {
/// A `box x` expression.
ExprBox(P<Expr>),
/// First expr is the place; second expr is the value.
ExprInPlace(P<Expr>, P<Expr>),
/// An array (`[a, b, c, d]`)
ExprVec(Vec<P<Expr>>),
/// A function call
///
/// The first field resolves to the function itself,
/// and the second field is the list of arguments
ExprCall(P<Expr>, Vec<P<Expr>>),
/// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
///
/// The `SpannedIdent` is the identifier for the method name.
/// The vector of `Ty`s are the ascripted type parameters for the method
/// (within the angle brackets).
///
/// The first element of the vector of `Expr`s is the expression that evaluates
/// to the object on which the method is being called on (the receiver),
/// and the remaining elements are the rest of the arguments.
///
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
/// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
/// A tuple (`(a, b, c ,d)`)
ExprTup(Vec<P<Expr>>),
/// A binary operation (For example: `a + b`, `a * b`)
ExprBinary(BinOp, P<Expr>, P<Expr>),
/// A unary operation (For example: `!x`, `*x`)
ExprUnary(UnOp, P<Expr>),
/// A literal (For example: `1u8`, `"foo"`)
ExprLit(P<Lit>),
/// A cast (`foo as f64`)
ExprCast(P<Expr>, P<Ty>),
ExprType(P<Expr>, P<Ty>),
/// An `if` block, with an optional else block
///
/// `if expr { block } else { expr }`
ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
/// An `if let` expression with an optional else block
///
/// `if let pat = expr { block } else { expr }`
///
/// This is desugared to a `match` expression.
ExprIfLet(P<Pat>, P<Expr>, P<Block>, Option<P<Expr>>),
/// A while loop, with an optional label
///
/// `'label: while expr { block }`
ExprWhile(P<Expr>, P<Block>, Option<Ident>),
/// A while-let loop, with an optional label
///
/// `'label: while let pat = expr { block }`
///
/// This is desugared to a combination of `loop` and `match` expressions.
ExprWhileLet(P<Pat>, P<Expr>, P<Block>, Option<Ident>),
/// A for loop, with an optional label
///
/// `'label: for pat in expr { block }`
///
/// This is desugared to a combination of `loop` and `match` expressions.
ExprForLoop(P<Pat>, P<Expr>, P<Block>, Option<Ident>),
/// Conditionless loop (can be exited with break, continue, or return)
///
/// `'label: loop { block }`
ExprLoop(P<Block>, Option<Ident>),
/// A `match` block.
ExprMatch(P<Expr>, Vec<Arm>),
/// A closure (for example, `move |a, b, c| {a + b + c}`)
ExprClosure(CaptureClause, P<FnDecl>, P<Block>),
/// A block (`{ ... }`)
ExprBlock(P<Block>),
/// An assignment (`a = foo()`)
ExprAssign(P<Expr>, P<Expr>),
/// An assignment with an operator
///
/// For example, `a += 1`.
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
/// Access of a named struct field (`obj.foo`)
ExprField(P<Expr>, SpannedIdent),
/// Access of an unnamed field of a struct or tuple-struct
///
/// For example, `foo.0`.
ExprTupField(P<Expr>, Spanned<usize>),
/// An indexing operation (`foo[2]`)
ExprIndex(P<Expr>, P<Expr>),
/// A range (`1..2`, `1..`, or `..2`)
ExprRange(Option<P<Expr>>, Option<P<Expr>>),
/// Variable reference, possibly containing `::` and/or type
/// parameters, e.g. foo::bar::<baz>.
///
/// Optionally "qualified",
/// e.g. `<Vec<T> as SomeTrait>::SomeType`.
ExprPath(Option<QSelf>, Path),
/// A referencing operation (`&a` or `&mut a`)
ExprAddrOf(Mutability, P<Expr>),
/// A `break`, with an optional label to break
ExprBreak(Option<SpannedIdent>),
/// A `continue`, with an optional label
ExprAgain(Option<SpannedIdent>),
/// A `return`, with an optional value to be returned
ExprRet(Option<P<Expr>>),
/// Output of the `asm!()` macro
ExprInlineAsm(InlineAsm),
/// A macro invocation; pre-expansion
ExprMac(Mac),
/// A struct literal expression.
///
/// For example, `Foo {x: 1, y: 2}`, or
/// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`.
ExprStruct(Path, Vec<Field>, Option<P<Expr>>),
/// An array literal constructed from one repeated element.
///
/// For example, `[1u8; 5]`. The first expression is the element
/// to be repeated; the second is the number of times to repeat it.
ExprRepeat(P<Expr>, P<Expr>),
/// No-op: used solely so we can pretty-print faithfully
ExprParen(P<Expr>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Expr_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Expr_::ExprBox(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprBox");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprInPlace");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprVec(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprVec");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprCall(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprCall");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("ExprMethodCall");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprTup(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprTup");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("ExprBinary");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprUnary(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprUnary");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprLit(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprLit");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprCast(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprCast");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprType(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprType");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprIf(ref __self_0, ref __self_1, ref __self_2),) =>
{
let mut builder = __arg_0.debug_tuple("ExprIf");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprIfLet(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let mut builder = __arg_0.debug_tuple("ExprIfLet");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
builder.finish()
}
(&Expr_::ExprWhile(ref __self_0, ref __self_1, ref __self_2),)
=> {
let mut builder = __arg_0.debug_tuple("ExprWhile");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),) => {
let mut builder = __arg_0.debug_tuple("ExprWhileLet");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
builder.finish()
}
(&Expr_::ExprForLoop(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let mut builder = __arg_0.debug_tuple("ExprForLoop");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
builder.finish()
}
(&Expr_::ExprLoop(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprLoop");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprMatch(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprMatch");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("ExprClosure");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprBlock(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprBlock");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprAssign(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprAssign");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("ExprAssignOp");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprField(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprField");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprTupField(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprTupField");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprIndex(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprIndex");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprRange(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprRange");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprPath(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprPath");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprAddrOf");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprBreak(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprBreak");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprAgain(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprAgain");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprRet(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprRet");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprInlineAsm(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprInlineAsm");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprMac(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprMac");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("ExprStruct");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ExprRepeat");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Expr_::ExprParen(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ExprParen");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Expr_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Expr_::ExprBox(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprVec(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprCall(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprTup(ref __self_0),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprUnary(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprLit(ref __self_0),) => {
::std::hash::Hash::hash(&8usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprCast(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&9usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprType(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&10usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprIf(ref __self_0, ref __self_1, ref __self_2),) =>
{
::std::hash::Hash::hash(&11usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprIfLet(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
::std::hash::Hash::hash(&12usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
}
(&Expr_::ExprWhile(ref __self_0, ref __self_1, ref __self_2),)
=> {
::std::hash::Hash::hash(&13usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),) => {
::std::hash::Hash::hash(&14usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
}
(&Expr_::ExprForLoop(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
::std::hash::Hash::hash(&15usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
}
(&Expr_::ExprLoop(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&16usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprMatch(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&17usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&18usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprBlock(ref __self_0),) => {
::std::hash::Hash::hash(&19usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprAssign(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&20usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&21usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprField(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&22usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprTupField(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&23usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprIndex(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&24usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprRange(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&25usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprPath(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&26usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&27usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprBreak(ref __self_0),) => {
::std::hash::Hash::hash(&28usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprAgain(ref __self_0),) => {
::std::hash::Hash::hash(&29usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprRet(ref __self_0),) => {
::std::hash::Hash::hash(&30usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprInlineAsm(ref __self_0),) => {
::std::hash::Hash::hash(&31usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprMac(ref __self_0),) => {
::std::hash::Hash::hash(&32usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&33usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&34usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Expr_::ExprParen(ref __self_0),) => {
::std::hash::Hash::hash(&35usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Expr_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Expr_, __D::Error> {
__arg_0.read_enum("Expr_", |_d| -> _ {
_d.read_enum_variant(&["ExprBox", "ExprInPlace",
"ExprVec", "ExprCall",
"ExprMethodCall",
"ExprTup", "ExprBinary",
"ExprUnary", "ExprLit",
"ExprCast", "ExprType",
"ExprIf", "ExprIfLet",
"ExprWhile",
"ExprWhileLet",
"ExprForLoop",
"ExprLoop", "ExprMatch",
"ExprClosure",
"ExprBlock",
"ExprAssign",
"ExprAssignOp",
"ExprField",
"ExprTupField",
"ExprIndex", "ExprRange",
"ExprPath", "ExprAddrOf",
"ExprBreak", "ExprAgain",
"ExprRet",
"ExprInlineAsm",
"ExprMac", "ExprStruct",
"ExprRepeat",
"ExprParen"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Expr_::ExprBox(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Expr_::ExprInPlace(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Expr_::ExprVec(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Expr_::ExprCall(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Expr_::ExprMethodCall(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Expr_::ExprTup(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Expr_::ExprBinary(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Expr_::ExprUnary(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
8usize
=>
Expr_::ExprLit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
9usize
=>
Expr_::ExprCast(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
10usize
=>
Expr_::ExprType(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
11usize
=>
Expr_::ExprIf(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
12usize
=>
Expr_::ExprIfLet(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
13usize
=>
Expr_::ExprWhile(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
14usize
=>
Expr_::ExprWhileLet(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
15usize
=>
Expr_::ExprForLoop(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
16usize
=>
Expr_::ExprLoop(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
17usize
=>
Expr_::ExprMatch(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
18usize
=>
Expr_::ExprClosure(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
19usize
=>
Expr_::ExprBlock(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
20usize
=>
Expr_::ExprAssign(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
21usize
=>
Expr_::ExprAssignOp(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
22usize
=>
Expr_::ExprField(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
23usize
=>
Expr_::ExprTupField(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
24usize
=>
Expr_::ExprIndex(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
25usize
=>
Expr_::ExprRange(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
26usize
=>
Expr_::ExprPath(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
27usize
=>
Expr_::ExprAddrOf(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
28usize
=>
Expr_::ExprBreak(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
29usize
=>
Expr_::ExprAgain(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
30usize
=>
Expr_::ExprRet(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
31usize
=>
Expr_::ExprInlineAsm(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
32usize
=>
Expr_::ExprMac(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
33usize
=>
Expr_::ExprStruct(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
34usize
=>
Expr_::ExprRepeat(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
35usize
=>
Expr_::ExprParen(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
908u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Expr_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Expr_::ExprBox(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprBox", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprInPlace", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprVec(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprVec", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprCall(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprCall", 3usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprMethodCall",
4usize, 3usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprTup(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprTup", 5usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprBinary", 6usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprUnary(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprUnary", 7usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprLit(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprLit", 8usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprCast(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprCast", 9usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprType(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprType", 10usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprIf(ref __self_0, ref __self_1, ref __self_2),) =>
{
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprIf", 11usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprIfLet(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprIfLet", 12usize,
4usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
});
}) })
}
(&Expr_::ExprWhile(ref __self_0, ref __self_1, ref __self_2),)
=> {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprWhile", 13usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprWhileLet", 14usize,
4usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
});
}) })
}
(&Expr_::ExprForLoop(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprForLoop", 15usize,
4usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
});
}) })
}
(&Expr_::ExprLoop(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprLoop", 16usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprMatch(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprMatch", 17usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprClosure", 18usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprBlock(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprBlock", 19usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprAssign(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprAssign", 20usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprAssignOp", 21usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprField(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprField", 22usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprTupField(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprTupField", 23usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprIndex(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprIndex", 24usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprRange(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprRange", 25usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprPath(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprPath", 26usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprAddrOf", 27usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprBreak(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprBreak", 28usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprAgain(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprAgain", 29usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprRet(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprRet", 30usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprInlineAsm(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprInlineAsm",
31usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprMac(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprMac", 32usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprStruct", 33usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprRepeat", 34usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Expr_::ExprParen(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Expr_", |_e| -> _ {
_e.emit_enum_variant("ExprParen", 35usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Expr_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Expr_::ExprBox(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprVec(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprCall(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprTup(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprUnary(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprLit(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprCast(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprType(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprIf(ref __self_0, ref __self_1, ref __self_2),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprIfLet(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
}
(&Expr_::ExprWhile(ref __self_0, ref __self_1, ref __self_2),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
}
(&Expr_::ExprForLoop(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
}
(&Expr_::ExprLoop(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprMatch(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprBlock(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprAssign(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprField(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprTupField(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprIndex(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprRange(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprPath(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprBreak(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprAgain(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprRet(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprInlineAsm(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprMac(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Expr_::ExprParen(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Expr_ {
#[inline]
fn eq(&self, __arg_0: &Expr_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Expr_::ExprBox(ref __self_0),
&Expr_::ExprBox(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),
&Expr_::ExprInPlace(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprVec(ref __self_0),
&Expr_::ExprVec(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprCall(ref __self_0, ref __self_1),
&Expr_::ExprCall(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprMethodCall(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprTup(ref __self_0),
&Expr_::ExprTup(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprBinary(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprUnary(ref __self_0, ref __self_1),
&Expr_::ExprUnary(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprLit(ref __self_0),
&Expr_::ExprLit(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprCast(ref __self_0, ref __self_1),
&Expr_::ExprCast(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprType(ref __self_0, ref __self_1),
&Expr_::ExprType(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprIf(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprIf(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprIfLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Expr_::ExprIfLet(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3),
(&Expr_::ExprWhile(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprWhile(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Expr_::ExprWhileLet(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3),
(&Expr_::ExprForLoop(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Expr_::ExprForLoop(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3),
(&Expr_::ExprLoop(ref __self_0, ref __self_1),
&Expr_::ExprLoop(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprMatch(ref __self_0, ref __self_1),
&Expr_::ExprMatch(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprClosure(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprBlock(ref __self_0),
&Expr_::ExprBlock(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprAssign(ref __self_0, ref __self_1),
&Expr_::ExprAssign(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprAssignOp(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprField(ref __self_0, ref __self_1),
&Expr_::ExprField(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprTupField(ref __self_0, ref __self_1),
&Expr_::ExprTupField(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprIndex(ref __self_0, ref __self_1),
&Expr_::ExprIndex(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprRange(ref __self_0, ref __self_1),
&Expr_::ExprRange(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprPath(ref __self_0, ref __self_1),
&Expr_::ExprPath(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),
&Expr_::ExprAddrOf(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprBreak(ref __self_0),
&Expr_::ExprBreak(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprAgain(ref __self_0),
&Expr_::ExprAgain(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprRet(ref __self_0),
&Expr_::ExprRet(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprInlineAsm(ref __self_0),
&Expr_::ExprInlineAsm(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprMac(ref __self_0),
&Expr_::ExprMac(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprStruct(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),
&Expr_::ExprRepeat(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Expr_::ExprParen(ref __self_0),
&Expr_::ExprParen(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Expr_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Expr_::ExprBox(ref __self_0),
&Expr_::ExprBox(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),
&Expr_::ExprInPlace(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprVec(ref __self_0),
&Expr_::ExprVec(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprCall(ref __self_0, ref __self_1),
&Expr_::ExprCall(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprMethodCall(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprTup(ref __self_0),
&Expr_::ExprTup(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprBinary(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprUnary(ref __self_0, ref __self_1),
&Expr_::ExprUnary(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprLit(ref __self_0),
&Expr_::ExprLit(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprCast(ref __self_0, ref __self_1),
&Expr_::ExprCast(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprType(ref __self_0, ref __self_1),
&Expr_::ExprType(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprIf(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprIf(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprIfLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Expr_::ExprIfLet(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3),
(&Expr_::ExprWhile(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprWhile(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Expr_::ExprWhileLet(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3),
(&Expr_::ExprForLoop(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Expr_::ExprForLoop(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3),
(&Expr_::ExprLoop(ref __self_0, ref __self_1),
&Expr_::ExprLoop(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprMatch(ref __self_0, ref __self_1),
&Expr_::ExprMatch(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprClosure(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprBlock(ref __self_0),
&Expr_::ExprBlock(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprAssign(ref __self_0, ref __self_1),
&Expr_::ExprAssign(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprAssignOp(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprField(ref __self_0, ref __self_1),
&Expr_::ExprField(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprTupField(ref __self_0, ref __self_1),
&Expr_::ExprTupField(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprIndex(ref __self_0, ref __self_1),
&Expr_::ExprIndex(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprRange(ref __self_0, ref __self_1),
&Expr_::ExprRange(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprPath(ref __self_0, ref __self_1),
&Expr_::ExprPath(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),
&Expr_::ExprAddrOf(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprBreak(ref __self_0),
&Expr_::ExprBreak(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprAgain(ref __self_0),
&Expr_::ExprAgain(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprRet(ref __self_0),
&Expr_::ExprRet(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprInlineAsm(ref __self_0),
&Expr_::ExprInlineAsm(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprMac(ref __self_0),
&Expr_::ExprMac(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),
&Expr_::ExprStruct(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),
&Expr_::ExprRepeat(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Expr_::ExprParen(ref __self_0),
&Expr_::ExprParen(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Expr_ {
#[inline]
fn clone(&self) -> Expr_ {
match (&*self,) {
(&Expr_::ExprBox(ref __self_0),) =>
Expr_::ExprBox(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprInPlace(ref __self_0, ref __self_1),) =>
Expr_::ExprInPlace(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprVec(ref __self_0),) =>
Expr_::ExprVec(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprCall(ref __self_0, ref __self_1),) =>
Expr_::ExprCall(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprMethodCall(ref __self_0, ref __self_1,
ref __self_2),) =>
Expr_::ExprMethodCall(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprTup(ref __self_0),) =>
Expr_::ExprTup(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprBinary(ref __self_0, ref __self_1,
ref __self_2),) =>
Expr_::ExprBinary(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprUnary(ref __self_0, ref __self_1),) =>
Expr_::ExprUnary(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprLit(ref __self_0),) =>
Expr_::ExprLit(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprCast(ref __self_0, ref __self_1),) =>
Expr_::ExprCast(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprType(ref __self_0, ref __self_1),) =>
Expr_::ExprType(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprIf(ref __self_0, ref __self_1, ref __self_2),) =>
Expr_::ExprIf(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprIfLet(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) =>
Expr_::ExprIfLet(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3))),
(&Expr_::ExprWhile(ref __self_0, ref __self_1, ref __self_2),)
=>
Expr_::ExprWhile(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprWhileLet(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),) =>
Expr_::ExprWhileLet(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3))),
(&Expr_::ExprForLoop(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) =>
Expr_::ExprForLoop(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3))),
(&Expr_::ExprLoop(ref __self_0, ref __self_1),) =>
Expr_::ExprLoop(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprMatch(ref __self_0, ref __self_1),) =>
Expr_::ExprMatch(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprClosure(ref __self_0, ref __self_1,
ref __self_2),) =>
Expr_::ExprClosure(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprBlock(ref __self_0),) =>
Expr_::ExprBlock(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprAssign(ref __self_0, ref __self_1),) =>
Expr_::ExprAssign(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprAssignOp(ref __self_0, ref __self_1,
ref __self_2),) =>
Expr_::ExprAssignOp(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprField(ref __self_0, ref __self_1),) =>
Expr_::ExprField(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprTupField(ref __self_0, ref __self_1),) =>
Expr_::ExprTupField(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprIndex(ref __self_0, ref __self_1),) =>
Expr_::ExprIndex(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprRange(ref __self_0, ref __self_1),) =>
Expr_::ExprRange(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprPath(ref __self_0, ref __self_1),) =>
Expr_::ExprPath(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprAddrOf(ref __self_0, ref __self_1),) =>
Expr_::ExprAddrOf(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprBreak(ref __self_0),) =>
Expr_::ExprBreak(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprAgain(ref __self_0),) =>
Expr_::ExprAgain(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprRet(ref __self_0),) =>
Expr_::ExprRet(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprInlineAsm(ref __self_0),) =>
Expr_::ExprInlineAsm(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprMac(ref __self_0),) =>
Expr_::ExprMac(::std::clone::Clone::clone(&(*__self_0))),
(&Expr_::ExprStruct(ref __self_0, ref __self_1,
ref __self_2),) =>
Expr_::ExprStruct(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Expr_::ExprRepeat(ref __self_0, ref __self_1),) =>
Expr_::ExprRepeat(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Expr_::ExprParen(ref __self_0),) =>
Expr_::ExprParen(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
/// The explicit Self type in a "qualified path". The actual
/// path, including the trait and the associated item, is stored
/// separately. `position` represents the index of the associated
/// item qualified with this Self type.
///
/// ```ignore
/// <Vec<T> as a::b::Trait>::AssociatedItem
/// ^~~~~ ~~~~~~~~~~~~~~^
/// ty position = 3
///
/// <Vec<T>>::AssociatedItem
/// ^~~~~ ^
/// ty position = 0
/// ```
pub struct QSelf {
pub ty: P<Ty>,
pub position: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for QSelf {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("QSelf");
let _ = builder.field("ty", &&(*__self_0_0));
let _ = builder.field("position", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for QSelf {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for QSelf {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<QSelf, __D::Error> {
__arg_0.read_struct("QSelf", 2usize, |_d| -> _ {
::std::result::Result::Ok(QSelf{ty:
match _d.read_struct_field("ty",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
position:
match _d.read_struct_field("position",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for QSelf {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } =>
__arg_0.emit_struct("QSelf", 2usize, |_e| -> _ {
match _e.emit_struct_field("ty", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("position",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for QSelf {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for QSelf {
#[inline]
fn eq(&self, __arg_0: &QSelf) -> bool {
match *__arg_0 {
QSelf { ty: ref __self_1_0, position: ref __self_1_1 } =>
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &QSelf) -> bool {
match *__arg_0 {
QSelf { ty: ref __self_1_0, position: ref __self_1_1 } =>
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for QSelf {
#[inline]
fn clone(&self) -> QSelf {
match *self {
QSelf { ty: ref __self_0_0, position: ref __self_0_1 } =>
QSelf{ty: ::std::clone::Clone::clone(&(*__self_0_0)),
position: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub enum CaptureClause { CaptureByValue, CaptureByRef, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for CaptureClause { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for CaptureClause {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&CaptureClause::CaptureByValue,) => {
let mut builder = __arg_0.debug_tuple("CaptureByValue");
builder.finish()
}
(&CaptureClause::CaptureByRef,) => {
let mut builder = __arg_0.debug_tuple("CaptureByRef");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for CaptureClause {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&CaptureClause::CaptureByValue,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&CaptureClause::CaptureByRef,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for CaptureClause {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<CaptureClause, __D::Error> {
__arg_0.read_enum("CaptureClause", |_d| -> _ {
_d.read_enum_variant(&["CaptureByValue",
"CaptureByRef"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
CaptureClause::CaptureByValue,
1usize
=>
CaptureClause::CaptureByRef,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1057u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for CaptureClause {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&CaptureClause::CaptureByValue,) => {
let _e = __arg_0;
_e.emit_enum("CaptureClause", |_e| -> _ {
_e.emit_enum_variant("CaptureByValue",
0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&CaptureClause::CaptureByRef,) => {
let _e = __arg_0;
_e.emit_enum("CaptureClause", |_e| -> _ {
_e.emit_enum_variant("CaptureByRef", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for CaptureClause {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&CaptureClause::CaptureByValue,) => { }
(&CaptureClause::CaptureByRef,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for CaptureClause {
#[inline]
fn eq(&self, __arg_0: &CaptureClause) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&CaptureClause::CaptureByValue,
&CaptureClause::CaptureByValue) => true,
(&CaptureClause::CaptureByRef,
&CaptureClause::CaptureByRef) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &CaptureClause) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&CaptureClause::CaptureByValue,
&CaptureClause::CaptureByValue) => false,
(&CaptureClause::CaptureByRef,
&CaptureClause::CaptureByRef) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for CaptureClause {
#[inline]
fn clone(&self) -> CaptureClause {
match (&*self,) {
(&CaptureClause::CaptureByValue,) =>
CaptureClause::CaptureByValue,
(&CaptureClause::CaptureByRef,) =>
CaptureClause::CaptureByRef,
}
}
}
/// A delimited sequence of token trees
pub struct Delimited {
/// The type of delimiter
pub delim: token::DelimToken,
/// The span covering the opening delimiter
pub open_span: Span,
/// The delimited sequence of token trees
pub tts: Vec<TokenTree>,
/// The span covering the closing delimiter
pub close_span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Delimited {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("Delimited");
let _ = builder.field("delim", &&(*__self_0_0));
let _ = builder.field("open_span", &&(*__self_0_1));
let _ = builder.field("tts", &&(*__self_0_2));
let _ = builder.field("close_span", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Delimited {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Delimited {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Delimited, __D::Error> {
__arg_0.read_struct("Delimited", 4usize, |_d| -> _ {
::std::result::Result::Ok(Delimited{delim:
match _d.read_struct_field("delim",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
open_span:
match _d.read_struct_field("open_span",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
tts:
match _d.read_struct_field("tts",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
close_span:
match _d.read_struct_field("close_span",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Delimited {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } =>
__arg_0.emit_struct("Delimited", 4usize, |_e| -> _ {
match _e.emit_struct_field("delim",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("open_span",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("tts", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("close_span",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Delimited {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Delimited {
#[inline]
fn eq(&self, __arg_0: &Delimited) -> bool {
match *__arg_0 {
Delimited {
delim: ref __self_1_0,
open_span: ref __self_1_1,
tts: ref __self_1_2,
close_span: ref __self_1_3 } =>
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Delimited) -> bool {
match *__arg_0 {
Delimited {
delim: ref __self_1_0,
open_span: ref __self_1_1,
tts: ref __self_1_2,
close_span: ref __self_1_3 } =>
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Delimited {
#[inline]
fn clone(&self) -> Delimited {
match *self {
Delimited {
delim: ref __self_0_0,
open_span: ref __self_0_1,
tts: ref __self_0_2,
close_span: ref __self_0_3 } =>
Delimited{delim: ::std::clone::Clone::clone(&(*__self_0_0)),
open_span:
::std::clone::Clone::clone(&(*__self_0_1)),
tts: ::std::clone::Clone::clone(&(*__self_0_2)),
close_span:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
impl Delimited {
/// Returns the opening delimiter as a token.
pub fn open_token(&self) -> token::Token {
token::OpenDelim(self.delim)
}
/// Returns the closing delimiter as a token.
pub fn close_token(&self) -> token::Token {
token::CloseDelim(self.delim)
}
/// Returns the opening delimiter as a token tree.
pub fn open_tt(&self) -> TokenTree {
TokenTree::Token(self.open_span, self.open_token())
}
/// Returns the closing delimiter as a token tree.
pub fn close_tt(&self) -> TokenTree {
TokenTree::Token(self.close_span, self.close_token())
}
}
/// A sequence of token trees
pub struct SequenceRepetition {
/// The sequence of token trees
pub tts: Vec<TokenTree>,
/// The optional separator
pub separator: Option<token::Token>,
/// Whether the sequence can be repeated zero (*), or one or more times (+)
pub op: KleeneOp,
/// The number of `MatchNt`s that appear in the sequence (and subsequences)
pub num_captures: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for SequenceRepetition {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } => {
let mut builder =
__arg_0.debug_struct("SequenceRepetition");
let _ = builder.field("tts", &&(*__self_0_0));
let _ = builder.field("separator", &&(*__self_0_1));
let _ = builder.field("op", &&(*__self_0_2));
let _ = builder.field("num_captures", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for SequenceRepetition {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for SequenceRepetition {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<SequenceRepetition, __D::Error> {
__arg_0.read_struct("SequenceRepetition", 4usize, |_d| -> _ {
::std::result::Result::Ok(SequenceRepetition{tts:
match _d.read_struct_field("tts",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
separator:
match _d.read_struct_field("separator",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
op:
match _d.read_struct_field("op",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
num_captures:
match _d.read_struct_field("num_captures",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for SequenceRepetition {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } =>
__arg_0.emit_struct("SequenceRepetition", 4usize, |_e| -> _ {
match _e.emit_struct_field("tts", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("separator",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("op", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("num_captures",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for SequenceRepetition {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for SequenceRepetition {
#[inline]
fn eq(&self, __arg_0: &SequenceRepetition) -> bool {
match *__arg_0 {
SequenceRepetition {
tts: ref __self_1_0,
separator: ref __self_1_1,
op: ref __self_1_2,
num_captures: ref __self_1_3 } =>
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &SequenceRepetition) -> bool {
match *__arg_0 {
SequenceRepetition {
tts: ref __self_1_0,
separator: ref __self_1_1,
op: ref __self_1_2,
num_captures: ref __self_1_3 } =>
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for SequenceRepetition {
#[inline]
fn clone(&self) -> SequenceRepetition {
match *self {
SequenceRepetition {
tts: ref __self_0_0,
separator: ref __self_0_1,
op: ref __self_0_2,
num_captures: ref __self_0_3 } =>
SequenceRepetition{tts:
::std::clone::Clone::clone(&(*__self_0_0)),
separator:
::std::clone::Clone::clone(&(*__self_0_1)),
op:
::std::clone::Clone::clone(&(*__self_0_2)),
num_captures:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
/// for token sequences.
pub enum KleeneOp { ZeroOrMore, OneOrMore, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for KleeneOp { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for KleeneOp {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&KleeneOp::ZeroOrMore,) => {
let mut builder = __arg_0.debug_tuple("ZeroOrMore");
builder.finish()
}
(&KleeneOp::OneOrMore,) => {
let mut builder = __arg_0.debug_tuple("OneOrMore");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for KleeneOp {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&KleeneOp::ZeroOrMore,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&KleeneOp::OneOrMore,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for KleeneOp {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<KleeneOp, __D::Error> {
__arg_0.read_enum("KleeneOp", |_d| -> _ {
_d.read_enum_variant(&["ZeroOrMore",
"OneOrMore"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
KleeneOp::ZeroOrMore,
1usize
=>
KleeneOp::OneOrMore,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1113u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for KleeneOp {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&KleeneOp::ZeroOrMore,) => {
let _e = __arg_0;
_e.emit_enum("KleeneOp", |_e| -> _ {
_e.emit_enum_variant("ZeroOrMore", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&KleeneOp::OneOrMore,) => {
let _e = __arg_0;
_e.emit_enum("KleeneOp", |_e| -> _ {
_e.emit_enum_variant("OneOrMore", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for KleeneOp {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&KleeneOp::ZeroOrMore,) => { }
(&KleeneOp::OneOrMore,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for KleeneOp {
#[inline]
fn eq(&self, __arg_0: &KleeneOp) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&KleeneOp::ZeroOrMore, &KleeneOp::ZeroOrMore) =>
true,
(&KleeneOp::OneOrMore, &KleeneOp::OneOrMore) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &KleeneOp) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&KleeneOp::ZeroOrMore, &KleeneOp::ZeroOrMore) =>
false,
(&KleeneOp::OneOrMore, &KleeneOp::OneOrMore) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for KleeneOp {
#[inline]
fn clone(&self) -> KleeneOp {
match (&*self,) {
(&KleeneOp::ZeroOrMore,) => KleeneOp::ZeroOrMore,
(&KleeneOp::OneOrMore,) => KleeneOp::OneOrMore,
}
}
}
/// When the main rust parser encounters a syntax-extension invocation, it
/// parses the arguments to the invocation as a token-tree. This is a very
/// loose structure, such that all sorts of different AST-fragments can
/// be passed to syntax extensions using a uniform type.
///
/// If the syntax extension is an MBE macro, it will attempt to match its
/// LHS token tree against the provided token tree, and if it finds a
/// match, will transcribe the RHS token tree, splicing in any captured
/// macro_parser::matched_nonterminals into the `SubstNt`s it finds.
///
/// The RHS of an MBE macro is the only place `SubstNt`s are substituted.
/// Nothing special happens to misnamed or misplaced `SubstNt`s.
pub enum TokenTree {
/// A single token
Token(Span, token::Token),
/// A delimited sequence of token trees
Delimited(Span, Rc<Delimited>),
/// A kleene-style repetition sequence with a span
Sequence(Span, Rc<SequenceRepetition>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TokenTree {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&TokenTree::Token(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Token");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&TokenTree::Delimited(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Delimited");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&TokenTree::Sequence(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Sequence");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TokenTree {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&TokenTree::Token(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&TokenTree::Delimited(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&TokenTree::Sequence(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TokenTree {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TokenTree, __D::Error> {
__arg_0.read_enum("TokenTree", |_d| -> _ {
_d.read_enum_variant(&["Token", "Delimited",
"Sequence"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
TokenTree::Token(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
TokenTree::Delimited(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
TokenTree::Sequence(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1131u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TokenTree {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&TokenTree::Token(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("TokenTree", |_e| -> _ {
_e.emit_enum_variant("Token", 0usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&TokenTree::Delimited(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("TokenTree", |_e| -> _ {
_e.emit_enum_variant("Delimited", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&TokenTree::Sequence(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("TokenTree", |_e| -> _ {
_e.emit_enum_variant("Sequence", 2usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TokenTree {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&TokenTree::Token(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&TokenTree::Delimited(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&TokenTree::Sequence(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TokenTree {
#[inline]
fn eq(&self, __arg_0: &TokenTree) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TokenTree::Token(ref __self_0, ref __self_1),
&TokenTree::Token(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&TokenTree::Delimited(ref __self_0, ref __self_1),
&TokenTree::Delimited(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&TokenTree::Sequence(ref __self_0, ref __self_1),
&TokenTree::Sequence(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &TokenTree) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TokenTree::Token(ref __self_0, ref __self_1),
&TokenTree::Token(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&TokenTree::Delimited(ref __self_0, ref __self_1),
&TokenTree::Delimited(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&TokenTree::Sequence(ref __self_0, ref __self_1),
&TokenTree::Sequence(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TokenTree {
#[inline]
fn clone(&self) -> TokenTree {
match (&*self,) {
(&TokenTree::Token(ref __self_0, ref __self_1),) =>
TokenTree::Token(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&TokenTree::Delimited(ref __self_0, ref __self_1),) =>
TokenTree::Delimited(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&TokenTree::Sequence(ref __self_0, ref __self_1),) =>
TokenTree::Sequence(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
impl TokenTree {
pub fn len(&self) -> usize {
match *self {
TokenTree::Token(_, token::DocComment(name)) => {
match doc_comment_style(&name.as_str()) {
AttrStyle::Outer => 2,
AttrStyle::Inner => 3,
}
}
TokenTree::Token(_, token::SpecialVarNt(..)) => 2,
TokenTree::Token(_, token::MatchNt(..)) => 3,
TokenTree::Delimited(_, ref delimed) => {
delimed.tts.len() + 2
}
TokenTree::Sequence(_, ref seq) => { seq.tts.len() }
TokenTree::Token(..) => 0,
}
}
pub fn get_tt(&self, index: usize) -> TokenTree {
match (self, index) {
(&TokenTree::Token(sp, token::DocComment(_)), 0) => {
TokenTree::Token(sp, token::Pound)
}
(&TokenTree::Token(sp, token::DocComment(name)), 1) if
doc_comment_style(&name.as_str()) == AttrStyle::Inner => {
TokenTree::Token(sp, token::Not)
}
(&TokenTree::Token(sp, token::DocComment(name)), _) => {
let stripped =
strip_doc_comment_decoration(&name.as_str());
TokenTree::Delimited(sp,
Rc::new(Delimited{delim:
token::Bracket,
open_span: sp,
tts:
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(sp,
token::Ident(token::str_to_ident("doc"),
token::Plain)),
TokenTree::Token(sp,
token::Eq),
TokenTree::Token(sp,
token::Literal(token::StrRaw(token::intern(&stripped),
0),
None))])),
close_span: sp,}))
}
(&TokenTree::Delimited(_, ref delimed), _) => {
if index == 0 { return delimed.open_tt(); }
if index == delimed.tts.len() + 1 {
return delimed.close_tt();
}
delimed.tts[index - 1].clone()
}
(&TokenTree::Token(sp, token::SpecialVarNt(var)), _) => {
let v =
[TokenTree::Token(sp, token::Dollar),
TokenTree::Token(sp,
token::Ident(token::str_to_ident(var.as_str()),
token::Plain))];
v[index].clone()
}
(&TokenTree::Token(sp,
token::MatchNt(name, kind, name_st,
kind_st)), _) => {
let v =
[TokenTree::Token(sp, token::SubstNt(name, name_st)),
TokenTree::Token(sp, token::Colon),
TokenTree::Token(sp, token::Ident(kind, kind_st))];
v[index].clone()
}
(&TokenTree::Sequence(_, ref seq), _) => {
seq.tts[index].clone()
}
_ => {
::std::rt::begin_unwind("Cannot expand a token tree",
{
static _FILE_LINE:
(&'static str, u32) =
("src/ast.rs", 1212u32);
&_FILE_LINE
})
}
}
}
/// Returns the `Span` corresponding to this token tree.
pub fn get_span(&self) -> Span {
match *self {
TokenTree::Token(span, _) => span,
TokenTree::Delimited(span, _) => span,
TokenTree::Sequence(span, _) => span,
}
}
/// Use this token tree as a matcher to parse given tts.
pub fn parse(cx: &base::ExtCtxt, mtch: &[TokenTree],
tts: &[TokenTree]) -> macro_parser::NamedParseResult {
let arg_rdr =
lexer::new_tt_reader_with_doc_flag(&cx.parse_sess().span_diagnostic,
None, None,
tts.iter().cloned().collect(),
true);
macro_parser::parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtch)
}
}
pub type Mac = Spanned<Mac_>;
/// Represents a macro invocation. The Path indicates which macro
/// is being invoked, and the vector of token-trees contains the source
/// of the macro invocation.
///
/// NB: the additional ident for a macro_rules-style macro is actually
/// stored in the enclosing item. Oog.
pub struct Mac_ {
pub path: Path,
pub tts: Vec<TokenTree>,
pub ctxt: SyntaxContext,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Mac_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("Mac_");
let _ = builder.field("path", &&(*__self_0_0));
let _ = builder.field("tts", &&(*__self_0_1));
let _ = builder.field("ctxt", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Mac_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Mac_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Mac_, __D::Error> {
__arg_0.read_struct("Mac_", 3usize, |_d| -> _ {
::std::result::Result::Ok(Mac_{path:
match _d.read_struct_field("path",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
tts:
match _d.read_struct_field("tts",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ctxt:
match _d.read_struct_field("ctxt",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Mac_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } =>
__arg_0.emit_struct("Mac_", 3usize, |_e| -> _ {
match _e.emit_struct_field("path", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("tts", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("ctxt",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Mac_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Mac_ {
#[inline]
fn eq(&self, __arg_0: &Mac_) -> bool {
match *__arg_0 {
Mac_ {
path: ref __self_1_0,
tts: ref __self_1_1,
ctxt: ref __self_1_2 } =>
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Mac_) -> bool {
match *__arg_0 {
Mac_ {
path: ref __self_1_0,
tts: ref __self_1_1,
ctxt: ref __self_1_2 } =>
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Mac_ {
#[inline]
fn clone(&self) -> Mac_ {
match *self {
Mac_ {
path: ref __self_0_0,
tts: ref __self_0_1,
ctxt: ref __self_0_2 } =>
Mac_{path: ::std::clone::Clone::clone(&(*__self_0_0)),
tts: ::std::clone::Clone::clone(&(*__self_0_1)),
ctxt: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub enum StrStyle {
/// A regular string, like `"foo"`
CookedStr,
/// A raw string, like `r##"foo"##`
///
/// The uint is the number of `#` symbols used
RawStr(usize),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for StrStyle { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for StrStyle {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&StrStyle::CookedStr,) => {
let mut builder = __arg_0.debug_tuple("CookedStr");
builder.finish()
}
(&StrStyle::RawStr(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("RawStr");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for StrStyle {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&StrStyle::CookedStr,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&StrStyle::RawStr(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for StrStyle {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<StrStyle, __D::Error> {
__arg_0.read_enum("StrStyle", |_d| -> _ {
_d.read_enum_variant(&["CookedStr", "RawStr"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
StrStyle::CookedStr,
1usize
=>
StrStyle::RawStr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1253u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for StrStyle {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&StrStyle::CookedStr,) => {
let _e = __arg_0;
_e.emit_enum("StrStyle", |_e| -> _ {
_e.emit_enum_variant("CookedStr", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&StrStyle::RawStr(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("StrStyle", |_e| -> _ {
_e.emit_enum_variant("RawStr", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for StrStyle {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&StrStyle::CookedStr,) => { }
(&StrStyle::RawStr(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for StrStyle {
#[inline]
fn eq(&self, __arg_0: &StrStyle) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StrStyle::CookedStr, &StrStyle::CookedStr) => true,
(&StrStyle::RawStr(ref __self_0),
&StrStyle::RawStr(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &StrStyle) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StrStyle::CookedStr, &StrStyle::CookedStr) => false,
(&StrStyle::RawStr(ref __self_0),
&StrStyle::RawStr(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for StrStyle {
#[inline]
fn clone(&self) -> StrStyle {
match (&*self,) {
(&StrStyle::CookedStr,) => StrStyle::CookedStr,
(&StrStyle::RawStr(ref __self_0),) =>
StrStyle::RawStr(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
/// A literal
pub type Lit = Spanned<Lit_>;
pub enum Sign { Minus, Plus, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Sign { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Sign {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Sign::Minus,) => {
let mut builder = __arg_0.debug_tuple("Minus");
builder.finish()
}
(&Sign::Plus,) => {
let mut builder = __arg_0.debug_tuple("Plus");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Sign {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Sign::Minus,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Sign::Plus,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Sign {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Sign, __D::Error> {
__arg_0.read_enum("Sign", |_d| -> _ {
_d.read_enum_variant(&["Minus", "Plus"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Sign::Minus,
1usize
=>
Sign::Plus,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1266u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Sign {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Sign::Minus,) => {
let _e = __arg_0;
_e.emit_enum("Sign", |_e| -> _ {
_e.emit_enum_variant("Minus", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Sign::Plus,) => {
let _e = __arg_0;
_e.emit_enum("Sign", |_e| -> _ {
_e.emit_enum_variant("Plus", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Sign {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) { (&Sign::Minus,) => { } (&Sign::Plus,) => { } }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Sign {
#[inline]
fn eq(&self, __arg_0: &Sign) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Sign::Minus, &Sign::Minus) => true,
(&Sign::Plus, &Sign::Plus) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Sign) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Sign::Minus, &Sign::Minus) => false,
(&Sign::Plus, &Sign::Plus) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Sign {
#[inline]
fn clone(&self) -> Sign {
match (&*self,) {
(&Sign::Minus,) => Sign::Minus,
(&Sign::Plus,) => Sign::Plus,
}
}
}
impl Sign {
pub fn new<T: IntSign>(n: T) -> Sign { n.sign() }
}
pub trait IntSign {
fn sign(&self)
-> Sign;
}
impl IntSign for i8 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for i16 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for i32 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for i64 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for isize {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for u8 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for u16 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for u32 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for u64 {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
impl IntSign for usize {
#[allow(unused_comparisons)]
fn sign(&self) -> Sign { if *self < 0 { Minus } else { Plus } }
}
pub enum LitIntType {
SignedIntLit(IntTy, Sign),
UnsignedIntLit(UintTy),
UnsuffixedIntLit(Sign),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for LitIntType { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for LitIntType {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&LitIntType::SignedIntLit(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("SignedIntLit");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&LitIntType::UnsignedIntLit(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("UnsignedIntLit");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&LitIntType::UnsuffixedIntLit(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("UnsuffixedIntLit");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for LitIntType {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&LitIntType::SignedIntLit(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&LitIntType::UnsignedIntLit(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&LitIntType::UnsuffixedIntLit(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for LitIntType {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<LitIntType, __D::Error> {
__arg_0.read_enum("LitIntType", |_d| -> _ {
_d.read_enum_variant(&["SignedIntLit",
"UnsignedIntLit",
"UnsuffixedIntLit"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
LitIntType::SignedIntLit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
LitIntType::UnsignedIntLit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
LitIntType::UnsuffixedIntLit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1291u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for LitIntType {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&LitIntType::SignedIntLit(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("LitIntType", |_e| -> _ {
_e.emit_enum_variant("SignedIntLit", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&LitIntType::UnsignedIntLit(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("LitIntType", |_e| -> _ {
_e.emit_enum_variant("UnsignedIntLit",
1usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&LitIntType::UnsuffixedIntLit(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("LitIntType", |_e| -> _ {
_e.emit_enum_variant("UnsuffixedIntLit",
2usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for LitIntType {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&LitIntType::SignedIntLit(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&LitIntType::UnsignedIntLit(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&LitIntType::UnsuffixedIntLit(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for LitIntType {
#[inline]
fn eq(&self, __arg_0: &LitIntType) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&LitIntType::SignedIntLit(ref __self_0,
ref __self_1),
&LitIntType::SignedIntLit(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&LitIntType::UnsignedIntLit(ref __self_0),
&LitIntType::UnsignedIntLit(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&LitIntType::UnsuffixedIntLit(ref __self_0),
&LitIntType::UnsuffixedIntLit(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &LitIntType) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&LitIntType::SignedIntLit(ref __self_0,
ref __self_1),
&LitIntType::SignedIntLit(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&LitIntType::UnsignedIntLit(ref __self_0),
&LitIntType::UnsignedIntLit(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&LitIntType::UnsuffixedIntLit(ref __self_0),
&LitIntType::UnsuffixedIntLit(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for LitIntType {
#[inline]
fn clone(&self) -> LitIntType {
match (&*self,) {
(&LitIntType::SignedIntLit(ref __self_0, ref __self_1),) =>
LitIntType::SignedIntLit(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&LitIntType::UnsignedIntLit(ref __self_0),) =>
LitIntType::UnsignedIntLit(::std::clone::Clone::clone(&(*__self_0))),
(&LitIntType::UnsuffixedIntLit(ref __self_0),) =>
LitIntType::UnsuffixedIntLit(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum Lit_ {
/// A string literal (`"foo"`)
LitStr(InternedString, StrStyle),
/// A byte string (`b"foo"`)
LitByteStr(Rc<Vec<u8>>),
/// A byte char (`b'f'`)
LitByte(u8),
/// A character literal (`'a'`)
LitChar(char),
/// An integer literal (`1u8`)
LitInt(u64, LitIntType),
/// A float literal (`1f64` or `1E10f64`)
LitFloat(InternedString, FloatTy),
/// A float literal without a suffix (`1.0 or 1.0E10`)
LitFloatUnsuffixed(InternedString),
/// A boolean literal
LitBool(bool),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Lit_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Lit_::LitStr(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("LitStr");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Lit_::LitByteStr(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("LitByteStr");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit_::LitByte(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("LitByte");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit_::LitChar(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("LitChar");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit_::LitInt(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("LitInt");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Lit_::LitFloat(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("LitFloat");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Lit_::LitFloatUnsuffixed(ref __self_0),) => {
let mut builder =
__arg_0.debug_tuple("LitFloatUnsuffixed");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit_::LitBool(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("LitBool");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Lit_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Lit_::LitStr(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Lit_::LitByteStr(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit_::LitByte(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit_::LitChar(ref __self_0),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit_::LitInt(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Lit_::LitFloat(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Lit_::LitFloatUnsuffixed(ref __self_0),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit_::LitBool(ref __self_0),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Lit_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Lit_, __D::Error> {
__arg_0.read_enum("Lit_", |_d| -> _ {
_d.read_enum_variant(&["LitStr", "LitByteStr",
"LitByte", "LitChar",
"LitInt", "LitFloat",
"LitFloatUnsuffixed",
"LitBool"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Lit_::LitStr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Lit_::LitByteStr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Lit_::LitByte(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Lit_::LitChar(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Lit_::LitInt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Lit_::LitFloat(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Lit_::LitFloatUnsuffixed(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Lit_::LitBool(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1298u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Lit_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Lit_::LitStr(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitStr", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Lit_::LitByteStr(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitByteStr", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit_::LitByte(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitByte", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit_::LitChar(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitChar", 3usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit_::LitInt(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitInt", 4usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Lit_::LitFloat(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitFloat", 5usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Lit_::LitFloatUnsuffixed(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitFloatUnsuffixed",
6usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit_::LitBool(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit_", |_e| -> _ {
_e.emit_enum_variant("LitBool", 7usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Lit_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Lit_::LitStr(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Lit_::LitByteStr(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit_::LitByte(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit_::LitChar(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit_::LitInt(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Lit_::LitFloat(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Lit_::LitFloatUnsuffixed(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit_::LitBool(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Lit_ {
#[inline]
fn eq(&self, __arg_0: &Lit_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Lit_::LitStr(ref __self_0, ref __self_1),
&Lit_::LitStr(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Lit_::LitByteStr(ref __self_0),
&Lit_::LitByteStr(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit_::LitByte(ref __self_0),
&Lit_::LitByte(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit_::LitChar(ref __self_0),
&Lit_::LitChar(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit_::LitInt(ref __self_0, ref __self_1),
&Lit_::LitInt(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Lit_::LitFloat(ref __self_0, ref __self_1),
&Lit_::LitFloat(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Lit_::LitFloatUnsuffixed(ref __self_0),
&Lit_::LitFloatUnsuffixed(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit_::LitBool(ref __self_0),
&Lit_::LitBool(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Lit_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Lit_::LitStr(ref __self_0, ref __self_1),
&Lit_::LitStr(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Lit_::LitByteStr(ref __self_0),
&Lit_::LitByteStr(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit_::LitByte(ref __self_0),
&Lit_::LitByte(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit_::LitChar(ref __self_0),
&Lit_::LitChar(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit_::LitInt(ref __self_0, ref __self_1),
&Lit_::LitInt(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Lit_::LitFloat(ref __self_0, ref __self_1),
&Lit_::LitFloat(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Lit_::LitFloatUnsuffixed(ref __self_0),
&Lit_::LitFloatUnsuffixed(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit_::LitBool(ref __self_0),
&Lit_::LitBool(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Lit_ {
#[inline]
fn clone(&self) -> Lit_ {
match (&*self,) {
(&Lit_::LitStr(ref __self_0, ref __self_1),) =>
Lit_::LitStr(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Lit_::LitByteStr(ref __self_0),) =>
Lit_::LitByteStr(::std::clone::Clone::clone(&(*__self_0))),
(&Lit_::LitByte(ref __self_0),) =>
Lit_::LitByte(::std::clone::Clone::clone(&(*__self_0))),
(&Lit_::LitChar(ref __self_0),) =>
Lit_::LitChar(::std::clone::Clone::clone(&(*__self_0))),
(&Lit_::LitInt(ref __self_0, ref __self_1),) =>
Lit_::LitInt(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Lit_::LitFloat(ref __self_0, ref __self_1),) =>
Lit_::LitFloat(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Lit_::LitFloatUnsuffixed(ref __self_0),) =>
Lit_::LitFloatUnsuffixed(::std::clone::Clone::clone(&(*__self_0))),
(&Lit_::LitBool(ref __self_0),) =>
Lit_::LitBool(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl Lit_ {
/// Returns true if this literal is a string and false otherwise.
pub fn is_str(&self) -> bool {
match *self { LitStr(..) => true, _ => false, }
}
}
pub struct MutTy {
pub ty: P<Ty>,
pub mutbl: Mutability,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for MutTy {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("MutTy");
let _ = builder.field("ty", &&(*__self_0_0));
let _ = builder.field("mutbl", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for MutTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for MutTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<MutTy, __D::Error> {
__arg_0.read_struct("MutTy", 2usize, |_d| -> _ {
::std::result::Result::Ok(MutTy{ty:
match _d.read_struct_field("ty",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
mutbl:
match _d.read_struct_field("mutbl",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for MutTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } =>
__arg_0.emit_struct("MutTy", 2usize, |_e| -> _ {
match _e.emit_struct_field("ty", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("mutbl",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MutTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for MutTy {
#[inline]
fn eq(&self, __arg_0: &MutTy) -> bool {
match *__arg_0 {
MutTy { ty: ref __self_1_0, mutbl: ref __self_1_1 } =>
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &MutTy) -> bool {
match *__arg_0 {
MutTy { ty: ref __self_1_0, mutbl: ref __self_1_1 } =>
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MutTy {
#[inline]
fn clone(&self) -> MutTy {
match *self {
MutTy { ty: ref __self_0_0, mutbl: ref __self_0_1 } =>
MutTy{ty: ::std::clone::Clone::clone(&(*__self_0_0)),
mutbl: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
/// Represents a method's signature in a trait declaration,
/// or in an implementation.
pub struct MethodSig {
pub unsafety: Unsafety,
pub constness: Constness,
pub abi: Abi,
pub decl: P<FnDecl>,
pub generics: Generics,
pub explicit_self: ExplicitSelf,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for MethodSig {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } => {
let mut builder = __arg_0.debug_struct("MethodSig");
let _ = builder.field("unsafety", &&(*__self_0_0));
let _ = builder.field("constness", &&(*__self_0_1));
let _ = builder.field("abi", &&(*__self_0_2));
let _ = builder.field("decl", &&(*__self_0_3));
let _ = builder.field("generics", &&(*__self_0_4));
let _ = builder.field("explicit_self", &&(*__self_0_5));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for MethodSig {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for MethodSig {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<MethodSig, __D::Error> {
__arg_0.read_struct("MethodSig", 6usize, |_d| -> _ {
::std::result::Result::Ok(MethodSig{unsafety:
match _d.read_struct_field("unsafety",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
constness:
match _d.read_struct_field("constness",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
abi:
match _d.read_struct_field("abi",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
decl:
match _d.read_struct_field("decl",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
generics:
match _d.read_struct_field("generics",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
explicit_self:
match _d.read_struct_field("explicit_self",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for MethodSig {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } =>
__arg_0.emit_struct("MethodSig", 6usize, |_e| -> _ {
match _e.emit_struct_field("unsafety",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("constness",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("abi", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("decl", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("generics",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("explicit_self",
5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MethodSig {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for MethodSig {
#[inline]
fn eq(&self, __arg_0: &MethodSig) -> bool {
match *__arg_0 {
MethodSig {
unsafety: ref __self_1_0,
constness: ref __self_1_1,
abi: ref __self_1_2,
decl: ref __self_1_3,
generics: ref __self_1_4,
explicit_self: ref __self_1_5 } =>
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5),
},
}
}
#[inline]
fn ne(&self, __arg_0: &MethodSig) -> bool {
match *__arg_0 {
MethodSig {
unsafety: ref __self_1_0,
constness: ref __self_1_1,
abi: ref __self_1_2,
decl: ref __self_1_3,
generics: ref __self_1_4,
explicit_self: ref __self_1_5 } =>
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MethodSig {
#[inline]
fn clone(&self) -> MethodSig {
match *self {
MethodSig {
unsafety: ref __self_0_0,
constness: ref __self_0_1,
abi: ref __self_0_2,
decl: ref __self_0_3,
generics: ref __self_0_4,
explicit_self: ref __self_0_5 } =>
MethodSig{unsafety:
::std::clone::Clone::clone(&(*__self_0_0)),
constness:
::std::clone::Clone::clone(&(*__self_0_1)),
abi: ::std::clone::Clone::clone(&(*__self_0_2)),
decl: ::std::clone::Clone::clone(&(*__self_0_3)),
generics:
::std::clone::Clone::clone(&(*__self_0_4)),
explicit_self:
::std::clone::Clone::clone(&(*__self_0_5)),},
}
}
}
/// Represents a method declaration in a trait declaration, possibly including
/// a default implementation. A trait method is either required (meaning it
/// doesn't have an implementation, just a signature) or provided (meaning it
/// has a default implementation).
pub struct TraitItem {
pub id: NodeId,
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub node: TraitItem_,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TraitItem {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } => {
let mut builder = __arg_0.debug_struct("TraitItem");
let _ = builder.field("id", &&(*__self_0_0));
let _ = builder.field("ident", &&(*__self_0_1));
let _ = builder.field("attrs", &&(*__self_0_2));
let _ = builder.field("node", &&(*__self_0_3));
let _ = builder.field("span", &&(*__self_0_4));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TraitItem {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TraitItem {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TraitItem, __D::Error> {
__arg_0.read_struct("TraitItem", 5usize, |_d| -> _ {
::std::result::Result::Ok(TraitItem{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ident:
match _d.read_struct_field("ident",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TraitItem {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } =>
__arg_0.emit_struct("TraitItem", 5usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ident",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TraitItem {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TraitItem {
#[inline]
fn eq(&self, __arg_0: &TraitItem) -> bool {
match *__arg_0 {
TraitItem {
id: ref __self_1_0,
ident: ref __self_1_1,
attrs: ref __self_1_2,
node: ref __self_1_3,
span: ref __self_1_4 } =>
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4),
},
}
}
#[inline]
fn ne(&self, __arg_0: &TraitItem) -> bool {
match *__arg_0 {
TraitItem {
id: ref __self_1_0,
ident: ref __self_1_1,
attrs: ref __self_1_2,
node: ref __self_1_3,
span: ref __self_1_4 } =>
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TraitItem {
#[inline]
fn clone(&self) -> TraitItem {
match *self {
TraitItem {
id: ref __self_0_0,
ident: ref __self_0_1,
attrs: ref __self_0_2,
node: ref __self_0_3,
span: ref __self_0_4 } =>
TraitItem{id: ::std::clone::Clone::clone(&(*__self_0_0)),
ident: ::std::clone::Clone::clone(&(*__self_0_1)),
attrs: ::std::clone::Clone::clone(&(*__self_0_2)),
node: ::std::clone::Clone::clone(&(*__self_0_3)),
span: ::std::clone::Clone::clone(&(*__self_0_4)),},
}
}
}
pub enum TraitItem_ {
ConstTraitItem(P<Ty>, Option<P<Expr>>),
MethodTraitItem(MethodSig, Option<P<Block>>),
TypeTraitItem(TyParamBounds, Option<P<Ty>>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TraitItem_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&TraitItem_::ConstTraitItem(ref __self_0, ref __self_1),) =>
{
let mut builder = __arg_0.debug_tuple("ConstTraitItem");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&TraitItem_::MethodTraitItem(ref __self_0, ref __self_1),) =>
{
let mut builder = __arg_0.debug_tuple("MethodTraitItem");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&TraitItem_::TypeTraitItem(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("TypeTraitItem");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TraitItem_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&TraitItem_::ConstTraitItem(ref __self_0, ref __self_1),) =>
{
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&TraitItem_::MethodTraitItem(ref __self_0, ref __self_1),) =>
{
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&TraitItem_::TypeTraitItem(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TraitItem_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TraitItem_, __D::Error> {
__arg_0.read_enum("TraitItem_", |_d| -> _ {
_d.read_enum_variant(&["ConstTraitItem",
"MethodTraitItem",
"TypeTraitItem"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
TraitItem_::ConstTraitItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
TraitItem_::MethodTraitItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
TraitItem_::TypeTraitItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1361u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TraitItem_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&TraitItem_::ConstTraitItem(ref __self_0, ref __self_1),) =>
{
let _e = __arg_0;
_e.emit_enum("TraitItem_", |_e| -> _ {
_e.emit_enum_variant("ConstTraitItem",
0usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&TraitItem_::MethodTraitItem(ref __self_0, ref __self_1),) =>
{
let _e = __arg_0;
_e.emit_enum("TraitItem_", |_e| -> _ {
_e.emit_enum_variant("MethodTraitItem",
1usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&TraitItem_::TypeTraitItem(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("TraitItem_", |_e| -> _ {
_e.emit_enum_variant("TypeTraitItem", 2usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TraitItem_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&TraitItem_::ConstTraitItem(ref __self_0, ref __self_1),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&TraitItem_::MethodTraitItem(ref __self_0, ref __self_1),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&TraitItem_::TypeTraitItem(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TraitItem_ {
#[inline]
fn eq(&self, __arg_0: &TraitItem_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TraitItem_::ConstTraitItem(ref __self_0,
ref __self_1),
&TraitItem_::ConstTraitItem(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&TraitItem_::MethodTraitItem(ref __self_0,
ref __self_1),
&TraitItem_::MethodTraitItem(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&TraitItem_::TypeTraitItem(ref __self_0,
ref __self_1),
&TraitItem_::TypeTraitItem(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &TraitItem_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TraitItem_::ConstTraitItem(ref __self_0,
ref __self_1),
&TraitItem_::ConstTraitItem(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&TraitItem_::MethodTraitItem(ref __self_0,
ref __self_1),
&TraitItem_::MethodTraitItem(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&TraitItem_::TypeTraitItem(ref __self_0,
ref __self_1),
&TraitItem_::TypeTraitItem(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TraitItem_ {
#[inline]
fn clone(&self) -> TraitItem_ {
match (&*self,) {
(&TraitItem_::ConstTraitItem(ref __self_0, ref __self_1),) =>
TraitItem_::ConstTraitItem(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&TraitItem_::MethodTraitItem(ref __self_0, ref __self_1),) =>
TraitItem_::MethodTraitItem(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&TraitItem_::TypeTraitItem(ref __self_0, ref __self_1),) =>
TraitItem_::TypeTraitItem(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
pub struct ImplItem {
pub id: NodeId,
pub ident: Ident,
pub vis: Visibility,
pub attrs: Vec<Attribute>,
pub node: ImplItemKind,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ImplItem {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } => {
let mut builder = __arg_0.debug_struct("ImplItem");
let _ = builder.field("id", &&(*__self_0_0));
let _ = builder.field("ident", &&(*__self_0_1));
let _ = builder.field("vis", &&(*__self_0_2));
let _ = builder.field("attrs", &&(*__self_0_3));
let _ = builder.field("node", &&(*__self_0_4));
let _ = builder.field("span", &&(*__self_0_5));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ImplItem {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ImplItem {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ImplItem, __D::Error> {
__arg_0.read_struct("ImplItem", 6usize, |_d| -> _ {
::std::result::Result::Ok(ImplItem{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ident:
match _d.read_struct_field("ident",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
vis:
match _d.read_struct_field("vis",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ImplItem {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } =>
__arg_0.emit_struct("ImplItem", 6usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ident",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("vis", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ImplItem {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ImplItem {
#[inline]
fn eq(&self, __arg_0: &ImplItem) -> bool {
match *__arg_0 {
ImplItem {
id: ref __self_1_0,
ident: ref __self_1_1,
vis: ref __self_1_2,
attrs: ref __self_1_3,
node: ref __self_1_4,
span: ref __self_1_5 } =>
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ImplItem) -> bool {
match *__arg_0 {
ImplItem {
id: ref __self_1_0,
ident: ref __self_1_1,
vis: ref __self_1_2,
attrs: ref __self_1_3,
node: ref __self_1_4,
span: ref __self_1_5 } =>
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ImplItem {
#[inline]
fn clone(&self) -> ImplItem {
match *self {
ImplItem {
id: ref __self_0_0,
ident: ref __self_0_1,
vis: ref __self_0_2,
attrs: ref __self_0_3,
node: ref __self_0_4,
span: ref __self_0_5 } =>
ImplItem{id: ::std::clone::Clone::clone(&(*__self_0_0)),
ident: ::std::clone::Clone::clone(&(*__self_0_1)),
vis: ::std::clone::Clone::clone(&(*__self_0_2)),
attrs: ::std::clone::Clone::clone(&(*__self_0_3)),
node: ::std::clone::Clone::clone(&(*__self_0_4)),
span: ::std::clone::Clone::clone(&(*__self_0_5)),},
}
}
}
pub enum ImplItemKind {
Const(P<Ty>, P<Expr>),
Method(MethodSig, P<Block>),
Type(P<Ty>),
Macro(Mac),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ImplItemKind {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Const");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&ImplItemKind::Method(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Method");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&ImplItemKind::Type(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Type");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&ImplItemKind::Macro(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Macro");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ImplItemKind {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&ImplItemKind::Method(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&ImplItemKind::Type(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&ImplItemKind::Macro(ref __self_0),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ImplItemKind {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ImplItemKind, __D::Error> {
__arg_0.read_enum("ImplItemKind", |_d| -> _ {
_d.read_enum_variant(&["Const", "Method",
"Type", "Macro"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
ImplItemKind::Const(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
ImplItemKind::Method(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
ImplItemKind::Type(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
ImplItemKind::Macro(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1378u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ImplItemKind {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("ImplItemKind", |_e| -> _ {
_e.emit_enum_variant("Const", 0usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&ImplItemKind::Method(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("ImplItemKind", |_e| -> _ {
_e.emit_enum_variant("Method", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&ImplItemKind::Type(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("ImplItemKind", |_e| -> _ {
_e.emit_enum_variant("Type", 2usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&ImplItemKind::Macro(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("ImplItemKind", |_e| -> _ {
_e.emit_enum_variant("Macro", 3usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ImplItemKind {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&ImplItemKind::Method(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&ImplItemKind::Type(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&ImplItemKind::Macro(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ImplItemKind {
#[inline]
fn eq(&self, __arg_0: &ImplItemKind) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),
&ImplItemKind::Const(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&ImplItemKind::Method(ref __self_0, ref __self_1),
&ImplItemKind::Method(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&ImplItemKind::Type(ref __self_0),
&ImplItemKind::Type(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&ImplItemKind::Macro(ref __self_0),
&ImplItemKind::Macro(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ImplItemKind) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),
&ImplItemKind::Const(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&ImplItemKind::Method(ref __self_0, ref __self_1),
&ImplItemKind::Method(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&ImplItemKind::Type(ref __self_0),
&ImplItemKind::Type(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&ImplItemKind::Macro(ref __self_0),
&ImplItemKind::Macro(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ImplItemKind {
#[inline]
fn clone(&self) -> ImplItemKind {
match (&*self,) {
(&ImplItemKind::Const(ref __self_0, ref __self_1),) =>
ImplItemKind::Const(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&ImplItemKind::Method(ref __self_0, ref __self_1),) =>
ImplItemKind::Method(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&ImplItemKind::Type(ref __self_0),) =>
ImplItemKind::Type(::std::clone::Clone::clone(&(*__self_0))),
(&ImplItemKind::Macro(ref __self_0),) =>
ImplItemKind::Macro(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum IntTy { TyIs, TyI8, TyI16, TyI32, TyI64, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for IntTy { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for IntTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&IntTy::TyIs,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&IntTy::TyI8,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&IntTy::TyI16,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
(&IntTy::TyI32,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&IntTy::TyI64,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for IntTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<IntTy, __D::Error> {
__arg_0.read_enum("IntTy", |_d| -> _ {
_d.read_enum_variant(&["TyIs", "TyI8", "TyI16",
"TyI32", "TyI64"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
IntTy::TyIs,
1usize
=>
IntTy::TyI8,
2usize
=>
IntTy::TyI16,
3usize
=>
IntTy::TyI32,
4usize
=>
IntTy::TyI64,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1386u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for IntTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&IntTy::TyIs,) => {
let _e = __arg_0;
_e.emit_enum("IntTy", |_e| -> _ {
_e.emit_enum_variant("TyIs", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&IntTy::TyI8,) => {
let _e = __arg_0;
_e.emit_enum("IntTy", |_e| -> _ {
_e.emit_enum_variant("TyI8", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&IntTy::TyI16,) => {
let _e = __arg_0;
_e.emit_enum("IntTy", |_e| -> _ {
_e.emit_enum_variant("TyI16", 2usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&IntTy::TyI32,) => {
let _e = __arg_0;
_e.emit_enum("IntTy", |_e| -> _ {
_e.emit_enum_variant("TyI32", 3usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&IntTy::TyI64,) => {
let _e = __arg_0;
_e.emit_enum("IntTy", |_e| -> _ {
_e.emit_enum_variant("TyI64", 4usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for IntTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&IntTy::TyIs,) => { }
(&IntTy::TyI8,) => { }
(&IntTy::TyI16,) => { }
(&IntTy::TyI32,) => { }
(&IntTy::TyI64,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for IntTy {
#[inline]
fn eq(&self, __arg_0: &IntTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&IntTy::TyIs, &IntTy::TyIs) => true,
(&IntTy::TyI8, &IntTy::TyI8) => true,
(&IntTy::TyI16, &IntTy::TyI16) => true,
(&IntTy::TyI32, &IntTy::TyI32) => true,
(&IntTy::TyI64, &IntTy::TyI64) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &IntTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&IntTy::TyIs, &IntTy::TyIs) => false,
(&IntTy::TyI8, &IntTy::TyI8) => false,
(&IntTy::TyI16, &IntTy::TyI16) => false,
(&IntTy::TyI32, &IntTy::TyI32) => false,
(&IntTy::TyI64, &IntTy::TyI64) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for IntTy {
#[inline]
fn clone(&self) -> IntTy {
match (&*self,) {
(&IntTy::TyIs,) => IntTy::TyIs,
(&IntTy::TyI8,) => IntTy::TyI8,
(&IntTy::TyI16,) => IntTy::TyI16,
(&IntTy::TyI32,) => IntTy::TyI32,
(&IntTy::TyI64,) => IntTy::TyI64,
}
}
}
impl fmt::Debug for IntTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for IntTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&self.ty_to_string(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
impl IntTy {
pub fn ty_to_string(&self) -> &'static str {
match *self {
TyIs => "isize",
TyI8 => "i8",
TyI16 => "i16",
TyI32 => "i32",
TyI64 => "i64",
}
}
pub fn val_to_string(&self, val: i64) -> String {
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
""];
__STATIC_FMTSTR
},
&match (&(val as
u64),
&self.ty_to_string())
{
(__arg0,
__arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
pub fn ty_max(&self) -> u64 {
match *self {
TyI8 => 128,
TyI16 => 32768,
TyIs | TyI32 => 2147483648,
TyI64 => 9223372036854775808,
}
}
pub fn bit_width(&self) -> Option<usize> {
Some(match *self {
TyIs => return None,
TyI8 => 8,
TyI16 => 16,
TyI32 => 32,
TyI64 => 64,
})
}
}
pub enum UintTy { TyUs, TyU8, TyU16, TyU32, TyU64, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for UintTy { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for UintTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&UintTy::TyUs,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&UintTy::TyU8,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&UintTy::TyU16,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
(&UintTy::TyU32,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&UintTy::TyU64,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for UintTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<UintTy, __D::Error> {
__arg_0.read_enum("UintTy", |_d| -> _ {
_d.read_enum_variant(&["TyUs", "TyU8", "TyU16",
"TyU32", "TyU64"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
UintTy::TyUs,
1usize
=>
UintTy::TyU8,
2usize
=>
UintTy::TyU16,
3usize
=>
UintTy::TyU32,
4usize
=>
UintTy::TyU64,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1445u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for UintTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&UintTy::TyUs,) => {
let _e = __arg_0;
_e.emit_enum("UintTy", |_e| -> _ {
_e.emit_enum_variant("TyUs", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UintTy::TyU8,) => {
let _e = __arg_0;
_e.emit_enum("UintTy", |_e| -> _ {
_e.emit_enum_variant("TyU8", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UintTy::TyU16,) => {
let _e = __arg_0;
_e.emit_enum("UintTy", |_e| -> _ {
_e.emit_enum_variant("TyU16", 2usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UintTy::TyU32,) => {
let _e = __arg_0;
_e.emit_enum("UintTy", |_e| -> _ {
_e.emit_enum_variant("TyU32", 3usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&UintTy::TyU64,) => {
let _e = __arg_0;
_e.emit_enum("UintTy", |_e| -> _ {
_e.emit_enum_variant("TyU64", 4usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for UintTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&UintTy::TyUs,) => { }
(&UintTy::TyU8,) => { }
(&UintTy::TyU16,) => { }
(&UintTy::TyU32,) => { }
(&UintTy::TyU64,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for UintTy {
#[inline]
fn eq(&self, __arg_0: &UintTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&UintTy::TyUs, &UintTy::TyUs) => true,
(&UintTy::TyU8, &UintTy::TyU8) => true,
(&UintTy::TyU16, &UintTy::TyU16) => true,
(&UintTy::TyU32, &UintTy::TyU32) => true,
(&UintTy::TyU64, &UintTy::TyU64) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &UintTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&UintTy::TyUs, &UintTy::TyUs) => false,
(&UintTy::TyU8, &UintTy::TyU8) => false,
(&UintTy::TyU16, &UintTy::TyU16) => false,
(&UintTy::TyU32, &UintTy::TyU32) => false,
(&UintTy::TyU64, &UintTy::TyU64) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for UintTy {
#[inline]
fn clone(&self) -> UintTy {
match (&*self,) {
(&UintTy::TyUs,) => UintTy::TyUs,
(&UintTy::TyU8,) => UintTy::TyU8,
(&UintTy::TyU16,) => UintTy::TyU16,
(&UintTy::TyU32,) => UintTy::TyU32,
(&UintTy::TyU64,) => UintTy::TyU64,
}
}
}
impl UintTy {
pub fn ty_to_string(&self) -> &'static str {
match *self {
TyUs => "usize",
TyU8 => "u8",
TyU16 => "u16",
TyU32 => "u32",
TyU64 => "u64",
}
}
pub fn val_to_string(&self, val: u64) -> String {
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
""];
__STATIC_FMTSTR
},
&match (&val,
&self.ty_to_string())
{
(__arg0,
__arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
pub fn ty_max(&self) -> u64 {
match *self {
TyU8 => 255,
TyU16 => 65535,
TyUs | TyU32 => 4294967295,
TyU64 => 18446744073709551615,
}
}
pub fn bit_width(&self) -> Option<usize> {
Some(match *self {
TyUs => return None,
TyU8 => 8,
TyU16 => 16,
TyU32 => 32,
TyU64 => 64,
})
}
}
impl fmt::Debug for UintTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for UintTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&self.ty_to_string(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
pub enum FloatTy { TyF32, TyF64, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for FloatTy { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for FloatTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&FloatTy::TyF32,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&FloatTy::TyF64,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for FloatTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<FloatTy, __D::Error> {
__arg_0.read_enum("FloatTy", |_d| -> _ {
_d.read_enum_variant(&["TyF32", "TyF64"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
FloatTy::TyF32,
1usize
=>
FloatTy::TyF64,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1501u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for FloatTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&FloatTy::TyF32,) => {
let _e = __arg_0;
_e.emit_enum("FloatTy", |_e| -> _ {
_e.emit_enum_variant("TyF32", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&FloatTy::TyF64,) => {
let _e = __arg_0;
_e.emit_enum("FloatTy", |_e| -> _ {
_e.emit_enum_variant("TyF64", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for FloatTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&FloatTy::TyF32,) => { }
(&FloatTy::TyF64,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for FloatTy {
#[inline]
fn eq(&self, __arg_0: &FloatTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&FloatTy::TyF32, &FloatTy::TyF32) => true,
(&FloatTy::TyF64, &FloatTy::TyF64) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &FloatTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&FloatTy::TyF32, &FloatTy::TyF32) => false,
(&FloatTy::TyF64, &FloatTy::TyF64) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for FloatTy {
#[inline]
fn clone(&self) -> FloatTy {
match (&*self,) {
(&FloatTy::TyF32,) => FloatTy::TyF32,
(&FloatTy::TyF64,) => FloatTy::TyF64,
}
}
}
impl fmt::Debug for FloatTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for FloatTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&self.ty_to_string(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
impl FloatTy {
pub fn ty_to_string(&self) -> &'static str {
match *self { TyF32 => "f32", TyF64 => "f64", }
}
pub fn bit_width(&self) -> usize {
match *self { TyF32 => 32, TyF64 => 64, }
}
}
pub struct TypeBinding {
pub id: NodeId,
pub ident: Ident,
pub ty: P<Ty>,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TypeBinding {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("TypeBinding");
let _ = builder.field("id", &&(*__self_0_0));
let _ = builder.field("ident", &&(*__self_0_1));
let _ = builder.field("ty", &&(*__self_0_2));
let _ = builder.field("span", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TypeBinding {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TypeBinding {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TypeBinding, __D::Error> {
__arg_0.read_struct("TypeBinding", 4usize, |_d| -> _ {
::std::result::Result::Ok(TypeBinding{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ident:
match _d.read_struct_field("ident",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ty:
match _d.read_struct_field("ty",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TypeBinding {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } =>
__arg_0.emit_struct("TypeBinding", 4usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ident",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ty", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TypeBinding {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TypeBinding {
#[inline]
fn eq(&self, __arg_0: &TypeBinding) -> bool {
match *__arg_0 {
TypeBinding {
id: ref __self_1_0,
ident: ref __self_1_1,
ty: ref __self_1_2,
span: ref __self_1_3 } =>
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &TypeBinding) -> bool {
match *__arg_0 {
TypeBinding {
id: ref __self_1_0,
ident: ref __self_1_1,
ty: ref __self_1_2,
span: ref __self_1_3 } =>
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TypeBinding {
#[inline]
fn clone(&self) -> TypeBinding {
match *self {
TypeBinding {
id: ref __self_0_0,
ident: ref __self_0_1,
ty: ref __self_0_2,
span: ref __self_0_3 } =>
TypeBinding{id: ::std::clone::Clone::clone(&(*__self_0_0)),
ident: ::std::clone::Clone::clone(&(*__self_0_1)),
ty: ::std::clone::Clone::clone(&(*__self_0_2)),
span:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
pub struct Ty {
pub id: NodeId,
pub node: Ty_,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Ty {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Ty {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Ty {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Ty, __D::Error> {
__arg_0.read_struct("Ty", 3usize, |_d| -> _ {
::std::result::Result::Ok(Ty{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Ty {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Ty {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} =>
__arg_0.emit_struct("Ty", 3usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Ty {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Ty {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Ty {
#[inline]
fn eq(&self, __arg_0: &Ty) -> bool {
match *__arg_0 {
Ty {
id: ref __self_1_0, node: ref __self_1_1, span: ref __self_1_2
} =>
match *self {
Ty {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Ty) -> bool {
match *__arg_0 {
Ty {
id: ref __self_1_0, node: ref __self_1_1, span: ref __self_1_2
} =>
match *self {
Ty {
id: ref __self_0_0,
node: ref __self_0_1,
span: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Ty {
#[inline]
fn clone(&self) -> Ty {
match *self {
Ty {
id: ref __self_0_0, node: ref __self_0_1, span: ref __self_0_2
} =>
Ty{id: ::std::clone::Clone::clone(&(*__self_0_0)),
node: ::std::clone::Clone::clone(&(*__self_0_1)),
span: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl fmt::Debug for Ty {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["type(", ")"];
__STATIC_FMTSTR
},
&match (&pprust::ty_to_string(self),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
/// Not represented directly in the AST, referred to by name through a ty_path.
pub enum PrimTy {
TyInt(IntTy),
TyUint(UintTy),
TyFloat(FloatTy),
TyStr,
TyBool,
TyChar,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for PrimTy { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for PrimTy {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&PrimTy::TyInt(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyInt");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&PrimTy::TyUint(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyUint");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&PrimTy::TyFloat(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyFloat");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&PrimTy::TyStr,) => {
let mut builder = __arg_0.debug_tuple("TyStr");
builder.finish()
}
(&PrimTy::TyBool,) => {
let mut builder = __arg_0.debug_tuple("TyBool");
builder.finish()
}
(&PrimTy::TyChar,) => {
let mut builder = __arg_0.debug_tuple("TyChar");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for PrimTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&PrimTy::TyInt(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&PrimTy::TyUint(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&PrimTy::TyFloat(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&PrimTy::TyStr,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&PrimTy::TyBool,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
(&PrimTy::TyChar,) => {
::std::hash::Hash::hash(&5usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for PrimTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<PrimTy, __D::Error> {
__arg_0.read_enum("PrimTy", |_d| -> _ {
_d.read_enum_variant(&["TyInt", "TyUint",
"TyFloat", "TyStr",
"TyBool", "TyChar"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
PrimTy::TyInt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
PrimTy::TyUint(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
PrimTy::TyFloat(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
PrimTy::TyStr,
4usize
=>
PrimTy::TyBool,
5usize
=>
PrimTy::TyChar,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1558u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for PrimTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&PrimTy::TyInt(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("PrimTy", |_e| -> _ {
_e.emit_enum_variant("TyInt", 0usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&PrimTy::TyUint(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("PrimTy", |_e| -> _ {
_e.emit_enum_variant("TyUint", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&PrimTy::TyFloat(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("PrimTy", |_e| -> _ {
_e.emit_enum_variant("TyFloat", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&PrimTy::TyStr,) => {
let _e = __arg_0;
_e.emit_enum("PrimTy", |_e| -> _ {
_e.emit_enum_variant("TyStr", 3usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&PrimTy::TyBool,) => {
let _e = __arg_0;
_e.emit_enum("PrimTy", |_e| -> _ {
_e.emit_enum_variant("TyBool", 4usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&PrimTy::TyChar,) => {
let _e = __arg_0;
_e.emit_enum("PrimTy", |_e| -> _ {
_e.emit_enum_variant("TyChar", 5usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for PrimTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&PrimTy::TyInt(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&PrimTy::TyUint(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&PrimTy::TyFloat(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&PrimTy::TyStr,) => { }
(&PrimTy::TyBool,) => { }
(&PrimTy::TyChar,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for PrimTy {
#[inline]
fn eq(&self, __arg_0: &PrimTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PrimTy::TyInt(ref __self_0),
&PrimTy::TyInt(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&PrimTy::TyUint(ref __self_0),
&PrimTy::TyUint(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&PrimTy::TyFloat(ref __self_0),
&PrimTy::TyFloat(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&PrimTy::TyStr, &PrimTy::TyStr) => true,
(&PrimTy::TyBool, &PrimTy::TyBool) => true,
(&PrimTy::TyChar, &PrimTy::TyChar) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &PrimTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PrimTy::TyInt(ref __self_0),
&PrimTy::TyInt(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&PrimTy::TyUint(ref __self_0),
&PrimTy::TyUint(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&PrimTy::TyFloat(ref __self_0),
&PrimTy::TyFloat(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&PrimTy::TyStr, &PrimTy::TyStr) => false,
(&PrimTy::TyBool, &PrimTy::TyBool) => false,
(&PrimTy::TyChar, &PrimTy::TyChar) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PrimTy {
#[inline]
fn clone(&self) -> PrimTy {
match (&*self,) {
(&PrimTy::TyInt(ref __self_0),) =>
PrimTy::TyInt(::std::clone::Clone::clone(&(*__self_0))),
(&PrimTy::TyUint(ref __self_0),) =>
PrimTy::TyUint(::std::clone::Clone::clone(&(*__self_0))),
(&PrimTy::TyFloat(ref __self_0),) =>
PrimTy::TyFloat(::std::clone::Clone::clone(&(*__self_0))),
(&PrimTy::TyStr,) => PrimTy::TyStr,
(&PrimTy::TyBool,) => PrimTy::TyBool,
(&PrimTy::TyChar,) => PrimTy::TyChar,
}
}
}
pub struct BareFnTy {
pub unsafety: Unsafety,
pub abi: Abi,
pub lifetimes: Vec<LifetimeDef>,
pub decl: P<FnDecl>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for BareFnTy {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("BareFnTy");
let _ = builder.field("unsafety", &&(*__self_0_0));
let _ = builder.field("abi", &&(*__self_0_1));
let _ = builder.field("lifetimes", &&(*__self_0_2));
let _ = builder.field("decl", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for BareFnTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for BareFnTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<BareFnTy, __D::Error> {
__arg_0.read_struct("BareFnTy", 4usize, |_d| -> _ {
::std::result::Result::Ok(BareFnTy{unsafety:
match _d.read_struct_field("unsafety",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
abi:
match _d.read_struct_field("abi",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
lifetimes:
match _d.read_struct_field("lifetimes",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
decl:
match _d.read_struct_field("decl",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for BareFnTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } =>
__arg_0.emit_struct("BareFnTy", 4usize, |_e| -> _ {
match _e.emit_struct_field("unsafety",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("abi", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("lifetimes",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("decl",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for BareFnTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for BareFnTy {
#[inline]
fn eq(&self, __arg_0: &BareFnTy) -> bool {
match *__arg_0 {
BareFnTy {
unsafety: ref __self_1_0,
abi: ref __self_1_1,
lifetimes: ref __self_1_2,
decl: ref __self_1_3 } =>
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &BareFnTy) -> bool {
match *__arg_0 {
BareFnTy {
unsafety: ref __self_1_0,
abi: ref __self_1_1,
lifetimes: ref __self_1_2,
decl: ref __self_1_3 } =>
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BareFnTy {
#[inline]
fn clone(&self) -> BareFnTy {
match *self {
BareFnTy {
unsafety: ref __self_0_0,
abi: ref __self_0_1,
lifetimes: ref __self_0_2,
decl: ref __self_0_3 } =>
BareFnTy{unsafety: ::std::clone::Clone::clone(&(*__self_0_0)),
abi: ::std::clone::Clone::clone(&(*__self_0_1)),
lifetimes:
::std::clone::Clone::clone(&(*__self_0_2)),
decl: ::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
/// The different kinds of types recognized by the compiler
pub enum Ty_ {
TyVec(P<Ty>),
/// A fixed length array (`[T; n]`)
TyFixedLengthVec(P<Ty>, P<Expr>),
/// A raw pointer (`*const T` or `*mut T`)
TyPtr(MutTy),
/// A reference (`&'a T` or `&'a mut T`)
TyRptr(Option<Lifetime>, MutTy),
/// A bare function (e.g. `fn(usize) -> bool`)
TyBareFn(P<BareFnTy>),
/// A tuple (`(A, B, C, D,...)`)
TyTup(Vec<P<Ty>>),
/// A path (`module::module::...::Type`), optionally
/// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
///
/// Type parameters are stored in the Path itself
TyPath(Option<QSelf>, Path),
/// Something like `A+B`. Note that `B` must always be a path.
TyObjectSum(P<Ty>, TyParamBounds),
/// A type like `for<'a> Foo<&'a Bar>`
TyPolyTraitRef(TyParamBounds),
/// No-op; kept solely so that we can pretty-print faithfully
TyParen(P<Ty>),
/// Unused for now
TyTypeof(P<Expr>),
/// TyInfer means the type should be inferred instead of it having been
/// specified. This can appear anywhere in a type.
TyInfer,
TyMac(Mac),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Ty_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Ty_::TyVec(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyVec");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("TyFixedLengthVec");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Ty_::TyPtr(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyPtr");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyRptr(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("TyRptr");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Ty_::TyBareFn(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyBareFn");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyTup(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyTup");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyPath(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("TyPath");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("TyObjectSum");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Ty_::TyPolyTraitRef(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyPolyTraitRef");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyParen(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyParen");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyTypeof(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyTypeof");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Ty_::TyInfer,) => {
let mut builder = __arg_0.debug_tuple("TyInfer");
builder.finish()
}
(&Ty_::TyMac(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TyMac");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Ty_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Ty_::TyVec(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Ty_::TyPtr(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyRptr(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Ty_::TyBareFn(ref __self_0),) => {
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyTup(ref __self_0),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyPath(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Ty_::TyPolyTraitRef(ref __self_0),) => {
::std::hash::Hash::hash(&8usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyParen(ref __self_0),) => {
::std::hash::Hash::hash(&9usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyTypeof(ref __self_0),) => {
::std::hash::Hash::hash(&10usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Ty_::TyInfer,) => {
::std::hash::Hash::hash(&11usize, __arg_0);
}
(&Ty_::TyMac(ref __self_0),) => {
::std::hash::Hash::hash(&12usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Ty_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Ty_, __D::Error> {
__arg_0.read_enum("Ty_", |_d| -> _ {
_d.read_enum_variant(&["TyVec",
"TyFixedLengthVec",
"TyPtr", "TyRptr",
"TyBareFn", "TyTup",
"TyPath", "TyObjectSum",
"TyPolyTraitRef",
"TyParen", "TyTypeof",
"TyInfer", "TyMac"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Ty_::TyVec(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Ty_::TyFixedLengthVec(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Ty_::TyPtr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Ty_::TyRptr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Ty_::TyBareFn(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Ty_::TyTup(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Ty_::TyPath(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Ty_::TyObjectSum(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
8usize
=>
Ty_::TyPolyTraitRef(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
9usize
=>
Ty_::TyParen(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
10usize
=>
Ty_::TyTypeof(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
11usize
=>
Ty_::TyInfer,
12usize
=>
Ty_::TyMac(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1576u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Ty_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Ty_::TyVec(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyVec", 0usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyFixedLengthVec",
1usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Ty_::TyPtr(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyPtr", 2usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyRptr(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyRptr", 3usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Ty_::TyBareFn(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyBareFn", 4usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyTup(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyTup", 5usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyPath(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyPath", 6usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyObjectSum", 7usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Ty_::TyPolyTraitRef(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyPolyTraitRef",
8usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyParen(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyParen", 9usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyTypeof(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyTypeof", 10usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Ty_::TyInfer,) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyInfer", 11usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Ty_::TyMac(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Ty_", |_e| -> _ {
_e.emit_enum_variant("TyMac", 12usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Ty_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Ty_::TyVec(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Ty_::TyPtr(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyRptr(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Ty_::TyBareFn(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyTup(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyPath(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Ty_::TyPolyTraitRef(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyParen(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyTypeof(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Ty_::TyInfer,) => { }
(&Ty_::TyMac(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Ty_ {
#[inline]
fn eq(&self, __arg_0: &Ty_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Ty_::TyVec(ref __self_0),
&Ty_::TyVec(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),
&Ty_::TyFixedLengthVec(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Ty_::TyPtr(ref __self_0),
&Ty_::TyPtr(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyRptr(ref __self_0, ref __self_1),
&Ty_::TyRptr(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Ty_::TyBareFn(ref __self_0),
&Ty_::TyBareFn(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyTup(ref __self_0),
&Ty_::TyTup(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyPath(ref __self_0, ref __self_1),
&Ty_::TyPath(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),
&Ty_::TyObjectSum(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Ty_::TyPolyTraitRef(ref __self_0),
&Ty_::TyPolyTraitRef(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyParen(ref __self_0),
&Ty_::TyParen(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyTypeof(ref __self_0),
&Ty_::TyTypeof(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Ty_::TyInfer, &Ty_::TyInfer) => true,
(&Ty_::TyMac(ref __self_0),
&Ty_::TyMac(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Ty_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Ty_::TyVec(ref __self_0),
&Ty_::TyVec(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),
&Ty_::TyFixedLengthVec(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Ty_::TyPtr(ref __self_0),
&Ty_::TyPtr(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyRptr(ref __self_0, ref __self_1),
&Ty_::TyRptr(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Ty_::TyBareFn(ref __self_0),
&Ty_::TyBareFn(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyTup(ref __self_0),
&Ty_::TyTup(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyPath(ref __self_0, ref __self_1),
&Ty_::TyPath(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),
&Ty_::TyObjectSum(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Ty_::TyPolyTraitRef(ref __self_0),
&Ty_::TyPolyTraitRef(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyParen(ref __self_0),
&Ty_::TyParen(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyTypeof(ref __self_0),
&Ty_::TyTypeof(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Ty_::TyInfer, &Ty_::TyInfer) => false,
(&Ty_::TyMac(ref __self_0),
&Ty_::TyMac(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Ty_ {
#[inline]
fn clone(&self) -> Ty_ {
match (&*self,) {
(&Ty_::TyVec(ref __self_0),) =>
Ty_::TyVec(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyFixedLengthVec(ref __self_0, ref __self_1),) =>
Ty_::TyFixedLengthVec(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Ty_::TyPtr(ref __self_0),) =>
Ty_::TyPtr(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyRptr(ref __self_0, ref __self_1),) =>
Ty_::TyRptr(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Ty_::TyBareFn(ref __self_0),) =>
Ty_::TyBareFn(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyTup(ref __self_0),) =>
Ty_::TyTup(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyPath(ref __self_0, ref __self_1),) =>
Ty_::TyPath(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Ty_::TyObjectSum(ref __self_0, ref __self_1),) =>
Ty_::TyObjectSum(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Ty_::TyPolyTraitRef(ref __self_0),) =>
Ty_::TyPolyTraitRef(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyParen(ref __self_0),) =>
Ty_::TyParen(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyTypeof(ref __self_0),) =>
Ty_::TyTypeof(::std::clone::Clone::clone(&(*__self_0))),
(&Ty_::TyInfer,) => Ty_::TyInfer,
(&Ty_::TyMac(ref __self_0),) =>
Ty_::TyMac(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum AsmDialect { Att, Intel, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AsmDialect { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AsmDialect {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&AsmDialect::Att,) => {
let mut builder = __arg_0.debug_tuple("Att");
builder.finish()
}
(&AsmDialect::Intel,) => {
let mut builder = __arg_0.debug_tuple("Intel");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for AsmDialect {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&AsmDialect::Att,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&AsmDialect::Intel,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for AsmDialect {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<AsmDialect, __D::Error> {
__arg_0.read_enum("AsmDialect", |_d| -> _ {
_d.read_enum_variant(&["Att", "Intel"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
AsmDialect::Att,
1usize
=>
AsmDialect::Intel,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1610u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for AsmDialect {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&AsmDialect::Att,) => {
let _e = __arg_0;
_e.emit_enum("AsmDialect", |_e| -> _ {
_e.emit_enum_variant("Att", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&AsmDialect::Intel,) => {
let _e = __arg_0;
_e.emit_enum("AsmDialect", |_e| -> _ {
_e.emit_enum_variant("Intel", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for AsmDialect {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&AsmDialect::Att,) => { }
(&AsmDialect::Intel,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AsmDialect {
#[inline]
fn eq(&self, __arg_0: &AsmDialect) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AsmDialect::Att, &AsmDialect::Att) => true,
(&AsmDialect::Intel, &AsmDialect::Intel) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &AsmDialect) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AsmDialect::Att, &AsmDialect::Att) => false,
(&AsmDialect::Intel, &AsmDialect::Intel) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AsmDialect {
#[inline]
fn clone(&self) -> AsmDialect {
match (&*self,) {
(&AsmDialect::Att,) => AsmDialect::Att,
(&AsmDialect::Intel,) => AsmDialect::Intel,
}
}
}
pub struct InlineAsmOutput {
pub constraint: InternedString,
pub expr: P<Expr>,
pub is_rw: bool,
pub is_indirect: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for InlineAsmOutput {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("InlineAsmOutput");
let _ = builder.field("constraint", &&(*__self_0_0));
let _ = builder.field("expr", &&(*__self_0_1));
let _ = builder.field("is_rw", &&(*__self_0_2));
let _ = builder.field("is_indirect", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for InlineAsmOutput {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for InlineAsmOutput {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<InlineAsmOutput, __D::Error> {
__arg_0.read_struct("InlineAsmOutput", 4usize, |_d| -> _ {
::std::result::Result::Ok(InlineAsmOutput{constraint:
match _d.read_struct_field("constraint",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
expr:
match _d.read_struct_field("expr",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
is_rw:
match _d.read_struct_field("is_rw",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
is_indirect:
match _d.read_struct_field("is_indirect",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for InlineAsmOutput {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } =>
__arg_0.emit_struct("InlineAsmOutput", 4usize, |_e| -> _ {
match _e.emit_struct_field("constraint",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("expr", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("is_rw",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("is_indirect",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for InlineAsmOutput {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for InlineAsmOutput {
#[inline]
fn eq(&self, __arg_0: &InlineAsmOutput) -> bool {
match *__arg_0 {
InlineAsmOutput {
constraint: ref __self_1_0,
expr: ref __self_1_1,
is_rw: ref __self_1_2,
is_indirect: ref __self_1_3 } =>
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &InlineAsmOutput) -> bool {
match *__arg_0 {
InlineAsmOutput {
constraint: ref __self_1_0,
expr: ref __self_1_1,
is_rw: ref __self_1_2,
is_indirect: ref __self_1_3 } =>
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for InlineAsmOutput {
#[inline]
fn clone(&self) -> InlineAsmOutput {
match *self {
InlineAsmOutput {
constraint: ref __self_0_0,
expr: ref __self_0_1,
is_rw: ref __self_0_2,
is_indirect: ref __self_0_3 } =>
InlineAsmOutput{constraint:
::std::clone::Clone::clone(&(*__self_0_0)),
expr:
::std::clone::Clone::clone(&(*__self_0_1)),
is_rw:
::std::clone::Clone::clone(&(*__self_0_2)),
is_indirect:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
pub struct InlineAsm {
pub asm: InternedString,
pub asm_str_style: StrStyle,
pub outputs: Vec<InlineAsmOutput>,
pub inputs: Vec<(InternedString, P<Expr>)>,
pub clobbers: Vec<InternedString>,
pub volatile: bool,
pub alignstack: bool,
pub dialect: AsmDialect,
pub expn_id: ExpnId,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for InlineAsm {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } => {
let mut builder = __arg_0.debug_struct("InlineAsm");
let _ = builder.field("asm", &&(*__self_0_0));
let _ = builder.field("asm_str_style", &&(*__self_0_1));
let _ = builder.field("outputs", &&(*__self_0_2));
let _ = builder.field("inputs", &&(*__self_0_3));
let _ = builder.field("clobbers", &&(*__self_0_4));
let _ = builder.field("volatile", &&(*__self_0_5));
let _ = builder.field("alignstack", &&(*__self_0_6));
let _ = builder.field("dialect", &&(*__self_0_7));
let _ = builder.field("expn_id", &&(*__self_0_8));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for InlineAsm {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
::std::hash::Hash::hash(&(*__self_0_6), __arg_0);
::std::hash::Hash::hash(&(*__self_0_7), __arg_0);
::std::hash::Hash::hash(&(*__self_0_8), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for InlineAsm {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<InlineAsm, __D::Error> {
__arg_0.read_struct("InlineAsm", 9usize, |_d| -> _ {
::std::result::Result::Ok(InlineAsm{asm:
match _d.read_struct_field("asm",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
asm_str_style:
match _d.read_struct_field("asm_str_style",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
outputs:
match _d.read_struct_field("outputs",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
inputs:
match _d.read_struct_field("inputs",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
clobbers:
match _d.read_struct_field("clobbers",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
volatile:
match _d.read_struct_field("volatile",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
alignstack:
match _d.read_struct_field("alignstack",
6usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
dialect:
match _d.read_struct_field("dialect",
7usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
expn_id:
match _d.read_struct_field("expn_id",
8usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for InlineAsm {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } =>
__arg_0.emit_struct("InlineAsm", 9usize, |_e| -> _ {
match _e.emit_struct_field("asm", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("asm_str_style",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("outputs",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("inputs",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("clobbers",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("volatile",
5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("alignstack",
6usize,
|_e| -> _ {
(*__self_0_6).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("dialect",
7usize,
|_e| -> _ {
(*__self_0_7).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("expn_id",
8usize,
|_e| -> _ {
(*__self_0_8).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for InlineAsm {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
(*__self_0_6).assert_receiver_is_total_eq();
(*__self_0_7).assert_receiver_is_total_eq();
(*__self_0_8).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for InlineAsm {
#[inline]
fn eq(&self, __arg_0: &InlineAsm) -> bool {
match *__arg_0 {
InlineAsm {
asm: ref __self_1_0,
asm_str_style: ref __self_1_1,
outputs: ref __self_1_2,
inputs: ref __self_1_3,
clobbers: ref __self_1_4,
volatile: ref __self_1_5,
alignstack: ref __self_1_6,
dialect: ref __self_1_7,
expn_id: ref __self_1_8 } =>
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5) &&
(*__self_0_6) == (*__self_1_6) &&
(*__self_0_7) == (*__self_1_7) &&
(*__self_0_8) == (*__self_1_8),
},
}
}
#[inline]
fn ne(&self, __arg_0: &InlineAsm) -> bool {
match *__arg_0 {
InlineAsm {
asm: ref __self_1_0,
asm_str_style: ref __self_1_1,
outputs: ref __self_1_2,
inputs: ref __self_1_3,
clobbers: ref __self_1_4,
volatile: ref __self_1_5,
alignstack: ref __self_1_6,
dialect: ref __self_1_7,
expn_id: ref __self_1_8 } =>
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5) ||
(*__self_0_6) != (*__self_1_6) ||
(*__self_0_7) != (*__self_1_7) ||
(*__self_0_8) != (*__self_1_8),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for InlineAsm {
#[inline]
fn clone(&self) -> InlineAsm {
match *self {
InlineAsm {
asm: ref __self_0_0,
asm_str_style: ref __self_0_1,
outputs: ref __self_0_2,
inputs: ref __self_0_3,
clobbers: ref __self_0_4,
volatile: ref __self_0_5,
alignstack: ref __self_0_6,
dialect: ref __self_0_7,
expn_id: ref __self_0_8 } =>
InlineAsm{asm: ::std::clone::Clone::clone(&(*__self_0_0)),
asm_str_style:
::std::clone::Clone::clone(&(*__self_0_1)),
outputs: ::std::clone::Clone::clone(&(*__self_0_2)),
inputs: ::std::clone::Clone::clone(&(*__self_0_3)),
clobbers:
::std::clone::Clone::clone(&(*__self_0_4)),
volatile:
::std::clone::Clone::clone(&(*__self_0_5)),
alignstack:
::std::clone::Clone::clone(&(*__self_0_6)),
dialect: ::std::clone::Clone::clone(&(*__self_0_7)),
expn_id:
::std::clone::Clone::clone(&(*__self_0_8)),},
}
}
}
/// represents an argument in a function header
pub struct Arg {
pub ty: P<Ty>,
pub pat: P<Pat>,
pub id: NodeId,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Arg {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Arg {
ty: ref __self_0_0, pat: ref __self_0_1, id: ref __self_0_2 }
=> {
let mut builder = __arg_0.debug_struct("Arg");
let _ = builder.field("ty", &&(*__self_0_0));
let _ = builder.field("pat", &&(*__self_0_1));
let _ = builder.field("id", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Arg {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Arg {
ty: ref __self_0_0, pat: ref __self_0_1, id: ref __self_0_2 }
=> {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Arg {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Arg, __D::Error> {
__arg_0.read_struct("Arg", 3usize, |_d| -> _ {
::std::result::Result::Ok(Arg{ty:
match _d.read_struct_field("ty",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
pat:
match _d.read_struct_field("pat",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Arg {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Arg {
ty: ref __self_0_0, pat: ref __self_0_1, id: ref __self_0_2 }
=>
__arg_0.emit_struct("Arg", 3usize, |_e| -> _ {
match _e.emit_struct_field("ty", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("pat", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("id", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Arg {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Arg {
ty: ref __self_0_0, pat: ref __self_0_1, id: ref __self_0_2 }
=> {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Arg {
#[inline]
fn eq(&self, __arg_0: &Arg) -> bool {
match *__arg_0 {
Arg {
ty: ref __self_1_0, pat: ref __self_1_1, id: ref __self_1_2 }
=>
match *self {
Arg {
ty: ref __self_0_0,
pat: ref __self_0_1,
id: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Arg) -> bool {
match *__arg_0 {
Arg {
ty: ref __self_1_0, pat: ref __self_1_1, id: ref __self_1_2 }
=>
match *self {
Arg {
ty: ref __self_0_0,
pat: ref __self_0_1,
id: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Arg {
#[inline]
fn clone(&self) -> Arg {
match *self {
Arg {
ty: ref __self_0_0, pat: ref __self_0_1, id: ref __self_0_2 }
=>
Arg{ty: ::std::clone::Clone::clone(&(*__self_0_0)),
pat: ::std::clone::Clone::clone(&(*__self_0_1)),
id: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl Arg {
pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident)
-> Arg {
let path = Spanned{span: span, node: self_ident,};
Arg{ty: P(Ty{id: DUMMY_NODE_ID, node: TyInfer, span: DUMMY_SP,}),
pat:
P(Pat{id: DUMMY_NODE_ID,
node:
PatIdent(BindingMode::ByValue(mutability), path,
None),
span: span,}),
id: DUMMY_NODE_ID,}
}
}
/// Represents the header (not the body) of a function declaration
pub struct FnDecl {
pub inputs: Vec<Arg>,
pub output: FunctionRetTy,
pub variadic: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for FnDecl {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("FnDecl");
let _ = builder.field("inputs", &&(*__self_0_0));
let _ = builder.field("output", &&(*__self_0_1));
let _ = builder.field("variadic", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for FnDecl {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for FnDecl {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<FnDecl, __D::Error> {
__arg_0.read_struct("FnDecl", 3usize, |_d| -> _ {
::std::result::Result::Ok(FnDecl{inputs:
match _d.read_struct_field("inputs",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
output:
match _d.read_struct_field("output",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
variadic:
match _d.read_struct_field("variadic",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for FnDecl {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } =>
__arg_0.emit_struct("FnDecl", 3usize, |_e| -> _ {
match _e.emit_struct_field("inputs",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("output",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("variadic",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for FnDecl {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for FnDecl {
#[inline]
fn eq(&self, __arg_0: &FnDecl) -> bool {
match *__arg_0 {
FnDecl {
inputs: ref __self_1_0,
output: ref __self_1_1,
variadic: ref __self_1_2 } =>
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &FnDecl) -> bool {
match *__arg_0 {
FnDecl {
inputs: ref __self_1_0,
output: ref __self_1_1,
variadic: ref __self_1_2 } =>
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for FnDecl {
#[inline]
fn clone(&self) -> FnDecl {
match *self {
FnDecl {
inputs: ref __self_0_0,
output: ref __self_0_1,
variadic: ref __self_0_2 } =>
FnDecl{inputs: ::std::clone::Clone::clone(&(*__self_0_0)),
output: ::std::clone::Clone::clone(&(*__self_0_1)),
variadic: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub enum Unsafety { Unsafe, Normal, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Unsafety {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Unsafety::Unsafe,) => {
let mut builder = __arg_0.debug_tuple("Unsafe");
builder.finish()
}
(&Unsafety::Normal,) => {
let mut builder = __arg_0.debug_tuple("Normal");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Unsafety {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Unsafety::Unsafe,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Unsafety::Normal,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Unsafety {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Unsafety, __D::Error> {
__arg_0.read_enum("Unsafety", |_d| -> _ {
_d.read_enum_variant(&["Unsafe", "Normal"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Unsafety::Unsafe,
1usize
=>
Unsafety::Normal,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1673u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Unsafety {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Unsafety::Unsafe,) => {
let _e = __arg_0;
_e.emit_enum("Unsafety", |_e| -> _ {
_e.emit_enum_variant("Unsafe", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Unsafety::Normal,) => {
let _e = __arg_0;
_e.emit_enum("Unsafety", |_e| -> _ {
_e.emit_enum_variant("Normal", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Unsafety {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Unsafety::Unsafe,) => { }
(&Unsafety::Normal,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Unsafety {
#[inline]
fn eq(&self, __arg_0: &Unsafety) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Unsafety::Unsafe, &Unsafety::Unsafe) => true,
(&Unsafety::Normal, &Unsafety::Normal) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Unsafety) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Unsafety::Unsafe, &Unsafety::Unsafe) => false,
(&Unsafety::Normal, &Unsafety::Normal) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Unsafety {
#[inline]
fn clone(&self) -> Unsafety {
match (&*self,) {
(&Unsafety::Unsafe,) => Unsafety::Unsafe,
(&Unsafety::Normal,) => Unsafety::Normal,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Unsafety { }
pub enum Constness { Const, NotConst, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Constness {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Constness::Const,) => {
let mut builder = __arg_0.debug_tuple("Const");
builder.finish()
}
(&Constness::NotConst,) => {
let mut builder = __arg_0.debug_tuple("NotConst");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Constness {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Constness::Const,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Constness::NotConst,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Constness {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Constness, __D::Error> {
__arg_0.read_enum("Constness", |_d| -> _ {
_d.read_enum_variant(&["Const", "NotConst"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Constness::Const,
1usize
=>
Constness::NotConst,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1679u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Constness {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Constness::Const,) => {
let _e = __arg_0;
_e.emit_enum("Constness", |_e| -> _ {
_e.emit_enum_variant("Const", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Constness::NotConst,) => {
let _e = __arg_0;
_e.emit_enum("Constness", |_e| -> _ {
_e.emit_enum_variant("NotConst", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Constness {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Constness::Const,) => { }
(&Constness::NotConst,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Constness {
#[inline]
fn eq(&self, __arg_0: &Constness) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Constness::Const, &Constness::Const) => true,
(&Constness::NotConst, &Constness::NotConst) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Constness) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Constness::Const, &Constness::Const) => false,
(&Constness::NotConst, &Constness::NotConst) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Constness {
#[inline]
fn clone(&self) -> Constness {
match (&*self,) {
(&Constness::Const,) => Constness::Const,
(&Constness::NotConst,) => Constness::NotConst,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Constness { }
impl fmt::Display for Unsafety {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(match *self {
Unsafety::Normal => "normal",
Unsafety::Unsafe => "unsafe",
}, f)
}
}
pub enum ImplPolarity {
/// `impl Trait for Type`
Positive,
/// `impl !Trait for Type`
Negative,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ImplPolarity {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&ImplPolarity::Positive,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&ImplPolarity::Negative,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ImplPolarity {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ImplPolarity, __D::Error> {
__arg_0.read_enum("ImplPolarity", |_d| -> _ {
_d.read_enum_variant(&["Positive", "Negative"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
ImplPolarity::Positive,
1usize
=>
ImplPolarity::Negative,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1694u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ImplPolarity {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&ImplPolarity::Positive,) => {
let _e = __arg_0;
_e.emit_enum("ImplPolarity", |_e| -> _ {
_e.emit_enum_variant("Positive", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&ImplPolarity::Negative,) => {
let _e = __arg_0;
_e.emit_enum("ImplPolarity", |_e| -> _ {
_e.emit_enum_variant("Negative", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ImplPolarity {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ImplPolarity::Positive,) => { }
(&ImplPolarity::Negative,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ImplPolarity {
#[inline]
fn eq(&self, __arg_0: &ImplPolarity) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ImplPolarity::Positive, &ImplPolarity::Positive) =>
true,
(&ImplPolarity::Negative, &ImplPolarity::Negative) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ImplPolarity) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ImplPolarity::Positive, &ImplPolarity::Positive) =>
false,
(&ImplPolarity::Negative, &ImplPolarity::Negative) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ImplPolarity {
#[inline]
fn clone(&self) -> ImplPolarity {
match (&*self,) {
(&ImplPolarity::Positive,) => ImplPolarity::Positive,
(&ImplPolarity::Negative,) => ImplPolarity::Negative,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ImplPolarity { }
impl fmt::Debug for ImplPolarity {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ImplPolarity::Positive => "positive".fmt(f),
ImplPolarity::Negative => "negative".fmt(f),
}
}
}
pub enum FunctionRetTy {
/// Functions with return type `!`that always
/// raise an error or exit (i.e. never return to the caller)
NoReturn(Span),
/// Return type is not specified.
///
/// Functions default to `()` and
/// closures default to inference. Span points to where return
/// type would be inserted.
DefaultReturn(Span),
/// Everything else
Return(P<Ty>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for FunctionRetTy {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&FunctionRetTy::NoReturn(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("NoReturn");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&FunctionRetTy::DefaultReturn(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("DefaultReturn");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&FunctionRetTy::Return(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Return");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for FunctionRetTy {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&FunctionRetTy::NoReturn(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&FunctionRetTy::DefaultReturn(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&FunctionRetTy::Return(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for FunctionRetTy {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<FunctionRetTy, __D::Error> {
__arg_0.read_enum("FunctionRetTy", |_d| -> _ {
_d.read_enum_variant(&["NoReturn",
"DefaultReturn",
"Return"], |_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
FunctionRetTy::NoReturn(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
FunctionRetTy::DefaultReturn(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
FunctionRetTy::Return(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1712u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for FunctionRetTy {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&FunctionRetTy::NoReturn(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("FunctionRetTy", |_e| -> _ {
_e.emit_enum_variant("NoReturn", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&FunctionRetTy::DefaultReturn(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("FunctionRetTy", |_e| -> _ {
_e.emit_enum_variant("DefaultReturn", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&FunctionRetTy::Return(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("FunctionRetTy", |_e| -> _ {
_e.emit_enum_variant("Return", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for FunctionRetTy {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&FunctionRetTy::NoReturn(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&FunctionRetTy::DefaultReturn(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&FunctionRetTy::Return(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for FunctionRetTy {
#[inline]
fn eq(&self, __arg_0: &FunctionRetTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&FunctionRetTy::NoReturn(ref __self_0),
&FunctionRetTy::NoReturn(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&FunctionRetTy::DefaultReturn(ref __self_0),
&FunctionRetTy::DefaultReturn(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&FunctionRetTy::Return(ref __self_0),
&FunctionRetTy::Return(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &FunctionRetTy) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&FunctionRetTy::NoReturn(ref __self_0),
&FunctionRetTy::NoReturn(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&FunctionRetTy::DefaultReturn(ref __self_0),
&FunctionRetTy::DefaultReturn(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&FunctionRetTy::Return(ref __self_0),
&FunctionRetTy::Return(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for FunctionRetTy {
#[inline]
fn clone(&self) -> FunctionRetTy {
match (&*self,) {
(&FunctionRetTy::NoReturn(ref __self_0),) =>
FunctionRetTy::NoReturn(::std::clone::Clone::clone(&(*__self_0))),
(&FunctionRetTy::DefaultReturn(ref __self_0),) =>
FunctionRetTy::DefaultReturn(::std::clone::Clone::clone(&(*__self_0))),
(&FunctionRetTy::Return(ref __self_0),) =>
FunctionRetTy::Return(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl FunctionRetTy {
pub fn span(&self) -> Span {
match *self {
NoReturn(span) => span,
DefaultReturn(span) => span,
Return(ref ty) => ty.span,
}
}
}
/// Represents the kind of 'self' associated with a method
pub enum ExplicitSelf_ {
/// No self
SelfStatic,
/// `self`
SelfValue(Ident),
/// `&'lt self`, `&'lt mut self`
SelfRegion(Option<Lifetime>, Mutability, Ident),
/// `self: TYPE`
SelfExplicit(P<Ty>, Ident),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ExplicitSelf_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&ExplicitSelf_::SelfStatic,) => {
let mut builder = __arg_0.debug_tuple("SelfStatic");
builder.finish()
}
(&ExplicitSelf_::SelfValue(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("SelfValue");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&ExplicitSelf_::SelfRegion(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("SelfRegion");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&ExplicitSelf_::SelfExplicit(ref __self_0, ref __self_1),) =>
{
let mut builder = __arg_0.debug_tuple("SelfExplicit");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ExplicitSelf_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&ExplicitSelf_::SelfStatic,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&ExplicitSelf_::SelfValue(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&ExplicitSelf_::SelfRegion(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&ExplicitSelf_::SelfExplicit(ref __self_0, ref __self_1),) =>
{
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ExplicitSelf_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ExplicitSelf_, __D::Error> {
__arg_0.read_enum("ExplicitSelf_", |_d| -> _ {
_d.read_enum_variant(&["SelfStatic",
"SelfValue",
"SelfRegion",
"SelfExplicit"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
ExplicitSelf_::SelfStatic,
1usize
=>
ExplicitSelf_::SelfValue(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
ExplicitSelf_::SelfRegion(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
ExplicitSelf_::SelfExplicit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1738u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ExplicitSelf_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&ExplicitSelf_::SelfStatic,) => {
let _e = __arg_0;
_e.emit_enum("ExplicitSelf_", |_e| -> _ {
_e.emit_enum_variant("SelfStatic", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&ExplicitSelf_::SelfValue(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("ExplicitSelf_", |_e| -> _ {
_e.emit_enum_variant("SelfValue", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&ExplicitSelf_::SelfRegion(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("ExplicitSelf_", |_e| -> _ {
_e.emit_enum_variant("SelfRegion", 2usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&ExplicitSelf_::SelfExplicit(ref __self_0, ref __self_1),) =>
{
let _e = __arg_0;
_e.emit_enum("ExplicitSelf_", |_e| -> _ {
_e.emit_enum_variant("SelfExplicit", 3usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ExplicitSelf_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ExplicitSelf_::SelfStatic,) => { }
(&ExplicitSelf_::SelfValue(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&ExplicitSelf_::SelfRegion(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&ExplicitSelf_::SelfExplicit(ref __self_0, ref __self_1),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ExplicitSelf_ {
#[inline]
fn eq(&self, __arg_0: &ExplicitSelf_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ExplicitSelf_::SelfStatic,
&ExplicitSelf_::SelfStatic) => true,
(&ExplicitSelf_::SelfValue(ref __self_0),
&ExplicitSelf_::SelfValue(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&ExplicitSelf_::SelfRegion(ref __self_0,
ref __self_1,
ref __self_2),
&ExplicitSelf_::SelfRegion(ref __arg_1_0,
ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&ExplicitSelf_::SelfExplicit(ref __self_0,
ref __self_1),
&ExplicitSelf_::SelfExplicit(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ExplicitSelf_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ExplicitSelf_::SelfStatic,
&ExplicitSelf_::SelfStatic) => false,
(&ExplicitSelf_::SelfValue(ref __self_0),
&ExplicitSelf_::SelfValue(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&ExplicitSelf_::SelfRegion(ref __self_0,
ref __self_1,
ref __self_2),
&ExplicitSelf_::SelfRegion(ref __arg_1_0,
ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&ExplicitSelf_::SelfExplicit(ref __self_0,
ref __self_1),
&ExplicitSelf_::SelfExplicit(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ExplicitSelf_ {
#[inline]
fn clone(&self) -> ExplicitSelf_ {
match (&*self,) {
(&ExplicitSelf_::SelfStatic,) => ExplicitSelf_::SelfStatic,
(&ExplicitSelf_::SelfValue(ref __self_0),) =>
ExplicitSelf_::SelfValue(::std::clone::Clone::clone(&(*__self_0))),
(&ExplicitSelf_::SelfRegion(ref __self_0, ref __self_1,
ref __self_2),) =>
ExplicitSelf_::SelfRegion(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&ExplicitSelf_::SelfExplicit(ref __self_0, ref __self_1),) =>
ExplicitSelf_::SelfExplicit(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
pub type ExplicitSelf = Spanned<ExplicitSelf_>;
pub struct Mod {
/// A span from the first token past `{` to the last token until `}`.
/// For `mod foo;`, the inner span ranges from the first token
/// to the last token in the external file.
pub inner: Span,
pub items: Vec<P<Item>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Mod {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("Mod");
let _ = builder.field("inner", &&(*__self_0_0));
let _ = builder.field("items", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Mod {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Mod {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Mod, __D::Error> {
__arg_0.read_struct("Mod", 2usize, |_d| -> _ {
::std::result::Result::Ok(Mod{inner:
match _d.read_struct_field("inner",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
items:
match _d.read_struct_field("items",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Mod {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } =>
__arg_0.emit_struct("Mod", 2usize, |_e| -> _ {
match _e.emit_struct_field("inner",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("items",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Mod {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Mod {
#[inline]
fn eq(&self, __arg_0: &Mod) -> bool {
match *__arg_0 {
Mod { inner: ref __self_1_0, items: ref __self_1_1 } =>
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Mod) -> bool {
match *__arg_0 {
Mod { inner: ref __self_1_0, items: ref __self_1_1 } =>
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Mod {
#[inline]
fn clone(&self) -> Mod {
match *self {
Mod { inner: ref __self_0_0, items: ref __self_0_1 } =>
Mod{inner: ::std::clone::Clone::clone(&(*__self_0_0)),
items: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct ForeignMod {
pub abi: Abi,
pub items: Vec<P<ForeignItem>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ForeignMod {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("ForeignMod");
let _ = builder.field("abi", &&(*__self_0_0));
let _ = builder.field("items", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ForeignMod {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ForeignMod {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ForeignMod, __D::Error> {
__arg_0.read_struct("ForeignMod", 2usize, |_d| -> _ {
::std::result::Result::Ok(ForeignMod{abi:
match _d.read_struct_field("abi",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
items:
match _d.read_struct_field("items",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ForeignMod {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 } =>
__arg_0.emit_struct("ForeignMod", 2usize, |_e| -> _ {
match _e.emit_struct_field("abi", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("items",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ForeignMod {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ForeignMod {
#[inline]
fn eq(&self, __arg_0: &ForeignMod) -> bool {
match *__arg_0 {
ForeignMod { abi: ref __self_1_0, items: ref __self_1_1 } =>
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 }
=>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ForeignMod) -> bool {
match *__arg_0 {
ForeignMod { abi: ref __self_1_0, items: ref __self_1_1 } =>
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 }
=>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ForeignMod {
#[inline]
fn clone(&self) -> ForeignMod {
match *self {
ForeignMod { abi: ref __self_0_0, items: ref __self_0_1 } =>
ForeignMod{abi: ::std::clone::Clone::clone(&(*__self_0_0)),
items:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct EnumDef {
pub variants: Vec<P<Variant>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for EnumDef {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
EnumDef { variants: ref __self_0_0 } => {
let mut builder = __arg_0.debug_struct("EnumDef");
let _ = builder.field("variants", &&(*__self_0_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for EnumDef {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
EnumDef { variants: ref __self_0_0 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for EnumDef {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<EnumDef, __D::Error> {
__arg_0.read_struct("EnumDef", 1usize, |_d| -> _ {
::std::result::Result::Ok(EnumDef{variants:
match _d.read_struct_field("variants",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for EnumDef {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
EnumDef { variants: ref __self_0_0 } =>
__arg_0.emit_struct("EnumDef", 1usize, |_e| -> _ {
return _e.emit_struct_field("variants",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for EnumDef {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
EnumDef { variants: ref __self_0_0 } => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for EnumDef {
#[inline]
fn eq(&self, __arg_0: &EnumDef) -> bool {
match *__arg_0 {
EnumDef { variants: ref __self_1_0 } =>
match *self {
EnumDef { variants: ref __self_0_0 } =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &EnumDef) -> bool {
match *__arg_0 {
EnumDef { variants: ref __self_1_0 } =>
match *self {
EnumDef { variants: ref __self_0_0 } =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for EnumDef {
#[inline]
fn clone(&self) -> EnumDef {
match *self {
EnumDef { variants: ref __self_0_0 } =>
EnumDef{variants:
::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
pub struct Variant_ {
pub name: Ident,
pub attrs: Vec<Attribute>,
pub data: VariantData,
/// Explicit discriminant, eg `Foo = 1`
pub disr_expr: Option<P<Expr>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Variant_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("Variant_");
let _ = builder.field("name", &&(*__self_0_0));
let _ = builder.field("attrs", &&(*__self_0_1));
let _ = builder.field("data", &&(*__self_0_2));
let _ = builder.field("disr_expr", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Variant_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Variant_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Variant_, __D::Error> {
__arg_0.read_struct("Variant_", 4usize, |_d| -> _ {
::std::result::Result::Ok(Variant_{name:
match _d.read_struct_field("name",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
data:
match _d.read_struct_field("data",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
disr_expr:
match _d.read_struct_field("disr_expr",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Variant_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } =>
__arg_0.emit_struct("Variant_", 4usize, |_e| -> _ {
match _e.emit_struct_field("name", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("data", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("disr_expr",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Variant_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Variant_ {
#[inline]
fn eq(&self, __arg_0: &Variant_) -> bool {
match *__arg_0 {
Variant_ {
name: ref __self_1_0,
attrs: ref __self_1_1,
data: ref __self_1_2,
disr_expr: ref __self_1_3 } =>
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Variant_) -> bool {
match *__arg_0 {
Variant_ {
name: ref __self_1_0,
attrs: ref __self_1_1,
data: ref __self_1_2,
disr_expr: ref __self_1_3 } =>
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Variant_ {
#[inline]
fn clone(&self) -> Variant_ {
match *self {
Variant_ {
name: ref __self_0_0,
attrs: ref __self_0_1,
data: ref __self_0_2,
disr_expr: ref __self_0_3 } =>
Variant_{name: ::std::clone::Clone::clone(&(*__self_0_0)),
attrs: ::std::clone::Clone::clone(&(*__self_0_1)),
data: ::std::clone::Clone::clone(&(*__self_0_2)),
disr_expr:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
pub type Variant = Spanned<Variant_>;
pub enum PathListItem_ {
PathListIdent {
name: Ident,
/// renamed in list, eg `use foo::{bar as baz};`
rename: Option<Ident>,
id: NodeId,
},
PathListMod {
/// renamed in list, eg `use foo::{self as baz};`
rename: Option<Ident>,
id: NodeId,
},
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for PathListItem_ { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for PathListItem_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&PathListItem_::PathListIdent {
name: ref __self_0, rename: ref __self_1, id: ref __self_2
},) => {
let mut builder = __arg_0.debug_struct("PathListIdent");
let _ = builder.field("name", &&(*__self_0));
let _ = builder.field("rename", &&(*__self_1));
let _ = builder.field("id", &&(*__self_2));
builder.finish()
}
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },) => {
let mut builder = __arg_0.debug_struct("PathListMod");
let _ = builder.field("rename", &&(*__self_0));
let _ = builder.field("id", &&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for PathListItem_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&PathListItem_::PathListIdent {
name: ref __self_0, rename: ref __self_1, id: ref __self_2
},) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for PathListItem_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<PathListItem_, __D::Error> {
__arg_0.read_enum("PathListItem_", |_d| -> _ {
_d.read_enum_variant(&["PathListIdent",
"PathListMod"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
PathListItem_::PathListIdent{name:
match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
rename:
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},},
1usize
=>
PathListItem_::PathListMod{rename:
match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},},
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1783u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for PathListItem_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&PathListItem_::PathListIdent {
name: ref __self_0, rename: ref __self_1, id: ref __self_2
},) => {
let _e = __arg_0;
_e.emit_enum("PathListItem_", |_e| -> _ {
_e.emit_enum_variant("PathListIdent", 0usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },) => {
let _e = __arg_0;
_e.emit_enum("PathListItem_", |_e| -> _ {
_e.emit_enum_variant("PathListMod", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for PathListItem_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&PathListItem_::PathListIdent {
name: ref __self_0, rename: ref __self_1, id: ref __self_2
},) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for PathListItem_ {
#[inline]
fn eq(&self, __arg_0: &PathListItem_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PathListItem_::PathListIdent {
name: ref __self_0,
rename: ref __self_1,
id: ref __self_2 }, &PathListItem_::PathListIdent {
name: ref __arg_1_0,
rename: ref __arg_1_1,
id: ref __arg_1_2 }) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },
&PathListItem_::PathListMod {
rename: ref __arg_1_0, id: ref __arg_1_1 }) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &PathListItem_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PathListItem_::PathListIdent {
name: ref __self_0,
rename: ref __self_1,
id: ref __self_2 }, &PathListItem_::PathListIdent {
name: ref __arg_1_0,
rename: ref __arg_1_1,
id: ref __arg_1_2 }) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },
&PathListItem_::PathListMod {
rename: ref __arg_1_0, id: ref __arg_1_1 }) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PathListItem_ {
#[inline]
fn clone(&self) -> PathListItem_ {
match (&*self,) {
(&PathListItem_::PathListIdent {
name: ref __self_0, rename: ref __self_1, id: ref __self_2
},) =>
PathListItem_::PathListIdent{name:
::std::clone::Clone::clone(&(*__self_0)),
rename:
::std::clone::Clone::clone(&(*__self_1)),
id:
::std::clone::Clone::clone(&(*__self_2)),},
(&PathListItem_::PathListMod {
rename: ref __self_0, id: ref __self_1 },) =>
PathListItem_::PathListMod{rename:
::std::clone::Clone::clone(&(*__self_0)),
id:
::std::clone::Clone::clone(&(*__self_1)),},
}
}
}
impl PathListItem_ {
pub fn id(&self) -> NodeId {
match *self {
PathListIdent { id, .. } | PathListMod { id, .. } => id,
}
}
pub fn name(&self) -> Option<Ident> {
match *self {
PathListIdent { name, .. } => Some(name),
PathListMod { .. } => None,
}
}
pub fn rename(&self) -> Option<Ident> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } =>
rename,
}
}
}
pub type PathListItem = Spanned<PathListItem_>;
pub type ViewPath = Spanned<ViewPath_>;
pub enum ViewPath_ {
/// `foo::bar::baz as quux`
///
/// or just
///
/// `foo::bar::baz` (with `as baz` implicitly on the right)
ViewPathSimple(Ident, Path),
/// `foo::bar::*`
ViewPathGlob(Path),
/// `foo::bar::{a,b,c}`
ViewPathList(Path, Vec<PathListItem>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ViewPath_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&ViewPath_::ViewPathSimple(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ViewPathSimple");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&ViewPath_::ViewPathGlob(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ViewPathGlob");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ViewPathList");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ViewPath_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&ViewPath_::ViewPathSimple(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&ViewPath_::ViewPathGlob(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ViewPath_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ViewPath_, __D::Error> {
__arg_0.read_enum("ViewPath_", |_d| -> _ {
_d.read_enum_variant(&["ViewPathSimple",
"ViewPathGlob",
"ViewPathList"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
ViewPath_::ViewPathSimple(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
ViewPath_::ViewPathGlob(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
ViewPath_::ViewPathList(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1823u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ViewPath_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&ViewPath_::ViewPathSimple(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("ViewPath_", |_e| -> _ {
_e.emit_enum_variant("ViewPathSimple",
0usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&ViewPath_::ViewPathGlob(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("ViewPath_", |_e| -> _ {
_e.emit_enum_variant("ViewPathGlob", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("ViewPath_", |_e| -> _ {
_e.emit_enum_variant("ViewPathList", 2usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ViewPath_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ViewPath_::ViewPathSimple(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&ViewPath_::ViewPathGlob(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ViewPath_ {
#[inline]
fn eq(&self, __arg_0: &ViewPath_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ViewPath_::ViewPathSimple(ref __self_0,
ref __self_1),
&ViewPath_::ViewPathSimple(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&ViewPath_::ViewPathGlob(ref __self_0),
&ViewPath_::ViewPathGlob(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),
&ViewPath_::ViewPathList(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ViewPath_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ViewPath_::ViewPathSimple(ref __self_0,
ref __self_1),
&ViewPath_::ViewPathSimple(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&ViewPath_::ViewPathGlob(ref __self_0),
&ViewPath_::ViewPathGlob(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),
&ViewPath_::ViewPathList(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ViewPath_ {
#[inline]
fn clone(&self) -> ViewPath_ {
match (&*self,) {
(&ViewPath_::ViewPathSimple(ref __self_0, ref __self_1),) =>
ViewPath_::ViewPathSimple(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&ViewPath_::ViewPathGlob(ref __self_0),) =>
ViewPath_::ViewPathGlob(::std::clone::Clone::clone(&(*__self_0))),
(&ViewPath_::ViewPathList(ref __self_0, ref __self_1),) =>
ViewPath_::ViewPathList(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
/// Meta-data associated with an item
pub type Attribute = Spanned<Attribute_>;
/// Distinguishes between Attributes that decorate items and Attributes that
/// are contained as statements within items. These two cases need to be
/// distinguished for pretty-printing.
pub enum AttrStyle { Outer, Inner, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AttrStyle { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AttrStyle {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&AttrStyle::Outer,) => {
let mut builder = __arg_0.debug_tuple("Outer");
builder.finish()
}
(&AttrStyle::Inner,) => {
let mut builder = __arg_0.debug_tuple("Inner");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for AttrStyle {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&AttrStyle::Outer,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&AttrStyle::Inner,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for AttrStyle {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<AttrStyle, __D::Error> {
__arg_0.read_enum("AttrStyle", |_d| -> _ {
_d.read_enum_variant(&["Outer", "Inner"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
AttrStyle::Outer,
1usize
=>
AttrStyle::Inner,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1846u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for AttrStyle {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&AttrStyle::Outer,) => {
let _e = __arg_0;
_e.emit_enum("AttrStyle", |_e| -> _ {
_e.emit_enum_variant("Outer", 0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&AttrStyle::Inner,) => {
let _e = __arg_0;
_e.emit_enum("AttrStyle", |_e| -> _ {
_e.emit_enum_variant("Inner", 1usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for AttrStyle {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&AttrStyle::Outer,) => { }
(&AttrStyle::Inner,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AttrStyle {
#[inline]
fn eq(&self, __arg_0: &AttrStyle) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AttrStyle::Outer, &AttrStyle::Outer) => true,
(&AttrStyle::Inner, &AttrStyle::Inner) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &AttrStyle) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AttrStyle::Outer, &AttrStyle::Outer) => false,
(&AttrStyle::Inner, &AttrStyle::Inner) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AttrStyle {
#[inline]
fn clone(&self) -> AttrStyle {
match (&*self,) {
(&AttrStyle::Outer,) => AttrStyle::Outer,
(&AttrStyle::Inner,) => AttrStyle::Inner,
}
}
}
pub struct AttrId(pub usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AttrId { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AttrId {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
AttrId(ref __self_0_0) => {
let mut builder = __arg_0.debug_tuple("AttrId");
let _ = builder.field(&&(*__self_0_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for AttrId {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
AttrId(ref __self_0_0) => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for AttrId {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<AttrId, __D::Error> {
__arg_0.read_struct("AttrId", 1usize, |_d| -> _ {
::std::result::Result::Ok(AttrId(match _d.read_struct_field("_field0",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
})) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for AttrId {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
AttrId(ref __self_0_0) =>
__arg_0.emit_struct("AttrId", 1usize, |_e| -> _ {
return _e.emit_struct_field("_field0",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for AttrId {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
AttrId(ref __self_0_0) => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AttrId {
#[inline]
fn eq(&self, __arg_0: &AttrId) -> bool {
match *__arg_0 {
AttrId(ref __self_1_0) =>
match *self {
AttrId(ref __self_0_0) =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &AttrId) -> bool {
match *__arg_0 {
AttrId(ref __self_1_0) =>
match *self {
AttrId(ref __self_0_0) =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AttrId {
#[inline]
fn clone(&self) -> AttrId {
match *self {
AttrId(ref __self_0_0) =>
AttrId(::std::clone::Clone::clone(&(*__self_0_0))),
}
}
}
/// Doc-comments are promoted to attributes that have is_sugared_doc = true
pub struct Attribute_ {
pub id: AttrId,
pub style: AttrStyle,
pub value: P<MetaItem>,
pub is_sugared_doc: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Attribute_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("Attribute_");
let _ = builder.field("id", &&(*__self_0_0));
let _ = builder.field("style", &&(*__self_0_1));
let _ = builder.field("value", &&(*__self_0_2));
let _ = builder.field("is_sugared_doc", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Attribute_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Attribute_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Attribute_, __D::Error> {
__arg_0.read_struct("Attribute_", 4usize, |_d| -> _ {
::std::result::Result::Ok(Attribute_{id:
match _d.read_struct_field("id",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
style:
match _d.read_struct_field("style",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
value:
match _d.read_struct_field("value",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
is_sugared_doc:
match _d.read_struct_field("is_sugared_doc",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Attribute_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } =>
__arg_0.emit_struct("Attribute_", 4usize, |_e| -> _ {
match _e.emit_struct_field("id", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("style",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("value",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("is_sugared_doc",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Attribute_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Attribute_ {
#[inline]
fn eq(&self, __arg_0: &Attribute_) -> bool {
match *__arg_0 {
Attribute_ {
id: ref __self_1_0,
style: ref __self_1_1,
value: ref __self_1_2,
is_sugared_doc: ref __self_1_3 } =>
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Attribute_) -> bool {
match *__arg_0 {
Attribute_ {
id: ref __self_1_0,
style: ref __self_1_1,
value: ref __self_1_2,
is_sugared_doc: ref __self_1_3 } =>
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Attribute_ {
#[inline]
fn clone(&self) -> Attribute_ {
match *self {
Attribute_ {
id: ref __self_0_0,
style: ref __self_0_1,
value: ref __self_0_2,
is_sugared_doc: ref __self_0_3 } =>
Attribute_{id: ::std::clone::Clone::clone(&(*__self_0_0)),
style: ::std::clone::Clone::clone(&(*__self_0_1)),
value: ::std::clone::Clone::clone(&(*__self_0_2)),
is_sugared_doc:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
/// TraitRef's appear in impls.
///
/// resolve maps each TraitRef's ref_id to its defining trait; that's all
/// that the ref_id is for. The impl_id maps to the "self type" of this impl.
/// If this impl is an ItemImpl, the impl_id is redundant (it could be the
/// same as the impl's node id).
pub struct TraitRef {
pub path: Path,
pub ref_id: NodeId,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TraitRef {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("TraitRef");
let _ = builder.field("path", &&(*__self_0_0));
let _ = builder.field("ref_id", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for TraitRef {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for TraitRef {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<TraitRef, __D::Error> {
__arg_0.read_struct("TraitRef", 2usize, |_d| -> _ {
::std::result::Result::Ok(TraitRef{path:
match _d.read_struct_field("path",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ref_id:
match _d.read_struct_field("ref_id",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for TraitRef {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 } =>
__arg_0.emit_struct("TraitRef", 2usize, |_e| -> _ {
match _e.emit_struct_field("path", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("ref_id",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TraitRef {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TraitRef {
#[inline]
fn eq(&self, __arg_0: &TraitRef) -> bool {
match *__arg_0 {
TraitRef { path: ref __self_1_0, ref_id: ref __self_1_1 } =>
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 }
=>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &TraitRef) -> bool {
match *__arg_0 {
TraitRef { path: ref __self_1_0, ref_id: ref __self_1_1 } =>
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 }
=>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TraitRef {
#[inline]
fn clone(&self) -> TraitRef {
match *self {
TraitRef { path: ref __self_0_0, ref_id: ref __self_0_1 } =>
TraitRef{path: ::std::clone::Clone::clone(&(*__self_0_0)),
ref_id: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct PolyTraitRef {
/// The `'a` in `<'a> Foo<&'a T>`
pub bound_lifetimes: Vec<LifetimeDef>,
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
pub trait_ref: TraitRef,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for PolyTraitRef {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("PolyTraitRef");
let _ = builder.field("bound_lifetimes", &&(*__self_0_0));
let _ = builder.field("trait_ref", &&(*__self_0_1));
let _ = builder.field("span", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for PolyTraitRef {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for PolyTraitRef {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<PolyTraitRef, __D::Error> {
__arg_0.read_struct("PolyTraitRef", 3usize, |_d| -> _ {
::std::result::Result::Ok(PolyTraitRef{bound_lifetimes:
match _d.read_struct_field("bound_lifetimes",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
trait_ref:
match _d.read_struct_field("trait_ref",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for PolyTraitRef {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } =>
__arg_0.emit_struct("PolyTraitRef", 3usize, |_e| -> _ {
match _e.emit_struct_field("bound_lifetimes",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("trait_ref",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for PolyTraitRef {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for PolyTraitRef {
#[inline]
fn eq(&self, __arg_0: &PolyTraitRef) -> bool {
match *__arg_0 {
PolyTraitRef {
bound_lifetimes: ref __self_1_0,
trait_ref: ref __self_1_1,
span: ref __self_1_2 } =>
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &PolyTraitRef) -> bool {
match *__arg_0 {
PolyTraitRef {
bound_lifetimes: ref __self_1_0,
trait_ref: ref __self_1_1,
span: ref __self_1_2 } =>
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PolyTraitRef {
#[inline]
fn clone(&self) -> PolyTraitRef {
match *self {
PolyTraitRef {
bound_lifetimes: ref __self_0_0,
trait_ref: ref __self_0_1,
span: ref __self_0_2 } =>
PolyTraitRef{bound_lifetimes:
::std::clone::Clone::clone(&(*__self_0_0)),
trait_ref:
::std::clone::Clone::clone(&(*__self_0_1)),
span:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub enum Visibility { Public, Inherited, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Visibility { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Visibility {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Visibility::Public,) => {
let mut builder = __arg_0.debug_tuple("Public");
builder.finish()
}
(&Visibility::Inherited,) => {
let mut builder = __arg_0.debug_tuple("Inherited");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Visibility {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Visibility::Public,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Visibility::Inherited,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Visibility {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Visibility, __D::Error> {
__arg_0.read_enum("Visibility", |_d| -> _ {
_d.read_enum_variant(&["Public", "Inherited"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Visibility::Public,
1usize
=>
Visibility::Inherited,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1887u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Visibility {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Visibility::Public,) => {
let _e = __arg_0;
_e.emit_enum("Visibility", |_e| -> _ {
_e.emit_enum_variant("Public", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Visibility::Inherited,) => {
let _e = __arg_0;
_e.emit_enum("Visibility", |_e| -> _ {
_e.emit_enum_variant("Inherited", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Visibility {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Visibility::Public,) => { }
(&Visibility::Inherited,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Visibility {
#[inline]
fn eq(&self, __arg_0: &Visibility) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Visibility::Public, &Visibility::Public) => true,
(&Visibility::Inherited, &Visibility::Inherited) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Visibility) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Visibility::Public, &Visibility::Public) => false,
(&Visibility::Inherited, &Visibility::Inherited) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Visibility {
#[inline]
fn clone(&self) -> Visibility {
match (&*self,) {
(&Visibility::Public,) => Visibility::Public,
(&Visibility::Inherited,) => Visibility::Inherited,
}
}
}
impl Visibility {
pub fn inherit_from(&self, parent_visibility: Visibility)
-> Visibility {
match *self { Inherited => parent_visibility, Public => *self, }
}
}
pub struct StructField_ {
pub kind: StructFieldKind,
pub id: NodeId,
pub ty: P<Ty>,
pub attrs: Vec<Attribute>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for StructField_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("StructField_");
let _ = builder.field("kind", &&(*__self_0_0));
let _ = builder.field("id", &&(*__self_0_1));
let _ = builder.field("ty", &&(*__self_0_2));
let _ = builder.field("attrs", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for StructField_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for StructField_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<StructField_, __D::Error> {
__arg_0.read_struct("StructField_", 4usize, |_d| -> _ {
::std::result::Result::Ok(StructField_{kind:
match _d.read_struct_field("kind",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
ty:
match _d.read_struct_field("ty",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for StructField_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } =>
__arg_0.emit_struct("StructField_", 4usize, |_e| -> _ {
match _e.emit_struct_field("kind", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("ty", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("attrs",
3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for StructField_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for StructField_ {
#[inline]
fn eq(&self, __arg_0: &StructField_) -> bool {
match *__arg_0 {
StructField_ {
kind: ref __self_1_0,
id: ref __self_1_1,
ty: ref __self_1_2,
attrs: ref __self_1_3 } =>
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &StructField_) -> bool {
match *__arg_0 {
StructField_ {
kind: ref __self_1_0,
id: ref __self_1_1,
ty: ref __self_1_2,
attrs: ref __self_1_3 } =>
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for StructField_ {
#[inline]
fn clone(&self) -> StructField_ {
match *self {
StructField_ {
kind: ref __self_0_0,
id: ref __self_0_1,
ty: ref __self_0_2,
attrs: ref __self_0_3 } =>
StructField_{kind: ::std::clone::Clone::clone(&(*__self_0_0)),
id: ::std::clone::Clone::clone(&(*__self_0_1)),
ty: ::std::clone::Clone::clone(&(*__self_0_2)),
attrs:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
impl StructField_ {
pub fn ident(&self) -> Option<Ident> {
match self.kind {
NamedField(ref ident, _) => Some(ident.clone()),
UnnamedField(_) => None,
}
}
}
pub type StructField = Spanned<StructField_>;
pub enum StructFieldKind {
NamedField(Ident, Visibility),
/// Element of a tuple-like struct
UnnamedField(Visibility),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for StructFieldKind { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for StructFieldKind {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&StructFieldKind::NamedField(ref __self_0, ref __self_1),) =>
{
let mut builder = __arg_0.debug_tuple("NamedField");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&StructFieldKind::UnnamedField(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("UnnamedField");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for StructFieldKind {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&StructFieldKind::NamedField(ref __self_0, ref __self_1),) =>
{
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&StructFieldKind::UnnamedField(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for StructFieldKind {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<StructFieldKind, __D::Error> {
__arg_0.read_enum("StructFieldKind", |_d| -> _ {
_d.read_enum_variant(&["NamedField",
"UnnamedField"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
StructFieldKind::NamedField(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
StructFieldKind::UnnamedField(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1921u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for StructFieldKind {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&StructFieldKind::NamedField(ref __self_0, ref __self_1),) =>
{
let _e = __arg_0;
_e.emit_enum("StructFieldKind", |_e| -> _ {
_e.emit_enum_variant("NamedField", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&StructFieldKind::UnnamedField(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("StructFieldKind", |_e| -> _ {
_e.emit_enum_variant("UnnamedField", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for StructFieldKind {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&StructFieldKind::NamedField(ref __self_0, ref __self_1),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&StructFieldKind::UnnamedField(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for StructFieldKind {
#[inline]
fn eq(&self, __arg_0: &StructFieldKind) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StructFieldKind::NamedField(ref __self_0,
ref __self_1),
&StructFieldKind::NamedField(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&StructFieldKind::UnnamedField(ref __self_0),
&StructFieldKind::UnnamedField(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &StructFieldKind) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StructFieldKind::NamedField(ref __self_0,
ref __self_1),
&StructFieldKind::NamedField(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&StructFieldKind::UnnamedField(ref __self_0),
&StructFieldKind::UnnamedField(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for StructFieldKind {
#[inline]
fn clone(&self) -> StructFieldKind {
match (&*self,) {
(&StructFieldKind::NamedField(ref __self_0, ref __self_1),) =>
StructFieldKind::NamedField(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&StructFieldKind::UnnamedField(ref __self_0),) =>
StructFieldKind::UnnamedField(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl StructFieldKind {
pub fn is_unnamed(&self) -> bool {
match *self { UnnamedField(..) => true, NamedField(..) => false, }
}
pub fn visibility(&self) -> Visibility {
match *self { NamedField(_, vis) | UnnamedField(vis) => vis, }
}
}
/// Fields and Ids of enum variants and structs
///
/// For enum variants: `NodeId` represents both an Id of the variant itself (relevant for all
/// variant kinds) and an Id of the variant's constructor (not relevant for `Struct`-variants).
/// One shared Id can be successfully used for these two purposes.
/// Id of the whole enum lives in `Item`.
///
/// For structs: `NodeId` represents an Id of the structure's constructor, so it is not actually
/// used for `Struct`-structs (but still presents). Structures don't have an analogue of "Id of
/// the variant itself" from enum variants.
/// Id of the whole struct lives in `Item`.
pub enum VariantData {
Struct(Vec<StructField>, NodeId),
Tuple(Vec<StructField>, NodeId),
Unit(NodeId),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for VariantData {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&VariantData::Struct(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Struct");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&VariantData::Tuple(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Tuple");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&VariantData::Unit(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Unit");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for VariantData {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&VariantData::Struct(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&VariantData::Tuple(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&VariantData::Unit(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for VariantData {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<VariantData, __D::Error> {
__arg_0.read_enum("VariantData", |_d| -> _ {
_d.read_enum_variant(&["Struct", "Tuple",
"Unit"], |_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
VariantData::Struct(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
VariantData::Tuple(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
VariantData::Unit(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
1954u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for VariantData {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&VariantData::Struct(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("VariantData", |_e| -> _ {
_e.emit_enum_variant("Struct", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&VariantData::Tuple(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("VariantData", |_e| -> _ {
_e.emit_enum_variant("Tuple", 1usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&VariantData::Unit(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("VariantData", |_e| -> _ {
_e.emit_enum_variant("Unit", 2usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for VariantData {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&VariantData::Struct(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&VariantData::Tuple(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&VariantData::Unit(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for VariantData {
#[inline]
fn eq(&self, __arg_0: &VariantData) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&VariantData::Struct(ref __self_0, ref __self_1),
&VariantData::Struct(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&VariantData::Tuple(ref __self_0, ref __self_1),
&VariantData::Tuple(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&VariantData::Unit(ref __self_0),
&VariantData::Unit(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &VariantData) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&VariantData::Struct(ref __self_0, ref __self_1),
&VariantData::Struct(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&VariantData::Tuple(ref __self_0, ref __self_1),
&VariantData::Tuple(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&VariantData::Unit(ref __self_0),
&VariantData::Unit(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for VariantData {
#[inline]
fn clone(&self) -> VariantData {
match (&*self,) {
(&VariantData::Struct(ref __self_0, ref __self_1),) =>
VariantData::Struct(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&VariantData::Tuple(ref __self_0, ref __self_1),) =>
VariantData::Tuple(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&VariantData::Unit(ref __self_0),) =>
VariantData::Unit(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl VariantData {
pub fn fields(&self) -> &[StructField] {
match *self {
VariantData::Struct(ref fields, _) |
VariantData::Tuple(ref fields, _) => fields,
_ => &[],
}
}
pub fn id(&self) -> NodeId {
match *self {
VariantData::Struct(_, id) | VariantData::Tuple(_, id) |
VariantData::Unit(id) => id,
}
}
pub fn is_struct(&self) -> bool {
if let VariantData::Struct(..) = *self { true } else { false }
}
pub fn is_tuple(&self) -> bool {
if let VariantData::Tuple(..) = *self { true } else { false }
}
pub fn is_unit(&self) -> bool {
if let VariantData::Unit(..) = *self { true } else { false }
}
}
/// An item
///
/// The name might be a dummy name in case of anonymous items
pub struct Item {
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub id: NodeId,
pub node: Item_,
pub vis: Visibility,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Item {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } => {
let mut builder = __arg_0.debug_struct("Item");
let _ = builder.field("ident", &&(*__self_0_0));
let _ = builder.field("attrs", &&(*__self_0_1));
let _ = builder.field("id", &&(*__self_0_2));
let _ = builder.field("node", &&(*__self_0_3));
let _ = builder.field("vis", &&(*__self_0_4));
let _ = builder.field("span", &&(*__self_0_5));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Item {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Item {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Item, __D::Error> {
__arg_0.read_struct("Item", 6usize, |_d| -> _ {
::std::result::Result::Ok(Item{ident:
match _d.read_struct_field("ident",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
vis:
match _d.read_struct_field("vis",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Item {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } =>
__arg_0.emit_struct("Item", 6usize, |_e| -> _ {
match _e.emit_struct_field("ident",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("vis", 4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Item {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Item {
#[inline]
fn eq(&self, __arg_0: &Item) -> bool {
match *__arg_0 {
Item {
ident: ref __self_1_0,
attrs: ref __self_1_1,
id: ref __self_1_2,
node: ref __self_1_3,
vis: ref __self_1_4,
span: ref __self_1_5 } =>
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Item) -> bool {
match *__arg_0 {
Item {
ident: ref __self_1_0,
attrs: ref __self_1_1,
id: ref __self_1_2,
node: ref __self_1_3,
vis: ref __self_1_4,
span: ref __self_1_5 } =>
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Item {
#[inline]
fn clone(&self) -> Item {
match *self {
Item {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
node: ref __self_0_3,
vis: ref __self_0_4,
span: ref __self_0_5 } =>
Item{ident: ::std::clone::Clone::clone(&(*__self_0_0)),
attrs: ::std::clone::Clone::clone(&(*__self_0_1)),
id: ::std::clone::Clone::clone(&(*__self_0_2)),
node: ::std::clone::Clone::clone(&(*__self_0_3)),
vis: ::std::clone::Clone::clone(&(*__self_0_4)),
span: ::std::clone::Clone::clone(&(*__self_0_5)),},
}
}
}
impl Item {
pub fn attrs(&self) -> &[Attribute] { &self.attrs }
}
pub enum Item_ {
/// An`extern crate` item, with optional original crate name,
///
/// e.g. `extern crate foo` or `extern crate foo_bar as foo`
ItemExternCrate(Option<Name>),
/// A `use` or `pub use` item
ItemUse(P<ViewPath>),
/// A `static` item
ItemStatic(P<Ty>, Mutability, P<Expr>),
/// A `const` item
ItemConst(P<Ty>, P<Expr>),
/// A function declaration
ItemFn(P<FnDecl>, Unsafety, Constness, Abi, Generics, P<Block>),
/// A module
ItemMod(Mod),
/// An external module
ItemForeignMod(ForeignMod),
/// A type alias, e.g. `type Foo = Bar<u8>`
ItemTy(P<Ty>, Generics),
/// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
ItemEnum(EnumDef, Generics),
/// A struct definition, e.g. `struct Foo<A> {x: A}`
ItemStruct(VariantData, Generics),
/// Represents a Trait Declaration
ItemTrait(Unsafety, Generics, TyParamBounds, Vec<P<TraitItem>>),
///
ItemDefaultImpl(Unsafety, TraitRef),
/// An implementation, eg `impl<A> Trait for Foo { .. }`
ItemImpl(Unsafety, ImplPolarity, Generics, Option<TraitRef>, P<Ty>,
Vec<P<ImplItem>>),
/// A macro invocation (which includes macro definition)
ItemMac(Mac),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Item_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Item_::ItemExternCrate(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ItemExternCrate");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Item_::ItemUse(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ItemUse");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("ItemStatic");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&Item_::ItemConst(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ItemConst");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Item_::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),) =>
{
let mut builder = __arg_0.debug_tuple("ItemFn");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
let _ = builder.field(&&(*__self_4));
let _ = builder.field(&&(*__self_5));
builder.finish()
}
(&Item_::ItemMod(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ItemMod");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Item_::ItemForeignMod(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ItemForeignMod");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Item_::ItemTy(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ItemTy");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Item_::ItemEnum(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ItemEnum");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Item_::ItemStruct(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ItemStruct");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Item_::ItemTrait(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let mut builder = __arg_0.debug_tuple("ItemTrait");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
builder.finish()
}
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ItemDefaultImpl");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Item_::ItemImpl(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=> {
let mut builder = __arg_0.debug_tuple("ItemImpl");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
let _ = builder.field(&&(*__self_4));
let _ = builder.field(&&(*__self_5));
builder.finish()
}
(&Item_::ItemMac(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ItemMac");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Item_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&Item_::ItemExternCrate(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Item_::ItemUse(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&Item_::ItemConst(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Item_::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),) =>
{
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
::std::hash::Hash::hash(&(*__self_4), __arg_0);
::std::hash::Hash::hash(&(*__self_5), __arg_0);
}
(&Item_::ItemMod(ref __self_0),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Item_::ItemForeignMod(ref __self_0),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Item_::ItemTy(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Item_::ItemEnum(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&8usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Item_::ItemStruct(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&9usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Item_::ItemTrait(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
::std::hash::Hash::hash(&10usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
}
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&11usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Item_::ItemImpl(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=> {
::std::hash::Hash::hash(&12usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
::std::hash::Hash::hash(&(*__self_4), __arg_0);
::std::hash::Hash::hash(&(*__self_5), __arg_0);
}
(&Item_::ItemMac(ref __self_0),) => {
::std::hash::Hash::hash(&13usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Item_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Item_, __D::Error> {
__arg_0.read_enum("Item_", |_d| -> _ {
_d.read_enum_variant(&["ItemExternCrate",
"ItemUse", "ItemStatic",
"ItemConst", "ItemFn",
"ItemMod",
"ItemForeignMod",
"ItemTy", "ItemEnum",
"ItemStruct",
"ItemTrait",
"ItemDefaultImpl",
"ItemImpl", "ItemMac"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Item_::ItemExternCrate(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Item_::ItemUse(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Item_::ItemStatic(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Item_::ItemConst(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Item_::ItemFn(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Item_::ItemMod(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Item_::ItemForeignMod(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Item_::ItemTy(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
8usize
=>
Item_::ItemEnum(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
9usize
=>
Item_::ItemStruct(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
10usize
=>
Item_::ItemTrait(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
11usize
=>
Item_::ItemDefaultImpl(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
12usize
=>
Item_::ItemImpl(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
13usize
=>
Item_::ItemMac(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
2007u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Item_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Item_::ItemExternCrate(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemExternCrate",
0usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Item_::ItemUse(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemUse", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemStatic", 2usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&Item_::ItemConst(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemConst", 3usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Item_::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),) =>
{
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemFn", 4usize,
6usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(4usize,
|_e|
->
_
{
(*__self_4).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(5usize,
|_e|
->
_
{
(*__self_5).encode(_e)
});
}) })
}
(&Item_::ItemMod(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemMod", 5usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Item_::ItemForeignMod(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemForeignMod",
6usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Item_::ItemTy(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemTy", 7usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Item_::ItemEnum(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemEnum", 8usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Item_::ItemStruct(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemStruct", 9usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Item_::ItemTrait(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemTrait", 10usize,
4usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
});
}) })
}
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemDefaultImpl",
11usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Item_::ItemImpl(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=> {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemImpl", 12usize,
6usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(4usize,
|_e|
->
_
{
(*__self_4).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(5usize,
|_e|
->
_
{
(*__self_5).encode(_e)
});
}) })
}
(&Item_::ItemMac(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Item_", |_e| -> _ {
_e.emit_enum_variant("ItemMac", 13usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Item_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Item_::ItemExternCrate(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Item_::ItemUse(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&Item_::ItemConst(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Item_::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
(*__self_4).assert_receiver_is_total_eq();
(*__self_5).assert_receiver_is_total_eq();
}
(&Item_::ItemMod(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Item_::ItemForeignMod(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Item_::ItemTy(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Item_::ItemEnum(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Item_::ItemStruct(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Item_::ItemTrait(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
}
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Item_::ItemImpl(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
(*__self_4).assert_receiver_is_total_eq();
(*__self_5).assert_receiver_is_total_eq();
}
(&Item_::ItemMac(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Item_ {
#[inline]
fn eq(&self, __arg_0: &Item_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Item_::ItemExternCrate(ref __self_0),
&Item_::ItemExternCrate(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Item_::ItemUse(ref __self_0),
&Item_::ItemUse(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),
&Item_::ItemStatic(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&Item_::ItemConst(ref __self_0, ref __self_1),
&Item_::ItemConst(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Item_::ItemFn(ref __self_0, ref __self_1,
ref __self_2, ref __self_3,
ref __self_4, ref __self_5),
&Item_::ItemFn(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3,
ref __arg_1_4, ref __arg_1_5)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3) &&
(*__self_4) == (*__arg_1_4) &&
(*__self_5) == (*__arg_1_5),
(&Item_::ItemMod(ref __self_0),
&Item_::ItemMod(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Item_::ItemForeignMod(ref __self_0),
&Item_::ItemForeignMod(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Item_::ItemTy(ref __self_0, ref __self_1),
&Item_::ItemTy(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Item_::ItemEnum(ref __self_0, ref __self_1),
&Item_::ItemEnum(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Item_::ItemStruct(ref __self_0, ref __self_1),
&Item_::ItemStruct(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Item_::ItemTrait(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Item_::ItemTrait(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3),
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),
&Item_::ItemDefaultImpl(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Item_::ItemImpl(ref __self_0, ref __self_1,
ref __self_2, ref __self_3,
ref __self_4, ref __self_5),
&Item_::ItemImpl(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3,
ref __arg_1_4, ref __arg_1_5)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3) &&
(*__self_4) == (*__arg_1_4) &&
(*__self_5) == (*__arg_1_5),
(&Item_::ItemMac(ref __self_0),
&Item_::ItemMac(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Item_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Item_::ItemExternCrate(ref __self_0),
&Item_::ItemExternCrate(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Item_::ItemUse(ref __self_0),
&Item_::ItemUse(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),
&Item_::ItemStatic(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&Item_::ItemConst(ref __self_0, ref __self_1),
&Item_::ItemConst(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Item_::ItemFn(ref __self_0, ref __self_1,
ref __self_2, ref __self_3,
ref __self_4, ref __self_5),
&Item_::ItemFn(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3,
ref __arg_1_4, ref __arg_1_5)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3) ||
(*__self_4) != (*__arg_1_4) ||
(*__self_5) != (*__arg_1_5),
(&Item_::ItemMod(ref __self_0),
&Item_::ItemMod(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Item_::ItemForeignMod(ref __self_0),
&Item_::ItemForeignMod(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Item_::ItemTy(ref __self_0, ref __self_1),
&Item_::ItemTy(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Item_::ItemEnum(ref __self_0, ref __self_1),
&Item_::ItemEnum(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Item_::ItemStruct(ref __self_0, ref __self_1),
&Item_::ItemStruct(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Item_::ItemTrait(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Item_::ItemTrait(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3),
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),
&Item_::ItemDefaultImpl(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Item_::ItemImpl(ref __self_0, ref __self_1,
ref __self_2, ref __self_3,
ref __self_4, ref __self_5),
&Item_::ItemImpl(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3,
ref __arg_1_4, ref __arg_1_5)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3) ||
(*__self_4) != (*__arg_1_4) ||
(*__self_5) != (*__arg_1_5),
(&Item_::ItemMac(ref __self_0),
&Item_::ItemMac(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Item_ {
#[inline]
fn clone(&self) -> Item_ {
match (&*self,) {
(&Item_::ItemExternCrate(ref __self_0),) =>
Item_::ItemExternCrate(::std::clone::Clone::clone(&(*__self_0))),
(&Item_::ItemUse(ref __self_0),) =>
Item_::ItemUse(::std::clone::Clone::clone(&(*__self_0))),
(&Item_::ItemStatic(ref __self_0, ref __self_1,
ref __self_2),) =>
Item_::ItemStatic(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&Item_::ItemConst(ref __self_0, ref __self_1),) =>
Item_::ItemConst(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Item_::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),) =>
Item_::ItemFn(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3)),
::std::clone::Clone::clone(&(*__self_4)),
::std::clone::Clone::clone(&(*__self_5))),
(&Item_::ItemMod(ref __self_0),) =>
Item_::ItemMod(::std::clone::Clone::clone(&(*__self_0))),
(&Item_::ItemForeignMod(ref __self_0),) =>
Item_::ItemForeignMod(::std::clone::Clone::clone(&(*__self_0))),
(&Item_::ItemTy(ref __self_0, ref __self_1),) =>
Item_::ItemTy(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Item_::ItemEnum(ref __self_0, ref __self_1),) =>
Item_::ItemEnum(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Item_::ItemStruct(ref __self_0, ref __self_1),) =>
Item_::ItemStruct(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Item_::ItemTrait(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) =>
Item_::ItemTrait(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3))),
(&Item_::ItemDefaultImpl(ref __self_0, ref __self_1),) =>
Item_::ItemDefaultImpl(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Item_::ItemImpl(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=>
Item_::ItemImpl(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3)),
::std::clone::Clone::clone(&(*__self_4)),
::std::clone::Clone::clone(&(*__self_5))),
(&Item_::ItemMac(ref __self_0),) =>
Item_::ItemMac(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl Item_ {
pub fn descriptive_variant(&self) -> &str {
match *self {
ItemExternCrate(..) => "extern crate",
ItemUse(..) => "use",
ItemStatic(..) => "static item",
ItemConst(..) => "constant item",
ItemFn(..) => "function",
ItemMod(..) => "module",
ItemForeignMod(..) => "foreign module",
ItemTy(..) => "type alias",
ItemEnum(..) => "enum",
ItemStruct(..) => "struct",
ItemTrait(..) => "trait",
ItemMac(..) | ItemImpl(..) | ItemDefaultImpl(..) => "item",
}
}
}
pub struct ForeignItem {
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub node: ForeignItem_,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ForeignItem {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } => {
let mut builder = __arg_0.debug_struct("ForeignItem");
let _ = builder.field("ident", &&(*__self_0_0));
let _ = builder.field("attrs", &&(*__self_0_1));
let _ = builder.field("node", &&(*__self_0_2));
let _ = builder.field("id", &&(*__self_0_3));
let _ = builder.field("span", &&(*__self_0_4));
let _ = builder.field("vis", &&(*__self_0_5));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ForeignItem {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ForeignItem {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ForeignItem, __D::Error> {
__arg_0.read_struct("ForeignItem", 6usize, |_d| -> _ {
::std::result::Result::Ok(ForeignItem{ident:
match _d.read_struct_field("ident",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
node:
match _d.read_struct_field("node",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
vis:
match _d.read_struct_field("vis",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ForeignItem {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } =>
__arg_0.emit_struct("ForeignItem", 6usize, |_e| -> _ {
match _e.emit_struct_field("ident",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("node", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("vis", 5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ForeignItem {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ForeignItem {
#[inline]
fn eq(&self, __arg_0: &ForeignItem) -> bool {
match *__arg_0 {
ForeignItem {
ident: ref __self_1_0,
attrs: ref __self_1_1,
node: ref __self_1_2,
id: ref __self_1_3,
span: ref __self_1_4,
vis: ref __self_1_5 } =>
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ForeignItem) -> bool {
match *__arg_0 {
ForeignItem {
ident: ref __self_1_0,
attrs: ref __self_1_1,
node: ref __self_1_2,
id: ref __self_1_3,
span: ref __self_1_4,
vis: ref __self_1_5 } =>
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ForeignItem {
#[inline]
fn clone(&self) -> ForeignItem {
match *self {
ForeignItem {
ident: ref __self_0_0,
attrs: ref __self_0_1,
node: ref __self_0_2,
id: ref __self_0_3,
span: ref __self_0_4,
vis: ref __self_0_5 } =>
ForeignItem{ident: ::std::clone::Clone::clone(&(*__self_0_0)),
attrs: ::std::clone::Clone::clone(&(*__self_0_1)),
node: ::std::clone::Clone::clone(&(*__self_0_2)),
id: ::std::clone::Clone::clone(&(*__self_0_3)),
span: ::std::clone::Clone::clone(&(*__self_0_4)),
vis: ::std::clone::Clone::clone(&(*__self_0_5)),},
}
}
}
/// An item within an `extern` block
pub enum ForeignItem_ {
/// A foreign function
ForeignItemFn(P<FnDecl>, Generics),
/// A foreign static item (`static ext: u8`), with optional mutability
/// (the boolean is true when mutable)
ForeignItemStatic(P<Ty>, bool),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ForeignItem_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&ForeignItem_::ForeignItemFn(ref __self_0, ref __self_1),) =>
{
let mut builder = __arg_0.debug_tuple("ForeignItemFn");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),) => {
let mut builder =
__arg_0.debug_tuple("ForeignItemStatic");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ForeignItem_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&ForeignItem_::ForeignItemFn(ref __self_0, ref __self_1),) =>
{
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ForeignItem_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ForeignItem_, __D::Error> {
__arg_0.read_enum("ForeignItem_", |_d| -> _ {
_d.read_enum_variant(&["ForeignItemFn",
"ForeignItemStatic"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
ForeignItem_::ForeignItemFn(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
ForeignItem_::ForeignItemStatic(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ast.rs",
2085u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ForeignItem_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&ForeignItem_::ForeignItemFn(ref __self_0, ref __self_1),) =>
{
let _e = __arg_0;
_e.emit_enum("ForeignItem_", |_e| -> _ {
_e.emit_enum_variant("ForeignItemFn", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("ForeignItem_", |_e| -> _ {
_e.emit_enum_variant("ForeignItemStatic",
1usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ForeignItem_ {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ForeignItem_::ForeignItemFn(ref __self_0, ref __self_1),) =>
{
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ForeignItem_ {
#[inline]
fn eq(&self, __arg_0: &ForeignItem_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ForeignItem_::ForeignItemFn(ref __self_0,
ref __self_1),
&ForeignItem_::ForeignItemFn(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),
&ForeignItem_::ForeignItemStatic(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ForeignItem_) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ForeignItem_::ForeignItemFn(ref __self_0,
ref __self_1),
&ForeignItem_::ForeignItemFn(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),
&ForeignItem_::ForeignItemStatic(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ForeignItem_ {
#[inline]
fn clone(&self) -> ForeignItem_ {
match (&*self,) {
(&ForeignItem_::ForeignItemFn(ref __self_0, ref __self_1),) =>
ForeignItem_::ForeignItemFn(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&ForeignItem_::ForeignItemStatic(ref __self_0,
ref __self_1),) =>
ForeignItem_::ForeignItemStatic(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
impl ForeignItem_ {
pub fn descriptive_variant(&self) -> &str {
match *self {
ForeignItemFn(..) => "foreign function",
ForeignItemStatic(..) => "foreign static item",
}
}
}
/// A macro definition, in this crate or imported from another.
///
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
pub struct MacroDef {
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub id: NodeId,
pub span: Span,
pub imported_from: Option<Ident>,
pub export: bool,
pub use_locally: bool,
pub allow_internal_unstable: bool,
pub body: Vec<TokenTree>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for MacroDef {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } => {
let mut builder = __arg_0.debug_struct("MacroDef");
let _ = builder.field("ident", &&(*__self_0_0));
let _ = builder.field("attrs", &&(*__self_0_1));
let _ = builder.field("id", &&(*__self_0_2));
let _ = builder.field("span", &&(*__self_0_3));
let _ = builder.field("imported_from", &&(*__self_0_4));
let _ = builder.field("export", &&(*__self_0_5));
let _ = builder.field("use_locally", &&(*__self_0_6));
let _ =
builder.field("allow_internal_unstable",
&&(*__self_0_7));
let _ = builder.field("body", &&(*__self_0_8));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for MacroDef {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
::std::hash::Hash::hash(&(*__self_0_3), __arg_0);
::std::hash::Hash::hash(&(*__self_0_4), __arg_0);
::std::hash::Hash::hash(&(*__self_0_5), __arg_0);
::std::hash::Hash::hash(&(*__self_0_6), __arg_0);
::std::hash::Hash::hash(&(*__self_0_7), __arg_0);
::std::hash::Hash::hash(&(*__self_0_8), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for MacroDef {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<MacroDef, __D::Error> {
__arg_0.read_struct("MacroDef", 9usize, |_d| -> _ {
::std::result::Result::Ok(MacroDef{ident:
match _d.read_struct_field("ident",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
attrs:
match _d.read_struct_field("attrs",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
id:
match _d.read_struct_field("id",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
imported_from:
match _d.read_struct_field("imported_from",
4usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
export:
match _d.read_struct_field("export",
5usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
use_locally:
match _d.read_struct_field("use_locally",
6usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
allow_internal_unstable:
match _d.read_struct_field("allow_internal_unstable",
7usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
body:
match _d.read_struct_field("body",
8usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for MacroDef {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } =>
__arg_0.emit_struct("MacroDef", 9usize, |_e| -> _ {
match _e.emit_struct_field("ident",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("attrs",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("id", 2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("span", 3usize,
|_e| -> _ {
(*__self_0_3).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("imported_from",
4usize,
|_e| -> _ {
(*__self_0_4).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("export",
5usize,
|_e| -> _ {
(*__self_0_5).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("use_locally",
6usize,
|_e| -> _ {
(*__self_0_6).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("allow_internal_unstable",
7usize,
|_e| -> _ {
(*__self_0_7).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("body",
8usize,
|_e| -> _ {
(*__self_0_8).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MacroDef {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
(*__self_0_4).assert_receiver_is_total_eq();
(*__self_0_5).assert_receiver_is_total_eq();
(*__self_0_6).assert_receiver_is_total_eq();
(*__self_0_7).assert_receiver_is_total_eq();
(*__self_0_8).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for MacroDef {
#[inline]
fn eq(&self, __arg_0: &MacroDef) -> bool {
match *__arg_0 {
MacroDef {
ident: ref __self_1_0,
attrs: ref __self_1_1,
id: ref __self_1_2,
span: ref __self_1_3,
imported_from: ref __self_1_4,
export: ref __self_1_5,
use_locally: ref __self_1_6,
allow_internal_unstable: ref __self_1_7,
body: ref __self_1_8 } =>
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3) &&
(*__self_0_4) == (*__self_1_4) &&
(*__self_0_5) == (*__self_1_5) &&
(*__self_0_6) == (*__self_1_6) &&
(*__self_0_7) == (*__self_1_7) &&
(*__self_0_8) == (*__self_1_8),
},
}
}
#[inline]
fn ne(&self, __arg_0: &MacroDef) -> bool {
match *__arg_0 {
MacroDef {
ident: ref __self_1_0,
attrs: ref __self_1_1,
id: ref __self_1_2,
span: ref __self_1_3,
imported_from: ref __self_1_4,
export: ref __self_1_5,
use_locally: ref __self_1_6,
allow_internal_unstable: ref __self_1_7,
body: ref __self_1_8 } =>
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3) ||
(*__self_0_4) != (*__self_1_4) ||
(*__self_0_5) != (*__self_1_5) ||
(*__self_0_6) != (*__self_1_6) ||
(*__self_0_7) != (*__self_1_7) ||
(*__self_0_8) != (*__self_1_8),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MacroDef {
#[inline]
fn clone(&self) -> MacroDef {
match *self {
MacroDef {
ident: ref __self_0_0,
attrs: ref __self_0_1,
id: ref __self_0_2,
span: ref __self_0_3,
imported_from: ref __self_0_4,
export: ref __self_0_5,
use_locally: ref __self_0_6,
allow_internal_unstable: ref __self_0_7,
body: ref __self_0_8 } =>
MacroDef{ident: ::std::clone::Clone::clone(&(*__self_0_0)),
attrs: ::std::clone::Clone::clone(&(*__self_0_1)),
id: ::std::clone::Clone::clone(&(*__self_0_2)),
span: ::std::clone::Clone::clone(&(*__self_0_3)),
imported_from:
::std::clone::Clone::clone(&(*__self_0_4)),
export: ::std::clone::Clone::clone(&(*__self_0_5)),
use_locally:
::std::clone::Clone::clone(&(*__self_0_6)),
allow_internal_unstable:
::std::clone::Clone::clone(&(*__self_0_7)),
body: ::std::clone::Clone::clone(&(*__self_0_8)),},
}
}
}
}
pub mod ast_util {
#[prelude_import]
use std::prelude::v1::*;
use ast::*;
use ast;
use codemap;
use codemap::Span;
use parse::token;
use print::pprust;
use ptr::P;
use visit::{FnKind, Visitor};
use visit;
use std::cmp;
use std::u32;
pub fn path_name_i(idents: &[Ident]) -> String {
idents.iter().map(|i|
i.to_string()).collect::<Vec<String>>().join("::")
}
pub fn is_path(e: P<Expr>) -> bool {
match e.node { ExprPath(..) => true, _ => false, }
}
pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
ast::Path{span: s,
global: false,
segments:
<[_]>::into_vec(::std::boxed::Box::new([ast::PathSegment{identifier:
identifier,
parameters:
ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData{lifetimes:
Vec::new(),
types:
P::empty(),
bindings:
P::empty(),}),}])),}
}
pub fn path_to_ident(path: &Path) -> Option<Ident> {
if path.segments.len() != 1 { return None; }
let segment = &path.segments[0];
if !segment.parameters.is_empty() { return None; }
Some(segment.identifier)
}
pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P<Pat> {
P(Pat{id: id,
node:
PatIdent(BindingMode::ByValue(MutImmutable),
codemap::Spanned{span: s, node: i,}, None),
span: s,})
}
/// Generate a "pretty" name for an `impl` from its type and trait.
/// This is designed so that symbols of `impl`'d methods give some
/// hint of where they came from, (previously they would all just be
/// listed as `__extensions__::method_name::hash`, with no indication
/// of the type).
pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: Option<&Ty>)
-> Ident {
let mut pretty =
match ty {
Some(t) => pprust::ty_to_string(t),
None => String::from(".."),
};
match *trait_ref {
Some(ref trait_ref) => {
pretty.push('.');
pretty.push_str(&pprust::path_to_string(&trait_ref.path));
}
None => { }
}
token::gensym_ident(&pretty[..])
}
pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
match field.node.kind {
ast::NamedField(_, v) | ast::UnnamedField(v) => v,
}
}
pub struct IdRange {
pub min: NodeId,
pub max: NodeId,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for IdRange {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
IdRange { min: ref __self_0_0, max: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("IdRange");
let _ = builder.field("min", &&(*__self_0_0));
let _ = builder.field("max", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for IdRange {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<IdRange, __D::Error> {
__arg_0.read_struct("IdRange", 2usize, |_d| -> _ {
::std::result::Result::Ok(IdRange{min:
match _d.read_struct_field("min",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
max:
match _d.read_struct_field("max",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for IdRange {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
IdRange { min: ref __self_0_0, max: ref __self_0_1 } =>
__arg_0.emit_struct("IdRange", 2usize, |_e| -> _ {
match _e.emit_struct_field("min", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("max", 1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for IdRange {
#[inline]
fn clone(&self) -> IdRange {
match *self {
IdRange { min: ref __self_0_0, max: ref __self_0_1 } =>
IdRange{min: ::std::clone::Clone::clone(&(*__self_0_0)),
max: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for IdRange { }
impl IdRange {
pub fn max() -> IdRange { IdRange{min: u32::MAX, max: u32::MIN,} }
pub fn empty(&self) -> bool { self.min >= self.max }
pub fn add(&mut self, id: NodeId) {
self.min = cmp::min(self.min, id);
self.max = cmp::max(self.max, id + 1);
}
}
pub trait IdVisitingOperation {
fn visit_id(&mut self, node_id: NodeId);
}
/// A visitor that applies its operation to all of the node IDs
/// in a visitable thing.
pub struct IdVisitor<'a, O: 'a> {
pub operation: &'a mut O,
pub visited_outermost: bool,
}
impl <'a, O: IdVisitingOperation> IdVisitor<'a, O> {
fn visit_generics_helper(&mut self, generics: &Generics) {
for type_parameter in generics.ty_params.iter() {
self.operation.visit_id(type_parameter.id)
}
for lifetime in &generics.lifetimes {
self.operation.visit_id(lifetime.lifetime.id)
}
}
}
impl <'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
fn visit_mod(&mut self, module: &Mod, _: Span, node_id: NodeId) {
self.operation.visit_id(node_id);
visit::walk_mod(self, module)
}
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
self.operation.visit_id(foreign_item.id);
visit::walk_foreign_item(self, foreign_item)
}
fn visit_item(&mut self, item: &Item) {
if self.visited_outermost {
return
} else { self.visited_outermost = true }
self.operation.visit_id(item.id);
match item.node {
ItemUse(ref view_path) => {
match view_path.node {
ViewPathSimple(_, _) | ViewPathGlob(_) => { }
ViewPathList(_, ref paths) => {
for path in paths {
self.operation.visit_id(path.node.id())
}
}
}
}
_ => { }
}
visit::walk_item(self, item);
self.visited_outermost = false
}
fn visit_local(&mut self, local: &Local) {
self.operation.visit_id(local.id);
visit::walk_local(self, local)
}
fn visit_block(&mut self, block: &Block) {
self.operation.visit_id(block.id);
visit::walk_block(self, block)
}
fn visit_stmt(&mut self, statement: &Stmt) {
self.operation.visit_id(statement.node.id().expect("attempted to visit unexpanded stmt"));
visit::walk_stmt(self, statement)
}
fn visit_pat(&mut self, pattern: &Pat) {
self.operation.visit_id(pattern.id);
visit::walk_pat(self, pattern)
}
fn visit_expr(&mut self, expression: &Expr) {
self.operation.visit_id(expression.id);
visit::walk_expr(self, expression)
}
fn visit_ty(&mut self, typ: &Ty) {
self.operation.visit_id(typ.id);
visit::walk_ty(self, typ)
}
fn visit_generics(&mut self, generics: &Generics) {
self.visit_generics_helper(generics);
visit::walk_generics(self, generics)
}
fn visit_fn(&mut self, function_kind: visit::FnKind<'v>,
function_declaration: &'v FnDecl, block: &'v Block,
span: Span, node_id: NodeId) {
match function_kind {
FnKind::Method(..) if self.visited_outermost => return,
FnKind::Method(..) => self.visited_outermost = true,
_ => { }
}
self.operation.visit_id(node_id);
match function_kind {
FnKind::ItemFn(_, generics, _, _, _, _) => {
self.visit_generics_helper(generics)
}
FnKind::Method(_, sig, _) => {
self.visit_generics_helper(&sig.generics)
}
FnKind::Closure => { }
}
for argument in &function_declaration.inputs {
self.operation.visit_id(argument.id)
}
visit::walk_fn(self, function_kind, function_declaration, block,
span);
if let FnKind::Method(..) = function_kind {
self.visited_outermost = false;
}
}
fn visit_struct_field(&mut self, struct_field: &StructField) {
self.operation.visit_id(struct_field.node.id);
visit::walk_struct_field(self, struct_field)
}
fn visit_variant_data(&mut self, struct_def: &VariantData,
_: ast::Ident, _: &ast::Generics, _: NodeId,
_: Span) {
self.operation.visit_id(struct_def.id());
visit::walk_struct_def(self, struct_def);
}
fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
self.operation.visit_id(ti.id);
visit::walk_trait_item(self, ti);
}
fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
self.operation.visit_id(ii.id);
visit::walk_impl_item(self, ii);
}
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
self.operation.visit_id(lifetime.id);
}
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
self.visit_lifetime(&def.lifetime);
}
fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {
self.operation.visit_id(trait_ref.ref_id);
visit::walk_trait_ref(self, trait_ref);
}
}
pub struct IdRangeComputingVisitor {
pub result: IdRange,
}
impl IdRangeComputingVisitor {
pub fn new() -> IdRangeComputingVisitor {
IdRangeComputingVisitor{result: IdRange::max(),}
}
pub fn result(&self) -> IdRange { self.result }
}
impl IdVisitingOperation for IdRangeComputingVisitor {
fn visit_id(&mut self, id: NodeId) { self.result.add(id); }
}
/// Computes the id range for a single fn body, ignoring nested items.
pub fn compute_id_range_for_fn_body(fk: FnKind, decl: &FnDecl,
body: &Block, sp: Span, id: NodeId)
-> IdRange {
let mut visitor = IdRangeComputingVisitor::new();
let mut id_visitor =
IdVisitor{operation: &mut visitor, visited_outermost: false,};
id_visitor.visit_fn(fk, decl, body, sp, id);
id_visitor.operation.result
}
/// Returns true if the given pattern consists solely of an identifier
/// and false otherwise.
pub fn pat_is_ident(pat: P<ast::Pat>) -> bool {
match pat.node { ast::PatIdent(..) => true, _ => false, }
}
pub fn path_name_eq(a: &ast::Path, b: &ast::Path) -> bool {
(a.span == b.span) && (a.global == b.global) &&
(segments_name_eq(&a.segments[..], &b.segments[..]))
}
pub fn segments_name_eq(a: &[ast::PathSegment], b: &[ast::PathSegment])
-> bool {
a.len() == b.len() &&
a.iter().zip(b).all(|(s, t)| {
s.identifier.name == t.identifier.name &&
s.parameters == t.parameters })
}
}
pub mod attr {
#[prelude_import]
use std::prelude::v1::*;
pub use self::StabilityLevel::*;
pub use self::ReprAttr::*;
pub use self::IntType::*;
use ast;
use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord,
MetaNameValue, MetaList};
use ast::{Stmt, StmtDecl, StmtExpr, StmtMac, StmtSemi, DeclItem,
DeclLocal};
use ast::{Expr, Item, Local, Decl};
use codemap::{Span, Spanned, spanned, dummy_spanned};
use codemap::BytePos;
use config::CfgDiag;
use errors::Handler;
use feature_gate::{GatedCfg, GatedCfgAttr};
use parse::lexer::comments::{doc_comment_style,
strip_doc_comment_decoration};
use parse::token::InternedString;
use parse::token;
use ptr::P;
use std::cell::{RefCell, Cell};
use std::collections::HashSet;
static USED_ATTRS: ::std::thread::LocalKey<RefCell<Vec<u64>>> =
{
fn __init() -> RefCell<Vec<u64>> { RefCell::new(Vec::new()) }
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<RefCell<Vec<u64>>>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY:
::std::thread::__ElfLocalKeyInner<RefCell<Vec<u64>>> =
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
pub fn mark_used(attr: &Attribute) {
let AttrId(id) = attr.node.id;
USED_ATTRS.with(|slot| { let idx = (id / 64) as usize;
let shift = id % 64;
if slot.borrow().len() <= idx {
let len = slot.borrow().len();
slot.borrow_mut().extend((0..(idx + 1 -
len)).map(|_|
0));
} slot.borrow_mut()[idx] |= 1 << shift; });
}
pub fn is_used(attr: &Attribute) -> bool {
let AttrId(id) = attr.node.id;
USED_ATTRS.with(|slot| { let idx = (id / 64) as usize;
let shift = id % 64;
slot.borrow().get(idx).map(|bits|
bits & (1 << shift) !=
0).unwrap_or(false)
})
}
pub trait AttrMetaMethods {
fn check_name(&self, name: &str) -> bool { name == &self.name()[..] }
/// Retrieve the name of the meta item, e.g. `foo` in `#[foo]`,
/// `#[foo="bar"]` and `#[foo(bar)]`
fn name(&self)
-> InternedString;
/// Gets the string value if self is a MetaNameValue variant
/// containing a string, otherwise None.
fn value_str(&self)
-> Option<InternedString>;
/// Gets a list of inner meta items from a list MetaItem type.
fn meta_item_list(&self)
-> Option<&[P<MetaItem>]>;
fn span(&self)
-> Span;
}
impl AttrMetaMethods for Attribute {
fn check_name(&self, name: &str) -> bool {
let matches = name == &self.name()[..];
if matches { mark_used(self); }
matches
}
fn name(&self) -> InternedString { self.meta().name() }
fn value_str(&self) -> Option<InternedString> {
self.meta().value_str()
}
fn meta_item_list(&self) -> Option<&[P<MetaItem>]> {
self.node.value.meta_item_list()
}
fn span(&self) -> Span { self.meta().span }
}
impl AttrMetaMethods for MetaItem {
fn name(&self) -> InternedString {
match self.node {
MetaWord(ref n) => (*n).clone(),
MetaNameValue(ref n, _) => (*n).clone(),
MetaList(ref n, _) => (*n).clone(),
}
}
fn value_str(&self) -> Option<InternedString> {
match self.node {
MetaNameValue(_, ref v) => {
match v.node {
ast::LitStr(ref s, _) => Some((*s).clone()),
_ => None,
}
}
_ => None,
}
}
fn meta_item_list(&self) -> Option<&[P<MetaItem>]> {
match self.node { MetaList(_, ref l) => Some(&l[..]), _ => None, }
}
fn span(&self) -> Span { self.span }
}
impl AttrMetaMethods for P<MetaItem> {
fn name(&self) -> InternedString { (**self).name() }
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
fn meta_item_list(&self) -> Option<&[P<MetaItem>]> {
(**self).meta_item_list()
}
fn span(&self) -> Span { (**self).span() }
}
pub trait AttributeMethods {
fn meta(&self)
-> &MetaItem;
fn with_desugared_doc<T, F>(&self, f: F)
-> T
where
F: FnOnce(&Attribute)
->
T;
}
impl AttributeMethods for Attribute {
/// Extract the MetaItem from inside this Attribute.
fn meta(&self) -> &MetaItem { &*self.node.value }
/// Convert self to a normal #[doc="foo"] comment, if it is a
/// comment like `///` or `/** */`. (Returns self unchanged for
/// non-sugared doc attributes.)
fn with_desugared_doc<T, F>(&self, f: F) -> T where
F: FnOnce(&Attribute) -> T {
if self.node.is_sugared_doc {
let comment = self.value_str().unwrap();
let meta =
mk_name_value_item_str(InternedString::new("doc"),
token::intern_and_get_ident(&strip_doc_comment_decoration(&comment)));
if self.node.style == ast::AttrStyle::Outer {
f(&mk_attr_outer(self.node.id, meta))
} else { f(&mk_attr_inner(self.node.id, meta)) }
} else { f(self) }
}
}
pub fn mk_name_value_item_str(name: InternedString, value: InternedString)
-> P<MetaItem> {
let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr));
mk_name_value_item(name, value_lit)
}
pub fn mk_name_value_item(name: InternedString, value: ast::Lit)
-> P<MetaItem> {
P(dummy_spanned(MetaNameValue(name, value)))
}
pub fn mk_list_item(name: InternedString, items: Vec<P<MetaItem>>)
-> P<MetaItem> {
P(dummy_spanned(MetaList(name, items)))
}
pub fn mk_word_item(name: InternedString) -> P<MetaItem> {
P(dummy_spanned(MetaWord(name)))
}
static NEXT_ATTR_ID: ::std::thread::LocalKey<Cell<usize>> =
{
fn __init() -> Cell<usize> { Cell::new(0) }
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<Cell<usize>>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY: ::std::thread::__ElfLocalKeyInner<Cell<usize>> =
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
pub fn mk_attr_id() -> AttrId {
let id =
NEXT_ATTR_ID.with(|slot| { let r = slot.get(); slot.set(r + 1); r
});
AttrId(id)
}
/// Returns an inner attribute with the given value.
pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
dummy_spanned(Attribute_{id: id,
style: ast::AttrStyle::Inner,
value: item,
is_sugared_doc: false,})
}
/// Returns an outer attribute with the given value.
pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
dummy_spanned(Attribute_{id: id,
style: ast::AttrStyle::Outer,
value: item,
is_sugared_doc: false,})
}
pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos,
hi: BytePos) -> Attribute {
let style = doc_comment_style(&text);
let lit = spanned(lo, hi, ast::LitStr(text, ast::CookedStr));
let attr =
Attribute_{id: id,
style: style,
value:
P(spanned(lo, hi,
MetaNameValue(InternedString::new("doc"),
lit))),
is_sugared_doc: true,};
spanned(lo, hi, attr)
}
/// Check if `needle` occurs in `haystack` by a structural
/// comparison. This is slightly subtle, and relies on ignoring the
/// span included in the `==` comparison a plain MetaItem.
pub fn contains(haystack: &[P<MetaItem>], needle: &MetaItem) -> bool {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 245u32,
__file: "src/attr.rs",
__module_path: "syntex_syntax::attr",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::attr", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["attr::contains (name=",
")"];
__STATIC_FMTSTR
},
&match (&needle.name(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
haystack.iter().any(|item| {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 247u32,
__file: "src/attr.rs",
__module_path:
"syntex_syntax::attr",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::attr",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[" testing: "];
__STATIC_FMTSTR
},
&match (&item.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}; item.node == needle.node })
}
pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str)
-> bool {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 253u32,
__file: "src/attr.rs",
__module_path: "syntex_syntax::attr",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::attr", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["attr::contains_name (name=",
")"];
__STATIC_FMTSTR
},
&match (&name,) {
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
metas.iter().any(|item| {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 255u32,
__file: "src/attr.rs",
__module_path:
"syntex_syntax::attr",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::attr",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[" testing: "];
__STATIC_FMTSTR
},
&match (&item.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}; item.check_name(name) })
}
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str)
-> Option<InternedString> {
attrs.iter().find(|at|
at.check_name(name)).and_then(|at|
at.value_str())
}
pub fn last_meta_item_value_str_by_name(items: &[P<MetaItem>], name: &str)
-> Option<InternedString> {
items.iter().rev().find(|mi|
mi.check_name(name)).and_then(|i|
i.value_str())
}
pub fn sort_meta_items(items: Vec<P<MetaItem>>) -> Vec<P<MetaItem>> {
let mut v =
items.into_iter().map(|mi|
(mi.name(),
mi)).collect::<Vec<(InternedString,
P<MetaItem>)>>();
v.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
v.into_iter().map(|(_, m)|
m.map(|Spanned { node, span }| {
Spanned{node:
match node {
MetaList(n, mis) =>
MetaList(n,
sort_meta_items(mis)),
_ => node,
},
span: span,} })).collect()
}
pub fn find_crate_name(attrs: &[Attribute]) -> Option<InternedString> {
first_attr_value_str_by_name(attrs, "crate_name")
}
/// Find the value of #[export_name=*] attribute and check its validity.
pub fn find_export_name_attr(diag: &Handler, attrs: &[Attribute])
-> Option<InternedString> {
attrs.iter().fold(None, |ia, attr| {
if attr.check_name("export_name") {
if let s@Some(_) = attr.value_str() {
s
} else {
diag.struct_span_err(attr.span,
"export_name attribute has invalid format").help("use #[export_name=\"*\"]").emit();
None
}
} else { ia } })
}
pub enum InlineAttr { None, Hint, Always, Never, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for InlineAttr {
#[inline]
fn eq(&self, __arg_0: &InlineAttr) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&InlineAttr::None, &InlineAttr::None) => true,
(&InlineAttr::Hint, &InlineAttr::Hint) => true,
(&InlineAttr::Always, &InlineAttr::Always) => true,
(&InlineAttr::Never, &InlineAttr::Never) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &InlineAttr) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&InlineAttr::None, &InlineAttr::None) => false,
(&InlineAttr::Hint, &InlineAttr::Hint) => false,
(&InlineAttr::Always, &InlineAttr::Always) => false,
(&InlineAttr::Never, &InlineAttr::Never) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for InlineAttr {
#[inline]
fn clone(&self) -> InlineAttr {
match (&*self,) {
(&InlineAttr::None,) => InlineAttr::None,
(&InlineAttr::Hint,) => InlineAttr::Hint,
(&InlineAttr::Always,) => InlineAttr::Always,
(&InlineAttr::Never,) => InlineAttr::Never,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for InlineAttr { }
/// Determine what `#[inline]` attribute is present in `attrs`, if any.
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute])
-> InlineAttr {
attrs.iter().fold(InlineAttr::None, |ia, attr| {
match attr.node.value.node {
MetaWord(ref n) if *n == "inline" => {
mark_used(attr);
InlineAttr::Hint
}
MetaList(ref n, ref items) if *n == "inline" =>
{
mark_used(attr);
if items.len() != 1 {
diagnostic.map(|d| {
d.span_err(attr.span,
"expected one argument");
});
InlineAttr::None
} else if contains_name(&items[..],
"always") {
InlineAttr::Always
} else if contains_name(&items[..], "never")
{
InlineAttr::Never
} else {
diagnostic.map(|d| {
d.span_err((*items[0]).span,
"invalid argument");
});
InlineAttr::None
}
}
_ => ia,
} })
}
/// True if `#[inline]` or `#[inline(always)]` is present in `attrs`.
pub fn requests_inline(attrs: &[Attribute]) -> bool {
match find_inline_attr(None, attrs) {
InlineAttr::Hint | InlineAttr::Always => true,
InlineAttr::None | InlineAttr::Never => false,
}
}
/// Tests if a cfg-pattern matches the cfg set
pub fn cfg_matches<T: CfgDiag>(cfgs: &[P<MetaItem>], cfg: &ast::MetaItem,
diag: &mut T) -> bool {
match cfg.node {
ast::MetaList(ref pred, ref mis) if &pred[..] == "any" =>
mis.iter().any(|mi| cfg_matches(cfgs, &**mi, diag)),
ast::MetaList(ref pred, ref mis) if &pred[..] == "all" =>
mis.iter().all(|mi| cfg_matches(cfgs, &**mi, diag)),
ast::MetaList(ref pred, ref mis) if &pred[..] == "not" => {
if mis.len() != 1 {
diag.emit_error(|diagnostic| {
diagnostic.span_err(cfg.span,
"expected 1 cfg-pattern");
});
return false;
}
!cfg_matches(cfgs, &*mis[0], diag)
}
ast::MetaList(ref pred, _) => {
diag.emit_error(|diagnostic| {
diagnostic.span_err(cfg.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid predicate `",
"`"];
__STATIC_FMTSTR
},
&match (&pred,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
});
false
}
ast::MetaWord(_) | ast::MetaNameValue(..) => {
diag.flag_gated(|feature_gated_cfgs| {
feature_gated_cfgs.extend(GatedCfg::gate(cfg).map(GatedCfgAttr::GatedCfg));
});
contains(cfgs, cfg)
}
}
}
/// Represents the #[stable], #[unstable] and #[rustc_deprecated] attributes.
pub struct Stability {
pub level: StabilityLevel,
pub feature: InternedString,
pub rustc_depr: Option<RustcDeprecation>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Stability {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Stability {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Stability {
#[inline]
fn eq(&self, __arg_0: &Stability) -> bool {
match *__arg_0 {
Stability {
level: ref __self_1_0,
feature: ref __self_1_1,
rustc_depr: ref __self_1_2 } =>
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Stability) -> bool {
match *__arg_0 {
Stability {
level: ref __self_1_0,
feature: ref __self_1_1,
rustc_depr: ref __self_1_2 } =>
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Stability {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("Stability");
let _ = builder.field("level", &&(*__self_0_0));
let _ = builder.field("feature", &&(*__self_0_1));
let _ = builder.field("rustc_depr", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Stability {
#[inline]
fn clone(&self) -> Stability {
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } =>
Stability{level: ::std::clone::Clone::clone(&(*__self_0_0)),
feature: ::std::clone::Clone::clone(&(*__self_0_1)),
rustc_depr:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Stability {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Stability, __D::Error> {
__arg_0.read_struct("Stability", 3usize, |_d| -> _ {
::std::result::Result::Ok(Stability{level:
match _d.read_struct_field("level",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
feature:
match _d.read_struct_field("feature",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
rustc_depr:
match _d.read_struct_field("rustc_depr",
2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Stability {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Stability {
level: ref __self_0_0,
feature: ref __self_0_1,
rustc_depr: ref __self_0_2 } =>
__arg_0.emit_struct("Stability", 3usize, |_e| -> _ {
match _e.emit_struct_field("level",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_struct_field("feature",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("rustc_depr",
2usize,
|_e| -> _ {
(*__self_0_2).encode(_e)
}); }),
}
}
}
/// The available stability levels.
pub enum StabilityLevel {
Unstable {
reason: Option<InternedString>,
issue: u32,
},
Stable {
since: InternedString,
},
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for StabilityLevel {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&StabilityLevel::Stable { since: ref __self_0 },) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for StabilityLevel {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&StabilityLevel::Stable { since: ref __self_0 },) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for StabilityLevel {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },) => {
let mut builder = __arg_0.debug_struct("Unstable");
let _ = builder.field("reason", &&(*__self_0));
let _ = builder.field("issue", &&(*__self_1));
builder.finish()
}
(&StabilityLevel::Stable { since: ref __self_0 },) => {
let mut builder = __arg_0.debug_struct("Stable");
let _ = builder.field("since", &&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for StabilityLevel {
#[inline]
fn clone(&self) -> StabilityLevel {
match (&*self,) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },) =>
StabilityLevel::Unstable{reason:
::std::clone::Clone::clone(&(*__self_0)),
issue:
::std::clone::Clone::clone(&(*__self_1)),},
(&StabilityLevel::Stable { since: ref __self_0 },) =>
StabilityLevel::Stable{since:
::std::clone::Clone::clone(&(*__self_0)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for StabilityLevel {
#[inline]
fn partial_cmp(&self, __arg_0: &StabilityLevel)
-> ::std::option::Option<::std::cmp::Ordering> {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0),
&(*__arg_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
{
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_1),
&(*__arg_1_1));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
} else { __test }
}
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
{
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0),
&(*__arg_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { __self_vi.partial_cmp(&__arg_1_vi) }
}
}
#[inline]
fn lt(&self, __arg_0: &StabilityLevel) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) =>
(*__self_0) < (*__arg_1_0) ||
!((*__arg_1_0) < (*__self_0)) &&
((*__self_1) < (*__arg_1_1) ||
!((*__arg_1_1) < (*__self_1)) && false),
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
(*__self_0) < (*__arg_1_0) ||
!((*__arg_1_0) < (*__self_0)) && false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { __self_vi.lt(&__arg_1_vi) }
}
}
#[inline]
fn le(&self, __arg_0: &StabilityLevel) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) =>
(*__self_0) < (*__arg_1_0) ||
!((*__arg_1_0) < (*__self_0)) &&
((*__self_1) < (*__arg_1_1) ||
!((*__arg_1_1) < (*__self_1)) && true),
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
(*__self_0) < (*__arg_1_0) ||
!((*__arg_1_0) < (*__self_0)) && true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { __self_vi.le(&__arg_1_vi) }
}
}
#[inline]
fn gt(&self, __arg_0: &StabilityLevel) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) =>
(*__self_0) > (*__arg_1_0) ||
!((*__arg_1_0) > (*__self_0)) &&
((*__self_1) > (*__arg_1_1) ||
!((*__arg_1_1) > (*__self_1)) && false),
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
(*__self_0) > (*__arg_1_0) ||
!((*__arg_1_0) > (*__self_0)) && false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { __self_vi.gt(&__arg_1_vi) }
}
}
#[inline]
fn ge(&self, __arg_0: &StabilityLevel) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) =>
(*__self_0) > (*__arg_1_0) ||
!((*__arg_1_0) > (*__self_0)) &&
((*__self_1) > (*__arg_1_1) ||
!((*__arg_1_1) > (*__self_1)) && true),
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
(*__self_0) > (*__arg_1_0) ||
!((*__arg_1_0) > (*__self_0)) && true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { __self_vi.ge(&__arg_1_vi) }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for StabilityLevel {
#[inline]
fn eq(&self, __arg_0: &StabilityLevel) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &StabilityLevel) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },
&StabilityLevel::Unstable {
reason: ref __arg_1_0, issue: ref __arg_1_1 }) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&StabilityLevel::Stable { since: ref __self_0 },
&StabilityLevel::Stable { since: ref __arg_1_0 }) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for StabilityLevel {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<StabilityLevel, __D::Error> {
__arg_0.read_enum("StabilityLevel", |_d| -> _ {
_d.read_enum_variant(&["Unstable", "Stable"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
StabilityLevel::Unstable{reason:
match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
issue:
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},},
1usize
=>
StabilityLevel::Stable{since:
match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},},
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/attr.rs",
408u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for StabilityLevel {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&StabilityLevel::Unstable {
reason: ref __self_0, issue: ref __self_1 },) => {
let _e = __arg_0;
_e.emit_enum("StabilityLevel", |_e| -> _ {
_e.emit_enum_variant("Unstable", 0usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&StabilityLevel::Stable { since: ref __self_0 },) => {
let _e = __arg_0;
_e.emit_enum("StabilityLevel", |_e| -> _ {
_e.emit_enum_variant("Stable", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
pub struct RustcDeprecation {
pub since: InternedString,
pub reason: InternedString,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for RustcDeprecation {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for RustcDeprecation {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for RustcDeprecation {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } => {
let mut builder =
__arg_0.debug_struct("RustcDeprecation");
let _ = builder.field("since", &&(*__self_0_0));
let _ = builder.field("reason", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for RustcDeprecation {
#[inline]
fn clone(&self) -> RustcDeprecation {
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
RustcDeprecation{since:
::std::clone::Clone::clone(&(*__self_0_0)),
reason:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for RustcDeprecation {
#[inline]
fn partial_cmp(&self, __arg_0: &RustcDeprecation)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
{
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_1),
&(*__self_1_1));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &RustcDeprecation) -> bool {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) &&
((*__self_0_1) < (*__self_1_1) ||
!((*__self_1_1) < (*__self_0_1)) && false),
},
}
}
#[inline]
fn le(&self, __arg_0: &RustcDeprecation) -> bool {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) &&
((*__self_0_1) < (*__self_1_1) ||
!((*__self_1_1) < (*__self_0_1)) && true),
},
}
}
#[inline]
fn gt(&self, __arg_0: &RustcDeprecation) -> bool {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) &&
((*__self_0_1) > (*__self_1_1) ||
!((*__self_1_1) > (*__self_0_1)) && false),
},
}
}
#[inline]
fn ge(&self, __arg_0: &RustcDeprecation) -> bool {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) &&
((*__self_0_1) > (*__self_1_1) ||
!((*__self_1_1) > (*__self_0_1)) && true),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for RustcDeprecation {
#[inline]
fn eq(&self, __arg_0: &RustcDeprecation) -> bool {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &RustcDeprecation) -> bool {
match *__arg_0 {
RustcDeprecation {
since: ref __self_1_0, reason: ref __self_1_1 } =>
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for RustcDeprecation {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<RustcDeprecation, __D::Error> {
__arg_0.read_struct("RustcDeprecation", 2usize, |_d| -> _ {
::std::result::Result::Ok(RustcDeprecation{since:
match _d.read_struct_field("since",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
reason:
match _d.read_struct_field("reason",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for RustcDeprecation {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
RustcDeprecation {
since: ref __self_0_0, reason: ref __self_0_1 } =>
__arg_0.emit_struct("RustcDeprecation", 2usize, |_e| -> _ {
match _e.emit_struct_field("since",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("reason",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
pub struct Deprecation {
pub since: Option<InternedString>,
pub note: Option<InternedString>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Deprecation {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1 } =>
{
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Deprecation {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1 } =>
{
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Deprecation {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1 } =>
{
let mut builder = __arg_0.debug_struct("Deprecation");
let _ = builder.field("since", &&(*__self_0_0));
let _ = builder.field("note", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Deprecation {
#[inline]
fn clone(&self) -> Deprecation {
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1 } =>
Deprecation{since: ::std::clone::Clone::clone(&(*__self_0_0)),
note:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for Deprecation {
#[inline]
fn partial_cmp(&self, __arg_0: &Deprecation)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
{
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_1),
&(*__self_1_1));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &Deprecation) -> bool {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) &&
((*__self_0_1) < (*__self_1_1) ||
!((*__self_1_1) < (*__self_0_1)) && false),
},
}
}
#[inline]
fn le(&self, __arg_0: &Deprecation) -> bool {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) &&
((*__self_0_1) < (*__self_1_1) ||
!((*__self_1_1) < (*__self_0_1)) && true),
},
}
}
#[inline]
fn gt(&self, __arg_0: &Deprecation) -> bool {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) &&
((*__self_0_1) > (*__self_1_1) ||
!((*__self_1_1) > (*__self_0_1)) && false),
},
}
}
#[inline]
fn ge(&self, __arg_0: &Deprecation) -> bool {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) &&
((*__self_0_1) > (*__self_1_1) ||
!((*__self_1_1) > (*__self_0_1)) && true),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Deprecation {
#[inline]
fn eq(&self, __arg_0: &Deprecation) -> bool {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Deprecation) -> bool {
match *__arg_0 {
Deprecation { since: ref __self_1_0, note: ref __self_1_1 } =>
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1
} =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Deprecation {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Deprecation, __D::Error> {
__arg_0.read_struct("Deprecation", 2usize, |_d| -> _ {
::std::result::Result::Ok(Deprecation{since:
match _d.read_struct_field("since",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
note:
match _d.read_struct_field("note",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Deprecation {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Deprecation { since: ref __self_0_0, note: ref __self_0_1 } =>
__arg_0.emit_struct("Deprecation", 2usize, |_e| -> _ {
match _e.emit_struct_field("since",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("note",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
impl StabilityLevel {
pub fn is_unstable(&self) -> bool {
if let Unstable { .. } = *self { true } else { false }
}
pub fn is_stable(&self) -> bool {
if let Stable { .. } = *self { true } else { false }
}
}
fn find_stability_generic<'a,
I>(diagnostic: &Handler, attrs_iter: I,
item_sp: Span) -> Option<Stability> where
I: Iterator<Item = &'a Attribute> {
let mut stab: Option<Stability> = None;
let mut rustc_depr: Option<RustcDeprecation> = None;
'outer:
for attr in attrs_iter {
let tag = attr.name();
let tag = &*tag;
if tag != "rustc_deprecated" && tag != "unstable" &&
tag != "stable" {
continue
}
mark_used(attr);
if let Some(metas) = attr.meta_item_list() {
let get =
|meta: &MetaItem, item: &mut Option<InternedString>| {
if item.is_some() {
diagnostic.span_err(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["multiple \'",
"\' items"];
__STATIC_FMTSTR
},
&match (&meta.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return false
}
if let Some(v) = meta.value_str() {
*item = Some(v);
true
} else {
diagnostic.span_err(meta.span,
"incorrect meta item");
false
} };
match tag {
"rustc_deprecated" => {
if rustc_depr.is_some() {
diagnostic.span_err(item_sp,
"multiple rustc_deprecated attributes");
break
}
let mut since = None;
let mut reason = None;
for meta in metas {
match &*meta.name() {
"since" =>
if !get(meta, &mut since) {
continue 'outer
},
"reason" =>
if !get(meta, &mut reason) {
continue 'outer
},
_ => {
diagnostic.span_err(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unknown meta item \'",
"\'"];
__STATIC_FMTSTR
},
&match (&meta.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
continue 'outer
}
}
}
match (since, reason) {
(Some(since), Some(reason)) => {
rustc_depr =
Some(RustcDeprecation{since: since,
reason:
reason,})
}
(None, _) => {
diagnostic.span_err(attr.span(),
"missing \'since\'");
continue
}
_ => {
diagnostic.span_err(attr.span(),
"missing \'reason\'");
continue
}
}
}
"unstable" => {
if stab.is_some() {
diagnostic.span_err(item_sp,
"multiple stability levels");
break
}
let mut feature = None;
let mut reason = None;
let mut issue = None;
for meta in metas {
match &*meta.name() {
"feature" =>
if !get(meta, &mut feature) {
continue 'outer
},
"reason" =>
if !get(meta, &mut reason) {
continue 'outer
},
"issue" =>
if !get(meta, &mut issue) {
continue 'outer
},
_ => {
diagnostic.span_err(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unknown meta item \'",
"\'"];
__STATIC_FMTSTR
},
&match (&meta.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
continue 'outer
}
}
}
match (feature, reason, issue) {
(Some(feature), reason, Some(issue)) => {
stab =
Some(Stability{level:
Unstable{reason:
reason,
issue:
{
if let Ok(issue)
=
issue.parse()
{
issue
} else {
diagnostic.span_err(attr.span(),
"incorrect \'issue\'");
continue
}
},},
feature: feature,
rustc_depr: None,})
}
(None, _, _) => {
diagnostic.span_err(attr.span(),
"missing \'feature\'");
continue
}
_ => {
diagnostic.span_err(attr.span(),
"missing \'issue\'");
continue
}
}
}
"stable" => {
if stab.is_some() {
diagnostic.span_err(item_sp,
"multiple stability levels");
break
}
let mut feature = None;
let mut since = None;
for meta in metas {
match &*meta.name() {
"feature" =>
if !get(meta, &mut feature) {
continue 'outer
},
"since" =>
if !get(meta, &mut since) {
continue 'outer
},
_ => {
diagnostic.span_err(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unknown meta item \'",
"\'"];
__STATIC_FMTSTR
},
&match (&meta.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
continue 'outer
}
}
}
match (feature, since) {
(Some(feature), Some(since)) => {
stab =
Some(Stability{level:
Stable{since:
since,},
feature: feature,
rustc_depr: None,})
}
(None, _) => {
diagnostic.span_err(attr.span(),
"missing \'feature\'");
continue
}
_ => {
diagnostic.span_err(attr.span(),
"missing \'since\'");
continue
}
}
}
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/attr.rs",
594u32);
&_FILE_LINE
})
}
}
}
} else {
diagnostic.span_err(attr.span(),
"incorrect stability attribute type");
continue
}
}
if let Some(rustc_depr) = rustc_depr {
if let Some(ref mut stab) = stab {
if let Unstable { reason: ref mut reason@None, .. } =
stab.level {
*reason = Some(rustc_depr.reason.clone())
}
stab.rustc_depr = Some(rustc_depr);
} else {
diagnostic.span_err(item_sp,
"rustc_deprecated attribute must be paired with either stable or unstable attribute");
}
}
stab
}
fn find_deprecation_generic<'a,
I>(diagnostic: &Handler, attrs_iter: I,
item_sp: Span) -> Option<Deprecation> where
I: Iterator<Item = &'a Attribute> {
let mut depr: Option<Deprecation> = None;
'outer:
for attr in attrs_iter {
if attr.name() != "deprecated" { continue }
mark_used(attr);
if depr.is_some() {
diagnostic.span_err(item_sp,
"multiple deprecated attributes");
break
}
depr =
if let Some(metas) = attr.meta_item_list() {
let get =
|meta: &MetaItem,
item: &mut Option<InternedString>| {
if item.is_some() {
diagnostic.span_err(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["multiple \'",
"\' items"];
__STATIC_FMTSTR
},
&match (&meta.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return false
}
if let Some(v) = meta.value_str() {
*item = Some(v);
true
} else {
diagnostic.span_err(meta.span,
"incorrect meta item");
false
} };
let mut since = None;
let mut note = None;
for meta in metas {
match &*meta.name() {
"since" =>
if !get(meta, &mut since) {
continue 'outer
},
"note" =>
if !get(meta, &mut note) { continue 'outer },
_ => {
diagnostic.span_err(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unknown meta item \'",
"\'"];
__STATIC_FMTSTR
},
&match (&meta.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
continue 'outer
}
}
}
Some(Deprecation{since: since, note: note,})
} else { Some(Deprecation{since: None, note: None,}) }
}
depr
}
/// Find the first stability attribute. `None` if none exists.
pub fn find_stability(diagnostic: &Handler, attrs: &[Attribute],
item_sp: Span) -> Option<Stability> {
find_stability_generic(diagnostic, attrs.iter(), item_sp)
}
/// Find the deprecation attribute. `None` if none exists.
pub fn find_deprecation(diagnostic: &Handler, attrs: &[Attribute],
item_sp: Span) -> Option<Deprecation> {
find_deprecation_generic(diagnostic, attrs.iter(), item_sp)
}
pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
let mut set = HashSet::new();
for meta in metas {
let name = meta.name();
if !set.insert(name.clone()) {
{
::std::rt::begin_unwind(diagnostic.span_fatal(meta.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["duplicate meta item `",
"`"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))),
{
static _FILE_LINE:
(&'static str, u32) =
("src/attr.rs", 695u32);
&_FILE_LINE
})
};
}
}
}
/// Parse #[repr(...)] forms.
///
/// Valid repr contents: any of the primitive integral type names (see
/// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
/// the same discriminant size that the corresponding C enum would or C
/// structure layout, and `packed` to remove padding.
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute)
-> Vec<ReprAttr> {
let mut acc = Vec::new();
match attr.node.value.node {
ast::MetaList(ref s, ref items) if *s == "repr" => {
mark_used(attr);
for item in items {
match item.node {
ast::MetaWord(ref word) => {
let hint =
match &word[..] {
"C" => Some(ReprExtern),
"packed" => Some(ReprPacked),
"simd" => Some(ReprSimd),
_ =>
match int_type_of_word(&word) {
Some(ity) =>
Some(ReprInt(item.span, ity)),
None => {
diagnostic.span_err(item.span,
"unrecognized representation hint");
None
}
},
};
match hint { Some(h) => acc.push(h), None => { } }
}
_ =>
diagnostic.span_err(item.span,
"unrecognized enum representation hint"),
}
}
}
_ => { }
}
acc
}
fn int_type_of_word(s: &str) -> Option<IntType> {
match s {
"i8" => Some(SignedInt(ast::TyI8)),
"u8" => Some(UnsignedInt(ast::TyU8)),
"i16" => Some(SignedInt(ast::TyI16)),
"u16" => Some(UnsignedInt(ast::TyU16)),
"i32" => Some(SignedInt(ast::TyI32)),
"u32" => Some(UnsignedInt(ast::TyU32)),
"i64" => Some(SignedInt(ast::TyI64)),
"u64" => Some(UnsignedInt(ast::TyU64)),
"isize" => Some(SignedInt(ast::TyIs)),
"usize" => Some(UnsignedInt(ast::TyUs)),
_ => None,
}
}
pub enum ReprAttr {
ReprAny,
ReprInt(Span, IntType),
ReprExtern,
ReprPacked,
ReprSimd,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ReprAttr {
#[inline]
fn clone(&self) -> ReprAttr {
match (&*self,) {
(&ReprAttr::ReprAny,) => ReprAttr::ReprAny,
(&ReprAttr::ReprInt(ref __self_0, ref __self_1),) =>
ReprAttr::ReprInt(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&ReprAttr::ReprExtern,) => ReprAttr::ReprExtern,
(&ReprAttr::ReprPacked,) => ReprAttr::ReprPacked,
(&ReprAttr::ReprSimd,) => ReprAttr::ReprSimd,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ReprAttr { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ReprAttr {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ReprAttr, __D::Error> {
__arg_0.read_enum("ReprAttr", |_d| -> _ {
_d.read_enum_variant(&["ReprAny", "ReprInt",
"ReprExtern",
"ReprPacked",
"ReprSimd"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
ReprAttr::ReprAny,
1usize
=>
ReprAttr::ReprInt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
ReprAttr::ReprExtern,
3usize
=>
ReprAttr::ReprPacked,
4usize
=>
ReprAttr::ReprSimd,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/attr.rs",
764u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ReprAttr {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&ReprAttr::ReprAny,) => {
let _e = __arg_0;
_e.emit_enum("ReprAttr", |_e| -> _ {
_e.emit_enum_variant("ReprAny", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&ReprAttr::ReprInt(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("ReprAttr", |_e| -> _ {
_e.emit_enum_variant("ReprInt", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&ReprAttr::ReprExtern,) => {
let _e = __arg_0;
_e.emit_enum("ReprAttr", |_e| -> _ {
_e.emit_enum_variant("ReprExtern", 2usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&ReprAttr::ReprPacked,) => {
let _e = __arg_0;
_e.emit_enum("ReprAttr", |_e| -> _ {
_e.emit_enum_variant("ReprPacked", 3usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&ReprAttr::ReprSimd,) => {
let _e = __arg_0;
_e.emit_enum("ReprAttr", |_e| -> _ {
_e.emit_enum_variant("ReprSimd", 4usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ReprAttr {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&ReprAttr::ReprAny,) => {
let mut builder = __arg_0.debug_tuple("ReprAny");
builder.finish()
}
(&ReprAttr::ReprInt(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ReprInt");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&ReprAttr::ReprExtern,) => {
let mut builder = __arg_0.debug_tuple("ReprExtern");
builder.finish()
}
(&ReprAttr::ReprPacked,) => {
let mut builder = __arg_0.debug_tuple("ReprPacked");
builder.finish()
}
(&ReprAttr::ReprSimd,) => {
let mut builder = __arg_0.debug_tuple("ReprSimd");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ReprAttr {
#[inline]
fn eq(&self, __arg_0: &ReprAttr) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ReprAttr::ReprAny, &ReprAttr::ReprAny) => true,
(&ReprAttr::ReprInt(ref __self_0, ref __self_1),
&ReprAttr::ReprInt(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&ReprAttr::ReprExtern, &ReprAttr::ReprExtern) =>
true,
(&ReprAttr::ReprPacked, &ReprAttr::ReprPacked) =>
true,
(&ReprAttr::ReprSimd, &ReprAttr::ReprSimd) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ReprAttr) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ReprAttr::ReprAny, &ReprAttr::ReprAny) => false,
(&ReprAttr::ReprInt(ref __self_0, ref __self_1),
&ReprAttr::ReprInt(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&ReprAttr::ReprExtern, &ReprAttr::ReprExtern) =>
false,
(&ReprAttr::ReprPacked, &ReprAttr::ReprPacked) =>
false,
(&ReprAttr::ReprSimd, &ReprAttr::ReprSimd) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
impl ReprAttr {
pub fn is_ffi_safe(&self) -> bool {
match *self {
ReprAny => false,
ReprInt(_sp, ity) => ity.is_ffi_safe(),
ReprExtern => true,
ReprPacked => false,
ReprSimd => true,
}
}
}
pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy), }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for IntType {
#[inline]
fn clone(&self) -> IntType {
match (&*self,) {
(&IntType::SignedInt(ref __self_0),) =>
IntType::SignedInt(::std::clone::Clone::clone(&(*__self_0))),
(&IntType::UnsignedInt(ref __self_0),) =>
IntType::UnsignedInt(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for IntType { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for IntType {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<IntType, __D::Error> {
__arg_0.read_enum("IntType", |_d| -> _ {
_d.read_enum_variant(&["SignedInt",
"UnsignedInt"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
IntType::SignedInt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
IntType::UnsignedInt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/attr.rs",
785u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for IntType {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&IntType::SignedInt(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("IntType", |_e| -> _ {
_e.emit_enum_variant("SignedInt", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&IntType::UnsignedInt(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("IntType", |_e| -> _ {
_e.emit_enum_variant("UnsignedInt", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for IntType {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&IntType::SignedInt(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("SignedInt");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&IntType::UnsignedInt(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("UnsignedInt");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for IntType {
#[inline]
fn eq(&self, __arg_0: &IntType) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&IntType::SignedInt(ref __self_0),
&IntType::SignedInt(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&IntType::UnsignedInt(ref __self_0),
&IntType::UnsignedInt(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &IntType) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&IntType::SignedInt(ref __self_0),
&IntType::SignedInt(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&IntType::UnsignedInt(ref __self_0),
&IntType::UnsignedInt(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for IntType {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&IntType::SignedInt(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&IntType::UnsignedInt(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for IntType {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&IntType::SignedInt(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&IntType::UnsignedInt(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
impl IntType {
#[inline]
pub fn is_signed(self) -> bool {
match self { SignedInt(..) => true, UnsignedInt(..) => false, }
}
fn is_ffi_safe(self) -> bool {
match self {
SignedInt(ast::TyI8) | UnsignedInt(ast::TyU8) |
SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) |
SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) |
SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true,
SignedInt(ast::TyIs) | UnsignedInt(ast::TyUs) => false,
}
}
}
/// A list of attributes, behind a optional box as
/// a space optimization.
pub type ThinAttributes = Option<Box<Vec<Attribute>>>;
pub trait ThinAttributesExt {
fn map_thin_attrs<F>(self, f: F)
-> Self
where
F: FnOnce(Vec<Attribute>)
->
Vec<Attribute>;
fn prepend(mut self, attrs: Self)
-> Self;
fn append(mut self, attrs: Self)
-> Self;
fn update<F>(&mut self, f: F)
where
Self: Sized,
F: FnOnce(Self)
->
Self;
fn as_attr_slice(&self)
-> &[Attribute];
fn into_attr_vec(self)
-> Vec<Attribute>;
}
impl ThinAttributesExt for ThinAttributes {
fn map_thin_attrs<F>(self, f: F) -> Self where
F: FnOnce(Vec<Attribute>) -> Vec<Attribute> {
f(self.map(|b| *b).unwrap_or(Vec::new())).into_thin_attrs()
}
fn prepend(self, attrs: ThinAttributes) -> Self {
attrs.map_thin_attrs(|mut attrs| {
attrs.extend(self.into_attr_vec()); attrs })
}
fn append(self, attrs: ThinAttributes) -> Self {
self.map_thin_attrs(|mut self_| {
self_.extend(attrs.into_attr_vec()); self_ })
}
fn update<F>(&mut self, f: F) where Self: Sized,
F: FnOnce(ThinAttributes) -> ThinAttributes {
let self_ = f(self.take());
*self = self_;
}
fn as_attr_slice(&self) -> &[Attribute] {
match *self { Some(ref b) => b, None => &[], }
}
fn into_attr_vec(self) -> Vec<Attribute> {
match self { Some(b) => *b, None => Vec::new(), }
}
}
pub trait AttributesExt {
fn into_thin_attrs(self)
-> ThinAttributes;
}
impl AttributesExt for Vec<Attribute> {
fn into_thin_attrs(self) -> ThinAttributes {
if self.len() == 0 { None } else { Some(Box::new(self)) }
}
}
/// A cheap way to add Attributes to an AST node.
pub trait WithAttrs {
fn with_attrs(self, attrs: ThinAttributes)
-> Self;
}
impl WithAttrs for P<Expr> {
fn with_attrs(self, attrs: ThinAttributes) -> Self {
self.map(|mut e| { e.attrs.update(|a| a.append(attrs)); e })
}
}
impl WithAttrs for P<Item> {
fn with_attrs(self, attrs: ThinAttributes) -> Self {
self.map(|Item { ident, attrs: mut ats, id, node, vis, span }| {
ats.extend(attrs.into_attr_vec());
Item{ident: ident,
attrs: ats,
id: id,
node: node,
vis: vis,
span: span,} })
}
}
impl WithAttrs for P<Local> {
fn with_attrs(self, attrs: ThinAttributes) -> Self {
self.map(|Local { pat, ty, init, id, span, attrs: mut ats }| {
ats.update(|a| a.append(attrs));
Local{pat: pat,
ty: ty,
init: init,
id: id,
span: span,
attrs: ats,} })
}
}
impl WithAttrs for P<Decl> {
fn with_attrs(self, attrs: ThinAttributes) -> Self {
self.map(|Spanned { span, node }| {
Spanned{span: span,
node:
match node {
DeclLocal(local) =>
DeclLocal(local.with_attrs(attrs)),
DeclItem(item) =>
DeclItem(item.with_attrs(attrs)),
},} })
}
}
impl WithAttrs for P<Stmt> {
fn with_attrs(self, attrs: ThinAttributes) -> Self {
self.map(|Spanned { span, node }| {
Spanned{span: span,
node:
match node {
StmtDecl(decl, id) =>
StmtDecl(decl.with_attrs(attrs), id),
StmtExpr(expr, id) =>
StmtExpr(expr.with_attrs(attrs), id),
StmtSemi(expr, id) =>
StmtSemi(expr.with_attrs(attrs), id),
StmtMac(mac, style, mut ats) => {
ats.update(|a| a.append(attrs));
StmtMac(mac, style, ats)
}
},} })
}
}
}
pub mod codemap {
//! The CodeMap tracks all the source code used within a single crate, mapping
//! from integer byte positions to the original source code location. Each bit
//! of source parsed during crate parsing (typically files, in-memory strings,
//! or various bits of macro expansion) cover a continuous range of bytes in the
//! CodeMap and are represented by FileMaps. Byte positions are stored in
//! `spans` and used pervasively in the compiler. They are absolute positions
//! within the CodeMap, which upon request can be converted to line and column
//! information, source code snippets, etc.
#[prelude_import]
use std::prelude::v1::*;
pub use self::ExpnFormat::*;
use std::cell::{Cell, RefCell};
use std::ops::{Add, Sub};
use std::path::Path;
use std::rc::Rc;
use std::{fmt, fs};
use std::io::{self, Read};
use serialize::{Encodable, Decodable, Encoder, Decoder};
use ast::Name;
pub trait Pos {
fn from_usize(n: usize)
-> Self;
fn to_usize(&self)
-> usize;
}
/// A byte offset. Keep this small (currently 32-bits), as AST contains
/// a lot of them.
pub struct BytePos(pub u32);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for BytePos {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
BytePos(ref __self_0_0) => {
let mut builder = __arg_0.debug_tuple("BytePos");
let _ = builder.field(&&(*__self_0_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for BytePos {
#[inline]
fn partial_cmp(&self, __arg_0: &BytePos)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &BytePos) -> bool {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &BytePos) -> bool {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &BytePos) -> bool {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &BytePos) -> bool {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for BytePos {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
BytePos(ref __self_0_0) => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for BytePos {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
BytePos(ref __self_0_0) => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for BytePos {
#[inline]
fn eq(&self, __arg_0: &BytePos) -> bool {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &BytePos) -> bool {
match *__arg_0 {
BytePos(ref __self_1_0) =>
match *self {
BytePos(ref __self_0_0) =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BytePos { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BytePos {
#[inline]
fn clone(&self) -> BytePos {
match *self {
BytePos(ref __self_0_0) =>
BytePos(::std::clone::Clone::clone(&(*__self_0_0))),
}
}
}
/// A character offset. Because of multibyte utf8 characters, a byte offset
/// is not equivalent to a character offset. The CodeMap will convert BytePos
/// values to CharPos values as necessary.
pub struct CharPos(pub usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for CharPos {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
CharPos(ref __self_0_0) => {
let mut builder = __arg_0.debug_tuple("CharPos");
let _ = builder.field(&&(*__self_0_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for CharPos {
#[inline]
fn partial_cmp(&self, __arg_0: &CharPos)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &CharPos) -> bool {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &CharPos) -> bool {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &CharPos) -> bool {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &CharPos) -> bool {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for CharPos {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
CharPos(ref __self_0_0) => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for CharPos {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
CharPos(ref __self_0_0) => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for CharPos {
#[inline]
fn eq(&self, __arg_0: &CharPos) -> bool {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &CharPos) -> bool {
match *__arg_0 {
CharPos(ref __self_1_0) =>
match *self {
CharPos(ref __self_0_0) =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for CharPos {
#[inline]
fn clone(&self) -> CharPos {
match *self {
CharPos(ref __self_0_0) =>
CharPos(::std::clone::Clone::clone(&(*__self_0_0))),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for CharPos { }
impl Pos for BytePos {
fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }
fn to_usize(&self) -> usize { let BytePos(n) = *self; n as usize }
}
impl Add for BytePos {
type
Output
=
BytePos;
fn add(self, rhs: BytePos) -> BytePos {
BytePos((self.to_usize() + rhs.to_usize()) as u32)
}
}
impl Sub for BytePos {
type
Output
=
BytePos;
fn sub(self, rhs: BytePos) -> BytePos {
BytePos((self.to_usize() - rhs.to_usize()) as u32)
}
}
impl Encodable for BytePos {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_u32(self.0)
}
}
impl Decodable for BytePos {
fn decode<D: Decoder>(d: &mut D) -> Result<BytePos, D::Error> {
Ok(BytePos(match d.read_u32() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
}
}
impl Pos for CharPos {
fn from_usize(n: usize) -> CharPos { CharPos(n) }
fn to_usize(&self) -> usize { let CharPos(n) = *self; n }
}
impl Add for CharPos {
type
Output
=
CharPos;
fn add(self, rhs: CharPos) -> CharPos {
CharPos(self.to_usize() + rhs.to_usize())
}
}
impl Sub for CharPos {
type
Output
=
CharPos;
fn sub(self, rhs: CharPos) -> CharPos {
CharPos(self.to_usize() - rhs.to_usize())
}
}
/// Spans represent a region of code, used for error reporting. Positions in spans
/// are *absolute* positions from the beginning of the codemap, not positions
/// relative to FileMaps. Methods on the CodeMap can be used to relate spans back
/// to the original source.
/// You must be careful if the span crosses more than one file - you will not be
/// able to use many of the functions on spans in codemap and you cannot assume
/// that the length of the span = hi - lo; there may be space in the BytePos
/// range between files.
pub struct Span {
pub lo: BytePos,
pub hi: BytePos,
/// Information about where the macro came from, if this piece of
/// code was created by a macro expansion.
pub expn_id: ExpnId,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Span {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Span {
lo: ref __self_0_0,
hi: ref __self_0_1,
expn_id: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Span { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Span {
#[inline]
fn clone(&self) -> Span {
match *self {
Span {
lo: ref __self_0_0,
hi: ref __self_0_1,
expn_id: ref __self_0_2 } =>
Span{lo: ::std::clone::Clone::clone(&(*__self_0_0)),
hi: ::std::clone::Clone::clone(&(*__self_0_1)),
expn_id: ::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub const DUMMY_SP: Span =
Span{lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION,};
pub const COMMAND_LINE_SP: Span =
Span{lo: BytePos(0), hi: BytePos(0), expn_id: COMMAND_LINE_EXPN,};
impl Span {
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
pub fn substitute_dummy(self, other: Span) -> Span {
if self == DUMMY_SP { other } else { self }
}
pub fn contains(self, other: Span) -> bool {
self.lo <= other.lo && other.hi <= self.hi
}
}
pub struct Spanned<T> {
pub node: T,
pub span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::marker::Copy> ::std::marker::Copy for Spanned<T> { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::fmt::Debug> ::std::fmt::Debug for Spanned<T> {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("Spanned");
let _ = builder.field("node", &&(*__self_0_0));
let _ = builder.field("span", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::hash::Hash> ::std::hash::Hash for Spanned<T> {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::rustc_serialize::Decodable> ::rustc_serialize::Decodable for
Spanned<T> {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Spanned<T>, __D::Error> {
__arg_0.read_struct("Spanned", 2usize, |_d| -> _ {
::std::result::Result::Ok(Spanned{node:
match _d.read_struct_field("node",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
span:
match _d.read_struct_field("span",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::rustc_serialize::Encodable> ::rustc_serialize::Encodable for
Spanned<T> {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } =>
__arg_0.emit_struct("Spanned", 2usize, |_e| -> _ {
match _e.emit_struct_field("node", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("span",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::cmp::Eq> ::std::cmp::Eq for Spanned<T> {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::cmp::PartialEq> ::std::cmp::PartialEq for Spanned<T> {
#[inline]
fn eq(&self, __arg_0: &Spanned<T>) -> bool {
match *__arg_0 {
Spanned { node: ref __self_1_0, span: ref __self_1_1 } =>
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Spanned<T>) -> bool {
match *__arg_0 {
Spanned { node: ref __self_1_0, span: ref __self_1_1 } =>
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::clone::Clone> ::std::clone::Clone for Spanned<T> {
#[inline]
fn clone(&self) -> Spanned<T> {
match *self {
Spanned { node: ref __self_0_0, span: ref __self_0_1 } =>
Spanned{node: ::std::clone::Clone::clone(&(*__self_0_0)),
span: ::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
impl PartialEq for Span {
fn eq(&self, other: &Span) -> bool {
return (*self).lo == (*other).lo && (*self).hi == (*other).hi;
}
fn ne(&self, other: &Span) -> bool { !(*self).eq(other) }
}
impl Eq for Span { }
impl Encodable for Span {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
match s.emit_u32(self.lo.0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
s.emit_u32(self.hi.0)
}
}
impl Decodable for Span {
fn decode<D: Decoder>(d: &mut D) -> Result<Span, D::Error> {
let lo =
BytePos(match d.read_u32() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
let hi =
BytePos(match d.read_u32() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
Ok(mk_sp(lo, hi))
}
}
fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["Span { lo: ",
", hi: ",
", expn_id: ",
" }"];
__STATIC_FMTSTR
},
&match (&span.lo, &span.hi,
&span.expn_id) {
(__arg0, __arg1,
__arg2) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Debug::fmt)],
}))
}
pub static SPAN_DEBUG:
::std::thread::LocalKey<Cell<fn(Span, &mut fmt::Formatter)
-> fmt::Result>> =
{
fn __init()
-> Cell<fn(Span, &mut fmt::Formatter) -> fmt::Result> {
Cell::new(default_span_debug)
}
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<Cell<fn(Span,
&mut fmt::Formatter)
->
fmt::Result>>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY:
::std::thread::__ElfLocalKeyInner<Cell<fn(Span,
&mut fmt::Formatter)
->
fmt::Result>>
=
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
SPAN_DEBUG.with(|span_debug| span_debug.get()(*self, f))
}
}
pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> Spanned<T> {
respan(mk_sp(lo, hi), t)
}
pub fn respan<T>(sp: Span, t: T) -> Spanned<T> {
Spanned{node: t, span: sp,}
}
pub fn dummy_spanned<T>(t: T) -> Spanned<T> { respan(DUMMY_SP, t) }
pub fn mk_sp(lo: BytePos, hi: BytePos) -> Span {
Span{lo: lo, hi: hi, expn_id: NO_EXPANSION,}
}
/// Return the span itself if it doesn't come from a macro expansion,
/// otherwise return the call site span up to the `enclosing_sp` by
/// following the `expn_info` chain.
pub fn original_sp(cm: &CodeMap, sp: Span, enclosing_sp: Span) -> Span {
let call_site1 =
cm.with_expn_info(sp.expn_id, |ei| ei.map(|ei| ei.call_site));
let call_site2 =
cm.with_expn_info(enclosing_sp.expn_id,
|ei| ei.map(|ei| ei.call_site));
match (call_site1, call_site2) {
(None, _) => sp,
(Some(call_site1), Some(call_site2)) if call_site1 == call_site2
=> sp,
(Some(call_site1), _) =>
original_sp(cm, call_site1, enclosing_sp),
}
}
/// A source code location used for error reporting
pub struct Loc {
/// Information about the original source
pub file: Rc<FileMap>,
/// The (1-based) line number
pub line: usize,
/// The (0-based) column offset
pub col: CharPos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Loc {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
Loc {
file: ref __self_0_0,
line: ref __self_0_1,
col: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("Loc");
let _ = builder.field("file", &&(*__self_0_0));
let _ = builder.field("line", &&(*__self_0_1));
let _ = builder.field("col", &&(*__self_0_2));
builder.finish()
}
}
}
}
/// A source code location used as the result of lookup_char_pos_adj
pub struct LocWithOpt {
pub filename: FileName,
pub line: usize,
pub col: CharPos,
pub file: Option<Rc<FileMap>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for LocWithOpt {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
LocWithOpt {
filename: ref __self_0_0,
line: ref __self_0_1,
col: ref __self_0_2,
file: ref __self_0_3 } => {
let mut builder = __arg_0.debug_struct("LocWithOpt");
let _ = builder.field("filename", &&(*__self_0_0));
let _ = builder.field("line", &&(*__self_0_1));
let _ = builder.field("col", &&(*__self_0_2));
let _ = builder.field("file", &&(*__self_0_3));
builder.finish()
}
}
}
}
pub struct FileMapAndLine {
pub fm: Rc<FileMap>,
pub line: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for FileMapAndLine {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
FileMapAndLine { fm: ref __self_0_0, line: ref __self_0_1 } =>
{
let mut builder = __arg_0.debug_struct("FileMapAndLine");
let _ = builder.field("fm", &&(*__self_0_0));
let _ = builder.field("line", &&(*__self_0_1));
builder.finish()
}
}
}
}
pub struct FileMapAndBytePos {
pub fm: Rc<FileMap>,
pub pos: BytePos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for FileMapAndBytePos {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
FileMapAndBytePos { fm: ref __self_0_0, pos: ref __self_0_1 }
=> {
let mut builder =
__arg_0.debug_struct("FileMapAndBytePos");
let _ = builder.field("fm", &&(*__self_0_0));
let _ = builder.field("pos", &&(*__self_0_1));
builder.finish()
}
}
}
}
/// The source of expansion.
pub enum ExpnFormat {
/// e.g. #[derive(...)] <item>
MacroAttribute(Name),
/// e.g. `format!()`
MacroBang(Name),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ExpnFormat {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ExpnFormat::MacroAttribute(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&ExpnFormat::MacroBang(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ExpnFormat {
#[inline]
fn eq(&self, __arg_0: &ExpnFormat) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ExpnFormat::MacroAttribute(ref __self_0),
&ExpnFormat::MacroAttribute(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&ExpnFormat::MacroBang(ref __self_0),
&ExpnFormat::MacroBang(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ExpnFormat) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ExpnFormat::MacroAttribute(ref __self_0),
&ExpnFormat::MacroAttribute(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&ExpnFormat::MacroBang(ref __self_0),
&ExpnFormat::MacroBang(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ExpnFormat {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&ExpnFormat::MacroAttribute(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("MacroAttribute");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&ExpnFormat::MacroBang(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("MacroBang");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ExpnFormat {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match (&*self,) {
(&ExpnFormat::MacroAttribute(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&ExpnFormat::MacroBang(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ExpnFormat {
#[inline]
fn clone(&self) -> ExpnFormat {
match (&*self,) {
(&ExpnFormat::MacroAttribute(ref __self_0),) =>
ExpnFormat::MacroAttribute(::std::clone::Clone::clone(&(*__self_0))),
(&ExpnFormat::MacroBang(ref __self_0),) =>
ExpnFormat::MacroBang(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub struct NameAndSpan {
/// The format with which the macro was invoked.
pub format: ExpnFormat,
/// Whether the macro is allowed to use #[unstable]/feature-gated
/// features internally without forcing the whole crate to opt-in
/// to them.
pub allow_internal_unstable: bool,
/// The span of the macro definition itself. The macro may not
/// have a sensible definition span (e.g. something defined
/// completely inside libsyntax) in which case this is None.
pub span: Option<Span>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for NameAndSpan {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
NameAndSpan {
format: ref __self_0_0,
allow_internal_unstable: ref __self_0_1,
span: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("NameAndSpan");
let _ = builder.field("format", &&(*__self_0_0));
let _ =
builder.field("allow_internal_unstable",
&&(*__self_0_1));
let _ = builder.field("span", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for NameAndSpan {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
NameAndSpan {
format: ref __self_0_0,
allow_internal_unstable: ref __self_0_1,
span: ref __self_0_2 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
::std::hash::Hash::hash(&(*__self_0_2), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for NameAndSpan {
#[inline]
fn clone(&self) -> NameAndSpan {
match *self {
NameAndSpan {
format: ref __self_0_0,
allow_internal_unstable: ref __self_0_1,
span: ref __self_0_2 } =>
NameAndSpan{format:
::std::clone::Clone::clone(&(*__self_0_0)),
allow_internal_unstable:
::std::clone::Clone::clone(&(*__self_0_1)),
span:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
impl NameAndSpan {
pub fn name(&self) -> Name {
match self.format {
ExpnFormat::MacroAttribute(s) => s,
ExpnFormat::MacroBang(s) => s,
}
}
}
/// Extra information for tracking spans of macro and syntax sugar expansion
pub struct ExpnInfo {
/// The location of the actual macro invocation or syntax sugar , e.g.
/// `let x = foo!();` or `if let Some(y) = x {}`
///
/// This may recursively refer to other macro invocations, e.g. if
/// `foo!()` invoked `bar!()` internally, and there was an
/// expression inside `bar!`; the call_site of the expression in
/// the expansion would point to the `bar!` invocation; that
/// call_site span would have its own ExpnInfo, with the call_site
/// pointing to the `foo!` invocation.
pub call_site: Span,
/// Information about the expansion.
pub callee: NameAndSpan,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ExpnInfo {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ExpnInfo { call_site: ref __self_0_0, callee: ref __self_0_1 }
=> {
let mut builder = __arg_0.debug_struct("ExpnInfo");
let _ = builder.field("call_site", &&(*__self_0_0));
let _ = builder.field("callee", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ExpnInfo {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
ExpnInfo { call_site: ref __self_0_0, callee: ref __self_0_1 }
=> {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
::std::hash::Hash::hash(&(*__self_0_1), __arg_0);
}
}
}
}
pub struct ExpnId(u32);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ExpnId { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for ExpnId {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<ExpnId, __D::Error> {
__arg_0.read_struct("ExpnId", 1usize, |_d| -> _ {
::std::result::Result::Ok(ExpnId(match _d.read_struct_field("_field0",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
})) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for ExpnId {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
ExpnId(ref __self_0_0) =>
__arg_0.emit_struct("ExpnId", 1usize, |_e| -> _ {
return _e.emit_struct_field("_field0",
0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ExpnId {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
ExpnId(ref __self_0_0) => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for ExpnId {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
ExpnId(ref __self_0_0) => {
let mut builder = __arg_0.debug_tuple("ExpnId");
let _ = builder.field(&&(*__self_0_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ExpnId {
#[inline]
fn clone(&self) -> ExpnId {
match *self {
ExpnId(ref __self_0_0) =>
ExpnId(::std::clone::Clone::clone(&(*__self_0_0))),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ExpnId {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
ExpnId(ref __self_0_0) => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ExpnId {
#[inline]
fn eq(&self, __arg_0: &ExpnId) -> bool {
match *__arg_0 {
ExpnId(ref __self_1_0) =>
match *self {
ExpnId(ref __self_0_0) =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &ExpnId) -> bool {
match *__arg_0 {
ExpnId(ref __self_1_0) =>
match *self {
ExpnId(ref __self_0_0) =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
pub const NO_EXPANSION: ExpnId = ExpnId(!0);
pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(!1);
impl ExpnId {
pub fn from_u32(id: u32) -> ExpnId { ExpnId(id) }
pub fn into_u32(self) -> u32 { self.0 }
}
pub type FileName = String;
pub struct LineInfo {
/// Index of line, starting from 0.
pub line_index: usize,
/// Column in line where span begins, starting from 0.
pub start_col: CharPos,
/// Column in line where span ends, starting from 0, exclusive.
pub end_col: CharPos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for LineInfo {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
LineInfo {
line_index: ref __self_0_0,
start_col: ref __self_0_1,
end_col: ref __self_0_2 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for LineInfo {
#[inline]
fn eq(&self, __arg_0: &LineInfo) -> bool {
match *__arg_0 {
LineInfo {
line_index: ref __self_1_0,
start_col: ref __self_1_1,
end_col: ref __self_1_2 } =>
match *self {
LineInfo {
line_index: ref __self_0_0,
start_col: ref __self_0_1,
end_col: ref __self_0_2 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2),
},
}
}
#[inline]
fn ne(&self, __arg_0: &LineInfo) -> bool {
match *__arg_0 {
LineInfo {
line_index: ref __self_1_0,
start_col: ref __self_1_1,
end_col: ref __self_1_2 } =>
match *self {
LineInfo {
line_index: ref __self_0_0,
start_col: ref __self_0_1,
end_col: ref __self_0_2 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for LineInfo {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
LineInfo {
line_index: ref __self_0_0,
start_col: ref __self_0_1,
end_col: ref __self_0_2 } => {
let mut builder = __arg_0.debug_struct("LineInfo");
let _ = builder.field("line_index", &&(*__self_0_0));
let _ = builder.field("start_col", &&(*__self_0_1));
let _ = builder.field("end_col", &&(*__self_0_2));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for LineInfo {
#[inline]
fn clone(&self) -> LineInfo {
match *self {
LineInfo {
line_index: ref __self_0_0,
start_col: ref __self_0_1,
end_col: ref __self_0_2 } =>
LineInfo{line_index:
::std::clone::Clone::clone(&(*__self_0_0)),
start_col:
::std::clone::Clone::clone(&(*__self_0_1)),
end_col:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for LineInfo { }
pub struct FileLines {
pub file: Rc<FileMap>,
pub lines: Vec<LineInfo>,
}
/// Identifies an offset of a multi-byte character in a FileMap
pub struct MultiByteChar {
/// The absolute offset of the character in the CodeMap
pub pos: BytePos,
/// The number of bytes, >=2
pub bytes: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for MultiByteChar {
#[inline]
fn eq(&self, __arg_0: &MultiByteChar) -> bool {
match *__arg_0 {
MultiByteChar { pos: ref __self_1_0, bytes: ref __self_1_1 }
=>
match *self {
MultiByteChar { pos: ref __self_0_0, bytes: ref __self_0_1
} =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &MultiByteChar) -> bool {
match *__arg_0 {
MultiByteChar { pos: ref __self_1_0, bytes: ref __self_1_1 }
=>
match *self {
MultiByteChar { pos: ref __self_0_0, bytes: ref __self_0_1
} =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MultiByteChar {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
MultiByteChar { pos: ref __self_0_0, bytes: ref __self_0_1 }
=> {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for MultiByteChar {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<MultiByteChar, __D::Error> {
__arg_0.read_struct("MultiByteChar", 2usize, |_d| -> _ {
::std::result::Result::Ok(MultiByteChar{pos:
match _d.read_struct_field("pos",
0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
bytes:
match _d.read_struct_field("bytes",
1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},})
})
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for MultiByteChar {
fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match *self {
MultiByteChar { pos: ref __self_0_0, bytes: ref __self_0_1 }
=>
__arg_0.emit_struct("MultiByteChar", 2usize, |_e| -> _ {
match _e.emit_struct_field("pos", 0usize,
|_e| -> _ {
(*__self_0_0).encode(_e)
}) {
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_struct_field("bytes",
1usize,
|_e| -> _ {
(*__self_0_1).encode(_e)
}); }),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MultiByteChar {
#[inline]
fn clone(&self) -> MultiByteChar {
match *self {
MultiByteChar { pos: ref __self_0_0, bytes: ref __self_0_1 }
=>
MultiByteChar{pos: ::std::clone::Clone::clone(&(*__self_0_0)),
bytes:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for MultiByteChar { }
/// A single source in the CodeMap.
pub struct FileMap {
/// The name of the file that the source came from, source that doesn't
/// originate from files has names between angle brackets by convention,
/// e.g. `<anon>`
pub name: FileName,
/// The complete source code
pub src: Option<Rc<String>>,
/// The start position of this source in the CodeMap
pub start_pos: BytePos,
/// The end position of this source in the CodeMap
pub end_pos: BytePos,
/// Locations of lines beginnings in the source code
pub lines: RefCell<Vec<BytePos>>,
/// Locations of multi-byte characters in the source code
pub multibyte_chars: RefCell<Vec<MultiByteChar>>,
}
impl Encodable for FileMap {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_struct("FileMap", 5, |s| {
match s.emit_struct_field("name", 0,
|s| self.name.encode(s)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.emit_struct_field("start_pos", 1,
|s|
self.start_pos.encode(s))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.emit_struct_field("end_pos", 2,
|s|
self.end_pos.encode(s))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.emit_struct_field("lines", 3, |s| {
let lines =
self.lines.borrow();
match s.emit_u32(lines.len()
as
u32)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !lines.is_empty() {
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 ...255 => 1,
256 ...65535
=> 2,
_ => 4,
};
match bytes_per_diff.encode(s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match lines[0].encode(s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let diff_iter =
(&lines[..]).windows(2).map(|w|
(w[1]
-
w[0]));
match bytes_per_diff {
1 =>
for diff in
diff_iter {
match (diff.0
as
u8).encode(s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
},
2 =>
for diff in
diff_iter {
match (diff.0
as
u16).encode(s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
},
4 =>
for diff in
diff_iter {
match diff.0.encode(s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
},
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/codemap.rs",
383u32);
&_FILE_LINE
})
}
}
}
} Ok(()) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
s.emit_struct_field("multibyte_chars", 4, |s| {
(*self.multibyte_chars.borrow()).encode(s)
}) })
}
}
impl Decodable for FileMap {
fn decode<D: Decoder>(d: &mut D) -> Result<FileMap, D::Error> {
d.read_struct("FileMap", 5, |d| {
let name: String =
match d.read_struct_field("name", 0,
|d|
Decodable::decode(d))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let start_pos: BytePos =
match d.read_struct_field("start_pos", 1,
|d|
Decodable::decode(d))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let end_pos: BytePos =
match d.read_struct_field("end_pos", 2,
|d|
Decodable::decode(d))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lines: Vec<BytePos> =
match d.read_struct_field("lines", 3, |d| {
let num_lines: u32 =
match Decodable::decode(d)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut lines =
Vec::with_capacity(num_lines
as
usize);
if num_lines > 0 {
let bytes_per_diff:
u8 =
match Decodable::decode(d)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut line_start:
BytePos =
match Decodable::decode(d)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
lines.push(line_start);
for _ in
1..num_lines {
let diff =
match bytes_per_diff
{
1 =>
(match d.read_u8()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}) as
u32,
2 =>
(match d.read_u16()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}) as
u32,
4 =>
match d.read_u32()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/codemap.rs",
450u32);
&_FILE_LINE
})
}
}
};
line_start =
line_start
+
BytePos(diff);
lines.push(line_start);
}
} Ok(lines) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let multibyte_chars: Vec<MultiByteChar> =
match d.read_struct_field("multibyte_chars", 4,
|d|
Decodable::decode(d))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(FileMap{name: name,
start_pos: start_pos,
end_pos: end_pos,
src: None,
lines: RefCell::new(lines),
multibyte_chars:
RefCell::new(multibyte_chars),}) })
}
}
impl fmt::Debug for FileMap {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["FileMap(",
")"];
__STATIC_FMTSTR
},
&match (&self.name,) {
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
}
impl FileMap {
/// EFFECT: register a start-of-line offset in the
/// table of line-beginnings.
/// UNCHECKED INVARIANT: these offsets must be added in the right
/// order and must be in the right places; there is shared knowledge
/// about what ends a line between this file and parse.rs
/// WARNING: pos param here is the offset relative to start of CodeMap,
/// and CodeMap will append a newline when adding a filemap without a newline at the end,
/// so the safe way to call this is with value calculated as
/// filemap.start_pos + newline_offset_relative_to_the_start_of_filemap.
pub fn next_line(&self, pos: BytePos) {
let mut lines = self.lines.borrow_mut();
let line_len = lines.len();
if !(line_len == 0 || ((*lines)[line_len - 1] < pos)) {
{
::std::rt::begin_unwind("assertion failed: line_len == 0 || ((*lines)[line_len - 1] < pos)",
{
static _FILE_LINE:
(&'static str, u32) =
("src/codemap.rs",
515u32);
&_FILE_LINE
})
}
};
lines.push(pos);
}
/// get a line from the list of pre-computed line-beginnings.
/// line-number here is 0-based.
pub fn get_line(&self, line_number: usize) -> Option<&str> {
match self.src {
Some(ref src) => {
let lines = self.lines.borrow();
lines.get(line_number).map(|&line| {
let begin: BytePos =
line - self.start_pos;
let begin = begin.to_usize();
let slice = &src[begin..];
match slice.find('\n') {
Some(e) => &slice[..e],
None => slice,
} })
}
None => None,
}
}
pub fn record_multibyte_char(&self, pos: BytePos, bytes: usize) {
if !(bytes >= 2 && bytes <= 4) {
{
::std::rt::begin_unwind("assertion failed: bytes >= 2 && bytes <= 4",
{
static _FILE_LINE:
(&'static str, u32) =
("src/codemap.rs",
543u32);
&_FILE_LINE
})
}
};
let mbc = MultiByteChar{pos: pos, bytes: bytes,};
self.multibyte_chars.borrow_mut().push(mbc);
}
pub fn is_real_file(&self) -> bool {
!(self.name.starts_with("<") && self.name.ends_with(">"))
}
pub fn is_imported(&self) -> bool { self.src.is_none() }
fn count_lines(&self) -> usize { self.lines.borrow().len() }
}
/// An abstraction over the fs operations used by the Parser.
pub trait FileLoader {
/// Query the existence of a file.
fn file_exists(&self, path: &Path)
-> bool;
/// Read the contents of an UTF-8 file into memory.
fn read_file(&self, path: &Path)
-> io::Result<String>;
}
/// A FileLoader that uses std::fs to load real files.
pub struct RealFileLoader;
impl FileLoader for RealFileLoader {
fn file_exists(&self, path: &Path) -> bool {
fs::metadata(path).is_ok()
}
fn read_file(&self, path: &Path) -> io::Result<String> {
let mut src = String::new();
match match fs::File::open(path) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.read_to_string(&mut src) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(src)
}
}
pub struct CodeMap {
pub files: RefCell<Vec<Rc<FileMap>>>,
expansions: RefCell<Vec<ExpnInfo>>,
file_loader: Box<FileLoader>,
}
impl CodeMap {
pub fn new() -> CodeMap {
CodeMap{files: RefCell::new(Vec::new()),
expansions: RefCell::new(Vec::new()),
file_loader: Box::new(RealFileLoader),}
}
pub fn with_file_loader(file_loader: Box<FileLoader>) -> CodeMap {
CodeMap{files: RefCell::new(Vec::new()),
expansions: RefCell::new(Vec::new()),
file_loader: file_loader,}
}
pub fn file_exists(&self, path: &Path) -> bool {
self.file_loader.file_exists(path)
}
pub fn load_file(&self, path: &Path) -> io::Result<Rc<FileMap>> {
let src =
match self.file_loader.read_file(path) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(self.new_filemap(path.to_str().unwrap().to_string(), src))
}
fn next_start_pos(&self) -> usize {
let files = self.files.borrow();
match files.last() {
None => 0,
Some(last) => last.end_pos.to_usize() + 1,
}
}
/// Creates a new filemap without setting its line information. If you don't
/// intend to set the line information yourself, you should use new_filemap_and_lines.
pub fn new_filemap(&self, filename: FileName, mut src: String)
-> Rc<FileMap> {
let start_pos = self.next_start_pos();
let mut files = self.files.borrow_mut();
src =
if src.starts_with("\u{feff}") {
String::from(&src[3..])
} else { String::from(&src[..]) };
let end_pos = start_pos + src.len();
let filemap =
Rc::new(FileMap{name: filename,
src: Some(Rc::new(src)),
start_pos: Pos::from_usize(start_pos),
end_pos: Pos::from_usize(end_pos),
lines: RefCell::new(Vec::new()),
multibyte_chars: RefCell::new(Vec::new()),});
files.push(filemap.clone());
filemap
}
/// Creates a new filemap and sets its line information.
pub fn new_filemap_and_lines(&self, filename: &str, src: &str)
-> Rc<FileMap> {
let fm = self.new_filemap(filename.to_string(), src.to_owned());
let mut byte_pos: u32 = 0;
for line in src.lines() {
fm.next_line(BytePos(byte_pos));
byte_pos += (line.len() as u32) + 1;
}
fm
}
/// Allocates a new FileMap representing a source file from an external
/// crate. The source code of such an "imported filemap" is not available,
/// but we still know enough to generate accurate debuginfo location
/// information for things inlined from other crates.
pub fn new_imported_filemap(&self, filename: FileName,
source_len: usize,
mut file_local_lines: Vec<BytePos>,
mut file_local_multibyte_chars:
Vec<MultiByteChar>) -> Rc<FileMap> {
let start_pos = self.next_start_pos();
let mut files = self.files.borrow_mut();
let end_pos = Pos::from_usize(start_pos + source_len);
let start_pos = Pos::from_usize(start_pos);
for pos in &mut file_local_lines { *pos = *pos + start_pos; }
for mbc in &mut file_local_multibyte_chars {
mbc.pos = mbc.pos + start_pos;
}
let filemap =
Rc::new(FileMap{name: filename,
src: None,
start_pos: start_pos,
end_pos: end_pos,
lines: RefCell::new(file_local_lines),
multibyte_chars:
RefCell::new(file_local_multibyte_chars),});
files.push(filemap.clone());
filemap
}
pub fn mk_substr_filename(&self, sp: Span) -> String {
let pos = self.lookup_char_pos(sp.lo);
(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["<",
":",
":",
">"];
__STATIC_FMTSTR
},
&match (&pos.file.name,
&pos.line,
&(pos.col.to_usize()
+
1))
{
(__arg0,
__arg1,
__arg2) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))).to_string()
}
/// Lookup source information about a BytePos
pub fn lookup_char_pos(&self, pos: BytePos) -> Loc {
let chpos = self.bytepos_to_file_charpos(pos);
match self.lookup_line(pos) {
Ok(FileMapAndLine { fm: f, line: a }) => {
let line = a + 1;
let linebpos = (*f.lines.borrow())[a];
let linechpos = self.bytepos_to_file_charpos(linebpos);
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 735u32,
__file: "src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::codemap", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["byte pos ",
" is on the line at byte pos "];
__STATIC_FMTSTR
},
&match (&pos,
&linebpos)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 737u32,
__file: "src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::codemap", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["char pos ",
" is on the line at char pos "];
__STATIC_FMTSTR
},
&match (&chpos,
&linechpos)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 739u32,
__file: "src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::codemap", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["byte is on line: "];
__STATIC_FMTSTR
},
&match (&line,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
if !(chpos >= linechpos) {
{
::std::rt::begin_unwind("assertion failed: chpos >= linechpos",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/codemap.rs",
740u32);
&_FILE_LINE
})
}
};
Loc{file: f, line: line, col: chpos - linechpos,}
}
Err(f) => { Loc{file: f, line: 0, col: chpos,} }
}
}
fn lookup_line(&self, pos: BytePos)
-> Result<FileMapAndLine, Rc<FileMap>> {
let idx = self.lookup_filemap_idx(pos);
let files = self.files.borrow();
let f = (*files)[idx].clone();
let len = f.lines.borrow().len();
if len == 0 { return Err(f); }
let mut a = 0;
{
let lines = f.lines.borrow();
let mut b = lines.len();
while b - a > 1 {
let m = (a + b) / 2;
if (*lines)[m] > pos { b = m; } else { a = m; }
}
if !(a <= lines.len()) {
{
::std::rt::begin_unwind("assertion failed: a <= lines.len()",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/codemap.rs",
781u32);
&_FILE_LINE
})
}
};
}
Ok(FileMapAndLine{fm: f, line: a,})
}
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
let loc = self.lookup_char_pos(pos);
LocWithOpt{filename: loc.file.name.to_string(),
line: loc.line,
col: loc.col,
file: Some(loc.file),}
}
pub fn span_to_string(&self, sp: Span) -> String {
if self.files.borrow().is_empty() && sp == DUMMY_SP {
return "no-location".to_string();
}
let lo = self.lookup_char_pos_adj(sp.lo);
let hi = self.lookup_char_pos_adj(sp.hi);
return (::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
":",
":",
": ",
":"];
__STATIC_FMTSTR
},
&match (&lo.filename,
&lo.line,
&(lo.col.to_usize()
+
1),
&hi.line,
&(hi.col.to_usize()
+
1))
{
(__arg0,
__arg1,
__arg2,
__arg3,
__arg4)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg4,
::std::fmt::Display::fmt)],
}))).to_string()
}
fn match_callees(&self, sp_a: &Span, sp_b: &Span) -> bool {
let fmt_a =
self.with_expn_info(sp_a.expn_id,
|ei|
ei.map(|ei|
ei.callee.format.clone()));
let fmt_b =
self.with_expn_info(sp_b.expn_id,
|ei|
ei.map(|ei|
ei.callee.format.clone()));
fmt_a == fmt_b
}
/// Returns a formatted string showing the expansion chain of a span
///
/// Spans are printed in the following format:
///
/// filename:start_line:col: end_line:col
/// snippet
/// Callee:
/// Callee span
/// Callsite:
/// Callsite span
///
/// Callees and callsites are printed recursively (if available, otherwise header
/// and span is omitted), expanding into their own callee/callsite spans.
/// Each layer of recursion has an increased indent, and snippets are truncated
/// to at most 50 characters. Finally, recursive calls to the same macro are squashed,
/// with '...' used to represent any number of recursive calls.
pub fn span_to_expanded_string(&self, sp: Span) -> String {
self.span_to_expanded_string_internal(sp, "")
}
fn span_to_expanded_string_internal(&self, sp: Span, indent: &str)
-> String {
let mut indent = indent.to_owned();
let mut output = "".to_owned();
let span_str = self.span_to_string(sp);
let mut span_snip =
self.span_to_snippet(sp).unwrap_or("Snippet unavailable".to_owned());
if span_snip.len() > 50 {
span_snip.truncate(50);
span_snip.push_str("...");
}
output.push_str(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"",
"\n",
"`",
"`\n"];
__STATIC_FMTSTR
},
&match (&indent,
&span_str,
&indent,
&span_snip)
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt)],
})));
if sp.expn_id == NO_EXPANSION || sp.expn_id == COMMAND_LINE_EXPN {
return output;
}
let mut callee =
self.with_expn_info(sp.expn_id,
|ei|
ei.and_then(|ei|
ei.callee.span.clone()));
let mut callsite =
self.with_expn_info(sp.expn_id,
|ei| ei.map(|ei| ei.call_site.clone()));
indent.push_str(" ");
let mut is_recursive = false;
while callee.is_some() &&
self.match_callees(&sp, &callee.unwrap()) {
callee =
self.with_expn_info(callee.unwrap().expn_id,
|ei|
ei.and_then(|ei|
ei.callee.span.clone()));
is_recursive = true;
}
if let Some(span) = callee {
output.push_str(&indent);
output.push_str("Callee:\n");
if is_recursive {
output.push_str(&indent);
output.push_str("...\n");
}
output.push_str(&(self.span_to_expanded_string_internal(span,
&indent)));
}
is_recursive = false;
while callsite.is_some() &&
self.match_callees(&sp, &callsite.unwrap()) {
callsite =
self.with_expn_info(callsite.unwrap().expn_id,
|ei|
ei.map(|ei|
ei.call_site.clone()));
is_recursive = true;
}
if let Some(span) = callsite {
output.push_str(&indent);
output.push_str("Callsite:\n");
if is_recursive {
output.push_str(&indent);
output.push_str("...\n");
}
output.push_str(&(self.span_to_expanded_string_internal(span,
&indent)));
}
output
}
pub fn span_to_filename(&self, sp: Span) -> FileName {
self.lookup_char_pos(sp.lo).file.name.to_string()
}
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
if sp.lo > sp.hi {
return Err(SpanLinesError::IllFormedSpan(sp));
}
let lo = self.lookup_char_pos(sp.lo);
let hi = self.lookup_char_pos(sp.hi);
if lo.file.start_pos != hi.file.start_pos {
return Err(SpanLinesError::DistinctSources(DistinctSources{begin:
(lo.file.name.clone(),
lo.file.start_pos),
end:
(hi.file.name.clone(),
hi.file.start_pos),}));
}
if !(hi.line >= lo.line) {
{
::std::rt::begin_unwind("assertion failed: hi.line >= lo.line",
{
static _FILE_LINE:
(&'static str, u32) =
("src/codemap.rs",
919u32);
&_FILE_LINE
})
}
};
let mut lines = Vec::with_capacity(hi.line - lo.line + 1);
let mut start_col = lo.col;
for line_index in lo.line - 1..hi.line - 1 {
let line_len =
lo.file.get_line(line_index).map(|s|
s.len()).unwrap_or(0);
lines.push(LineInfo{line_index: line_index,
start_col: start_col,
end_col: CharPos::from_usize(line_len),});
start_col = CharPos::from_usize(0);
}
lines.push(LineInfo{line_index: hi.line - 1,
start_col: start_col,
end_col: hi.col,});
Ok(FileLines{file: lo.file, lines: lines,})
}
pub fn span_to_snippet(&self, sp: Span)
-> Result<String, SpanSnippetError> {
if sp.lo > sp.hi {
return Err(SpanSnippetError::IllFormedSpan(sp));
}
let local_begin = self.lookup_byte_offset(sp.lo);
let local_end = self.lookup_byte_offset(sp.hi);
if local_begin.fm.start_pos != local_end.fm.start_pos {
return Err(SpanSnippetError::DistinctSources(DistinctSources{begin:
(local_begin.fm.name.clone(),
local_begin.fm.start_pos),
end:
(local_end.fm.name.clone(),
local_end.fm.start_pos),}));
} else {
match local_begin.fm.src {
Some(ref src) => {
let start_index = local_begin.pos.to_usize();
let end_index = local_end.pos.to_usize();
let source_len =
(local_begin.fm.end_pos -
local_begin.fm.start_pos).to_usize();
if start_index > end_index || end_index > source_len {
return Err(SpanSnippetError::MalformedForCodemap(MalformedCodemapPositions{name:
local_begin.fm.name.clone(),
source_len:
source_len,
begin_pos:
local_begin.pos,
end_pos:
local_end.pos,}));
}
return Ok((&src[start_index..end_index]).to_string())
}
None => {
return Err(SpanSnippetError::SourceNotAvailable{filename:
local_begin.fm.name.clone(),});
}
}
}
}
pub fn get_filemap(&self, filename: &str) -> Rc<FileMap> {
for fm in self.files.borrow().iter() {
if filename == fm.name { return fm.clone(); }
}
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["asking for ",
" which we don\'t know about"];
__STATIC_FMTSTR
},
&match (&filename,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str, u32) =
("src/codemap.rs",
997u32);
&_FILE_LINE
})
};
}
/// For a global BytePos compute the local offset within the containing FileMap
pub fn lookup_byte_offset(&self, bpos: BytePos) -> FileMapAndBytePos {
let idx = self.lookup_filemap_idx(bpos);
let fm = (*self.files.borrow())[idx].clone();
let offset = bpos - fm.start_pos;
FileMapAndBytePos{fm: fm, pos: offset,}
}
/// Converts an absolute BytePos to a CharPos relative to the filemap.
pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
let idx = self.lookup_filemap_idx(bpos);
let files = self.files.borrow();
let map = &(*files)[idx];
let mut total_extra_bytes = 0;
for mbc in map.multibyte_chars.borrow().iter() {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1018u32,
__file: "src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::codemap", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"-byte char at "];
__STATIC_FMTSTR
},
&match (&mbc.bytes,
&mbc.pos)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
if mbc.pos < bpos {
total_extra_bytes += mbc.bytes - 1;
if !(bpos.to_usize() >= mbc.pos.to_usize() + mbc.bytes) {
{
::std::rt::begin_unwind("assertion failed: bpos.to_usize() >= mbc.pos.to_usize() + mbc.bytes",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/codemap.rs",
1025u32);
&_FILE_LINE
})
}
};
} else { break ; }
}
if !(map.start_pos.to_usize() + total_extra_bytes <=
bpos.to_usize()) {
{
::std::rt::begin_unwind("assertion failed: map.start_pos.to_usize() + total_extra_bytes <= bpos.to_usize()",
{
static _FILE_LINE:
(&'static str, u32) =
("src/codemap.rs",
1031u32);
&_FILE_LINE
})
}
};
CharPos(bpos.to_usize() - map.start_pos.to_usize() -
total_extra_bytes)
}
fn lookup_filemap_idx(&self, pos: BytePos) -> usize {
let files = self.files.borrow();
let files = &*files;
let count = files.len();
let mut a = 0;
let mut b = count;
while b - a > 1 {
let m = (a + b) / 2;
if files[m].start_pos > pos { b = m; } else { a = m; }
}
if !(a < count) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["position ",
" does not resolve to a source location"];
__STATIC_FMTSTR
},
&match (&pos.to_usize(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/codemap.rs",
1053u32);
&_FILE_LINE
})
}
};
return a;
}
pub fn record_expansion(&self, expn_info: ExpnInfo) -> ExpnId {
let mut expansions = self.expansions.borrow_mut();
expansions.push(expn_info);
let len = expansions.len();
if len > (u32::max_value() as usize) {
{
::std::rt::begin_unwind("too many ExpnInfo\'s!",
{
static _FILE_LINE:
(&'static str, u32) =
("src/codemap.rs",
1063u32);
&_FILE_LINE
})
};
}
ExpnId((len as u32) - 1)
}
pub fn with_expn_info<T, F>(&self, id: ExpnId, f: F) -> T where
F: FnOnce(Option<&ExpnInfo>) -> T {
match id {
NO_EXPANSION | COMMAND_LINE_EXPN => f(None),
ExpnId(i) =>
f(Some(&(*self.expansions.borrow())[i as usize])),
}
}
/// Check if a span is "internal" to a macro in which #[unstable]
/// items can be used (that is, a macro marked with
/// `#[allow_internal_unstable]`).
pub fn span_allows_unstable(&self, span: Span) -> bool {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1081u32,
__file: "src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::codemap", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["span_allows_unstable(span = ",
")"];
__STATIC_FMTSTR
},
&match (&span,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
let mut allows_unstable = false;
let mut expn_id = span.expn_id;
loop {
let quit =
self.with_expn_info(expn_id, |expninfo| {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line:
1086u32,
__file:
"src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <=
::log::__static_max_level()
&&
lvl <=
::log::max_log_level()
{
::log::__log(lvl,
"syntex_syntax::codemap",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["span_allows_unstable: expninfo = "];
__STATIC_FMTSTR
},
&match (&expninfo,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
expninfo.map_or(true, |info| {
let span_comes_from_this_expansion =
info.callee.span.map_or(span
==
info.call_site,
|mac_span|
{
mac_span.contains(span)
});
{
static _LOC:
::log::LogLocation
=
::log::LogLocation{__line:
1094u32,
__file:
"src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl =
::log::LogLevel::Debug;
if lvl <=
::log::__static_max_level()
&&
lvl <=
::log::max_log_level()
{
::log::__log(lvl,
"syntex_syntax::codemap",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["span_allows_unstable: span: ",
" call_site: ",
" callee: "];
__STATIC_FMTSTR
},
&match (&(span.lo,
span.hi),
&(info.call_site.lo,
info.call_site.hi),
&info.callee.span.map(|x|
(x.lo,
x.hi)))
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Debug::fmt)],
}))
}
};
{
static _LOC:
::log::LogLocation
=
::log::LogLocation{__line:
1098u32,
__file:
"src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl =
::log::LogLevel::Debug;
if lvl <=
::log::__static_max_level()
&&
lvl <=
::log::max_log_level()
{
::log::__log(lvl,
"syntex_syntax::codemap",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["span_allows_unstable: from this expansion? ",
", allows unstable? "];
__STATIC_FMTSTR
},
&match (&span_comes_from_this_expansion,
&info.callee.allow_internal_unstable)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
if span_comes_from_this_expansion
{
allows_unstable =
info.callee.allow_internal_unstable;
true
} else {
expn_id =
info.call_site.expn_id;
false
} }) });
if quit { break }
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1116u32,
__file: "src/codemap.rs",
__module_path:
"syntex_syntax::codemap",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::codemap", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["span_allows_unstable? "];
__STATIC_FMTSTR
},
&match (&allows_unstable,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
allows_unstable
}
pub fn count_lines(&self) -> usize {
self.files.borrow().iter().fold(0, |a, f| a + f.count_lines())
}
}
pub type FileLinesResult = Result<FileLines, SpanLinesError>;
pub enum SpanLinesError {
IllFormedSpan(Span),
DistinctSources(DistinctSources),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for SpanLinesError {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&SpanLinesError::IllFormedSpan(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("IllFormedSpan");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&SpanLinesError::DistinctSources(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("DistinctSources");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for SpanLinesError {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&SpanLinesError::IllFormedSpan(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&SpanLinesError::DistinctSources(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for SpanLinesError {
#[inline]
fn eq(&self, __arg_0: &SpanLinesError) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&SpanLinesError::IllFormedSpan(ref __self_0),
&SpanLinesError::IllFormedSpan(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&SpanLinesError::DistinctSources(ref __self_0),
&SpanLinesError::DistinctSources(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &SpanLinesError) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&SpanLinesError::IllFormedSpan(ref __self_0),
&SpanLinesError::IllFormedSpan(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&SpanLinesError::DistinctSources(ref __self_0),
&SpanLinesError::DistinctSources(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for SpanLinesError {
#[inline]
fn clone(&self) -> SpanLinesError {
match (&*self,) {
(&SpanLinesError::IllFormedSpan(ref __self_0),) =>
SpanLinesError::IllFormedSpan(::std::clone::Clone::clone(&(*__self_0))),
(&SpanLinesError::DistinctSources(ref __self_0),) =>
SpanLinesError::DistinctSources(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
pub enum SpanSnippetError {
IllFormedSpan(Span),
DistinctSources(DistinctSources),
MalformedForCodemap(MalformedCodemapPositions),
SourceNotAvailable {
filename: String,
},
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for SpanSnippetError {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&SpanSnippetError::IllFormedSpan(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("IllFormedSpan");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&SpanSnippetError::DistinctSources(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("DistinctSources");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&SpanSnippetError::MalformedForCodemap(ref __self_0),) => {
let mut builder =
__arg_0.debug_tuple("MalformedForCodemap");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&SpanSnippetError::SourceNotAvailable {
filename: ref __self_0 },) => {
let mut builder =
__arg_0.debug_struct("SourceNotAvailable");
let _ = builder.field("filename", &&(*__self_0));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for SpanSnippetError {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&SpanSnippetError::IllFormedSpan(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&SpanSnippetError::DistinctSources(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&SpanSnippetError::MalformedForCodemap(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&SpanSnippetError::SourceNotAvailable {
filename: ref __self_0 },) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for SpanSnippetError {
#[inline]
fn eq(&self, __arg_0: &SpanSnippetError) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&SpanSnippetError::IllFormedSpan(ref __self_0),
&SpanSnippetError::IllFormedSpan(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&SpanSnippetError::DistinctSources(ref __self_0),
&SpanSnippetError::DistinctSources(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&SpanSnippetError::MalformedForCodemap(ref __self_0),
&SpanSnippetError::MalformedForCodemap(ref __arg_1_0))
=> true && (*__self_0) == (*__arg_1_0),
(&SpanSnippetError::SourceNotAvailable {
filename: ref __self_0 },
&SpanSnippetError::SourceNotAvailable {
filename: ref __arg_1_0 }) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &SpanSnippetError) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&SpanSnippetError::IllFormedSpan(ref __self_0),
&SpanSnippetError::IllFormedSpan(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&SpanSnippetError::DistinctSources(ref __self_0),
&SpanSnippetError::DistinctSources(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&SpanSnippetError::MalformedForCodemap(ref __self_0),
&SpanSnippetError::MalformedForCodemap(ref __arg_1_0))
=> false || (*__self_0) != (*__arg_1_0),
(&SpanSnippetError::SourceNotAvailable {
filename: ref __self_0 },
&SpanSnippetError::SourceNotAvailable {
filename: ref __arg_1_0 }) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for SpanSnippetError {
#[inline]
fn clone(&self) -> SpanSnippetError {
match (&*self,) {
(&SpanSnippetError::IllFormedSpan(ref __self_0),) =>
SpanSnippetError::IllFormedSpan(::std::clone::Clone::clone(&(*__self_0))),
(&SpanSnippetError::DistinctSources(ref __self_0),) =>
SpanSnippetError::DistinctSources(::std::clone::Clone::clone(&(*__self_0))),
(&SpanSnippetError::MalformedForCodemap(ref __self_0),) =>
SpanSnippetError::MalformedForCodemap(::std::clone::Clone::clone(&(*__self_0))),
(&SpanSnippetError::SourceNotAvailable {
filename: ref __self_0 },) =>
SpanSnippetError::SourceNotAvailable{filename:
::std::clone::Clone::clone(&(*__self_0)),},
}
}
}
pub struct DistinctSources {
begin: (String, BytePos),
end: (String, BytePos),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for DistinctSources {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
DistinctSources { begin: ref __self_0_0, end: ref __self_0_1 }
=> {
let mut builder = __arg_0.debug_struct("DistinctSources");
let _ = builder.field("begin", &&(*__self_0_0));
let _ = builder.field("end", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for DistinctSources {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
DistinctSources { begin: ref __self_0_0, end: ref __self_0_1 }
=> {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for DistinctSources {
#[inline]
fn eq(&self, __arg_0: &DistinctSources) -> bool {
match *__arg_0 {
DistinctSources { begin: ref __self_1_0, end: ref __self_1_1 }
=>
match *self {
DistinctSources {
begin: ref __self_0_0, end: ref __self_0_1 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &DistinctSources) -> bool {
match *__arg_0 {
DistinctSources { begin: ref __self_1_0, end: ref __self_1_1 }
=>
match *self {
DistinctSources {
begin: ref __self_0_0, end: ref __self_0_1 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for DistinctSources {
#[inline]
fn clone(&self) -> DistinctSources {
match *self {
DistinctSources { begin: ref __self_0_0, end: ref __self_0_1 }
=>
DistinctSources{begin:
::std::clone::Clone::clone(&(*__self_0_0)),
end:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct MalformedCodemapPositions {
name: String,
source_len: usize,
begin_pos: BytePos,
end_pos: BytePos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for MalformedCodemapPositions {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
MalformedCodemapPositions {
name: ref __self_0_0,
source_len: ref __self_0_1,
begin_pos: ref __self_0_2,
end_pos: ref __self_0_3 } => {
let mut builder =
__arg_0.debug_struct("MalformedCodemapPositions");
let _ = builder.field("name", &&(*__self_0_0));
let _ = builder.field("source_len", &&(*__self_0_1));
let _ = builder.field("begin_pos", &&(*__self_0_2));
let _ = builder.field("end_pos", &&(*__self_0_3));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for MalformedCodemapPositions {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
MalformedCodemapPositions {
name: ref __self_0_0,
source_len: ref __self_0_1,
begin_pos: ref __self_0_2,
end_pos: ref __self_0_3 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
(*__self_0_2).assert_receiver_is_total_eq();
(*__self_0_3).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for MalformedCodemapPositions {
#[inline]
fn eq(&self, __arg_0: &MalformedCodemapPositions) -> bool {
match *__arg_0 {
MalformedCodemapPositions {
name: ref __self_1_0,
source_len: ref __self_1_1,
begin_pos: ref __self_1_2,
end_pos: ref __self_1_3 } =>
match *self {
MalformedCodemapPositions {
name: ref __self_0_0,
source_len: ref __self_0_1,
begin_pos: ref __self_0_2,
end_pos: ref __self_0_3 } =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1) &&
(*__self_0_2) == (*__self_1_2) &&
(*__self_0_3) == (*__self_1_3),
},
}
}
#[inline]
fn ne(&self, __arg_0: &MalformedCodemapPositions) -> bool {
match *__arg_0 {
MalformedCodemapPositions {
name: ref __self_1_0,
source_len: ref __self_1_1,
begin_pos: ref __self_1_2,
end_pos: ref __self_1_3 } =>
match *self {
MalformedCodemapPositions {
name: ref __self_0_0,
source_len: ref __self_0_1,
begin_pos: ref __self_0_2,
end_pos: ref __self_0_3 } =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1) ||
(*__self_0_2) != (*__self_1_2) ||
(*__self_0_3) != (*__self_1_3),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MalformedCodemapPositions {
#[inline]
fn clone(&self) -> MalformedCodemapPositions {
match *self {
MalformedCodemapPositions {
name: ref __self_0_0,
source_len: ref __self_0_1,
begin_pos: ref __self_0_2,
end_pos: ref __self_0_3 } =>
MalformedCodemapPositions{name:
::std::clone::Clone::clone(&(*__self_0_0)),
source_len:
::std::clone::Clone::clone(&(*__self_0_1)),
begin_pos:
::std::clone::Clone::clone(&(*__self_0_2)),
end_pos:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
}
pub mod config {
#[prelude_import]
use std::prelude::v1::*;
use attr::AttrMetaMethods;
use errors::Handler;
use feature_gate::GatedCfgAttr;
use fold::Folder;
use {ast, fold, attr};
use visit;
use codemap::{Spanned, respan};
use ptr::P;
use util::small_vector::SmallVector;
/// A folder that strips out items that do not belong in the current
/// configuration.
struct Context<'a, F> where F: FnMut(&[ast::Attribute]) -> bool {
in_cfg: F,
diagnostic: &'a Handler,
}
pub fn strip_unconfigured_items(diagnostic: &Handler, krate: ast::Crate,
feature_gated_cfgs:
&mut Vec<GatedCfgAttr>)
-> ast::Crate {
check_for_gated_stmt_expr_attributes(&krate, feature_gated_cfgs);
let krate = process_cfg_attr(diagnostic, krate, feature_gated_cfgs);
let config = krate.config.clone();
strip_items(diagnostic, krate, |attrs| {
let mut diag =
CfgDiagReal{diag: diagnostic,
feature_gated_cfgs: feature_gated_cfgs,};
in_cfg(&config, attrs, &mut diag) })
}
impl <'a, F> fold::Folder for Context<'a, F> where
F: FnMut(&[ast::Attribute]) -> bool {
fn fold_foreign_mod(&mut self, foreign_mod: ast::ForeignMod)
-> ast::ForeignMod {
fold_foreign_mod(self, foreign_mod)
}
fn fold_item_underscore(&mut self, item: ast::Item_) -> ast::Item_ {
fold_item_underscore(self, item)
}
fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(a)) {
self.diagnostic.span_err(attr.span,
"removing an expression is not supported in this position");
}
fold_expr(self, expr)
}
fn fold_opt_expr(&mut self, expr: P<ast::Expr>)
-> Option<P<ast::Expr>> {
fold_opt_expr(self, expr)
}
fn fold_stmt(&mut self, stmt: P<ast::Stmt>)
-> SmallVector<P<ast::Stmt>> {
fold_stmt(self, stmt)
}
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self)
}
fn fold_item(&mut self, item: P<ast::Item>)
-> SmallVector<P<ast::Item>> {
fold_item(self, item)
}
}
pub fn strip_items<'a,
F>(diagnostic: &'a Handler, krate: ast::Crate,
in_cfg: F) -> ast::Crate where
F: FnMut(&[ast::Attribute]) -> bool {
let mut ctxt = Context{in_cfg: in_cfg, diagnostic: diagnostic,};
ctxt.fold_crate(krate)
}
fn filter_foreign_item<F>(cx: &mut Context<F>, item: P<ast::ForeignItem>)
-> Option<P<ast::ForeignItem>> where F: FnMut(&[ast::Attribute]) ->
bool {
if foreign_item_in_cfg(cx, &item) { Some(item) } else { None }
}
fn fold_foreign_mod<F>(cx: &mut Context<F>,
ast::ForeignMod { abi, items }: ast::ForeignMod)
-> ast::ForeignMod where F: FnMut(&[ast::Attribute]) -> bool {
ast::ForeignMod{abi: abi,
items:
items.into_iter().filter_map(|a|
filter_foreign_item(cx,
a)).collect(),}
}
fn fold_item<F>(cx: &mut Context<F>, item: P<ast::Item>)
-> SmallVector<P<ast::Item>> where F: FnMut(&[ast::Attribute]) -> bool {
if item_in_cfg(cx, &item) {
SmallVector::one(item.map(|i| cx.fold_item_simple(i)))
} else { SmallVector::zero() }
}
fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_)
-> ast::Item_ where F: FnMut(&[ast::Attribute]) -> bool {
let item =
match item {
ast::ItemImpl(u, o, a, b, c, impl_items) => {
let impl_items =
impl_items.into_iter().filter(|ii|
(cx.in_cfg)(&ii.attrs)).collect();
ast::ItemImpl(u, o, a, b, c, impl_items)
}
ast::ItemTrait(u, a, b, methods) => {
let methods =
methods.into_iter().filter(|ti|
(cx.in_cfg)(&ti.attrs)).collect();
ast::ItemTrait(u, a, b, methods)
}
ast::ItemStruct(def, generics) => {
ast::ItemStruct(fold_struct(cx, def), generics)
}
ast::ItemEnum(def, generics) => {
let variants =
def.variants.into_iter().filter_map(|v| {
if !(cx.in_cfg)(&v.node.attrs)
{
None
} else {
Some(v.map(|Spanned {
node: ast::Variant_ {
name,
attrs,
data,
disr_expr
},
span
}|
{
Spanned{node:
ast::Variant_{name:
name,
attrs:
attrs,
data:
fold_struct(cx,
data),
disr_expr:
disr_expr,},
span:
span,}
}))
} });
ast::ItemEnum(ast::EnumDef{variants: variants.collect(),},
generics)
}
item => item,
};
fold::noop_fold_item_underscore(item, cx)
}
fn fold_struct<F>(cx: &mut Context<F>, vdata: ast::VariantData)
-> ast::VariantData where F: FnMut(&[ast::Attribute]) -> bool {
match vdata {
ast::VariantData::Struct(fields, id) => {
ast::VariantData::Struct(fields.into_iter().filter(|m| {
(cx.in_cfg)(&m.node.attrs)
}).collect(),
id)
}
ast::VariantData::Tuple(fields, id) => {
ast::VariantData::Tuple(fields.into_iter().filter(|m| {
(cx.in_cfg)(&m.node.attrs)
}).collect(),
id)
}
ast::VariantData::Unit(id) => ast::VariantData::Unit(id),
}
}
fn fold_opt_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>)
-> Option<P<ast::Expr>> where F: FnMut(&[ast::Attribute]) -> bool {
if expr_in_cfg(cx, &expr) { Some(fold_expr(cx, expr)) } else { None }
}
fn fold_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>) -> P<ast::Expr>
where F: FnMut(&[ast::Attribute]) -> bool {
expr.map(|ast::Expr { id, span, node, attrs }| {
fold::noop_fold_expr(ast::Expr{id: id,
node:
match node {
ast::ExprMatch(m,
arms)
=> {
ast::ExprMatch(m,
arms.into_iter().filter(|a|
(cx.in_cfg)(&a.attrs)).collect())
}
_ => node,
},
span: span,
attrs: attrs,}, cx) })
}
fn fold_stmt<F>(cx: &mut Context<F>, stmt: P<ast::Stmt>)
-> SmallVector<P<ast::Stmt>> where F: FnMut(&[ast::Attribute]) -> bool {
if stmt_in_cfg(cx, &stmt) {
stmt.and_then(|s| fold::noop_fold_stmt(s, cx))
} else { SmallVector::zero() }
}
fn stmt_in_cfg<F>(cx: &mut Context<F>, stmt: &ast::Stmt) -> bool where
F: FnMut(&[ast::Attribute]) -> bool {
(cx.in_cfg)(stmt.node.attrs())
}
fn expr_in_cfg<F>(cx: &mut Context<F>, expr: &ast::Expr) -> bool where
F: FnMut(&[ast::Attribute]) -> bool {
(cx.in_cfg)(expr.attrs())
}
fn item_in_cfg<F>(cx: &mut Context<F>, item: &ast::Item) -> bool where
F: FnMut(&[ast::Attribute]) -> bool {
return (cx.in_cfg)(&item.attrs);
}
fn foreign_item_in_cfg<F>(cx: &mut Context<F>, item: &ast::ForeignItem)
-> bool where F: FnMut(&[ast::Attribute]) -> bool {
return (cx.in_cfg)(&item.attrs);
}
fn is_cfg(attr: &ast::Attribute) -> bool { attr.check_name("cfg") }
fn in_cfg<T: CfgDiag>(cfg: &[P<ast::MetaItem>], attrs: &[ast::Attribute],
diag: &mut T) -> bool {
attrs.iter().all(|attr| {
let mis =
match attr.node.value.node {
ast::MetaList(_, ref mis) if is_cfg(&attr) =>
mis,
_ => return true,
};
if mis.len() != 1 {
diag.emit_error(|diagnostic| {
diagnostic.span_err(attr.span,
"expected 1 cfg-pattern");
});
return true;
} attr::cfg_matches(cfg, &mis[0], diag) })
}
struct CfgAttrFolder<'a, T> {
diag: T,
config: &'a ast::CrateConfig,
}
fn process_cfg_attr(diagnostic: &Handler, krate: ast::Crate,
feature_gated_cfgs: &mut Vec<GatedCfgAttr>)
-> ast::Crate {
let mut fld =
CfgAttrFolder{diag:
CfgDiagReal{diag: diagnostic,
feature_gated_cfgs:
feature_gated_cfgs,},
config: &krate.config.clone(),};
fld.fold_crate(krate)
}
impl <'a, T: CfgDiag> fold::Folder for CfgAttrFolder<'a, T> {
fn fold_attribute(&mut self, attr: ast::Attribute)
-> Option<ast::Attribute> {
if !attr.check_name("cfg_attr") {
return fold::noop_fold_attribute(attr, self);
}
let attr_list =
match attr.meta_item_list() {
Some(attr_list) => attr_list,
None => {
self.diag.emit_error(|diag| {
diag.span_err(attr.span,
"expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
});
return None;
}
};
let (cfg, mi) =
match (attr_list.len(), attr_list.get(0), attr_list.get(1)) {
(2, Some(cfg), Some(mi)) => (cfg, mi),
_ => {
self.diag.emit_error(|diag| {
diag.span_err(attr.span,
"expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
});
return None;
}
};
if attr::cfg_matches(&self.config[..], &cfg, &mut self.diag) {
Some(respan(mi.span,
ast::Attribute_{id: attr::mk_attr_id(),
style: attr.node.style,
value: mi.clone(),
is_sugared_doc: false,}))
} else { None }
}
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self)
}
}
fn check_for_gated_stmt_expr_attributes(krate: &ast::Crate,
discovered:
&mut Vec<GatedCfgAttr>) {
let mut v =
StmtExprAttrFeatureVisitor{config: &krate.config,
discovered: discovered,};
visit::walk_crate(&mut v, krate);
}
/// To cover this feature, we need to discover all attributes
/// so we need to run before cfg.
struct StmtExprAttrFeatureVisitor<'a, 'b> {
config: &'a ast::CrateConfig,
discovered: &'b mut Vec<GatedCfgAttr>,
}
impl <'v, 'a, 'b> visit::Visitor<'v> for
StmtExprAttrFeatureVisitor<'a, 'b> {
fn visit_stmt(&mut self, s: &'v ast::Stmt) {
let stmt_attrs = s.node.attrs();
if stmt_attrs.len() > 0 {
if let ast::StmtDecl(ref decl, _) = s.node {
if let ast::DeclItem(_) = decl.node {
visit::walk_stmt(self, s);
return;
}
}
for attr in stmt_attrs {
self.discovered.push(GatedCfgAttr::GatedAttr(attr.span));
}
if node_survives_cfg(stmt_attrs, self.config) {
visit::walk_stmt(self, s);
}
} else { visit::walk_stmt(self, s); }
}
fn visit_expr(&mut self, ex: &'v ast::Expr) {
let expr_attrs = ex.attrs();
if expr_attrs.len() > 0 {
for attr in expr_attrs {
self.discovered.push(GatedCfgAttr::GatedAttr(attr.span));
}
if node_survives_cfg(expr_attrs, self.config) {
visit::walk_expr(self, ex);
}
} else { visit::walk_expr(self, ex); }
}
fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) {
if node_survives_cfg(&i.attrs, self.config) {
visit::walk_foreign_item(self, i);
}
}
fn visit_item(&mut self, i: &'v ast::Item) {
if node_survives_cfg(&i.attrs, self.config) {
visit::walk_item(self, i);
}
}
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
if node_survives_cfg(&ii.attrs, self.config) {
visit::walk_impl_item(self, ii);
}
}
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
if node_survives_cfg(&ti.attrs, self.config) {
visit::walk_trait_item(self, ti);
}
}
fn visit_struct_field(&mut self, s: &'v ast::StructField) {
if node_survives_cfg(&s.node.attrs, self.config) {
visit::walk_struct_field(self, s);
}
}
fn visit_variant(&mut self, v: &'v ast::Variant, g: &'v ast::Generics,
item_id: ast::NodeId) {
if node_survives_cfg(&v.node.attrs, self.config) {
visit::walk_variant(self, v, g, item_id);
}
}
fn visit_arm(&mut self, a: &'v ast::Arm) {
if node_survives_cfg(&a.attrs, self.config) {
visit::walk_arm(self, a);
}
}
fn visit_mac(&mut self, mac: &'v ast::Mac) {
visit::walk_mac(self, mac)
}
}
pub trait CfgDiag {
fn emit_error<F>(&mut self, f: F)
where
F: FnMut(&Handler);
fn flag_gated<F>(&mut self, f: F)
where
F: FnMut(&mut Vec<GatedCfgAttr>);
}
pub struct CfgDiagReal<'a, 'b> {
pub diag: &'a Handler,
pub feature_gated_cfgs: &'b mut Vec<GatedCfgAttr>,
}
impl <'a, 'b> CfgDiag for CfgDiagReal<'a, 'b> {
fn emit_error<F>(&mut self, mut f: F) where F: FnMut(&Handler) {
f(self.diag)
}
fn flag_gated<F>(&mut self, mut f: F) where
F: FnMut(&mut Vec<GatedCfgAttr>) {
f(self.feature_gated_cfgs)
}
}
struct CfgDiagSilent {
error: bool,
}
impl CfgDiag for CfgDiagSilent {
fn emit_error<F>(&mut self, _: F) where F: FnMut(&Handler) {
self.error = true;
}
fn flag_gated<F>(&mut self, _: F) where
F: FnMut(&mut Vec<GatedCfgAttr>) {
}
}
fn node_survives_cfg(attrs: &[ast::Attribute], config: &ast::CrateConfig)
-> bool {
let mut survives_cfg = true;
for attr in attrs {
let mut fld =
CfgAttrFolder{diag: CfgDiagSilent{error: false,},
config: config,};
let attr = fld.fold_attribute(attr.clone());
if fld.diag.error { return true; }
survives_cfg &=
attr.map(|attr| { let mut diag = CfgDiagSilent{error: false,};
let r = in_cfg(config, &[attr], &mut diag);
if diag.error { return true; } r }).unwrap_or(true)
}
survives_cfg
}
}
pub mod entry {
#[prelude_import]
use std::prelude::v1::*;
use attr;
use ast::{Item, ItemFn};
pub enum EntryPointType { None, MainNamed, MainAttr, Start, OtherMain, }
pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
match item.node {
ItemFn(..) => {
if attr::contains_name(&item.attrs, "start") {
EntryPointType::Start
} else if attr::contains_name(&item.attrs, "main") {
EntryPointType::MainAttr
} else if item.ident.name.as_str() == "main" {
if depth == 1 {
EntryPointType::MainNamed
} else { EntryPointType::OtherMain }
} else { EntryPointType::None }
}
_ => EntryPointType::None,
}
}
}
pub mod feature_gate {
//! Feature gating
//!
//! This module implements the gating necessary for preventing certain compiler
//! features from being used by default. This module will crawl a pre-expanded
//! AST to ensure that there are no features which are used that are not
//! enabled.
//!
//! Features are enabled in programs via the crate-level attributes of
//! `#![feature(...)]` with a comma-separated list of features.
//!
//! For the purpose of future feature-tracking, once code for detection of feature
//! gate usage is added, *do not remove it again* even once the feature
//! becomes stable.
#[prelude_import]
use std::prelude::v1::*;
use self::Status::*;
use self::AttributeType::*;
use self::AttributeGate::*;
use abi::Abi;
use ast::NodeId;
use ast;
use attr;
use attr::AttrMetaMethods;
use codemap::{CodeMap, Span};
use errors::Handler;
use visit;
use visit::{FnKind, Visitor};
use parse::token::InternedString;
use std::ascii::AsciiExt;
use std::cmp;
const KNOWN_FEATURES:
&'static [(&'static str, &'static str, Option<u32>, Status)] =
&[("globs", "1.0.0", None, Accepted),
("macro_rules", "1.0.0", None, Accepted),
("struct_variant", "1.0.0", None, Accepted),
("asm", "1.0.0", Some(29722), Active),
("managed_boxes", "1.0.0", None, Removed),
("non_ascii_idents", "1.0.0", Some(28979), Active),
("thread_local", "1.0.0", Some(29594), Active),
("link_args", "1.0.0", Some(29596), Active),
("plugin_registrar", "1.0.0", Some(29597), Active),
("log_syntax", "1.0.0", Some(29598), Active),
("trace_macros", "1.0.0", Some(29598), Active),
("concat_idents", "1.0.0", Some(29599), Active),
("intrinsics", "1.0.0", None, Active),
("lang_items", "1.0.0", None, Active),
("simd", "1.0.0", Some(27731), Active),
("default_type_params", "1.0.0", None, Accepted),
("quote", "1.0.0", Some(29601), Active),
("link_llvm_intrinsics", "1.0.0", Some(29602), Active),
("linkage", "1.0.0", Some(29603), Active),
("struct_inherit", "1.0.0", None, Removed),
("quad_precision_float", "1.0.0", None, Removed),
("rustc_diagnostic_macros", "1.0.0", None, Active),
("unboxed_closures", "1.0.0", Some(29625), Active),
("reflect", "1.0.0", Some(27749), Active),
("import_shadowing", "1.0.0", None, Removed),
("advanced_slice_patterns", "1.0.0", Some(23121), Active),
("tuple_indexing", "1.0.0", None, Accepted),
("associated_types", "1.0.0", None, Accepted),
("visible_private_types", "1.0.0", None, Removed),
("slicing_syntax", "1.0.0", None, Accepted),
("box_syntax", "1.0.0", Some(27779), Active),
("placement_in_syntax", "1.0.0", Some(27779), Active),
("pushpop_unsafe", "1.2.0", None, Active),
("on_unimplemented", "1.0.0", Some(29628), Active),
("simd_ffi", "1.0.0", Some(27731), Active),
("allocator", "1.0.0", Some(27389), Active),
("needs_allocator", "1.4.0", Some(27389), Active),
("linked_from", "1.3.0", Some(29629), Active),
("if_let", "1.0.0", None, Accepted),
("while_let", "1.0.0", None, Accepted),
("plugin", "1.0.0", Some(29597), Active),
("start", "1.0.0", Some(29633), Active),
("main", "1.0.0", Some(29634), Active),
("fundamental", "1.0.0", Some(29635), Active),
("issue_5723_bootstrap", "1.0.0", None, Accepted),
("opt_out_copy", "1.0.0", None, Removed),
("optin_builtin_traits", "1.0.0", Some(13231), Active),
("macro_reexport", "1.0.0", Some(29638), Active),
("test_accepted_feature", "1.0.0", None, Accepted),
("test_removed_feature", "1.0.0", None, Removed),
("staged_api", "1.0.0", None, Active),
("unmarked_api", "1.0.0", None, Active),
("no_std", "1.0.0", None, Accepted),
("no_core", "1.3.0", Some(29639), Active),
("box_patterns", "1.0.0", Some(29641), Active),
("unsafe_no_drop_flag", "1.0.0", None, Active),
("dropck_parametricity", "1.3.0", Some(28498), Active),
("custom_attribute", "1.0.0", Some(29642), Active),
("custom_derive", "1.0.0", Some(29644), Active),
("rustc_attrs", "1.0.0", Some(29642), Active),
("allow_internal_unstable", "1.0.0", None, Active),
("slice_patterns", "1.0.0", Some(23121), Active),
("negate_unsigned", "1.0.0", Some(29645), Active),
("associated_consts", "1.0.0", Some(29646), Active),
("const_fn", "1.2.0", Some(24111), Active),
("const_indexing", "1.4.0", Some(29947), Active),
("prelude_import", "1.2.0", None, Active),
("static_recursion", "1.3.0", Some(29719), Active),
("default_type_parameter_fallback", "1.3.0", Some(27336), Active),
("associated_type_defaults", "1.2.0", Some(29661), Active),
("type_macros", "1.3.0", Some(27336), Active),
("repr_simd", "1.4.0", Some(27731), Active),
("cfg_target_feature", "1.4.0", Some(29717), Active),
("platform_intrinsics", "1.4.0", Some(27731), Active),
("unwind_attributes", "1.4.0", None, Active),
("braced_empty_structs", "1.5.0", Some(29720), Active),
("augmented_assignments", "1.5.0", Some(28235), Active),
("no_debug", "1.5.0", Some(29721), Active),
("omit_gdb_pretty_printer_section", "1.5.0", None, Active),
("cfg_target_vendor", "1.5.0", Some(29718), Active),
("stmt_expr_attributes", "1.6.0", Some(15701), Active),
("deprecated", "1.6.0", Some(29935), Active),
("type_ascription", "1.6.0", Some(23416), Active),
("cfg_target_thread_local", "1.7.0", Some(29594), Active)];
enum Status {
/// Represents an active feature that is currently being implemented or
/// currently being considered for addition/removal.
Active,
/// Represents a feature which has since been removed (it was once Active)
Removed,
/// This language feature has since been Accepted (it was once Active)
Accepted,
}
pub const KNOWN_ATTRIBUTES:
&'static [(&'static str, AttributeType, AttributeGate)] =
&[("warn", Normal, Ungated), ("allow", Normal, Ungated),
("forbid", Normal, Ungated), ("deny", Normal, Ungated),
("macro_reexport", Normal, Ungated), ("macro_use", Normal, Ungated),
("macro_export", Normal, Ungated),
("plugin_registrar", Normal, Ungated), ("cfg", Normal, Ungated),
("cfg_attr", Normal, Ungated), ("main", Normal, Ungated),
("start", Normal, Ungated), ("test", Normal, Ungated),
("bench", Normal, Ungated), ("simd", Normal, Ungated),
("repr", Normal, Ungated), ("path", Normal, Ungated),
("abi", Normal, Ungated),
("automatically_derived", Normal, Ungated),
("no_mangle", Normal, Ungated), ("no_link", Normal, Ungated),
("derive", Normal, Ungated), ("should_panic", Normal, Ungated),
("ignore", Normal, Ungated),
("no_implicit_prelude", Normal, Ungated),
("reexport_test_harness_main", Normal, Ungated),
("link_args", Normal, Ungated), ("macro_escape", Normal, Ungated),
("no_stack_check", Normal, Ungated),
("plugin", CrateLevel,
Gated("plugin",
"compiler plugins are experimental and possibly buggy")),
("no_std", CrateLevel, Ungated),
("no_core", CrateLevel,
Gated("no_core", "no_core is experimental")),
("lang", Normal,
Gated("lang_items", "language items are subject to change")),
("linkage", Whitelisted,
Gated("linkage",
"the `linkage` attribute is experimental and not portable across platforms")),
("thread_local", Whitelisted,
Gated("thread_local",
"`#[thread_local]` is an experimental feature, and does not currently handle destructors. There is no corresponding `#[task_local]` mapping to the task model")),
("rustc_on_unimplemented", Normal,
Gated("on_unimplemented",
"the `#[rustc_on_unimplemented]` attribute is an experimental feature")),
("allocator", Whitelisted,
Gated("allocator",
"the `#[allocator]` attribute is an experimental feature")),
("needs_allocator", Normal,
Gated("needs_allocator",
"the `#[needs_allocator]` attribute is an experimental feature")),
("rustc_variance", Normal,
Gated("rustc_attrs",
"the `#[rustc_variance]` attribute is just used for rustc unit tests and will never be stable")),
("rustc_error", Whitelisted,
Gated("rustc_attrs",
"the `#[rustc_error]` attribute is just used for rustc unit tests and will never be stable")),
("rustc_if_this_changed", Whitelisted,
Gated("rustc_attrs",
"the `#[rustc_if_this_changed]` attribute is just used for rustc unit tests and will never be stable")),
("rustc_then_this_would_need", Whitelisted,
Gated("rustc_attrs",
"the `#[rustc_if_this_changed]` attribute is just used for rustc unit tests and will never be stable")),
("rustc_move_fragments", Normal,
Gated("rustc_attrs",
"the `#[rustc_move_fragments]` attribute is just used for rustc unit tests and will never be stable")),
("rustc_mir", Normal,
Gated("rustc_attrs",
"the `#[rustc_mir]` attribute is just used for rustc unit tests and will never be stable")),
("allow_internal_unstable", Normal,
Gated("allow_internal_unstable", EXPLAIN_ALLOW_INTERNAL_UNSTABLE)),
("fundamental", Whitelisted,
Gated("fundamental",
"the `#[fundamental]` attribute is an experimental feature")),
("linked_from", Normal,
Gated("linked_from",
"the `#[linked_from]` attribute is an experimental feature")),
("doc", Whitelisted, Ungated), ("cold", Whitelisted, Ungated),
("export_name", Whitelisted, Ungated),
("inline", Whitelisted, Ungated), ("link", Whitelisted, Ungated),
("link_name", Whitelisted, Ungated),
("link_section", Whitelisted, Ungated),
("no_builtins", Whitelisted, Ungated),
("no_mangle", Whitelisted, Ungated),
("no_debug", Whitelisted,
Gated("no_debug",
"the `#[no_debug]` attribute is an experimental feature")),
("omit_gdb_pretty_printer_section", Whitelisted,
Gated("omit_gdb_pretty_printer_section",
"the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite")),
("unsafe_no_drop_flag", Whitelisted,
Gated("unsafe_no_drop_flag",
"unsafe_no_drop_flag has unstable semantics and may be removed in the future")),
("unsafe_destructor_blind_to_params", Normal,
Gated("dropck_parametricity",
"unsafe_destructor_blind_to_params has unstable semantics and may be removed in the future")),
("unwind", Whitelisted,
Gated("unwind_attributes", "#[unwind] is experimental")),
("prelude_import", Whitelisted,
Gated("prelude_import",
"`#[prelude_import]` is for use by rustc only")),
("rustc_deprecated", Whitelisted, Ungated),
("must_use", Whitelisted, Ungated),
("stable", Whitelisted, Ungated),
("unstable", Whitelisted, Ungated),
("deprecated", Normal,
Gated("deprecated", "`#[deprecated]` attribute is unstable")),
("rustc_paren_sugar", Normal,
Gated("unboxed_closures", "unboxed_closures are still evolving")),
("rustc_reflect_like", Whitelisted,
Gated("reflect", "defining reflective traits is still evolving")),
("crate_name", CrateLevel, Ungated),
("crate_type", CrateLevel, Ungated),
("crate_id", CrateLevel, Ungated), ("feature", CrateLevel, Ungated),
("no_start", CrateLevel, Ungated), ("no_main", CrateLevel, Ungated),
("no_builtins", CrateLevel, Ungated),
("recursion_limit", CrateLevel, Ungated)];
const GATED_CFGS:
&'static [(&'static str, &'static str, fn(&Features) -> bool)] =
&[("target_feature", "cfg_target_feature",
{
fn f(x: &Features) -> bool { x.cfg_target_feature }
f as fn(&Features) -> bool
}),
("target_vendor", "cfg_target_vendor",
{
fn f(x: &Features) -> bool { x.cfg_target_vendor }
f as fn(&Features) -> bool
}),
("target_thread_local", "cfg_target_thread_local",
{
fn f(x: &Features) -> bool { x.cfg_target_thread_local }
f as fn(&Features) -> bool
})];
pub enum GatedCfgAttr { GatedCfg(GatedCfg), GatedAttr(Span), }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for GatedCfgAttr {
#[inline]
fn eq(&self, __arg_0: &GatedCfgAttr) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&GatedCfgAttr::GatedCfg(ref __self_0),
&GatedCfgAttr::GatedCfg(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&GatedCfgAttr::GatedAttr(ref __self_0),
&GatedCfgAttr::GatedAttr(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &GatedCfgAttr) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&GatedCfgAttr::GatedCfg(ref __self_0),
&GatedCfgAttr::GatedCfg(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&GatedCfgAttr::GatedAttr(ref __self_0),
&GatedCfgAttr::GatedAttr(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for GatedCfgAttr {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&GatedCfgAttr::GatedCfg(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&GatedCfgAttr::GatedAttr(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for GatedCfgAttr {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&GatedCfgAttr::GatedCfg(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("GatedCfg");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&GatedCfgAttr::GatedAttr(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("GatedAttr");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
pub struct GatedCfg {
span: Span,
index: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for GatedCfg {
#[inline]
fn eq(&self, __arg_0: &GatedCfg) -> bool {
match *__arg_0 {
GatedCfg { span: ref __self_1_0, index: ref __self_1_1 } =>
match *self {
GatedCfg { span: ref __self_0_0, index: ref __self_0_1 }
=>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &GatedCfg) -> bool {
match *__arg_0 {
GatedCfg { span: ref __self_1_0, index: ref __self_1_1 } =>
match *self {
GatedCfg { span: ref __self_0_0, index: ref __self_0_1 }
=>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for GatedCfg {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
GatedCfg { span: ref __self_0_0, index: ref __self_0_1 } => {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for GatedCfg {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
GatedCfg { span: ref __self_0_0, index: ref __self_0_1 } => {
let mut builder = __arg_0.debug_struct("GatedCfg");
let _ = builder.field("span", &&(*__self_0_0));
let _ = builder.field("index", &&(*__self_0_1));
builder.finish()
}
}
}
}
impl Ord for GatedCfgAttr {
fn cmp(&self, other: &GatedCfgAttr) -> cmp::Ordering {
let to_tup =
|s: &GatedCfgAttr|
match *s {
GatedCfgAttr::GatedCfg(ref gated_cfg) => {
(gated_cfg.span.lo.0, gated_cfg.span.hi.0,
gated_cfg.index)
}
GatedCfgAttr::GatedAttr(ref span) => {
(span.lo.0, span.hi.0, GATED_CFGS.len())
}
};
to_tup(self).cmp(&to_tup(other))
}
}
impl PartialOrd for GatedCfgAttr {
fn partial_cmp(&self, other: &GatedCfgAttr) -> Option<cmp::Ordering> {
Some(self.cmp(other))
}
}
impl GatedCfgAttr {
pub fn check_and_emit(&self, diagnostic: &Handler,
features: &Features, codemap: &CodeMap) {
match *self {
GatedCfgAttr::GatedCfg(ref cfg) => {
cfg.check_and_emit(diagnostic, features, codemap);
}
GatedCfgAttr::GatedAttr(span) => {
if !features.stmt_expr_attributes {
emit_feature_err(diagnostic, "stmt_expr_attributes",
span, GateIssue::Language,
EXPLAIN_STMT_ATTR_SYNTAX);
}
}
}
}
}
impl GatedCfg {
pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> {
let name = cfg.name();
GATED_CFGS.iter().position(|info|
info.0 ==
name).map(|idx| {
GatedCfg{span:
cfg.span,
index: idx,}
})
}
fn check_and_emit(&self, diagnostic: &Handler, features: &Features,
codemap: &CodeMap) {
let (cfg, feature, has_feature) = GATED_CFGS[self.index];
if !has_feature(features) &&
!codemap.span_allows_unstable(self.span) {
let explain =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["`cfg(",
")` is experimental and subject to change"];
__STATIC_FMTSTR
},
&match (&cfg,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
emit_feature_err(diagnostic, feature, self.span,
GateIssue::Language, &explain);
}
}
}
pub enum AttributeType {
/// Normal, builtin attribute that is consumed
/// by the compiler before the unused_attribute check
Normal,
/// Builtin attribute that may not be consumed by the compiler
/// before the unused_attribute check. These attributes
/// will be ignored by the unused_attribute lint
Whitelisted,
/// Builtin attribute that is only allowed at the crate level
CrateLevel,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AttributeType {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&AttributeType::Normal,) => {
let mut builder = __arg_0.debug_tuple("Normal");
builder.finish()
}
(&AttributeType::Whitelisted,) => {
let mut builder = __arg_0.debug_tuple("Whitelisted");
builder.finish()
}
(&AttributeType::CrateLevel,) => {
let mut builder = __arg_0.debug_tuple("CrateLevel");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AttributeType {
#[inline]
fn clone(&self) -> AttributeType {
match (&*self,) {
(&AttributeType::Normal,) => AttributeType::Normal,
(&AttributeType::Whitelisted,) => AttributeType::Whitelisted,
(&AttributeType::CrateLevel,) => AttributeType::CrateLevel,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AttributeType { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AttributeType {
#[inline]
fn eq(&self, __arg_0: &AttributeType) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AttributeType::Normal, &AttributeType::Normal) =>
true,
(&AttributeType::Whitelisted,
&AttributeType::Whitelisted) => true,
(&AttributeType::CrateLevel,
&AttributeType::CrateLevel) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &AttributeType) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AttributeType::Normal, &AttributeType::Normal) =>
false,
(&AttributeType::Whitelisted,
&AttributeType::Whitelisted) => false,
(&AttributeType::CrateLevel,
&AttributeType::CrateLevel) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
pub enum AttributeGate {
/// Is gated by a given feature gate and reason
Gated(&'static str, &'static str),
/// Ungated attribute, can be used on all release channels
Ungated,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for AttributeGate {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&AttributeGate::Gated(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Gated");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&AttributeGate::Ungated,) => {
let mut builder = __arg_0.debug_tuple("Ungated");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for AttributeGate {
#[inline]
fn clone(&self) -> AttributeGate {
match (&*self,) {
(&AttributeGate::Gated(ref __self_0, ref __self_1),) =>
AttributeGate::Gated(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&AttributeGate::Ungated,) => AttributeGate::Ungated,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for AttributeGate { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for AttributeGate {
#[inline]
fn eq(&self, __arg_0: &AttributeGate) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AttributeGate::Gated(ref __self_0, ref __self_1),
&AttributeGate::Gated(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&AttributeGate::Ungated, &AttributeGate::Ungated) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &AttributeGate) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&AttributeGate::Gated(ref __self_0, ref __self_1),
&AttributeGate::Gated(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&AttributeGate::Ungated, &AttributeGate::Ungated) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
/// A set of features to be used by later passes.
pub struct Features {
pub unboxed_closures: bool,
pub rustc_diagnostic_macros: bool,
pub allow_quote: bool,
pub allow_asm: bool,
pub allow_log_syntax: bool,
pub allow_concat_idents: bool,
pub allow_trace_macros: bool,
pub allow_internal_unstable: bool,
pub allow_custom_derive: bool,
pub allow_placement_in: bool,
pub allow_box: bool,
pub allow_pushpop_unsafe: bool,
pub simd_ffi: bool,
pub unmarked_api: bool,
pub negate_unsigned: bool,
/// spans of #![feature] attrs for stable language features. for error reporting
pub declared_stable_lang_features: Vec<Span>,
/// #![feature] attrs for non-language (library) features
pub declared_lib_features: Vec<(InternedString, Span)>,
pub const_fn: bool,
pub const_indexing: bool,
pub static_recursion: bool,
pub default_type_parameter_fallback: bool,
pub type_macros: bool,
pub cfg_target_feature: bool,
pub cfg_target_vendor: bool,
pub cfg_target_thread_local: bool,
pub augmented_assignments: bool,
pub braced_empty_structs: bool,
pub staged_api: bool,
pub stmt_expr_attributes: bool,
pub deprecated: bool,
}
impl Features {
pub fn new() -> Features {
Features{unboxed_closures: false,
rustc_diagnostic_macros: false,
allow_quote: false,
allow_asm: false,
allow_log_syntax: false,
allow_concat_idents: false,
allow_trace_macros: false,
allow_internal_unstable: false,
allow_custom_derive: false,
allow_placement_in: false,
allow_box: false,
allow_pushpop_unsafe: false,
simd_ffi: false,
unmarked_api: false,
negate_unsigned: false,
declared_stable_lang_features: Vec::new(),
declared_lib_features: Vec::new(),
const_fn: false,
const_indexing: false,
static_recursion: false,
default_type_parameter_fallback: false,
type_macros: false,
cfg_target_feature: false,
cfg_target_vendor: false,
cfg_target_thread_local: false,
augmented_assignments: false,
braced_empty_structs: false,
staged_api: false,
stmt_expr_attributes: false,
deprecated: false,}
}
}
const EXPLAIN_BOX_SYNTAX: &'static str =
"box expression syntax is experimental; you can call `Box::new` instead.";
const EXPLAIN_PLACEMENT_IN: &'static str =
"placement-in expression syntax is experimental and subject to change.";
const EXPLAIN_PUSHPOP_UNSAFE: &'static str =
"push/pop_unsafe macros are experimental and subject to change.";
const EXPLAIN_STMT_ATTR_SYNTAX: &'static str =
"attributes on non-item statements and expressions are experimental.";
pub fn check_for_box_syntax(f: Option<&Features>, diag: &Handler,
span: Span) {
if let Some(&Features { allow_box: true, .. }) = f { return; }
emit_feature_err(diag, "box_syntax", span, GateIssue::Language,
EXPLAIN_BOX_SYNTAX);
}
pub fn check_for_placement_in(f: Option<&Features>, diag: &Handler,
span: Span) {
if let Some(&Features { allow_placement_in: true, .. }) = f {
return;
}
emit_feature_err(diag, "placement_in_syntax", span,
GateIssue::Language, EXPLAIN_PLACEMENT_IN);
}
pub fn check_for_pushpop_syntax(f: Option<&Features>, diag: &Handler,
span: Span) {
if let Some(&Features { allow_pushpop_unsafe: true, .. }) = f {
return;
}
emit_feature_err(diag, "pushpop_unsafe", span, GateIssue::Language,
EXPLAIN_PUSHPOP_UNSAFE);
}
struct Context<'a> {
features: Vec<&'static str>,
span_handler: &'a Handler,
cm: &'a CodeMap,
plugin_attributes: &'a [(String, AttributeType)],
}
impl <'a> Context<'a> {
fn enable_feature(&mut self, feature: &'static str) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 650u32,
__file: "src/feature_gate.rs",
__module_path:
"syntex_syntax::feature_gate",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::feature_gate", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["enabling feature: "];
__STATIC_FMTSTR
},
&match (&feature,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
self.features.push(feature);
}
fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
let has_feature = self.has_feature(feature);
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 656u32,
__file: "src/feature_gate.rs",
__module_path:
"syntex_syntax::feature_gate",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::feature_gate", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["gate_feature(feature = ",
", span = ",
"); has? "];
__STATIC_FMTSTR
},
&match (&feature,
&span,
&has_feature)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
}
};
if !has_feature {
emit_feature_err(self.span_handler, feature, span,
GateIssue::Language, explain);
}
}
fn has_feature(&self, feature: &str) -> bool {
self.features.iter().any(|&n| n == feature)
}
fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 666u32,
__file: "src/feature_gate.rs",
__module_path:
"syntex_syntax::feature_gate",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::feature_gate", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["check_attribute(attr = ",
")"];
__STATIC_FMTSTR
},
&match (&attr,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
let name = &*attr.name();
for &(n, ty, gateage) in KNOWN_ATTRIBUTES {
if n == name {
if let Gated(gate, desc) = gateage {
self.gate_feature(gate, attr.span, desc);
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 673u32,
__file: "src/feature_gate.rs",
__module_path:
"syntex_syntax::feature_gate",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::feature_gate",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["check_attribute: ",
" is known, ",
", "];
__STATIC_FMTSTR
},
&match (&name,
&ty,
&gateage)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Debug::fmt)],
}))
}
};
return;
}
}
for &(ref n, ref ty) in self.plugin_attributes {
if &*n == name {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 682u32,
__file: "src/feature_gate.rs",
__module_path:
"syntex_syntax::feature_gate",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::feature_gate",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["check_attribute: ",
" is registered by a plugin, "];
__STATIC_FMTSTR
},
&match (&name,
&ty)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
return;
}
}
if name.starts_with("rustc_") {
self.gate_feature("rustc_attrs", attr.span,
"unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics");
} else if name.starts_with("derive_") {
self.gate_feature("custom_derive", attr.span,
"attributes of the form `#[derive_*]` are reserved for the compiler");
} else {
if !is_macro {
self.gate_feature("custom_attribute", attr.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["The attribute `",
"` is currently unknown to the compiler and may have meaning added to it in the future"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
}
}
}
fn find_lang_feature_issue(feature: &str) -> Option<u32> {
let info = KNOWN_FEATURES.iter().find(|t| t.0 == feature).unwrap();
let issue = info.2;
if let Active = info.3 { }
issue
}
pub enum GateIssue { Language, Library(Option<u32>), }
pub fn emit_feature_err(diag: &Handler, feature: &str, span: Span,
issue: GateIssue, explain: &str) {
let issue =
match issue {
GateIssue::Language => find_lang_feature_issue(feature),
GateIssue::Library(lib) => lib,
};
let mut err =
if let Some(n) = issue {
diag.struct_span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" (see issue #",
")"];
__STATIC_FMTSTR
},
&match (&explain,
&n)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})))
} else { diag.struct_span_err(span, explain) };
if ::std::option::Option::None::<&'static str>.is_some() {
err.emit();
return;
}
err.fileline_help(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["add #![feature(",
")] to the crate attributes to enable"];
__STATIC_FMTSTR
},
&match (&feature,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
err.emit();
}
pub const EXPLAIN_ASM: &'static str =
"inline assembly is not stable enough for use and is subject to change";
pub const EXPLAIN_LOG_SYNTAX: &'static str =
"`log_syntax!` is not stable enough for use and is subject to change";
pub const EXPLAIN_CONCAT_IDENTS: &'static str =
"`concat_idents` is not stable enough for use and is subject to change";
pub const EXPLAIN_TRACE_MACROS: &'static str =
"`trace_macros` is not stable enough for use and is subject to change";
pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &'static str =
"allow_internal_unstable side-steps feature gating and stability checks";
pub const EXPLAIN_CUSTOM_DERIVE: &'static str =
"`#[derive]` for custom traits is not stable enough for use and is subject to change";
struct MacroVisitor<'a> {
context: &'a Context<'a>,
}
impl <'a, 'v> Visitor<'v> for MacroVisitor<'a> {
fn visit_mac(&mut self, mac: &ast::Mac) {
let path = &mac.node.path;
let name = path.segments.last().unwrap().identifier.name.as_str();
if name == "asm" {
self.context.gate_feature("asm", path.span, EXPLAIN_ASM);
} else if name == "log_syntax" {
self.context.gate_feature("log_syntax", path.span,
EXPLAIN_LOG_SYNTAX);
} else if name == "trace_macros" {
self.context.gate_feature("trace_macros", path.span,
EXPLAIN_TRACE_MACROS);
} else if name == "concat_idents" {
self.context.gate_feature("concat_idents", path.span,
EXPLAIN_CONCAT_IDENTS);
}
}
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
self.context.check_attribute(attr, true);
}
fn visit_expr(&mut self, e: &ast::Expr) {
if let ast::ExprBox(_) = e.node {
self.context.gate_feature("box_syntax", e.span,
EXPLAIN_BOX_SYNTAX);
}
if let ast::ExprInPlace(..) = e.node {
self.context.gate_feature("placement_in_syntax", e.span,
EXPLAIN_PLACEMENT_IN);
}
visit::walk_expr(self, e);
}
}
struct PostExpansionVisitor<'a> {
context: &'a Context<'a>,
}
impl <'a> PostExpansionVisitor<'a> {
fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
if !self.context.cm.span_allows_unstable(span) {
self.context.gate_feature(feature, span, explain)
}
}
}
impl <'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
if !self.context.cm.span_allows_unstable(attr.span) {
self.context.check_attribute(attr, false);
}
}
fn visit_name(&mut self, sp: Span, name: ast::Name) {
if !name.as_str().is_ascii() {
self.gate_feature("non_ascii_idents", sp,
"non-ascii idents are not fully supported.");
}
}
fn visit_item(&mut self, i: &ast::Item) {
match i.node {
ast::ItemExternCrate(_) => {
if attr::contains_name(&i.attrs[..], "macro_reexport") {
self.gate_feature("macro_reexport", i.span,
"macros reexports are experimental and possibly buggy");
}
}
ast::ItemForeignMod(ref foreign_module) => {
if attr::contains_name(&i.attrs[..], "link_args") {
self.gate_feature("link_args", i.span,
"the `link_args` attribute is not portable across platforms, it is recommended to use `#[link(name = \"foo\")]` instead")
}
let maybe_feature =
match foreign_module.abi {
Abi::RustIntrinsic =>
Some(("intrinsics",
"intrinsics are subject to change")),
Abi::PlatformIntrinsic => {
Some(("platform_intrinsics",
"platform intrinsics are experimental and possibly buggy"))
}
_ => None,
};
if let Some((feature, msg)) = maybe_feature {
self.gate_feature(feature, i.span, msg)
}
}
ast::ItemFn(..) => {
if attr::contains_name(&i.attrs[..], "plugin_registrar") {
self.gate_feature("plugin_registrar", i.span,
"compiler plugins are experimental and possibly buggy");
}
if attr::contains_name(&i.attrs[..], "start") {
self.gate_feature("start", i.span,
"a #[start] function is an experimental feature whose signature may change over time");
}
if attr::contains_name(&i.attrs[..], "main") {
self.gate_feature("main", i.span,
"declaration of a nonstandard #[main] function may change over time, for now a top-level `fn main()` is required");
}
}
ast::ItemStruct(..) => {
if attr::contains_name(&i.attrs[..], "simd") {
self.gate_feature("simd", i.span,
"SIMD types are experimental and possibly buggy");
self.context.span_handler.span_warn(i.span,
"the `#[simd]` attribute is deprecated, use `#[repr(simd)]` instead");
}
for attr in &i.attrs {
if attr.name() == "repr" {
for item in attr.meta_item_list().unwrap_or(&[]) {
if item.name() == "simd" {
self.gate_feature("repr_simd", i.span,
"SIMD types are experimental and possibly buggy");
}
}
}
}
}
ast::ItemDefaultImpl(..) => {
self.gate_feature("optin_builtin_traits", i.span,
"default trait implementations are experimental and possibly buggy");
}
ast::ItemImpl(_, polarity, _, _, _, _) => {
match polarity {
ast::ImplPolarity::Negative => {
self.gate_feature("optin_builtin_traits", i.span,
"negative trait bounds are not yet fully implemented; use marker types for now");
}
_ => { }
}
}
_ => { }
}
visit::walk_item(self, i);
}
fn visit_variant_data(&mut self, s: &'v ast::VariantData,
_: ast::Ident, _: &'v ast::Generics,
_: ast::NodeId, span: Span) {
if s.fields().is_empty() {
if s.is_struct() {
self.gate_feature("braced_empty_structs", span,
"empty structs and enum variants with braces are unstable");
} else if s.is_tuple() {
self.context.span_handler.struct_span_err(span,
"empty tuple structs and enum variants are not allowed, use unit structs and enum variants instead").span_help(span,
"remove trailing `()` to make a unit struct or unit enum variant").emit();
}
}
visit::walk_struct_def(self, s)
}
fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
let links_to_llvm =
match attr::first_attr_value_str_by_name(&i.attrs,
"link_name") {
Some(val) => val.starts_with("llvm."),
_ => false,
};
if links_to_llvm {
self.gate_feature("link_llvm_intrinsics", i.span,
"linking to LLVM intrinsics is experimental");
}
visit::walk_foreign_item(self, i)
}
fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
ast::ExprBox(_) => {
self.gate_feature("box_syntax", e.span,
"box expression syntax is experimental; you can call `Box::new` instead.");
}
ast::ExprType(..) => {
self.gate_feature("type_ascription", e.span,
"type ascription is experimental");
}
_ => { }
}
visit::walk_expr(self, e);
}
fn visit_pat(&mut self, pattern: &ast::Pat) {
match pattern.node {
ast::PatVec(_, Some(_), ref last) if !last.is_empty() => {
self.gate_feature("advanced_slice_patterns", pattern.span,
"multiple-element slice matches anywhere but at the end of a slice (e.g. `[0, ..xs, 0]`) are experimental")
}
ast::PatVec(..) => {
self.gate_feature("slice_patterns", pattern.span,
"slice pattern syntax is experimental");
}
ast::PatBox(..) => {
self.gate_feature("box_patterns", pattern.span,
"box pattern syntax is experimental");
}
_ => { }
}
visit::walk_pat(self, pattern)
}
fn visit_fn(&mut self, fn_kind: FnKind<'v>, fn_decl: &'v ast::FnDecl,
block: &'v ast::Block, span: Span, _node_id: NodeId) {
match fn_kind {
FnKind::ItemFn(_, _, _, ast::Constness::Const, _, _) => {
self.gate_feature("const_fn", span,
"const fn is unstable");
}
_ => { }
}
match fn_kind {
FnKind::ItemFn(_, _, _, _, abi, _) if
abi == Abi::RustIntrinsic => {
self.gate_feature("intrinsics", span,
"intrinsics are subject to change")
}
FnKind::ItemFn(_, _, _, _, abi, _) |
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) if
abi == Abi::RustCall => {
self.gate_feature("unboxed_closures", span,
"rust-call ABI is subject to change")
}
_ => { }
}
visit::walk_fn(self, fn_kind, fn_decl, block, span);
}
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
match ti.node {
ast::ConstTraitItem(..) => {
self.gate_feature("associated_consts", ti.span,
"associated constants are experimental")
}
ast::MethodTraitItem(ref sig, _) => {
if sig.constness == ast::Constness::Const {
self.gate_feature("const_fn", ti.span,
"const fn is unstable");
}
}
ast::TypeTraitItem(_, Some(_)) => {
self.gate_feature("associated_type_defaults", ti.span,
"associated type defaults are unstable");
}
_ => { }
}
visit::walk_trait_item(self, ti);
}
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
match ii.node {
ast::ImplItemKind::Const(..) => {
self.gate_feature("associated_consts", ii.span,
"associated constants are experimental")
}
ast::ImplItemKind::Method(ref sig, _) => {
if sig.constness == ast::Constness::Const {
self.gate_feature("const_fn", ii.span,
"const fn is unstable");
}
}
_ => { }
}
visit::walk_impl_item(self, ii);
}
}
fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
krate: &ast::Crate,
plugin_attributes: &[(String, AttributeType)],
check: F) -> Features where
F: FnOnce(&mut Context, &ast::Crate) {
let mut cx =
Context{features: Vec::new(),
span_handler: span_handler,
cm: cm,
plugin_attributes: plugin_attributes,};
let mut accepted_features = Vec::new();
let mut unknown_features = Vec::new();
for attr in &krate.attrs {
if !attr.check_name("feature") { continue }
match attr.meta_item_list() {
None => {
span_handler.span_err(attr.span,
"malformed feature attribute, expected #![feature(...)]");
}
Some(list) => {
for mi in list {
let name =
match mi.node {
ast::MetaWord(ref word) => (*word).clone(),
_ => {
span_handler.span_err(mi.span,
"malformed feature, expected just one word");
continue
}
};
match KNOWN_FEATURES.iter().find(|&&(n, _, _, _)|
name == n) {
Some(&(name, _, _, Active)) => {
cx.enable_feature(name);
}
Some(&(_, _, _, Removed)) => {
span_handler.span_err(mi.span,
"feature has been removed");
}
Some(&(_, _, _, Accepted)) => {
accepted_features.push(mi.span);
}
None => {
unknown_features.push((name, mi.span));
}
}
}
}
}
}
check(&mut cx, krate);
Features{unboxed_closures: cx.has_feature("unboxed_closures"),
rustc_diagnostic_macros:
cx.has_feature("rustc_diagnostic_macros"),
allow_quote: cx.has_feature("quote"),
allow_asm: cx.has_feature("asm"),
allow_log_syntax: cx.has_feature("log_syntax"),
allow_concat_idents: cx.has_feature("concat_idents"),
allow_trace_macros: cx.has_feature("trace_macros"),
allow_internal_unstable:
cx.has_feature("allow_internal_unstable"),
allow_custom_derive: cx.has_feature("custom_derive"),
allow_placement_in: cx.has_feature("placement_in_syntax"),
allow_box: cx.has_feature("box_syntax"),
allow_pushpop_unsafe: cx.has_feature("pushpop_unsafe"),
simd_ffi: cx.has_feature("simd_ffi"),
unmarked_api: cx.has_feature("unmarked_api"),
negate_unsigned: cx.has_feature("negate_unsigned"),
declared_stable_lang_features: accepted_features,
declared_lib_features: unknown_features,
const_fn: cx.has_feature("const_fn"),
const_indexing: cx.has_feature("const_indexing"),
static_recursion: cx.has_feature("static_recursion"),
default_type_parameter_fallback:
cx.has_feature("default_type_parameter_fallback"),
type_macros: cx.has_feature("type_macros"),
cfg_target_feature: cx.has_feature("cfg_target_feature"),
cfg_target_vendor: cx.has_feature("cfg_target_vendor"),
cfg_target_thread_local:
cx.has_feature("cfg_target_thread_local"),
augmented_assignments:
cx.has_feature("augmented_assignments"),
braced_empty_structs: cx.has_feature("braced_empty_structs"),
staged_api: cx.has_feature("staged_api"),
stmt_expr_attributes: cx.has_feature("stmt_expr_attributes"),
deprecated: cx.has_feature("deprecated"),}
}
pub fn check_crate_macros(cm: &CodeMap, span_handler: &Handler,
krate: &ast::Crate) -> Features {
check_crate_inner(cm, span_handler, krate, &[] as &'static [_],
|ctx, krate|
visit::walk_crate(&mut MacroVisitor{context:
ctx,},
krate))
}
pub fn check_crate(cm: &CodeMap, span_handler: &Handler,
krate: &ast::Crate,
plugin_attributes: &[(String, AttributeType)],
unstable: UnstableFeatures) -> Features {
maybe_stage_features(span_handler, krate, unstable);
check_crate_inner(cm, span_handler, krate, plugin_attributes,
|ctx, krate|
visit::walk_crate(&mut PostExpansionVisitor{context:
ctx,},
krate))
}
pub enum UnstableFeatures {
/// Hard errors for unstable features are active, as on
/// beta/stable channels.
Disallow,
/// Allow features to me activated, as on nightly.
Allow,
/// Errors are bypassed for bootstrapping. This is required any time
/// during the build that feature-related lints are set to warn or above
/// because the build turns on warnings-as-errors and uses lots of unstable
/// features. As a result, this is always required for building Rust itself.
Cheat,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for UnstableFeatures { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for UnstableFeatures {
#[inline]
fn clone(&self) -> UnstableFeatures {
match (&*self,) {
(&UnstableFeatures::Disallow,) => UnstableFeatures::Disallow,
(&UnstableFeatures::Allow,) => UnstableFeatures::Allow,
(&UnstableFeatures::Cheat,) => UnstableFeatures::Cheat,
}
}
}
fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate,
unstable: UnstableFeatures) {
let allow_features =
match unstable {
UnstableFeatures::Allow => true,
UnstableFeatures::Disallow => false,
UnstableFeatures::Cheat => true,
};
if !allow_features {
for attr in &krate.attrs {
if attr.check_name("feature") {
let release_channel =
::std::option::Option::None::<&'static str>.unwrap_or("(unknown)");
let ref msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["#[feature] may not be used on the ",
" release channel"];
__STATIC_FMTSTR
},
&match (&release_channel,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
span_handler.span_err(attr.span, msg);
}
}
}
}
}
pub mod fold {
//! A Folder represents an AST->AST fold; it accepts an AST piece,
//! and returns a piece of the same type. So, for instance, macro
//! expansion is a Folder that walks over an AST and produces another
//! AST.
//!
//! Note: using a Folder (other than the MacroExpander Folder) on
//! an AST before macro expansion is probably a bad idea. For instance,
//! a folder renaming item names in a module will miss all of those
//! that are created by the expansion of a macro.
#[prelude_import]
use std::prelude::v1::*;
use ast::*;
use ast;
use attr::{ThinAttributes, ThinAttributesExt};
use ast_util;
use codemap::{respan, Span, Spanned};
use parse::token;
use ptr::P;
use util::small_vector::SmallVector;
use util::move_map::MoveMap;
use std::rc::Rc;
pub trait Folder: Sized {
fn fold_crate(&mut self, c: Crate) -> Crate {
noop_fold_crate(c, self)
}
fn fold_meta_items(&mut self, meta_items: Vec<P<MetaItem>>)
-> Vec<P<MetaItem>> {
noop_fold_meta_items(meta_items, self)
}
fn fold_meta_item(&mut self, meta_item: P<MetaItem>) -> P<MetaItem> {
noop_fold_meta_item(meta_item, self)
}
fn fold_view_path(&mut self, view_path: P<ViewPath>) -> P<ViewPath> {
noop_fold_view_path(view_path, self)
}
fn fold_foreign_item(&mut self, ni: P<ForeignItem>)
-> P<ForeignItem> {
noop_fold_foreign_item(ni, self)
}
fn fold_item(&mut self, i: P<Item>) -> SmallVector<P<Item>> {
noop_fold_item(i, self)
}
fn fold_item_simple(&mut self, i: Item) -> Item {
noop_fold_item_simple(i, self)
}
fn fold_struct_field(&mut self, sf: StructField) -> StructField {
noop_fold_struct_field(sf, self)
}
fn fold_item_underscore(&mut self, i: Item_) -> Item_ {
noop_fold_item_underscore(i, self)
}
fn fold_trait_item(&mut self, i: P<TraitItem>)
-> SmallVector<P<TraitItem>> {
noop_fold_trait_item(i, self)
}
fn fold_impl_item(&mut self, i: P<ImplItem>)
-> SmallVector<P<ImplItem>> {
noop_fold_impl_item(i, self)
}
fn fold_fn_decl(&mut self, d: P<FnDecl>) -> P<FnDecl> {
noop_fold_fn_decl(d, self)
}
fn fold_block(&mut self, b: P<Block>) -> P<Block> {
noop_fold_block(b, self)
}
fn fold_stmt(&mut self, s: P<Stmt>) -> SmallVector<P<Stmt>> {
s.and_then(|s| noop_fold_stmt(s, self))
}
fn fold_arm(&mut self, a: Arm) -> Arm { noop_fold_arm(a, self) }
fn fold_pat(&mut self, p: P<Pat>) -> P<Pat> { noop_fold_pat(p, self) }
fn fold_decl(&mut self, d: P<Decl>) -> SmallVector<P<Decl>> {
noop_fold_decl(d, self)
}
fn fold_expr(&mut self, e: P<Expr>) -> P<Expr> {
e.map(|e| noop_fold_expr(e, self))
}
fn fold_opt_expr(&mut self, e: P<Expr>) -> Option<P<Expr>> {
noop_fold_opt_expr(e, self)
}
fn fold_exprs(&mut self, es: Vec<P<Expr>>) -> Vec<P<Expr>> {
noop_fold_exprs(es, self)
}
fn fold_ty(&mut self, t: P<Ty>) -> P<Ty> { noop_fold_ty(t, self) }
fn fold_ty_binding(&mut self, t: P<TypeBinding>) -> P<TypeBinding> {
noop_fold_ty_binding(t, self)
}
fn fold_mod(&mut self, m: Mod) -> Mod { noop_fold_mod(m, self) }
fn fold_foreign_mod(&mut self, nm: ForeignMod) -> ForeignMod {
noop_fold_foreign_mod(nm, self)
}
fn fold_variant(&mut self, v: P<Variant>) -> P<Variant> {
noop_fold_variant(v, self)
}
fn fold_ident(&mut self, i: Ident) -> Ident {
noop_fold_ident(i, self)
}
fn fold_usize(&mut self, i: usize) -> usize {
noop_fold_usize(i, self)
}
fn fold_path(&mut self, p: Path) -> Path { noop_fold_path(p, self) }
fn fold_path_parameters(&mut self, p: PathParameters)
-> PathParameters {
noop_fold_path_parameters(p, self)
}
fn fold_angle_bracketed_parameter_data(&mut self,
p: AngleBracketedParameterData)
-> AngleBracketedParameterData {
noop_fold_angle_bracketed_parameter_data(p, self)
}
fn fold_parenthesized_parameter_data(&mut self,
p: ParenthesizedParameterData)
-> ParenthesizedParameterData {
noop_fold_parenthesized_parameter_data(p, self)
}
fn fold_local(&mut self, l: P<Local>) -> P<Local> {
noop_fold_local(l, self)
}
fn fold_mac(&mut self, _mac: Mac) -> Mac {
{
::std::rt::begin_unwind("fold_mac disabled by default",
{
static _FILE_LINE:
(&'static str, u32) =
("src/fold.rs", 175u32);
&_FILE_LINE
})
};
}
fn fold_explicit_self(&mut self, es: ExplicitSelf) -> ExplicitSelf {
noop_fold_explicit_self(es, self)
}
fn fold_explicit_self_underscore(&mut self, es: ExplicitSelf_)
-> ExplicitSelf_ {
noop_fold_explicit_self_underscore(es, self)
}
fn fold_lifetime(&mut self, l: Lifetime) -> Lifetime {
noop_fold_lifetime(l, self)
}
fn fold_lifetime_def(&mut self, l: LifetimeDef) -> LifetimeDef {
noop_fold_lifetime_def(l, self)
}
fn fold_attribute(&mut self, at: Attribute) -> Option<Attribute> {
noop_fold_attribute(at, self)
}
fn fold_arg(&mut self, a: Arg) -> Arg { noop_fold_arg(a, self) }
fn fold_generics(&mut self, generics: Generics) -> Generics {
noop_fold_generics(generics, self)
}
fn fold_trait_ref(&mut self, p: TraitRef) -> TraitRef {
noop_fold_trait_ref(p, self)
}
fn fold_poly_trait_ref(&mut self, p: PolyTraitRef) -> PolyTraitRef {
noop_fold_poly_trait_ref(p, self)
}
fn fold_variant_data(&mut self, vdata: VariantData) -> VariantData {
noop_fold_variant_data(vdata, self)
}
fn fold_lifetimes(&mut self, lts: Vec<Lifetime>) -> Vec<Lifetime> {
noop_fold_lifetimes(lts, self)
}
fn fold_lifetime_defs(&mut self, lts: Vec<LifetimeDef>)
-> Vec<LifetimeDef> {
noop_fold_lifetime_defs(lts, self)
}
fn fold_ty_param(&mut self, tp: TyParam) -> TyParam {
noop_fold_ty_param(tp, self)
}
fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> {
noop_fold_ty_params(tps, self)
}
fn fold_tt(&mut self, tt: &TokenTree) -> TokenTree {
noop_fold_tt(tt, self)
}
fn fold_tts(&mut self, tts: &[TokenTree]) -> Vec<TokenTree> {
noop_fold_tts(tts, self)
}
fn fold_token(&mut self, t: token::Token) -> token::Token {
noop_fold_token(t, self)
}
fn fold_interpolated(&mut self, nt: token::Nonterminal)
-> token::Nonterminal {
noop_fold_interpolated(nt, self)
}
fn fold_opt_lifetime(&mut self, o_lt: Option<Lifetime>)
-> Option<Lifetime> {
noop_fold_opt_lifetime(o_lt, self)
}
fn fold_opt_bounds(&mut self, b: Option<TyParamBounds>)
-> Option<TyParamBounds> {
noop_fold_opt_bounds(b, self)
}
fn fold_bounds(&mut self, b: TyParamBounds) -> TyParamBounds {
noop_fold_bounds(b, self)
}
fn fold_ty_param_bound(&mut self, tpb: TyParamBound) -> TyParamBound {
noop_fold_ty_param_bound(tpb, self)
}
fn fold_mt(&mut self, mt: MutTy) -> MutTy { noop_fold_mt(mt, self) }
fn fold_field(&mut self, field: Field) -> Field {
noop_fold_field(field, self)
}
fn fold_where_clause(&mut self, where_clause: WhereClause)
-> WhereClause {
noop_fold_where_clause(where_clause, self)
}
fn fold_where_predicate(&mut self, where_predicate: WherePredicate)
-> WherePredicate {
noop_fold_where_predicate(where_predicate, self)
}
fn new_id(&mut self, i: NodeId) -> NodeId { i }
fn new_span(&mut self, sp: Span) -> Span { sp }
}
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>,
fld: &mut T) -> Vec<P<MetaItem>> {
meta_items.move_map(|x| fld.fold_meta_item(x))
}
pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T)
-> P<ViewPath> {
view_path.map(|Spanned { node, span }|
Spanned{node:
match node {
ViewPathSimple(ident, path) => {
ViewPathSimple(ident,
fld.fold_path(path))
}
ViewPathGlob(path) => {
ViewPathGlob(fld.fold_path(path))
}
ViewPathList(path, path_list_idents)
=> {
ViewPathList(fld.fold_path(path),
path_list_idents.move_map(|path_list_ident|
{
Spanned{node:
match path_list_ident.node
{
PathListIdent {
id,
name,
rename
}
=>
PathListIdent{id:
fld.new_id(id),
rename:
rename,
name:
name,},
PathListMod {
id,
rename
}
=>
PathListMod{id:
fld.new_id(id),
rename:
rename,},
},
span:
fld.new_span(path_list_ident.span),}
}))
}
},
span: fld.new_span(span),})
}
pub fn fold_attrs<T: Folder>(attrs: Vec<Attribute>, fld: &mut T)
-> Vec<Attribute> {
attrs.move_flat_map(|x| fld.fold_attribute(x))
}
pub fn fold_thin_attrs<T: Folder>(attrs: ThinAttributes, fld: &mut T)
-> ThinAttributes {
attrs.map_thin_attrs(|v| fold_attrs(v, fld))
}
pub fn noop_fold_arm<T: Folder>(Arm { attrs, pats, guard, body }: Arm,
fld: &mut T) -> Arm {
Arm{attrs: fold_attrs(attrs, fld),
pats: pats.move_map(|x| fld.fold_pat(x)),
guard: guard.map(|x| fld.fold_expr(x)),
body: fld.fold_expr(body),}
}
pub fn noop_fold_decl<T: Folder>(d: P<Decl>, fld: &mut T)
-> SmallVector<P<Decl>> {
d.and_then(|Spanned { node, span }|
match node {
DeclLocal(l) =>
SmallVector::one(P(Spanned{node:
DeclLocal(fld.fold_local(l)),
span:
fld.new_span(span),})),
DeclItem(it) =>
fld.fold_item(it).into_iter().map(|i|
P(Spanned{node:
DeclItem(i),
span:
fld.new_span(span),})).collect(),
})
}
pub fn noop_fold_ty_binding<T: Folder>(b: P<TypeBinding>, fld: &mut T)
-> P<TypeBinding> {
b.map(|TypeBinding { id, ident, ty, span }|
TypeBinding{id: fld.new_id(id),
ident: ident,
ty: fld.fold_ty(ty),
span: fld.new_span(span),})
}
pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
t.map(|Ty { id, node, span }|
Ty{id: fld.new_id(id),
node:
match node {
TyInfer => node,
TyVec(ty) => TyVec(fld.fold_ty(ty)),
TyPtr(mt) => TyPtr(fld.fold_mt(mt)),
TyRptr(region, mt) => {
TyRptr(fld.fold_opt_lifetime(region),
fld.fold_mt(mt))
}
TyBareFn(f) => {
TyBareFn(f.map(|BareFnTy {
lifetimes,
unsafety,
abi,
decl }|
BareFnTy{lifetimes:
fld.fold_lifetime_defs(lifetimes),
unsafety:
unsafety,
abi: abi,
decl:
fld.fold_fn_decl(decl),}))
}
TyTup(tys) =>
TyTup(tys.move_map(|ty| fld.fold_ty(ty))),
TyParen(ty) => TyParen(fld.fold_ty(ty)),
TyPath(qself, path) => {
let qself =
qself.map(|QSelf { ty, position }| {
QSelf{ty: fld.fold_ty(ty),
position: position,} });
TyPath(qself, fld.fold_path(path))
}
TyObjectSum(ty, bounds) => {
TyObjectSum(fld.fold_ty(ty),
fld.fold_bounds(bounds))
}
TyFixedLengthVec(ty, e) => {
TyFixedLengthVec(fld.fold_ty(ty),
fld.fold_expr(e))
}
TyTypeof(expr) => {
TyTypeof(fld.fold_expr(expr))
}
TyPolyTraitRef(bounds) => {
TyPolyTraitRef(bounds.move_map(|b|
fld.fold_ty_param_bound(b)))
}
TyMac(mac) => { TyMac(fld.fold_mac(mac)) }
},
span: fld.new_span(span),})
}
pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod { abi, items }:
ForeignMod, fld: &mut T)
-> ForeignMod {
ForeignMod{abi: abi,
items: items.move_map(|x| fld.fold_foreign_item(x)),}
}
pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T)
-> P<Variant> {
v.map(|Spanned { node: Variant_ { name, attrs, data, disr_expr }, span
}|
Spanned{node:
Variant_{name: name,
attrs: fold_attrs(attrs, fld),
data: fld.fold_variant_data(data),
disr_expr:
disr_expr.map(|e|
fld.fold_expr(e)),},
span: fld.new_span(span),})
}
pub fn noop_fold_ident<T: Folder>(i: Ident, _: &mut T) -> Ident { i }
pub fn noop_fold_usize<T: Folder>(i: usize, _: &mut T) -> usize { i }
pub fn noop_fold_path<T: Folder>(Path { global, segments, span }: Path,
fld: &mut T) -> Path {
Path{global: global,
segments:
segments.move_map(|PathSegment { identifier, parameters }|
PathSegment{identifier:
fld.fold_ident(identifier),
parameters:
fld.fold_path_parameters(parameters),}),
span: fld.new_span(span),}
}
pub fn noop_fold_path_parameters<T: Folder>(path_parameters:
PathParameters,
fld: &mut T)
-> PathParameters {
match path_parameters {
PathParameters::AngleBracketed(data) =>
PathParameters::AngleBracketed(fld.fold_angle_bracketed_parameter_data(data)),
PathParameters::Parenthesized(data) =>
PathParameters::Parenthesized(fld.fold_parenthesized_parameter_data(data)),
}
}
pub fn noop_fold_angle_bracketed_parameter_data<T: Folder>(data:
AngleBracketedParameterData,
fld: &mut T)
-> AngleBracketedParameterData {
let AngleBracketedParameterData { lifetimes, types, bindings } = data;
AngleBracketedParameterData{lifetimes: fld.fold_lifetimes(lifetimes),
types:
types.move_map(|ty| fld.fold_ty(ty)),
bindings:
bindings.move_map(|b|
fld.fold_ty_binding(b)),}
}
pub fn noop_fold_parenthesized_parameter_data<T: Folder>(data:
ParenthesizedParameterData,
fld: &mut T)
-> ParenthesizedParameterData {
let ParenthesizedParameterData { inputs, output, span } = data;
ParenthesizedParameterData{inputs:
inputs.move_map(|ty| fld.fold_ty(ty)),
output: output.map(|ty| fld.fold_ty(ty)),
span: fld.new_span(span),}
}
pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
l.map(|Local { id, pat, ty, init, span, attrs }|
Local{id: fld.new_id(id),
ty: ty.map(|t| fld.fold_ty(t)),
pat: fld.fold_pat(pat),
init: init.map(|e| fld.fold_expr(e)),
span: fld.new_span(span),
attrs: attrs.map_thin_attrs(|v| fold_attrs(v, fld)),})
}
pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T)
-> Option<Attribute> {
let Spanned {
node: Attribute_ { id, style, value, is_sugared_doc }, span
} = at;
Some(Spanned{node:
Attribute_{id: id,
style: style,
value: fld.fold_meta_item(value),
is_sugared_doc: is_sugared_doc,},
span: fld.new_span(span),})
}
pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_,
fld: &mut T)
-> ExplicitSelf_ {
match es {
SelfStatic | SelfValue(_) => es,
SelfRegion(lifetime, m, ident) => {
SelfRegion(fld.fold_opt_lifetime(lifetime), m, ident)
}
SelfExplicit(typ, ident) => {
SelfExplicit(fld.fold_ty(typ), ident)
}
}
}
pub fn noop_fold_explicit_self<T: Folder>(Spanned { span, node }:
ExplicitSelf, fld: &mut T)
-> ExplicitSelf {
Spanned{node: fld.fold_explicit_self_underscore(node),
span: fld.new_span(span),}
}
pub fn noop_fold_mac<T: Folder>(Spanned { node, span }: Mac, fld: &mut T)
-> Mac {
Spanned{node:
Mac_{path: fld.fold_path(node.path),
tts: fld.fold_tts(&node.tts),
ctxt: node.ctxt,},
span: fld.new_span(span),}
}
pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T)
-> P<MetaItem> {
mi.map(|Spanned { node, span }|
Spanned{node:
match node {
MetaWord(id) => MetaWord(id),
MetaList(id, mis) => {
MetaList(id,
mis.move_map(|e|
fld.fold_meta_item(e)))
}
MetaNameValue(id, s) =>
MetaNameValue(id, s),
},
span: fld.new_span(span),})
}
pub fn noop_fold_arg<T: Folder>(Arg { id, pat, ty }: Arg, fld: &mut T)
-> Arg {
Arg{id: fld.new_id(id), pat: fld.fold_pat(pat), ty: fld.fold_ty(ty),}
}
pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
match *tt {
TokenTree::Token(span, ref tok) =>
TokenTree::Token(span, fld.fold_token(tok.clone())),
TokenTree::Delimited(span, ref delimed) => {
TokenTree::Delimited(span,
Rc::new(Delimited{delim: delimed.delim,
open_span:
delimed.open_span,
tts:
fld.fold_tts(&delimed.tts),
close_span:
delimed.close_span,}))
}
TokenTree::Sequence(span, ref seq) =>
TokenTree::Sequence(span,
Rc::new(SequenceRepetition{tts:
fld.fold_tts(&seq.tts),
separator:
seq.separator.clone().map(|tok|
fld.fold_token(tok)),
..**seq})),
}
}
pub fn noop_fold_tts<T: Folder>(tts: &[TokenTree], fld: &mut T)
-> Vec<TokenTree> {
tts.iter().map(|tt| fld.fold_tt(tt)).collect()
}
pub fn noop_fold_token<T: Folder>(t: token::Token, fld: &mut T)
-> token::Token {
match t {
token::Ident(id, followed_by_colons) => {
token::Ident(fld.fold_ident(id), followed_by_colons)
}
token::Lifetime(id) => token::Lifetime(fld.fold_ident(id)),
token::Interpolated(nt) =>
token::Interpolated(fld.fold_interpolated(nt)),
token::SubstNt(ident, namep) => {
token::SubstNt(fld.fold_ident(ident), namep)
}
token::MatchNt(name, kind, namep, kindp) => {
token::MatchNt(fld.fold_ident(name), fld.fold_ident(kind),
namep, kindp)
}
_ => t,
}
}
/// apply folder to elements of interpolated nodes
pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal,
fld: &mut T)
-> token::Nonterminal {
match nt {
token::NtItem(item) =>
token::NtItem(fld.fold_item(item).expect_one("expected fold to produce exactly one item")),
token::NtBlock(block) => token::NtBlock(fld.fold_block(block)),
token::NtStmt(stmt) =>
token::NtStmt(fld.fold_stmt(stmt).expect_one("expected fold to produce exactly one statement")),
token::NtPat(pat) => token::NtPat(fld.fold_pat(pat)),
token::NtExpr(expr) => token::NtExpr(fld.fold_expr(expr)),
token::NtTy(ty) => token::NtTy(fld.fold_ty(ty)),
token::NtIdent(id, is_mod_name) =>
token::NtIdent(Box::new(Spanned::<Ident>{node:
fld.fold_ident(id.node),
..*id}),
is_mod_name),
token::NtMeta(meta_item) =>
token::NtMeta(fld.fold_meta_item(meta_item)),
token::NtPath(path) =>
token::NtPath(Box::new(fld.fold_path(*path))),
token::NtTT(tt) => token::NtTT(P(fld.fold_tt(&tt))),
token::NtArm(arm) => token::NtArm(fld.fold_arm(arm)),
token::NtImplItem(arm) =>
token::NtImplItem(fld.fold_impl_item(arm).expect_one("expected fold to produce exactly one item")),
token::NtTraitItem(arm) =>
token::NtTraitItem(fld.fold_trait_item(arm).expect_one("expected fold to produce exactly one item")),
token::NtGenerics(generics) =>
token::NtGenerics(fld.fold_generics(generics)),
token::NtWhereClause(where_clause) =>
token::NtWhereClause(fld.fold_where_clause(where_clause)),
token::NtArg(arg) => token::NtArg(fld.fold_arg(arg)),
}
}
pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T)
-> P<FnDecl> {
decl.map(|FnDecl { inputs, output, variadic }|
FnDecl{inputs: inputs.move_map(|x| fld.fold_arg(x)),
output:
match output {
Return(ty) => Return(fld.fold_ty(ty)),
DefaultReturn(span) =>
DefaultReturn(span),
NoReturn(span) => NoReturn(span),
},
variadic: variadic,})
}
pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T)
-> TyParamBound where T: Folder {
match tpb {
TraitTyParamBound(ty, modifier) =>
TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier),
RegionTyParamBound(lifetime) =>
RegionTyParamBound(fld.fold_lifetime(lifetime)),
}
}
pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T)
-> TyParam {
let TyParam { id, ident, bounds, default, span } = tp;
TyParam{id: fld.new_id(id),
ident: ident,
bounds: fld.fold_bounds(bounds),
default: default.map(|x| fld.fold_ty(x)),
span: span,}
}
pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>, fld: &mut T)
-> P<[TyParam]> {
tps.move_map(|tp| fld.fold_ty_param(tp))
}
pub fn noop_fold_lifetime<T: Folder>(l: Lifetime, fld: &mut T)
-> Lifetime {
Lifetime{id: fld.new_id(l.id),
name: l.name,
span: fld.new_span(l.span),}
}
pub fn noop_fold_lifetime_def<T: Folder>(l: LifetimeDef, fld: &mut T)
-> LifetimeDef {
LifetimeDef{lifetime: fld.fold_lifetime(l.lifetime),
bounds: fld.fold_lifetimes(l.bounds),}
}
pub fn noop_fold_lifetimes<T: Folder>(lts: Vec<Lifetime>, fld: &mut T)
-> Vec<Lifetime> {
lts.move_map(|l| fld.fold_lifetime(l))
}
pub fn noop_fold_lifetime_defs<T: Folder>(lts: Vec<LifetimeDef>,
fld: &mut T)
-> Vec<LifetimeDef> {
lts.move_map(|l| fld.fold_lifetime_def(l))
}
pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>,
fld: &mut T)
-> Option<Lifetime> {
o_lt.map(|lt| fld.fold_lifetime(lt))
}
pub fn noop_fold_generics<T: Folder>(Generics {
ty_params,
lifetimes,
where_clause }: Generics,
fld: &mut T) -> Generics {
Generics{ty_params: fld.fold_ty_params(ty_params),
lifetimes: fld.fold_lifetime_defs(lifetimes),
where_clause: fld.fold_where_clause(where_clause),}
}
pub fn noop_fold_where_clause<T: Folder>(WhereClause { id, predicates }:
WhereClause, fld: &mut T)
-> WhereClause {
WhereClause{id: fld.new_id(id),
predicates:
predicates.move_map(|predicate| {
fld.fold_where_predicate(predicate)
}),}
}
pub fn noop_fold_where_predicate<T: Folder>(pred: WherePredicate,
fld: &mut T)
-> WherePredicate {
match pred {
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
bound_lifetimes,
bounded_ty,
bounds,
span }) => {
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{bound_lifetimes:
fld.fold_lifetime_defs(bound_lifetimes),
bounded_ty:
fld.fold_ty(bounded_ty),
bounds:
bounds.move_map(|x|
fld.fold_ty_param_bound(x)),
span:
fld.new_span(span),})
}
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
lifetime, bounds, span }) =>
{
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{span:
fld.new_span(span),
lifetime:
fld.fold_lifetime(lifetime),
bounds:
bounds.move_map(|bound|
fld.fold_lifetime(bound)),})
}
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
id, path, ty, span }) => {
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{id:
fld.new_id(id),
path:
fld.fold_path(path),
ty:
fld.fold_ty(ty),
span:
fld.new_span(span),})
}
}
}
pub fn noop_fold_variant_data<T: Folder>(vdata: VariantData, fld: &mut T)
-> VariantData {
match vdata {
ast::VariantData::Struct(fields, id) => {
ast::VariantData::Struct(fields.move_map(|f|
fld.fold_struct_field(f)),
fld.new_id(id))
}
ast::VariantData::Tuple(fields, id) => {
ast::VariantData::Tuple(fields.move_map(|f|
fld.fold_struct_field(f)),
fld.new_id(id))
}
ast::VariantData::Unit(id) =>
ast::VariantData::Unit(fld.new_id(id)),
}
}
pub fn noop_fold_trait_ref<T: Folder>(p: TraitRef, fld: &mut T)
-> TraitRef {
let id = fld.new_id(p.ref_id);
let TraitRef { path, ref_id: _ } = p;
ast::TraitRef{path: fld.fold_path(path), ref_id: id,}
}
pub fn noop_fold_poly_trait_ref<T: Folder>(p: PolyTraitRef, fld: &mut T)
-> PolyTraitRef {
ast::PolyTraitRef{bound_lifetimes:
fld.fold_lifetime_defs(p.bound_lifetimes),
trait_ref: fld.fold_trait_ref(p.trait_ref),
span: fld.new_span(p.span),}
}
pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T)
-> StructField {
let StructField { node: StructField_ { id, kind, ty, attrs }, span } =
f;
Spanned{node:
StructField_{id: fld.new_id(id),
kind: kind,
ty: fld.fold_ty(ty),
attrs: fold_attrs(attrs, fld),},
span: fld.new_span(span),}
}
pub fn noop_fold_field<T: Folder>(Field { ident, expr, span }: Field,
folder: &mut T) -> Field {
Field{ident: respan(ident.span, folder.fold_ident(ident.node)),
expr: folder.fold_expr(expr),
span: folder.new_span(span),}
}
pub fn noop_fold_mt<T: Folder>(MutTy { ty, mutbl }: MutTy, folder: &mut T)
-> MutTy {
MutTy{ty: folder.fold_ty(ty), mutbl: mutbl,}
}
pub fn noop_fold_opt_bounds<T: Folder>(b: Option<TyParamBounds>,
folder: &mut T)
-> Option<TyParamBounds> {
b.map(|bounds| folder.fold_bounds(bounds))
}
fn noop_fold_bounds<T: Folder>(bounds: TyParamBounds, folder: &mut T)
-> TyParamBounds {
bounds.move_map(|bound| folder.fold_ty_param_bound(bound))
}
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T)
-> P<Block> {
b.map(|Block { id, stmts, expr, rules, span }|
Block{id: folder.new_id(id),
stmts:
stmts.move_flat_map(|s|
folder.fold_stmt(s).into_iter()),
expr: expr.and_then(|x| folder.fold_opt_expr(x)),
rules: rules,
span: folder.new_span(span),})
}
pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T)
-> Item_ {
match i {
ItemExternCrate(string) => ItemExternCrate(string),
ItemUse(view_path) => {
ItemUse(folder.fold_view_path(view_path))
}
ItemStatic(t, m, e) => {
ItemStatic(folder.fold_ty(t), m, folder.fold_expr(e))
}
ItemConst(t, e) => {
ItemConst(folder.fold_ty(t), folder.fold_expr(e))
}
ItemFn(decl, unsafety, constness, abi, generics, body) => {
ItemFn(folder.fold_fn_decl(decl), unsafety, constness, abi,
folder.fold_generics(generics),
folder.fold_block(body))
}
ItemMod(m) => ItemMod(folder.fold_mod(m)),
ItemForeignMod(nm) => ItemForeignMod(folder.fold_foreign_mod(nm)),
ItemTy(t, generics) => {
ItemTy(folder.fold_ty(t), folder.fold_generics(generics))
}
ItemEnum(enum_definition, generics) => {
ItemEnum(ast::EnumDef{variants:
enum_definition.variants.move_map(|x|
folder.fold_variant(x)),},
folder.fold_generics(generics))
}
ItemStruct(struct_def, generics) => {
let struct_def = folder.fold_variant_data(struct_def);
ItemStruct(struct_def, folder.fold_generics(generics))
}
ItemDefaultImpl(unsafety, ref trait_ref) => {
ItemDefaultImpl(unsafety,
folder.fold_trait_ref((*trait_ref).clone()))
}
ItemImpl(unsafety, polarity, generics, ifce, ty, impl_items) => {
let new_impl_items =
impl_items.move_flat_map(|item| {
folder.fold_impl_item(item) });
let ifce =
match ifce {
None => None,
Some(ref trait_ref) => {
Some(folder.fold_trait_ref((*trait_ref).clone()))
}
};
ItemImpl(unsafety, polarity, folder.fold_generics(generics),
ifce, folder.fold_ty(ty), new_impl_items)
}
ItemTrait(unsafety, generics, bounds, items) => {
let bounds = folder.fold_bounds(bounds);
let items =
items.move_flat_map(|item| { folder.fold_trait_item(item)
});
ItemTrait(unsafety, folder.fold_generics(generics), bounds,
items)
}
ItemMac(m) => ItemMac(folder.fold_mac(m)),
}
}
pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
-> SmallVector<P<TraitItem>> {
SmallVector::one(i.map(|TraitItem { id, ident, attrs, node, span }|
TraitItem{id: folder.new_id(id),
ident: folder.fold_ident(ident),
attrs: fold_attrs(attrs, folder),
node:
match node {
ConstTraitItem(ty,
default)
=> {
ConstTraitItem(folder.fold_ty(ty),
default.map(|x|
folder.fold_expr(x)))
}
MethodTraitItem(sig,
body) =>
{
MethodTraitItem(noop_fold_method_sig(sig,
folder),
body.map(|x|
folder.fold_block(x)))
}
TypeTraitItem(bounds,
default) =>
{
TypeTraitItem(folder.fold_bounds(bounds),
default.map(|x|
folder.fold_ty(x)))
}
},
span: folder.new_span(span),}))
}
pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T)
-> SmallVector<P<ImplItem>> {
SmallVector::one(i.map(|ImplItem { id, ident, attrs, node, vis, span
}|
ImplItem{id: folder.new_id(id),
ident: folder.fold_ident(ident),
attrs: fold_attrs(attrs, folder),
vis: vis,
node:
match node {
ast::ImplItemKind::Const(ty,
expr)
=> {
ast::ImplItemKind::Const(folder.fold_ty(ty),
folder.fold_expr(expr))
}
ast::ImplItemKind::Method(sig,
body)
=> {
ast::ImplItemKind::Method(noop_fold_method_sig(sig,
folder),
folder.fold_block(body))
}
ast::ImplItemKind::Type(ty)
=>
ast::ImplItemKind::Type(folder.fold_ty(ty)),
ast::ImplItemKind::Macro(mac)
=>
ast::ImplItemKind::Macro(folder.fold_mac(mac)),
},
span: folder.new_span(span),}))
}
pub fn noop_fold_mod<T: Folder>(Mod { inner, items }: Mod, folder: &mut T)
-> Mod {
Mod{inner: folder.new_span(inner),
items: items.move_flat_map(|x| folder.fold_item(x)),}
}
pub fn noop_fold_crate<T: Folder>(Crate {
module,
attrs,
config,
mut exported_macros,
span }: Crate, folder: &mut T)
-> Crate {
let config = folder.fold_meta_items(config);
let mut items =
folder.fold_item(P(ast::Item{ident:
token::special_idents::invalid,
attrs: attrs,
id: ast::DUMMY_NODE_ID,
vis: ast::Public,
span: span,
node:
ast::ItemMod(module),})).into_iter();
let (module, attrs, span) =
match items.next() {
Some(item) => {
if !items.next().is_none() {
{
::std::rt::begin_unwind("a crate cannot expand to more than one item",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/fold.rs",
1033u32);
&_FILE_LINE
})
}
};
item.and_then(|ast::Item { attrs, span, node, .. }| {
match node {
ast::ItemMod(m) => (m, attrs, span),
_ => {
::std::rt::begin_unwind("fold converted a module to not a module",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/fold.rs",
1038u32);
&_FILE_LINE
})
}
} })
}
None =>
(ast::Mod{inner: span,
items:
<[_]>::into_vec(::std::boxed::Box::new([])),},
<[_]>::into_vec(::std::boxed::Box::new([])), span),
};
for def in &mut exported_macros { def.id = folder.new_id(def.id); }
Crate{module: module,
attrs: attrs,
config: config,
exported_macros: exported_macros,
span: span,}
}
pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T)
-> SmallVector<P<Item>> {
SmallVector::one(i.map(|i| folder.fold_item_simple(i)))
}
pub fn noop_fold_item_simple<T: Folder>(Item {
id,
ident,
attrs,
node,
vis,
span }: Item, folder: &mut T)
-> Item {
let id = folder.new_id(id);
let node = folder.fold_item_underscore(node);
let ident =
match node {
ItemImpl(_, _, _, ref maybe_trait, ref ty, _) => {
ast_util::impl_pretty_name(maybe_trait, Some(&**ty))
}
_ => ident,
};
Item{id: id,
ident: folder.fold_ident(ident),
attrs: fold_attrs(attrs, folder),
node: node,
vis: vis,
span: folder.new_span(span),}
}
pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>,
folder: &mut T)
-> P<ForeignItem> {
ni.map(|ForeignItem { id, ident, attrs, node, span, vis }|
ForeignItem{id: folder.new_id(id),
ident: folder.fold_ident(ident),
attrs: fold_attrs(attrs, folder),
node:
match node {
ForeignItemFn(fdec, generics) => {
ForeignItemFn(folder.fold_fn_decl(fdec),
folder.fold_generics(generics))
}
ForeignItemStatic(t, m) => {
ForeignItemStatic(folder.fold_ty(t),
m)
}
},
vis: vis,
span: folder.new_span(span),})
}
pub fn noop_fold_method_sig<T: Folder>(sig: MethodSig, folder: &mut T)
-> MethodSig {
MethodSig{generics: folder.fold_generics(sig.generics),
abi: sig.abi,
explicit_self: folder.fold_explicit_self(sig.explicit_self),
unsafety: sig.unsafety,
constness: sig.constness,
decl: folder.fold_fn_decl(sig.decl),}
}
pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
p.map(|Pat { id, node, span }|
Pat{id: folder.new_id(id),
node:
match node {
PatWild => PatWild,
PatIdent(binding_mode, pth1, sub) => {
PatIdent(binding_mode,
Spanned{span:
folder.new_span(pth1.span),
node:
folder.fold_ident(pth1.node),},
sub.map(|x| folder.fold_pat(x)))
}
PatLit(e) => PatLit(folder.fold_expr(e)),
PatEnum(pth, pats) => {
PatEnum(folder.fold_path(pth),
pats.map(|pats|
pats.move_map(|x|
folder.fold_pat(x))))
}
PatQPath(qself, pth) => {
let qself =
QSelf{ty:
folder.fold_ty(qself.ty),
..qself};
PatQPath(qself, folder.fold_path(pth))
}
PatStruct(pth, fields, etc) => {
let pth = folder.fold_path(pth);
let fs =
fields.move_map(|f| {
Spanned{span:
folder.new_span(f.span),
node:
ast::FieldPat{ident:
f.node.ident,
pat:
folder.fold_pat(f.node.pat),
is_shorthand:
f.node.is_shorthand,},}
});
PatStruct(pth, fs, etc)
}
PatTup(elts) =>
PatTup(elts.move_map(|x| folder.fold_pat(x))),
PatBox(inner) => PatBox(folder.fold_pat(inner)),
PatRegion(inner, mutbl) =>
PatRegion(folder.fold_pat(inner), mutbl),
PatRange(e1, e2) => {
PatRange(folder.fold_expr(e1),
folder.fold_expr(e2))
}
PatVec(before, slice, after) => {
PatVec(before.move_map(|x|
folder.fold_pat(x)),
slice.map(|x| folder.fold_pat(x)),
after.move_map(|x|
folder.fold_pat(x)))
}
PatMac(mac) => PatMac(folder.fold_mac(mac)),
},
span: folder.new_span(span),})
}
pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr,
folder: &mut T) -> Expr {
Expr{id: folder.new_id(id),
node:
match node {
ExprBox(e) => { ExprBox(folder.fold_expr(e)) }
ExprInPlace(p, e) => {
ExprInPlace(folder.fold_expr(p), folder.fold_expr(e))
}
ExprVec(exprs) => { ExprVec(folder.fold_exprs(exprs)) }
ExprRepeat(expr, count) => {
ExprRepeat(folder.fold_expr(expr),
folder.fold_expr(count))
}
ExprTup(exprs) => ExprTup(folder.fold_exprs(exprs)),
ExprCall(f, args) => {
ExprCall(folder.fold_expr(f),
folder.fold_exprs(args))
}
ExprMethodCall(i, tps, args) => {
ExprMethodCall(respan(folder.new_span(i.span),
folder.fold_ident(i.node)),
tps.move_map(|x| folder.fold_ty(x)),
folder.fold_exprs(args))
}
ExprBinary(binop, lhs, rhs) => {
ExprBinary(binop, folder.fold_expr(lhs),
folder.fold_expr(rhs))
}
ExprUnary(binop, ohs) => {
ExprUnary(binop, folder.fold_expr(ohs))
}
ExprLit(l) => ExprLit(l),
ExprCast(expr, ty) => {
ExprCast(folder.fold_expr(expr), folder.fold_ty(ty))
}
ExprType(expr, ty) => {
ExprType(folder.fold_expr(expr), folder.fold_ty(ty))
}
ExprAddrOf(m, ohs) =>
ExprAddrOf(m, folder.fold_expr(ohs)),
ExprIf(cond, tr, fl) => {
ExprIf(folder.fold_expr(cond), folder.fold_block(tr),
fl.map(|x| folder.fold_expr(x)))
}
ExprIfLet(pat, expr, tr, fl) => {
ExprIfLet(folder.fold_pat(pat),
folder.fold_expr(expr),
folder.fold_block(tr),
fl.map(|x| folder.fold_expr(x)))
}
ExprWhile(cond, body, opt_ident) => {
ExprWhile(folder.fold_expr(cond),
folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
}
ExprWhileLet(pat, expr, body, opt_ident) => {
ExprWhileLet(folder.fold_pat(pat),
folder.fold_expr(expr),
folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
}
ExprForLoop(pat, iter, body, opt_ident) => {
ExprForLoop(folder.fold_pat(pat),
folder.fold_expr(iter),
folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
}
ExprLoop(body, opt_ident) => {
ExprLoop(folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
}
ExprMatch(expr, arms) => {
ExprMatch(folder.fold_expr(expr),
arms.move_map(|x| folder.fold_arm(x)))
}
ExprClosure(capture_clause, decl, body) => {
ExprClosure(capture_clause,
folder.fold_fn_decl(decl),
folder.fold_block(body))
}
ExprBlock(blk) => ExprBlock(folder.fold_block(blk)),
ExprAssign(el, er) => {
ExprAssign(folder.fold_expr(el),
folder.fold_expr(er))
}
ExprAssignOp(op, el, er) => {
ExprAssignOp(op, folder.fold_expr(el),
folder.fold_expr(er))
}
ExprField(el, ident) => {
ExprField(folder.fold_expr(el),
respan(folder.new_span(ident.span),
folder.fold_ident(ident.node)))
}
ExprTupField(el, ident) => {
ExprTupField(folder.fold_expr(el),
respan(folder.new_span(ident.span),
folder.fold_usize(ident.node)))
}
ExprIndex(el, er) => {
ExprIndex(folder.fold_expr(el), folder.fold_expr(er))
}
ExprRange(e1, e2) => {
ExprRange(e1.map(|x| folder.fold_expr(x)),
e2.map(|x| folder.fold_expr(x)))
}
ExprPath(qself, path) => {
let qself =
qself.map(|QSelf { ty, position }| {
QSelf{ty: folder.fold_ty(ty),
position: position,} });
ExprPath(qself, folder.fold_path(path))
}
ExprBreak(opt_ident) =>
ExprBreak(opt_ident.map(|label|
respan(folder.new_span(label.span),
folder.fold_ident(label.node)))),
ExprAgain(opt_ident) =>
ExprAgain(opt_ident.map(|label|
respan(folder.new_span(label.span),
folder.fold_ident(label.node)))),
ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))),
ExprInlineAsm(InlineAsm {
inputs,
outputs,
asm,
asm_str_style,
clobbers,
volatile,
alignstack,
dialect,
expn_id }) =>
ExprInlineAsm(InlineAsm{inputs:
inputs.move_map(|(c, input)|
{
(c,
folder.fold_expr(input))
}),
outputs:
outputs.move_map(|out| {
InlineAsmOutput{constraint:
out.constraint,
expr:
folder.fold_expr(out.expr),
is_rw:
out.is_rw,
is_indirect:
out.is_indirect,}
}),
asm: asm,
asm_str_style: asm_str_style,
clobbers: clobbers,
volatile: volatile,
alignstack: alignstack,
dialect: dialect,
expn_id: expn_id,}),
ExprMac(mac) => ExprMac(folder.fold_mac(mac)),
ExprStruct(path, fields, maybe_expr) => {
ExprStruct(folder.fold_path(path),
fields.move_map(|x| folder.fold_field(x)),
maybe_expr.map(|x| folder.fold_expr(x)))
}
ExprParen(ex) => ExprParen(folder.fold_expr(ex)),
},
span: folder.new_span(span),
attrs: attrs.map_thin_attrs(|v| fold_attrs(v, folder)),}
}
pub fn noop_fold_opt_expr<T: Folder>(e: P<Expr>, folder: &mut T)
-> Option<P<Expr>> {
Some(folder.fold_expr(e))
}
pub fn noop_fold_exprs<T: Folder>(es: Vec<P<Expr>>, folder: &mut T)
-> Vec<P<Expr>> {
es.move_flat_map(|e| folder.fold_opt_expr(e))
}
pub fn noop_fold_stmt<T: Folder>(Spanned { node, span }: Stmt,
folder: &mut T) -> SmallVector<P<Stmt>> {
let span = folder.new_span(span);
match node {
StmtDecl(d, id) => {
let id = folder.new_id(id);
folder.fold_decl(d).into_iter().map(|d|
P(Spanned{node:
StmtDecl(d,
id),
span:
span,})).collect()
}
StmtExpr(e, id) => {
let id = folder.new_id(id);
if let Some(e) = folder.fold_opt_expr(e) {
SmallVector::one(P(Spanned{node: StmtExpr(e, id),
span: span,}))
} else { SmallVector::zero() }
}
StmtSemi(e, id) => {
let id = folder.new_id(id);
if let Some(e) = folder.fold_opt_expr(e) {
SmallVector::one(P(Spanned{node: StmtSemi(e, id),
span: span,}))
} else { SmallVector::zero() }
}
StmtMac(mac, semi, attrs) =>
SmallVector::one(P(Spanned{node:
StmtMac(mac.map(|m|
folder.fold_mac(m)),
semi,
attrs.map_thin_attrs(|v|
fold_attrs(v,
folder))),
span: span,})),
}
}
}
pub mod owned_slice {
#[prelude_import]
use std::prelude::v1::*;
/// A non-growable owned slice.
pub type OwnedSlice<T> = ::ptr::P<[T]>;
}
pub mod parse {
//! The main parser interface
#[prelude_import]
use std::prelude::v1::*;
use ast;
use codemap::{self, Span, CodeMap, FileMap};
use errors::{Handler, ColorConfig, DiagnosticBuilder};
use parse::parser::Parser;
use parse::token::InternedString;
use ptr::P;
use str::char_at;
use std::cell::RefCell;
use std::io::Read;
use std::iter;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str;
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;
#[macro_use]
pub mod parser {
#[prelude_import]
use std::prelude::v1::*;
pub use self::PathParsingMode::*;
use abi;
use ast::BareFnTy;
use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::{Public, Unsafety};
use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindingMode};
use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block};
use ast::{BlockCheckMode, CaptureByRef, CaptureByValue,
CaptureClause};
use ast::{Constness, ConstTraitItem, Crate, CrateConfig};
use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn};
use ast::{UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf};
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace};
use ast::{ExprField, ExprTupField, ExprClosure, ExprIf, ExprIfLet,
ExprIndex};
use ast::{ExprLit, ExprLoop, ExprMac, ExprRange};
use ast::{ExprMethodCall, ExprParen, ExprPath};
use ast::{ExprRepeat, ExprRet, ExprStruct, ExprTup, ExprType,
ExprUnary};
use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field,
FnDecl};
use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn,
FunctionRetTy};
use ast::{Ident, Inherited, ImplItem, Item, Item_, ItemStatic};
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy,
ItemDefaultImpl};
use ast::{ItemExternCrate, ItemUse};
use ast::{Lit, Lit_};
use ast::{LitBool, LitChar, LitByte, LitByteStr};
use ast::{LitStr, LitInt, Local};
use ast::{MacStmtWithBraces, MacStmtWithSemicolon,
MacStmtWithoutBraces};
use ast::{MutImmutable, MutMutable, Mac_};
use ast::{MutTy, BiMul, Mutability};
use ast::{NamedField, UnNeg, NoReturn, UnNot};
use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac,
PatRange};
use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild};
use ast::{PolyTraitRef, QSelf};
use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField};
use ast::{BiSub, StrStyle};
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem,
TraitRef};
use ast::{Ty, Ty_, TypeBinding, TyMac};
use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer};
use ast::{TyParam, TyParamBounds, TyParen, TyPath, TyPtr};
use ast::{TyRptr, TyTup, TyU32, TyVec};
use ast::TypeTraitItem;
use ast::{UnnamedField, UnsafeBlock};
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
use ast::{Visibility, WhereClause};
use attr::{ThinAttributes, ThinAttributesExt, AttributesExt};
use ast;
use ast_util::{self, ident_to_path};
use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap};
use errors::{self, DiagnosticBuilder};
use ext::tt::macro_parser;
use parse;
use parse::classify;
use parse::common::{SeqSep, seq_sep_none, seq_sep_trailing_allowed};
use parse::lexer::{Reader, TokenAndSpan};
use parse::obsolete::{ParserObsoleteMethods, ObsoleteSyntax};
use parse::token::{self, intern, MatchNt, SubstNt, SpecialVarNt,
InternedString};
use parse::token::{keywords, special_idents, SpecialMacroVar};
use parse::{new_sub_parser_from_file, ParseSess};
use util::parser::{AssocOp, Fixity};
use print::pprust;
use ptr::P;
use parse::PResult;
use std::collections::HashSet;
use std::io::prelude::*;
use std::mem;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::slice;
pub struct Restrictions {
bits: u8,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Restrictions {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match *self {
Restrictions { bits: ref __self_0_0 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Ord for Restrictions {
#[inline]
fn cmp(&self, __arg_0: &Restrictions) -> ::std::cmp::Ordering {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } => {
let __test =
::std::cmp::Ord::cmp(&(*__self_0_0),
&(*__self_1_0));
if __test == ::std::cmp::Ordering::Equal {
::std::cmp::Ordering::Equal
} else { __test }
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for Restrictions {
#[inline]
fn partial_cmp(&self, __arg_0: &Restrictions)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &Restrictions) -> bool {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &Restrictions) -> bool {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &Restrictions) -> bool {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &Restrictions) -> bool {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Restrictions {
#[inline]
fn clone(&self) -> Restrictions {
match *self {
Restrictions { bits: ref __self_0_0 } =>
Restrictions{bits:
::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Restrictions {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
Restrictions { bits: ref __self_0_0 } => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Restrictions {
#[inline]
fn eq(&self, __arg_0: &Restrictions) -> bool {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &Restrictions) -> bool {
match *__arg_0 {
Restrictions { bits: ref __self_1_0 } =>
match *self {
Restrictions { bits: ref __self_0_0 } =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Restrictions { }
pub const RESTRICTION_STMT_EXPR: Restrictions =
Restrictions{bits: 1 << 0,};
pub const RESTRICTION_NO_STRUCT_LITERAL: Restrictions =
Restrictions{bits: 1 << 1,};
impl ::bitflags::__core::fmt::Debug for Restrictions {
fn fmt(&self, f: &mut ::bitflags::__core::fmt::Formatter)
-> ::bitflags::__core::fmt::Result {
#[allow(dead_code)]
#[allow(unused_assignments)]
mod dummy {
#[prelude_import]
use std::prelude::v1::*;
const RESTRICTION_STMT_EXPR: super::Restrictions =
super::Restrictions{bits: 0,};
const RESTRICTION_NO_STRUCT_LITERAL: super::Restrictions =
super::Restrictions{bits: 0,};
#[inline]
pub fn fmt(self_: &super::Restrictions,
f: &mut ::bitflags::__core::fmt::Formatter)
-> ::bitflags::__core::fmt::Result {
use super::*;
let mut first = true;
if RESTRICTION_STMT_EXPR.bits != 0 &&
self_.contains(RESTRICTION_STMT_EXPR) {
if !first {
match f.write_str(" | ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
first = false;
match f.write_str("RESTRICTION_STMT_EXPR") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if RESTRICTION_NO_STRUCT_LITERAL.bits != 0 &&
self_.contains(RESTRICTION_NO_STRUCT_LITERAL) {
if !first {
match f.write_str(" | ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
first = false;
match f.write_str("RESTRICTION_NO_STRUCT_LITERAL")
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
}
dummy::fmt(self, f)
}
}
#[allow(dead_code)]
impl Restrictions {
/// Returns an empty set of flags.
#[inline]
pub fn empty() -> Restrictions { Restrictions{bits: 0,} }
/// Returns the set containing all flags.
#[inline]
pub fn all() -> Restrictions {
#[allow(dead_code)]
mod dummy {
#[prelude_import]
use std::prelude::v1::*;
const RESTRICTION_STMT_EXPR: super::Restrictions =
super::Restrictions{bits: 0,};
const RESTRICTION_NO_STRUCT_LITERAL: super::Restrictions =
super::Restrictions{bits: 0,};
#[inline]
pub fn all() -> super::Restrictions {
use super::*;
Restrictions{bits:
RESTRICTION_STMT_EXPR.bits |
RESTRICTION_NO_STRUCT_LITERAL.bits,}
}
}
dummy::all()
}
/// Returns the raw value of the flags currently stored.
#[inline]
pub fn bits(&self) -> u8 { self.bits }
/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
#[inline]
pub fn from_bits(bits: u8)
-> ::bitflags::__core::option::Option<Restrictions> {
if (bits & !Restrictions::all().bits()) != 0 {
::bitflags::__core::option::Option::None
} else {
::bitflags::__core::option::Option::Some(Restrictions{bits:
bits,})
}
}
/// Convert from underlying bit representation, dropping any bits
/// that do not correspond to flags.
#[inline]
pub fn from_bits_truncate(bits: u8) -> Restrictions {
Restrictions{bits: bits,} & Restrictions::all()
}
/// Returns `true` if no flags are currently stored.
#[inline]
pub fn is_empty(&self) -> bool { *self == Restrictions::empty() }
/// Returns `true` if all flags are currently set.
#[inline]
pub fn is_all(&self) -> bool { *self == Restrictions::all() }
/// Returns `true` if there are flags common to both `self` and `other`.
#[inline]
pub fn intersects(&self, other: Restrictions) -> bool {
!(*self & other).is_empty()
}
/// Returns `true` all of the flags in `other` are contained within `self`.
#[inline]
pub fn contains(&self, other: Restrictions) -> bool {
(*self & other) == other
}
/// Inserts the specified flags in-place.
#[inline]
pub fn insert(&mut self, other: Restrictions) {
self.bits |= other.bits;
}
/// Removes the specified flags in-place.
#[inline]
pub fn remove(&mut self, other: Restrictions) {
self.bits &= !other.bits;
}
/// Toggles the specified flags in-place.
#[inline]
pub fn toggle(&mut self, other: Restrictions) {
self.bits ^= other.bits;
}
}
impl ::bitflags::__core::ops::BitOr for Restrictions {
type
Output
=
Restrictions;
/// Returns the union of the two sets of flags.
#[inline]
fn bitor(self, other: Restrictions) -> Restrictions {
Restrictions{bits: self.bits | other.bits,}
}
}
impl ::bitflags::__core::ops::BitXor for Restrictions {
type
Output
=
Restrictions;
/// Returns the left flags, but with all the right flags toggled.
#[inline]
fn bitxor(self, other: Restrictions) -> Restrictions {
Restrictions{bits: self.bits ^ other.bits,}
}
}
impl ::bitflags::__core::ops::BitAnd for Restrictions {
type
Output
=
Restrictions;
/// Returns the intersection between the two sets of flags.
#[inline]
fn bitand(self, other: Restrictions) -> Restrictions {
Restrictions{bits: self.bits & other.bits,}
}
}
impl ::bitflags::__core::ops::Sub for Restrictions {
type
Output
=
Restrictions;
/// Returns the set difference of the two sets of flags.
#[inline]
fn sub(self, other: Restrictions) -> Restrictions {
Restrictions{bits: self.bits & !other.bits,}
}
}
impl ::bitflags::__core::ops::Not for Restrictions {
type
Output
=
Restrictions;
/// Returns the complement of this set of flags.
#[inline]
fn not(self) -> Restrictions {
Restrictions{bits: !self.bits,} & Restrictions::all()
}
}
impl ::bitflags::__core::iter::FromIterator<Restrictions> for
Restrictions {
fn from_iter<T: ::bitflags::__core::iter::IntoIterator<Item =
Restrictions>>(iterator: T) -> Restrictions {
let mut result = Self::empty();
for item in iterator { result.insert(item) }
result
}
}
type ItemInfo = (Ident, Item_, Option<Vec<Attribute>>);
/// How to parse a path. There are four different kinds of paths, all of which
/// are parsed somewhat differently.
pub enum PathParsingMode {
/// A path with no type parameters; e.g. `foo::bar::Baz`
NoTypesAllowed,
/// A path with a lifetime and type parameters, with no double colons
/// before the type parameters; e.g. `foo::bar<'a>::Baz<T>`
LifetimeAndTypesWithoutColons,
/// A path with a lifetime and type parameters with double colons before
/// the type parameters; e.g. `foo::bar::<'a>::Baz::<T>`
LifetimeAndTypesWithColons,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for PathParsingMode {
#[inline]
fn eq(&self, __arg_0: &PathParsingMode) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PathParsingMode::NoTypesAllowed,
&PathParsingMode::NoTypesAllowed) => true,
(&PathParsingMode::LifetimeAndTypesWithoutColons,
&PathParsingMode::LifetimeAndTypesWithoutColons)
=> true,
(&PathParsingMode::LifetimeAndTypesWithColons,
&PathParsingMode::LifetimeAndTypesWithColons) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &PathParsingMode) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&PathParsingMode::NoTypesAllowed,
&PathParsingMode::NoTypesAllowed) => false,
(&PathParsingMode::LifetimeAndTypesWithoutColons,
&PathParsingMode::LifetimeAndTypesWithoutColons)
=> false,
(&PathParsingMode::LifetimeAndTypesWithColons,
&PathParsingMode::LifetimeAndTypesWithColons) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PathParsingMode {
#[inline]
fn clone(&self) -> PathParsingMode {
match (&*self,) {
(&PathParsingMode::NoTypesAllowed,) =>
PathParsingMode::NoTypesAllowed,
(&PathParsingMode::LifetimeAndTypesWithoutColons,) =>
PathParsingMode::LifetimeAndTypesWithoutColons,
(&PathParsingMode::LifetimeAndTypesWithColons,) =>
PathParsingMode::LifetimeAndTypesWithColons,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for PathParsingMode { }
/// How to parse a bound, whether to allow bound modifiers such as `?`.
pub enum BoundParsingMode { Bare, Modified, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for BoundParsingMode {
#[inline]
fn eq(&self, __arg_0: &BoundParsingMode) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BoundParsingMode::Bare, &BoundParsingMode::Bare)
=> true,
(&BoundParsingMode::Modified,
&BoundParsingMode::Modified) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &BoundParsingMode) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BoundParsingMode::Bare, &BoundParsingMode::Bare)
=> false,
(&BoundParsingMode::Modified,
&BoundParsingMode::Modified) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BoundParsingMode {
#[inline]
fn clone(&self) -> BoundParsingMode {
match (&*self,) {
(&BoundParsingMode::Bare,) => BoundParsingMode::Bare,
(&BoundParsingMode::Modified,) =>
BoundParsingMode::Modified,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BoundParsingMode { }
/// `pub` should be parsed in struct fields and not parsed in variant fields
pub enum ParsePub { Yes, No, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ParsePub {
#[inline]
fn eq(&self, __arg_0: &ParsePub) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ParsePub::Yes, &ParsePub::Yes) => true,
(&ParsePub::No, &ParsePub::No) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ParsePub) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ParsePub::Yes, &ParsePub::Yes) => false,
(&ParsePub::No, &ParsePub::No) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ParsePub { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ParsePub {
#[inline]
fn clone(&self) -> ParsePub {
match (&*self,) {
(&ParsePub::Yes,) => ParsePub::Yes,
(&ParsePub::No,) => ParsePub::No,
}
}
}
fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
-> Vec<Attribute> {
if let Some(ref attrs) = rhs { lhs.extend(attrs.iter().cloned()) }
lhs
}
pub struct Parser<'a> {
pub sess: &'a ParseSess,
/// the current token:
pub token: token::Token,
/// the span of the current token:
pub span: Span,
/// the span of the prior token:
pub last_span: Span,
pub cfg: CrateConfig,
/// the previous token or None (only stashed sometimes).
pub last_token: Option<Box<token::Token>>,
pub buffer: [TokenAndSpan; 4],
pub buffer_start: isize,
pub buffer_end: isize,
pub tokens_consumed: usize,
pub restrictions: Restrictions,
pub quote_depth: usize,
pub reader: Box<Reader+ 'a>,
pub interner: Rc<token::IdentInterner>,
/// The set of seen errors about obsolete syntax. Used to suppress
/// extra detail when the same error is seen twice
pub obsolete_set: HashSet<ObsoleteSyntax>,
/// Used to determine the path to externally loaded source files
pub mod_path_stack: Vec<InternedString>,
/// Stack of spans of open delimiters. Used for error message.
pub open_braces: Vec<Span>,
/// Flag if this parser "owns" the directory that it is currently parsing
/// in. This will affect how nested files are looked up.
pub owns_directory: bool,
/// Name of the root module this parser originated from. If `None`, then the
/// name is not known. This does not change while the parser is descending
/// into modules, and sub-parsers have new values for this name.
pub root_module_name: Option<String>,
pub expected_tokens: Vec<TokenType>,
}
pub enum TokenType {
Token(token::Token),
Keyword(keywords::Keyword),
Operator,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TokenType {
#[inline]
fn clone(&self) -> TokenType {
match (&*self,) {
(&TokenType::Token(ref __self_0),) =>
TokenType::Token(::std::clone::Clone::clone(&(*__self_0))),
(&TokenType::Keyword(ref __self_0),) =>
TokenType::Keyword(::std::clone::Clone::clone(&(*__self_0))),
(&TokenType::Operator,) => TokenType::Operator,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TokenType {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&TokenType::Token(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&TokenType::Keyword(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&TokenType::Operator,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TokenType {
#[inline]
fn eq(&self, __arg_0: &TokenType) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TokenType::Token(ref __self_0),
&TokenType::Token(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&TokenType::Keyword(ref __self_0),
&TokenType::Keyword(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&TokenType::Operator, &TokenType::Operator) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &TokenType) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&TokenType::Token(ref __self_0),
&TokenType::Token(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&TokenType::Keyword(ref __self_0),
&TokenType::Keyword(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&TokenType::Operator, &TokenType::Operator) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
impl TokenType {
fn to_string(&self) -> String {
match *self {
TokenType::Token(ref t) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["`",
"`"];
__STATIC_FMTSTR
},
&match (&Parser::token_to_string(t),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
TokenType::Operator => "an operator".to_string(),
TokenType::Keyword(kw) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["`",
"`"];
__STATIC_FMTSTR
},
&match (&kw.to_name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
}
}
}
fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
t.is_plain_ident() || *t == token::Underscore
}
/// Information about the path to a module.
pub struct ModulePath {
pub name: String,
pub path_exists: bool,
pub result: Result<ModulePathSuccess, ModulePathError>,
}
pub struct ModulePathSuccess {
pub path: ::std::path::PathBuf,
pub owns_directory: bool,
}
pub struct ModulePathError {
pub err_msg: String,
pub help_msg: String,
}
pub enum LhsExpr {
NotYetParsed,
AttributesParsed(ThinAttributes),
AlreadyParsed(P<Expr>),
}
impl From<Option<ThinAttributes>> for LhsExpr {
fn from(o: Option<ThinAttributes>) -> Self {
if let Some(attrs) = o {
LhsExpr::AttributesParsed(attrs)
} else { LhsExpr::NotYetParsed }
}
}
impl From<P<Expr>> for LhsExpr {
fn from(expr: P<Expr>) -> Self { LhsExpr::AlreadyParsed(expr) }
}
impl <'a> Parser<'a> {
pub fn new(sess: &'a ParseSess, cfg: ast::CrateConfig,
mut rdr: Box<Reader+ 'a>) -> Parser<'a> {
let tok0 = rdr.real_token();
let span = tok0.sp;
let placeholder =
TokenAndSpan{tok: token::Underscore, sp: span,};
Parser{reader: rdr,
interner: token::get_ident_interner(),
sess: sess,
cfg: cfg,
token: tok0.tok,
span: span,
last_span: span,
last_token: None,
buffer:
[placeholder.clone(), placeholder.clone(),
placeholder.clone(), placeholder.clone()],
buffer_start: 0,
buffer_end: 0,
tokens_consumed: 0,
restrictions: Restrictions::empty(),
quote_depth: 0,
obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(),
open_braces: Vec::new(),
owns_directory: true,
root_module_name: None,
expected_tokens: Vec::new(),}
}
/// Convert a token to a string using self's reader
pub fn token_to_string(token: &token::Token) -> String {
pprust::token_to_string(token)
}
/// Convert the current token to a string using self's reader
pub fn this_token_to_string(&self) -> String {
Parser::token_to_string(&self.token)
}
pub fn unexpected_last<T>(&self, t: &token::Token)
-> PResult<'a, T> {
let token_str = Parser::token_to_string(t);
let last_span = self.last_span;
Err(self.span_fatal(last_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unexpected token: `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
pub fn unexpected<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) {
Err(e) => Err(e),
Ok(_) => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/parser.rs",
404u32);
&_FILE_LINE
})
}
}
}
}
/// Expect and consume the token t. Signal an error if
/// the next token is not t.
pub fn expect(&mut self, t: &token::Token) -> PResult<'a, ()> {
if self.expected_tokens.is_empty() {
if self.token == *t {
self.bump();
Ok(())
} else {
let token_str = Parser::token_to_string(t);
let this_token_str = self.this_token_to_string();
Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `",
"`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,
&this_token_str)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))))
}
} else {
self.expect_one_of(unsafe { slice::from_raw_parts(t, 1) },
&[])
}
}
/// Expect next token to be edible or inedible token. If edible,
/// then consume it; if inedible, then return without consuming
/// anything. Signal a fatal error if next token is unexpected.
pub fn expect_one_of(&mut self, edible: &[token::Token],
inedible: &[token::Token])
-> PResult<'a, ()> {
fn tokens_to_string(tokens: &[TokenType]) -> String {
let mut i = tokens.iter();
let b =
i.next().map_or("".to_string(), |t| t.to_string());
i.enumerate().fold(b, |mut b, (i, ref a)| {
if tokens.len() > 2 &&
i == tokens.len() - 2 {
b.push_str(", or ");
} else if tokens.len() == 2 &&
i == tokens.len() - 2 {
b.push_str(" or ");
} else { b.push_str(", "); }
b.push_str(&*a.to_string()); b })
}
if edible.contains(&self.token) {
self.bump();
Ok(())
} else if inedible.contains(&self.token) {
Ok(())
} else {
let mut expected =
edible.iter().map(|x|
TokenType::Token(x.clone())).chain(inedible.iter().map(|x|
TokenType::Token(x.clone()))).chain(self.expected_tokens.iter().cloned()).collect::<Vec<_>>();
expected.sort_by(|a, b|
a.to_string().cmp(&b.to_string()));
expected.dedup();
let expect = tokens_to_string(&expected[..]);
let actual = self.this_token_to_string();
Err(self.fatal(&(if expected.len() > 1 {
(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected one of ",
", found `",
"`"];
__STATIC_FMTSTR
},
&match (&expect,
&actual)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})))
} else if expected.is_empty() {
(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unexpected token: `",
"`"];
__STATIC_FMTSTR
},
&match (&actual,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
} else {
(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected ",
", found `",
"`"];
__STATIC_FMTSTR
},
&match (&expect,
&actual)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})))
})[..]))
}
}
/// Check for erroneous `ident { }`; if matches, signal error and
/// recover (without consuming any expected input token). Returns
/// true if and only if input was consumed for recovery.
pub fn check_for_erroneous_unit_struct_expecting(&mut self,
expected:
&[token::Token])
-> bool {
if self.token == token::OpenDelim(token::Brace) &&
expected.iter().all(|t|
*t !=
token::OpenDelim(token::Brace))
&&
self.look_ahead(1,
|t|
*t ==
token::CloseDelim(token::Brace))
{
let span = self.span;
self.span_err(span,
"unit-like struct construction is written with no trailing `{ }`");
self.eat(&token::OpenDelim(token::Brace));
self.eat(&token::CloseDelim(token::Brace));
true
} else { false }
}
/// Commit to parsing a complete expression `e` expected to be
/// followed by some token from the set edible + inedible. Recover
/// from anticipated input errors, discarding erroneous characters.
pub fn commit_expr(&mut self, e: &Expr, edible: &[token::Token],
inedible: &[token::Token]) -> PResult<'a, ()> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 508u32,
__file: "src/parse/parser.rs",
__module_path:
"syntex_syntax::parse::parser",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::parser",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["commit_expr "];
__STATIC_FMTSTR
},
&match (&e,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
if let ExprPath(..) = e.node {
let expected =
edible.iter().cloned().chain(inedible.iter().cloned()).collect::<Vec<_>>();
self.check_for_erroneous_unit_struct_expecting(&expected[..]);
}
self.expect_one_of(edible, inedible)
}
pub fn commit_expr_expecting(&mut self, e: &Expr,
edible: token::Token)
-> PResult<'a, ()> {
self.commit_expr(e, &[edible], &[])
}
/// Commit to parsing a complete statement `s`, which expects to be
/// followed by some token from the set edible + inedible. Check
/// for recoverable input errors, discarding erroneous characters.
pub fn commit_stmt(&mut self, edible: &[token::Token],
inedible: &[token::Token]) -> PResult<'a, ()> {
if self.last_token.as_ref().map_or(false,
|t|
t.is_ident() ||
t.is_path()) {
let expected =
edible.iter().cloned().chain(inedible.iter().cloned()).collect::<Vec<_>>();
self.check_for_erroneous_unit_struct_expecting(&expected);
}
self.expect_one_of(edible, inedible)
}
pub fn commit_stmt_expecting(&mut self, edible: token::Token)
-> PResult<'a, ()> {
self.commit_stmt(&[edible], &[])
}
pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
self.check_strict_keywords();
self.check_reserved_keywords();
match self.token {
token::Ident(i, _) => { self.bump(); Ok(i) }
token::Interpolated(token::NtIdent(..)) => {
self.bug("ident interpolation not converted to real token");
}
_ => {
let token_str = self.this_token_to_string();
Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected ident, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
}
}
pub fn parse_ident_or_self_type(&mut self)
-> PResult<'a, ast::Ident> {
if self.is_self_type_ident() {
self.expect_self_type_ident()
} else { self.parse_ident() }
}
pub fn parse_path_list_item(&mut self)
-> PResult<'a, ast::PathListItem> {
let lo = self.span.lo;
let node =
if self.eat_keyword(keywords::SelfValue) {
let rename =
match self.parse_rename() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
ast::PathListMod{id: ast::DUMMY_NODE_ID,
rename: rename,}
} else {
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let rename =
match self.parse_rename() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
ast::PathListIdent{name: ident,
rename: rename,
id: ast::DUMMY_NODE_ID,}
};
let hi = self.last_span.hi;
Ok(spanned(lo, hi, node))
}
/// Check if the next token is `tok`, and return `true` if so.
///
/// This method is will automatically add `tok` to `expected_tokens` if `tok` is not
/// encountered.
pub fn check(&mut self, tok: &token::Token) -> bool {
let is_present = self.token == *tok;
if !is_present {
self.expected_tokens.push(TokenType::Token(tok.clone()));
}
is_present
}
/// Consume token 'tok' if it exists. Returns true if the given
/// token was present, false otherwise.
pub fn eat(&mut self, tok: &token::Token) -> bool {
let is_present = self.check(tok);
if is_present { self.bump() }
is_present
}
pub fn check_keyword(&mut self, kw: keywords::Keyword) -> bool {
self.expected_tokens.push(TokenType::Keyword(kw));
self.token.is_keyword(kw)
}
/// If the next token is the given keyword, eat it and return
/// true. Otherwise, return false.
pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool {
if self.check_keyword(kw) { self.bump(); true } else { false }
}
pub fn eat_keyword_noexpect(&mut self, kw: keywords::Keyword)
-> bool {
if self.token.is_keyword(kw) {
self.bump();
true
} else { false }
}
/// If the given word is not a keyword, signal an error.
/// If the next token is not the given word, signal an error.
/// Otherwise, eat it.
pub fn expect_keyword(&mut self, kw: keywords::Keyword)
-> PResult<'a, ()> {
if !self.eat_keyword(kw) { self.unexpected() } else { Ok(()) }
}
/// Signal an error if the given string is a strict keyword
pub fn check_strict_keywords(&mut self) {
if self.token.is_strict_keyword() {
let token_str = self.this_token_to_string();
let span = self.span;
self.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected identifier, found keyword `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
}
/// Signal an error if the current token is a reserved keyword
pub fn check_reserved_keywords(&mut self) {
if self.token.is_reserved_keyword() {
let token_str = self.this_token_to_string();
self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["`",
"` is a reserved keyword"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).emit()
}
}
/// Expect and consume an `&`. If `&&` is seen, replace it with a single
/// `&` and continue. If an `&` is not seen, signal an error.
fn expect_and(&mut self) -> PResult<'a, ()> {
self.expected_tokens.push(TokenType::Token(token::BinOp(token::And)));
match self.token {
token::BinOp(token::And) => { self.bump(); Ok(()) }
token::AndAnd => {
let span = self.span;
let lo = span.lo + BytePos(1);
Ok(self.replace_token(token::BinOp(token::And), lo,
span.hi))
}
_ => self.unexpected(),
}
}
pub fn expect_no_suffix(&self, sp: Span, kind: &str,
suffix: Option<ast::Name>) {
match suffix {
None => { }
Some(suf) => {
let text = suf.as_str();
if text.is_empty() {
self.span_bug(sp,
"found empty literal suffix in Some")
}
self.span_err(sp,
&*::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" with a suffix is invalid"];
__STATIC_FMTSTR
},
&match (&kind,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
}
}
/// Attempt to consume a `<`. If `<<` is seen, replace it with a single
/// `<` and continue. If a `<` is not seen, return false.
///
/// This is meant to be used when parsing generics on a path to get the
/// starting token.
fn eat_lt(&mut self) -> bool {
self.expected_tokens.push(TokenType::Token(token::Lt));
match self.token {
token::Lt => { self.bump(); true }
token::BinOp(token::Shl) => {
let span = self.span;
let lo = span.lo + BytePos(1);
self.replace_token(token::Lt, lo, span.hi);
true
}
_ => false,
}
}
fn expect_lt(&mut self) -> PResult<'a, ()> {
if !self.eat_lt() { self.unexpected() } else { Ok(()) }
}
/// Expect and consume a GT. if a >> is seen, replace it
/// with a single > and continue. If a GT is not seen,
/// signal an error.
pub fn expect_gt(&mut self) -> PResult<'a, ()> {
self.expected_tokens.push(TokenType::Token(token::Gt));
match self.token {
token::Gt => { self.bump(); Ok(()) }
token::BinOp(token::Shr) => {
let span = self.span;
let lo = span.lo + BytePos(1);
Ok(self.replace_token(token::Gt, lo, span.hi))
}
token::BinOpEq(token::Shr) => {
let span = self.span;
let lo = span.lo + BytePos(1);
Ok(self.replace_token(token::Ge, lo, span.hi))
}
token::Ge => {
let span = self.span;
let lo = span.lo + BytePos(1);
Ok(self.replace_token(token::Eq, lo, span.hi))
}
_ => {
let gt_str = Parser::token_to_string(&token::Gt);
let this_token_str = self.this_token_to_string();
Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `",
"`, found `",
"`"];
__STATIC_FMTSTR
},
&match (>_str,
&this_token_str)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))))
}
}
}
pub fn parse_seq_to_before_gt_or_return<T,
F>(&mut self,
sep:
Option<token::Token>,
mut f: F)
-> PResult<'a, (P<[T]>, bool)> where F: FnMut(&mut Parser<'a>) ->
PResult<'a, Option<T>> {
let mut v = Vec::new();
for i in 0.. {
if self.check(&token::Gt) ||
self.token == token::BinOp(token::Shr) ||
self.token == token::Ge ||
self.token == token::BinOpEq(token::Shr) {
break ;
}
if i % 2 == 0 {
match match f(self) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
Some(result) => v.push(result),
None => return Ok((P::from_vec(v), true)),
}
} else {
if let Some(t) = sep.as_ref() {
match self.expect(t) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
return Ok((P::from_vec(v), false));
}
/// Parse a sequence bracketed by '<' and '>', stopping
/// before the '>'.
pub fn parse_seq_to_before_gt<T,
F>(&mut self,
sep: Option<token::Token>,
mut f: F) -> PResult<'a, P<[T]>>
where F: FnMut(&mut Parser<'a>) -> PResult<'a, T> {
let (result, returned) =
match self.parse_seq_to_before_gt_or_return(sep,
|p|
Ok(Some(match f(p)
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !!returned {
{
::std::rt::begin_unwind("assertion failed: !returned",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/parser.rs",
802u32);
&_FILE_LINE
})
}
};
return Ok(result);
}
pub fn parse_seq_to_gt<T,
F>(&mut self, sep: Option<token::Token>,
f: F) -> PResult<'a, P<[T]>> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, T> {
let v =
match self.parse_seq_to_before_gt(sep, f) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect_gt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
return Ok(v);
}
pub fn parse_seq_to_gt_or_return<T,
F>(&mut self,
sep: Option<token::Token>,
f: F)
-> PResult<'a, (P<[T]>, bool)> where F: FnMut(&mut Parser<'a>) ->
PResult<'a, Option<T>> {
let (v, returned) =
match self.parse_seq_to_before_gt_or_return(sep, f) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !returned {
match self.expect_gt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
return Ok((v, returned));
}
/// Parse a sequence, including the closing delimiter. The function
/// f must consume tokens until reaching the next separator or
/// closing bracket.
pub fn parse_seq_to_end<T,
F>(&mut self, ket: &token::Token,
sep: SeqSep, f: F)
-> PResult<'a, Vec<T>> where F: FnMut(&mut Parser<'a>) ->
PResult<'a, T> {
let val =
match self.parse_seq_to_before_end(ket, sep, f) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.bump();
Ok(val)
}
/// Parse a sequence, not including the closing delimiter. The function
/// f must consume tokens until reaching the next separator or
/// closing bracket.
pub fn parse_seq_to_before_end<T,
F>(&mut self, ket: &token::Token,
sep: SeqSep, mut f: F)
-> PResult<'a, Vec<T>> where F: FnMut(&mut Parser<'a>) ->
PResult<'a, T> {
let mut first: bool = true;
let mut v = <[_]>::into_vec(::std::boxed::Box::new([]));
while self.token != *ket {
match sep.sep {
Some(ref t) => {
if first {
first = false;
} else {
match self.expect(t) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
_ => (),
}
if sep.trailing_sep_allowed && self.check(ket) { break ; }
v.push(match f(self) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
return Ok(v);
}
/// Parse a sequence, including the closing delimiter. The function
/// f must consume tokens until reaching the next separator or
/// closing bracket.
pub fn parse_unspanned_seq<T,
F>(&mut self, bra: &token::Token,
ket: &token::Token, sep: SeqSep,
f: F) -> PResult<'a, Vec<T>> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, T> {
match self.expect(bra) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let result =
match self.parse_seq_to_before_end(ket, sep, f) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.bump();
Ok(result)
}
/// Parse a sequence parameter of enum variant. For consistency purposes,
/// these should not be empty.
pub fn parse_enum_variant_seq<T,
F>(&mut self, bra: &token::Token,
ket: &token::Token, sep: SeqSep,
f: F) -> PResult<'a, Vec<T>>
where F: FnMut(&mut Parser<'a>) -> PResult<'a, T> {
let result =
match self.parse_unspanned_seq(bra, ket, sep, f) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if result.is_empty() {
let last_span = self.last_span;
self.span_err(last_span,
"nullary enum variants are written with no trailing `( )`");
}
Ok(result)
}
pub fn parse_seq<T,
F>(&mut self, bra: &token::Token,
ket: &token::Token, sep: SeqSep, f: F)
-> PResult<'a, Spanned<Vec<T>>> where F: FnMut(&mut Parser<'a>)
-> PResult<'a, T> {
let lo = self.span.lo;
match self.expect(bra) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let result =
match self.parse_seq_to_before_end(ket, sep, f) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
self.bump();
Ok(spanned(lo, hi, result))
}
/// Advance the parser by one token
pub fn bump(&mut self) {
self.last_span = self.span;
self.last_token =
if self.token.is_ident() || self.token.is_path() ||
self.token == token::Comma {
Some(Box::new(self.token.clone()))
} else { None };
let next =
if self.buffer_start == self.buffer_end {
self.reader.real_token()
} else {
let buffer_start = self.buffer_start as usize;
let next_index = (buffer_start + 1) & 3;
self.buffer_start = next_index as isize;
let placeholder =
TokenAndSpan{tok: token::Underscore,
sp: self.span,};
mem::replace(&mut self.buffer[buffer_start],
placeholder)
};
self.span = next.sp;
self.token = next.tok;
self.tokens_consumed += 1;
self.expected_tokens.clear();
self.check_unknown_macro_variable();
}
/// Advance the parser by one token and return the bumped token.
pub fn bump_and_get(&mut self) -> token::Token {
let old_token =
mem::replace(&mut self.token, token::Underscore);
self.bump();
old_token
}
/// EFFECT: replace the current token and span with the given one
pub fn replace_token(&mut self, next: token::Token, lo: BytePos,
hi: BytePos) {
self.last_span = mk_sp(self.span.lo, lo);
self.token = next;
self.span = mk_sp(lo, hi);
}
pub fn buffer_length(&mut self) -> isize {
if self.buffer_start <= self.buffer_end {
return self.buffer_end - self.buffer_start;
}
return (4 - self.buffer_start) + self.buffer_end;
}
pub fn look_ahead<R, F>(&mut self, distance: usize, f: F) -> R
where F: FnOnce(&token::Token) -> R {
let dist = distance as isize;
while self.buffer_length() < dist {
self.buffer[self.buffer_end as usize] =
self.reader.real_token();
self.buffer_end = (self.buffer_end + 1) & 3;
}
f(&self.buffer[((self.buffer_start + dist - 1) & 3) as
usize].tok)
}
pub fn fatal(&self, m: &str) -> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_fatal(self.span, m)
}
pub fn span_fatal(&self, sp: Span, m: &str)
-> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_fatal(sp, m)
}
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str)
-> DiagnosticBuilder<'a> {
let mut err =
self.sess.span_diagnostic.struct_span_fatal(sp, m);
err.fileline_help(sp, help);
err
}
pub fn bug(&self, m: &str) -> ! {
self.sess.span_diagnostic.span_bug(self.span, m)
}
pub fn warn(&self, m: &str) {
self.sess.span_diagnostic.span_warn(self.span, m)
}
pub fn span_warn(&self, sp: Span, m: &str) {
self.sess.span_diagnostic.span_warn(sp, m)
}
pub fn span_err(&self, sp: Span, m: &str) {
self.sess.span_diagnostic.span_err(sp, m)
}
pub fn span_bug(&self, sp: Span, m: &str) -> ! {
self.sess.span_diagnostic.span_bug(sp, m)
}
pub fn abort_if_errors(&self) {
self.sess.span_diagnostic.abort_if_errors();
}
pub fn diagnostic(&self) -> &'a errors::Handler {
&self.sess.span_diagnostic
}
pub fn id_to_interned_str(&mut self, id: Ident)
-> InternedString {
id.name.as_str()
}
/// Is the current token one of the keywords that signals a bare function
/// type?
pub fn token_is_bare_fn_keyword(&mut self) -> bool {
self.check_keyword(keywords::Fn) ||
self.check_keyword(keywords::Unsafe) ||
self.check_keyword(keywords::Extern)
}
pub fn get_lifetime(&mut self) -> ast::Ident {
match self.token {
token::Lifetime(ref ident) => *ident,
_ => self.bug("not a lifetime"),
}
}
pub fn parse_for_in_type(&mut self) -> PResult<'a, Ty_> {
let lo = self.span.lo;
let lifetime_defs =
match self.parse_late_bound_lifetime_defs() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.token_is_bare_fn_keyword() {
self.parse_ty_bare_fn(lifetime_defs)
} else {
let hi = self.span.hi;
let trait_ref =
match self.parse_trait_ref() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let poly_trait_ref =
ast::PolyTraitRef{bound_lifetimes: lifetime_defs,
trait_ref: trait_ref,
span: mk_sp(lo, hi),};
let other_bounds =
if self.eat(&token::BinOp(token::Plus)) {
match self.parse_ty_param_bounds(BoundParsingMode::Bare)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else { P::empty() };
let all_bounds =
Some(TraitTyParamBound(poly_trait_ref,
TraitBoundModifier::None)).into_iter().chain(other_bounds.into_vec()).collect();
Ok(ast::TyPolyTraitRef(all_bounds))
}
}
pub fn parse_ty_path(&mut self) -> PResult<'a, Ty_> {
Ok(TyPath(None,
match self.parse_path(LifetimeAndTypesWithoutColons)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
}
/// parse a TyBareFn type:
pub fn parse_ty_bare_fn(&mut self,
lifetime_defs: Vec<ast::LifetimeDef>)
-> PResult<'a, Ty_> {
let unsafety =
match self.parse_unsafety() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let abi =
if self.eat_keyword(keywords::Extern) {
match self.parse_opt_abi() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.unwrap_or(abi::C)
} else { abi::Rust };
match self.expect_keyword(keywords::Fn) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (inputs, variadic) =
match self.parse_fn_args(false, true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ret_ty =
match self.parse_ret_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let decl =
P(FnDecl{inputs: inputs,
output: ret_ty,
variadic: variadic,});
Ok(TyBareFn(P(BareFnTy{abi: abi,
unsafety: unsafety,
lifetimes: lifetime_defs,
decl: decl,})))
}
/// Parses an obsolete closure kind (`&:`, `&mut:`, or `:`).
pub fn parse_obsolete_closure_kind(&mut self) -> PResult<'a, ()> {
let lo = self.span.lo;
if self.check(&token::BinOp(token::And)) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Mut)) &&
self.look_ahead(2, |t| *t == token::Colon) {
self.bump();
self.bump();
self.bump();
} else if self.token == token::BinOp(token::And) &&
self.look_ahead(1, |t| *t == token::Colon) {
self.bump();
self.bump();
} else if self.eat(&token::Colon) { } else { return Ok(()); }
let span = mk_sp(lo, self.span.hi);
self.obsolete(span, ObsoleteSyntax::ClosureKind);
Ok(())
}
pub fn parse_unsafety(&mut self) -> PResult<'a, Unsafety> {
if self.eat_keyword(keywords::Unsafe) {
return Ok(Unsafety::Unsafe);
} else { return Ok(Unsafety::Normal); }
}
/// Parse the items in a trait declaration
pub fn parse_trait_items(&mut self)
-> PResult<'a, Vec<P<TraitItem>>> {
self.parse_unspanned_seq(&token::OpenDelim(token::Brace),
&token::CloseDelim(token::Brace),
seq_sep_none(),
|p| -> PResult<'a, P<TraitItem>> {
{
let found =
match (p).token {
token::Interpolated(token::NtTraitItem(_))
=> {
Some((p).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtTraitItem(x)))
= found {
return Ok(x);
}
};
let mut attrs =
match p.parse_outer_attributes()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; let lo = p.span.lo;
let (name, node) =
if p.eat_keyword(keywords::Type)
{
let TyParam {
ident,
bounds,
default, .. } =
match p.parse_ty_param()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match p.expect(&token::Semi)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(ident,
TypeTraitItem(bounds,
default))
} else if p.is_const_item() {
match p.expect_keyword(keywords::Const)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ident =
match p.parse_ident() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match p.expect(&token::Colon)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ty =
match p.parse_ty_sum() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let default =
if p.check(&token::Eq) {
p.bump();
let expr =
match p.parse_expr()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match p.commit_expr_expecting(&expr,
token::Semi)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Some(expr)
} else {
match p.expect(&token::Semi)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
None
};
(ident,
ConstTraitItem(ty, default))
} else {
let (constness, unsafety,
abi) =
match p.parse_fn_front_matter()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ident =
match p.parse_ident() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut generics =
match p.parse_generics()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (explicit_self, d) =
match p.parse_fn_decl_with_self(|p:
&mut Parser<'a>|
{
p.parse_arg_general(false)
})
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
generics.where_clause =
match p.parse_where_clause()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let sig =
ast::MethodSig{unsafety:
unsafety,
constness:
constness,
decl: d,
generics:
generics,
abi: abi,
explicit_self:
explicit_self,};
let body =
match p.token {
token::Semi => {
p.bump();
{
static _LOC:
::log::LogLocation
=
::log::LogLocation{__line:
1221u32,
__file:
"src/parse/parser.rs",
__module_path:
"syntex_syntax::parse::parser",};
let lvl =
::log::LogLevel::Debug;
if lvl <=
::log::__static_max_level()
&&
lvl <=
::log::max_log_level()
{
::log::__log(lvl,
"syntex_syntax::parse::parser",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_trait_methods(): parsing required method"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
None
}
token::OpenDelim(token::Brace)
=> {
{
static _LOC:
::log::LogLocation
=
::log::LogLocation{__line:
1225u32,
__file:
"src/parse/parser.rs",
__module_path:
"syntex_syntax::parse::parser",};
let lvl =
::log::LogLevel::Debug;
if lvl <=
::log::__static_max_level()
&&
lvl <=
::log::max_log_level()
{
::log::__log(lvl,
"syntex_syntax::parse::parser",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_trait_methods(): parsing provided method"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
let (inner_attrs,
body) =
match p.parse_inner_attrs_and_block()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
attrs.extend(inner_attrs.iter().cloned());
Some(body)
}
_ => {
let token_str =
p.this_token_to_string();
return Err(p.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `;` or `{`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))[..]))
}
};
(ident,
ast::MethodTraitItem(sig,
body))
};
Ok(P(TraitItem{id:
ast::DUMMY_NODE_ID,
ident: name,
attrs: attrs,
node: node,
span:
mk_sp(lo,
p.last_span.hi),}))
})
}
/// Parse a possibly mutable type
pub fn parse_mt(&mut self) -> PResult<'a, MutTy> {
let mutbl =
match self.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let t =
match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(MutTy{ty: t, mutbl: mutbl,})
}
/// Parse optional return type [ -> TY ] in function decl
pub fn parse_ret_ty(&mut self) -> PResult<'a, FunctionRetTy> {
if self.eat(&token::RArrow) {
if self.eat(&token::Not) {
Ok(NoReturn(self.last_span))
} else {
Ok(Return(match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
}
} else {
let pos = self.span.lo;
Ok(DefaultReturn(mk_sp(pos, pos)))
}
}
/// Parse a type in a context where `T1+T2` is allowed.
pub fn parse_ty_sum(&mut self) -> PResult<'a, P<Ty>> {
let lo = self.span.lo;
let lhs =
match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !self.eat(&token::BinOp(token::Plus)) { return Ok(lhs); }
let bounds =
match self.parse_ty_param_bounds(BoundParsingMode::Bare) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if bounds.is_empty() {
let last_span = self.last_span;
self.span_err(last_span,
"at least one type parameter bound must be specified");
}
let sp = mk_sp(lo, self.last_span.hi);
let sum = ast::TyObjectSum(lhs, bounds);
Ok(P(Ty{id: ast::DUMMY_NODE_ID, node: sum, span: sp,}))
}
/// Parse a type.
pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
{
let found =
match (self).token {
token::Interpolated(token::NtTy(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtTy(x))) = found {
return Ok(x);
}
};
let lo = self.span.lo;
let t =
if self.check(&token::OpenDelim(token::Paren)) {
self.bump();
let mut ts =
<[_]>::into_vec(::std::boxed::Box::new([]));
let mut last_comma = false;
while self.token != token::CloseDelim(token::Paren) {
ts.push(match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
if self.check(&token::Comma) {
last_comma = true;
self.bump();
} else { last_comma = false; break ; }
}
match self.expect(&token::CloseDelim(token::Paren)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if ts.len() == 1 && !last_comma {
TyParen(ts.into_iter().nth(0).unwrap())
} else { TyTup(ts) }
} else if self.check(&token::BinOp(token::Star)) {
self.bump();
TyPtr(match self.parse_ptr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
} else if self.check(&token::OpenDelim(token::Bracket)) {
match self.expect(&token::OpenDelim(token::Bracket)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let t =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let t =
match match self.maybe_parse_fixed_length_of_vec()
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
None => TyVec(t),
Some(suffix) => TyFixedLengthVec(t, suffix),
};
match self.expect(&token::CloseDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
t
} else if self.check(&token::BinOp(token::And)) ||
self.token == token::AndAnd {
match self.expect_and() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.parse_borrowed_pointee() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else if self.check_keyword(keywords::For) {
match self.parse_for_in_type() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else if self.token_is_bare_fn_keyword() {
match self.parse_ty_bare_fn(Vec::new()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else if self.eat_keyword_noexpect(keywords::Typeof) {
match self.expect(&token::OpenDelim(token::Paren)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let e =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::CloseDelim(token::Paren)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
TyTypeof(e)
} else if self.eat_lt() {
let (qself, path) =
match self.parse_qualified_path(NoTypesAllowed) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
TyPath(Some(qself), path)
} else if self.check(&token::ModSep) ||
self.token.is_ident() ||
self.token.is_path() {
let path =
match self.parse_path(LifetimeAndTypesWithoutColons)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::Not) {
self.bump();
let delim =
match self.expect_open_delim() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let tts =
match self.parse_seq_to_end(&token::CloseDelim(delim),
seq_sep_none(),
|p|
p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
TyMac(spanned(lo, hi,
Mac_{path: path,
tts: tts,
ctxt: EMPTY_CTXT,}))
} else { TyPath(None, path) }
} else if self.eat(&token::Underscore) {
TyInfer
} else {
let this_token_str = self.this_token_to_string();
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected type, found `",
"`"];
__STATIC_FMTSTR
},
&match (&this_token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
return Err(self.fatal(&msg[..]));
};
let sp = mk_sp(lo, self.last_span.hi);
Ok(P(Ty{id: ast::DUMMY_NODE_ID, node: t, span: sp,}))
}
pub fn parse_borrowed_pointee(&mut self) -> PResult<'a, Ty_> {
let opt_lifetime =
match self.parse_opt_lifetime() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mt =
match self.parse_mt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
return Ok(TyRptr(opt_lifetime, mt));
}
pub fn parse_ptr(&mut self) -> PResult<'a, MutTy> {
let mutbl =
if self.eat_keyword(keywords::Mut) {
MutMutable
} else if self.eat_keyword(keywords::Const) {
MutImmutable
} else {
let span = self.last_span;
self.span_err(span,
"bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`");
MutImmutable
};
let t =
match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(MutTy{ty: t, mutbl: mutbl,})
}
pub fn is_named_argument(&mut self) -> bool {
let offset =
match self.token {
token::BinOp(token::And) => 1,
token::AndAnd => 1,
_ if self.token.is_keyword(keywords::Mut) => 1,
_ => 0,
};
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1431u32,
__file: "src/parse/parser.rs",
__module_path:
"syntex_syntax::parse::parser",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::parser",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parser is_named_argument offset:"];
__STATIC_FMTSTR
},
&match (&offset,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
if offset == 0 {
is_plain_ident_or_underscore(&self.token) &&
self.look_ahead(1, |t| *t == token::Colon)
} else {
self.look_ahead(offset,
|t| is_plain_ident_or_underscore(t)) &&
self.look_ahead(offset + 1, |t| *t == token::Colon)
}
}
/// This version of parse arg doesn't necessarily require
/// identifier names.
pub fn parse_arg_general(&mut self, require_name: bool)
-> PResult<'a, Arg> {
{
let found =
match (self).token {
token::Interpolated(token::NtArg(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtArg(x))) = found
{
return Ok(x);
}
};
let pat =
if require_name || self.is_named_argument() {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1448u32,
__file:
"src/parse/parser.rs",
__module_path:
"syntex_syntax::parse::parser",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::parser",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_arg_general parse_pat (require_name:",
")"];
__STATIC_FMTSTR
},
&match (&require_name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1455u32,
__file:
"src/parse/parser.rs",
__module_path:
"syntex_syntax::parse::parser",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::parser",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_arg_general ident_to_pat"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
ast_util::ident_to_pat(ast::DUMMY_NODE_ID,
self.last_span,
special_idents::invalid)
};
let t =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(Arg{ty: t, pat: pat, id: ast::DUMMY_NODE_ID,})
}
/// Parse a single function argument
pub fn parse_arg(&mut self) -> PResult<'a, Arg> {
self.parse_arg_general(true)
}
/// Parse an argument in a lambda header e.g. |arg, arg|
pub fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let t =
if self.eat(&token::Colon) {
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else {
P(Ty{id: ast::DUMMY_NODE_ID,
node: TyInfer,
span: mk_sp(self.span.lo, self.span.hi),})
};
Ok(Arg{ty: t, pat: pat, id: ast::DUMMY_NODE_ID,})
}
pub fn maybe_parse_fixed_length_of_vec(&mut self)
-> PResult<'a, Option<P<ast::Expr>>> {
if self.check(&token::Semi) {
self.bump();
Ok(Some(match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} else { Ok(None) }
}
/// Matches token_lit = LIT_INTEGER | ...
pub fn lit_from_token(&self, tok: &token::Token)
-> PResult<'a, Lit_> {
match *tok {
token::Interpolated(token::NtExpr(ref v)) => {
match v.node {
ExprLit(ref lit) => { Ok(lit.node.clone()) }
_ => { return self.unexpected_last(tok); }
}
}
token::Literal(lit, suf) => {
let (suffix_illegal, out) =
match lit {
token::Byte(i) =>
(true,
LitByte(parse::byte_lit(&i.as_str()).0)),
token::Char(i) =>
(true,
LitChar(parse::char_lit(&i.as_str()).0)),
token::Integer(s) => {
(false,
parse::integer_lit(&s.as_str(),
suf.as_ref().map(|s|
s.as_str()),
&self.sess.span_diagnostic,
self.last_span))
}
token::Float(s) => {
(false,
parse::float_lit(&s.as_str(),
suf.as_ref().map(|s|
s.as_str()),
&self.sess.span_diagnostic,
self.last_span))
}
token::Str_(s) => {
(true,
LitStr(token::intern_and_get_ident(&parse::str_lit(&s.as_str())),
ast::CookedStr))
}
token::StrRaw(s, n) => {
(true,
LitStr(token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())),
ast::RawStr(n)))
}
token::ByteStr(i) =>
(true,
LitByteStr(parse::byte_str_lit(&i.as_str()))),
token::ByteStrRaw(i, _) =>
(true,
LitByteStr(Rc::new(i.to_string().into_bytes()))),
};
if suffix_illegal {
let sp = self.last_span;
self.expect_no_suffix(sp,
&*::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" literal"];
__STATIC_FMTSTR
},
&match (&lit.short_name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
suf)
}
Ok(out)
}
_ => { return self.unexpected_last(tok); }
}
}
/// Matches lit = true | false | token_lit
pub fn parse_lit(&mut self) -> PResult<'a, Lit> {
let lo = self.span.lo;
let lit =
if self.eat_keyword(keywords::True) {
LitBool(true)
} else if self.eat_keyword(keywords::False) {
LitBool(false)
} else {
let token = self.bump_and_get();
let lit =
match self.lit_from_token(&token) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
lit
};
Ok(codemap::Spanned{node: lit,
span: mk_sp(lo, self.last_span.hi),})
}
/// matches '-' lit | lit
pub fn parse_pat_literal_maybe_minus(&mut self)
-> PResult<'a, P<Expr>> {
let minus_lo = self.span.lo;
let minus_present = self.eat(&token::BinOp(token::Minus));
let lo = self.span.lo;
let literal =
P(match self.parse_lit() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
let hi = self.last_span.hi;
let expr = self.mk_expr(lo, hi, ExprLit(literal), None);
if minus_present {
let minus_hi = self.last_span.hi;
let unary = self.mk_unary(UnNeg, expr);
Ok(self.mk_expr(minus_lo, minus_hi, unary, None))
} else { Ok(expr) }
}
/// Parses qualified path.
///
/// Assumes that the leading `<` has been parsed already.
///
/// Qualifed paths are a part of the universal function call
/// syntax (UFCS).
///
/// `qualified_path = <type [as trait_ref]>::path`
///
/// See `parse_path` for `mode` meaning.
///
/// # Examples:
///
/// `<T as U>::a`
/// `<T as U>::F::a::<S>`
pub fn parse_qualified_path(&mut self, mode: PathParsingMode)
-> PResult<'a, (QSelf, ast::Path)> {
let span = self.last_span;
let self_type =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut path =
if self.eat_keyword(keywords::As) {
match self.parse_path(LifetimeAndTypesWithoutColons) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else {
ast::Path{span: span,
global: false,
segments:
<[_]>::into_vec(::std::boxed::Box::new([])),}
};
let qself =
QSelf{ty: self_type, position: path.segments.len(),};
match self.expect(&token::Gt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::ModSep) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let segments =
match mode {
LifetimeAndTypesWithoutColons => {
match self.parse_path_segments_without_colons() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
LifetimeAndTypesWithColons => {
match self.parse_path_segments_with_colons() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
NoTypesAllowed => {
match self.parse_path_segments_without_types() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
};
path.segments.extend(segments);
path.span.hi = self.last_span.hi;
Ok((qself, path))
}
/// Parses a path and optional type parameter bounds, depending on the
/// mode. The `mode` parameter determines whether lifetimes, types, and/or
/// bounds are permitted and whether `::` must precede type parameter
/// groups.
pub fn parse_path(&mut self, mode: PathParsingMode)
-> PResult<'a, ast::Path> {
let found =
match self.token {
token::Interpolated(token::NtPath(_)) =>
Some(self.bump_and_get()),
_ => None,
};
if let Some(token::Interpolated(token::NtPath(path))) = found
{
return Ok(*path);
}
let lo = self.span.lo;
let is_global = self.eat(&token::ModSep);
let segments =
match mode {
LifetimeAndTypesWithoutColons => {
match self.parse_path_segments_without_colons() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
LifetimeAndTypesWithColons => {
match self.parse_path_segments_with_colons() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
NoTypesAllowed => {
match self.parse_path_segments_without_types() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
};
let span = mk_sp(lo, self.last_span.hi);
Ok(ast::Path{span: span,
global: is_global,
segments: segments,})
}
/// Examples:
/// - `a::b<T,U>::c<V,W>`
/// - `a::b<T,U>::c(V) -> W`
/// - `a::b<T,U>::c(V)`
pub fn parse_path_segments_without_colons(&mut self)
-> PResult<'a, Vec<ast::PathSegment>> {
let mut segments = Vec::new();
loop {
let identifier =
match self.parse_ident_or_self_type() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let parameters =
if self.eat_lt() {
let (lifetimes, types, bindings) =
match self.parse_generic_values_after_lt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData{lifetimes:
lifetimes,
types:
P::from_vec(types),
bindings:
P::from_vec(bindings),})
} else if self.eat(&token::OpenDelim(token::Paren)) {
let lo = self.last_span.lo;
let inputs =
match self.parse_seq_to_end(&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p|
p.parse_ty_sum())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let output_ty =
if self.eat(&token::RArrow) {
Some(match self.parse_ty() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
} else { None };
let hi = self.last_span.hi;
ast::PathParameters::Parenthesized(ast::ParenthesizedParameterData{span:
mk_sp(lo,
hi),
inputs:
inputs,
output:
output_ty,})
} else { ast::PathParameters::none() };
segments.push(ast::PathSegment{identifier: identifier,
parameters: parameters,});
if !self.eat(&token::ModSep) { return Ok(segments); }
}
}
/// Examples:
/// - `a::b::<T,U>::c`
pub fn parse_path_segments_with_colons(&mut self)
-> PResult<'a, Vec<ast::PathSegment>> {
let mut segments = Vec::new();
loop {
let identifier =
match self.parse_ident_or_self_type() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !self.eat(&token::ModSep) {
segments.push(ast::PathSegment{identifier: identifier,
parameters:
ast::PathParameters::none(),});
return Ok(segments);
}
if self.eat_lt() {
let (lifetimes, types, bindings) =
match self.parse_generic_values_after_lt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let parameters =
ast::AngleBracketedParameterData{lifetimes:
lifetimes,
types:
P::from_vec(types),
bindings:
P::from_vec(bindings),};
segments.push(ast::PathSegment{identifier: identifier,
parameters:
ast::PathParameters::AngleBracketed(parameters),});
if !self.eat(&token::ModSep) { return Ok(segments); }
} else {
segments.push(ast::PathSegment{identifier: identifier,
parameters:
ast::PathParameters::none(),});
}
}
}
/// Examples:
/// - `a::b::c`
pub fn parse_path_segments_without_types(&mut self)
-> PResult<'a, Vec<ast::PathSegment>> {
let mut segments = Vec::new();
loop {
let identifier =
match self.parse_ident_or_self_type() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
segments.push(ast::PathSegment{identifier: identifier,
parameters:
ast::PathParameters::none(),});
if !self.eat(&token::ModSep) { return Ok(segments); }
}
}
/// parses 0 or 1 lifetime
pub fn parse_opt_lifetime(&mut self)
-> PResult<'a, Option<ast::Lifetime>> {
match self.token {
token::Lifetime(..) => {
Ok(Some(match self.parse_lifetime() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
}
_ => { Ok(None) }
}
}
/// Parses a single lifetime
/// Matches lifetime = LIFETIME
pub fn parse_lifetime(&mut self) -> PResult<'a, ast::Lifetime> {
match self.token {
token::Lifetime(i) => {
let span = self.span;
self.bump();
return Ok(ast::Lifetime{id: ast::DUMMY_NODE_ID,
span: span,
name: i.name,});
}
_ => {
return Err(self.fatal("expected a lifetime name"));
}
}
}
/// Parses `lifetime_defs = [ lifetime_defs { ',' lifetime_defs } ]` where `lifetime_def =
/// lifetime [':' lifetimes]`
pub fn parse_lifetime_defs(&mut self)
-> PResult<'a, Vec<ast::LifetimeDef>> {
let mut res = Vec::new();
loop {
match self.token {
token::Lifetime(_) => {
let lifetime =
match self.parse_lifetime() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let bounds =
if self.eat(&token::Colon) {
match self.parse_lifetimes(token::BinOp(token::Plus))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else { Vec::new() };
res.push(ast::LifetimeDef{lifetime: lifetime,
bounds: bounds,});
}
_ => { return Ok(res); }
}
match self.token {
token::Comma => { self.bump(); }
token::Gt => { return Ok(res); }
token::BinOp(token::Shr) => { return Ok(res); }
_ => {
let this_token_str = self.this_token_to_string();
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `,` or `>` after lifetime name, found `",
"`"];
__STATIC_FMTSTR
},
&match (&this_token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
return Err(self.fatal(&msg[..]));
}
}
}
}
/// matches lifetimes = ( lifetime ) | ( lifetime , lifetimes ) actually, it matches the empty
/// one too, but putting that in there messes up the grammar....
///
/// Parses zero or more comma separated lifetimes. Expects each lifetime to be followed by
/// either a comma or `>`. Used when parsing type parameter lists, where we expect something
/// like `<'a, 'b, T>`.
pub fn parse_lifetimes(&mut self, sep: token::Token)
-> PResult<'a, Vec<ast::Lifetime>> {
let mut res = Vec::new();
loop {
match self.token {
token::Lifetime(_) => {
res.push(match self.parse_lifetime() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
_ => { return Ok(res); }
}
if self.token != sep { return Ok(res); }
self.bump();
}
}
/// Parse mutability declaration (mut/const/imm)
pub fn parse_mutability(&mut self) -> PResult<'a, Mutability> {
if self.eat_keyword(keywords::Mut) {
Ok(MutMutable)
} else { Ok(MutImmutable) }
}
/// Parse ident COLON expr
pub fn parse_field(&mut self) -> PResult<'a, Field> {
let lo = self.span.lo;
let i =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.last_span.hi;
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let e =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(ast::Field{ident: spanned(lo, hi, i),
span: mk_sp(lo, e.span.hi),
expr: e,})
}
pub fn mk_expr(&mut self, lo: BytePos, hi: BytePos, node: Expr_,
attrs: ThinAttributes) -> P<Expr> {
P(Expr{id: ast::DUMMY_NODE_ID,
node: node,
span: mk_sp(lo, hi),
attrs: attrs,})
}
pub fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>)
-> ast::Expr_ {
ExprUnary(unop, expr)
}
pub fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>,
rhs: P<Expr>) -> ast::Expr_ {
ExprBinary(binop, lhs, rhs)
}
pub fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>)
-> ast::Expr_ {
ExprCall(f, args)
}
fn mk_method_call(&mut self, ident: ast::SpannedIdent,
tps: Vec<P<Ty>>, args: Vec<P<Expr>>)
-> ast::Expr_ {
ExprMethodCall(ident, tps, args)
}
pub fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>)
-> ast::Expr_ {
ExprIndex(expr, idx)
}
pub fn mk_range(&mut self, start: Option<P<Expr>>,
end: Option<P<Expr>>) -> ast::Expr_ {
ExprRange(start, end)
}
pub fn mk_field(&mut self, expr: P<Expr>,
ident: ast::SpannedIdent) -> ast::Expr_ {
ExprField(expr, ident)
}
pub fn mk_tup_field(&mut self, expr: P<Expr>,
idx: codemap::Spanned<usize>) -> ast::Expr_ {
ExprTupField(expr, idx)
}
pub fn mk_assign_op(&mut self, binop: ast::BinOp, lhs: P<Expr>,
rhs: P<Expr>) -> ast::Expr_ {
ExprAssignOp(binop, lhs, rhs)
}
pub fn mk_mac_expr(&mut self, lo: BytePos, hi: BytePos, m: Mac_,
attrs: ThinAttributes) -> P<Expr> {
P(Expr{id: ast::DUMMY_NODE_ID,
node:
ExprMac(codemap::Spanned{node: m,
span: mk_sp(lo, hi),}),
span: mk_sp(lo, hi),
attrs: attrs,})
}
pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinAttributes)
-> P<Expr> {
let span = &self.span;
let lv_lit =
P(codemap::Spanned{node:
LitInt(i as u64,
ast::UnsignedIntLit(TyU32)),
span: *span,});
P(Expr{id: ast::DUMMY_NODE_ID,
node: ExprLit(lv_lit),
span: *span,
attrs: attrs,})
}
fn expect_open_delim(&mut self)
-> PResult<'a, token::DelimToken> {
self.expected_tokens.push(TokenType::Token(token::Gt));
match self.token {
token::OpenDelim(delim) => { self.bump(); Ok(delim) }
_ => Err(self.fatal("expected open delimiter")),
}
}
/// At the bottom (top?) of the precedence hierarchy,
/// parse things like parenthesized exprs,
/// macros, return, etc.
///
/// NB: This does not parse outer attributes,
/// and is private because it only works
/// correctly if called from parse_dot_or_call_expr().
fn parse_bottom_expr(&mut self) -> PResult<'a, P<Expr>> {
{
let found =
match self.token {
token::Interpolated(token::NtExpr(ref e)) => {
Some((*e).clone())
}
token::Interpolated(token::NtPath(_)) => {
let pt =
match self.token {
token::Interpolated(token::NtPath(ref pt))
=> (**pt).clone(),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/parser.rs",
2033u32);
&_FILE_LINE
})
}
}
};
let span = self.span;
Some(self.mk_expr(span.lo, span.hi,
ExprPath(None, pt), None))
}
token::Interpolated(token::NtBlock(_)) => {
let b =
match self.token {
token::Interpolated(token::NtBlock(ref b))
=> (*b).clone(),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/parser.rs",
2033u32);
&_FILE_LINE
})
}
}
};
let span = self.span;
Some(self.mk_expr(span.lo, span.hi,
ExprBlock(b), None))
}
_ => None,
};
match found {
Some(e) => { self.bump(); return Ok(e); }
None => (),
}
};
let mut attrs = None;
let lo = self.span.lo;
let mut hi = self.span.hi;
let ex: Expr_;
match self.token {
token::OpenDelim(token::Paren) => {
self.bump();
let attrs =
match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.into_thin_attrs().prepend(attrs);
let mut es =
<[_]>::into_vec(::std::boxed::Box::new([]));
let mut trailing_comma = false;
while self.token != token::CloseDelim(token::Paren) {
es.push(match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
match self.commit_expr(&**es.last().unwrap(), &[],
&[token::Comma,
token::CloseDelim(token::Paren)])
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::Comma) {
trailing_comma = true;
self.bump();
} else { trailing_comma = false; break ; }
}
self.bump();
hi = self.last_span.hi;
return if es.len() == 1 && !trailing_comma {
Ok(self.mk_expr(lo, hi,
ExprParen(es.into_iter().nth(0).unwrap()),
attrs))
} else {
Ok(self.mk_expr(lo, hi, ExprTup(es),
attrs))
}
}
token::OpenDelim(token::Brace) => {
return self.parse_block_expr(lo, DefaultBlock, attrs);
}
token::BinOp(token::Or) | token::OrOr => {
let lo = self.span.lo;
return self.parse_lambda_expr(lo, CaptureByRef,
attrs);
}
token::Ident(id@ast::Ident {
name: token::SELF_KEYWORD_NAME, ctxt: _ },
token::Plain) => {
self.bump();
let path = ast_util::ident_to_path(mk_sp(lo, hi), id);
ex = ExprPath(None, path);
hi = self.last_span.hi;
}
token::OpenDelim(token::Bracket) => {
self.bump();
let inner_attrs =
match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.into_thin_attrs();
attrs.update(|attrs| attrs.append(inner_attrs));
if self.check(&token::CloseDelim(token::Bracket)) {
self.bump();
ex = ExprVec(Vec::new());
} else {
let first_expr =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::Semi) {
self.bump();
let count =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::CloseDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
ex = ExprRepeat(first_expr, count);
} else if self.check(&token::Comma) {
self.bump();
let remaining_exprs =
match self.parse_seq_to_end(&token::CloseDelim(token::Bracket),
seq_sep_trailing_allowed(token::Comma),
|p|
Ok(match p.parse_expr()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut exprs =
<[_]>::into_vec(::std::boxed::Box::new([first_expr]));
exprs.extend(remaining_exprs);
ex = ExprVec(exprs);
} else {
match self.expect(&token::CloseDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
ex =
ExprVec(<[_]>::into_vec(::std::boxed::Box::new([first_expr])));
}
}
hi = self.last_span.hi;
}
_ => {
if self.eat_lt() {
let (qself, path) =
match self.parse_qualified_path(LifetimeAndTypesWithColons)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = path.span.hi;
return Ok(self.mk_expr(lo, hi,
ExprPath(Some(qself),
path), attrs));
}
if self.eat_keyword(keywords::Move) {
let lo = self.last_span.lo;
return self.parse_lambda_expr(lo, CaptureByValue,
attrs);
}
if self.eat_keyword(keywords::If) {
return self.parse_if_expr(attrs);
}
if self.eat_keyword(keywords::For) {
let lo = self.last_span.lo;
return self.parse_for_expr(None, lo, attrs);
}
if self.eat_keyword(keywords::While) {
let lo = self.last_span.lo;
return self.parse_while_expr(None, lo, attrs);
}
if self.token.is_lifetime() {
let lifetime = self.get_lifetime();
let lo = self.span.lo;
self.bump();
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat_keyword(keywords::While) {
return self.parse_while_expr(Some(lifetime),
lo, attrs)
}
if self.eat_keyword(keywords::For) {
return self.parse_for_expr(Some(lifetime), lo,
attrs)
}
if self.eat_keyword(keywords::Loop) {
return self.parse_loop_expr(Some(lifetime),
lo, attrs)
}
return Err(self.fatal("expected `while`, `for`, or `loop` after a label"))
}
if self.eat_keyword(keywords::Loop) {
let lo = self.last_span.lo;
return self.parse_loop_expr(None, lo, attrs);
}
if self.eat_keyword(keywords::Continue) {
let ex =
if self.token.is_lifetime() {
let ex =
ExprAgain(Some(Spanned{node:
self.get_lifetime(),
span:
self.span,}));
self.bump();
ex
} else { ExprAgain(None) };
let hi = self.last_span.hi;
return Ok(self.mk_expr(lo, hi, ex, attrs));
}
if self.eat_keyword(keywords::Match) {
return self.parse_match_expr(attrs);
}
if self.eat_keyword(keywords::Unsafe) {
return self.parse_block_expr(lo,
UnsafeBlock(ast::UserProvided),
attrs);
}
if self.eat_keyword(keywords::Return) {
if self.token.can_begin_expr() {
let e =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = e.span.hi;
ex = ExprRet(Some(e));
} else { ex = ExprRet(None); }
} else if self.eat_keyword(keywords::Break) {
if self.token.is_lifetime() {
ex =
ExprBreak(Some(Spanned{node:
self.get_lifetime(),
span:
self.span,}));
self.bump();
} else { ex = ExprBreak(None); }
hi = self.last_span.hi;
} else if self.check(&token::ModSep) ||
self.token.is_ident() &&
!self.check_keyword(keywords::True)
&&
!self.check_keyword(keywords::False)
{
let pth =
match self.parse_path(LifetimeAndTypesWithColons)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::Not) {
self.bump();
let delim =
match self.expect_open_delim() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let tts =
match self.parse_seq_to_end(&token::CloseDelim(delim),
seq_sep_none(),
|p|
p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.last_span.hi;
return Ok(self.mk_mac_expr(lo, hi,
Mac_{path: pth,
tts: tts,
ctxt:
EMPTY_CTXT,},
attrs));
}
if self.check(&token::OpenDelim(token::Brace)) {
let prohibited =
self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL);
if !prohibited {
self.bump();
let mut fields = Vec::new();
let mut base = None;
let attrs =
attrs.append(match self.parse_inner_attributes()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.into_thin_attrs());
while self.token !=
token::CloseDelim(token::Brace)
{
if self.eat(&token::DotDot) {
base =
Some(match self.parse_expr() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
break ;
}
fields.push(match self.parse_field() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
match self.commit_expr(&*fields.last().unwrap().expr,
&[token::Comma],
&[token::CloseDelim(token::Brace)])
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
hi = self.span.hi;
match self.expect(&token::CloseDelim(token::Brace))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
ex = ExprStruct(pth, fields, base);
return Ok(self.mk_expr(lo, hi, ex,
attrs));
}
}
hi = pth.span.hi;
ex = ExprPath(None, pth);
} else {
let lit =
match self.parse_lit() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = lit.span.hi;
ex = ExprLit(P(lit));
}
}
}
return Ok(self.mk_expr(lo, hi, ex, attrs));
}
fn parse_or_use_outer_attributes(&mut self,
already_parsed_attrs:
Option<ThinAttributes>)
-> PResult<'a, ThinAttributes> {
if let Some(attrs) = already_parsed_attrs {
Ok(attrs)
} else {
self.parse_outer_attributes().map(|a| a.into_thin_attrs())
}
}
/// Parse a block or unsafe block
pub fn parse_block_expr(&mut self, lo: BytePos,
blk_mode: BlockCheckMode,
attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
let outer_attrs = attrs;
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let inner_attrs =
match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.into_thin_attrs();
let attrs = outer_attrs.append(inner_attrs);
let blk =
match self.parse_block_tail(lo, blk_mode) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
return Ok(self.mk_expr(blk.span.lo, blk.span.hi,
ExprBlock(blk), attrs));
}
/// parse a.b or a(13) or a[4] or just a
pub fn parse_dot_or_call_expr(&mut self,
already_parsed_attrs:
Option<ThinAttributes>)
-> PResult<'a, P<Expr>> {
let attrs =
match self.parse_or_use_outer_attributes(already_parsed_attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let b =
match self.parse_bottom_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.parse_dot_or_call_expr_with(b, attrs)
}
pub fn parse_dot_or_call_expr_with(&mut self, e0: P<Expr>,
attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
self.parse_dot_or_call_expr_with_(e0).map(|expr|
expr.map(|mut expr|
{
expr.attrs.update(|a|
a.prepend(attrs));
match expr.node
{
ExprIf(..)
|
ExprIfLet(..)
=>
{
if !expr.attrs.as_attr_slice().is_empty()
{
let span =
expr.attrs.as_attr_slice()[0].span;
self.span_err(span,
"attributes are not yet allowed on `if` expressions");
}
}
_
=>
{
}
} expr
}))
}
fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>)
-> PResult<'a, P<Expr>> {
let mut e = e0;
let lo = e.span.lo;
let mut hi;
loop {
if self.eat(&token::Dot) {
match self.token {
token::Ident(i, _) => {
let dot = self.last_span.hi;
hi = self.span.hi;
self.bump();
let (_, tys, bindings) =
if self.eat(&token::ModSep) {
match self.expect_lt() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.parse_generic_values_after_lt()
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else {
(Vec::new(), Vec::new(), Vec::new())
};
if !bindings.is_empty() {
let last_span = self.last_span;
self.span_err(last_span,
"type bindings are only permitted on trait paths");
}
match self.token {
token::OpenDelim(token::Paren) => {
let mut es =
match self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p|
Ok(match p.parse_expr()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = self.last_span.hi;
es.insert(0, e);
let id = spanned(dot, hi, i);
let nd =
self.mk_method_call(id, tys, es);
e = self.mk_expr(lo, hi, nd, None);
}
_ => {
if !tys.is_empty() {
let last_span = self.last_span;
self.span_err(last_span,
"field expressions may not have type parameters");
}
let id = spanned(dot, hi, i);
let field = self.mk_field(e, id);
e = self.mk_expr(lo, hi, field, None);
}
}
}
token::Literal(token::Integer(n), suf) => {
let sp = self.span;
self.expect_no_suffix(sp, "tuple index", suf);
let dot = self.last_span.hi;
hi = self.span.hi;
self.bump();
let index = n.as_str().parse::<usize>().ok();
match index {
Some(n) => {
let id = spanned(dot, hi, n);
let field = self.mk_tup_field(e, id);
e = self.mk_expr(lo, hi, field, None);
}
None => {
let last_span = self.last_span;
self.span_err(last_span,
"invalid tuple or tuple struct index");
}
}
}
token::Literal(token::Float(n), _suf) => {
self.bump();
let last_span = self.last_span;
let fstr = n.as_str();
let mut err =
self.diagnostic().struct_span_err(last_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unexpected token: `",
"`"];
__STATIC_FMTSTR
},
&match (&n.as_str(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
if fstr.chars().all(|x|
"0123456789.".contains(x))
{
let float =
match fstr.parse::<f64>().ok() {
Some(f) => f,
None => continue ,
};
err.fileline_help(last_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["try parenthesizing the first index; e.g., `(foo.",
")",
"`"];
__STATIC_FMTSTR
},
&match (&(float.trunc()
as
usize),
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["."];
__STATIC_FMTSTR
},
&match (&fstr.splitn(2,
".").last().unwrap(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
}
err.emit();
self.abort_if_errors();
}
_ => return self.unexpected(),
}
continue ;
}
if self.expr_is_complete(&*e) { break ; }
match self.token {
token::OpenDelim(token::Paren) => {
let es =
match self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p|
Ok(match p.parse_expr()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = self.last_span.hi;
let nd = self.mk_call(e, es);
e = self.mk_expr(lo, hi, nd, None);
}
token::OpenDelim(token::Bracket) => {
self.bump();
let ix =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = self.span.hi;
match self.commit_expr_expecting(&*ix,
token::CloseDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let index = self.mk_index(e, ix);
e = self.mk_expr(lo, hi, index, None)
}
_ => return Ok(e),
}
}
return Ok(e);
}
fn parse_unquoted(&mut self) -> PResult<'a, TokenTree> {
let mut sp = self.span;
let (name, namep) =
match self.token {
token::Dollar => {
self.bump();
if self.token == token::OpenDelim(token::Paren) {
let Spanned { node: seq, span: seq_span } =
match self.parse_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_none(),
|p|
p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (sep, repeat) =
match self.parse_sep_and_kleene_op() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let name_num =
macro_parser::count_names(&seq);
return Ok(TokenTree::Sequence(mk_sp(sp.lo,
seq_span.hi),
Rc::new(SequenceRepetition{tts:
seq,
separator:
sep,
op:
repeat,
num_captures:
name_num,})));
} else if self.token.is_keyword_allow_following_colon(keywords::Crate)
{
self.bump();
return Ok(TokenTree::Token(sp,
SpecialVarNt(SpecialMacroVar::CrateMacroVar)));
} else {
sp = mk_sp(sp.lo, self.span.hi);
let namep =
match self.token {
token::Ident(_, p) => p,
_ => token::Plain,
};
let name =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(name, namep)
}
}
token::SubstNt(name, namep) => {
self.bump();
(name, namep)
}
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/parser.rs",
2528u32);
&_FILE_LINE
})
}
}
};
if self.token == token::Colon &&
self.look_ahead(1,
|t|
t.is_ident() &&
!t.is_strict_keyword() &&
!t.is_reserved_keyword()) {
self.bump();
sp = mk_sp(sp.lo, self.span.hi);
let kindp =
match self.token {
token::Ident(_, p) => p,
_ => token::Plain,
};
let nt_kind =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(TokenTree::Token(sp,
MatchNt(name, nt_kind, namep, kindp)))
} else { Ok(TokenTree::Token(sp, SubstNt(name, namep))) }
}
pub fn check_unknown_macro_variable(&mut self) {
if self.quote_depth == 0 {
match self.token {
token::SubstNt(name, _) =>
self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unknown macro variable `",
"`"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).emit(),
_ => { }
}
}
}
/// Parse an optional separator followed by a Kleene-style
/// repetition token (+ or *).
pub fn parse_sep_and_kleene_op(&mut self)
-> PResult<'a, (Option<token::Token>, ast::KleeneOp)> {
fn parse_kleene_op<'a>(parser: &mut Parser<'a>)
-> PResult<'a, Option<ast::KleeneOp>> {
match parser.token {
token::BinOp(token::Star) => {
parser.bump();
Ok(Some(ast::ZeroOrMore))
}
token::BinOp(token::Plus) => {
parser.bump();
Ok(Some(ast::OneOrMore))
}
_ => Ok(None),
}
}
match match parse_kleene_op(self) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
Some(kleene_op) => return Ok((None, kleene_op)),
None => { }
}
let separator = self.bump_and_get();
match match parse_kleene_op(self) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
Some(zerok) => Ok((Some(separator), zerok)),
None => return Err(self.fatal("expected `*` or `+`")),
}
}
/// parse a single token tree from the input.
pub fn parse_token_tree(&mut self) -> PResult<'a, TokenTree> {
{
let found =
match (self).token {
token::Interpolated(token::NtTT(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtTT(x))) = found {
return Ok((*x).clone());
}
};
fn parse_non_delim_tt_tok<'b>(p: &mut Parser<'b>)
-> PResult<'b, TokenTree> {
{
let found =
match (p).token {
token::Interpolated(token::NtTT(_)) => {
Some((p).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtTT(x))) =
found {
return Ok((*x).clone());
}
};
match p.token {
token::CloseDelim(_) => {
let token_str = p.this_token_to_string();
let mut err =
p.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["incorrect close delimiter: `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
if let Some(&sp) = p.open_braces.last() {
err.span_note(sp, "unclosed delimiter");
};
Err(err)
}
token::Dollar | token::SubstNt(..) if
p.quote_depth > 0 => {
p.parse_unquoted()
}
_ => {
Ok(TokenTree::Token(p.span, p.bump_and_get()))
}
}
}
match self.token {
token::Eof => {
let open_braces = self.open_braces.clone();
let mut err: DiagnosticBuilder<'a> =
self.fatal("this file contains an un-closed delimiter");
for sp in &open_braces {
err.span_help(*sp,
"did you mean to close this delimiter?");
}
return Err(err);
}
token::OpenDelim(delim) => {
let pre_span = self.span;
self.open_braces.push(self.span);
let open_span = self.span;
self.bump();
let tts =
match self.parse_seq_to_before_end(&token::CloseDelim(delim),
seq_sep_none(),
|p|
p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let close_span = self.span;
self.bump();
self.open_braces.pop().unwrap();
let span = Span{hi: close_span.hi, ..pre_span};
Ok(TokenTree::Delimited(span,
Rc::new(Delimited{delim:
delim,
open_span:
open_span,
tts: tts,
close_span:
close_span,})))
}
_ => parse_non_delim_tt_tok(self),
}
}
pub fn parse_all_token_trees(&mut self)
-> PResult<'a, Vec<TokenTree>> {
let mut tts = Vec::new();
while self.token != token::Eof {
tts.push(match self.parse_token_tree() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
Ok(tts)
}
/// Parse a prefix-unary-operator expr
pub fn parse_prefix_expr(&mut self,
already_parsed_attrs:
Option<ThinAttributes>)
-> PResult<'a, P<Expr>> {
let attrs =
match self.parse_or_use_outer_attributes(already_parsed_attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lo = self.span.lo;
let hi;
let ex =
match self.token {
token::Not => {
self.bump();
let e =
match self.parse_prefix_expr(None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = e.span.hi;
self.mk_unary(UnNot, e)
}
token::BinOp(token::Minus) => {
self.bump();
let e =
match self.parse_prefix_expr(None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = e.span.hi;
self.mk_unary(UnNeg, e)
}
token::BinOp(token::Star) => {
self.bump();
let e =
match self.parse_prefix_expr(None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = e.span.hi;
self.mk_unary(UnDeref, e)
}
token::BinOp(token::And) | token::AndAnd => {
match self.expect_and() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let m =
match self.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let e =
match self.parse_prefix_expr(None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = e.span.hi;
ExprAddrOf(m, e)
}
token::Ident(..) if
self.token.is_keyword(keywords::In) => {
self.bump();
let place =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let blk =
match self.parse_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let span = blk.span;
hi = span.hi;
let blk_expr =
self.mk_expr(span.lo, span.hi, ExprBlock(blk),
None);
ExprInPlace(place, blk_expr)
}
token::Ident(..) if
self.token.is_keyword(keywords::Box) => {
self.bump();
let subexpression =
match self.parse_prefix_expr(None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = subexpression.span.hi;
ExprBox(subexpression)
}
_ => return self.parse_dot_or_call_expr(Some(attrs)),
};
return Ok(self.mk_expr(lo, hi, ex, attrs));
}
/// Parse an associative expression
///
/// This parses an expression accounting for associativity and precedence of the operators in
/// the expression.
pub fn parse_assoc_expr(&mut self,
already_parsed_attrs:
Option<ThinAttributes>)
-> PResult<'a, P<Expr>> {
self.parse_assoc_expr_with(0, already_parsed_attrs.into())
}
/// Parse an associative expression with operators of at least `min_prec` precedence
pub fn parse_assoc_expr_with(&mut self, min_prec: usize,
lhs: LhsExpr)
-> PResult<'a, P<Expr>> {
let mut lhs =
if let LhsExpr::AlreadyParsed(expr) = lhs {
expr
} else {
let attrs =
match lhs {
LhsExpr::AttributesParsed(attrs) =>
Some(attrs),
_ => None,
};
if self.token == token::DotDot {
return self.parse_prefix_range_expr(attrs);
} else {
match self.parse_prefix_expr(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
};
if self.expr_is_complete(&*lhs) { return Ok(lhs); }
self.expected_tokens.push(TokenType::Operator);
while let Some(op) = AssocOp::from_token(&self.token) {
let cur_op_span = self.span;
let restrictions =
if op.is_assign_like() {
self.restrictions & RESTRICTION_NO_STRUCT_LITERAL
} else { self.restrictions };
if op.precedence() < min_prec { break ; }
self.bump();
if op.is_comparison() {
self.check_no_chained_comparison(&*lhs, &op);
}
if op == AssocOp::As {
let rhs =
match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
lhs =
self.mk_expr(lhs.span.lo, rhs.span.hi,
ExprCast(lhs, rhs), None);
continue
} else if op == AssocOp::Colon {
let rhs =
match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
lhs =
self.mk_expr(lhs.span.lo, rhs.span.hi,
ExprType(lhs, rhs), None);
continue
} else if op == AssocOp::DotDot {
let rhs =
if self.is_at_start_of_range_notation_rhs() {
let rhs =
self.parse_assoc_expr_with(op.precedence()
+ 1,
LhsExpr::NotYetParsed);
match rhs {
Ok(e) => Some(e),
Err(mut e) => { e.cancel(); None }
}
} else { None };
let (lhs_span, rhs_span) =
(lhs.span,
if let Some(ref x) = rhs {
x.span
} else { cur_op_span });
let r = self.mk_range(Some(lhs), rhs);
lhs = self.mk_expr(lhs_span.lo, rhs_span.hi, r, None);
break
}
let rhs =
match match op.fixity() {
Fixity::Right =>
self.with_res(restrictions -
RESTRICTION_STMT_EXPR,
|this| {
this.parse_assoc_expr_with(op.precedence(),
LhsExpr::NotYetParsed)
}),
Fixity::Left =>
self.with_res(restrictions -
RESTRICTION_STMT_EXPR,
|this| {
this.parse_assoc_expr_with(op.precedence()
+
1,
LhsExpr::NotYetParsed)
}),
Fixity::None =>
self.with_res(restrictions -
RESTRICTION_STMT_EXPR,
|this| {
this.parse_assoc_expr_with(op.precedence()
+
1,
LhsExpr::NotYetParsed)
}),
} {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
lhs =
match op {
AssocOp::Add | AssocOp::Subtract |
AssocOp::Multiply | AssocOp::Divide |
AssocOp::Modulus | AssocOp::LAnd | AssocOp::LOr |
AssocOp::BitXor | AssocOp::BitAnd | AssocOp::BitOr
| AssocOp::ShiftLeft | AssocOp::ShiftRight |
AssocOp::Equal | AssocOp::Less |
AssocOp::LessEqual | AssocOp::NotEqual |
AssocOp::Greater | AssocOp::GreaterEqual => {
let ast_op = op.to_ast_binop().unwrap();
let (lhs_span, rhs_span) =
(lhs.span, rhs.span);
let binary =
self.mk_binary(codemap::respan(cur_op_span,
ast_op),
lhs, rhs);
self.mk_expr(lhs_span.lo, rhs_span.hi, binary,
None)
}
AssocOp::Assign =>
self.mk_expr(lhs.span.lo, rhs.span.hi,
ExprAssign(lhs, rhs), None),
AssocOp::Inplace =>
self.mk_expr(lhs.span.lo, rhs.span.hi,
ExprInPlace(lhs, rhs), None),
AssocOp::AssignOp(k) => {
let aop =
match k {
token::Plus => BiAdd,
token::Minus => BiSub,
token::Star => BiMul,
token::Slash => BiDiv,
token::Percent => BiRem,
token::Caret => BiBitXor,
token::And => BiBitAnd,
token::Or => BiBitOr,
token::Shl => BiShl,
token::Shr => BiShr,
};
let (lhs_span, rhs_span) =
(lhs.span, rhs.span);
let aopexpr =
self.mk_assign_op(codemap::respan(cur_op_span,
aop),
lhs, rhs);
self.mk_expr(lhs_span.lo, rhs_span.hi,
aopexpr, None)
}
AssocOp::As | AssocOp::Colon | AssocOp::DotDot =>
{
self.bug("As, Colon or DotDot branch reached")
}
};
if op.fixity() == Fixity::None { break }
}
Ok(lhs)
}
/// Produce an error if comparison operators are chained (RFC #558).
/// We only need to check lhs, not rhs, because all comparison ops
/// have same precedence and are left-associative
fn check_no_chained_comparison(&mut self, lhs: &Expr,
outer_op: &AssocOp) {
if true {
if !outer_op.is_comparison() {
{
::std::rt::begin_unwind("assertion failed: outer_op.is_comparison()",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/parser.rs",
2892u32);
&_FILE_LINE
})
}
};
};
match lhs.node {
ExprBinary(op, _, _) if op.node.is_comparison() => {
let op_span = mk_sp(op.span.lo, self.span.hi);
let mut err =
self.diagnostic().struct_span_err(op_span,
"chained comparison operators require parentheses");
if op.node == BiLt && *outer_op == AssocOp::Greater {
err.fileline_help(op_span,
"use `::<...>` instead of `<...>` if you meant to specify type arguments");
}
err.emit();
}
_ => { }
}
}
/// Parse prefix-forms of range notation: `..expr` and `..`
fn parse_prefix_range_expr(&mut self,
already_parsed_attrs:
Option<ThinAttributes>)
-> PResult<'a, P<Expr>> {
if true {
if !(self.token == token::DotDot) {
{
::std::rt::begin_unwind("assertion failed: self.token == token::DotDot",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/parser.rs",
2913u32);
&_FILE_LINE
})
}
};
};
let attrs =
match self.parse_or_use_outer_attributes(already_parsed_attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lo = self.span.lo;
let mut hi = self.span.hi;
self.bump();
let opt_end =
if self.is_at_start_of_range_notation_rhs() {
let next_prec =
AssocOp::from_token(&token::DotDot).unwrap().precedence()
+ 1;
Some(match self.parse_assoc_expr_with(next_prec,
LhsExpr::NotYetParsed).map(|x|
{
hi
=
x.span.hi;
x
})
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
} else { None };
let r = self.mk_range(None, opt_end);
Ok(self.mk_expr(lo, hi, r, attrs))
}
fn is_at_start_of_range_notation_rhs(&self) -> bool {
if self.token.can_begin_expr() {
if self.token == token::OpenDelim(token::Brace) {
return !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL);
}
true
} else { false }
}
/// Parse an 'if' or 'if let' expression ('if' token already eaten)
pub fn parse_if_expr(&mut self, attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
if self.check_keyword(keywords::Let) {
return self.parse_if_let_expr(attrs);
}
let lo = self.last_span.lo;
let cond =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let thn =
match self.parse_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut els: Option<P<Expr>> = None;
let mut hi = thn.span.hi;
if self.eat_keyword(keywords::Else) {
let elexpr =
match self.parse_else_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = elexpr.span.hi;
els = Some(elexpr);
}
Ok(self.mk_expr(lo, hi, ExprIf(cond, thn, els), attrs))
}
/// Parse an 'if let' expression ('if' token already eaten)
pub fn parse_if_let_expr(&mut self, attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
let lo = self.last_span.lo;
match self.expect_keyword(keywords::Let) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Eq) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let expr =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let thn =
match self.parse_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (hi, els) =
if self.eat_keyword(keywords::Else) {
let expr =
match self.parse_else_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(expr.span.hi, Some(expr))
} else { (thn.span.hi, None) };
Ok(self.mk_expr(lo, hi, ExprIfLet(pat, expr, thn, els),
attrs))
}
pub fn parse_lambda_expr(&mut self, lo: BytePos,
capture_clause: CaptureClause,
attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
let decl =
match self.parse_fn_block_decl() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let body =
match decl.output {
DefaultReturn(_) => {
let body_expr =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
P(ast::Block{id: ast::DUMMY_NODE_ID,
stmts:
<[_]>::into_vec(::std::boxed::Box::new([])),
span: body_expr.span,
expr: Some(body_expr),
rules: DefaultBlock,})
}
_ => {
match self.parse_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
};
Ok(self.mk_expr(lo, body.span.hi,
ExprClosure(capture_clause, decl, body),
attrs))
}
pub fn parse_else_expr(&mut self) -> PResult<'a, P<Expr>> {
if self.eat_keyword(keywords::If) {
return self.parse_if_expr(None);
} else {
let blk =
match self.parse_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
return Ok(self.mk_expr(blk.span.lo, blk.span.hi,
ExprBlock(blk), None));
}
}
/// Parse a 'for' .. 'in' expression ('for' token already eaten)
pub fn parse_for_expr(&mut self, opt_ident: Option<ast::Ident>,
span_lo: BytePos, attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect_keyword(keywords::In) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let expr =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (iattrs, loop_block) =
match self.parse_inner_attrs_and_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let attrs = attrs.append(iattrs.into_thin_attrs());
let hi = self.last_span.hi;
Ok(self.mk_expr(span_lo, hi,
ExprForLoop(pat, expr, loop_block, opt_ident),
attrs))
}
/// Parse a 'while' or 'while let' expression ('while' token already eaten)
pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>,
span_lo: BytePos, attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
if self.token.is_keyword(keywords::Let) {
return self.parse_while_let_expr(opt_ident, span_lo,
attrs);
}
let cond =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (iattrs, body) =
match self.parse_inner_attrs_and_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let attrs = attrs.append(iattrs.into_thin_attrs());
let hi = body.span.hi;
return Ok(self.mk_expr(span_lo, hi,
ExprWhile(cond, body, opt_ident),
attrs));
}
/// Parse a 'while let' expression ('while' token already eaten)
pub fn parse_while_let_expr(&mut self,
opt_ident: Option<ast::Ident>,
span_lo: BytePos,
attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
match self.expect_keyword(keywords::Let) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Eq) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let expr =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (iattrs, body) =
match self.parse_inner_attrs_and_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let attrs = attrs.append(iattrs.into_thin_attrs());
let hi = body.span.hi;
return Ok(self.mk_expr(span_lo, hi,
ExprWhileLet(pat, expr, body,
opt_ident), attrs));
}
pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::Ident>,
span_lo: BytePos, attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
let (iattrs, body) =
match self.parse_inner_attrs_and_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let attrs = attrs.append(iattrs.into_thin_attrs());
let hi = body.span.hi;
Ok(self.mk_expr(span_lo, hi, ExprLoop(body, opt_ident),
attrs))
}
fn parse_match_expr(&mut self, attrs: ThinAttributes)
-> PResult<'a, P<Expr>> {
let match_span = self.last_span;
let lo = self.last_span.lo;
let discriminant =
match self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Err(mut e) =
self.commit_expr_expecting(&*discriminant,
token::OpenDelim(token::Brace))
{
if self.token == token::Token::Semi {
e.span_note(match_span,
"did you mean to remove this `match` keyword?");
}
return Err(e)
}
let attrs =
attrs.append(match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.into_thin_attrs());
let mut arms: Vec<Arm> = Vec::new();
while self.token != token::CloseDelim(token::Brace) {
arms.push(match self.parse_arm() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
let hi = self.span.hi;
self.bump();
return Ok(self.mk_expr(lo, hi, ExprMatch(discriminant, arms),
attrs));
}
pub fn parse_arm(&mut self) -> PResult<'a, Arm> {
{
let found =
match (self).token {
token::Interpolated(token::NtArm(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtArm(x))) = found
{
return Ok(x);
}
};
let attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let pats =
match self.parse_pats() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut guard = None;
if self.eat_keyword(keywords::If) {
guard =
Some(match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
match self.expect(&token::FatArrow) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let expr =
match self.parse_expr_res(RESTRICTION_STMT_EXPR, None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let require_comma =
!classify::expr_is_simple_block(&*expr) &&
self.token != token::CloseDelim(token::Brace);
if require_comma {
match self.commit_expr(&*expr, &[token::Comma],
&[token::CloseDelim(token::Brace)])
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else { self.eat(&token::Comma); }
Ok(ast::Arm{attrs: attrs,
pats: pats,
guard: guard,
body: expr,})
}
/// Parse an expression
pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>> {
self.parse_expr_res(Restrictions::empty(), None)
}
/// Evaluate the closure with restrictions in place.
///
/// After the closure is evaluated, restrictions are reset.
pub fn with_res<F>(&mut self, r: Restrictions, f: F)
-> PResult<'a, P<Expr>> where F: FnOnce(&mut Self) ->
PResult<'a, P<Expr>> {
let old = self.restrictions;
self.restrictions = r;
let r = f(self);
self.restrictions = old;
return r;
}
/// Parse an expression, subject to the given restrictions
pub fn parse_expr_res(&mut self, r: Restrictions,
already_parsed_attrs:
Option<ThinAttributes>)
-> PResult<'a, P<Expr>> {
self.with_res(r,
|this|
this.parse_assoc_expr(already_parsed_attrs))
}
/// Parse the RHS of a local variable declaration (e.g. '= 14;')
fn parse_initializer(&mut self) -> PResult<'a, Option<P<Expr>>> {
if self.check(&token::Eq) {
self.bump();
Ok(Some(match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} else { Ok(None) }
}
/// Parse patterns, separated by '|' s
fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
let mut pats = Vec::new();
loop {
pats.push(match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
if self.check(&token::BinOp(token::Or)) {
self.bump();
} else { return Ok(pats); }
};
}
fn parse_pat_tuple_elements(&mut self)
-> PResult<'a, Vec<P<Pat>>> {
let mut fields = <[_]>::into_vec(::std::boxed::Box::new([]));
if !self.check(&token::CloseDelim(token::Paren)) {
fields.push(match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
if self.look_ahead(1,
|t|
*t !=
token::CloseDelim(token::Paren))
{
while self.eat(&token::Comma) &&
!self.check(&token::CloseDelim(token::Paren))
{
fields.push(match self.parse_pat() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
}
if fields.len() == 1 {
match self.expect(&token::Comma) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
Ok(fields)
}
fn parse_pat_vec_elements(&mut self)
-> PResult<'a, (Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>)> {
let mut before = Vec::new();
let mut slice = None;
let mut after = Vec::new();
let mut first = true;
let mut before_slice = true;
while self.token != token::CloseDelim(token::Bracket) {
if first {
first = false;
} else {
match self.expect(&token::Comma) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.token == token::CloseDelim(token::Bracket) &&
(before_slice || !after.is_empty()) {
break
}
}
if before_slice {
if self.check(&token::DotDot) {
self.bump();
if self.check(&token::Comma) ||
self.check(&token::CloseDelim(token::Bracket))
{
slice =
Some(P(ast::Pat{id: ast::DUMMY_NODE_ID,
node: PatWild,
span: self.span,}));
before_slice = false;
}
continue
}
}
let subpat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if before_slice && self.check(&token::DotDot) {
self.bump();
slice = Some(subpat);
before_slice = false;
} else if before_slice {
before.push(subpat);
} else { after.push(subpat); }
}
Ok((before, slice, after))
}
/// Parse the fields of a struct-like pattern
fn parse_pat_fields(&mut self)
-> PResult<'a, (Vec<codemap::Spanned<ast::FieldPat>>, bool)> {
let mut fields = Vec::new();
let mut etc = false;
let mut first = true;
while self.token != token::CloseDelim(token::Brace) {
if first {
first = false;
} else {
match self.expect(&token::Comma) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::CloseDelim(token::Brace)) {
break
}
}
let lo = self.span.lo;
let hi;
if self.check(&token::DotDot) {
self.bump();
if self.token != token::CloseDelim(token::Brace) {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `",
"`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&"}",
&token_str)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))))
}
etc = true;
break ;
}
let (subpat, fieldname, is_shorthand) =
if self.look_ahead(1, |t| t == &token::Colon) {
let fieldname =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.bump();
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = pat.span.hi;
(pat, fieldname, false)
} else {
let is_box = self.eat_keyword(keywords::Box);
let boxed_span_lo = self.span.lo;
let is_ref = self.eat_keyword(keywords::Ref);
let is_mut = self.eat_keyword(keywords::Mut);
let fieldname =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = self.last_span.hi;
let bind_type =
match (is_ref, is_mut) {
(true, true) =>
BindingMode::ByRef(MutMutable),
(true, false) =>
BindingMode::ByRef(MutImmutable),
(false, true) =>
BindingMode::ByValue(MutMutable),
(false, false) =>
BindingMode::ByValue(MutImmutable),
};
let fieldpath =
codemap::Spanned{span: self.last_span,
node: fieldname,};
let fieldpat =
P(ast::Pat{id: ast::DUMMY_NODE_ID,
node:
PatIdent(bind_type, fieldpath,
None),
span: mk_sp(boxed_span_lo, hi),});
let subpat =
if is_box {
P(ast::Pat{id: ast::DUMMY_NODE_ID,
node: PatBox(fieldpat),
span: mk_sp(lo, hi),})
} else { fieldpat };
(subpat, fieldname, true)
};
fields.push(codemap::Spanned{span: mk_sp(lo, hi),
node:
ast::FieldPat{ident:
fieldname,
pat:
subpat,
is_shorthand:
is_shorthand,},});
}
return Ok((fields, etc));
}
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
if self.is_path_start() {
let lo = self.span.lo;
let (qself, path) =
if self.eat_lt() {
let (qself, path) =
match self.parse_qualified_path(NoTypesAllowed)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(Some(qself), path)
} else {
(None,
match self.parse_path(LifetimeAndTypesWithColons)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
};
let hi = self.last_span.hi;
Ok(self.mk_expr(lo, hi, ExprPath(qself, path), None))
} else { self.parse_pat_literal_maybe_minus() }
}
fn is_path_start(&self) -> bool {
(self.token == token::Lt || self.token == token::ModSep ||
self.token.is_ident() || self.token.is_path()) &&
!self.token.is_keyword(keywords::True) &&
!self.token.is_keyword(keywords::False)
}
/// Parse a pattern.
pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
{
let found =
match (self).token {
token::Interpolated(token::NtPat(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtPat(x))) = found
{
return Ok(x.clone());
}
};
let lo = self.span.lo;
let pat;
match self.token {
token::Underscore => { self.bump(); pat = PatWild; }
token::BinOp(token::And) | token::AndAnd => {
match self.expect_and() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mutbl =
match self.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let token::Lifetime(ident) = self.token {
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unexpected lifetime `",
"` in pattern"];
__STATIC_FMTSTR
},
&match (&ident,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))));
}
let subpat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatRegion(subpat, mutbl);
}
token::OpenDelim(token::Paren) => {
self.bump();
let fields =
match self.parse_pat_tuple_elements() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::CloseDelim(token::Paren)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatTup(fields);
}
token::OpenDelim(token::Bracket) => {
self.bump();
let (before, slice, after) =
match self.parse_pat_vec_elements() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::CloseDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatVec(before, slice, after);
}
_ => {
if self.eat_keyword(keywords::Mut) {
pat =
match self.parse_pat_ident(BindingMode::ByValue(MutMutable))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else if self.eat_keyword(keywords::Ref) {
let mutbl =
match self.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat =
match self.parse_pat_ident(BindingMode::ByRef(mutbl))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else if self.eat_keyword(keywords::Box) {
let subpat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatBox(subpat);
} else if self.is_path_start() {
if self.token.is_plain_ident() &&
self.look_ahead(1,
|t|
*t != token::DotDotDot
&&
*t !=
token::OpenDelim(token::Brace)
&&
*t !=
token::OpenDelim(token::Paren)
&&
*t !=
token::ModSep)
{
if self.look_ahead(1, |t| *t == token::Not) {
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ident_span = self.last_span;
let path =
ident_to_path(ident_span, ident);
self.bump();
let delim =
match self.expect_open_delim() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let tts =
match self.parse_seq_to_end(&token::CloseDelim(delim),
seq_sep_none(),
|p|
p.parse_token_tree())
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mac =
Mac_{path: path,
tts: tts,
ctxt: EMPTY_CTXT,};
pat =
PatMac(codemap::Spanned{node: mac,
span:
mk_sp(lo,
self.last_span.hi),});
} else {
pat =
match self.parse_pat_ident(BindingMode::ByValue(MutImmutable))
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
} else {
let (qself, path) =
if self.eat_lt() {
let (qself, path) =
match self.parse_qualified_path(NoTypesAllowed)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(Some(qself), path)
} else {
(None,
match self.parse_path(LifetimeAndTypesWithColons)
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
};
match self.token {
token::DotDotDot => {
let hi = self.last_span.hi;
let begin =
self.mk_expr(lo, hi,
ExprPath(qself,
path),
None);
self.bump();
let end =
match self.parse_pat_range_end() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatRange(begin, end);
}
token::OpenDelim(token::Brace) => {
if qself.is_some() {
return Err(self.fatal("unexpected `{` after qualified path"));
}
self.bump();
let (fields, etc) =
match self.parse_pat_fields() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.bump();
pat = PatStruct(path, fields, etc);
}
token::OpenDelim(token::Paren) => {
if qself.is_some() {
return Err(self.fatal("unexpected `(` after qualified path"));
}
if self.look_ahead(1,
|t|
*t ==
token::DotDot)
{
self.bump();
self.bump();
match self.expect(&token::CloseDelim(token::Paren))
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatEnum(path, None);
} else {
let args =
match self.parse_enum_variant_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p|
p.parse_pat())
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatEnum(path, Some(args));
}
}
_ => {
pat =
match qself {
Some(qself) =>
PatQPath(qself, path),
None =>
PatEnum(path,
Some(<[_]>::into_vec(::std::boxed::Box::new([])))),
};
}
}
}
} else {
let begin =
match self.parse_pat_literal_maybe_minus() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat(&token::DotDotDot) {
let end =
match self.parse_pat_range_end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
pat = PatRange(begin, end);
} else { pat = PatLit(begin); }
}
}
}
let hi = self.last_span.hi;
Ok(P(ast::Pat{id: ast::DUMMY_NODE_ID,
node: pat,
span: mk_sp(lo, hi),}))
}
/// Parse ident or ident @ pat
/// used by the copy foo and ref foo patterns to give a good
/// error message when parsing mistakes like ref foo(a,b)
fn parse_pat_ident(&mut self, binding_mode: ast::BindingMode)
-> PResult<'a, ast::Pat_> {
if !self.token.is_plain_ident() {
let span = self.span;
let tok_str = self.this_token_to_string();
return Err(self.span_fatal(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected identifier, found `",
"`"];
__STATIC_FMTSTR
},
&match (&tok_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let name = codemap::Spanned{span: last_span, node: ident,};
let sub =
if self.eat(&token::At) {
Some(match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
} else { None };
if self.token == token::OpenDelim(token::Paren) {
let last_span = self.last_span;
return Err(self.span_fatal(last_span,
"expected identifier, found enum pattern"))
}
Ok(PatIdent(binding_mode, name, sub))
}
/// Parse a local variable declaration
fn parse_local(&mut self, attrs: ThinAttributes)
-> PResult<'a, P<Local>> {
let lo = self.span.lo;
let pat =
match self.parse_pat() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut ty = None;
if self.eat(&token::Colon) {
ty =
Some(match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
let init =
match self.parse_initializer() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(P(ast::Local{ty: ty,
pat: pat,
init: init,
id: ast::DUMMY_NODE_ID,
span: mk_sp(lo, self.last_span.hi),
attrs: attrs,}))
}
/// Parse a "let" stmt
fn parse_let(&mut self, attrs: ThinAttributes)
-> PResult<'a, P<Decl>> {
let lo = self.span.lo;
let local =
match self.parse_local(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(P(spanned(lo, self.last_span.hi, DeclLocal(local))))
}
/// Parse a structure field
fn parse_name_and_ty(&mut self, pr: Visibility,
attrs: Vec<Attribute>)
-> PResult<'a, StructField> {
let lo =
match pr {
Inherited => self.span.lo,
Public => self.last_span.lo,
};
if !self.token.is_plain_ident() {
return Err(self.fatal("expected ident"));
}
let name =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ty =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(spanned(lo, self.last_span.hi,
ast::StructField_{kind: NamedField(name, pr),
id: ast::DUMMY_NODE_ID,
ty: ty,
attrs: attrs,}))
}
/// Emit an expected item after attributes error.
fn expected_item_err(&self, attrs: &[Attribute]) {
let message =
match attrs.last() {
Some(&Attribute {
node: ast::Attribute_ {
is_sugared_doc: true,
..
}, .. }) => {
"expected item after doc comment"
}
_ => "expected item after attributes",
};
self.span_err(self.last_span, message);
}
/// Parse a statement. may include decl.
pub fn parse_stmt(&mut self) -> PResult<'a, Option<P<Stmt>>> {
Ok(match self.parse_stmt_() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.map(P))
}
fn parse_stmt_(&mut self) -> PResult<'a, Option<Stmt>> {
{
let found =
match (self).token {
token::Interpolated(token::NtStmt(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtStmt(x))) = found
{
return Ok(Some((*x).clone()));
}
};
let attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lo = self.span.lo;
Ok(Some(if self.check_keyword(keywords::Let) {
match self.expect_keyword(keywords::Let) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let decl =
match self.parse_let(attrs.into_thin_attrs())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = decl.span.hi;
let stmt = StmtDecl(decl, ast::DUMMY_NODE_ID);
spanned(lo, hi, stmt)
} else if self.token.is_ident() &&
!self.token.is_any_keyword() &&
self.look_ahead(1, |t| *t == token::Not)
{
let pth =
match self.parse_path(NoTypesAllowed) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.bump();
let id =
match self.token {
token::OpenDelim(_) =>
token::special_idents::invalid,
_ =>
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
};
let delim =
match self.token {
token::OpenDelim(delim) => delim,
_ => {
let ident_str =
if id.name ==
token::special_idents::invalid.name
{
"identifier, "
} else { "" };
let tok_str =
self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected ",
"`(` or `{`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&ident_str,
&tok_str)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))))
}
};
let tts =
match self.parse_unspanned_seq(&token::OpenDelim(delim),
&token::CloseDelim(delim),
seq_sep_none(),
|p|
p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.last_span.hi;
let style =
if delim == token::Brace {
MacStmtWithBraces
} else { MacStmtWithoutBraces };
if id.name == token::special_idents::invalid.name
{
let stmt =
StmtMac(P(spanned(lo, hi,
Mac_{path: pth,
tts: tts,
ctxt:
EMPTY_CTXT,})),
style, attrs.into_thin_attrs());
spanned(lo, hi, stmt)
} else {
if style != MacStmtWithBraces {
if !self.eat(&token::Semi) {
let last_span = self.last_span;
self.span_err(last_span,
"macros that expand to items must either be surrounded with braces or followed by a semicolon");
}
}
spanned(lo, hi,
StmtDecl(P(spanned(lo, hi,
DeclItem(self.mk_item(lo,
hi,
id,
ItemMac(spanned(lo,
hi,
Mac_{path:
pth,
tts:
tts,
ctxt:
EMPTY_CTXT,})),
Inherited,
attrs)))),
ast::DUMMY_NODE_ID))
}
} else {
match match self.parse_item_(attrs.clone(), false,
true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
Some(i) => {
let hi = i.span.hi;
let decl =
P(spanned(lo, hi, DeclItem(i)));
spanned(lo, hi,
StmtDecl(decl,
ast::DUMMY_NODE_ID))
}
None => {
let unused_attrs =
|attrs: &[_], s: &mut Self| {
if attrs.len() > 0 {
s.span_err(s.span,
"expected statement after outer attribute");
} };
if self.token == token::Semi {
unused_attrs(&attrs, self);
self.bump();
return Ok(None);
}
if self.token ==
token::CloseDelim(token::Brace) {
unused_attrs(&attrs, self);
return Ok(None);
}
let e =
match self.parse_expr_res(RESTRICTION_STMT_EXPR,
Some(attrs.into_thin_attrs()))
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = e.span.hi;
let stmt =
StmtExpr(e, ast::DUMMY_NODE_ID);
spanned(lo, hi, stmt)
}
}
}))
}
/// Is this expression a successfully-parsed statement?
fn expr_is_complete(&mut self, e: &Expr) -> bool {
self.restrictions.contains(RESTRICTION_STMT_EXPR) &&
!classify::expr_requires_semi_to_be_stmt(e)
}
/// Parse a block. No inner attrs are allowed.
pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
{
let found =
match (self).token {
token::Interpolated(token::NtBlock(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtBlock(x))) =
found {
return Ok(x);
}
};
let lo = self.span.lo;
if !self.eat(&token::OpenDelim(token::Brace)) {
let sp = self.span;
let tok = self.this_token_to_string();
return Err(self.span_fatal_help(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `{`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&tok,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
"place this code inside a block"));
}
self.parse_block_tail(lo, DefaultBlock)
}
/// Parse a block. Inner attrs are allowed.
fn parse_inner_attrs_and_block(&mut self)
-> PResult<'a, (Vec<Attribute>, P<Block>)> {
{
let found =
match (self).token {
token::Interpolated(token::NtBlock(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtBlock(x))) =
found {
return Ok((Vec::new(), x));
}
};
let lo = self.span.lo;
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
match self.parse_block_tail(lo, DefaultBlock) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
}
/// Parse the rest of a block expression or function body
/// Precondition: already parsed the '{'.
fn parse_block_tail(&mut self, lo: BytePos, s: BlockCheckMode)
-> PResult<'a, P<Block>> {
let mut stmts = <[_]>::into_vec(::std::boxed::Box::new([]));
let mut expr = None;
while !self.eat(&token::CloseDelim(token::Brace)) {
let Spanned { node, span } =
if let Some(s) =
match self.parse_stmt_() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
s
} else { continue ; };
match node {
StmtExpr(e, _) => {
match self.handle_expression_like_statement(e,
span,
&mut stmts,
&mut expr)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
StmtMac(mac, MacStmtWithoutBraces, attrs) => {
match self.token {
token::Semi => {
stmts.push(P(Spanned{node:
StmtMac(mac,
MacStmtWithSemicolon,
attrs),
span:
mk_sp(span.lo,
self.span.hi),}));
self.bump();
}
_ => {
let e =
self.mk_mac_expr(span.lo, span.hi,
mac.and_then(|m|
m.node),
None);
let e =
match self.parse_dot_or_call_expr_with(e,
attrs)
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let e =
match self.parse_assoc_expr_with(0,
LhsExpr::AlreadyParsed(e))
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.handle_expression_like_statement(e,
span,
&mut stmts,
&mut expr)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
StmtMac(m, style, attrs) => {
match self.token {
token::Semi => {
stmts.push(P(Spanned{node:
StmtMac(m,
MacStmtWithSemicolon,
attrs),
span:
mk_sp(span.lo,
self.span.hi),}));
self.bump();
}
token::CloseDelim(token::Brace) => {
expr =
Some(self.mk_mac_expr(span.lo,
span.hi,
m.and_then(|x|
x.node),
attrs));
}
_ => {
stmts.push(P(Spanned{node:
StmtMac(m, style,
attrs),
span: span,}));
}
}
}
_ => {
let mut hi = span.hi;
if classify::stmt_ends_with_semi(&node) {
match self.commit_stmt_expecting(token::Semi)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hi = self.last_span.hi;
}
stmts.push(P(Spanned{node: node,
span: mk_sp(span.lo, hi),}));
}
}
}
Ok(P(ast::Block{stmts: stmts,
expr: expr,
id: ast::DUMMY_NODE_ID,
rules: s,
span: mk_sp(lo, self.last_span.hi),}))
}
fn handle_expression_like_statement(&mut self, e: P<Expr>,
span: Span,
stmts: &mut Vec<P<Stmt>>,
last_block_expr:
&mut Option<P<Expr>>)
-> PResult<'a, ()> {
if classify::expr_requires_semi_to_be_stmt(&*e) {
match self.commit_stmt(&[],
&[token::Semi,
token::CloseDelim(token::Brace)])
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.token {
token::Semi => {
self.bump();
let span_with_semi =
Span{lo: span.lo,
hi: self.last_span.hi,
expn_id: span.expn_id,};
stmts.push(P(Spanned{node:
StmtSemi(e,
ast::DUMMY_NODE_ID),
span: span_with_semi,}));
}
token::CloseDelim(token::Brace) =>
*last_block_expr = Some(e),
_ => {
stmts.push(P(Spanned{node:
StmtExpr(e,
ast::DUMMY_NODE_ID),
span: span,}));
}
}
Ok(())
}
fn parse_colon_then_ty_param_bounds(&mut self,
mode: BoundParsingMode)
-> PResult<'a, TyParamBounds> {
if !self.eat(&token::Colon) {
Ok(P::empty())
} else { self.parse_ty_param_bounds(mode) }
}
fn parse_ty_param_bounds(&mut self, mode: BoundParsingMode)
-> PResult<'a, TyParamBounds> {
let mut result = <[_]>::into_vec(::std::boxed::Box::new([]));
loop {
let question_span = self.span;
let ate_question = self.eat(&token::Question);
match self.token {
token::Lifetime(lifetime) => {
if ate_question {
self.span_err(question_span,
"`?` may only modify trait bounds, not lifetime bounds");
}
result.push(RegionTyParamBound(ast::Lifetime{id:
ast::DUMMY_NODE_ID,
span:
self.span,
name:
lifetime.name,}));
self.bump();
}
token::ModSep | token::Ident(..) => {
let poly_trait_ref =
match self.parse_poly_trait_ref() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let modifier =
if ate_question {
if mode == BoundParsingMode::Modified {
TraitBoundModifier::Maybe
} else {
self.span_err(question_span,
"unexpected `?`");
TraitBoundModifier::None
}
} else { TraitBoundModifier::None };
result.push(TraitTyParamBound(poly_trait_ref,
modifier))
}
_ => break ,
}
if !self.eat(&token::BinOp(token::Plus)) { break ; }
}
return Ok(P::from_vec(result));
}
/// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )?
fn parse_ty_param(&mut self) -> PResult<'a, TyParam> {
let span = self.span;
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let bounds =
match self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let default =
if self.check(&token::Eq) {
self.bump();
Some(match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
})
} else { None };
Ok(TyParam{ident: ident,
id: ast::DUMMY_NODE_ID,
bounds: bounds,
default: default,
span: span,})
}
/// Parse a set of optional generic type parameter declarations. Where
/// clauses are not parsed here, and must be added later via
/// `parse_where_clause()`.
///
/// matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > )
/// | ( < lifetimes , typaramseq ( , )? > )
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
pub fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
{
let found =
match (self).token {
token::Interpolated(token::NtGenerics(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtGenerics(x))) =
found {
return Ok(x.clone());
}
};
if self.eat(&token::Lt) {
let lifetime_defs =
match self.parse_lifetime_defs() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut seen_default = false;
let ty_params =
match self.parse_seq_to_gt(Some(token::Comma), |p| {
match p.forbid_lifetime() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ty_param =
match p.parse_ty_param()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if ty_param.default.is_some()
{
seen_default = true;
} else if seen_default {
let last_span =
p.last_span;
p.span_err(last_span,
"type parameters with a default must be trailing");
} Ok(ty_param) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(ast::Generics{lifetimes: lifetime_defs,
ty_params: ty_params,
where_clause:
WhereClause{id: ast::DUMMY_NODE_ID,
predicates:
Vec::new(),},})
} else { Ok(ast::Generics::default()) }
}
fn parse_generic_values_after_lt(&mut self)
->
PResult<'a,
(Vec<ast::Lifetime>, Vec<P<Ty>>, Vec<P<TypeBinding>>)> {
let span_lo = self.span.lo;
let lifetimes =
match self.parse_lifetimes(token::Comma) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let missing_comma =
!lifetimes.is_empty() && !self.token.is_like_gt() &&
self.last_token.as_ref().map_or(true,
|x|
&**x !=
&token::Comma);
if missing_comma {
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `,` or `>` after lifetime name, found `",
"`"];
__STATIC_FMTSTR
},
&match (&self.this_token_to_string(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
let mut err =
self.diagnostic().struct_span_err(self.span, &msg);
let span_hi = self.span.hi;
let span_hi =
if self.parse_ty().is_ok() {
self.span.hi
} else { span_hi };
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["did you mean a single argument type &\'a Type, or did you mean the comma-separated arguments \'a, Type?"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}));
err.span_note(mk_sp(span_lo, span_hi), &msg);
err.emit();
self.abort_if_errors()
}
let (types, returned) =
match self.parse_seq_to_gt_or_return(Some(token::Comma),
|p| {
match p.forbid_lifetime()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if p.look_ahead(1,
|t|
t
==
&token::Eq)
{
Ok(None)
} else {
Ok(Some(match p.parse_ty_sum()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !returned {
return Ok((lifetimes, types.into_vec(), Vec::new()));
}
let bindings =
match self.parse_seq_to_gt(Some(token::Comma), |p| {
match p.forbid_lifetime() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; let lo = p.span.lo;
let ident =
match p.parse_ident() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let found_eq =
p.eat(&token::Eq);
if !found_eq {
let span = p.span;
p.span_warn(span,
"whoops, no =?");
}
let ty =
match p.parse_ty() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; let hi = ty.span.hi;
let span = mk_sp(lo, hi);
return Ok(P(TypeBinding{id:
ast::DUMMY_NODE_ID,
ident:
ident,
ty: ty,
span:
span,}));
}) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((lifetimes, types.into_vec(), bindings.into_vec()))
}
fn forbid_lifetime(&mut self) -> PResult<'a, ()> {
if self.token.is_lifetime() {
let span = self.span;
return Err(self.span_fatal(span,
"lifetime parameters must be declared prior to type parameters"))
}
Ok(())
}
/// Parses an optional `where` clause and places it in `generics`.
///
/// ```ignore
/// where T : Trait<U, V> + 'b, 'a : 'b
/// ```
pub fn parse_where_clause(&mut self)
-> PResult<'a, ast::WhereClause> {
{
let found =
match (self).token {
token::Interpolated(token::NtWhereClause(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtWhereClause(x)))
= found {
return Ok(x.clone());
}
};
let mut where_clause =
WhereClause{id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),};
if !self.eat_keyword(keywords::Where) {
return Ok(where_clause);
}
let mut parsed_something = false;
loop {
let lo = self.span.lo;
match self.token {
token::OpenDelim(token::Brace) => { break }
token::Lifetime(..) => {
let bounded_lifetime =
match self.parse_lifetime() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.eat(&token::Colon);
let bounds =
match self.parse_lifetimes(token::BinOp(token::Plus))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.last_span.hi;
let span = mk_sp(lo, hi);
where_clause.predicates.push(ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{span:
span,
lifetime:
bounded_lifetime,
bounds:
bounds,}));
parsed_something = true;
}
_ => {
let bound_lifetimes =
if self.eat_keyword(keywords::For) {
match self.expect(&token::Lt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lifetime_defs =
match self.parse_lifetime_defs() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect_gt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
lifetime_defs
} else {
<[_]>::into_vec(::std::boxed::Box::new([]))
};
let bounded_ty =
match self.parse_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat(&token::Colon) {
let bounds =
match self.parse_ty_param_bounds(BoundParsingMode::Bare)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.last_span.hi;
let span = mk_sp(lo, hi);
if bounds.is_empty() {
self.span_err(span,
"each predicate in a `where` clause must have at least one bound in it");
}
where_clause.predicates.push(ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{span:
span,
bound_lifetimes:
bound_lifetimes,
bounded_ty:
bounded_ty,
bounds:
bounds,}));
parsed_something = true;
} else if self.eat(&token::Eq) {
let hi = self.last_span.hi;
let span = mk_sp(lo, hi);
self.span_err(span,
"equality constraints are not yet supported in where clauses (#20041)");
} else {
let last_span = self.last_span;
self.span_err(last_span,
"unexpected token in `where` clause");
}
}
};
if !self.eat(&token::Comma) { break }
}
if !parsed_something {
let last_span = self.last_span;
self.span_err(last_span,
"a `where` clause must have at least one predicate in it");
}
Ok(where_clause)
}
fn parse_fn_args(&mut self, named_args: bool,
allow_variadic: bool)
-> PResult<'a, (Vec<Arg>, bool)> {
let sp = self.span;
let mut args: Vec<Option<Arg>> =
match self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p| {
if p.token ==
token::DotDotDot {
p.bump();
if allow_variadic {
if p.token !=
token::CloseDelim(token::Paren)
{
let span =
p.span;
return Err(p.span_fatal(span,
"`...` must be last in argument list for variadic function"))
}
} else {
let span = p.span;
return Err(p.span_fatal(span,
"only foreign functions are allowed to be variadic"))
}
Ok(None)
} else {
Ok(Some(match p.parse_arg_general(named_args)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let variadic =
match args.pop() {
Some(None) => true,
Some(x) => { args.push(x); false }
None => false,
};
if variadic && args.is_empty() {
self.span_err(sp,
"variadic function must be declared with at least one named argument");
}
let args = args.into_iter().map(|x| x.unwrap()).collect();
Ok((args, variadic))
}
/// Parse the argument list and result type of a function declaration
pub fn parse_fn_decl(&mut self, allow_variadic: bool)
-> PResult<'a, P<FnDecl>> {
let (args, variadic) =
match self.parse_fn_args(true, allow_variadic) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ret_ty =
match self.parse_ret_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(P(FnDecl{inputs: args,
output: ret_ty,
variadic: variadic,}))
}
fn is_self_ident(&mut self) -> bool {
match self.token {
token::Ident(id, token::Plain) =>
id.name == special_idents::self_.name,
_ => false,
}
}
fn expect_self_ident(&mut self) -> PResult<'a, ast::Ident> {
match self.token {
token::Ident(id, token::Plain) if
id.name == special_idents::self_.name => {
self.bump();
Ok(id)
}
_ => {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `self`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
}
}
fn is_self_type_ident(&mut self) -> bool {
match self.token {
token::Ident(id, token::Plain) =>
id.name == special_idents::type_self.name,
_ => false,
}
}
fn expect_self_type_ident(&mut self) -> PResult<'a, ast::Ident> {
match self.token {
token::Ident(id, token::Plain) if
id.name == special_idents::type_self.name => {
self.bump();
Ok(id)
}
_ => {
let token_str = self.this_token_to_string();
Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `Self`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
}
}
/// Parse the argument list and result type of a function
/// that may have a self type.
fn parse_fn_decl_with_self<F>(&mut self, parse_arg_fn: F)
-> PResult<'a, (ExplicitSelf, P<FnDecl>)> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, Arg> {
fn maybe_parse_borrowed_explicit_self<'b>(this:
&mut Parser<'b>)
-> PResult<'b, ast::ExplicitSelf_> {
if this.look_ahead(1,
|t| t.is_keyword(keywords::SelfValue))
{
this.bump();
Ok(SelfRegion(None, MutImmutable,
match this.expect_self_ident() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} else if this.look_ahead(1, |t| t.is_mutability()) &&
this.look_ahead(2,
|t|
t.is_keyword(keywords::SelfValue))
{
this.bump();
let mutability =
match this.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(SelfRegion(None, mutability,
match this.expect_self_ident() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} else if this.look_ahead(1, |t| t.is_lifetime()) &&
this.look_ahead(2,
|t|
t.is_keyword(keywords::SelfValue))
{
this.bump();
let lifetime =
match this.parse_lifetime() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(SelfRegion(Some(lifetime), MutImmutable,
match this.expect_self_ident() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} else if this.look_ahead(1, |t| t.is_lifetime()) &&
this.look_ahead(2, |t| t.is_mutability()) &&
this.look_ahead(3,
|t|
t.is_keyword(keywords::SelfValue))
{
this.bump();
let lifetime =
match this.parse_lifetime() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mutability =
match this.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(SelfRegion(Some(lifetime), mutability,
match this.expect_self_ident() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}))
} else { Ok(SelfStatic) }
}
match self.expect(&token::OpenDelim(token::Paren)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lo = self.span.lo;
let mut self_ident_lo = self.span.lo;
let mut self_ident_hi = self.span.hi;
let mut mutbl_self = MutImmutable;
let explicit_self =
match self.token {
token::BinOp(token::And) => {
let eself =
match maybe_parse_borrowed_explicit_self(self)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self_ident_lo = self.last_span.lo;
self_ident_hi = self.last_span.hi;
eself
}
token::BinOp(token::Star) => {
self.bump();
let _mutability =
if self.token.is_mutability() {
match self.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else { MutImmutable };
if self.is_self_ident() {
let span = self.span;
self.span_err(span,
"cannot pass self by raw pointer");
self.bump();
}
SelfValue(special_idents::self_)
}
token::Ident(..) => {
if self.is_self_ident() {
let self_ident =
match self.expect_self_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat(&token::Colon) {
SelfExplicit(match self.parse_ty_sum() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, self_ident)
} else { SelfValue(self_ident) }
} else if self.token.is_mutability() &&
self.look_ahead(1,
|t|
t.is_keyword(keywords::SelfValue))
{
mutbl_self =
match self.parse_mutability() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let self_ident =
match self.expect_self_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat(&token::Colon) {
SelfExplicit(match self.parse_ty_sum() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, self_ident)
} else { SelfValue(self_ident) }
} else { SelfStatic }
}
_ => SelfStatic,
};
let explicit_self_sp = mk_sp(self_ident_lo, self_ident_hi);
let fn_inputs =
match explicit_self {
SelfStatic => {
let sep = seq_sep_trailing_allowed(token::Comma);
match self.parse_seq_to_before_end(&token::CloseDelim(token::Paren),
sep,
parse_arg_fn) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
SelfValue(id) =>
match self.token {
token::Comma => {
self.bump();
let sep =
seq_sep_trailing_allowed(token::Comma);
let mut fn_inputs =
match self.parse_seq_to_before_end(&token::CloseDelim(token::Paren),
sep,
parse_arg_fn)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
fn_inputs.insert(0,
Arg::new_self(explicit_self_sp,
mutbl_self,
id));
fn_inputs
}
token::CloseDelim(token::Paren) => {
<[_]>::into_vec(::std::boxed::Box::new([Arg::new_self(explicit_self_sp,
mutbl_self,
id)]))
}
_ => {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `,` or `)`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
},
SelfRegion(_, _, id) =>
match self.token {
token::Comma => {
self.bump();
let sep =
seq_sep_trailing_allowed(token::Comma);
let mut fn_inputs =
match self.parse_seq_to_before_end(&token::CloseDelim(token::Paren),
sep,
parse_arg_fn)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
fn_inputs.insert(0,
Arg::new_self(explicit_self_sp,
mutbl_self,
id));
fn_inputs
}
token::CloseDelim(token::Paren) => {
<[_]>::into_vec(::std::boxed::Box::new([Arg::new_self(explicit_self_sp,
mutbl_self,
id)]))
}
_ => {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `,` or `)`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
},
SelfExplicit(_, id) =>
match self.token {
token::Comma => {
self.bump();
let sep =
seq_sep_trailing_allowed(token::Comma);
let mut fn_inputs =
match self.parse_seq_to_before_end(&token::CloseDelim(token::Paren),
sep,
parse_arg_fn)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
fn_inputs.insert(0,
Arg::new_self(explicit_self_sp,
mutbl_self,
id));
fn_inputs
}
token::CloseDelim(token::Paren) => {
<[_]>::into_vec(::std::boxed::Box::new([Arg::new_self(explicit_self_sp,
mutbl_self,
id)]))
}
_ => {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `,` or `)`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
},
};
match self.expect(&token::CloseDelim(token::Paren)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
let ret_ty =
match self.parse_ret_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let fn_decl =
P(FnDecl{inputs: fn_inputs,
output: ret_ty,
variadic: false,});
Ok((spanned(lo, hi, explicit_self), fn_decl))
}
fn parse_fn_block_decl(&mut self) -> PResult<'a, P<FnDecl>> {
let inputs_captures =
{
if self.eat(&token::OrOr) {
Vec::new()
} else {
match self.expect(&token::BinOp(token::Or)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.parse_obsolete_closure_kind() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let args =
match self.parse_seq_to_before_end(&token::BinOp(token::Or),
seq_sep_trailing_allowed(token::Comma),
|p|
p.parse_fn_block_arg())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.bump();
args
}
};
let output =
match self.parse_ret_ty() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(P(FnDecl{inputs: inputs_captures,
output: output,
variadic: false,}))
}
/// Parse the name and optional generic types of a function header.
fn parse_fn_header(&mut self)
-> PResult<'a, (Ident, ast::Generics)> {
let id =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let generics =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((id, generics))
}
fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident,
node: Item_, vis: Visibility, attrs: Vec<Attribute>)
-> P<Item> {
P(Item{ident: ident,
attrs: attrs,
id: ast::DUMMY_NODE_ID,
node: node,
vis: vis,
span: mk_sp(lo, hi),})
}
/// Parse an item-position function declaration.
fn parse_item_fn(&mut self, unsafety: Unsafety,
constness: Constness, abi: abi::Abi)
-> PResult<'a, ItemInfo> {
let (ident, mut generics) =
match self.parse_fn_header() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let decl =
match self.parse_fn_decl(false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (inner_attrs, body) =
match self.parse_inner_attrs_and_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((ident,
ItemFn(decl, unsafety, constness, abi, generics, body),
Some(inner_attrs)))
}
/// true if we are looking at `const ID`, false for things like `const fn` etc
pub fn is_const_item(&mut self) -> bool {
self.token.is_keyword(keywords::Const) &&
!self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) &&
!self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe))
}
/// parses all the "front matter" for a `fn` declaration, up to
/// and including the `fn` keyword:
///
/// - `const fn`
/// - `unsafe fn`
/// - `const unsafe fn`
/// - `extern fn`
/// - etc
pub fn parse_fn_front_matter(&mut self)
-> PResult<'a, (ast::Constness, ast::Unsafety, abi::Abi)> {
let is_const_fn = self.eat_keyword(keywords::Const);
let unsafety =
match self.parse_unsafety() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (constness, unsafety, abi) =
if is_const_fn {
(Constness::Const, unsafety, abi::Rust)
} else {
let abi =
if self.eat_keyword(keywords::Extern) {
match self.parse_opt_abi() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.unwrap_or(abi::C)
} else { abi::Rust };
(Constness::NotConst, unsafety, abi)
};
match self.expect_keyword(keywords::Fn) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((constness, unsafety, abi))
}
/// Parse an impl item.
pub fn parse_impl_item(&mut self) -> PResult<'a, P<ImplItem>> {
{
let found =
match (self).token {
token::Interpolated(token::NtImplItem(_)) => {
Some((self).bump_and_get())
}
_ => None,
};
if let Some(token::Interpolated(token::NtImplItem(x))) =
found {
return Ok(x);
}
};
let mut attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lo = self.span.lo;
let vis =
match self.parse_visibility() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (name, node) =
if self.eat_keyword(keywords::Type) {
let name =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Eq) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let typ =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(name, ast::ImplItemKind::Type(typ))
} else if self.is_const_item() {
match self.expect_keyword(keywords::Const) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let name =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let typ =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Eq) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let expr =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commit_expr_expecting(&expr, token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(name, ast::ImplItemKind::Const(typ, expr))
} else {
let (name, inner_attrs, node) =
match self.parse_impl_method(vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
attrs.extend(inner_attrs);
(name, node)
};
Ok(P(ImplItem{id: ast::DUMMY_NODE_ID,
span: mk_sp(lo, self.last_span.hi),
ident: name,
vis: vis,
attrs: attrs,
node: node,}))
}
fn complain_if_pub_macro(&mut self, visa: Visibility,
span: Span) {
match visa {
Public => {
let is_macro_rules: bool =
match self.token {
token::Ident(sid, _) =>
sid.name == intern("macro_rules"),
_ => false,
};
if is_macro_rules {
self.diagnostic().struct_span_err(span,
"can\'t qualify macro_rules invocation with `pub`").fileline_help(span,
"did you mean #[macro_export]?").emit();
} else {
self.diagnostic().struct_span_err(span,
"can\'t qualify macro invocation with `pub`").fileline_help(span,
"try adjusting the macro to put `pub` inside the invocation").emit();
}
}
Inherited => (),
}
}
/// Parse a method or a macro invocation in a trait impl.
fn parse_impl_method(&mut self, vis: Visibility)
-> PResult<'a, (Ident, Vec<ast::Attribute>, ast::ImplItemKind)> {
if !self.token.is_any_keyword() &&
self.look_ahead(1, |t| *t == token::Not) &&
(self.look_ahead(2,
|t|
*t ==
token::OpenDelim(token::Paren))
||
self.look_ahead(2,
|t|
*t ==
token::OpenDelim(token::Brace)))
{
let last_span = self.last_span;
self.complain_if_pub_macro(vis, last_span);
let lo = self.span.lo;
let pth =
match self.parse_path(NoTypesAllowed) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Not) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let delim =
match self.expect_open_delim() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let tts =
match self.parse_seq_to_end(&token::CloseDelim(delim),
seq_sep_none(),
|p| p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let m_ = Mac_{path: pth, tts: tts, ctxt: EMPTY_CTXT,};
let m: ast::Mac =
codemap::Spanned{node: m_,
span: mk_sp(lo, self.last_span.hi),};
if delim != token::Brace {
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
Ok((token::special_idents::invalid,
<[_]>::into_vec(::std::boxed::Box::new([])),
ast::ImplItemKind::Macro(m)))
} else {
let (constness, unsafety, abi) =
match self.parse_fn_front_matter() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut generics =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (explicit_self, decl) =
match self.parse_fn_decl_with_self(|p| { p.parse_arg()
}) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (inner_attrs, body) =
match self.parse_inner_attrs_and_block() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((ident, inner_attrs,
ast::ImplItemKind::Method(ast::MethodSig{generics:
generics,
abi: abi,
explicit_self:
explicit_self,
unsafety:
unsafety,
constness:
constness,
decl: decl,},
body)))
}
}
/// Parse trait Foo { ... }
fn parse_item_trait(&mut self, unsafety: Unsafety)
-> PResult<'a, ItemInfo> {
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut tps =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let bounds =
match self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
tps.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let meths =
match self.parse_trait_items() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((ident, ItemTrait(unsafety, tps, bounds, meths), None))
}
/// Parses items implementations variants
/// impl<T> Foo { ... }
/// impl<T> ToString for &'static T { ... }
/// impl Send for .. {}
fn parse_item_impl(&mut self, unsafety: ast::Unsafety)
-> PResult<'a, ItemInfo> {
let impl_span = self.span;
let mut generics =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let could_be_trait =
self.token != token::OpenDelim(token::Paren);
let neg_span = self.span;
let polarity =
if self.eat(&token::Not) {
ast::ImplPolarity::Negative
} else { ast::ImplPolarity::Positive };
let mut ty =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let opt_trait =
if could_be_trait && self.eat_keyword(keywords::For) {
match ty.node {
TyPath(None, ref path) => {
Some(TraitRef{path: (*path).clone(),
ref_id: ty.id,})
}
_ => {
self.span_err(ty.span, "not a trait");
None
}
}
} else {
match polarity {
ast::ImplPolarity::Negative => {
self.span_err(neg_span,
"inherent implementation can\'t be negated");
}
_ => { }
}
None
};
if opt_trait.is_some() && self.eat(&token::DotDot) {
if generics.is_parameterized() {
self.span_err(impl_span,
"default trait implementations are not allowed to have generics");
}
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::CloseDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((ast_util::impl_pretty_name(&opt_trait, None),
ItemDefaultImpl(unsafety, opt_trait.unwrap()), None))
} else {
if opt_trait.is_some() {
ty =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let attrs =
match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut impl_items =
<[_]>::into_vec(::std::boxed::Box::new([]));
while !self.eat(&token::CloseDelim(token::Brace)) {
impl_items.push(match self.parse_impl_item() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
Ok((ast_util::impl_pretty_name(&opt_trait, Some(&*ty)),
ItemImpl(unsafety, polarity, generics, opt_trait, ty,
impl_items), Some(attrs)))
}
}
/// Parse a::B<String,i32>
fn parse_trait_ref(&mut self) -> PResult<'a, TraitRef> {
Ok(ast::TraitRef{path:
match self.parse_path(LifetimeAndTypesWithoutColons)
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ref_id: ast::DUMMY_NODE_ID,})
}
fn parse_late_bound_lifetime_defs(&mut self)
-> PResult<'a, Vec<ast::LifetimeDef>> {
if self.eat_keyword(keywords::For) {
match self.expect(&token::Lt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lifetime_defs =
match self.parse_lifetime_defs() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect_gt() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(lifetime_defs)
} else { Ok(Vec::new()) }
}
/// Parse for<'l> a::B<String,i32>
fn parse_poly_trait_ref(&mut self) -> PResult<'a, PolyTraitRef> {
let lo = self.span.lo;
let lifetime_defs =
match self.parse_late_bound_lifetime_defs() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(ast::PolyTraitRef{bound_lifetimes: lifetime_defs,
trait_ref:
match self.parse_trait_ref() {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
span: mk_sp(lo, self.last_span.hi),})
}
/// Parse struct Foo { ... }
fn parse_item_struct(&mut self) -> PResult<'a, ItemInfo> {
let class_name =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut generics =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let vdata =
if self.token.is_keyword(keywords::Where) {
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat(&token::Semi) {
VariantData::Unit(ast::DUMMY_NODE_ID)
} else {
VariantData::Struct(match self.parse_record_struct_body(ParsePub::Yes)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, ast::DUMMY_NODE_ID)
}
} else if self.eat(&token::Semi) {
VariantData::Unit(ast::DUMMY_NODE_ID)
} else if self.token == token::OpenDelim(token::Brace) {
VariantData::Struct(match self.parse_record_struct_body(ParsePub::Yes)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, ast::DUMMY_NODE_ID)
} else if self.token == token::OpenDelim(token::Paren) {
let body =
VariantData::Tuple(match self.parse_tuple_struct_body(ParsePub::Yes)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, ast::DUMMY_NODE_ID);
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
body
} else {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `where`, `{`, `(`, or `;` after struct name, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
};
Ok((class_name, ItemStruct(vdata, generics), None))
}
pub fn parse_record_struct_body(&mut self, parse_pub: ParsePub)
-> PResult<'a, Vec<StructField>> {
let mut fields = Vec::new();
if self.eat(&token::OpenDelim(token::Brace)) {
while self.token != token::CloseDelim(token::Brace) {
fields.push(match self.parse_struct_decl_field(parse_pub)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
self.bump();
} else {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `where`, or `{` after struct name, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))));
}
Ok(fields)
}
pub fn parse_tuple_struct_body(&mut self, parse_pub: ParsePub)
-> PResult<'a, Vec<StructField>> {
let fields =
match self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p| {
let attrs =
match p.parse_outer_attributes()
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; let lo = p.span.lo;
let struct_field_ =
ast::StructField_{kind:
UnnamedField(if parse_pub
==
ParsePub::Yes
{
match p.parse_visibility()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else {
Inherited
}),
id:
ast::DUMMY_NODE_ID,
ty:
match p.parse_ty_sum()
{
::std::result::Result::Ok(val)
=>
val,
::std::result::Result::Err(err)
=>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
attrs:
attrs,};
Ok(spanned(lo, p.span.hi,
struct_field_))
}) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(fields)
}
/// Parse a structure field declaration
pub fn parse_single_struct_field(&mut self, vis: Visibility,
attrs: Vec<Attribute>)
-> PResult<'a, StructField> {
let a_var =
match self.parse_name_and_ty(vis, attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.token {
token::Comma => { self.bump(); }
token::CloseDelim(token::Brace) => { }
_ => {
let span = self.span;
let token_str = self.this_token_to_string();
return Err(self.span_fatal_help(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `,`, or `}`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
"struct fields should be separated by commas"))
}
}
Ok(a_var)
}
/// Parse an element of a struct definition
fn parse_struct_decl_field(&mut self, parse_pub: ParsePub)
-> PResult<'a, StructField> {
let attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat_keyword(keywords::Pub) {
if parse_pub == ParsePub::No {
let span = self.last_span;
self.span_err(span, "`pub` is not allowed here");
}
return self.parse_single_struct_field(Public, attrs);
}
return self.parse_single_struct_field(Inherited, attrs);
}
/// Parse visibility: PUB or nothing
fn parse_visibility(&mut self) -> PResult<'a, Visibility> {
if self.eat_keyword(keywords::Pub) {
Ok(Public)
} else { Ok(Inherited) }
}
/// Given a termination token, parse all of the items in a module
fn parse_mod_items(&mut self, term: &token::Token,
inner_lo: BytePos) -> PResult<'a, Mod> {
let mut items = <[_]>::into_vec(::std::boxed::Box::new([]));
while let Some(item) =
match self.parse_item() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
items.push(item);
}
if !self.eat(term) {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected item, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))));
}
let hi =
if self.span == codemap::DUMMY_SP {
inner_lo
} else { self.last_span.hi };
Ok(ast::Mod{inner: mk_sp(inner_lo, hi), items: items,})
}
fn parse_item_const(&mut self, m: Option<Mutability>)
-> PResult<'a, ItemInfo> {
let id =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ty =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Eq) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let e =
match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commit_expr_expecting(&*e, token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let item =
match m {
Some(m) => ItemStatic(ty, m, e),
None => ItemConst(ty, e),
};
Ok((id, item, None))
}
/// Parse a `mod <foo> { ... }` or `mod <foo>;` item
fn parse_item_mod(&mut self, outer_attrs: &[Attribute])
-> PResult<'a, ItemInfo> {
let id_span = self.span;
let id =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::Semi) {
self.bump();
let (m, attrs) =
match self.eval_src_mod(id, outer_attrs, id_span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((id, m, Some(attrs)))
} else {
self.push_mod_path(id, outer_attrs);
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mod_inner_lo = self.span.lo;
let old_owns_directory = self.owns_directory;
self.owns_directory = true;
let attrs =
match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let m =
match self.parse_mod_items(&token::CloseDelim(token::Brace),
mod_inner_lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.owns_directory = old_owns_directory;
self.pop_mod_path();
Ok((id, ItemMod(m), Some(attrs)))
}
}
fn push_mod_path(&mut self, id: Ident, attrs: &[Attribute]) {
let default_path = self.id_to_interned_str(id);
let file_path =
match ::attr::first_attr_value_str_by_name(attrs, "path")
{
Some(d) => d,
None => default_path,
};
self.mod_path_stack.push(file_path)
}
fn pop_mod_path(&mut self) { self.mod_path_stack.pop().unwrap(); }
pub fn submod_path_from_attr(attrs: &[ast::Attribute],
dir_path: &Path) -> Option<PathBuf> {
::attr::first_attr_value_str_by_name(attrs,
"path").map(|d|
dir_path.join(&*d))
}
/// Returns either a path to a module, or .
pub fn default_submod_path(id: ast::Ident, dir_path: &Path,
codemap: &CodeMap) -> ModulePath {
let mod_name = id.to_string();
let default_path_str =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
".rs"];
__STATIC_FMTSTR
},
&match (&mod_name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
let secondary_path_str =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"/mod.rs"];
__STATIC_FMTSTR
},
&match (&mod_name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
let default_path = dir_path.join(&default_path_str);
let secondary_path = dir_path.join(&secondary_path_str);
let default_exists = codemap.file_exists(&default_path);
let secondary_exists = codemap.file_exists(&secondary_path);
let result =
match (default_exists, secondary_exists) {
(true, false) =>
Ok(ModulePathSuccess{path: default_path,
owns_directory: false,}),
(false, true) =>
Ok(ModulePathSuccess{path: secondary_path,
owns_directory: true,}),
(false, false) =>
Err(ModulePathError{err_msg:
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["file not found for module `",
"`"];
__STATIC_FMTSTR
},
&match (&mod_name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
help_msg:
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["name the file either ",
" or ",
" inside the directory "];
__STATIC_FMTSTR
},
&match (&default_path_str,
&secondary_path_str,
&dir_path.display())
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Debug::fmt)],
})),}),
(true, true) =>
Err(ModulePathError{err_msg:
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["file for module `",
"` found at both ",
" and "];
__STATIC_FMTSTR
},
&match (&mod_name,
&default_path_str,
&secondary_path_str)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
})),
help_msg:
"delete or rename one of them to remove the ambiguity".to_owned(),}),
};
ModulePath{name: mod_name,
path_exists: default_exists || secondary_exists,
result: result,}
}
fn submod_path(&mut self, id: ast::Ident,
outer_attrs: &[ast::Attribute], id_sp: Span)
-> PResult<'a, ModulePathSuccess> {
let mut prefix =
PathBuf::from(&self.sess.codemap().span_to_filename(self.span));
prefix.pop();
let mut dir_path = prefix;
for part in &self.mod_path_stack { dir_path.push(&**part); }
if let Some(p) =
Parser::submod_path_from_attr(outer_attrs, &dir_path) {
return Ok(ModulePathSuccess{path: p,
owns_directory: true,});
}
let paths =
Parser::default_submod_path(id, &dir_path,
self.sess.codemap());
if !self.owns_directory {
let mut err =
self.diagnostic().struct_span_err(id_sp,
"cannot declare a new module at this location");
let this_module =
match self.mod_path_stack.last() {
Some(name) => name.to_string(),
None =>
self.root_module_name.as_ref().unwrap().clone(),
};
err.span_note(id_sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["maybe move this module `",
"` to its own directory via `",
"/mod.rs`"];
__STATIC_FMTSTR
},
&match (&this_module,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
})));
if paths.path_exists {
err.span_note(id_sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["... or maybe `use` the module `",
"` instead of possibly redeclaring it"];
__STATIC_FMTSTR
},
&match (&paths.name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
err.emit();
self.abort_if_errors();
}
match paths.result {
Ok(succ) => Ok(succ),
Err(err) =>
Err(self.span_fatal_help(id_sp, &err.err_msg,
&err.help_msg)),
}
}
/// Read a module from a source file.
fn eval_src_mod(&mut self, id: ast::Ident,
outer_attrs: &[ast::Attribute], id_sp: Span)
-> PResult<'a, (ast::Item_, Vec<ast::Attribute>)> {
let ModulePathSuccess { path, owns_directory } =
match self.submod_path(id, outer_attrs, id_sp) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.eval_src_mod_from_path(path, owns_directory,
id.to_string(), id_sp)
}
fn eval_src_mod_from_path(&mut self, path: PathBuf,
owns_directory: bool, name: String,
id_sp: Span)
-> PResult<'a, (ast::Item_, Vec<ast::Attribute>)> {
let mut included_mod_stack =
self.sess.included_mod_stack.borrow_mut();
match included_mod_stack.iter().position(|p| *p == path) {
Some(i) => {
let mut err = String::from("circular modules: ");
let len = included_mod_stack.len();
for p in &included_mod_stack[i..len] {
err.push_str(&p.to_string_lossy());
err.push_str(" -> ");
}
err.push_str(&path.to_string_lossy());
return Err(self.span_fatal(id_sp, &err[..]));
}
None => (),
}
included_mod_stack.push(path.clone());
drop(included_mod_stack);
let mut p0 =
new_sub_parser_from_file(self.sess, self.cfg.clone(),
&path, owns_directory,
Some(name), id_sp);
let mod_inner_lo = p0.span.lo;
let mod_attrs =
match p0.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let m0 =
match p0.parse_mod_items(&token::Eof, mod_inner_lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.sess.included_mod_stack.borrow_mut().pop();
Ok((ast::ItemMod(m0), mod_attrs))
}
/// Parse a function declaration from a foreign module
fn parse_item_foreign_fn(&mut self, vis: ast::Visibility,
lo: BytePos, attrs: Vec<Attribute>)
-> PResult<'a, P<ForeignItem>> {
match self.expect_keyword(keywords::Fn) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (ident, mut generics) =
match self.parse_fn_header() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let decl =
match self.parse_fn_decl(true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(P(ast::ForeignItem{ident: ident,
attrs: attrs,
node: ForeignItemFn(decl, generics),
id: ast::DUMMY_NODE_ID,
span: mk_sp(lo, hi),
vis: vis,}))
}
/// Parse a static item from a foreign module
fn parse_item_foreign_static(&mut self, vis: ast::Visibility,
lo: BytePos, attrs: Vec<Attribute>)
-> PResult<'a, P<ForeignItem>> {
match self.expect_keyword(keywords::Static) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mutbl = self.eat_keyword(keywords::Mut);
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Colon) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ty =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(P(ForeignItem{ident: ident,
attrs: attrs,
node: ForeignItemStatic(ty, mutbl),
id: ast::DUMMY_NODE_ID,
span: mk_sp(lo, hi),
vis: vis,}))
}
/// Parse extern crate links
///
/// # Examples
///
/// extern crate foo;
/// extern crate bar as foo;
fn parse_item_extern_crate(&mut self, lo: BytePos,
visibility: Visibility,
attrs: Vec<Attribute>)
-> PResult<'a, P<Item>> {
let crate_name =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (maybe_path, ident) =
if let Some(ident) =
match self.parse_rename() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
(Some(crate_name.name), ident)
} else { (None, crate_name) };
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
if visibility == ast::Public {
self.span_warn(mk_sp(lo, last_span.hi),
"`pub extern crate` does not work as expected and should not be used. Likely to become an error. Prefer `extern crate` and `pub use`.");
}
Ok(self.mk_item(lo, last_span.hi, ident,
ItemExternCrate(maybe_path), visibility,
attrs))
}
/// Parse `extern` for foreign ABIs
/// modules.
///
/// `extern` is expected to have been
/// consumed before calling this method
///
/// # Examples:
///
/// extern "C" {}
/// extern {}
fn parse_item_foreign_mod(&mut self, lo: BytePos,
opt_abi: Option<abi::Abi>,
visibility: Visibility,
mut attrs: Vec<Attribute>)
-> PResult<'a, P<Item>> {
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let abi = opt_abi.unwrap_or(abi::C);
attrs.extend(match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
let mut foreign_items =
<[_]>::into_vec(::std::boxed::Box::new([]));
while let Some(item) =
match self.parse_foreign_item() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
foreign_items.push(item);
}
match self.expect(&token::CloseDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let m = ast::ForeignMod{abi: abi, items: foreign_items,};
Ok(self.mk_item(lo, last_span.hi, special_idents::invalid,
ItemForeignMod(m), visibility, attrs))
}
/// Parse type Foo = Bar;
fn parse_item_type(&mut self) -> PResult<'a, ItemInfo> {
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut tps =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
tps.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Eq) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let ty =
match self.parse_ty_sum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((ident, ItemTy(ty, tps), None))
}
/// Parse the part of an "enum" decl following the '{'
fn parse_enum_def(&mut self, _generics: &ast::Generics)
-> PResult<'a, EnumDef> {
let mut variants = Vec::new();
let mut all_nullary = true;
let mut any_disr = None;
while self.token != token::CloseDelim(token::Brace) {
let variant_attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let vlo = self.span.lo;
let struct_def;
let mut disr_expr = None;
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check(&token::OpenDelim(token::Brace)) {
all_nullary = false;
struct_def =
VariantData::Struct(match self.parse_record_struct_body(ParsePub::No)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, ast::DUMMY_NODE_ID);
} else if self.check(&token::OpenDelim(token::Paren)) {
all_nullary = false;
struct_def =
VariantData::Tuple(match self.parse_tuple_struct_body(ParsePub::No)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}, ast::DUMMY_NODE_ID);
} else if self.eat(&token::Eq) {
disr_expr =
Some(match self.parse_expr() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
any_disr = disr_expr.as_ref().map(|expr| expr.span);
struct_def = VariantData::Unit(ast::DUMMY_NODE_ID);
} else {
struct_def = VariantData::Unit(ast::DUMMY_NODE_ID);
}
let vr =
ast::Variant_{name: ident,
attrs: variant_attrs,
data: struct_def,
disr_expr: disr_expr,};
variants.push(P(spanned(vlo, self.last_span.hi, vr)));
if !self.eat(&token::Comma) { break ; }
}
match self.expect(&token::CloseDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match any_disr {
Some(disr_span) if !all_nullary =>
self.span_err(disr_span,
"discriminator values can only be used with a c-like enum"),
_ => (),
}
Ok(ast::EnumDef{variants: variants,})
}
/// Parse an "enum" declaration
fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
let id =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut generics =
match self.parse_generics() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
generics.where_clause =
match self.parse_where_clause() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::OpenDelim(token::Brace)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let enum_definition =
match self.parse_enum_def(&generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok((id, ItemEnum(enum_definition, generics), None))
}
/// Parses a string as an ABI spec on an extern type or module. Consumes
/// the `extern` keyword, if one is found.
fn parse_opt_abi(&mut self) -> PResult<'a, Option<abi::Abi>> {
match self.token {
token::Literal(token::Str_(s), suf) |
token::Literal(token::StrRaw(s, _), suf) => {
let sp = self.span;
self.expect_no_suffix(sp, "ABI spec", suf);
self.bump();
match abi::lookup(&s.as_str()) {
Some(abi) => Ok(Some(abi)),
None => {
let last_span = self.last_span;
self.span_err(last_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid ABI: expected one of [",
"], found `",
"`"];
__STATIC_FMTSTR
},
&match (&abi::all_names().join(", "),
&s)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
Ok(None)
}
}
}
_ => Ok(None),
}
}
/// Parse one of the items allowed by the flags.
/// NB: this function no longer parses the items inside an
/// extern crate.
fn parse_item_(&mut self, attrs: Vec<Attribute>,
macros_allowed: bool, attributes_allowed: bool)
-> PResult<'a, Option<P<Item>>> {
let nt_item =
match self.token {
token::Interpolated(token::NtItem(ref item)) => {
Some((**item).clone())
}
_ => None,
};
match nt_item {
Some(mut item) => {
self.bump();
let mut attrs = attrs;
mem::swap(&mut item.attrs, &mut attrs);
item.attrs.extend(attrs);
return Ok(Some(P(item)));
}
None => { }
}
let lo = self.span.lo;
let visibility =
match self.parse_visibility() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat_keyword(keywords::Use) {
let item_ =
ItemUse(match self.parse_view_path() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
match self.expect(&token::Semi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi,
token::special_idents::invalid, item_,
visibility, attrs);
return Ok(Some(item));
}
if self.eat_keyword(keywords::Extern) {
if self.eat_keyword(keywords::Crate) {
return Ok(Some(match self.parse_item_extern_crate(lo,
visibility,
attrs)
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}));
}
let opt_abi =
match self.parse_opt_abi() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.eat_keyword(keywords::Fn) {
let abi = opt_abi.unwrap_or(abi::C);
let (ident, item_, extra_attrs) =
match self.parse_item_fn(Unsafety::Normal,
Constness::NotConst, abi)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
} else if self.check(&token::OpenDelim(token::Brace)) {
return Ok(Some(match self.parse_item_foreign_mod(lo,
opt_abi,
visibility,
attrs)
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}));
}
match self.unexpected() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if self.eat_keyword(keywords::Static) {
let m =
if self.eat_keyword(keywords::Mut) {
MutMutable
} else { MutImmutable };
let (ident, item_, extra_attrs) =
match self.parse_item_const(Some(m)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Const) {
if self.check_keyword(keywords::Fn) ||
(self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1,
|t|
t.is_keyword(keywords::Fn)))
{
let unsafety =
if self.eat_keyword(keywords::Unsafe) {
Unsafety::Unsafe
} else { Unsafety::Normal };
self.bump();
let (ident, item_, extra_attrs) =
match self.parse_item_fn(unsafety,
Constness::Const,
abi::Rust) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Mut) {
let last_span = self.last_span;
self.diagnostic().struct_span_err(last_span,
"const globals cannot be mutable").fileline_help(last_span,
"did you mean to declare a static?").emit();
}
let (ident, item_, extra_attrs) =
match self.parse_item_const(None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Trait)) {
match self.expect_keyword(keywords::Unsafe) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect_keyword(keywords::Trait) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (ident, item_, extra_attrs) =
match self.parse_item_trait(ast::Unsafety::Unsafe) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Impl)) {
match self.expect_keyword(keywords::Unsafe) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect_keyword(keywords::Impl) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (ident, item_, extra_attrs) =
match self.parse_item_impl(ast::Unsafety::Unsafe) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Fn) {
self.bump();
let (ident, item_, extra_attrs) =
match self.parse_item_fn(Unsafety::Normal,
Constness::NotConst,
abi::Rust) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1,
|t|
*t !=
token::OpenDelim(token::Brace))
{
self.bump();
let abi =
if self.eat_keyword(keywords::Extern) {
match self.parse_opt_abi() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.unwrap_or(abi::C)
} else { abi::Rust };
match self.expect_keyword(keywords::Fn) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let (ident, item_, extra_attrs) =
match self.parse_item_fn(Unsafety::Unsafe,
Constness::NotConst, abi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Mod) {
let (ident, item_, extra_attrs) =
match self.parse_item_mod(&attrs[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Type) {
let (ident, item_, extra_attrs) =
match self.parse_item_type() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Enum) {
let (ident, item_, extra_attrs) =
match self.parse_item_enum() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Trait) {
let (ident, item_, extra_attrs) =
match self.parse_item_trait(ast::Unsafety::Normal) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Impl) {
let (ident, item_, extra_attrs) =
match self.parse_item_impl(ast::Unsafety::Normal) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Struct) {
let (ident, item_, extra_attrs) =
match self.parse_item_struct() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
self.parse_macro_use_or_failure(attrs, macros_allowed,
attributes_allowed, lo,
visibility)
}
/// Parse a foreign item.
fn parse_foreign_item(&mut self)
-> PResult<'a, Option<P<ForeignItem>>> {
let attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let lo = self.span.lo;
let visibility =
match self.parse_visibility() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check_keyword(keywords::Static) {
return Ok(Some(match self.parse_item_foreign_static(visibility,
lo,
attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}));
}
if self.check_keyword(keywords::Fn) ||
self.check_keyword(keywords::Unsafe) {
return Ok(Some(match self.parse_item_foreign_fn(visibility,
lo, attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}));
}
match match self.parse_macro_use_or_failure(attrs, true,
false, lo,
visibility) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
} {
Some(item) => {
return Err(self.span_fatal(item.span,
"macros cannot expand to foreign items"));
}
None => Ok(None),
}
}
/// This is the fall-through for parsing items.
fn parse_macro_use_or_failure(&mut self, attrs: Vec<Attribute>,
macros_allowed: bool,
attributes_allowed: bool,
lo: BytePos, visibility: Visibility)
-> PResult<'a, Option<P<Item>>> {
if macros_allowed && !self.token.is_any_keyword() &&
self.look_ahead(1, |t| *t == token::Not) &&
(self.look_ahead(2, |t| t.is_plain_ident()) ||
self.look_ahead(2,
|t|
*t ==
token::OpenDelim(token::Paren))
||
self.look_ahead(2,
|t|
*t ==
token::OpenDelim(token::Brace)))
{
let last_span = self.last_span;
self.complain_if_pub_macro(visibility, last_span);
let mac_lo = self.span.lo;
let pth =
match self.parse_path(NoTypesAllowed) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.expect(&token::Not) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let id =
if self.token.is_plain_ident() {
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
} else { token::special_idents::invalid };
let delim =
match self.expect_open_delim() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let tts =
match self.parse_seq_to_end(&token::CloseDelim(delim),
seq_sep_none(),
|p| p.parse_token_tree())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let m = Mac_{path: pth, tts: tts, ctxt: EMPTY_CTXT,};
let m: ast::Mac =
codemap::Spanned{node: m,
span:
mk_sp(mac_lo,
self.last_span.hi),};
if delim != token::Brace {
if !self.eat(&token::Semi) {
let last_span = self.last_span;
self.span_err(last_span,
"macros that expand to items must either be surrounded with braces or followed by a semicolon");
}
}
let item_ = ItemMac(m);
let last_span = self.last_span;
let item =
self.mk_item(lo, last_span.hi, id, item_, visibility,
attrs);
return Ok(Some(item));
}
match visibility {
Inherited => { }
Public => {
let last_span = self.last_span;
return Err(self.span_fatal(last_span,
"unmatched visibility `pub`"));
}
}
if !attributes_allowed && !attrs.is_empty() {
self.expected_item_err(&attrs);
}
Ok(None)
}
pub fn parse_item(&mut self) -> PResult<'a, Option<P<Item>>> {
let attrs =
match self.parse_outer_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.parse_item_(attrs, true, false)
}
/// Matches view_path : MOD? non_global_path as IDENT
/// | MOD? non_global_path MOD_SEP LBRACE RBRACE
/// | MOD? non_global_path MOD_SEP LBRACE ident_seq RBRACE
/// | MOD? non_global_path MOD_SEP STAR
/// | MOD? non_global_path
fn parse_view_path(&mut self) -> PResult<'a, P<ViewPath>> {
let lo = self.span.lo;
self.eat(&token::ModSep);
if self.check(&token::OpenDelim(token::Brace)) {
let idents =
match self.parse_unspanned_seq(&token::OpenDelim(token::Brace),
&token::CloseDelim(token::Brace),
seq_sep_trailing_allowed(token::Comma),
|p|
p.parse_path_list_item())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let path =
ast::Path{span: mk_sp(lo, self.span.hi),
global: false,
segments: Vec::new(),};
return Ok(P(spanned(lo, self.span.hi,
ViewPathList(path, idents))));
}
let first_ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut path =
<[_]>::into_vec(::std::boxed::Box::new([first_ident]));
if let token::ModSep = self.token {
while self.check(&token::ModSep) {
self.bump();
match self.token {
token::Ident(..) => {
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
path.push(ident);
}
token::OpenDelim(token::Brace) => {
let idents =
match self.parse_unspanned_seq(&token::OpenDelim(token::Brace),
&token::CloseDelim(token::Brace),
seq_sep_trailing_allowed(token::Comma),
|p|
p.parse_path_list_item())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let path =
ast::Path{span: mk_sp(lo, self.span.hi),
global: false,
segments:
path.into_iter().map(|identifier|
{
ast::PathSegment{identifier:
identifier,
parameters:
ast::PathParameters::none(),}
}).collect(),};
return Ok(P(spanned(lo, self.span.hi,
ViewPathList(path,
idents))));
}
token::BinOp(token::Star) => {
self.bump();
let path =
ast::Path{span: mk_sp(lo, self.span.hi),
global: false,
segments:
path.into_iter().map(|identifier|
{
ast::PathSegment{identifier:
identifier,
parameters:
ast::PathParameters::none(),}
}).collect(),};
return Ok(P(spanned(lo, self.span.hi,
ViewPathGlob(path))));
}
token::Semi => {
self.span_err(self.span,
"expected identifier or `{` or `*`, found `;`");
}
_ => break ,
}
}
}
let mut rename_to = path[path.len() - 1];
let path =
ast::Path{span: mk_sp(lo, self.last_span.hi),
global: false,
segments:
path.into_iter().map(|identifier| {
ast::PathSegment{identifier:
identifier,
parameters:
ast::PathParameters::none(),}
}).collect(),};
rename_to =
match self.parse_rename() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.unwrap_or(rename_to);
Ok(P(spanned(lo, self.last_span.hi,
ViewPathSimple(rename_to, path))))
}
fn parse_rename(&mut self) -> PResult<'a, Option<Ident>> {
if self.eat_keyword(keywords::As) {
self.parse_ident().map(Some)
} else { Ok(None) }
}
/// Parses a source module as a crate. This is the main
/// entry point for the parser.
pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate> {
let lo = self.span.lo;
Ok(ast::Crate{attrs:
match self.parse_inner_attributes() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
module:
match self.parse_mod_items(&token::Eof, lo)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
config: self.cfg.clone(),
span: mk_sp(lo, self.span.lo),
exported_macros: Vec::new(),})
}
pub fn parse_optional_str(&mut self)
-> Option<(InternedString, ast::StrStyle, Option<ast::Name>)> {
let ret =
match self.token {
token::Literal(token::Str_(s), suf) => {
(self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)),
ast::CookedStr, suf)
}
token::Literal(token::StrRaw(s, n), suf) => {
(self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)),
ast::RawStr(n), suf)
}
_ => return None,
};
self.bump();
Some(ret)
}
pub fn parse_str(&mut self)
-> PResult<'a, (InternedString, StrStyle)> {
match self.parse_optional_str() {
Some((s, style, suf)) => {
let sp = self.last_span;
self.expect_no_suffix(sp, "string literal", suf);
Ok((s, style))
}
_ => Err(self.fatal("expected string literal")),
}
}
}
}
pub mod lexer {
#[prelude_import]
use std::prelude::v1::*;
use ast;
use codemap::{BytePos, CharPos, CodeMap, Pos, Span};
use codemap;
use errors::{FatalError, Handler, DiagnosticBuilder};
use ext::tt::transcribe::tt_next_token;
use parse::token::str_to_ident;
use parse::token;
use str::char_at;
use std::borrow::Cow;
use std::char;
use std::mem::replace;
use std::rc::Rc;
use unicode_xid::UnicodeXID;
pub use ext::tt::transcribe::{TtReader, new_tt_reader,
new_tt_reader_with_doc_flag};
pub mod comments {
#[prelude_import]
use std::prelude::v1::*;
pub use self::CommentStyle::*;
use ast;
use codemap::{BytePos, CharPos, CodeMap, Pos};
use errors;
use parse::lexer::is_block_doc_comment;
use parse::lexer::{StringReader, TokenAndSpan};
use parse::lexer::{is_whitespace, Reader};
use parse::lexer;
use print::pprust;
use str::char_at;
use std::io::Read;
use std::usize;
pub enum CommentStyle {
/// No code on either side of each line of the comment
Isolated,
/// Code exists to the left of the comment
Trailing,
/// Code before /* foo */ and after the comment
Mixed,
/// Just a manual blank line "\n\n", for layout
BlankLine,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for CommentStyle {
#[inline]
fn eq(&self, __arg_0: &CommentStyle) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&CommentStyle::Isolated,
&CommentStyle::Isolated) => true,
(&CommentStyle::Trailing,
&CommentStyle::Trailing) => true,
(&CommentStyle::Mixed, &CommentStyle::Mixed)
=> true,
(&CommentStyle::BlankLine,
&CommentStyle::BlankLine) => true,
_ => unsafe {
::std::intrinsics::unreachable()
}
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &CommentStyle) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&CommentStyle::Isolated,
&CommentStyle::Isolated) => false,
(&CommentStyle::Trailing,
&CommentStyle::Trailing) => false,
(&CommentStyle::Mixed, &CommentStyle::Mixed)
=> false,
(&CommentStyle::BlankLine,
&CommentStyle::BlankLine) => false,
_ => unsafe {
::std::intrinsics::unreachable()
}
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for CommentStyle { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for CommentStyle {
#[inline]
fn clone(&self) -> CommentStyle {
match (&*self,) {
(&CommentStyle::Isolated,) => CommentStyle::Isolated,
(&CommentStyle::Trailing,) => CommentStyle::Trailing,
(&CommentStyle::Mixed,) => CommentStyle::Mixed,
(&CommentStyle::BlankLine,) =>
CommentStyle::BlankLine,
}
}
}
pub struct Comment {
pub style: CommentStyle,
pub lines: Vec<String>,
pub pos: BytePos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Comment {
#[inline]
fn clone(&self) -> Comment {
match *self {
Comment {
style: ref __self_0_0,
lines: ref __self_0_1,
pos: ref __self_0_2 } =>
Comment{style:
::std::clone::Clone::clone(&(*__self_0_0)),
lines:
::std::clone::Clone::clone(&(*__self_0_1)),
pos:
::std::clone::Clone::clone(&(*__self_0_2)),},
}
}
}
pub fn is_doc_comment(s: &str) -> bool {
(s.starts_with("///") && super::is_doc_comment(s)) ||
s.starts_with("//!") ||
(s.starts_with("/**") && is_block_doc_comment(s)) ||
s.starts_with("/*!")
}
pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
if !is_doc_comment(comment) {
{
::std::rt::begin_unwind("assertion failed: is_doc_comment(comment)",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/comments.rs",
53u32);
&_FILE_LINE
})
}
};
if comment.starts_with("//!") || comment.starts_with("/*!") {
ast::AttrStyle::Inner
} else { ast::AttrStyle::Outer }
}
pub fn strip_doc_comment_decoration(comment: &str) -> String {
/// remove whitespace-only lines from the start/end of lines
fn vertical_trim(lines: Vec<String>) -> Vec<String> {
let mut i = 0;
let mut j = lines.len();
if !lines.is_empty() && lines[0].chars().all(|c| c == '*')
{
i += 1;
}
while i < j && lines[i].trim().is_empty() { i += 1; }
if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*')
{
j -= 1;
}
while j > i && lines[j - 1].trim().is_empty() { j -= 1; }
lines[i..j].iter().cloned().collect()
}
/// remove a "[ \t]*\*" block from each line, if possible
fn horizontal_trim(lines: Vec<String>) -> Vec<String> {
let mut i = usize::MAX;
let mut can_trim = true;
let mut first = true;
for line in &lines {
for (j, c) in line.chars().enumerate() {
if j > i || !"* \t".contains(c) {
can_trim = false;
break ;
}
if c == '*' {
if first {
i = j;
first = false;
} else if i != j { can_trim = false; }
break ;
}
}
if i > line.len() { can_trim = false; }
if !can_trim { break ; }
}
if can_trim {
lines.iter().map(|line| {
(&line[i +
1..line.len()]).to_string()
}).collect()
} else { lines }
}
const ONELINERS: &'static [&'static str] =
&["///!", "///", "//!", "//"];
for prefix in ONELINERS {
if comment.starts_with(*prefix) {
return (&comment[prefix.len()..]).to_string();
}
}
if comment.starts_with("/*") {
let lines =
comment[3..comment.len() -
2].lines().map(|s|
s.to_string()).collect::<Vec<String>>();
let lines = vertical_trim(lines);
let lines = horizontal_trim(lines);
return lines.join("\n");
}
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["not a doc-comment: "];
__STATIC_FMTSTR
},
&match (&comment,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/comments.rs",
145u32);
&_FILE_LINE
})
};
}
fn push_blank_line_comment(rdr: &StringReader,
comments: &mut Vec<Comment>) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 149u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[">>> blank-line comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
comments.push(Comment{style: BlankLine,
lines: Vec::new(),
pos: rdr.last_pos,});
}
fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader,
comments:
&mut Vec<Comment>) {
while is_whitespace(rdr.curr) && !rdr.is_eof() {
if rdr.col == CharPos(0) && rdr.curr_is('\n') {
push_blank_line_comment(rdr, &mut *comments);
}
rdr.bump();
}
}
fn read_shebang_comment(rdr: &mut StringReader,
code_to_the_left: bool,
comments: &mut Vec<Comment>) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 170u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[">>> shebang comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
let p = rdr.last_pos;
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 172u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["<<< shebang comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
comments.push(Comment{style:
if code_to_the_left {
Trailing
} else { Isolated },
lines:
<[_]>::into_vec(::std::boxed::Box::new([rdr.read_one_line_comment()])),
pos: p,});
}
fn read_line_comments(rdr: &mut StringReader,
code_to_the_left: bool,
comments: &mut Vec<Comment>) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 182u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[">>> line comments"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
let p = rdr.last_pos;
let mut lines: Vec<String> = Vec::new();
while rdr.curr_is('/') && rdr.nextch_is('/') {
let line = rdr.read_one_line_comment();
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 187u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&line,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
if is_doc_comment(&line[..]) { break ; }
lines.push(line);
rdr.consume_non_eol_whitespace();
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 195u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["<<< line comments"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
if !lines.is_empty() {
comments.push(Comment{style:
if code_to_the_left {
Trailing
} else { Isolated },
lines: lines,
pos: p,});
}
}
/// Returns None if the first col chars of s contain a non-whitespace char.
/// Otherwise returns Some(k) where k is first char offset after that leading
/// whitespace. Note k may be outside bounds of s.
fn all_whitespace(s: &str, col: CharPos) -> Option<usize> {
let len = s.len();
let mut col = col.to_usize();
let mut cursor: usize = 0;
while col > 0 && cursor < len {
let ch = char_at(s, cursor);
if !ch.is_whitespace() { return None; }
cursor += ch.len_utf8();
col -= 1;
}
return Some(cursor);
}
fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String>,
s: String, col: CharPos) {
let len = s.len();
let s1 =
match all_whitespace(&s[..], col) {
Some(col) => {
if col < len {
(&s[col..len]).to_string()
} else { "".to_string() }
}
None => s,
};
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 236u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pushing line: "];
__STATIC_FMTSTR
},
&match (&s1,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
lines.push(s1);
}
fn read_block_comment(rdr: &mut StringReader,
code_to_the_left: bool,
comments: &mut Vec<Comment>) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 243u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[">>> block comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
let p = rdr.last_pos;
let mut lines: Vec<String> = Vec::new();
let col = rdr.col;
rdr.bump();
rdr.bump();
let mut curr_line = String::from("/*");
if (rdr.curr_is('*') && !rdr.nextch_is('*')) ||
rdr.curr_is('!') {
while !(rdr.curr_is('*') && rdr.nextch_is('/')) &&
!rdr.is_eof() {
curr_line.push(rdr.curr.unwrap());
rdr.bump();
}
if !rdr.is_eof() {
curr_line.push_str("*/");
rdr.bump();
rdr.bump();
}
if is_block_doc_comment(&curr_line[..]) { return }
if !!curr_line.contains('\n') {
{
::std::rt::begin_unwind("assertion failed: !curr_line.contains(\'\\n\')",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/comments.rs",
266u32);
&_FILE_LINE
})
}
};
lines.push(curr_line);
} else {
let mut level: isize = 1;
while level > 0 {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 271u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["=== block comment level "];
__STATIC_FMTSTR
},
&match (&level,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
if rdr.is_eof() {
{
::std::rt::begin_unwind(rdr.fatal("unterminated block comment"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/comments.rs",
273u32);
&_FILE_LINE
})
};
}
if rdr.curr_is('\n') {
trim_whitespace_prefix_and_push_line(&mut lines,
curr_line,
col);
curr_line = String::new();
rdr.bump();
} else {
curr_line.push(rdr.curr.unwrap());
if rdr.curr_is('/') && rdr.nextch_is('*') {
rdr.bump();
rdr.bump();
curr_line.push('*');
level += 1;
} else {
if rdr.curr_is('*') && rdr.nextch_is('/') {
rdr.bump();
rdr.bump();
curr_line.push('/');
level -= 1;
} else { rdr.bump(); }
}
}
}
if !curr_line.is_empty() {
trim_whitespace_prefix_and_push_line(&mut lines,
curr_line, col);
}
}
let mut style =
if code_to_the_left { Trailing } else { Isolated };
rdr.consume_non_eol_whitespace();
if !rdr.is_eof() && !rdr.curr_is('\n') && lines.len() == 1 {
style = Mixed;
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 310u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["<<< block comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
comments.push(Comment{style: style, lines: lines, pos: p,});
}
fn consume_comment(rdr: &mut StringReader, code_to_the_left: bool,
comments: &mut Vec<Comment>) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 318u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[">>> consume comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
if rdr.curr_is('/') && rdr.nextch_is('/') {
read_line_comments(rdr, code_to_the_left, comments);
} else if rdr.curr_is('/') && rdr.nextch_is('*') {
read_block_comment(rdr, code_to_the_left, comments);
} else if rdr.curr_is('#') && rdr.nextch_is('!') {
read_shebang_comment(rdr, code_to_the_left, comments);
} else {
{
{
::std::rt::begin_unwind("explicit panic",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/comments.rs",
325u32);
&_FILE_LINE
})
}
};
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 326u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["<<< consume comment"];
__STATIC_FMTSTR
},
&match () {
() =>
[],
}))
}
};
}
pub struct Literal {
pub lit: String,
pub pos: BytePos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Literal {
#[inline]
fn clone(&self) -> Literal {
match *self {
Literal { lit: ref __self_0_0, pos: ref __self_0_1 }
=>
Literal{lit:
::std::clone::Clone::clone(&(*__self_0_0)),
pos:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub fn gather_comments_and_literals(span_diagnostic:
&errors::Handler,
path: String, srdr: &mut Read)
-> (Vec<Comment>, Vec<Literal>) {
let mut src = Vec::new();
srdr.read_to_end(&mut src).unwrap();
let src = String::from_utf8(src).unwrap();
let cm = CodeMap::new();
let filemap = cm.new_filemap(path, src);
let mut rdr =
lexer::StringReader::new_raw(span_diagnostic, filemap);
let mut comments: Vec<Comment> = Vec::new();
let mut literals: Vec<Literal> = Vec::new();
let mut first_read: bool = true;
while !rdr.is_eof() {
loop {
let mut code_to_the_left = !first_read;
rdr.consume_non_eol_whitespace();
if rdr.curr_is('\n') {
code_to_the_left = false;
consume_whitespace_counting_blank_lines(&mut rdr,
&mut comments);
}
while rdr.peeking_at_comment() {
consume_comment(&mut rdr, code_to_the_left,
&mut comments);
consume_whitespace_counting_blank_lines(&mut rdr,
&mut comments);
}
break ;
}
let bstart = rdr.last_pos;
rdr.next_token();
let TokenAndSpan { tok, sp } = rdr.peek();
if tok.is_lit() {
rdr.with_str_from(bstart, |s| {
{
static _LOC: ::log::LogLocation
=
::log::LogLocation{__line:
373u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl =
::log::LogLevel::Debug;
if lvl <=
::log::__static_max_level()
&&
lvl <=
::log::max_log_level()
{
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["tok lit: "];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
literals.push(Literal{lit:
s.to_string(),
pos: sp.lo,});
})
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 377u32,
__file:
"src/parse/lexer/comments.rs",
__module_path:
"syntex_syntax::parse::lexer::comments",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer::comments",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["tok: "];
__STATIC_FMTSTR
},
&match (&pprust::token_to_string(&tok),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
}
first_read = false;
}
(comments, literals)
}
}
mod unicode_chars {
#[prelude_import]
use std::prelude::v1::*;
use codemap::mk_sp as make_span;
use errors::DiagnosticBuilder;
use super::StringReader;
const UNICODE_ARRAY: &'static [(char, &'static str, char)] =
&[('\u{7fa}', "Nko Lajanyalan", '_'),
('\u{fe4d}', "Dashed Low Line", '_'),
('\u{fe4e}', "Centreline Low Line", '_'),
('\u{fe4f}', "Wavy Low Line", '_'),
('\u{2010}', "Hyphen", '-'),
('\u{2011}', "Non-Breaking Hyphen", '-'),
('\u{2012}', "Figure Dash", '-'),
('\u{2013}', "En Dash", '-'),
('\u{fe58}', "Small Em Dash", '-'),
('\u{2043}', "Hyphen Bullet", '-'),
('\u{2d7}', "Modifier Letter Minus Sign", '-'),
('\u{2212}', "Minus Sign", '-'),
('\u{66b}', "Arabic Decimal Separator", ','),
('\u{201a}', "Single Low-9 Quotation Mark", ','),
('\u{a4f9}', "Lisu Letter Tone Na Po", ','),
('\u{37e}', "Greek Question Mark", ';'),
('\u{903}', "Devanagari Sign Visarga", ':'),
('\u{a83}', "Gujarati Sign Visarga", ':'),
('\u{ff1a}', "Fullwidth Colon", ':'),
('\u{589}', "Armenian Full Stop", ':'),
('\u{703}', "Syriac Supralinear Colon", ':'),
('\u{704}', "Syriac Sublinear Colon", ':'),
('\u{fe30}',
"Presentation Form For Vertical Two Dot Leader", ':'),
('\u{1803}', "Mongolian Full Stop", ':'),
('\u{1809}', "Mongolian Manchu Full Stop", ':'),
('\u{205a}', "Two Dot Punctuation", ':'),
('\u{5c3}', "Hebrew Punctuation Sof Pasuq", ':'),
('\u{2f8}', "Modifier Letter Raised Colon", ':'),
('\u{a789}', "Modifier Letter Colon", ':'),
('\u{2236}', "Ratio", ':'),
('\u{2d0}', "Modifier Letter Triangular Colon", ':'),
('\u{a4fd}', "Lisu Letter Tone Mya Jeu", ':'),
('\u{ff01}', "Fullwidth Exclamation Mark", '!'),
('\u{1c3}', "Latin Letter Retroflex Click", '!'),
('\u{294}', "Latin Letter Glottal Stop", '?'),
('\u{97d}', "Devanagari Letter Glottal Stop", '?'),
('\u{13ae}', "Cherokee Letter He", '?'),
('\u{1d16d}', "Musical Symbol Combining Augmentation Dot",
'.'), ('\u{2024}', "One Dot Leader", '.'),
('\u{6d4}', "Arabic Full Stop", '.'),
('\u{701}', "Syriac Supralinear Full Stop", '.'),
('\u{702}', "Syriac Sublinear Full Stop", '.'),
('\u{a60e}', "Vai Full Stop", '.'),
('\u{10a50}', "Kharoshthi Punctuation Dot", '.'),
('\u{660}', "Arabic-Indic Digit Zero", '.'),
('\u{6f0}', "Extended Arabic-Indic Digit Zero", '.'),
('\u{a4f8}', "Lisu Letter Tone Mya Ti", '.'),
('\u{55d}', "Armenian Comma", '\''),
('\u{ff07}', "Fullwidth Apostrophe", '\''),
('\u{2018}', "Left Single Quotation Mark", '\''),
('\u{2019}', "Right Single Quotation Mark", '\''),
('\u{201b}', "Single High-Reversed-9 Quotation Mark", '\''),
('\u{2032}', "Prime", '\''),
('\u{2035}', "Reversed Prime", '\''),
('\u{55a}', "Armenian Apostrophe", '\''),
('\u{5f3}', "Hebrew Punctuation Geresh", '\''),
('\u{1fef}', "Greek Varia", '\''),
('\u{ff40}', "Fullwidth Grave Accent", '\''),
('\u{384}', "Greek Tonos", '\''),
('\u{1ffd}', "Greek Oxia", '\''),
('\u{1fbd}', "Greek Koronis", '\''),
('\u{1fbf}', "Greek Psili", '\''),
('\u{1ffe}', "Greek Dasia", '\''),
('\u{2b9}', "Modifier Letter Prime", '\''),
('\u{374}', "Greek Numeral Sign", '\''),
('\u{2ca}', "Modifier Letter Acute Accent", '\''),
('\u{2cb}', "Modifier Letter Grave Accent", '\''),
('\u{2f4}', "Modifier Letter Middle Grave Accent", '\''),
('\u{2bb}', "Modifier Letter Turned Comma", '\''),
('\u{2bd}', "Modifier Letter Reversed Comma", '\''),
('\u{2bc}', "Modifier Letter Apostrophe", '\''),
('\u{2be}', "Modifier Letter Right Half Ring", '\''),
('\u{a78c}', "Latin Small Letter Saltillo", '\''),
('\u{5d9}', "Hebrew Letter Yod", '\''),
('\u{7f4}', "Nko High Tone Apostrophe", '\''),
('\u{7f5}', "Nko Low Tone Apostrophe", '\''),
('\u{ff02}', "Fullwidth Quotation Mark", '\"'),
('\u{201c}', "Left Double Quotation Mark", '\"'),
('\u{201d}', "Right Double Quotation Mark", '\"'),
('\u{201f}', "Double High-Reversed-9 Quotation Mark", '\"'),
('\u{2033}', "Double Prime", '\"'),
('\u{2036}', "Reversed Double Prime", '\"'),
('\u{3003}', "Ditto Mark", '\"'),
('\u{5f4}', "Hebrew Punctuation Gershayim", '\"'),
('\u{2dd}', "Double Acute Accent", '\"'),
('\u{2ba}', "Modifier Letter Double Prime", '\"'),
('\u{2f6}', "Modifier Letter Middle Double Acute Accent",
'\"'),
('\u{2f5}', "Modifier Letter Middle Double Grave Accent",
'\"'),
('\u{2ee}', "Modifier Letter Double Apostrophe", '\"'),
('\u{5f2}', "Hebrew Ligature Yiddish Double Yod", '\"'),
('\u{275e}', "Heavy Double Comma Quotation Mark Ornament",
'\"'),
('\u{275d}',
"Heavy Double Turned Comma Quotation Mark Ornament", '\"'),
('\u{ff3b}', "Fullwidth Left Square Bracket", '('),
('\u{2768}', "Medium Left Parenthesis Ornament", '('),
('\u{2772}', "Light Left Tortoise Shell Bracket Ornament",
'('), ('\u{3014}', "Left Tortoise Shell Bracket", '('),
('\u{fd3e}', "Ornate Left Parenthesis", '('),
('\u{ff3d}', "Fullwidth Right Square Bracket", ')'),
('\u{2769}', "Medium Right Parenthesis Ornament", ')'),
('\u{2773}', "Light Right Tortoise Shell Bracket Ornament",
')'), ('\u{3015}', "Right Tortoise Shell Bracket", ')'),
('\u{fd3f}', "Ornate Right Parenthesis", ')'),
('\u{2774}', "Medium Left Curly Bracket Ornament", '{'),
('\u{2775}', "Medium Right Curly Bracket Ornament", '}'),
('\u{204e}', "Low Asterisk", '*'),
('\u{66d}', "Arabic Five Pointed Star", '*'),
('\u{2217}', "Asterisk Operator", '*'),
('\u{1735}', "Philippine Single Punctuation", '/'),
('\u{2041}', "Caret Insertion Point", '/'),
('\u{2215}', "Division Slash", '/'),
('\u{2044}', "Fraction Slash", '/'),
('\u{2571}',
"Box Drawings Light Diagonal Upper Right To Lower Left",
'/'), ('\u{27cb}', "Mathematical Rising Diagonal", '/'),
('\u{29f8}', "Big Solidus", '/'),
('\u{31d3}', "Cjk Stroke Sp", '/'),
('\u{3033}', "Vertical Kana Repeat Mark Upper Half", '/'),
('\u{4e3f}', "Cjk Unified Ideograph-4E3F", '/'),
('\u{2f03}', "Kangxi Radical Slash", '/'),
('\u{ff3c}', "Fullwidth Reverse Solidus", '\\'),
('\u{fe68}', "Small Reverse Solidus", '\\'),
('\u{2216}', "Set Minus", '\\'),
('\u{27cd}', "Mathematical Falling Diagonal", '\\'),
('\u{29f5}', "Reverse Solidus Operator", '\\'),
('\u{29f9}', "Big Reverse Solidus", '\\'),
('\u{31d4}', "Cjk Stroke D", '\\'),
('\u{4e36}', "Cjk Unified Ideograph-4E36", '\\'),
('\u{2f02}', "Kangxi Radical Dot", '\\'),
('\u{a778}', "Latin Small Letter Um", '&'),
('\u{fb29}', "Hebrew Letter Alternative Plus Sign", '+'),
('\u{2039}', "Single Left-Pointing Angle Quotation Mark",
'<'),
('\u{276e}',
"Heavy Left-Pointing Angle Quotation Mark Ornament", '<'),
('\u{2c2}', "Modifier Letter Left Arrowhead", '<'),
('\u{a4ff}', "Lisu Punctuation Full Stop", '='),
('\u{203a}', "Single Right-Pointing Angle Quotation Mark",
'>'),
('\u{276f}',
"Heavy Right-Pointing Angle Quotation Mark Ornament", '>'),
('\u{2c3}', "Modifier Letter Right Arrowhead", '>'),
('\u{2cba}', "Coptic Capital Letter Dialect-P Ni", '-'),
('\u{241}', "Latin Capital Letter Glottal Stop", '?'),
('\u{2cc6}', "Coptic Capital Letter Old Coptic Esh", '/')];
const ASCII_ARRAY: &'static [(char, &'static str)] =
&[('_', "Underscore"), ('-', "Minus/Hyphen"), (',', "Comma"),
(';', "Semicolon"), (':', "Colon"),
('!', "Exclamation Mark"), ('?', "Question Mark"),
('.', "Period"), ('\'', "Single Quote"),
('\"', "Quotation Mark"), ('(', "Left Parenthesis"),
(')', "Right Parenthesis"), ('{', "Left Curly Brace"),
('}', "Right Curly Brace"), ('*', "Asterisk"),
('/', "Slash"), ('\\', "Backslash"), ('&', "Ampersand"),
('+', "Plus Sign"), ('<', "Less-Than Sign"),
('=', "Equals Sign"), ('>', "Greater-Than Sign")];
pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
ch: char,
err:
&mut DiagnosticBuilder<'a>) {
UNICODE_ARRAY.iter().find(|&&(c, _, _)|
c ==
ch).map(|&(_, u_name,
ascii_char)| {
let span =
make_span(reader.last_pos,
reader.pos);
match ASCII_ARRAY.iter().find(|&&(c,
_)|
c
==
ascii_char)
{
Some(&(ascii_char,
ascii_name))
=> {
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["unicode character \'",
"\' (",
") looks much like \'",
"\' (",
"), but it\'s not"];
__STATIC_FMTSTR
},
&match (&ch,
&u_name,
&ascii_char,
&ascii_name)
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt)],
}));
err.span_help(span,
&msg);
}
None => {
reader.span_diagnostic.span_bug_no_panic(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["substitution character not found for \'",
"\'"];
__STATIC_FMTSTR
},
&match (&ch,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
} });
}
}
pub trait Reader {
fn is_eof(&self)
-> bool;
fn next_token(&mut self)
-> TokenAndSpan;
/// Report a fatal error with the current span.
fn fatal(&self, &str)
-> FatalError;
/// Report a non-fatal error with the current span.
fn err(&self, &str);
fn peek(&self)
-> TokenAndSpan;
/// Get a token the parser cares about.
fn real_token(&mut self) -> TokenAndSpan {
let mut t = self.next_token();
loop {
match t.tok {
token::Whitespace | token::Comment | token::Shebang(_)
=> {
t = self.next_token();
}
_ => break ,
}
}
t
}
}
pub struct TokenAndSpan {
pub tok: token::Token,
pub sp: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for TokenAndSpan {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match *self {
TokenAndSpan { tok: ref __self_0_0, sp: ref __self_0_1 }
=> {
let mut builder =
__arg_0.debug_struct("TokenAndSpan");
let _ = builder.field("tok", &&(*__self_0_0));
let _ = builder.field("sp", &&(*__self_0_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for TokenAndSpan {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
TokenAndSpan { tok: ref __self_0_0, sp: ref __self_0_1 }
=> {
(*__self_0_0).assert_receiver_is_total_eq();
(*__self_0_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for TokenAndSpan {
#[inline]
fn eq(&self, __arg_0: &TokenAndSpan) -> bool {
match *__arg_0 {
TokenAndSpan { tok: ref __self_1_0, sp: ref __self_1_1 }
=>
match *self {
TokenAndSpan { tok: ref __self_0_0, sp: ref __self_0_1
} =>
true && (*__self_0_0) == (*__self_1_0) &&
(*__self_0_1) == (*__self_1_1),
},
}
}
#[inline]
fn ne(&self, __arg_0: &TokenAndSpan) -> bool {
match *__arg_0 {
TokenAndSpan { tok: ref __self_1_0, sp: ref __self_1_1 }
=>
match *self {
TokenAndSpan { tok: ref __self_0_0, sp: ref __self_0_1
} =>
false || (*__self_0_0) != (*__self_1_0) ||
(*__self_0_1) != (*__self_1_1),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TokenAndSpan {
#[inline]
fn clone(&self) -> TokenAndSpan {
match *self {
TokenAndSpan { tok: ref __self_0_0, sp: ref __self_0_1 }
=>
TokenAndSpan{tok:
::std::clone::Clone::clone(&(*__self_0_0)),
sp:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct StringReader<'a> {
pub span_diagnostic: &'a Handler,
/// The absolute offset within the codemap of the next character to read
pub pos: BytePos,
/// The absolute offset within the codemap of the last character read(curr)
pub last_pos: BytePos,
/// The column of the next character to read
pub col: CharPos,
/// The last character to be read
pub curr: Option<char>,
pub filemap: Rc<codemap::FileMap>,
pub peek_tok: token::Token,
pub peek_span: Span,
source_text: Rc<String>,
}
impl <'a> Reader for StringReader<'a> {
fn is_eof(&self) -> bool { self.curr.is_none() }
/// Return the next token. EFFECT: advances the string_reader.
fn next_token(&mut self) -> TokenAndSpan {
let ret_val =
TokenAndSpan{tok:
replace(&mut self.peek_tok,
token::Underscore),
sp: self.peek_span,};
self.advance_token();
ret_val
}
fn fatal(&self, m: &str) -> FatalError {
self.fatal_span(self.peek_span, m)
}
fn err(&self, m: &str) { self.err_span(self.peek_span, m) }
fn peek(&self) -> TokenAndSpan {
TokenAndSpan{tok: self.peek_tok.clone(), sp: self.peek_span,}
}
}
impl <'a> Reader for TtReader<'a> {
fn is_eof(&self) -> bool { self.cur_tok == token::Eof }
fn next_token(&mut self) -> TokenAndSpan {
let r = tt_next_token(self);
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 113u32,
__file: "src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["TtReader: r="];
__STATIC_FMTSTR
},
&match (&r,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
r
}
fn fatal(&self, m: &str) -> FatalError {
self.sp_diag.span_fatal(self.cur_span, m)
}
fn err(&self, m: &str) {
self.sp_diag.span_err(self.cur_span, m);
}
fn peek(&self) -> TokenAndSpan {
TokenAndSpan{tok: self.cur_tok.clone(), sp: self.cur_span,}
}
}
impl <'a> StringReader<'a> {
/// For comments.rs, which hackily pokes into pos and curr
pub fn new_raw<'b>(span_diagnostic: &'b Handler,
filemap: Rc<codemap::FileMap>)
-> StringReader<'b> {
if filemap.src.is_none() {
span_diagnostic.bug(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["Cannot lex filemap without source: "];
__STATIC_FMTSTR
},
&match (&filemap.name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))[..]);
}
let source_text = (*filemap.src.as_ref().unwrap()).clone();
let mut sr =
StringReader{span_diagnostic: span_diagnostic,
pos: filemap.start_pos,
last_pos: filemap.start_pos,
col: CharPos(0),
curr: Some('\n'),
filemap: filemap,
peek_tok: token::Eof,
peek_span: codemap::DUMMY_SP,
source_text: source_text,};
sr.bump();
sr
}
pub fn new<'b>(span_diagnostic: &'b Handler,
filemap: Rc<codemap::FileMap>)
-> StringReader<'b> {
let mut sr = StringReader::new_raw(span_diagnostic, filemap);
sr.advance_token();
sr
}
pub fn curr_is(&self, c: char) -> bool { self.curr == Some(c) }
/// Report a fatal lexical error with a given span.
pub fn fatal_span(&self, sp: Span, m: &str) -> FatalError {
self.span_diagnostic.span_fatal(sp, m)
}
/// Report a lexical error with a given span.
pub fn err_span(&self, sp: Span, m: &str) {
self.span_diagnostic.span_err(sp, m)
}
/// Report a fatal error spanning [`from_pos`, `to_pos`).
fn fatal_span_(&self, from_pos: BytePos, to_pos: BytePos, m: &str)
-> FatalError {
self.fatal_span(codemap::mk_sp(from_pos, to_pos), m)
}
/// Report a lexical error spanning [`from_pos`, `to_pos`).
fn err_span_(&self, from_pos: BytePos, to_pos: BytePos, m: &str) {
self.err_span(codemap::mk_sp(from_pos, to_pos), m)
}
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
/// escaped character to the error message
fn fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos,
m: &str, c: char) -> FatalError {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() { m.push(c) }
self.fatal_span_(from_pos, to_pos, &m[..])
}
fn struct_fatal_span_char(&self, from_pos: BytePos,
to_pos: BytePos, m: &str, c: char)
-> DiagnosticBuilder<'a> {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() { m.push(c) }
self.span_diagnostic.struct_span_fatal(codemap::mk_sp(from_pos,
to_pos),
&m[..])
}
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
/// escaped character to the error message
fn err_span_char(&self, from_pos: BytePos, to_pos: BytePos,
m: &str, c: char) {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() { m.push(c) }
self.err_span_(from_pos, to_pos, &m[..]);
}
fn struct_err_span_char(&self, from_pos: BytePos, to_pos: BytePos,
m: &str, c: char)
-> DiagnosticBuilder<'a> {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() { m.push(c) }
self.span_diagnostic.struct_span_err(codemap::mk_sp(from_pos,
to_pos),
&m[..])
}
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending the
/// offending string to the error message
fn fatal_span_verbose(&self, from_pos: BytePos, to_pos: BytePos,
mut m: String) -> FatalError {
m.push_str(": ");
let from = self.byte_offset(from_pos).to_usize();
let to = self.byte_offset(to_pos).to_usize();
m.push_str(&self.source_text[from..to]);
self.fatal_span_(from_pos, to_pos, &m[..])
}
/// Advance peek_tok and peek_span to refer to the next token, and
/// possibly update the interner.
fn advance_token(&mut self) {
match self.scan_whitespace_or_comment() {
Some(comment) => {
self.peek_span = comment.sp;
self.peek_tok = comment.tok;
}
None => {
if self.is_eof() {
self.peek_tok = token::Eof;
self.peek_span =
codemap::mk_sp(self.filemap.end_pos,
self.filemap.end_pos);
} else {
let start_bytepos = self.last_pos;
self.peek_tok = self.next_token_inner();
self.peek_span =
codemap::mk_sp(start_bytepos, self.last_pos);
};
}
}
}
fn byte_offset(&self, pos: BytePos) -> BytePos {
(pos - self.filemap.start_pos)
}
/// Calls `f` with a string slice of the source text spanning from `start`
/// up to but excluding `self.last_pos`, meaning the slice does not include
/// the character `self.curr`.
pub fn with_str_from<T, F>(&self, start: BytePos, f: F) -> T where
F: FnOnce(&str) -> T {
self.with_str_from_to(start, self.last_pos, f)
}
/// Create a Name from a given offset to the current offset, each
/// adjusted 1 towards each other (assumes that on either side there is a
/// single-byte delimiter).
pub fn name_from(&self, start: BytePos) -> ast::Name {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 278u32,
__file: "src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["taking an ident from ",
" to "];
__STATIC_FMTSTR
},
&match (&start,
&self.last_pos)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
self.with_str_from(start, token::intern)
}
/// As name_from, with an explicit endpoint.
pub fn name_from_to(&self, start: BytePos, end: BytePos)
-> ast::Name {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 284u32,
__file: "src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["taking an ident from ",
" to "];
__STATIC_FMTSTR
},
&match (&start,
&end)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
self.with_str_from_to(start, end, token::intern)
}
/// Calls `f` with a string slice of the source text spanning from `start`
/// up to but excluding `end`.
fn with_str_from_to<T,
F>(&self, start: BytePos, end: BytePos, f: F)
-> T where F: FnOnce(&str) -> T {
f(&self.source_text[self.byte_offset(start).to_usize()..self.byte_offset(end).to_usize()])
}
/// Converts CRLF to LF in the given string, raising an error on bare CR.
fn translate_crlf<'b>(&self, start: BytePos, s: &'b str,
errmsg: &'b str) -> Cow<'b, str> {
let mut i = 0;
while i < s.len() {
let ch = char_at(s, i);
let next = i + ch.len_utf8();
if ch == '\r' {
if next < s.len() && char_at(s, next) == '\n' {
return translate_crlf_(self, start, s, errmsg,
i).into();
}
let pos = start + BytePos(i as u32);
let end_pos = start + BytePos(next as u32);
self.err_span_(pos, end_pos, errmsg);
}
i = next;
}
return s.into();
fn translate_crlf_(rdr: &StringReader, start: BytePos,
s: &str, errmsg: &str, mut i: usize)
-> String {
let mut buf = String::with_capacity(s.len());
let mut j = 0;
while i < s.len() {
let ch = char_at(s, i);
let next = i + ch.len_utf8();
if ch == '\r' {
if j < i { buf.push_str(&s[j..i]); }
j = next;
if next >= s.len() || char_at(s, next) != '\n' {
let pos = start + BytePos(i as u32);
let end_pos = start + BytePos(next as u32);
rdr.err_span_(pos, end_pos, errmsg);
}
}
i = next;
}
if j < s.len() { buf.push_str(&s[j..]); }
buf
}
}
/// Advance the StringReader by one character. If a newline is
/// discovered, add it to the FileMap's list of line start offsets.
pub fn bump(&mut self) {
self.last_pos = self.pos;
let current_byte_offset =
self.byte_offset(self.pos).to_usize();
if current_byte_offset < self.source_text.len() {
if !self.curr.is_some() {
{
::std::rt::begin_unwind("assertion failed: self.curr.is_some()",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
346u32);
&_FILE_LINE
})
}
};
let last_char = self.curr.unwrap();
let ch = char_at(&self.source_text, current_byte_offset);
let next = current_byte_offset + ch.len_utf8();
let byte_offset_diff = next - current_byte_offset;
self.pos = self.pos + Pos::from_usize(byte_offset_diff);
self.curr = Some(ch);
self.col = self.col + CharPos(1);
if last_char == '\n' {
self.filemap.next_line(self.last_pos);
self.col = CharPos(0);
}
if byte_offset_diff > 1 {
self.filemap.record_multibyte_char(self.last_pos,
byte_offset_diff);
}
} else { self.curr = None; }
}
pub fn nextch(&self) -> Option<char> {
let offset = self.byte_offset(self.pos).to_usize();
if offset < self.source_text.len() {
Some(char_at(&self.source_text, offset))
} else { None }
}
pub fn nextch_is(&self, c: char) -> bool {
self.nextch() == Some(c)
}
pub fn nextnextch(&self) -> Option<char> {
let offset = self.byte_offset(self.pos).to_usize();
let s = &self.source_text[..];
if offset >= s.len() { return None }
let next = offset + char_at(s, offset).len_utf8();
if next < s.len() { Some(char_at(s, next)) } else { None }
}
pub fn nextnextch_is(&self, c: char) -> bool {
self.nextnextch() == Some(c)
}
/// Eats <XID_start><XID_continue>*, if possible.
fn scan_optional_raw_name(&mut self) -> Option<ast::Name> {
if !ident_start(self.curr) { return None }
let start = self.last_pos;
while ident_continue(self.curr) { self.bump(); }
self.with_str_from(start, |string| {
if string == "_" {
None
} else { Some(token::intern(string)) } })
}
/// PRECONDITION: self.curr is not whitespace
/// Eats any kind of comment.
fn scan_comment(&mut self) -> Option<TokenAndSpan> {
match self.curr {
Some(c) => {
if c.is_whitespace() {
self.span_diagnostic.span_err(codemap::mk_sp(self.last_pos,
self.last_pos),
"called consume_any_line_comment, but there was whitespace");
}
}
None => { }
}
if self.curr_is('/') {
match self.nextch() {
Some('/') => {
self.bump();
self.bump();
let doc_comment =
self.curr_is('/') || self.curr_is('!');
let start_bpos =
if doc_comment {
self.pos - BytePos(3)
} else { self.last_pos - BytePos(2) };
while !self.is_eof() {
match self.curr.unwrap() {
'\n' => break ,
'\r' => {
if self.nextch_is('\n') {
break
} else if doc_comment {
self.err_span_(self.last_pos,
self.pos,
"bare CR not allowed in doc-comment");
}
}
_ => (),
}
self.bump();
}
return if doc_comment {
self.with_str_from(start_bpos,
|string| {
let tok =
if is_doc_comment(string)
{
token::DocComment(token::intern(string))
} else {
token::Comment
};
Some(TokenAndSpan{tok:
tok,
sp:
codemap::mk_sp(start_bpos,
self.last_pos),})
})
} else {
Some(TokenAndSpan{tok: token::Comment,
sp:
codemap::mk_sp(start_bpos,
self.last_pos),})
}
}
Some('*') => {
self.bump();
self.bump();
self.scan_block_comment()
}
_ => None,
}
} else if self.curr_is('#') {
if self.nextch_is('!') {
if self.nextnextch_is('[') { return None; }
let cmap = CodeMap::new();
cmap.files.borrow_mut().push(self.filemap.clone());
let loc = cmap.lookup_char_pos_adj(self.last_pos);
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 499u32,
__file:
"src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["Skipping a shebang"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
if loc.line == 1 && loc.col == CharPos(0) {
let start = self.last_pos;
while !self.curr_is('\n') && !self.is_eof() {
self.bump();
}
return Some(TokenAndSpan{tok:
token::Shebang(self.name_from(start)),
sp:
codemap::mk_sp(start,
self.last_pos),});
}
}
None
} else { None }
}
/// If there is whitespace, shebang, or a comment, scan it. Otherwise,
/// return None.
fn scan_whitespace_or_comment(&mut self) -> Option<TokenAndSpan> {
match self.curr.unwrap_or('\u{0}') {
'/' | '#' => {
let c = self.scan_comment();
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 524u32,
__file:
"src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["scanning a comment "];
__STATIC_FMTSTR
},
&match (&c,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
c
}
c if is_whitespace(Some(c)) => {
let start_bpos = self.last_pos;
while is_whitespace(self.curr) { self.bump(); }
let c =
Some(TokenAndSpan{tok: token::Whitespace,
sp:
codemap::mk_sp(start_bpos,
self.last_pos),});
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 534u32,
__file:
"src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["scanning whitespace: "];
__STATIC_FMTSTR
},
&match (&c,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
c
}
_ => None,
}
}
/// Might return a sugared-doc-attr
fn scan_block_comment(&mut self) -> Option<TokenAndSpan> {
let is_doc_comment = self.curr_is('*') || self.curr_is('!');
let start_bpos = self.last_pos - BytePos(2);
let mut level: isize = 1;
let mut has_cr = false;
while level > 0 {
if self.is_eof() {
let msg =
if is_doc_comment {
"unterminated block doc-comment"
} else { "unterminated block comment" };
let last_bpos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_bpos,
msg),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
557u32);
&_FILE_LINE
})
};
}
let n = self.curr.unwrap();
match n {
'/' if self.nextch_is('*') => {
level += 1;
self.bump();
}
'*' if self.nextch_is('/') => {
level -= 1;
self.bump();
}
'\r' => { has_cr = true; }
_ => (),
}
self.bump();
}
self.with_str_from(start_bpos, |string| {
let tok =
if is_block_doc_comment(string) {
let string =
if has_cr {
self.translate_crlf(start_bpos,
string,
"bare CR not allowed in block doc-comment")
} else { string.into() };
token::DocComment(token::intern(&string[..]))
} else { token::Comment };
Some(TokenAndSpan{tok: tok,
sp:
codemap::mk_sp(start_bpos,
self.last_pos),})
})
}
/// Scan through any digits (base `scan_radix`) or underscores,
/// and return how many digits there were.
///
/// `real_radix` represents the true radix of the number we're
/// interested in, and errors will be emitted for any digits
/// between `real_radix` and `scan_radix`.
fn scan_digits(&mut self, real_radix: u32, scan_radix: u32)
-> usize {
if !(real_radix <= scan_radix) {
{
::std::rt::begin_unwind("assertion failed: real_radix <= scan_radix",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/mod.rs",
603u32);
&_FILE_LINE
})
}
};
let mut len = 0;
loop {
let c = self.curr;
if c == Some('_') {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 607u32,
__file:
"src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["skipping a _"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
self.bump();
continue ;
}
match c.and_then(|cc| cc.to_digit(scan_radix)) {
Some(_) => {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 610u32,
__file:
"src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" in scan_digits"];
__STATIC_FMTSTR
},
&match (&c,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
if c.unwrap().to_digit(real_radix).is_none() {
self.err_span_(self.last_pos, self.pos,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid digit for a base ",
" literal"];
__STATIC_FMTSTR
},
&match (&real_radix,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
len += 1;
self.bump();
}
_ => return len,
}
};
}
/// Lex a LIT_INTEGER or a LIT_FLOAT
fn scan_number(&mut self, c: char) -> token::Lit {
let num_digits;
let mut base = 10;
let start_bpos = self.last_pos;
self.bump();
if c == '0' {
match self.curr.unwrap_or('\u{0}') {
'b' => {
self.bump();
base = 2;
num_digits = self.scan_digits(2, 10);
}
'o' => {
self.bump();
base = 8;
num_digits = self.scan_digits(8, 10);
}
'x' => {
self.bump();
base = 16;
num_digits = self.scan_digits(16, 16);
}
'0' ...'9' | '_' | '.' => {
num_digits = self.scan_digits(10, 10) + 1;
}
_ => {
return token::Integer(self.name_from(start_bpos));
}
}
} else if c.is_digit(10) {
num_digits = self.scan_digits(10, 10) + 1;
} else { num_digits = 0; }
if num_digits == 0 {
self.err_span_(start_bpos, self.last_pos,
"no valid digits found for number");
return token::Integer(token::intern("0"));
}
if self.curr_is('.') && !self.nextch_is('.') &&
!UnicodeXID::is_xid_start(self.nextch().unwrap_or('\u{0}'))
{
self.bump();
if self.curr.unwrap_or('\u{0}').is_digit(10) {
self.scan_digits(10, 10);
self.scan_float_exponent();
}
let last_pos = self.last_pos;
self.check_float_base(start_bpos, last_pos, base);
return token::Float(self.name_from(start_bpos));
} else {
if self.curr_is('e') || self.curr_is('E') {
self.scan_float_exponent();
let last_pos = self.last_pos;
self.check_float_base(start_bpos, last_pos, base);
return token::Float(self.name_from(start_bpos));
}
return token::Integer(self.name_from(start_bpos));
}
}
/// Scan over `n_digits` hex digits, stopping at `delim`, reporting an
/// error if too many or too few digits are encountered.
fn scan_hex_digits(&mut self, n_digits: usize, delim: char,
below_0x7f_only: bool) -> bool {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 694u32,
__file: "src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["scanning ",
" digits until "];
__STATIC_FMTSTR
},
&match (&n_digits,
&delim)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
let start_bpos = self.last_pos;
let mut accum_int = 0;
let mut valid = true;
for _ in 0..n_digits {
if self.is_eof() {
let last_bpos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_bpos,
"unterminated numeric character escape"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
702u32);
&_FILE_LINE
})
};
}
if self.curr_is(delim) {
let last_bpos = self.last_pos;
self.err_span_(start_bpos, last_bpos,
"numeric character escape is too short");
valid = false;
break ;
}
let c = self.curr.unwrap_or('\u{0}');
accum_int *= 16;
accum_int +=
c.to_digit(16).unwrap_or_else(|| {
self.err_span_char(self.last_pos,
self.pos,
"invalid character in numeric character escape",
c);
valid = false; 0 });
self.bump();
}
if below_0x7f_only && accum_int >= 128 {
self.err_span_(start_bpos, self.last_pos,
"this form of character escape may only be used with characters in the range [\\x00-\\x7f]");
valid = false;
}
match char::from_u32(accum_int) {
Some(_) => valid,
None => {
let last_bpos = self.last_pos;
self.err_span_(start_bpos, last_bpos,
"invalid numeric character escape");
false
}
}
}
/// Scan for a single (possibly escaped) byte or char
/// in a byte, (non-raw) byte string, char, or (non-raw) string literal.
/// `start` is the position of `first_source_char`, which is already consumed.
///
/// Returns true if there was a valid char/byte, false otherwise.
fn scan_char_or_byte(&mut self, start: BytePos,
first_source_char: char, ascii_only: bool,
delim: char) -> bool {
match first_source_char {
'\\' => {
let escaped = self.curr;
let escaped_pos = self.last_pos;
self.bump();
match escaped {
None => { }
Some(e) => {
return match e {
'n' | 'r' | 't' | '\\' | '\'' |
'\"' | '0' => true,
'x' =>
self.scan_byte_escape(delim,
!ascii_only),
'u' => {
let valid =
if self.curr_is('{') {
self.scan_unicode_escape(delim)
&& !ascii_only
} else {
let span =
codemap::mk_sp(start,
self.last_pos);
self.span_diagnostic.struct_span_err(span,
"incorrect unicode escape sequence").span_help(span,
"format of unicode escape sequences is `\\u{\u{2026}}`").emit();
false
};
if ascii_only {
self.err_span_(start,
self.last_pos,
"unicode escape sequences cannot be used as a byte or in a byte string");
}
valid
}
'\n' if delim == '\"' => {
self.consume_whitespace();
true
}
'\r' if
delim == '\"' && self.curr_is('\n')
=> {
self.consume_whitespace();
true
}
c => {
let last_pos = self.last_pos;
let mut err =
self.struct_err_span_char(escaped_pos,
last_pos,
if ascii_only
{
"unknown byte escape"
} else {
"unknown character escape"
},
c);
if e == '\r' {
err.span_help(codemap::mk_sp(escaped_pos,
last_pos),
"this is an isolated carriage return; consider checking your editor and version control settings");
}
if (e == '{' || e == '}') &&
!ascii_only {
err.span_help(codemap::mk_sp(escaped_pos,
last_pos),
"if used in a formatting string, curly braces are escaped with `{{` and `}}`");
}
err.emit();
false
}
}
}
}
}
'\t' | '\n' | '\r' | '\'' if delim == '\'' => {
let last_pos = self.last_pos;
self.err_span_char(start, last_pos,
if ascii_only {
"byte constant must be escaped"
} else {
"character constant must be escaped"
}, first_source_char);
return false;
}
'\r' => {
if self.curr_is('\n') {
self.bump();
return true;
} else {
self.err_span_(start, self.last_pos,
"bare CR not allowed in string, use \\r instead");
return false;
}
}
_ =>
if ascii_only && first_source_char > '\u{7f}' {
let last_pos = self.last_pos;
self.err_span_char(start, last_pos,
"byte constant must be ASCII. Use a \\xHH escape for a non-ASCII byte",
first_source_char);
return false;
},
}
true
}
/// Scan over a \u{...} escape
///
/// At this point, we have already seen the \ and the u, the { is the current character. We
/// will read at least one digit, and up to 6, and pass over the }.
fn scan_unicode_escape(&mut self, delim: char) -> bool {
self.bump();
let start_bpos = self.last_pos;
let mut count = 0;
let mut accum_int = 0;
let mut valid = true;
while !self.curr_is('}') && count <= 6 {
let c =
match self.curr {
Some(c) => c,
None => {
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
self.last_pos,
"unterminated unicode escape (found EOF)"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
860u32);
&_FILE_LINE
})
};
}
};
accum_int *= 16;
accum_int +=
c.to_digit(16).unwrap_or_else(|| {
if c == delim {
{
::std::rt::begin_unwind(self.fatal_span_(self.last_pos,
self.pos,
"unterminated unicode escape (needed a `}`)"),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/lexer/mod.rs",
867u32);
&_FILE_LINE
})
};
} else {
self.err_span_char(self.last_pos,
self.pos,
"invalid character in unicode escape",
c);
} valid = false; 0 });
self.bump();
count += 1;
}
if count > 6 {
self.err_span_(start_bpos, self.last_pos,
"overlong unicode escape (can have at most 6 hex digits)");
valid = false;
}
if valid &&
(char::from_u32(accum_int).is_none() || count == 0) {
self.err_span_(start_bpos, self.last_pos,
"invalid unicode character escape");
valid = false;
}
self.bump();
valid
}
/// Scan over a float exponent.
fn scan_float_exponent(&mut self) {
if self.curr_is('e') || self.curr_is('E') {
self.bump();
if self.curr_is('-') || self.curr_is('+') { self.bump(); }
if self.scan_digits(10, 10) == 0 {
self.err_span_(self.last_pos, self.pos,
"expected at least one digit in exponent")
}
}
}
/// Check that a base is valid for a floating literal, emitting a nice
/// error if it isn't.
fn check_float_base(&mut self, start_bpos: BytePos,
last_bpos: BytePos, base: usize) {
match base {
16 =>
self.err_span_(start_bpos, last_bpos,
"hexadecimal float literal is not supported"),
8 =>
self.err_span_(start_bpos, last_bpos,
"octal float literal is not supported"),
2 =>
self.err_span_(start_bpos, last_bpos,
"binary float literal is not supported"),
_ => (),
}
}
fn binop(&mut self, op: token::BinOpToken) -> token::Token {
self.bump();
if self.curr_is('=') {
self.bump();
return token::BinOpEq(op);
} else { return token::BinOp(op); }
}
/// Return the next token from the string, advances the input past that
/// token, and updates the interner
fn next_token_inner(&mut self) -> token::Token {
let c = self.curr;
if ident_start(c) &&
match (c.unwrap(), self.nextch(), self.nextnextch()) {
('r', Some('\"'), _) | ('r', Some('#'), _) |
('b', Some('\"'), _) | ('b', Some('\''), _) |
('b', Some('r'), Some('\"')) |
('b', Some('r'), Some('#')) => false,
_ => true,
} {
let start = self.last_pos;
while ident_continue(self.curr) { self.bump(); }
return self.with_str_from(start, |string| {
if string == "_" {
token::Underscore
} else {
if self.curr_is(':') &&
self.nextch_is(':') {
token::Ident(str_to_ident(string),
token::ModName)
} else {
token::Ident(str_to_ident(string),
token::Plain)
}
} });
}
if is_dec_digit(c) {
let num = self.scan_number(c.unwrap());
let suffix = self.scan_optional_raw_name();
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 965u32,
__file:
"src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["next_token_inner: scanned number ",
", "];
__STATIC_FMTSTR
},
&match (&num,
&suffix)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
return token::Literal(num, suffix)
}
match c.expect("next_token_inner called at EOF") {
';' => { self.bump(); return token::Semi; }
',' => { self.bump(); return token::Comma; }
'.' => {
self.bump();
return if self.curr_is('.') {
self.bump();
if self.curr_is('.') {
self.bump();
token::DotDotDot
} else { token::DotDot }
} else { token::Dot };
}
'(' => {
self.bump();
return token::OpenDelim(token::Paren);
}
')' => {
self.bump();
return token::CloseDelim(token::Paren);
}
'{' => {
self.bump();
return token::OpenDelim(token::Brace);
}
'}' => {
self.bump();
return token::CloseDelim(token::Brace);
}
'[' => {
self.bump();
return token::OpenDelim(token::Bracket);
}
']' => {
self.bump();
return token::CloseDelim(token::Bracket);
}
'@' => { self.bump(); return token::At; }
'#' => { self.bump(); return token::Pound; }
'~' => { self.bump(); return token::Tilde; }
'?' => { self.bump(); return token::Question; }
':' => {
self.bump();
if self.curr_is(':') {
self.bump();
return token::ModSep;
} else { return token::Colon; }
}
'$' => { self.bump(); return token::Dollar; }
'=' => {
self.bump();
if self.curr_is('=') {
self.bump();
return token::EqEq;
} else if self.curr_is('>') {
self.bump();
return token::FatArrow;
} else { return token::Eq; }
}
'!' => {
self.bump();
if self.curr_is('=') {
self.bump();
return token::Ne;
} else { return token::Not; }
}
'<' => {
self.bump();
match self.curr.unwrap_or('\u{0}') {
'=' => { self.bump(); return token::Le; }
'<' => { return self.binop(token::Shl); }
'-' => {
self.bump();
match self.curr.unwrap_or('\u{0}') {
_ => { return token::LArrow; }
}
}
_ => { return token::Lt; }
}
}
'>' => {
self.bump();
match self.curr.unwrap_or('\u{0}') {
'=' => { self.bump(); return token::Ge; }
'>' => { return self.binop(token::Shr); }
_ => { return token::Gt; }
}
}
'\'' => {
self.bump();
let start = self.last_pos;
let c2 = self.curr.unwrap_or('\u{0}');
self.bump();
if ident_start(Some(c2)) && !self.curr_is('\'') {
while ident_continue(self.curr) { self.bump(); }
let ident =
self.with_str_from(start, |lifetime_name| {
str_to_ident(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\'"];
__STATIC_FMTSTR
},
&match (&lifetime_name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
});
let keyword_checking_ident =
self.with_str_from(start, |lifetime_name| {
str_to_ident(lifetime_name)
});
let keyword_checking_token =
&token::Ident(keyword_checking_ident,
token::Plain);
let last_bpos = self.last_pos;
if keyword_checking_token.is_keyword(token::keywords::SelfValue)
{
self.err_span_(start, last_bpos,
"invalid lifetime name: \'self is no longer a special lifetime");
} else if keyword_checking_token.is_any_keyword()
&&
!keyword_checking_token.is_keyword(token::keywords::Static)
{
self.err_span_(start, last_bpos,
"invalid lifetime name");
}
return token::Lifetime(ident);
}
let valid =
self.scan_char_or_byte(start, c2, false, '\'');
if !self.curr_is('\'') {
let last_bpos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_verbose(start
-
BytePos(1),
last_bpos,
String::from("character literal may only contain one codepoint")),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1102u32);
&_FILE_LINE
})
};
}
let id =
if valid {
self.name_from(start)
} else { token::intern("0") };
self.bump();
let suffix = self.scan_optional_raw_name();
return token::Literal(token::Char(id), suffix);
}
'b' => {
self.bump();
let lit =
match self.curr {
Some('\'') => self.scan_byte(),
Some('\"') => self.scan_byte_string(),
Some('r') => self.scan_raw_byte_string(),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/lexer/mod.rs",
1121u32);
&_FILE_LINE
})
}
}
};
let suffix = self.scan_optional_raw_name();
return token::Literal(lit, suffix);
}
'\"' => {
let start_bpos = self.last_pos;
let mut valid = true;
self.bump();
while !self.curr_is('\"') {
if self.is_eof() {
let last_bpos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_bpos,
"unterminated double quote string"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1133u32);
&_FILE_LINE
})
};
}
let ch_start = self.last_pos;
let ch = self.curr.unwrap();
self.bump();
valid &=
self.scan_char_or_byte(ch_start, ch, false,
'\"');
}
let id =
if valid {
self.name_from(start_bpos + BytePos(1))
} else { token::intern("??") };
self.bump();
let suffix = self.scan_optional_raw_name();
return token::Literal(token::Str_(id), suffix);
}
'r' => {
let start_bpos = self.last_pos;
self.bump();
let mut hash_count = 0;
while self.curr_is('#') {
self.bump();
hash_count += 1;
}
if self.is_eof() {
let last_bpos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_bpos,
"unterminated raw string"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1161u32);
&_FILE_LINE
})
};
} else if !self.curr_is('\"') {
let last_bpos = self.last_pos;
let curr_char = self.curr.unwrap();
{
::std::rt::begin_unwind(self.fatal_span_char(start_bpos,
last_bpos,
"found invalid character; only `#` is allowed in raw string delimitation",
curr_char),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1165u32);
&_FILE_LINE
})
};
}
self.bump();
let content_start_bpos = self.last_pos;
let mut content_end_bpos;
let mut valid = true;
'outer:
loop {
if self.is_eof() {
let last_bpos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_bpos,
"unterminated raw string"),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/lexer/mod.rs",
1177u32);
&_FILE_LINE
})
};
}
let c = self.curr.unwrap();
match c {
'\"' => {
content_end_bpos = self.last_pos;
for _ in 0..hash_count {
self.bump();
if !self.curr_is('#') {
continue 'outer ;
}
}
break ;
}
'\r' => {
if !self.nextch_is('\n') {
let last_bpos = self.last_pos;
self.err_span_(start_bpos,
last_bpos,
"bare CR not allowed in raw string, use \\r instead");
valid = false;
}
}
_ => (),
}
self.bump();
}
self.bump();
let id =
if valid {
self.name_from_to(content_start_bpos,
content_end_bpos)
} else { token::intern("??") };
let suffix = self.scan_optional_raw_name();
return token::Literal(token::StrRaw(id, hash_count),
suffix);
}
'-' => {
if self.nextch_is('>') {
self.bump();
self.bump();
return token::RArrow;
} else { return self.binop(token::Minus); }
}
'&' => {
if self.nextch_is('&') {
self.bump();
self.bump();
return token::AndAnd;
} else { return self.binop(token::And); }
}
'|' => {
match self.nextch() {
Some('|') => {
self.bump();
self.bump();
return token::OrOr;
}
_ => { return self.binop(token::Or); }
}
}
'+' => { return self.binop(token::Plus); }
'*' => { return self.binop(token::Star); }
'/' => { return self.binop(token::Slash); }
'^' => { return self.binop(token::Caret); }
'%' => { return self.binop(token::Percent); }
c => {
let last_bpos = self.last_pos;
let bpos = self.pos;
let mut err =
self.struct_fatal_span_char(last_bpos, bpos,
"unknown start of token",
c);
unicode_chars::check_for_substitution(&self, c,
&mut err);
err.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1252u32);
&_FILE_LINE
})
};
}
}
}
fn consume_whitespace(&mut self) {
while is_whitespace(self.curr) && !self.is_eof() {
self.bump();
}
}
fn read_to_eol(&mut self) -> String {
let mut val = String::new();
while !self.curr_is('\n') && !self.is_eof() {
val.push(self.curr.unwrap());
self.bump();
}
if self.curr_is('\n') { self.bump(); }
return val
}
fn read_one_line_comment(&mut self) -> String {
let val = self.read_to_eol();
if !((val.as_bytes()[0] == b'/' && val.as_bytes()[1] == b'/')
||
(val.as_bytes()[0] == b'#' &&
val.as_bytes()[1] == b'!')) {
{
::std::rt::begin_unwind("assertion failed: (val.as_bytes()[0] == b\'/\' && val.as_bytes()[1] == b\'/\') ||\n (val.as_bytes()[0] == b\'#\' && val.as_bytes()[1] == b\'!\')",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/mod.rs",
1273u32);
&_FILE_LINE
})
}
};
return val;
}
fn consume_non_eol_whitespace(&mut self) {
while is_whitespace(self.curr) && !self.curr_is('\n') &&
!self.is_eof() {
self.bump();
}
}
fn peeking_at_comment(&self) -> bool {
(self.curr_is('/') && self.nextch_is('/')) ||
(self.curr_is('/') && self.nextch_is('*')) ||
(self.curr_is('#') && self.nextch_is('!') &&
!self.nextnextch_is('['))
}
fn scan_byte(&mut self) -> token::Lit {
self.bump();
let start = self.last_pos;
let c2 = self.curr.unwrap_or('\u{0}');
self.bump();
let valid = self.scan_char_or_byte(start, c2, true, '\'');
if !self.curr_is('\'') {
let last_pos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_verbose(start
-
BytePos(2),
last_pos,
"unterminated byte constant".to_string()),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/mod.rs",
1305u32);
&_FILE_LINE
})
};
}
let id =
if valid {
self.name_from(start)
} else { token::intern("?") };
self.bump();
return token::Byte(id);
}
fn scan_byte_escape(&mut self, delim: char, below_0x7f_only: bool)
-> bool {
self.scan_hex_digits(2, delim, below_0x7f_only)
}
fn scan_byte_string(&mut self) -> token::Lit {
self.bump();
let start = self.last_pos;
let mut valid = true;
while !self.curr_is('\"') {
if self.is_eof() {
let last_pos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start,
last_pos,
"unterminated double quote byte string"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1327u32);
&_FILE_LINE
})
};
}
let ch_start = self.last_pos;
let ch = self.curr.unwrap();
self.bump();
valid &= self.scan_char_or_byte(ch_start, ch, true, '\"');
}
let id =
if valid {
self.name_from(start)
} else { token::intern("??") };
self.bump();
return token::ByteStr(id);
}
fn scan_raw_byte_string(&mut self) -> token::Lit {
let start_bpos = self.last_pos;
self.bump();
let mut hash_count = 0;
while self.curr_is('#') { self.bump(); hash_count += 1; }
if self.is_eof() {
let last_pos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_pos,
"unterminated raw string"),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/mod.rs",
1351u32);
&_FILE_LINE
})
};
} else if !self.curr_is('\"') {
let last_pos = self.last_pos;
let ch = self.curr.unwrap();
{
::std::rt::begin_unwind(self.fatal_span_char(start_bpos,
last_pos,
"found invalid character; only `#` is allowed in raw string delimitation",
ch),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/lexer/mod.rs",
1355u32);
&_FILE_LINE
})
};
}
self.bump();
let content_start_bpos = self.last_pos;
let mut content_end_bpos;
'outer:
loop {
match self.curr {
None => {
let last_pos = self.last_pos;
{
::std::rt::begin_unwind(self.fatal_span_(start_bpos,
last_pos,
"unterminated raw string"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/lexer/mod.rs",
1367u32);
&_FILE_LINE
})
}
}
Some('\"') => {
content_end_bpos = self.last_pos;
for _ in 0..hash_count {
self.bump();
if !self.curr_is('#') {
continue 'outer ;
}
}
break ;
}
Some(c) =>
if c > '\u{7f}' {
let last_pos = self.last_pos;
self.err_span_char(last_pos, last_pos,
"raw byte string must be ASCII",
c);
},
}
self.bump();
}
self.bump();
return token::ByteStrRaw(self.name_from_to(content_start_bpos,
content_end_bpos),
hash_count);
}
}
pub fn is_whitespace(c: Option<char>) -> bool {
match c.unwrap_or('\u{0}') {
' ' | '\n' | '\t' | '\r' => true,
_ => false,
}
}
fn in_range(c: Option<char>, lo: char, hi: char) -> bool {
match c { Some(c) => lo <= c && c <= hi, _ => false, }
}
fn is_dec_digit(c: Option<char>) -> bool {
return in_range(c, '0', '9');
}
pub fn is_doc_comment(s: &str) -> bool {
let res =
(s.starts_with("///") &&
*s.as_bytes().get(3).unwrap_or(&b' ') != b'/') ||
s.starts_with("//!");
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1413u32,
__file: "src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["is ",
" a doc comment? "];
__STATIC_FMTSTR
},
&match (&s,
&res) {
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
res
}
pub fn is_block_doc_comment(s: &str) -> bool {
let res =
((s.starts_with("/**") &&
*s.as_bytes().get(3).unwrap_or(&b' ') != b'*') ||
s.starts_with("/*!")) && s.len() >= 5;
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 1421u32,
__file: "src/parse/lexer/mod.rs",
__module_path:
"syntex_syntax::parse::lexer",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::lexer", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["is ",
" a doc comment? "];
__STATIC_FMTSTR
},
&match (&s,
&res) {
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
res
}
fn ident_start(c: Option<char>) -> bool {
let c = match c { Some(c) => c, None => return false, };
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' ||
(c > '\u{7f}' && UnicodeXID::is_xid_start(c))
}
fn ident_continue(c: Option<char>) -> bool {
let c = match c { Some(c) => c, None => return false, };
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || c == '_' ||
(c > '\u{7f}' && UnicodeXID::is_xid_continue(c))
}
}
pub mod token {
#[prelude_import]
use std::prelude::v1::*;
pub use self::BinOpToken::*;
pub use self::Nonterminal::*;
pub use self::DelimToken::*;
pub use self::IdentStyle::*;
pub use self::Lit::*;
pub use self::Token::*;
use ast;
use ext::mtwt;
use ptr::P;
use util::interner::{RcStr, StrInterner};
use util::interner;
use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::fmt;
use std::ops::Deref;
use std::rc::Rc;
#[allow(non_camel_case_types)]
pub enum BinOpToken {
Plus,
Minus,
Star,
Slash,
Percent,
Caret,
And,
Or,
Shl,
Shr,
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::marker::Copy for BinOpToken { }
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::fmt::Debug for BinOpToken {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&BinOpToken::Plus,) => {
let mut builder = __arg_0.debug_tuple("Plus");
builder.finish()
}
(&BinOpToken::Minus,) => {
let mut builder = __arg_0.debug_tuple("Minus");
builder.finish()
}
(&BinOpToken::Star,) => {
let mut builder = __arg_0.debug_tuple("Star");
builder.finish()
}
(&BinOpToken::Slash,) => {
let mut builder = __arg_0.debug_tuple("Slash");
builder.finish()
}
(&BinOpToken::Percent,) => {
let mut builder = __arg_0.debug_tuple("Percent");
builder.finish()
}
(&BinOpToken::Caret,) => {
let mut builder = __arg_0.debug_tuple("Caret");
builder.finish()
}
(&BinOpToken::And,) => {
let mut builder = __arg_0.debug_tuple("And");
builder.finish()
}
(&BinOpToken::Or,) => {
let mut builder = __arg_0.debug_tuple("Or");
builder.finish()
}
(&BinOpToken::Shl,) => {
let mut builder = __arg_0.debug_tuple("Shl");
builder.finish()
}
(&BinOpToken::Shr,) => {
let mut builder = __arg_0.debug_tuple("Shr");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::hash::Hash for BinOpToken {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&BinOpToken::Plus,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&BinOpToken::Minus,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&BinOpToken::Star,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
(&BinOpToken::Slash,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&BinOpToken::Percent,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
(&BinOpToken::Caret,) => {
::std::hash::Hash::hash(&5usize, __arg_0);
}
(&BinOpToken::And,) => {
::std::hash::Hash::hash(&6usize, __arg_0);
}
(&BinOpToken::Or,) => {
::std::hash::Hash::hash(&7usize, __arg_0);
}
(&BinOpToken::Shl,) => {
::std::hash::Hash::hash(&8usize, __arg_0);
}
(&BinOpToken::Shr,) => {
::std::hash::Hash::hash(&9usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::cmp::Eq for BinOpToken {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&BinOpToken::Plus,) => { }
(&BinOpToken::Minus,) => { }
(&BinOpToken::Star,) => { }
(&BinOpToken::Slash,) => { }
(&BinOpToken::Percent,) => { }
(&BinOpToken::Caret,) => { }
(&BinOpToken::And,) => { }
(&BinOpToken::Or,) => { }
(&BinOpToken::Shl,) => { }
(&BinOpToken::Shr,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::cmp::PartialEq for BinOpToken {
#[inline]
fn eq(&self, __arg_0: &BinOpToken) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BinOpToken::Plus, &BinOpToken::Plus) => true,
(&BinOpToken::Minus, &BinOpToken::Minus) => true,
(&BinOpToken::Star, &BinOpToken::Star) => true,
(&BinOpToken::Slash, &BinOpToken::Slash) => true,
(&BinOpToken::Percent, &BinOpToken::Percent) =>
true,
(&BinOpToken::Caret, &BinOpToken::Caret) => true,
(&BinOpToken::And, &BinOpToken::And) => true,
(&BinOpToken::Or, &BinOpToken::Or) => true,
(&BinOpToken::Shl, &BinOpToken::Shl) => true,
(&BinOpToken::Shr, &BinOpToken::Shr) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &BinOpToken) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&BinOpToken::Plus, &BinOpToken::Plus) => false,
(&BinOpToken::Minus, &BinOpToken::Minus) => false,
(&BinOpToken::Star, &BinOpToken::Star) => false,
(&BinOpToken::Slash, &BinOpToken::Slash) => false,
(&BinOpToken::Percent, &BinOpToken::Percent) =>
false,
(&BinOpToken::Caret, &BinOpToken::Caret) => false,
(&BinOpToken::And, &BinOpToken::And) => false,
(&BinOpToken::Or, &BinOpToken::Or) => false,
(&BinOpToken::Shl, &BinOpToken::Shl) => false,
(&BinOpToken::Shr, &BinOpToken::Shr) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::rustc_serialize::Decodable for BinOpToken {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<BinOpToken, __D::Error> {
__arg_0.read_enum("BinOpToken", |_d| -> _ {
_d.read_enum_variant(&["Plus", "Minus",
"Star", "Slash",
"Percent", "Caret",
"And", "Or", "Shl",
"Shr"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
BinOpToken::Plus,
1usize
=>
BinOpToken::Minus,
2usize
=>
BinOpToken::Star,
3usize
=>
BinOpToken::Slash,
4usize
=>
BinOpToken::Percent,
5usize
=>
BinOpToken::Caret,
6usize
=>
BinOpToken::And,
7usize
=>
BinOpToken::Or,
8usize
=>
BinOpToken::Shl,
9usize
=>
BinOpToken::Shr,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
30u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::rustc_serialize::Encodable for BinOpToken {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&BinOpToken::Plus,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Plus", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Minus,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Minus", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Star,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Star", 2usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Slash,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Slash", 3usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Percent,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Percent", 4usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Caret,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Caret", 5usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::And,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("And", 6usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Or,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Or", 7usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Shl,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Shl", 8usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&BinOpToken::Shr,) => {
let _e = __arg_0;
_e.emit_enum("BinOpToken", |_e| -> _ {
_e.emit_enum_variant("Shr", 9usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::clone::Clone for BinOpToken {
#[inline]
fn clone(&self) -> BinOpToken {
match (&*self,) {
(&BinOpToken::Plus,) => BinOpToken::Plus,
(&BinOpToken::Minus,) => BinOpToken::Minus,
(&BinOpToken::Star,) => BinOpToken::Star,
(&BinOpToken::Slash,) => BinOpToken::Slash,
(&BinOpToken::Percent,) => BinOpToken::Percent,
(&BinOpToken::Caret,) => BinOpToken::Caret,
(&BinOpToken::And,) => BinOpToken::And,
(&BinOpToken::Or,) => BinOpToken::Or,
(&BinOpToken::Shl,) => BinOpToken::Shl,
(&BinOpToken::Shr,) => BinOpToken::Shr,
}
}
}
/// A delimiter token
pub enum DelimToken {
/// A round parenthesis: `(` or `)`
Paren,
/// A square bracket: `[` or `]`
Bracket,
/// A curly brace: `{` or `}`
Brace,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for DelimToken { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for DelimToken {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&DelimToken::Paren,) => {
let mut builder = __arg_0.debug_tuple("Paren");
builder.finish()
}
(&DelimToken::Bracket,) => {
let mut builder = __arg_0.debug_tuple("Bracket");
builder.finish()
}
(&DelimToken::Brace,) => {
let mut builder = __arg_0.debug_tuple("Brace");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for DelimToken {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&DelimToken::Paren,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&DelimToken::Bracket,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&DelimToken::Brace,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for DelimToken {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&DelimToken::Paren,) => { }
(&DelimToken::Bracket,) => { }
(&DelimToken::Brace,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for DelimToken {
#[inline]
fn eq(&self, __arg_0: &DelimToken) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&DelimToken::Paren, &DelimToken::Paren) => true,
(&DelimToken::Bracket, &DelimToken::Bracket) =>
true,
(&DelimToken::Brace, &DelimToken::Brace) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &DelimToken) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&DelimToken::Paren, &DelimToken::Paren) => false,
(&DelimToken::Bracket, &DelimToken::Bracket) =>
false,
(&DelimToken::Brace, &DelimToken::Brace) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for DelimToken {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<DelimToken, __D::Error> {
__arg_0.read_enum("DelimToken", |_d| -> _ {
_d.read_enum_variant(&["Paren", "Bracket",
"Brace"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
DelimToken::Paren,
1usize
=>
DelimToken::Bracket,
2usize
=>
DelimToken::Brace,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
45u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for DelimToken {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&DelimToken::Paren,) => {
let _e = __arg_0;
_e.emit_enum("DelimToken", |_e| -> _ {
_e.emit_enum_variant("Paren", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&DelimToken::Bracket,) => {
let _e = __arg_0;
_e.emit_enum("DelimToken", |_e| -> _ {
_e.emit_enum_variant("Bracket", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&DelimToken::Brace,) => {
let _e = __arg_0;
_e.emit_enum("DelimToken", |_e| -> _ {
_e.emit_enum_variant("Brace", 2usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for DelimToken {
#[inline]
fn clone(&self) -> DelimToken {
match (&*self,) {
(&DelimToken::Paren,) => DelimToken::Paren,
(&DelimToken::Bracket,) => DelimToken::Bracket,
(&DelimToken::Brace,) => DelimToken::Brace,
}
}
}
pub enum IdentStyle {
/// `::` follows the identifier with no whitespace in-between.
ModName,
Plain,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for IdentStyle { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for IdentStyle {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&IdentStyle::ModName,) => {
let mut builder = __arg_0.debug_tuple("ModName");
builder.finish()
}
(&IdentStyle::Plain,) => {
let mut builder = __arg_0.debug_tuple("Plain");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for IdentStyle {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&IdentStyle::ModName,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&IdentStyle::Plain,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for IdentStyle {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&IdentStyle::ModName,) => { }
(&IdentStyle::Plain,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for IdentStyle {
#[inline]
fn eq(&self, __arg_0: &IdentStyle) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&IdentStyle::ModName, &IdentStyle::ModName) =>
true,
(&IdentStyle::Plain, &IdentStyle::Plain) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &IdentStyle) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&IdentStyle::ModName, &IdentStyle::ModName) =>
false,
(&IdentStyle::Plain, &IdentStyle::Plain) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for IdentStyle {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<IdentStyle, __D::Error> {
__arg_0.read_enum("IdentStyle", |_d| -> _ {
_d.read_enum_variant(&["ModName", "Plain"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
IdentStyle::ModName,
1usize
=>
IdentStyle::Plain,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
55u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for IdentStyle {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&IdentStyle::ModName,) => {
let _e = __arg_0;
_e.emit_enum("IdentStyle", |_e| -> _ {
_e.emit_enum_variant("ModName", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&IdentStyle::Plain,) => {
let _e = __arg_0;
_e.emit_enum("IdentStyle", |_e| -> _ {
_e.emit_enum_variant("Plain", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for IdentStyle {
#[inline]
fn clone(&self) -> IdentStyle {
match (&*self,) {
(&IdentStyle::ModName,) => IdentStyle::ModName,
(&IdentStyle::Plain,) => IdentStyle::Plain,
}
}
}
pub enum SpecialMacroVar {
/// `$crate` will be filled in with the name of the crate a macro was
/// imported from, if any.
CrateMacroVar,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for SpecialMacroVar { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for SpecialMacroVar {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&SpecialMacroVar::CrateMacroVar,) => {
let mut builder =
__arg_0.debug_tuple("CrateMacroVar");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for SpecialMacroVar {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&SpecialMacroVar::CrateMacroVar,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for SpecialMacroVar {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) { (&SpecialMacroVar::CrateMacroVar,) => { } }
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for SpecialMacroVar {
#[inline]
fn eq(&self, __arg_0: &SpecialMacroVar) -> bool {
match (&*self, &*__arg_0) {
(&SpecialMacroVar::CrateMacroVar,
&SpecialMacroVar::CrateMacroVar) => true,
}
}
#[inline]
fn ne(&self, __arg_0: &SpecialMacroVar) -> bool {
match (&*self, &*__arg_0) {
(&SpecialMacroVar::CrateMacroVar,
&SpecialMacroVar::CrateMacroVar) => false,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for SpecialMacroVar {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<SpecialMacroVar, __D::Error> {
__arg_0.read_enum("SpecialMacroVar", |_d| -> _ {
_d.read_enum_variant(&["CrateMacroVar"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
SpecialMacroVar::CrateMacroVar,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
62u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for SpecialMacroVar {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&SpecialMacroVar::CrateMacroVar,) => {
let _e = __arg_0;
_e.emit_enum("SpecialMacroVar", |_e| -> _ {
_e.emit_enum_variant("CrateMacroVar",
0usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for SpecialMacroVar {
#[inline]
fn clone(&self) -> SpecialMacroVar {
match (&*self,) {
(&SpecialMacroVar::CrateMacroVar,) =>
SpecialMacroVar::CrateMacroVar,
}
}
}
impl SpecialMacroVar {
pub fn as_str(self) -> &'static str {
match self { SpecialMacroVar::CrateMacroVar => "crate", }
}
}
pub enum Lit {
Byte(ast::Name),
Char(ast::Name),
Integer(ast::Name),
Float(ast::Name),
Str_(ast::Name),
StrRaw(ast::Name, usize),
ByteStr(ast::Name),
ByteStrRaw(ast::Name, usize),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Lit { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Lit {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Lit::Byte(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Byte");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit::Char(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Char");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit::Integer(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Integer");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit::Float(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Float");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit::Str_(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Str_");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit::StrRaw(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("StrRaw");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Lit::ByteStr(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ByteStr");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("ByteStrRaw");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Lit {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&Lit::Byte(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit::Char(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit::Integer(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit::Float(ref __self_0),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit::Str_(ref __self_0),) => {
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit::StrRaw(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Lit::ByteStr(ref __self_0),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Lit {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Lit::Byte(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit::Char(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit::Integer(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit::Float(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit::Str_(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit::StrRaw(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Lit::ByteStr(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Lit {
#[inline]
fn eq(&self, __arg_0: &Lit) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Lit::Byte(ref __self_0),
&Lit::Byte(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit::Char(ref __self_0),
&Lit::Char(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit::Integer(ref __self_0),
&Lit::Integer(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit::Float(ref __self_0),
&Lit::Float(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit::Str_(ref __self_0),
&Lit::Str_(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit::StrRaw(ref __self_0, ref __self_1),
&Lit::StrRaw(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Lit::ByteStr(ref __self_0),
&Lit::ByteStr(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),
&Lit::ByteStrRaw(ref __arg_1_0, ref __arg_1_1))
=>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Lit) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Lit::Byte(ref __self_0),
&Lit::Byte(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit::Char(ref __self_0),
&Lit::Char(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit::Integer(ref __self_0),
&Lit::Integer(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit::Float(ref __self_0),
&Lit::Float(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit::Str_(ref __self_0),
&Lit::Str_(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit::StrRaw(ref __self_0, ref __self_1),
&Lit::StrRaw(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Lit::ByteStr(ref __self_0),
&Lit::ByteStr(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),
&Lit::ByteStrRaw(ref __arg_1_0, ref __arg_1_1))
=>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Lit {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Lit, __D::Error> {
__arg_0.read_enum("Lit", |_d| -> _ {
_d.read_enum_variant(&["Byte", "Char",
"Integer", "Float",
"Str_", "StrRaw",
"ByteStr",
"ByteStrRaw"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Lit::Byte(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Lit::Char(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Lit::Integer(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Lit::Float(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Lit::Str_(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Lit::StrRaw(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Lit::ByteStr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Lit::ByteStrRaw(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
77u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Lit {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Lit::Byte(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("Byte", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit::Char(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("Char", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit::Integer(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("Integer", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit::Float(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("Float", 3usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit::Str_(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("Str_", 4usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit::StrRaw(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("StrRaw", 5usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Lit::ByteStr(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("ByteStr", 6usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Lit", |_e| -> _ {
_e.emit_enum_variant("ByteStrRaw",
7usize, 2usize,
|_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Lit {
#[inline]
fn clone(&self) -> Lit {
match (&*self,) {
(&Lit::Byte(ref __self_0),) =>
Lit::Byte(::std::clone::Clone::clone(&(*__self_0))),
(&Lit::Char(ref __self_0),) =>
Lit::Char(::std::clone::Clone::clone(&(*__self_0))),
(&Lit::Integer(ref __self_0),) =>
Lit::Integer(::std::clone::Clone::clone(&(*__self_0))),
(&Lit::Float(ref __self_0),) =>
Lit::Float(::std::clone::Clone::clone(&(*__self_0))),
(&Lit::Str_(ref __self_0),) =>
Lit::Str_(::std::clone::Clone::clone(&(*__self_0))),
(&Lit::StrRaw(ref __self_0, ref __self_1),) =>
Lit::StrRaw(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Lit::ByteStr(ref __self_0),) =>
Lit::ByteStr(::std::clone::Clone::clone(&(*__self_0))),
(&Lit::ByteStrRaw(ref __self_0, ref __self_1),) =>
Lit::ByteStrRaw(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
}
}
}
impl Lit {
pub fn short_name(&self) -> &'static str {
match *self {
Byte(_) => "byte",
Char(_) => "char",
Integer(_) => "integer",
Float(_) => "float",
Str_(_) | StrRaw(..) => "string",
ByteStr(_) | ByteStrRaw(..) => "byte string",
}
}
}
#[allow(non_camel_case_types)]
pub enum Token {
Eq,
Lt,
Le,
EqEq,
Ne,
Ge,
Gt,
AndAnd,
OrOr,
Not,
Tilde,
BinOp(BinOpToken),
BinOpEq(BinOpToken),
At,
Dot,
DotDot,
DotDotDot,
Comma,
Semi,
Colon,
ModSep,
RArrow,
LArrow,
FatArrow,
Pound,
Dollar,
Question,
/// An opening delimiter, eg. `{`
OpenDelim(DelimToken),
/// A closing delimiter, eg. `}`
CloseDelim(DelimToken),
Literal(Lit, Option<ast::Name>),
Ident(ast::Ident, IdentStyle),
Underscore,
Lifetime(ast::Ident),
Interpolated(Nonterminal),
/// Doc comment
DocComment(ast::Name),
/// Parse a nonterminal (name to bind, name of NT, styles of their idents)
MatchNt(ast::Ident, ast::Ident, IdentStyle, IdentStyle),
/// A syntactic variable that will be filled in by macro expansion.
SubstNt(ast::Ident, IdentStyle),
/// A macro variable with special meaning.
SpecialVarNt(SpecialMacroVar),
/// Whitespace
Whitespace,
/// Comment
Comment,
Shebang(ast::Name),
Eof,
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::fmt::Debug for Token {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Token::Eq,) => {
let mut builder = __arg_0.debug_tuple("Eq");
builder.finish()
}
(&Token::Lt,) => {
let mut builder = __arg_0.debug_tuple("Lt");
builder.finish()
}
(&Token::Le,) => {
let mut builder = __arg_0.debug_tuple("Le");
builder.finish()
}
(&Token::EqEq,) => {
let mut builder = __arg_0.debug_tuple("EqEq");
builder.finish()
}
(&Token::Ne,) => {
let mut builder = __arg_0.debug_tuple("Ne");
builder.finish()
}
(&Token::Ge,) => {
let mut builder = __arg_0.debug_tuple("Ge");
builder.finish()
}
(&Token::Gt,) => {
let mut builder = __arg_0.debug_tuple("Gt");
builder.finish()
}
(&Token::AndAnd,) => {
let mut builder = __arg_0.debug_tuple("AndAnd");
builder.finish()
}
(&Token::OrOr,) => {
let mut builder = __arg_0.debug_tuple("OrOr");
builder.finish()
}
(&Token::Not,) => {
let mut builder = __arg_0.debug_tuple("Not");
builder.finish()
}
(&Token::Tilde,) => {
let mut builder = __arg_0.debug_tuple("Tilde");
builder.finish()
}
(&Token::BinOp(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("BinOp");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::BinOpEq(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("BinOpEq");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::At,) => {
let mut builder = __arg_0.debug_tuple("At");
builder.finish()
}
(&Token::Dot,) => {
let mut builder = __arg_0.debug_tuple("Dot");
builder.finish()
}
(&Token::DotDot,) => {
let mut builder = __arg_0.debug_tuple("DotDot");
builder.finish()
}
(&Token::DotDotDot,) => {
let mut builder = __arg_0.debug_tuple("DotDotDot");
builder.finish()
}
(&Token::Comma,) => {
let mut builder = __arg_0.debug_tuple("Comma");
builder.finish()
}
(&Token::Semi,) => {
let mut builder = __arg_0.debug_tuple("Semi");
builder.finish()
}
(&Token::Colon,) => {
let mut builder = __arg_0.debug_tuple("Colon");
builder.finish()
}
(&Token::ModSep,) => {
let mut builder = __arg_0.debug_tuple("ModSep");
builder.finish()
}
(&Token::RArrow,) => {
let mut builder = __arg_0.debug_tuple("RArrow");
builder.finish()
}
(&Token::LArrow,) => {
let mut builder = __arg_0.debug_tuple("LArrow");
builder.finish()
}
(&Token::FatArrow,) => {
let mut builder = __arg_0.debug_tuple("FatArrow");
builder.finish()
}
(&Token::Pound,) => {
let mut builder = __arg_0.debug_tuple("Pound");
builder.finish()
}
(&Token::Dollar,) => {
let mut builder = __arg_0.debug_tuple("Dollar");
builder.finish()
}
(&Token::Question,) => {
let mut builder = __arg_0.debug_tuple("Question");
builder.finish()
}
(&Token::OpenDelim(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("OpenDelim");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::CloseDelim(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("CloseDelim");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::Literal(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Literal");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Token::Ident(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Ident");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Token::Underscore,) => {
let mut builder = __arg_0.debug_tuple("Underscore");
builder.finish()
}
(&Token::Lifetime(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Lifetime");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::Interpolated(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Interpolated");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::DocComment(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("DocComment");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::MatchNt(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let mut builder = __arg_0.debug_tuple("MatchNt");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
let _ = builder.field(&&(*__self_3));
builder.finish()
}
(&Token::SubstNt(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("SubstNt");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&Token::SpecialVarNt(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("SpecialVarNt");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::Whitespace,) => {
let mut builder = __arg_0.debug_tuple("Whitespace");
builder.finish()
}
(&Token::Comment,) => {
let mut builder = __arg_0.debug_tuple("Comment");
builder.finish()
}
(&Token::Shebang(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Shebang");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Token::Eof,) => {
let mut builder = __arg_0.debug_tuple("Eof");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::hash::Hash for Token {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&Token::Eq,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&Token::Lt,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
(&Token::Le,) => {
::std::hash::Hash::hash(&2usize, __arg_0);
}
(&Token::EqEq,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
(&Token::Ne,) => {
::std::hash::Hash::hash(&4usize, __arg_0);
}
(&Token::Ge,) => {
::std::hash::Hash::hash(&5usize, __arg_0);
}
(&Token::Gt,) => {
::std::hash::Hash::hash(&6usize, __arg_0);
}
(&Token::AndAnd,) => {
::std::hash::Hash::hash(&7usize, __arg_0);
}
(&Token::OrOr,) => {
::std::hash::Hash::hash(&8usize, __arg_0);
}
(&Token::Not,) => {
::std::hash::Hash::hash(&9usize, __arg_0);
}
(&Token::Tilde,) => {
::std::hash::Hash::hash(&10usize, __arg_0);
}
(&Token::BinOp(ref __self_0),) => {
::std::hash::Hash::hash(&11usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::BinOpEq(ref __self_0),) => {
::std::hash::Hash::hash(&12usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::At,) => {
::std::hash::Hash::hash(&13usize, __arg_0);
}
(&Token::Dot,) => {
::std::hash::Hash::hash(&14usize, __arg_0);
}
(&Token::DotDot,) => {
::std::hash::Hash::hash(&15usize, __arg_0);
}
(&Token::DotDotDot,) => {
::std::hash::Hash::hash(&16usize, __arg_0);
}
(&Token::Comma,) => {
::std::hash::Hash::hash(&17usize, __arg_0);
}
(&Token::Semi,) => {
::std::hash::Hash::hash(&18usize, __arg_0);
}
(&Token::Colon,) => {
::std::hash::Hash::hash(&19usize, __arg_0);
}
(&Token::ModSep,) => {
::std::hash::Hash::hash(&20usize, __arg_0);
}
(&Token::RArrow,) => {
::std::hash::Hash::hash(&21usize, __arg_0);
}
(&Token::LArrow,) => {
::std::hash::Hash::hash(&22usize, __arg_0);
}
(&Token::FatArrow,) => {
::std::hash::Hash::hash(&23usize, __arg_0);
}
(&Token::Pound,) => {
::std::hash::Hash::hash(&24usize, __arg_0);
}
(&Token::Dollar,) => {
::std::hash::Hash::hash(&25usize, __arg_0);
}
(&Token::Question,) => {
::std::hash::Hash::hash(&26usize, __arg_0);
}
(&Token::OpenDelim(ref __self_0),) => {
::std::hash::Hash::hash(&27usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::CloseDelim(ref __self_0),) => {
::std::hash::Hash::hash(&28usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::Literal(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&29usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Token::Ident(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&30usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Token::Underscore,) => {
::std::hash::Hash::hash(&31usize, __arg_0);
}
(&Token::Lifetime(ref __self_0),) => {
::std::hash::Hash::hash(&32usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::Interpolated(ref __self_0),) => {
::std::hash::Hash::hash(&33usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::DocComment(ref __self_0),) => {
::std::hash::Hash::hash(&34usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::MatchNt(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
::std::hash::Hash::hash(&35usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
::std::hash::Hash::hash(&(*__self_3), __arg_0);
}
(&Token::SubstNt(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&36usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Token::SpecialVarNt(ref __self_0),) => {
::std::hash::Hash::hash(&37usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::Whitespace,) => {
::std::hash::Hash::hash(&38usize, __arg_0);
}
(&Token::Comment,) => {
::std::hash::Hash::hash(&39usize, __arg_0);
}
(&Token::Shebang(ref __self_0),) => {
::std::hash::Hash::hash(&40usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Token::Eof,) => {
::std::hash::Hash::hash(&41usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::cmp::Eq for Token {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Token::Eq,) => { }
(&Token::Lt,) => { }
(&Token::Le,) => { }
(&Token::EqEq,) => { }
(&Token::Ne,) => { }
(&Token::Ge,) => { }
(&Token::Gt,) => { }
(&Token::AndAnd,) => { }
(&Token::OrOr,) => { }
(&Token::Not,) => { }
(&Token::Tilde,) => { }
(&Token::BinOp(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::BinOpEq(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::At,) => { }
(&Token::Dot,) => { }
(&Token::DotDot,) => { }
(&Token::DotDotDot,) => { }
(&Token::Comma,) => { }
(&Token::Semi,) => { }
(&Token::Colon,) => { }
(&Token::ModSep,) => { }
(&Token::RArrow,) => { }
(&Token::LArrow,) => { }
(&Token::FatArrow,) => { }
(&Token::Pound,) => { }
(&Token::Dollar,) => { }
(&Token::Question,) => { }
(&Token::OpenDelim(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::CloseDelim(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::Literal(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Token::Ident(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Token::Underscore,) => { }
(&Token::Lifetime(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::Interpolated(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::DocComment(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::MatchNt(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
}
(&Token::SubstNt(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Token::SpecialVarNt(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::Whitespace,) => { }
(&Token::Comment,) => { }
(&Token::Shebang(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Token::Eof,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::cmp::PartialEq for Token {
#[inline]
fn eq(&self, __arg_0: &Token) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Token::Eq, &Token::Eq) => true,
(&Token::Lt, &Token::Lt) => true,
(&Token::Le, &Token::Le) => true,
(&Token::EqEq, &Token::EqEq) => true,
(&Token::Ne, &Token::Ne) => true,
(&Token::Ge, &Token::Ge) => true,
(&Token::Gt, &Token::Gt) => true,
(&Token::AndAnd, &Token::AndAnd) => true,
(&Token::OrOr, &Token::OrOr) => true,
(&Token::Not, &Token::Not) => true,
(&Token::Tilde, &Token::Tilde) => true,
(&Token::BinOp(ref __self_0),
&Token::BinOp(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::BinOpEq(ref __self_0),
&Token::BinOpEq(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::At, &Token::At) => true,
(&Token::Dot, &Token::Dot) => true,
(&Token::DotDot, &Token::DotDot) => true,
(&Token::DotDotDot, &Token::DotDotDot) => true,
(&Token::Comma, &Token::Comma) => true,
(&Token::Semi, &Token::Semi) => true,
(&Token::Colon, &Token::Colon) => true,
(&Token::ModSep, &Token::ModSep) => true,
(&Token::RArrow, &Token::RArrow) => true,
(&Token::LArrow, &Token::LArrow) => true,
(&Token::FatArrow, &Token::FatArrow) => true,
(&Token::Pound, &Token::Pound) => true,
(&Token::Dollar, &Token::Dollar) => true,
(&Token::Question, &Token::Question) => true,
(&Token::OpenDelim(ref __self_0),
&Token::OpenDelim(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::CloseDelim(ref __self_0),
&Token::CloseDelim(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::Literal(ref __self_0, ref __self_1),
&Token::Literal(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Token::Ident(ref __self_0, ref __self_1),
&Token::Ident(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Token::Underscore, &Token::Underscore) => true,
(&Token::Lifetime(ref __self_0),
&Token::Lifetime(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::Interpolated(ref __self_0),
&Token::Interpolated(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::DocComment(ref __self_0),
&Token::DocComment(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::MatchNt(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Token::MatchNt(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3),
(&Token::SubstNt(ref __self_0, ref __self_1),
&Token::SubstNt(ref __arg_1_0, ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Token::SpecialVarNt(ref __self_0),
&Token::SpecialVarNt(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::Whitespace, &Token::Whitespace) => true,
(&Token::Comment, &Token::Comment) => true,
(&Token::Shebang(ref __self_0),
&Token::Shebang(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Token::Eof, &Token::Eof) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Token) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Token::Eq, &Token::Eq) => false,
(&Token::Lt, &Token::Lt) => false,
(&Token::Le, &Token::Le) => false,
(&Token::EqEq, &Token::EqEq) => false,
(&Token::Ne, &Token::Ne) => false,
(&Token::Ge, &Token::Ge) => false,
(&Token::Gt, &Token::Gt) => false,
(&Token::AndAnd, &Token::AndAnd) => false,
(&Token::OrOr, &Token::OrOr) => false,
(&Token::Not, &Token::Not) => false,
(&Token::Tilde, &Token::Tilde) => false,
(&Token::BinOp(ref __self_0),
&Token::BinOp(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::BinOpEq(ref __self_0),
&Token::BinOpEq(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::At, &Token::At) => false,
(&Token::Dot, &Token::Dot) => false,
(&Token::DotDot, &Token::DotDot) => false,
(&Token::DotDotDot, &Token::DotDotDot) => false,
(&Token::Comma, &Token::Comma) => false,
(&Token::Semi, &Token::Semi) => false,
(&Token::Colon, &Token::Colon) => false,
(&Token::ModSep, &Token::ModSep) => false,
(&Token::RArrow, &Token::RArrow) => false,
(&Token::LArrow, &Token::LArrow) => false,
(&Token::FatArrow, &Token::FatArrow) => false,
(&Token::Pound, &Token::Pound) => false,
(&Token::Dollar, &Token::Dollar) => false,
(&Token::Question, &Token::Question) => false,
(&Token::OpenDelim(ref __self_0),
&Token::OpenDelim(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::CloseDelim(ref __self_0),
&Token::CloseDelim(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::Literal(ref __self_0, ref __self_1),
&Token::Literal(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Token::Ident(ref __self_0, ref __self_1),
&Token::Ident(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Token::Underscore, &Token::Underscore) => false,
(&Token::Lifetime(ref __self_0),
&Token::Lifetime(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::Interpolated(ref __self_0),
&Token::Interpolated(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::DocComment(ref __self_0),
&Token::DocComment(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::MatchNt(ref __self_0, ref __self_1,
ref __self_2, ref __self_3),
&Token::MatchNt(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3),
(&Token::SubstNt(ref __self_0, ref __self_1),
&Token::SubstNt(ref __arg_1_0, ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Token::SpecialVarNt(ref __self_0),
&Token::SpecialVarNt(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::Whitespace, &Token::Whitespace) => false,
(&Token::Comment, &Token::Comment) => false,
(&Token::Shebang(ref __self_0),
&Token::Shebang(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Token::Eof, &Token::Eof) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::rustc_serialize::Decodable for Token {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Token, __D::Error> {
__arg_0.read_enum("Token", |_d| -> _ {
_d.read_enum_variant(&["Eq", "Lt", "Le",
"EqEq", "Ne", "Ge",
"Gt", "AndAnd",
"OrOr", "Not",
"Tilde", "BinOp",
"BinOpEq", "At",
"Dot", "DotDot",
"DotDotDot", "Comma",
"Semi", "Colon",
"ModSep", "RArrow",
"LArrow", "FatArrow",
"Pound", "Dollar",
"Question",
"OpenDelim",
"CloseDelim",
"Literal", "Ident",
"Underscore",
"Lifetime",
"Interpolated",
"DocComment",
"MatchNt", "SubstNt",
"SpecialVarNt",
"Whitespace",
"Comment", "Shebang",
"Eof"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Token::Eq,
1usize
=>
Token::Lt,
2usize
=>
Token::Le,
3usize
=>
Token::EqEq,
4usize
=>
Token::Ne,
5usize
=>
Token::Ge,
6usize
=>
Token::Gt,
7usize
=>
Token::AndAnd,
8usize
=>
Token::OrOr,
9usize
=>
Token::Not,
10usize
=>
Token::Tilde,
11usize
=>
Token::BinOp(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
12usize
=>
Token::BinOpEq(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
13usize
=>
Token::At,
14usize
=>
Token::Dot,
15usize
=>
Token::DotDot,
16usize
=>
Token::DotDotDot,
17usize
=>
Token::Comma,
18usize
=>
Token::Semi,
19usize
=>
Token::Colon,
20usize
=>
Token::ModSep,
21usize
=>
Token::RArrow,
22usize
=>
Token::LArrow,
23usize
=>
Token::FatArrow,
24usize
=>
Token::Pound,
25usize
=>
Token::Dollar,
26usize
=>
Token::Question,
27usize
=>
Token::OpenDelim(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
28usize
=>
Token::CloseDelim(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
29usize
=>
Token::Literal(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
30usize
=>
Token::Ident(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
31usize
=>
Token::Underscore,
32usize
=>
Token::Lifetime(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
33usize
=>
Token::Interpolated(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
34usize
=>
Token::DocComment(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
35usize
=>
Token::MatchNt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(3usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
36usize
=>
Token::SubstNt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
37usize
=>
Token::SpecialVarNt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
38usize
=>
Token::Whitespace,
39usize
=>
Token::Comment,
40usize
=>
Token::Shebang(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
41usize
=>
Token::Eof,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
103u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::rustc_serialize::Encodable for Token {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Token::Eq,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Eq", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Lt,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Lt", 1usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Le,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Le", 2usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::EqEq,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("EqEq", 3usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Ne,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Ne", 4usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Ge,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Ge", 5usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Gt,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Gt", 6usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::AndAnd,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("AndAnd", 7usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::OrOr,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("OrOr", 8usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Not,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Not", 9usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Tilde,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Tilde", 10usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::BinOp(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("BinOp", 11usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::BinOpEq(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("BinOpEq", 12usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::At,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("At", 13usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Dot,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Dot", 14usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::DotDot,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("DotDot", 15usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::DotDotDot,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("DotDotDot",
16usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Comma,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Comma", 17usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Semi,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Semi", 18usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Colon,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Colon", 19usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::ModSep,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("ModSep", 20usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::RArrow,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("RArrow", 21usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::LArrow,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("LArrow", 22usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::FatArrow,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("FatArrow", 23usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Pound,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Pound", 24usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Dollar,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Dollar", 25usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Question,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Question", 26usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::OpenDelim(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("OpenDelim",
27usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::CloseDelim(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("CloseDelim",
28usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::Literal(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Literal", 29usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Token::Ident(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Ident", 30usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Token::Underscore,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Underscore",
31usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Lifetime(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Lifetime", 32usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::Interpolated(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Interpolated",
33usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::DocComment(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("DocComment",
34usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::MatchNt(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("MatchNt", 35usize,
4usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(3usize,
|_e|
->
_
{
(*__self_3).encode(_e)
});
}) })
}
(&Token::SubstNt(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("SubstNt", 36usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Token::SpecialVarNt(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("SpecialVarNt",
37usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::Whitespace,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Whitespace",
38usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Comment,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Comment", 39usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&Token::Shebang(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Shebang", 40usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Token::Eof,) => {
let _e = __arg_0;
_e.emit_enum("Token", |_e| -> _ {
_e.emit_enum_variant("Eof", 41usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
#[allow(non_camel_case_types)]
impl ::std::clone::Clone for Token {
#[inline]
fn clone(&self) -> Token {
match (&*self,) {
(&Token::Eq,) => Token::Eq,
(&Token::Lt,) => Token::Lt,
(&Token::Le,) => Token::Le,
(&Token::EqEq,) => Token::EqEq,
(&Token::Ne,) => Token::Ne,
(&Token::Ge,) => Token::Ge,
(&Token::Gt,) => Token::Gt,
(&Token::AndAnd,) => Token::AndAnd,
(&Token::OrOr,) => Token::OrOr,
(&Token::Not,) => Token::Not,
(&Token::Tilde,) => Token::Tilde,
(&Token::BinOp(ref __self_0),) =>
Token::BinOp(::std::clone::Clone::clone(&(*__self_0))),
(&Token::BinOpEq(ref __self_0),) =>
Token::BinOpEq(::std::clone::Clone::clone(&(*__self_0))),
(&Token::At,) => Token::At,
(&Token::Dot,) => Token::Dot,
(&Token::DotDot,) => Token::DotDot,
(&Token::DotDotDot,) => Token::DotDotDot,
(&Token::Comma,) => Token::Comma,
(&Token::Semi,) => Token::Semi,
(&Token::Colon,) => Token::Colon,
(&Token::ModSep,) => Token::ModSep,
(&Token::RArrow,) => Token::RArrow,
(&Token::LArrow,) => Token::LArrow,
(&Token::FatArrow,) => Token::FatArrow,
(&Token::Pound,) => Token::Pound,
(&Token::Dollar,) => Token::Dollar,
(&Token::Question,) => Token::Question,
(&Token::OpenDelim(ref __self_0),) =>
Token::OpenDelim(::std::clone::Clone::clone(&(*__self_0))),
(&Token::CloseDelim(ref __self_0),) =>
Token::CloseDelim(::std::clone::Clone::clone(&(*__self_0))),
(&Token::Literal(ref __self_0, ref __self_1),) =>
Token::Literal(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Token::Ident(ref __self_0, ref __self_1),) =>
Token::Ident(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Token::Underscore,) => Token::Underscore,
(&Token::Lifetime(ref __self_0),) =>
Token::Lifetime(::std::clone::Clone::clone(&(*__self_0))),
(&Token::Interpolated(ref __self_0),) =>
Token::Interpolated(::std::clone::Clone::clone(&(*__self_0))),
(&Token::DocComment(ref __self_0),) =>
Token::DocComment(::std::clone::Clone::clone(&(*__self_0))),
(&Token::MatchNt(ref __self_0, ref __self_1, ref __self_2,
ref __self_3),) =>
Token::MatchNt(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3))),
(&Token::SubstNt(ref __self_0, ref __self_1),) =>
Token::SubstNt(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Token::SpecialVarNt(ref __self_0),) =>
Token::SpecialVarNt(::std::clone::Clone::clone(&(*__self_0))),
(&Token::Whitespace,) => Token::Whitespace,
(&Token::Comment,) => Token::Comment,
(&Token::Shebang(ref __self_0),) =>
Token::Shebang(::std::clone::Clone::clone(&(*__self_0))),
(&Token::Eof,) => Token::Eof,
}
}
}
impl Token {
/// Returns `true` if the token starts with '>'.
pub fn is_like_gt(&self) -> bool {
match *self {
BinOp(Shr) | BinOpEq(Shr) | Gt | Ge => true,
_ => false,
}
}
/// Returns `true` if the token can appear at the start of an expression.
pub fn can_begin_expr(&self) -> bool {
match *self {
OpenDelim(_) => true,
Ident(_, _) => true,
Underscore => true,
Tilde => true,
Literal(_, _) => true,
Not => true,
BinOp(Minus) => true,
BinOp(Star) => true,
BinOp(And) => true,
BinOp(Or) => true,
OrOr => true,
AndAnd => true,
DotDot => true,
ModSep => true,
Interpolated(NtExpr(..)) => true,
Interpolated(NtIdent(..)) => true,
Interpolated(NtBlock(..)) => true,
Interpolated(NtPath(..)) => true,
Pound => true,
_ => false,
}
}
/// Returns `true` if the token is any literal
pub fn is_lit(&self) -> bool {
match *self { Literal(_, _) => true, _ => false, }
}
/// Returns `true` if the token is an identifier.
pub fn is_ident(&self) -> bool {
match *self { Ident(_, _) => true, _ => false, }
}
/// Returns `true` if the token is an interpolated path.
pub fn is_path(&self) -> bool {
match *self { Interpolated(NtPath(..)) => true, _ => false, }
}
/// Returns `true` if the token is a path that is not followed by a `::`
/// token.
#[allow(non_upper_case_globals)]
pub fn is_plain_ident(&self) -> bool {
match *self { Ident(_, Plain) => true, _ => false, }
}
/// Returns `true` if the token is a lifetime.
pub fn is_lifetime(&self) -> bool {
match *self { Lifetime(..) => true, _ => false, }
}
/// Returns `true` if the token is either the `mut` or `const` keyword.
pub fn is_mutability(&self) -> bool {
self.is_keyword(keywords::Mut) ||
self.is_keyword(keywords::Const)
}
/// Maps a token to its corresponding binary operator.
pub fn to_binop(&self) -> Option<ast::BinOp_> {
match *self {
BinOp(Star) => Some(ast::BiMul),
BinOp(Slash) => Some(ast::BiDiv),
BinOp(Percent) => Some(ast::BiRem),
BinOp(Plus) => Some(ast::BiAdd),
BinOp(Minus) => Some(ast::BiSub),
BinOp(Shl) => Some(ast::BiShl),
BinOp(Shr) => Some(ast::BiShr),
BinOp(And) => Some(ast::BiBitAnd),
BinOp(Caret) => Some(ast::BiBitXor),
BinOp(Or) => Some(ast::BiBitOr),
Lt => Some(ast::BiLt),
Le => Some(ast::BiLe),
Ge => Some(ast::BiGe),
Gt => Some(ast::BiGt),
EqEq => Some(ast::BiEq),
Ne => Some(ast::BiNe),
AndAnd => Some(ast::BiAnd),
OrOr => Some(ast::BiOr),
_ => None,
}
}
/// Returns `true` if the token is a given keyword, `kw`.
#[allow(non_upper_case_globals)]
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
match *self {
Ident(sid, Plain) => kw.to_name() == sid.name,
_ => false,
}
}
pub fn is_keyword_allow_following_colon(&self,
kw: keywords::Keyword)
-> bool {
match *self {
Ident(sid, _) => { kw.to_name() == sid.name }
_ => { false }
}
}
/// Returns `true` if the token is either a special identifier, or a strict
/// or reserved keyword.
#[allow(non_upper_case_globals)]
pub fn is_any_keyword(&self) -> bool {
match *self {
Ident(sid, Plain) => {
let n = sid.name;
n == SELF_KEYWORD_NAME || n == STATIC_KEYWORD_NAME ||
n == SUPER_KEYWORD_NAME ||
n == SELF_TYPE_KEYWORD_NAME ||
STRICT_KEYWORD_START <= n &&
n <= RESERVED_KEYWORD_FINAL
}
_ => false,
}
}
/// Returns `true` if the token may not appear as an identifier.
#[allow(non_upper_case_globals)]
pub fn is_strict_keyword(&self) -> bool {
match *self {
Ident(sid, Plain) => {
let n = sid.name;
n == SELF_KEYWORD_NAME || n == STATIC_KEYWORD_NAME ||
n == SUPER_KEYWORD_NAME ||
n == SELF_TYPE_KEYWORD_NAME ||
STRICT_KEYWORD_START <= n &&
n <= STRICT_KEYWORD_FINAL
}
Ident(sid, ModName) => {
let n = sid.name;
n != SELF_KEYWORD_NAME && n != SUPER_KEYWORD_NAME &&
STRICT_KEYWORD_START <= n &&
n <= STRICT_KEYWORD_FINAL
}
_ => false,
}
}
/// Returns `true` if the token is a keyword that has been reserved for
/// possible future use.
#[allow(non_upper_case_globals)]
pub fn is_reserved_keyword(&self) -> bool {
match *self {
Ident(sid, Plain) => {
let n = sid.name;
RESERVED_KEYWORD_START <= n &&
n <= RESERVED_KEYWORD_FINAL
}
_ => false,
}
}
/// Hygienic identifier equality comparison.
///
/// See `styntax::ext::mtwt`.
pub fn mtwt_eq(&self, other: &Token) -> bool {
match (self, other) {
(&Ident(id1, _), &Ident(id2, _)) |
(&Lifetime(id1), &Lifetime(id2)) =>
mtwt::resolve(id1) == mtwt::resolve(id2),
_ => *self == *other,
}
}
}
/// For interpolation during macro expansion.
pub enum Nonterminal {
NtItem(P<ast::Item>),
NtBlock(P<ast::Block>),
NtStmt(P<ast::Stmt>),
NtPat(P<ast::Pat>),
NtExpr(P<ast::Expr>),
NtTy(P<ast::Ty>),
NtIdent(Box<ast::SpannedIdent>, IdentStyle),
/// Stuff inside brackets for attributes
NtMeta(P<ast::MetaItem>),
NtPath(Box<ast::Path>),
NtTT(P<ast::TokenTree>),
NtArm(ast::Arm),
NtImplItem(P<ast::ImplItem>),
NtTraitItem(P<ast::TraitItem>),
NtGenerics(ast::Generics),
NtWhereClause(ast::WhereClause),
NtArg(ast::Arg),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for Nonterminal {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&Nonterminal::NtItem(ref __self_0),) => {
::std::hash::Hash::hash(&0usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtBlock(ref __self_0),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtStmt(ref __self_0),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtPat(ref __self_0),) => {
::std::hash::Hash::hash(&3usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtExpr(ref __self_0),) => {
::std::hash::Hash::hash(&4usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtTy(ref __self_0),) => {
::std::hash::Hash::hash(&5usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtIdent(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&6usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&Nonterminal::NtMeta(ref __self_0),) => {
::std::hash::Hash::hash(&7usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtPath(ref __self_0),) => {
::std::hash::Hash::hash(&8usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtTT(ref __self_0),) => {
::std::hash::Hash::hash(&9usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtArm(ref __self_0),) => {
::std::hash::Hash::hash(&10usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtImplItem(ref __self_0),) => {
::std::hash::Hash::hash(&11usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtTraitItem(ref __self_0),) => {
::std::hash::Hash::hash(&12usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtGenerics(ref __self_0),) => {
::std::hash::Hash::hash(&13usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtWhereClause(ref __self_0),) => {
::std::hash::Hash::hash(&14usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
(&Nonterminal::NtArg(ref __self_0),) => {
::std::hash::Hash::hash(&15usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Nonterminal {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Nonterminal::NtItem(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtBlock(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtStmt(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtPat(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtExpr(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtTy(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtIdent(ref __self_0, ref __self_1),) => {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
}
(&Nonterminal::NtMeta(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtPath(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtTT(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtArm(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtImplItem(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtTraitItem(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtGenerics(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtWhereClause(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
(&Nonterminal::NtArg(ref __self_0),) => {
(*__self_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Nonterminal {
#[inline]
fn eq(&self, __arg_0: &Nonterminal) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Nonterminal::NtItem(ref __self_0),
&Nonterminal::NtItem(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtBlock(ref __self_0),
&Nonterminal::NtBlock(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtStmt(ref __self_0),
&Nonterminal::NtStmt(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtPat(ref __self_0),
&Nonterminal::NtPat(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtExpr(ref __self_0),
&Nonterminal::NtExpr(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtTy(ref __self_0),
&Nonterminal::NtTy(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtIdent(ref __self_0,
ref __self_1),
&Nonterminal::NtIdent(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&Nonterminal::NtMeta(ref __self_0),
&Nonterminal::NtMeta(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtPath(ref __self_0),
&Nonterminal::NtPath(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtTT(ref __self_0),
&Nonterminal::NtTT(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtArm(ref __self_0),
&Nonterminal::NtArm(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtImplItem(ref __self_0),
&Nonterminal::NtImplItem(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtTraitItem(ref __self_0),
&Nonterminal::NtTraitItem(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtGenerics(ref __self_0),
&Nonterminal::NtGenerics(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtWhereClause(ref __self_0),
&Nonterminal::NtWhereClause(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
(&Nonterminal::NtArg(ref __self_0),
&Nonterminal::NtArg(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Nonterminal) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Nonterminal::NtItem(ref __self_0),
&Nonterminal::NtItem(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtBlock(ref __self_0),
&Nonterminal::NtBlock(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtStmt(ref __self_0),
&Nonterminal::NtStmt(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtPat(ref __self_0),
&Nonterminal::NtPat(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtExpr(ref __self_0),
&Nonterminal::NtExpr(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtTy(ref __self_0),
&Nonterminal::NtTy(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtIdent(ref __self_0,
ref __self_1),
&Nonterminal::NtIdent(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&Nonterminal::NtMeta(ref __self_0),
&Nonterminal::NtMeta(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtPath(ref __self_0),
&Nonterminal::NtPath(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtTT(ref __self_0),
&Nonterminal::NtTT(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtArm(ref __self_0),
&Nonterminal::NtArm(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtImplItem(ref __self_0),
&Nonterminal::NtImplItem(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtTraitItem(ref __self_0),
&Nonterminal::NtTraitItem(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtGenerics(ref __self_0),
&Nonterminal::NtGenerics(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtWhereClause(ref __self_0),
&Nonterminal::NtWhereClause(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
(&Nonterminal::NtArg(ref __self_0),
&Nonterminal::NtArg(ref __arg_1_0)) =>
false || (*__self_0) != (*__arg_1_0),
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Nonterminal {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<Nonterminal, __D::Error> {
__arg_0.read_enum("Nonterminal", |_d| -> _ {
_d.read_enum_variant(&["NtItem", "NtBlock",
"NtStmt", "NtPat",
"NtExpr", "NtTy",
"NtIdent", "NtMeta",
"NtPath", "NtTT",
"NtArm",
"NtImplItem",
"NtTraitItem",
"NtGenerics",
"NtWhereClause",
"NtArg"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
Nonterminal::NtItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
1usize
=>
Nonterminal::NtBlock(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
Nonterminal::NtStmt(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
Nonterminal::NtPat(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
4usize
=>
Nonterminal::NtExpr(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
5usize
=>
Nonterminal::NtTy(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
6usize
=>
Nonterminal::NtIdent(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
7usize
=>
Nonterminal::NtMeta(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
8usize
=>
Nonterminal::NtPath(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
9usize
=>
Nonterminal::NtTT(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
10usize
=>
Nonterminal::NtArm(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
11usize
=>
Nonterminal::NtImplItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
12usize
=>
Nonterminal::NtTraitItem(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
13usize
=>
Nonterminal::NtGenerics(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
14usize
=>
Nonterminal::NtWhereClause(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
15usize
=>
Nonterminal::NtArg(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/parse/token.rs",
371u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Nonterminal {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&Nonterminal::NtItem(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtItem", 0usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtBlock(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtBlock", 1usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtStmt(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtStmt", 2usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtPat(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtPat", 3usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtExpr(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtExpr", 4usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtTy(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtTy", 5usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtIdent(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtIdent", 6usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&Nonterminal::NtMeta(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtMeta", 7usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtPath(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtPath", 8usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtTT(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtTT", 9usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtArm(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtArm", 10usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtImplItem(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtImplItem",
11usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtTraitItem(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtTraitItem",
12usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtGenerics(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtGenerics",
13usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtWhereClause(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtWhereClause",
14usize, 1usize,
|_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
(&Nonterminal::NtArg(ref __self_0),) => {
let _e = __arg_0;
_e.emit_enum("Nonterminal", |_e| -> _ {
_e.emit_enum_variant("NtArg", 15usize,
1usize, |_e| -> _ {
return _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
});
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Nonterminal {
#[inline]
fn clone(&self) -> Nonterminal {
match (&*self,) {
(&Nonterminal::NtItem(ref __self_0),) =>
Nonterminal::NtItem(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtBlock(ref __self_0),) =>
Nonterminal::NtBlock(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtStmt(ref __self_0),) =>
Nonterminal::NtStmt(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtPat(ref __self_0),) =>
Nonterminal::NtPat(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtExpr(ref __self_0),) =>
Nonterminal::NtExpr(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtTy(ref __self_0),) =>
Nonterminal::NtTy(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtIdent(ref __self_0, ref __self_1),) =>
Nonterminal::NtIdent(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Nonterminal::NtMeta(ref __self_0),) =>
Nonterminal::NtMeta(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtPath(ref __self_0),) =>
Nonterminal::NtPath(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtTT(ref __self_0),) =>
Nonterminal::NtTT(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtArm(ref __self_0),) =>
Nonterminal::NtArm(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtImplItem(ref __self_0),) =>
Nonterminal::NtImplItem(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtTraitItem(ref __self_0),) =>
Nonterminal::NtTraitItem(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtGenerics(ref __self_0),) =>
Nonterminal::NtGenerics(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtWhereClause(ref __self_0),) =>
Nonterminal::NtWhereClause(::std::clone::Clone::clone(&(*__self_0))),
(&Nonterminal::NtArg(ref __self_0),) =>
Nonterminal::NtArg(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl fmt::Debug for Nonterminal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
NtItem(..) => f.pad("NtItem(..)"),
NtBlock(..) => f.pad("NtBlock(..)"),
NtStmt(..) => f.pad("NtStmt(..)"),
NtPat(..) => f.pad("NtPat(..)"),
NtExpr(..) => f.pad("NtExpr(..)"),
NtTy(..) => f.pad("NtTy(..)"),
NtIdent(..) => f.pad("NtIdent(..)"),
NtMeta(..) => f.pad("NtMeta(..)"),
NtPath(..) => f.pad("NtPath(..)"),
NtTT(..) => f.pad("NtTT(..)"),
NtArm(..) => f.pad("NtArm(..)"),
NtImplItem(..) => f.pad("NtImplItem(..)"),
NtTraitItem(..) => f.pad("NtTraitItem(..)"),
NtGenerics(..) => f.pad("NtGenerics(..)"),
NtWhereClause(..) => f.pad("NtWhereClause(..)"),
NtArg(..) => f.pad("NtArg(..)"),
}
}
}
pub const SELF_KEYWORD_NAME: ast::Name =
ast::Name(SELF_KEYWORD_NAME_NUM);
const STATIC_KEYWORD_NAME: ast::Name =
ast::Name(STATIC_KEYWORD_NAME_NUM);
const SUPER_KEYWORD_NAME: ast::Name =
ast::Name(SUPER_KEYWORD_NAME_NUM);
const SELF_TYPE_KEYWORD_NAME: ast::Name =
ast::Name(SELF_TYPE_KEYWORD_NAME_NUM);
pub const SELF_KEYWORD_NAME_NUM: u32 = 1;
const STATIC_KEYWORD_NAME_NUM: u32 = 2;
const SUPER_KEYWORD_NAME_NUM: u32 = 3;
const SELF_TYPE_KEYWORD_NAME_NUM: u32 = 10;
const STRICT_KEYWORD_START: ast::Name = ast::Name(12);
const STRICT_KEYWORD_FINAL: ast::Name = ast::Name(43);
const RESERVED_KEYWORD_START: ast::Name = ast::Name(44);
const RESERVED_KEYWORD_FINAL: ast::Name = ast::Name(59);
pub mod special_idents {
#[prelude_import]
use std::prelude::v1::*;
use ast;
#[allow(non_upper_case_globals)]
pub const invalid: ast::Ident =
ast::Ident{name: ast::Name(0), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const self_: ast::Ident =
ast::Ident{name: ast::Name(super::SELF_KEYWORD_NAME_NUM),
ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const statik: ast::Ident =
ast::Ident{name: ast::Name(super::STATIC_KEYWORD_NAME_NUM),
ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const super_: ast::Ident =
ast::Ident{name: ast::Name(super::SUPER_KEYWORD_NAME_NUM),
ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const static_lifetime: ast::Ident =
ast::Ident{name: ast::Name(4), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const tt: ast::Ident =
ast::Ident{name: ast::Name(5), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const matchers: ast::Ident =
ast::Ident{name: ast::Name(6), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const clownshoe_abi: ast::Ident =
ast::Ident{name: ast::Name(7), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const opaque: ast::Ident =
ast::Ident{name: ast::Name(8), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const unnamed_field: ast::Ident =
ast::Ident{name: ast::Name(9), ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const type_self: ast::Ident =
ast::Ident{name: ast::Name(super::SELF_TYPE_KEYWORD_NAME_NUM),
ctxt: ast::EMPTY_CTXT,};
#[allow(non_upper_case_globals)]
pub const prelude_import: ast::Ident =
ast::Ident{name: ast::Name(11), ctxt: ast::EMPTY_CTXT,};
}
pub mod special_names {
#[prelude_import]
use std::prelude::v1::*;
use ast;
#[allow(non_upper_case_globals)]
pub const invalid: ast::Name = ast::Name(0);
#[allow(non_upper_case_globals)]
pub const self_: ast::Name =
ast::Name(super::SELF_KEYWORD_NAME_NUM);
#[allow(non_upper_case_globals)]
pub const statik: ast::Name =
ast::Name(super::STATIC_KEYWORD_NAME_NUM);
#[allow(non_upper_case_globals)]
pub const super_: ast::Name =
ast::Name(super::SUPER_KEYWORD_NAME_NUM);
#[allow(non_upper_case_globals)]
pub const static_lifetime: ast::Name = ast::Name(4);
#[allow(non_upper_case_globals)]
pub const tt: ast::Name = ast::Name(5);
#[allow(non_upper_case_globals)]
pub const matchers: ast::Name = ast::Name(6);
#[allow(non_upper_case_globals)]
pub const clownshoe_abi: ast::Name = ast::Name(7);
#[allow(non_upper_case_globals)]
pub const opaque: ast::Name = ast::Name(8);
#[allow(non_upper_case_globals)]
pub const unnamed_field: ast::Name = ast::Name(9);
#[allow(non_upper_case_globals)]
pub const type_self: ast::Name =
ast::Name(super::SELF_TYPE_KEYWORD_NAME_NUM);
#[allow(non_upper_case_globals)]
pub const prelude_import: ast::Name = ast::Name(11);
}
/// All the valid words that have meaning in the Rust language.
///
/// Rust keywords are either 'strict' or 'reserved'. Strict keywords may not
/// appear as identifiers at all. Reserved keywords are not used anywhere in
/// the language and may not appear as identifiers.
pub mod keywords {
#[prelude_import]
use std::prelude::v1::*;
pub use self::Keyword::*;
use ast;
pub enum Keyword {
As,
Break,
Crate,
Else,
Enum,
Extern,
False,
Fn,
For,
If,
Impl,
In,
Let,
Loop,
Match,
Mod,
Move,
Mut,
Pub,
Ref,
Return,
Static,
SelfValue,
SelfType,
Struct,
Super,
True,
Trait,
Type,
Unsafe,
Use,
While,
Continue,
Box,
Const,
Where,
Virtual,
Proc,
Alignof,
Become,
Offsetof,
Priv,
Pure,
Sizeof,
Typeof,
Unsized,
Yield,
Do,
Abstract,
Final,
Override,
Macro,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for Keyword {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&Keyword::As,) => { }
(&Keyword::Break,) => { }
(&Keyword::Crate,) => { }
(&Keyword::Else,) => { }
(&Keyword::Enum,) => { }
(&Keyword::Extern,) => { }
(&Keyword::False,) => { }
(&Keyword::Fn,) => { }
(&Keyword::For,) => { }
(&Keyword::If,) => { }
(&Keyword::Impl,) => { }
(&Keyword::In,) => { }
(&Keyword::Let,) => { }
(&Keyword::Loop,) => { }
(&Keyword::Match,) => { }
(&Keyword::Mod,) => { }
(&Keyword::Move,) => { }
(&Keyword::Mut,) => { }
(&Keyword::Pub,) => { }
(&Keyword::Ref,) => { }
(&Keyword::Return,) => { }
(&Keyword::Static,) => { }
(&Keyword::SelfValue,) => { }
(&Keyword::SelfType,) => { }
(&Keyword::Struct,) => { }
(&Keyword::Super,) => { }
(&Keyword::True,) => { }
(&Keyword::Trait,) => { }
(&Keyword::Type,) => { }
(&Keyword::Unsafe,) => { }
(&Keyword::Use,) => { }
(&Keyword::While,) => { }
(&Keyword::Continue,) => { }
(&Keyword::Box,) => { }
(&Keyword::Const,) => { }
(&Keyword::Where,) => { }
(&Keyword::Virtual,) => { }
(&Keyword::Proc,) => { }
(&Keyword::Alignof,) => { }
(&Keyword::Become,) => { }
(&Keyword::Offsetof,) => { }
(&Keyword::Priv,) => { }
(&Keyword::Pure,) => { }
(&Keyword::Sizeof,) => { }
(&Keyword::Typeof,) => { }
(&Keyword::Unsized,) => { }
(&Keyword::Yield,) => { }
(&Keyword::Do,) => { }
(&Keyword::Abstract,) => { }
(&Keyword::Final,) => { }
(&Keyword::Override,) => { }
(&Keyword::Macro,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Keyword {
#[inline]
fn eq(&self, __arg_0: &Keyword) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Keyword::As, &Keyword::As) => true,
(&Keyword::Break, &Keyword::Break) => true,
(&Keyword::Crate, &Keyword::Crate) => true,
(&Keyword::Else, &Keyword::Else) => true,
(&Keyword::Enum, &Keyword::Enum) => true,
(&Keyword::Extern, &Keyword::Extern) => true,
(&Keyword::False, &Keyword::False) => true,
(&Keyword::Fn, &Keyword::Fn) => true,
(&Keyword::For, &Keyword::For) => true,
(&Keyword::If, &Keyword::If) => true,
(&Keyword::Impl, &Keyword::Impl) => true,
(&Keyword::In, &Keyword::In) => true,
(&Keyword::Let, &Keyword::Let) => true,
(&Keyword::Loop, &Keyword::Loop) => true,
(&Keyword::Match, &Keyword::Match) => true,
(&Keyword::Mod, &Keyword::Mod) => true,
(&Keyword::Move, &Keyword::Move) => true,
(&Keyword::Mut, &Keyword::Mut) => true,
(&Keyword::Pub, &Keyword::Pub) => true,
(&Keyword::Ref, &Keyword::Ref) => true,
(&Keyword::Return, &Keyword::Return) => true,
(&Keyword::Static, &Keyword::Static) => true,
(&Keyword::SelfValue, &Keyword::SelfValue) =>
true,
(&Keyword::SelfType, &Keyword::SelfType) =>
true,
(&Keyword::Struct, &Keyword::Struct) => true,
(&Keyword::Super, &Keyword::Super) => true,
(&Keyword::True, &Keyword::True) => true,
(&Keyword::Trait, &Keyword::Trait) => true,
(&Keyword::Type, &Keyword::Type) => true,
(&Keyword::Unsafe, &Keyword::Unsafe) => true,
(&Keyword::Use, &Keyword::Use) => true,
(&Keyword::While, &Keyword::While) => true,
(&Keyword::Continue, &Keyword::Continue) =>
true,
(&Keyword::Box, &Keyword::Box) => true,
(&Keyword::Const, &Keyword::Const) => true,
(&Keyword::Where, &Keyword::Where) => true,
(&Keyword::Virtual, &Keyword::Virtual) =>
true,
(&Keyword::Proc, &Keyword::Proc) => true,
(&Keyword::Alignof, &Keyword::Alignof) =>
true,
(&Keyword::Become, &Keyword::Become) => true,
(&Keyword::Offsetof, &Keyword::Offsetof) =>
true,
(&Keyword::Priv, &Keyword::Priv) => true,
(&Keyword::Pure, &Keyword::Pure) => true,
(&Keyword::Sizeof, &Keyword::Sizeof) => true,
(&Keyword::Typeof, &Keyword::Typeof) => true,
(&Keyword::Unsized, &Keyword::Unsized) =>
true,
(&Keyword::Yield, &Keyword::Yield) => true,
(&Keyword::Do, &Keyword::Do) => true,
(&Keyword::Abstract, &Keyword::Abstract) =>
true,
(&Keyword::Final, &Keyword::Final) => true,
(&Keyword::Override, &Keyword::Override) =>
true,
(&Keyword::Macro, &Keyword::Macro) => true,
_ => unsafe {
::std::intrinsics::unreachable()
}
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Keyword) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Keyword::As, &Keyword::As) => false,
(&Keyword::Break, &Keyword::Break) => false,
(&Keyword::Crate, &Keyword::Crate) => false,
(&Keyword::Else, &Keyword::Else) => false,
(&Keyword::Enum, &Keyword::Enum) => false,
(&Keyword::Extern, &Keyword::Extern) => false,
(&Keyword::False, &Keyword::False) => false,
(&Keyword::Fn, &Keyword::Fn) => false,
(&Keyword::For, &Keyword::For) => false,
(&Keyword::If, &Keyword::If) => false,
(&Keyword::Impl, &Keyword::Impl) => false,
(&Keyword::In, &Keyword::In) => false,
(&Keyword::Let, &Keyword::Let) => false,
(&Keyword::Loop, &Keyword::Loop) => false,
(&Keyword::Match, &Keyword::Match) => false,
(&Keyword::Mod, &Keyword::Mod) => false,
(&Keyword::Move, &Keyword::Move) => false,
(&Keyword::Mut, &Keyword::Mut) => false,
(&Keyword::Pub, &Keyword::Pub) => false,
(&Keyword::Ref, &Keyword::Ref) => false,
(&Keyword::Return, &Keyword::Return) => false,
(&Keyword::Static, &Keyword::Static) => false,
(&Keyword::SelfValue, &Keyword::SelfValue) =>
false,
(&Keyword::SelfType, &Keyword::SelfType) =>
false,
(&Keyword::Struct, &Keyword::Struct) => false,
(&Keyword::Super, &Keyword::Super) => false,
(&Keyword::True, &Keyword::True) => false,
(&Keyword::Trait, &Keyword::Trait) => false,
(&Keyword::Type, &Keyword::Type) => false,
(&Keyword::Unsafe, &Keyword::Unsafe) => false,
(&Keyword::Use, &Keyword::Use) => false,
(&Keyword::While, &Keyword::While) => false,
(&Keyword::Continue, &Keyword::Continue) =>
false,
(&Keyword::Box, &Keyword::Box) => false,
(&Keyword::Const, &Keyword::Const) => false,
(&Keyword::Where, &Keyword::Where) => false,
(&Keyword::Virtual, &Keyword::Virtual) =>
false,
(&Keyword::Proc, &Keyword::Proc) => false,
(&Keyword::Alignof, &Keyword::Alignof) =>
false,
(&Keyword::Become, &Keyword::Become) => false,
(&Keyword::Offsetof, &Keyword::Offsetof) =>
false,
(&Keyword::Priv, &Keyword::Priv) => false,
(&Keyword::Pure, &Keyword::Pure) => false,
(&Keyword::Sizeof, &Keyword::Sizeof) => false,
(&Keyword::Typeof, &Keyword::Typeof) => false,
(&Keyword::Unsized, &Keyword::Unsized) =>
false,
(&Keyword::Yield, &Keyword::Yield) => false,
(&Keyword::Do, &Keyword::Do) => false,
(&Keyword::Abstract, &Keyword::Abstract) =>
false,
(&Keyword::Final, &Keyword::Final) => false,
(&Keyword::Override, &Keyword::Override) =>
false,
(&Keyword::Macro, &Keyword::Macro) => false,
_ => unsafe {
::std::intrinsics::unreachable()
}
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Keyword {
#[inline]
fn clone(&self) -> Keyword {
match (&*self,) {
(&Keyword::As,) => Keyword::As,
(&Keyword::Break,) => Keyword::Break,
(&Keyword::Crate,) => Keyword::Crate,
(&Keyword::Else,) => Keyword::Else,
(&Keyword::Enum,) => Keyword::Enum,
(&Keyword::Extern,) => Keyword::Extern,
(&Keyword::False,) => Keyword::False,
(&Keyword::Fn,) => Keyword::Fn,
(&Keyword::For,) => Keyword::For,
(&Keyword::If,) => Keyword::If,
(&Keyword::Impl,) => Keyword::Impl,
(&Keyword::In,) => Keyword::In,
(&Keyword::Let,) => Keyword::Let,
(&Keyword::Loop,) => Keyword::Loop,
(&Keyword::Match,) => Keyword::Match,
(&Keyword::Mod,) => Keyword::Mod,
(&Keyword::Move,) => Keyword::Move,
(&Keyword::Mut,) => Keyword::Mut,
(&Keyword::Pub,) => Keyword::Pub,
(&Keyword::Ref,) => Keyword::Ref,
(&Keyword::Return,) => Keyword::Return,
(&Keyword::Static,) => Keyword::Static,
(&Keyword::SelfValue,) => Keyword::SelfValue,
(&Keyword::SelfType,) => Keyword::SelfType,
(&Keyword::Struct,) => Keyword::Struct,
(&Keyword::Super,) => Keyword::Super,
(&Keyword::True,) => Keyword::True,
(&Keyword::Trait,) => Keyword::Trait,
(&Keyword::Type,) => Keyword::Type,
(&Keyword::Unsafe,) => Keyword::Unsafe,
(&Keyword::Use,) => Keyword::Use,
(&Keyword::While,) => Keyword::While,
(&Keyword::Continue,) => Keyword::Continue,
(&Keyword::Box,) => Keyword::Box,
(&Keyword::Const,) => Keyword::Const,
(&Keyword::Where,) => Keyword::Where,
(&Keyword::Virtual,) => Keyword::Virtual,
(&Keyword::Proc,) => Keyword::Proc,
(&Keyword::Alignof,) => Keyword::Alignof,
(&Keyword::Become,) => Keyword::Become,
(&Keyword::Offsetof,) => Keyword::Offsetof,
(&Keyword::Priv,) => Keyword::Priv,
(&Keyword::Pure,) => Keyword::Pure,
(&Keyword::Sizeof,) => Keyword::Sizeof,
(&Keyword::Typeof,) => Keyword::Typeof,
(&Keyword::Unsized,) => Keyword::Unsized,
(&Keyword::Yield,) => Keyword::Yield,
(&Keyword::Do,) => Keyword::Do,
(&Keyword::Abstract,) => Keyword::Abstract,
(&Keyword::Final,) => Keyword::Final,
(&Keyword::Override,) => Keyword::Override,
(&Keyword::Macro,) => Keyword::Macro,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Keyword { }
impl Keyword {
pub fn to_name(&self) -> ast::Name {
match *self {
As => ast::Name(12),
Break => ast::Name(13),
Crate => ast::Name(14),
Else => ast::Name(15),
Enum => ast::Name(16),
Extern => ast::Name(17),
False => ast::Name(18),
Fn => ast::Name(19),
For => ast::Name(20),
If => ast::Name(21),
Impl => ast::Name(22),
In => ast::Name(23),
Let => ast::Name(24),
Loop => ast::Name(25),
Match => ast::Name(26),
Mod => ast::Name(27),
Move => ast::Name(28),
Mut => ast::Name(29),
Pub => ast::Name(30),
Ref => ast::Name(31),
Return => ast::Name(32),
Static => ast::Name(super::STATIC_KEYWORD_NAME_NUM),
SelfValue => ast::Name(super::SELF_KEYWORD_NAME_NUM),
SelfType =>
ast::Name(super::SELF_TYPE_KEYWORD_NAME_NUM),
Struct => ast::Name(33),
Super => ast::Name(super::SUPER_KEYWORD_NAME_NUM),
True => ast::Name(34),
Trait => ast::Name(35),
Type => ast::Name(36),
Unsafe => ast::Name(37),
Use => ast::Name(38),
While => ast::Name(39),
Continue => ast::Name(40),
Box => ast::Name(41),
Const => ast::Name(42),
Where => ast::Name(43),
Virtual => ast::Name(44),
Proc => ast::Name(45),
Alignof => ast::Name(46),
Become => ast::Name(47),
Offsetof => ast::Name(48),
Priv => ast::Name(49),
Pure => ast::Name(50),
Sizeof => ast::Name(51),
Typeof => ast::Name(52),
Unsized => ast::Name(53),
Yield => ast::Name(54),
Do => ast::Name(55),
Abstract => ast::Name(56),
Final => ast::Name(57),
Override => ast::Name(58),
Macro => ast::Name(59),
}
}
}
}
fn mk_fresh_ident_interner() -> IdentInterner {
let mut init_vec = Vec::new();
init_vec.push("");
init_vec.push("self");
init_vec.push("static");
init_vec.push("super");
init_vec.push("\'static");
init_vec.push("tt");
init_vec.push("matchers");
init_vec.push("__rust_abi");
init_vec.push("<opaque>");
init_vec.push("<unnamed_field>");
init_vec.push("Self");
init_vec.push("prelude_import");
init_vec.push("as");
init_vec.push("break");
init_vec.push("crate");
init_vec.push("else");
init_vec.push("enum");
init_vec.push("extern");
init_vec.push("false");
init_vec.push("fn");
init_vec.push("for");
init_vec.push("if");
init_vec.push("impl");
init_vec.push("in");
init_vec.push("let");
init_vec.push("loop");
init_vec.push("match");
init_vec.push("mod");
init_vec.push("move");
init_vec.push("mut");
init_vec.push("pub");
init_vec.push("ref");
init_vec.push("return");
init_vec.push("static");
init_vec.push("self");
init_vec.push("Self");
init_vec.push("struct");
init_vec.push("super");
init_vec.push("true");
init_vec.push("trait");
init_vec.push("type");
init_vec.push("unsafe");
init_vec.push("use");
init_vec.push("while");
init_vec.push("continue");
init_vec.push("box");
init_vec.push("const");
init_vec.push("where");
init_vec.push("virtual");
init_vec.push("proc");
init_vec.push("alignof");
init_vec.push("become");
init_vec.push("offsetof");
init_vec.push("priv");
init_vec.push("pure");
init_vec.push("sizeof");
init_vec.push("typeof");
init_vec.push("unsized");
init_vec.push("yield");
init_vec.push("do");
init_vec.push("abstract");
init_vec.push("final");
init_vec.push("override");
init_vec.push("macro");
interner::StrInterner::prefill(&init_vec[..])
}
pub type IdentInterner = StrInterner;
pub fn get_ident_interner() -> Rc<IdentInterner> {
static KEY:
::std::thread::LocalKey<Rc<::parse::token::IdentInterner>>
=
{
fn __init() -> Rc<::parse::token::IdentInterner> {
{ Rc::new(mk_fresh_ident_interner()) }
}
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<Rc<::parse::token::IdentInterner>>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY:
::std::thread::__ElfLocalKeyInner<Rc<::parse::token::IdentInterner>>
=
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
KEY.with(|k| k.clone())
}
/// Reset the ident interner to its initial state.
pub fn reset_ident_interner() {
let interner = get_ident_interner();
interner.reset(mk_fresh_ident_interner());
}
/// Represents a string stored in the thread-local interner. Because the
/// interner lives for the life of the thread, this can be safely treated as an
/// immortal string, as long as it never crosses between threads.
///
/// FIXME(pcwalton): You must be careful about what you do in the destructors
/// of objects stored in TLS, because they may run after the interner is
/// destroyed. In particular, they must not access string contents. This can
/// be fixed in the future by just leaking all strings until thread death
/// somehow.
pub struct InternedString {
string: RcStr,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Ord for InternedString {
#[inline]
fn cmp(&self, __arg_0: &InternedString) -> ::std::cmp::Ordering {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } => {
let __test =
::std::cmp::Ord::cmp(&(*__self_0_0),
&(*__self_1_0));
if __test == ::std::cmp::Ordering::Equal {
::std::cmp::Ordering::Equal
} else { __test }
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for InternedString {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
InternedString { string: ref __self_0_0 } => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialOrd for InternedString {
#[inline]
fn partial_cmp(&self, __arg_0: &InternedString)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &InternedString) -> bool {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &InternedString) -> bool {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &InternedString) -> bool {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &InternedString) -> bool {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for InternedString {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match *self {
InternedString { string: ref __self_0_0 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for InternedString {
#[inline]
fn eq(&self, __arg_0: &InternedString) -> bool {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &InternedString) -> bool {
match *__arg_0 {
InternedString { string: ref __self_1_0 } =>
match *self {
InternedString { string: ref __self_0_0 } =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for InternedString {
#[inline]
fn clone(&self) -> InternedString {
match *self {
InternedString { string: ref __self_0_0 } =>
InternedString{string:
::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
impl InternedString {
#[inline]
pub fn new(string: &'static str) -> InternedString {
InternedString{string: RcStr::new(string),}
}
#[inline]
fn new_from_rc_str(string: RcStr) -> InternedString {
InternedString{string: string,}
}
#[inline]
pub fn new_from_name(name: ast::Name) -> InternedString {
let interner = get_ident_interner();
InternedString::new_from_rc_str(interner.get(name))
}
}
impl Deref for InternedString {
type
Target
=
str;
fn deref(&self) -> &str { &*self.string }
}
impl fmt::Debug for InternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.string, f)
}
}
impl fmt::Display for InternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.string, f)
}
}
impl <'a> PartialEq<&'a str> for InternedString {
#[inline(always)]
fn eq(&self, other: &&'a str) -> bool {
PartialEq::eq(&self.string[..], *other)
}
#[inline(always)]
fn ne(&self, other: &&'a str) -> bool {
PartialEq::ne(&self.string[..], *other)
}
}
impl <'a> PartialEq<InternedString> for &'a str {
#[inline(always)]
fn eq(&self, other: &InternedString) -> bool {
PartialEq::eq(*self, &other.string[..])
}
#[inline(always)]
fn ne(&self, other: &InternedString) -> bool {
PartialEq::ne(*self, &other.string[..])
}
}
impl Decodable for InternedString {
fn decode<D: Decoder>(d: &mut D)
-> Result<InternedString, D::Error> {
Ok(intern(match d.read_str() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}.as_ref()).as_str())
}
}
impl Encodable for InternedString {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_str(&self.string)
}
}
/// Interns and returns the string contents of an identifier, using the
/// thread-local interner.
#[inline]
pub fn intern_and_get_ident(s: &str) -> InternedString {
intern(s).as_str()
}
/// Maps a string to its interned representation.
#[inline]
pub fn intern(s: &str) -> ast::Name { get_ident_interner().intern(s) }
/// gensym's a new usize, using the current interner.
#[inline]
pub fn gensym(s: &str) -> ast::Name { get_ident_interner().gensym(s) }
/// Maps a string to an identifier with an empty syntax context.
#[inline]
pub fn str_to_ident(s: &str) -> ast::Ident {
ast::Ident::with_empty_ctxt(intern(s))
}
/// Maps a string to a gensym'ed identifier.
#[inline]
pub fn gensym_ident(s: &str) -> ast::Ident {
ast::Ident::with_empty_ctxt(gensym(s))
}
pub fn fresh_name(src: ast::Ident) -> ast::Name {
let interner = get_ident_interner();
interner.gensym_copy(src.name)
}
pub fn fresh_mark() -> ast::Mrk { gensym("mark").0 }
}
pub mod attr {
#[prelude_import]
use std::prelude::v1::*;
use attr;
use ast;
use codemap::{spanned, Spanned, mk_sp, Span};
use parse::common::*;
use parse::PResult;
use parse::token;
use parse::parser::{Parser, TokenType};
use ptr::P;
impl <'a> Parser<'a> {
/// Parse attributes that appear before an item
pub fn parse_outer_attributes(&mut self)
-> PResult<'a, Vec<ast::Attribute>> {
let mut attrs: Vec<ast::Attribute> = Vec::new();
loop {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 25u32,
__file: "src/parse/attr.rs",
__module_path:
"syntex_syntax::parse::attr",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::attr",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_outer_attributes: self.token="];
__STATIC_FMTSTR
},
&match (&self.token,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
match self.token {
token::Pound => {
attrs.push(match self.parse_attribute(false) {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) =>
{
return ::std::result::Result::Err(::std::convert::From::from(err))
}
});
}
token::DocComment(s) => {
let attr =
::attr::mk_sugared_doc_attr(attr::mk_attr_id(),
self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)),
self.span.lo,
self.span.hi);
if attr.node.style != ast::AttrStyle::Outer {
return Err(self.fatal("expected outer comment"));
}
attrs.push(attr);
self.bump();
}
_ => break ,
}
}
return Ok(attrs);
}
/// Matches `attribute = # ! [ meta_item ]`
///
/// If permit_inner is true, then a leading `!` indicates an inner
/// attribute
pub fn parse_attribute(&mut self, permit_inner: bool)
-> PResult<'a, ast::Attribute> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 55u32,
__file: "src/parse/attr.rs",
__module_path:
"syntex_syntax::parse::attr",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse::attr", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_attributes: permit_inner=",
" self.token="];
__STATIC_FMTSTR
},
&match (&permit_inner,
&self.token)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
let (span, value, mut style) =
match self.token {
token::Pound => {
let lo = self.span.lo;
self.bump();
if permit_inner {
self.expected_tokens.push(TokenType::Token(token::Not));
}
let style =
if self.token == token::Not {
self.bump();
if !permit_inner {
let span = self.span;
self.diagnostic().struct_span_err(span,
"an inner attribute is not permitted in this context").fileline_help(span,
"place inner attribute at the top of the module or block").emit()
}
ast::AttrStyle::Inner
} else { ast::AttrStyle::Outer };
match self.expect(&token::OpenDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let meta_item =
match self.parse_meta_item() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
match self.expect(&token::CloseDelim(token::Bracket))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
(mk_sp(lo, hi), meta_item, style)
}
_ => {
let token_str = self.this_token_to_string();
return Err(self.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected `#`, found `",
"`"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))));
}
};
if permit_inner && self.token == token::Semi {
self.bump();
self.span_warn(span,
"this inner attribute syntax is deprecated. The new syntax is `#![foo]`, with a bang and no semicolon");
style = ast::AttrStyle::Inner;
}
Ok(Spanned{span: span,
node:
ast::Attribute_{id: attr::mk_attr_id(),
style: style,
value: value,
is_sugared_doc: false,},})
}
/// Parse attributes that appear after the opening of an item. These should
/// be preceded by an exclamation mark, but we accept and warn about one
/// terminated by a semicolon.
/// matches inner_attrs*
pub fn parse_inner_attributes(&mut self)
-> PResult<'a, Vec<ast::Attribute>> {
let mut attrs: Vec<ast::Attribute> =
<[_]>::into_vec(::std::boxed::Box::new([]));
loop {
match self.token {
token::Pound => {
if !self.look_ahead(1, |t| t == &token::Not) {
break ;
}
let attr =
match self.parse_attribute(true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !(attr.node.style == ast::AttrStyle::Inner) {
{
::std::rt::begin_unwind("assertion failed: attr.node.style == ast::AttrStyle::Inner",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/attr.rs",
127u32);
&_FILE_LINE
})
}
};
attrs.push(attr);
}
token::DocComment(s) => {
let Span { lo, hi, .. } = self.span;
let str =
self.id_to_interned_str(ast::Ident::with_empty_ctxt(s));
let attr =
attr::mk_sugared_doc_attr(attr::mk_attr_id(),
str, lo, hi);
if attr.node.style == ast::AttrStyle::Inner {
attrs.push(attr);
self.bump();
} else { break ; }
}
_ => break ,
}
}
Ok(attrs)
}
/// matches meta_item = IDENT
/// | IDENT = lit
/// | IDENT meta_seq
pub fn parse_meta_item(&mut self)
-> PResult<'a, P<ast::MetaItem>> {
let nt_meta =
match self.token {
token::Interpolated(token::NtMeta(ref e)) => {
Some(e.clone())
}
_ => None,
};
match nt_meta {
Some(meta) => { self.bump(); return Ok(meta); }
None => { }
}
let lo = self.span.lo;
let ident =
match self.parse_ident() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let name = self.id_to_interned_str(ident);
match self.token {
token::Eq => {
self.bump();
let lit =
match self.parse_lit() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match lit.node {
ast::LitStr(..) => { }
_ => {
self.span_err(lit.span,
"non-string literals are not allowed in meta-items");
}
}
let hi = self.span.hi;
Ok(P(spanned(lo, hi, ast::MetaNameValue(name, lit))))
}
token::OpenDelim(token::Paren) => {
let inner_items =
match self.parse_meta_seq() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let hi = self.span.hi;
Ok(P(spanned(lo, hi,
ast::MetaList(name, inner_items))))
}
_ => {
let hi = self.last_span.hi;
Ok(P(spanned(lo, hi, ast::MetaWord(name))))
}
}
}
/// matches meta_seq = ( COMMASEP(meta_item) )
fn parse_meta_seq(&mut self)
-> PResult<'a, Vec<P<ast::MetaItem>>> {
self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p: &mut Parser<'a>|
p.parse_meta_item())
}
}
}
pub mod common {
//! Common routines shared by parser mods
#[prelude_import]
use std::prelude::v1::*;
use parse::token;
/// SeqSep : a sequence separator (token)
/// and whether a trailing separator is allowed.
pub struct SeqSep {
pub sep: Option<token::Token>,
pub trailing_sep_allowed: bool,
}
pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {
SeqSep{sep: Some(t), trailing_sep_allowed: true,}
}
pub fn seq_sep_none() -> SeqSep {
SeqSep{sep: None, trailing_sep_allowed: false,}
}
}
pub mod classify {
//! Routines the parser uses to classify AST nodes
#[prelude_import]
use std::prelude::v1::*;
use ast;
/// Does this expression require a semicolon to be treated
/// as a statement? The negation of this: 'can this expression
/// be used as a statement without a semicolon' -- is used
/// as an early-bail-out in the parser so that, for instance,
/// if true {...} else {...}
/// |x| 5
/// isn't parsed as (if true {...} else {...} | x) | 5
pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
match e.node {
ast::ExprIf(..) | ast::ExprIfLet(..) | ast::ExprMatch(..) |
ast::ExprBlock(_) | ast::ExprWhile(..) | ast::ExprWhileLet(..)
| ast::ExprLoop(..) | ast::ExprForLoop(..) => false,
_ => true,
}
}
pub fn expr_is_simple_block(e: &ast::Expr) -> bool {
match e.node {
ast::ExprBlock(ref block) => block.rules == ast::DefaultBlock,
_ => false,
}
}
/// this statement requires a semicolon after it.
/// note that in one case (stmt_semi), we've already
/// seen the semicolon, and thus don't need another.
pub fn stmt_ends_with_semi(stmt: &ast::Stmt_) -> bool {
match *stmt {
ast::StmtDecl(ref d, _) => {
match d.node {
ast::DeclLocal(_) => true,
ast::DeclItem(_) => false,
}
}
ast::StmtExpr(ref e, _) => {
expr_requires_semi_to_be_stmt(e)
}
ast::StmtSemi(..) => { false }
ast::StmtMac(..) => { false }
}
}
}
pub mod obsolete {
//! Support for parsing unsupported, old syntaxes, for the purpose of reporting errors. Parsing of
//! these syntaxes is tested by compile-test/obsolete-syntax.rs.
//!
//! Obsolete syntax that becomes too hard to parse can be removed.
#[prelude_import]
use std::prelude::v1::*;
use codemap::Span;
use parse::parser;
/// The specific types of unsupported syntax
pub enum ObsoleteSyntax { ClosureKind, ExternCrateString, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for ObsoleteSyntax {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&ObsoleteSyntax::ClosureKind,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&ObsoleteSyntax::ExternCrateString,) => {
::std::hash::Hash::hash(&1usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::Eq for ObsoleteSyntax {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&ObsoleteSyntax::ClosureKind,) => { }
(&ObsoleteSyntax::ExternCrateString,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for ObsoleteSyntax {
#[inline]
fn eq(&self, __arg_0: &ObsoleteSyntax) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ObsoleteSyntax::ClosureKind,
&ObsoleteSyntax::ClosureKind) => true,
(&ObsoleteSyntax::ExternCrateString,
&ObsoleteSyntax::ExternCrateString) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &ObsoleteSyntax) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&ObsoleteSyntax::ClosureKind,
&ObsoleteSyntax::ClosureKind) => false,
(&ObsoleteSyntax::ExternCrateString,
&ObsoleteSyntax::ExternCrateString) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for ObsoleteSyntax {
#[inline]
fn clone(&self) -> ObsoleteSyntax {
match (&*self,) {
(&ObsoleteSyntax::ClosureKind,) =>
ObsoleteSyntax::ClosureKind,
(&ObsoleteSyntax::ExternCrateString,) =>
ObsoleteSyntax::ExternCrateString,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for ObsoleteSyntax { }
pub trait ParserObsoleteMethods {
/// Reports an obsolete syntax non-fatal error.
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax);
fn report(&mut self, sp: Span, kind: ObsoleteSyntax,
kind_str: &str, desc: &str, error: bool);
}
impl <'a> ParserObsoleteMethods for parser::Parser<'a> {
/// Reports an obsolete syntax non-fatal error.
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
let (kind_str, desc, error) =
match kind {
ObsoleteSyntax::ClosureKind =>
("`:`, `&mut:`, or `&:`", "rely on inference instead",
true),
ObsoleteSyntax::ExternCrateString =>
("\"crate-name\"",
"use an identifier not in quotes instead", false),
};
self.report(sp, kind, kind_str, desc, error);
}
fn report(&mut self, sp: Span, kind: ObsoleteSyntax,
kind_str: &str, desc: &str, error: bool) {
let mut err =
if error {
self.diagnostic().struct_span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["obsolete syntax: "];
__STATIC_FMTSTR
},
&match (&kind_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
} else {
self.diagnostic().struct_span_warn(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["obsolete syntax: "];
__STATIC_FMTSTR
},
&match (&kind_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
};
if !self.obsolete_set.contains(&kind) &&
(error || self.sess.span_diagnostic.can_emit_warnings)
{
err.note(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&desc,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
self.obsolete_set.insert(kind);
}
err.emit();
}
}
}
/// Info about a parsing session.
pub struct ParseSess {
pub span_diagnostic: Handler,
/// Used to determine and report recursive mod inclusions
included_mod_stack: RefCell<Vec<PathBuf>>,
code_map: Rc<CodeMap>,
}
impl ParseSess {
pub fn new() -> ParseSess {
let cm = Rc::new(CodeMap::new());
let handler =
Handler::new(ColorConfig::Auto, None, true, false,
cm.clone());
ParseSess::with_span_handler(handler, cm)
}
pub fn with_span_handler(handler: Handler, code_map: Rc<CodeMap>)
-> ParseSess {
ParseSess{span_diagnostic: handler,
included_mod_stack:
RefCell::new(<[_]>::into_vec(::std::boxed::Box::new([]))),
code_map: code_map,}
}
pub fn codemap(&self) -> &CodeMap { &self.code_map }
}
pub fn parse_crate_from_file(input: &Path, cfg: ast::CrateConfig,
sess: &ParseSess) -> ast::Crate {
let mut parser = new_parser_from_file(sess, cfg, input);
abort_if_errors(parser.parse_crate_mod(), &parser)
}
pub fn parse_crate_attrs_from_file(input: &Path, cfg: ast::CrateConfig,
sess: &ParseSess)
-> Vec<ast::Attribute> {
let mut parser = new_parser_from_file(sess, cfg, input);
abort_if_errors(parser.parse_inner_attributes(), &parser)
}
pub fn parse_crate_from_source_str(name: String, source: String,
cfg: ast::CrateConfig,
sess: &ParseSess) -> ast::Crate {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_crate_mod() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
101u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn parse_crate_attrs_from_source_str(name: String, source: String,
cfg: ast::CrateConfig,
sess: &ParseSess)
-> Vec<ast::Attribute> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_inner_attributes() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
113u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn parse_expr_from_source_str(name: String, source: String,
cfg: ast::CrateConfig, sess: &ParseSess)
-> P<ast::Expr> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
122u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn parse_item_from_source_str(name: String, source: String,
cfg: ast::CrateConfig, sess: &ParseSess)
-> Option<P<ast::Item>> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
131u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn parse_meta_from_source_str(name: String, source: String,
cfg: ast::CrateConfig, sess: &ParseSess)
-> P<ast::MetaItem> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_meta_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
140u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn parse_stmt_from_source_str(name: String, source: String,
cfg: ast::CrateConfig, sess: &ParseSess)
-> Option<P<ast::Stmt>> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_stmt() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
154u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn parse_tts_from_source_str(name: String, source: String,
cfg: ast::CrateConfig, sess: &ParseSess)
-> Vec<ast::TokenTree> {
let mut p = new_parser_from_source_str(sess, cfg, name, source);
p.quote_depth += 1;
maybe_aborted({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_all_token_trees() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
171u32);
&_FILE_LINE
})
};
}
}
}, p)
}
pub fn new_parser_from_source_str<'a>(sess: &'a ParseSess,
cfg: ast::CrateConfig, name: String,
source: String) -> Parser<'a> {
filemap_to_parser(sess, sess.codemap().new_filemap(name, source), cfg)
}
/// Create a new parser, handling errors as appropriate
/// if the file doesn't exist
pub fn new_parser_from_file<'a>(sess: &'a ParseSess,
cfg: ast::CrateConfig, path: &Path)
-> Parser<'a> {
filemap_to_parser(sess, file_to_filemap(sess, path, None), cfg)
}
/// Given a session, a crate config, a path, and a span, add
/// the file at the given path to the codemap, and return a parser.
/// On an error, use the given span as the source of the problem.
pub fn new_sub_parser_from_file<'a>(sess: &'a ParseSess,
cfg: ast::CrateConfig, path: &Path,
owns_directory: bool,
module_name: Option<String>, sp: Span)
-> Parser<'a> {
let mut p =
filemap_to_parser(sess, file_to_filemap(sess, path, Some(sp)),
cfg);
p.owns_directory = owns_directory;
p.root_module_name = module_name;
p
}
/// Given a filemap and config, return a parser
pub fn filemap_to_parser<'a>(sess: &'a ParseSess, filemap: Rc<FileMap>,
cfg: ast::CrateConfig) -> Parser<'a> {
let end_pos = filemap.end_pos;
let mut parser =
tts_to_parser(sess, filemap_to_tts(sess, filemap), cfg);
if parser.token == token::Eof && parser.span == codemap::DUMMY_SP {
parser.span = codemap::mk_sp(end_pos, end_pos);
}
parser
}
pub fn new_parser_from_tts<'a>(sess: &'a ParseSess, cfg: ast::CrateConfig,
tts: Vec<ast::TokenTree>) -> Parser<'a> {
tts_to_parser(sess, tts, cfg)
}
/// Given a session and a path and an optional span (for error reporting),
/// add the path to the session's codemap and return the new filemap.
fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
-> Rc<FileMap> {
match sess.codemap().load_file(path) {
Ok(filemap) => filemap,
Err(e) => {
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["couldn\'t read ",
": "];
__STATIC_FMTSTR
},
&match (&path.display(),
&e)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
match spanopt {
Some(sp) => {
::std::rt::begin_unwind(sess.span_diagnostic.span_fatal(sp,
&msg),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/mod.rs",
240u32);
&_FILE_LINE
})
}
None => {
::std::rt::begin_unwind(sess.span_diagnostic.fatal(&msg),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/mod.rs",
241u32);
&_FILE_LINE
})
}
}
}
}
}
/// Given a filemap, produce a sequence of token-trees
pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
-> Vec<ast::TokenTree> {
let cfg = Vec::new();
let srdr = lexer::StringReader::new(&sess.span_diagnostic, filemap);
let mut p1 = Parser::new(sess, cfg, Box::new(srdr));
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p1.parse_all_token_trees() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/mod.rs",
255u32);
&_FILE_LINE
})
};
}
}
}
}
/// Given tts and cfg, produce a parser
pub fn tts_to_parser<'a>(sess: &'a ParseSess, tts: Vec<ast::TokenTree>,
cfg: ast::CrateConfig) -> Parser<'a> {
let trdr =
lexer::new_tt_reader(&sess.span_diagnostic, None, None, tts);
let mut p = Parser::new(sess, cfg, Box::new(trdr));
p.check_unknown_macro_variable();
p
}
/// Abort if necessary
pub fn maybe_aborted<T>(result: T, p: Parser) -> T {
p.abort_if_errors();
result
}
fn abort_if_errors<'a, T>(result: PResult<'a, T>, p: &Parser) -> T {
match result {
Ok(c) => { p.abort_if_errors(); c }
Err(mut e) => {
e.emit();
p.abort_if_errors();
{
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/mod.rs",
283u32);
&_FILE_LINE
})
}
};
}
}
}
/// Parse a string representing a character literal into its final form.
/// Rather than just accepting/rejecting a given literal, unescapes it as
/// well. Can take any slice prefixed by a character escape. Returns the
/// character and the number of characters consumed.
pub fn char_lit(lit: &str) -> (char, isize) {
use std::char;
let mut chars = lit.chars();
let c =
match (chars.next(), chars.next()) {
(Some(c), None) if c != '\\' => return (c, 1),
(Some('\\'), Some(c)) =>
match c {
'\"' => Some('\"'),
'n' => Some('\n'),
'r' => Some('\r'),
't' => Some('\t'),
'\\' => Some('\\'),
'\'' => Some('\''),
'0' => Some('\u{0}'),
_ => { None }
},
_ => {
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["lexer accepted invalid char escape `",
"`"];
__STATIC_FMTSTR
},
&match (&lit,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str, u32)
=
("src/parse/mod.rs",
308u32);
&_FILE_LINE
})
}
};
match c { Some(x) => return (x, 2), None => { } }
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["lexer should have rejected a bad character escape "];
__STATIC_FMTSTR
},
&match (&lit,) {
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
let msg2 = &msg[..];
fn esc(len: usize, lit: &str) -> Option<(char, isize)> {
u32::from_str_radix(&lit[2..len],
16).ok().and_then(char::from_u32).map(|x|
(x,
len
as
isize))
}
let unicode_escape = || -> Option<(char, isize)> {
if lit.as_bytes()[2] == b'{' {
let idx = lit.find('}').expect(msg2);
let subslice = &lit[3..idx];
u32::from_str_radix(subslice,
16).ok().and_then(char::from_u32).map(|x|
(x,
(subslice.chars().count()
as
isize)
+
4))
} else { esc(6, lit) } };
return match lit.as_bytes()[1] as char {
'x' | 'X' => esc(4, lit),
'u' => unicode_escape(),
'U' => esc(10, lit),
_ => None,
}.expect(msg2);
}
/// Parse a string representing a string literal into its final form. Does
/// unescaping.
pub fn str_lit(lit: &str) -> String {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 349u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_str_lit: given "];
__STATIC_FMTSTR
},
&match (&lit.chars().flat_map(char::escape_default).collect::<String>(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let mut res = String::with_capacity(lit.len());
let error =
|i|
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["lexer should have rejected ",
" at "];
__STATIC_FMTSTR
},
&match (&lit,
&i) {
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
/// Eat everything up to a non-whitespace
fn eat<'a>(it: &mut iter::Peekable<str::CharIndices<'a>>) {
loop {
match it.peek().map(|x| x.1) {
Some(' ') | Some('\n') | Some('\r') | Some('\t') => {
it.next();
}
_ => { break ; }
}
}
}
let mut chars = lit.char_indices().peekable();
loop {
match chars.next() {
Some((i, c)) => {
match c {
'\\' => {
let ch =
chars.peek().unwrap_or_else(|| {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&error(i),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
375u32);
&_FILE_LINE
})
} }).1;
if ch == '\n' {
eat(&mut chars);
} else if ch == '\r' {
chars.next();
let ch =
chars.peek().unwrap_or_else(|| {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&error(i),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
383u32);
&_FILE_LINE
})
} }).1;
if ch != '\n' {
{
::std::rt::begin_unwind("lexer accepted bare CR",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
387u32);
&_FILE_LINE
})
};
}
eat(&mut chars);
} else {
let (c, n) = char_lit(&lit[i..]);
for _ in 0..n - 1 { chars.next(); }
res.push(c);
}
}
'\r' => {
let ch =
chars.peek().unwrap_or_else(|| {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&error(i),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/parse/mod.rs",
401u32);
&_FILE_LINE
})
} }).1;
if ch != '\n' {
{
::std::rt::begin_unwind("lexer accepted bare CR",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/mod.rs",
405u32);
&_FILE_LINE
})
};
}
chars.next();
res.push('\n');
}
c => res.push(c),
}
}
None => break ,
}
}
res.shrink_to_fit();
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 418u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["parse_str_lit: returning "];
__STATIC_FMTSTR
},
&match (&res,) {
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
res
}
/// Parse a string representing a raw string literal into its final form. The
/// only operation this does is convert embedded CRLF into a single LF.
pub fn raw_str_lit(lit: &str) -> String {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 425u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["raw_str_lit: given "];
__STATIC_FMTSTR
},
&match (&lit.chars().flat_map(char::escape_default).collect::<String>(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let mut res = String::with_capacity(lit.len());
let mut chars = lit.chars().peekable();
loop {
match chars.next() {
Some(c) => {
if c == '\r' {
if *chars.peek().unwrap() != '\n' {
{
::std::rt::begin_unwind("lexer accepted bare CR",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/mod.rs",
436u32);
&_FILE_LINE
})
};
}
chars.next();
res.push('\n');
} else { res.push(c); }
}
None => break ,
}
}
res.shrink_to_fit();
res
}
fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool {
s.len() > 1 && first_chars.contains(&char_at(s, 0)) &&
s[1..].chars().all(|c| '0' <= c && c <= '9')
}
fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
sd: &Handler, sp: Span) -> ast::Lit_ {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 461u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["filtered_float_lit: ",
", "];
__STATIC_FMTSTR
},
&match (&data,
&suffix) {
(__arg0,
__arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
match suffix.as_ref().map(|s| &**s) {
Some("f32") => ast::LitFloat(data, ast::TyF32),
Some("f64") => ast::LitFloat(data, ast::TyF64),
Some(suf) => {
if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) {
sd.struct_span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid width `",
"` for float literal"];
__STATIC_FMTSTR
},
&match (&&suf[1..],)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).fileline_help(sp,
"valid widths are 32 and 64").emit();
} else {
sd.struct_span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid suffix `",
"` for float literal"];
__STATIC_FMTSTR
},
&match (&suf,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).fileline_help(sp,
"valid suffixes are `f32` and `f64`").emit();
}
ast::LitFloatUnsuffixed(data)
}
None => ast::LitFloatUnsuffixed(data),
}
}
pub fn float_lit(s: &str, suffix: Option<InternedString>, sd: &Handler,
sp: Span) -> ast::Lit_ {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 484u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["float_lit: ",
", "];
__STATIC_FMTSTR
},
&match (&s,
&suffix) {
(__arg0,
__arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
let s = s.chars().filter(|&c| c != '_').collect::<String>();
let data = token::intern_and_get_ident(&s);
filtered_float_lit(data, suffix.as_ref().map(|s| &**s), sd, sp)
}
/// Parse a string representing a byte literal into its final form. Similar to `char_lit`
pub fn byte_lit(lit: &str) -> (u8, usize) {
let err =
|i|
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["lexer accepted invalid byte literal ",
" step "];
__STATIC_FMTSTR
},
&match (&lit,
&i) {
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
if lit.len() == 1 {
(lit.as_bytes()[0], 1)
} else {
if !(lit.as_bytes()[0] == b'\\') {
{
::std::rt::begin_unwind(err(0),
{
static _FILE_LINE:
(&'static str, u32) =
("src/parse/mod.rs",
498u32);
&_FILE_LINE
})
}
};
let b =
match lit.as_bytes()[1] {
b'\"' => b'\"',
b'n' => b'\n',
b'r' => b'\r',
b't' => b'\t',
b'\\' => b'\\',
b'\'' => b'\'',
b'0' => b'\x00',
_ => {
match u64::from_str_radix(&lit[2..4], 16).ok() {
Some(c) =>
if c > 255 {
{
::std::rt::begin_unwind(err(2),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/mod.rs",
511u32);
&_FILE_LINE
})
}
} else { return (c as u8, 4) },
None => {
::std::rt::begin_unwind(err(3),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/mod.rs",
515u32);
&_FILE_LINE
})
}
}
}
};
return (b, 2);
}
}
pub fn byte_str_lit(lit: &str) -> Rc<Vec<u8>> {
let mut res = Vec::with_capacity(lit.len());
let error =
|i|
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["lexer should have rejected ",
" at "];
__STATIC_FMTSTR
},
&match (&lit,
&i) {
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
/// Eat everything up to a non-whitespace
fn eat<'a, I: Iterator<Item =
(usize, u8)>>(it: &mut iter::Peekable<I>) {
loop {
match it.peek().map(|x| x.1) {
Some(b' ') | Some(b'\n') | Some(b'\r') | Some(b'\t') => {
it.next();
}
_ => { break ; }
}
}
}
let mut chars = lit.bytes().enumerate().peekable();
loop {
match chars.next() {
Some((i, b'\\')) => {
let em = error(i);
match chars.peek().expect(&em).1 {
b'\n' => eat(&mut chars),
b'\r' => {
chars.next();
if chars.peek().expect(&em).1 != b'\n' {
{
::std::rt::begin_unwind("lexer accepted bare CR",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/mod.rs",
552u32);
&_FILE_LINE
})
};
}
eat(&mut chars);
}
_ => {
let (c, n) = byte_lit(&lit[i..]);
for _ in 0..n - 1 { chars.next(); }
res.push(c);
}
}
}
Some((i, b'\r')) => {
let em = error(i);
if chars.peek().expect(&em).1 != b'\n' {
{
::std::rt::begin_unwind("lexer accepted bare CR",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/parse/mod.rs",
570u32);
&_FILE_LINE
})
};
}
chars.next();
res.push(b'\n');
}
Some((_, c)) => res.push(c),
None => break ,
}
}
Rc::new(res)
}
pub fn integer_lit(s: &str, suffix: Option<InternedString>, sd: &Handler,
sp: Span) -> ast::Lit_ {
let s2 = s.chars().filter(|&c| c != '_').collect::<String>();
let mut s = &s2[..];
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 593u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["integer_lit: ",
", "];
__STATIC_FMTSTR
},
&match (&s,
&suffix) {
(__arg0,
__arg1) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}))
}
};
let mut base = 10;
let orig = s;
let mut ty = ast::UnsuffixedIntLit(ast::Plus);
if char_at(s, 0) == '0' && s.len() > 1 {
match char_at(s, 1) {
'x' => base = 16,
'o' => base = 8,
'b' => base = 2,
_ => { }
}
}
if let Some(ref suf) = suffix {
if looks_like_width_suffix(&['f'], suf) {
match base {
16 =>
sd.span_err(sp,
"hexadecimal float literal is not supported"),
8 =>
sd.span_err(sp, "octal float literal is not supported"),
2 =>
sd.span_err(sp, "binary float literal is not supported"),
_ => (),
}
let ident = token::intern_and_get_ident(&*s);
return filtered_float_lit(ident, Some(&**suf), sd, sp)
}
}
if base != 10 { s = &s[2..]; }
if let Some(ref suf) = suffix {
if suf.is_empty() {
sd.span_bug(sp, "found empty literal suffix in Some")
}
ty =
match &**suf {
"isize" => ast::SignedIntLit(ast::TyIs, ast::Plus),
"i8" => ast::SignedIntLit(ast::TyI8, ast::Plus),
"i16" => ast::SignedIntLit(ast::TyI16, ast::Plus),
"i32" => ast::SignedIntLit(ast::TyI32, ast::Plus),
"i64" => ast::SignedIntLit(ast::TyI64, ast::Plus),
"usize" => ast::UnsignedIntLit(ast::TyUs),
"u8" => ast::UnsignedIntLit(ast::TyU8),
"u16" => ast::UnsignedIntLit(ast::TyU16),
"u32" => ast::UnsignedIntLit(ast::TyU32),
"u64" => ast::UnsignedIntLit(ast::TyU64),
_ => {
if looks_like_width_suffix(&['i', 'u'], suf) {
sd.struct_span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid width `",
"` for integer literal"];
__STATIC_FMTSTR
},
&match (&&suf[1..],)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).fileline_help(sp,
"valid widths are 8, 16, 32 and 64").emit();
} else {
sd.struct_span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid suffix `",
"` for numeric literal"];
__STATIC_FMTSTR
},
&match (&suf,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).fileline_help(sp,
"the suffix must be one of the integral types (`u32`, `isize`, etc)").emit();
}
ty
}
}
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 659u32,
__file: "src/parse/mod.rs",
__module_path: "syntex_syntax::parse",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::parse", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["integer_lit: the type is ",
", base ",
", the new string is ",
", the original string was ",
", the original suffix was "];
__STATIC_FMTSTR
},
&match (&ty, &base,
&s, &orig,
&suffix) {
(__arg0,
__arg1,
__arg2,
__arg3,
__arg4) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg4,
::std::fmt::Debug::fmt)],
}))
}
};
let res =
match u64::from_str_radix(s, base).ok() {
Some(r) => r,
None => {
let already_errored =
base < 10 &&
s.chars().any(|c|
c.to_digit(10).map_or(false,
|d|
d >=
base));
if !already_errored {
sd.span_err(sp, "int literal is too large");
}
0
}
};
let sign = ast::Sign::new(res);
match ty {
ast::SignedIntLit(t, _) =>
ast::LitInt(res, ast::SignedIntLit(t, sign)),
ast::UnsuffixedIntLit(_) =>
ast::LitInt(res, ast::UnsuffixedIntLit(sign)),
us@ast::UnsignedIntLit(_) => ast::LitInt(res, us),
}
}
}
pub mod ptr {
//! The AST pointer
//!
//! Provides `P<T>`, a frozen owned smart pointer, as a replacement for `@T` in
//! the AST.
//!
//! # Motivations and benefits
//!
//! * **Identity**: sharing AST nodes is problematic for the various analysis
//! passes (e.g. one may be able to bypass the borrow checker with a shared
//! `ExprAddrOf` node taking a mutable borrow). The only reason `@T` in the
//! AST hasn't caused issues is because of inefficient folding passes which
//! would always deduplicate any such shared nodes. Even if the AST were to
//! switch to an arena, this would still hold, i.e. it couldn't use `&'a T`,
//! but rather a wrapper like `P<'a, T>`.
//!
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
//! (unless it contains an `Unsafe` interior, but that may be denied later).
//! This mainly prevents mistakes, but can also enforces a kind of "purity".
//!
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
//! the latter even when the input and output types differ (as it would be the
//! case with arenas or a GADT AST using type parameters to toggle features).
//!
//! * **Maintainability**: `P<T>` provides a fixed interface - `Deref`,
//! `and_then` and `map` - which can remain fully functional even if the
//! implementation changes (using a special thread-local heap, for example).
//! Moreover, a switch to, e.g. `P<'a, T>` would be easy and mostly automated.
#[prelude_import]
use std::prelude::v1::*;
use std::fmt::{self, Display, Debug};
use std::iter::FromIterator;
use std::ops::Deref;
use std::{slice, vec};
use serialize::{Encodable, Decodable, Encoder, Decoder};
/// An owned smart pointer.
pub struct P<T: ?Sized> {
ptr: Box<T>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::cmp::Ord + ?Sized> ::std::cmp::Ord for P<T> {
#[inline]
fn cmp(&self, __arg_0: &P<T>) -> ::std::cmp::Ordering {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } => {
let __test =
::std::cmp::Ord::cmp(&(*__self_0_0),
&(*__self_1_0));
if __test == ::std::cmp::Ordering::Equal {
::std::cmp::Ordering::Equal
} else { __test }
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::cmp::PartialOrd + ?Sized> ::std::cmp::PartialOrd for P<T>
{
#[inline]
fn partial_cmp(&self, __arg_0: &P<T>)
-> ::std::option::Option<::std::cmp::Ordering> {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } => {
let __test =
::std::cmp::PartialOrd::partial_cmp(&(*__self_0_0),
&(*__self_1_0));
if __test ==
::std::option::Option::Some(::std::cmp::Ordering::Equal)
{
::std::option::Option::Some(::std::cmp::Ordering::Equal)
} else { __test }
}
},
}
}
#[inline]
fn lt(&self, __arg_0: &P<T>) -> bool {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && false,
},
}
}
#[inline]
fn le(&self, __arg_0: &P<T>) -> bool {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } =>
(*__self_0_0) < (*__self_1_0) ||
!((*__self_1_0) < (*__self_0_0)) && true,
},
}
}
#[inline]
fn gt(&self, __arg_0: &P<T>) -> bool {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && false,
},
}
}
#[inline]
fn ge(&self, __arg_0: &P<T>) -> bool {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } =>
(*__self_0_0) > (*__self_1_0) ||
!((*__self_1_0) > (*__self_0_0)) && true,
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::cmp::Eq + ?Sized> ::std::cmp::Eq for P<T> {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match *self {
P { ptr: ref __self_0_0 } => {
(*__self_0_0).assert_receiver_is_total_eq();
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::cmp::PartialEq + ?Sized> ::std::cmp::PartialEq for P<T> {
#[inline]
fn eq(&self, __arg_0: &P<T>) -> bool {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } =>
true && (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, __arg_0: &P<T>) -> bool {
match *__arg_0 {
P { ptr: ref __self_1_0 } =>
match *self {
P { ptr: ref __self_0_0 } =>
false || (*__self_0_0) != (*__self_1_0),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <T: ::std::hash::Hash + ?Sized> ::std::hash::Hash for P<T> {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H) -> () {
match *self {
P { ptr: ref __self_0_0 } => {
::std::hash::Hash::hash(&(*__self_0_0), __arg_0);
}
}
}
}
#[allow(non_snake_case)]
/// Construct a `P<T>` from a `T` value.
pub fn P<T: 'static>(value: T) -> P<T> { P{ptr: Box::new(value),} }
impl <T: 'static> P<T> {
/// Move out of the pointer.
/// Intended for chaining transformations not covered by `map`.
pub fn and_then<U, F>(self, f: F) -> U where F: FnOnce(T) -> U {
f(*self.ptr)
}
/// Transform the inner value, consuming `self` and producing a new `P<T>`.
pub fn map<F>(self, f: F) -> P<T> where F: FnOnce(T) -> T {
P(f(*self.ptr))
}
}
impl <T> Deref for P<T> {
type
Target
=
T;
fn deref<'a>(&'a self) -> &'a T { &*self.ptr }
}
impl <T: 'static + Clone> Clone for P<T> {
fn clone(&self) -> P<T> { P((**self).clone()) }
}
impl <T: Debug> Debug for P<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&**self, f)
}
}
impl <T: Display> Display for P<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&**self, f)
}
}
impl <T> fmt::Pointer for P<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&self.ptr, f)
}
}
impl <T: 'static + Decodable> Decodable for P<T> {
fn decode<D: Decoder>(d: &mut D) -> Result<P<T>, D::Error> {
Decodable::decode(d).map(P)
}
}
impl <T: Encodable> Encodable for P<T> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
(**self).encode(s)
}
}
impl <T: fmt::Debug> fmt::Debug for P<[T]> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.ptr.fmt(fmt)
}
}
impl <T> P<[T]> {
pub fn new() -> P<[T]> { P::empty() }
pub fn empty() -> P<[T]> { P{ptr: Default::default(),} }
#[inline(never)]
pub fn from_vec(v: Vec<T>) -> P<[T]> { P{ptr: v.into_boxed_slice(),} }
#[inline(never)]
pub fn into_vec(self) -> Vec<T> { self.ptr.into_vec() }
pub fn as_slice<'a>(&'a self) -> &'a [T] { &*self.ptr }
pub fn move_iter(self) -> vec::IntoIter<T> {
self.into_vec().into_iter()
}
pub fn map<U, F: FnMut(&T) -> U>(&self, f: F) -> P<[U]> {
self.iter().map(f).collect()
}
}
impl <T> Deref for P<[T]> {
type
Target
=
[T];
fn deref(&self) -> &[T] { self.as_slice() }
}
impl <T> Default for P<[T]> {
fn default() -> P<[T]> { P::empty() }
}
impl <T: Clone> Clone for P<[T]> {
fn clone(&self) -> P<[T]> { P::from_vec(self.to_vec()) }
}
impl <T> From<Vec<T>> for P<[T]> {
fn from(v: Vec<T>) -> Self { P::from_vec(v) }
}
impl <T> Into<Vec<T>> for P<[T]> {
fn into(self) -> Vec<T> { self.into_vec() }
}
impl <T> FromIterator<T> for P<[T]> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> P<[T]> {
P::from_vec(iter.into_iter().collect())
}
}
impl <T> IntoIterator for P<[T]> {
type
Item
=
T;
type
IntoIter
=
vec::IntoIter<T>;
fn into_iter(self) -> Self::IntoIter { self.into_vec().into_iter() }
}
impl <'a, T> IntoIterator for &'a P<[T]> {
type
Item
=
&'a T;
type
IntoIter
=
slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter { self.ptr.into_iter() }
}
impl <T: Encodable> Encodable for P<[T]> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
Encodable::encode(&**self, s)
}
}
impl <T: Decodable> Decodable for P<[T]> {
fn decode<D: Decoder>(d: &mut D) -> Result<P<[T]>, D::Error> {
Ok(P::from_vec(match Decodable::decode(d) {
Ok(t) => t,
Err(e) => return Err(e),
}))
}
}
}
pub mod show_span {
//! Span debugger
//!
//! This module shows spans for all expressions in the crate
//! to help with compiler debugging.
#[prelude_import]
use std::prelude::v1::*;
use std::str::FromStr;
use ast;
use errors;
use visit;
use visit::Visitor;
enum Mode { Expression, Pattern, Type, }
impl FromStr for Mode {
type
Err
=
();
fn from_str(s: &str) -> Result<Mode, ()> {
let mode =
match s {
"expr" => Mode::Expression,
"pat" => Mode::Pattern,
"ty" => Mode::Type,
_ => return Err(()),
};
Ok(mode)
}
}
struct ShowSpanVisitor<'a> {
span_diagnostic: &'a errors::Handler,
mode: Mode,
}
impl <'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
if let Mode::Expression = self.mode {
self.span_diagnostic.span_warn(e.span, "expression");
}
visit::walk_expr(self, e);
}
fn visit_pat(&mut self, p: &ast::Pat) {
if let Mode::Pattern = self.mode {
self.span_diagnostic.span_warn(p.span, "pattern");
}
visit::walk_pat(self, p);
}
fn visit_ty(&mut self, t: &ast::Ty) {
if let Mode::Type = self.mode {
self.span_diagnostic.span_warn(t.span, "type");
}
visit::walk_ty(self, t);
}
fn visit_mac(&mut self, mac: &ast::Mac) {
visit::walk_mac(self, mac);
}
}
pub fn run(span_diagnostic: &errors::Handler, mode: &str,
krate: &ast::Crate) {
let mode =
match mode.parse().ok() { Some(mode) => mode, None => return, };
let mut v =
ShowSpanVisitor{span_diagnostic: span_diagnostic, mode: mode,};
visit::walk_crate(&mut v, krate);
}
}
pub mod std_inject {
#[prelude_import]
use std::prelude::v1::*;
use ast;
use attr;
use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
use codemap;
use fold::Folder;
use fold;
use parse::token::{intern, InternedString, special_idents};
use parse::{token, ParseSess};
use ptr::P;
use util::small_vector::SmallVector;
/// Craft a span that will be ignored by the stability lint's
/// call to codemap's is_internal check.
/// The expanded code uses the unstable `#[prelude_import]` attribute.
fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
let info =
ExpnInfo{call_site: DUMMY_SP,
callee:
NameAndSpan{format:
MacroAttribute(intern("std_inject")),
span: None,
allow_internal_unstable: true,},};
let expn_id = sess.codemap().record_expansion(info);
let mut sp = sp;
sp.expn_id = expn_id;
return sp;
}
pub fn maybe_inject_crates_ref(krate: ast::Crate,
alt_std_name: Option<String>)
-> ast::Crate {
if no_core(&krate) {
krate
} else {
let name = if no_std(&krate) { "core" } else { "std" };
let mut fold =
CrateInjector{item_name: token::str_to_ident(name),
crate_name:
token::intern(&alt_std_name.unwrap_or(name.to_string())),};
fold.fold_crate(krate)
}
}
pub fn maybe_inject_prelude(sess: &ParseSess, krate: ast::Crate)
-> ast::Crate {
if no_core(&krate) {
krate
} else {
let name = if no_std(&krate) { "core" } else { "std" };
let mut fold =
PreludeInjector{span: ignored_span(sess, DUMMY_SP),
crate_identifier: token::str_to_ident(name),};
fold.fold_crate(krate)
}
}
pub fn no_core(krate: &ast::Crate) -> bool {
attr::contains_name(&krate.attrs, "no_core")
}
pub fn no_std(krate: &ast::Crate) -> bool {
attr::contains_name(&krate.attrs, "no_std") || no_core(krate)
}
fn no_prelude(attrs: &[ast::Attribute]) -> bool {
attr::contains_name(attrs, "no_implicit_prelude")
}
struct CrateInjector {
item_name: ast::Ident,
crate_name: ast::Name,
}
impl fold::Folder for CrateInjector {
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
krate.module.items.insert(0,
P(ast::Item{id: ast::DUMMY_NODE_ID,
ident: self.item_name,
attrs:
<[_]>::into_vec(::std::boxed::Box::new([attr::mk_attr_outer(attr::mk_attr_id(),
attr::mk_word_item(InternedString::new("macro_use")))])),
node:
ast::ItemExternCrate(Some(self.crate_name)),
vis: ast::Inherited,
span: DUMMY_SP,}));
krate
}
}
struct PreludeInjector {
span: Span,
crate_identifier: ast::Ident,
}
impl fold::Folder for PreludeInjector {
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
if !no_prelude(&krate.attrs) {
krate.module = self.fold_mod(krate.module);
}
krate
}
fn fold_item(&mut self, item: P<ast::Item>)
-> SmallVector<P<ast::Item>> {
if !no_prelude(&item.attrs) {
fold::noop_fold_item(item, self)
} else { SmallVector::one(item) }
}
fn fold_mod(&mut self, mut mod_: ast::Mod) -> ast::Mod {
let prelude_path =
ast::Path{span: self.span,
global: false,
segments:
<[_]>::into_vec(::std::boxed::Box::new([ast::PathSegment{identifier:
self.crate_identifier,
parameters:
ast::PathParameters::none(),},
ast::PathSegment{identifier:
token::str_to_ident("prelude"),
parameters:
ast::PathParameters::none(),},
ast::PathSegment{identifier:
token::str_to_ident("v1"),
parameters:
ast::PathParameters::none(),}])),};
let vp =
P(codemap::dummy_spanned(ast::ViewPathGlob(prelude_path)));
mod_.items.insert(0,
P(ast::Item{id: ast::DUMMY_NODE_ID,
ident: special_idents::invalid,
node: ast::ItemUse(vp),
attrs:
<[_]>::into_vec(::std::boxed::Box::new([ast::Attribute{span:
self.span,
node:
ast::Attribute_{id:
attr::mk_attr_id(),
style:
ast::AttrStyle::Outer,
value:
P(ast::MetaItem{span:
self.span,
node:
ast::MetaWord(special_idents::prelude_import.name.as_str()),}),
is_sugared_doc:
false,},}])),
vis: ast::Inherited,
span: self.span,}));
fold::noop_fold_mod(mod_, self)
}
}
}
pub mod str {
#[prelude_import]
use std::prelude::v1::*;
pub fn char_at(s: &str, byte: usize) -> char {
s[byte..].chars().next().unwrap()
}
#[inline]
pub fn slice_shift_char(s: &str) -> Option<(char, &str)> {
if s.is_empty() {
None
} else { let ch = char_at(s, 0); Some((ch, &s[ch.len_utf8()..])) }
}
}
pub mod test {
#![allow(dead_code)]
#![allow(unused_imports)]
#[prelude_import]
use std::prelude::v1::*;
use self::HasTestSignature::*;
use std::iter;
use std::slice;
use std::mem;
use std::vec;
use ast_util::*;
use attr::AttrMetaMethods;
use attr;
use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
use codemap;
use errors;
use config;
use entry::{self, EntryPointType};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::expand::ExpansionConfig;
use fold::Folder;
use util::move_map::MoveMap;
use fold;
use parse::token::{intern, InternedString};
use parse::{token, ParseSess};
use print::pprust;
use {ast, ast_util};
use ptr::P;
use util::small_vector::SmallVector;
enum ShouldPanic { No, Yes(Option<InternedString>), }
struct Test {
span: Span,
path: Vec<ast::Ident>,
bench: bool,
ignore: bool,
should_panic: ShouldPanic,
}
struct TestCtxt<'a> {
sess: &'a ParseSess,
span_diagnostic: &'a errors::Handler,
path: Vec<ast::Ident>,
ext_cx: ExtCtxt<'a>,
testfns: Vec<Test>,
reexport_test_harness_main: Option<InternedString>,
is_test_crate: bool,
config: ast::CrateConfig,
toplevel_reexport: Option<ast::Ident>,
}
pub fn modify_for_testing(sess: &ParseSess, cfg: &ast::CrateConfig,
krate: ast::Crate,
span_diagnostic: &errors::Handler)
-> ast::Crate {
let should_test = attr::contains_name(&krate.config, "test");
let reexport_test_harness_main =
attr::first_attr_value_str_by_name(&krate.attrs,
"reexport_test_harness_main");
if should_test {
generate_test_harness(sess, reexport_test_harness_main, krate,
cfg, span_diagnostic)
} else { strip_test_functions(span_diagnostic, krate) }
}
struct TestHarnessGenerator<'a> {
cx: TestCtxt<'a>,
tests: Vec<ast::Ident>,
tested_submods: Vec<(ast::Ident, ast::Ident)>,
}
impl <'a> fold::Folder for TestHarnessGenerator<'a> {
fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate {
let mut folded = fold::noop_fold_crate(c, self);
let (mod_, reexport) = mk_test_module(&mut self.cx);
match reexport {
Some(re) => folded.module.items.push(re),
None => { }
}
folded.module.items.push(mod_);
folded
}
fn fold_item(&mut self, i: P<ast::Item>)
-> SmallVector<P<ast::Item>> {
let ident = i.ident;
if ident.name != token::special_idents::invalid.name {
self.cx.path.push(ident);
}
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 123u32,
__file: "src/test.rs",
__module_path: "syntex_syntax::test",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::test", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["current path: "];
__STATIC_FMTSTR
},
&match (&ast_util::path_name_i(&self.cx.path),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let i =
if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
match i.node {
ast::ItemFn(_, ast::Unsafety::Unsafe, _, _, _, _) => {
let diag = self.cx.span_diagnostic;
{
::std::rt::begin_unwind(diag.span_fatal(i.span,
"unsafe functions cannot be used for tests"),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/test.rs",
130u32);
&_FILE_LINE
})
};
}
_ => {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 133u32,
__file: "src/test.rs",
__module_path:
"syntex_syntax::test",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::test",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["this is a test function"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
let test =
Test{span: i.span,
path: self.cx.path.clone(),
bench: is_bench_fn(&self.cx, &*i),
ignore: is_ignored(&*i),
should_panic: should_panic(&*i),};
self.cx.testfns.push(test);
self.tests.push(i.ident);
i.map(|mut i| { i.vis = ast::Public; i })
}
}
} else { i };
let res =
match i.node {
ast::ItemMod(..) => fold::noop_fold_item(i, self),
_ => SmallVector::one(i),
};
if ident.name != token::special_idents::invalid.name {
self.cx.path.pop();
}
res
}
fn fold_mod(&mut self, m: ast::Mod) -> ast::Mod {
let tests = mem::replace(&mut self.tests, Vec::new());
let tested_submods =
mem::replace(&mut self.tested_submods, Vec::new());
let mut mod_folded = fold::noop_fold_mod(m, self);
let tests = mem::replace(&mut self.tests, tests);
let tested_submods =
mem::replace(&mut self.tested_submods, tested_submods);
if !tests.is_empty() || !tested_submods.is_empty() {
let (it, sym) =
mk_reexport_mod(&mut self.cx, tests, tested_submods);
mod_folded.items.push(it);
if !self.cx.path.is_empty() {
self.tested_submods.push((self.cx.path[self.cx.path.len()
- 1], sym));
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 185u32,
__file: "src/test.rs",
__module_path:
"syntex_syntax::test",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::test", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pushing nothing, sym: "];
__STATIC_FMTSTR
},
&match (&sym,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt)],
}))
}
};
self.cx.toplevel_reexport = Some(sym);
}
}
mod_folded
}
}
struct EntryPointCleaner {
depth: usize,
}
impl fold::Folder for EntryPointCleaner {
fn fold_item(&mut self, i: P<ast::Item>)
-> SmallVector<P<ast::Item>> {
self.depth += 1;
let folded =
fold::noop_fold_item(i,
self).expect_one("noop did something");
self.depth -= 1;
let folded =
match entry::entry_point_type(&*folded, self.depth) {
EntryPointType::MainNamed | EntryPointType::MainAttr |
EntryPointType::Start =>
folded.map(|ast::Item { id, ident, attrs, node, vis, span
}| {
let allow_str = InternedString::new("allow");
let dead_code_str =
InternedString::new("dead_code");
let allow_dead_code_item =
attr::mk_list_item(allow_str,
<[_]>::into_vec(::std::boxed::Box::new([attr::mk_word_item(dead_code_str)])));
let allow_dead_code =
attr::mk_attr_outer(attr::mk_attr_id(),
allow_dead_code_item);
ast::Item{id: id,
ident: ident,
attrs:
attrs.into_iter().filter(|attr| {
!attr.check_name("main")
&&
!attr.check_name("start")
}).chain(iter::once(allow_dead_code)).collect(),
node: node,
vis: vis,
span: span,} }),
EntryPointType::None | EntryPointType::OtherMain =>
folded,
};
SmallVector::one(folded)
}
}
fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
tested_submods: Vec<(ast::Ident, ast::Ident)>)
-> (P<ast::Item>, ast::Ident) {
let super_ = token::str_to_ident("super");
let items =
tests.into_iter().map(|r| {
cx.ext_cx.item_use_simple(DUMMY_SP,
ast::Public,
cx.ext_cx.path(DUMMY_SP,
<[_]>::into_vec(::std::boxed::Box::new([super_,
r]))))
}).chain(tested_submods.into_iter().map(|(r,
sym)|
{
let path =
cx.ext_cx.path(DUMMY_SP,
<[_]>::into_vec(::std::boxed::Box::new([super_,
r,
sym])));
cx.ext_cx.item_use_simple_(DUMMY_SP,
ast::Public,
r,
path)
}));
let reexport_mod = ast::Mod{inner: DUMMY_SP, items: items.collect(),};
let sym = token::gensym_ident("__test_reexports");
let it =
P(ast::Item{ident: sym.clone(),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
node: ast::ItemMod(reexport_mod),
vis: ast::Public,
span: DUMMY_SP,});
(it, sym)
}
fn generate_test_harness(sess: &ParseSess,
reexport_test_harness_main:
Option<InternedString>, krate: ast::Crate,
cfg: &ast::CrateConfig, sd: &errors::Handler)
-> ast::Crate {
let mut cleaner = EntryPointCleaner{depth: 0,};
let krate = cleaner.fold_crate(krate);
let mut feature_gated_cfgs =
<[_]>::into_vec(::std::boxed::Box::new([]));
let mut cx: TestCtxt =
TestCtxt{sess: sess,
span_diagnostic: sd,
ext_cx:
ExtCtxt::new(sess, cfg.clone(),
ExpansionConfig::default("test".to_string()),
&mut feature_gated_cfgs),
path: Vec::new(),
testfns: Vec::new(),
reexport_test_harness_main: reexport_test_harness_main,
is_test_crate: is_test_crate(&krate),
config: krate.config.clone(),
toplevel_reexport: None,};
cx.ext_cx.crate_root = Some("std");
cx.ext_cx.bt_push(ExpnInfo{call_site: DUMMY_SP,
callee:
NameAndSpan{format:
MacroAttribute(intern("test")),
span: None,
allow_internal_unstable:
false,},});
let mut fold =
TestHarnessGenerator{cx: cx,
tests: Vec::new(),
tested_submods: Vec::new(),};
let res = fold.fold_crate(krate);
fold.cx.ext_cx.bt_pop();
return res;
}
fn strip_test_functions(diagnostic: &errors::Handler, krate: ast::Crate)
-> ast::Crate {
config::strip_items(diagnostic, krate, |attrs| {
!attr::contains_name(&attrs[..], "test") &&
!attr::contains_name(&attrs[..], "bench") })
}
/// Craft a span that will be ignored by the stability lint's
/// call to codemap's is_internal check.
/// The expanded code calls some unstable functions in the test crate.
fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
let info =
ExpnInfo{call_site: DUMMY_SP,
callee:
NameAndSpan{format: MacroAttribute(intern("test")),
span: None,
allow_internal_unstable: true,},};
let expn_id = cx.sess.codemap().record_expansion(info);
let mut sp = sp;
sp.expn_id = expn_id;
return sp;
}
enum HasTestSignature { Yes, No, NotEvenAFunction, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for HasTestSignature {
#[inline]
fn eq(&self, __arg_0: &HasTestSignature) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&HasTestSignature::Yes, &HasTestSignature::Yes) =>
true,
(&HasTestSignature::No, &HasTestSignature::No) =>
true,
(&HasTestSignature::NotEvenAFunction,
&HasTestSignature::NotEvenAFunction) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &HasTestSignature) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&HasTestSignature::Yes, &HasTestSignature::Yes) =>
false,
(&HasTestSignature::No, &HasTestSignature::No) =>
false,
(&HasTestSignature::NotEvenAFunction,
&HasTestSignature::NotEvenAFunction) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
let has_test_attr = attr::contains_name(&i.attrs, "test");
fn has_test_signature(i: &ast::Item) -> HasTestSignature {
match i.node {
ast::ItemFn(ref decl, _, _, _, ref generics, _) => {
let no_output =
match decl.output {
ast::DefaultReturn(..) => true,
ast::Return(ref t) if
t.node ==
ast::TyTup(<[_]>::into_vec(::std::boxed::Box::new([])))
=> true,
_ => false,
};
if decl.inputs.is_empty() && no_output &&
!generics.is_parameterized() {
Yes
} else { No }
}
_ => NotEvenAFunction,
}
}
if has_test_attr {
let diag = cx.span_diagnostic;
match has_test_signature(i) {
Yes => { }
No =>
diag.span_err(i.span,
"functions used as tests must have signature fn() -> ()"),
NotEvenAFunction =>
diag.span_err(i.span, "only functions may be used as tests"),
}
}
return has_test_attr && has_test_signature(i) == Yes;
}
fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
let has_bench_attr = attr::contains_name(&i.attrs, "bench");
fn has_test_signature(i: &ast::Item) -> bool {
match i.node {
ast::ItemFn(ref decl, _, _, _, ref generics, _) => {
let input_cnt = decl.inputs.len();
let no_output =
match decl.output {
ast::DefaultReturn(..) => true,
ast::Return(ref t) if
t.node ==
ast::TyTup(<[_]>::into_vec(::std::boxed::Box::new([])))
=> true,
_ => false,
};
let tparm_cnt = generics.ty_params.len();
input_cnt == 1 && no_output && tparm_cnt == 0
}
_ => false,
}
}
if has_bench_attr && !has_test_signature(i) {
let diag = cx.span_diagnostic;
diag.span_err(i.span,
"functions used as benches must have signature `fn(&mut Bencher) -> ()`");
}
return has_bench_attr && has_test_signature(i);
}
fn is_ignored(i: &ast::Item) -> bool {
i.attrs.iter().any(|attr| attr.check_name("ignore"))
}
fn should_panic(i: &ast::Item) -> ShouldPanic {
match i.attrs.iter().find(|attr| attr.check_name("should_panic")) {
Some(attr) => {
let msg =
attr.meta_item_list().and_then(|list|
list.iter().find(|mi|
mi.check_name("expected"))).and_then(|mi|
mi.value_str());
ShouldPanic::Yes(msg)
}
None => ShouldPanic::No,
}
}
fn mk_std(cx: &TestCtxt) -> P<ast::Item> {
let id_test = token::str_to_ident("test");
let (vi, vis, ident) =
if cx.is_test_crate {
(ast::ItemUse(P(nospan(ast::ViewPathSimple(id_test,
path_node(<[_]>::into_vec(::std::boxed::Box::new([id_test]))))))),
ast::Public, token::special_idents::invalid)
} else { (ast::ItemExternCrate(None), ast::Inherited, id_test) };
P(ast::Item{id: ast::DUMMY_NODE_ID,
ident: ident,
node: vi,
attrs: <[_]>::into_vec(::std::boxed::Box::new([])),
vis: vis,
span: DUMMY_SP,})
}
fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
let sp = ignored_span(cx, DUMMY_SP);
let ecx = &cx.ext_cx;
let test_main_path =
ecx.path(sp,
<[_]>::into_vec(::std::boxed::Box::new([token::str_to_ident("test"),
token::str_to_ident("test_main_static")])));
let test_main_path_expr = ecx.expr_path(test_main_path);
let tests_ident_expr =
ecx.expr_ident(sp, token::str_to_ident("TESTS"));
let call_test_main =
ecx.expr_call(sp, test_main_path_expr,
<[_]>::into_vec(::std::boxed::Box::new([tests_ident_expr])));
let call_test_main = ecx.stmt_expr(call_test_main);
let main_meta =
ecx.meta_word(sp, token::intern_and_get_ident("main"));
let main_attr = ecx.attribute(sp, main_meta);
let main_ret_ty =
ecx.ty(sp,
ast::TyTup(<[_]>::into_vec(::std::boxed::Box::new([]))));
let main_body =
ecx.block_all(sp,
<[_]>::into_vec(::std::boxed::Box::new([call_test_main])),
None);
let main =
ast::ItemFn(ecx.fn_decl(<[_]>::into_vec(::std::boxed::Box::new([])),
main_ret_ty), ast::Unsafety::Normal,
ast::Constness::NotConst, ::abi::Rust,
ast::Generics::default(), main_body);
let main =
P(ast::Item{ident: token::str_to_ident("main"),
attrs:
<[_]>::into_vec(::std::boxed::Box::new([main_attr])),
id: ast::DUMMY_NODE_ID,
node: main,
vis: ast::Public,
span: sp,});
return main;
}
fn mk_test_module(cx: &mut TestCtxt)
-> (P<ast::Item>, Option<P<ast::Item>>) {
let import = mk_std(cx);
let tests = mk_tests(cx);
let mainfn = mk_main(cx);
let testmod =
ast::Mod{inner: DUMMY_SP,
items:
<[_]>::into_vec(::std::boxed::Box::new([import,
mainfn,
tests])),};
let item_ = ast::ItemMod(testmod);
let mod_ident = token::gensym_ident("__test");
let item =
P(ast::Item{id: ast::DUMMY_NODE_ID,
ident: mod_ident,
attrs: <[_]>::into_vec(::std::boxed::Box::new([])),
node: item_,
vis: ast::Public,
span: DUMMY_SP,});
let reexport =
cx.reexport_test_harness_main.as_ref().map(|s| {
let reexport_ident =
token::str_to_ident(&s);
let use_path =
nospan(ast::ViewPathSimple(reexport_ident,
path_node(<[_]>::into_vec(::std::boxed::Box::new([mod_ident,
token::str_to_ident("main")])))));
P(ast::Item{id:
ast::DUMMY_NODE_ID,
ident:
token::special_idents::invalid,
attrs:
<[_]>::into_vec(::std::boxed::Box::new([])),
node:
ast::ItemUse(P(use_path)),
vis:
ast::Inherited,
span:
DUMMY_SP,})
});
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 559u32,
__file: "src/test.rs",
__module_path: "syntex_syntax::test",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::test", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["Synthetic test module:\n",
"\n"];
__STATIC_FMTSTR
},
&match (&pprust::item_to_string(&*item),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
(item, reexport)
}
fn nospan<T>(t: T) -> codemap::Spanned<T> {
codemap::Spanned{node: t, span: DUMMY_SP,}
}
fn path_node(ids: Vec<ast::Ident>) -> ast::Path {
ast::Path{span: DUMMY_SP,
global: false,
segments:
ids.into_iter().map(|identifier|
ast::PathSegment{identifier:
identifier,
parameters:
ast::PathParameters::none(),}).collect(),}
}
fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
let test_descs = mk_test_descs(cx);
let sp = DUMMY_SP;
let ecx = &cx.ext_cx;
let struct_type =
ecx.ty_path(ecx.path(sp,
<[_]>::into_vec(::std::boxed::Box::new([ecx.ident_of("self"),
ecx.ident_of("test"),
ecx.ident_of("TestDescAndFn")]))));
let static_lt =
ecx.lifetime(sp, token::special_idents::static_lifetime.name);
let static_type =
ecx.ty_rptr(sp, ecx.ty(sp, ast::TyVec(struct_type)),
Some(static_lt), ast::MutImmutable);
ecx.item_const(sp, ecx.ident_of("TESTS"), static_type, test_descs)
}
fn is_test_crate(krate: &ast::Crate) -> bool {
match attr::find_crate_name(&krate.attrs) {
Some(ref s) if "test" == &s[..] => true,
_ => false,
}
}
fn mk_test_descs(cx: &TestCtxt) -> P<ast::Expr> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 612u32,
__file: "src/test.rs",
__module_path: "syntex_syntax::test",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::test", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["building test vector from ",
" tests"];
__STATIC_FMTSTR
},
&match (&cx.testfns.len(),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
P(ast::Expr{id: ast::DUMMY_NODE_ID,
node:
ast::ExprAddrOf(ast::MutImmutable,
P(ast::Expr{id: ast::DUMMY_NODE_ID,
node:
ast::ExprVec(cx.testfns.iter().map(|test|
{
mk_test_desc_and_fn_rec(cx,
test)
}).collect()),
span: DUMMY_SP,
attrs: None,})),
span: DUMMY_SP,
attrs: None,})
}
fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
let span = ignored_span(cx, test.span);
let path = test.path.clone();
let ecx = &cx.ext_cx;
let self_id = ecx.ident_of("self");
let test_id = ecx.ident_of("test");
let test_path = |name| {
ecx.path(span,
<[_]>::into_vec(::std::boxed::Box::new([self_id, test_id,
ecx.ident_of(name)])))
};
let field =
|name, expr| ecx.field_imm(span, ecx.ident_of(name), expr);
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 648u32,
__file: "src/test.rs",
__module_path: "syntex_syntax::test",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::test", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["encoding "];
__STATIC_FMTSTR
},
&match (&ast_util::path_name_i(&path[..]),)
{
(__arg0,) =>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let path_string = ast_util::path_name_i(&path[..]);
let name_expr =
ecx.expr_str(span, token::intern_and_get_ident(&path_string[..]));
let name_expr =
ecx.expr_call(span, ecx.expr_path(test_path("StaticTestName")),
<[_]>::into_vec(::std::boxed::Box::new([name_expr])));
let ignore_expr = ecx.expr_bool(span, test.ignore);
let should_panic_path = |name| {
ecx.path(span,
<[_]>::into_vec(::std::boxed::Box::new([self_id, test_id,
ecx.ident_of("ShouldPanic"),
ecx.ident_of(name)])))
};
let fail_expr =
match test.should_panic {
ShouldPanic::No => ecx.expr_path(should_panic_path("No")),
ShouldPanic::Yes(ref msg) => {
match *msg {
Some(ref msg) => {
let msg = ecx.expr_str(span, msg.clone());
let path = should_panic_path("YesWithMessage");
ecx.expr_call(span, ecx.expr_path(path),
<[_]>::into_vec(::std::boxed::Box::new([msg])))
}
None => ecx.expr_path(should_panic_path("Yes")),
}
}
};
let desc_expr =
ecx.expr_struct(span, test_path("TestDesc"),
<[_]>::into_vec(::std::boxed::Box::new([field("name",
name_expr),
field("ignore",
ignore_expr),
field("should_panic",
fail_expr)])));
let mut visible_path =
match cx.toplevel_reexport {
Some(id) => <[_]>::into_vec(::std::boxed::Box::new([id])),
None => {
let diag = cx.span_diagnostic;
diag.bug("expected to find top-level re-export name, but found None");
}
};
visible_path.extend(path);
let fn_expr = ecx.expr_path(ecx.path_global(span, visible_path));
let variant_name =
if test.bench { "StaticBenchFn" } else { "StaticTestFn" };
let testfn_expr =
ecx.expr_call(span, ecx.expr_path(test_path(variant_name)),
<[_]>::into_vec(::std::boxed::Box::new([fn_expr])));
ecx.expr_struct(span, test_path("TestDescAndFn"),
<[_]>::into_vec(::std::boxed::Box::new([field("desc",
desc_expr),
field("testfn",
testfn_expr)])))
}
}
pub mod visit {
//! AST walker. Each overridden visit method has full control over what
//! happens with its node, it can do its own traversal of the node's children,
//! call `visit::walk_*` to apply the default traversal algorithm, or prevent
//! deeper traversal by doing nothing.
//!
//! Note: it is an important invariant that the default visitor walks the body
//! of a function in "execution order" (more concretely, reverse post-order
//! with respect to the CFG implied by the AST), meaning that if AST node A may
//! execute before AST node B, then A is visited first. The borrow checker in
//! particular relies on this property.
//!
//! Note: walking an AST before macro expansion is probably a bad idea. For
//! instance, a walker looking for item names in a module will miss all of
//! those that are created by the expansion of a macro.
#[prelude_import]
use std::prelude::v1::*;
use abi::Abi;
use ast::*;
use attr::ThinAttributesExt;
use codemap::Span;
pub enum FnKind<'a> {
/// fn foo() or extern "Abi" fn foo()
ItemFn(Ident, &'a Generics, Unsafety, Constness, Abi, Visibility),
/// fn foo(&self)
Method(Ident, &'a MethodSig, Option<Visibility>),
/// |x, y| {}
Closure,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <'a> ::std::cmp::Eq for FnKind<'a> {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
match (&*self,) {
(&FnKind::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
(*__self_3).assert_receiver_is_total_eq();
(*__self_4).assert_receiver_is_total_eq();
(*__self_5).assert_receiver_is_total_eq();
}
(&FnKind::Method(ref __self_0, ref __self_1, ref __self_2),)
=> {
(*__self_0).assert_receiver_is_total_eq();
(*__self_1).assert_receiver_is_total_eq();
(*__self_2).assert_receiver_is_total_eq();
}
(&FnKind::Closure,) => { }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <'a> ::std::cmp::PartialEq for FnKind<'a> {
#[inline]
fn eq(&self, __arg_0: &FnKind<'a>) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&FnKind::ItemFn(ref __self_0, ref __self_1,
ref __self_2, ref __self_3,
ref __self_4, ref __self_5),
&FnKind::ItemFn(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3,
ref __arg_1_4, ref __arg_1_5)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2) &&
(*__self_3) == (*__arg_1_3) &&
(*__self_4) == (*__arg_1_4) &&
(*__self_5) == (*__arg_1_5),
(&FnKind::Method(ref __self_0, ref __self_1,
ref __self_2),
&FnKind::Method(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&FnKind::Closure, &FnKind::Closure) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &FnKind<'a>) -> bool {
{
let __self_vi =
unsafe { ::std::intrinsics::discriminant_value(&*self) }
as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&FnKind::ItemFn(ref __self_0, ref __self_1,
ref __self_2, ref __self_3,
ref __self_4, ref __self_5),
&FnKind::ItemFn(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2, ref __arg_1_3,
ref __arg_1_4, ref __arg_1_5)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2) ||
(*__self_3) != (*__arg_1_3) ||
(*__self_4) != (*__arg_1_4) ||
(*__self_5) != (*__arg_1_5),
(&FnKind::Method(ref __self_0, ref __self_1,
ref __self_2),
&FnKind::Method(ref __arg_1_0, ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&FnKind::Closure, &FnKind::Closure) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <'a> ::std::clone::Clone for FnKind<'a> {
#[inline]
fn clone(&self) -> FnKind<'a> {
match (&*self,) {
(&FnKind::ItemFn(ref __self_0, ref __self_1, ref __self_2,
ref __self_3, ref __self_4, ref __self_5),)
=>
FnKind::ItemFn(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2)),
::std::clone::Clone::clone(&(*__self_3)),
::std::clone::Clone::clone(&(*__self_4)),
::std::clone::Clone::clone(&(*__self_5))),
(&FnKind::Method(ref __self_0, ref __self_1, ref __self_2),)
=>
FnKind::Method(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&FnKind::Closure,) => FnKind::Closure,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <'a> ::std::marker::Copy for FnKind<'a> { }
/// Each method of the Visitor trait is a hook to be potentially
/// overridden. Each method's default implementation recursively visits
/// the substructure of the input via the corresponding `walk` method;
/// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
///
/// If you want to ensure that your code handles every variant
/// explicitly, you need to override each method. (And you also need
/// to monitor future changes to `Visitor` in case a new method with a
/// new default implementation gets introduced.)
pub trait Visitor<'v>: Sized {
fn visit_name(&mut self, _span: Span, _name: Name) { }
fn visit_ident(&mut self, span: Span, ident: Ident) {
walk_ident(self, span, ident);
}
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) {
walk_mod(self, m)
}
fn visit_foreign_item(&mut self, i: &'v ForeignItem) {
walk_foreign_item(self, i)
}
fn visit_item(&mut self, i: &'v Item) { walk_item(self, i) }
fn visit_local(&mut self, l: &'v Local) { walk_local(self, l) }
fn visit_block(&mut self, b: &'v Block) { walk_block(self, b) }
fn visit_stmt(&mut self, s: &'v Stmt) { walk_stmt(self, s) }
fn visit_arm(&mut self, a: &'v Arm) { walk_arm(self, a) }
fn visit_pat(&mut self, p: &'v Pat) { walk_pat(self, p) }
fn visit_decl(&mut self, d: &'v Decl) { walk_decl(self, d) }
fn visit_expr(&mut self, ex: &'v Expr) { walk_expr(self, ex) }
fn visit_expr_post(&mut self, _ex: &'v Expr) { }
fn visit_ty(&mut self, t: &'v Ty) { walk_ty(self, t) }
fn visit_generics(&mut self, g: &'v Generics) {
walk_generics(self, g)
}
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block,
s: Span, _: NodeId) {
walk_fn(self, fk, fd, b, s)
}
fn visit_trait_item(&mut self, ti: &'v TraitItem) {
walk_trait_item(self, ti)
}
fn visit_impl_item(&mut self, ii: &'v ImplItem) {
walk_impl_item(self, ii)
}
fn visit_trait_ref(&mut self, t: &'v TraitRef) {
walk_trait_ref(self, t)
}
fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) {
walk_ty_param_bound(self, bounds)
}
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef,
m: &'v TraitBoundModifier) {
walk_poly_trait_ref(self, t, m)
}
fn visit_variant_data(&mut self, s: &'v VariantData, _: Ident,
_: &'v Generics, _: NodeId, _: Span) {
walk_struct_def(self, s)
}
fn visit_struct_field(&mut self, s: &'v StructField) {
walk_struct_field(self, s)
}
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef,
generics: &'v Generics, item_id: NodeId, _: Span) {
walk_enum_def(self, enum_definition, generics, item_id)
}
fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics,
item_id: NodeId) {
walk_variant(self, v, g, item_id)
}
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
}
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
walk_lifetime_def(self, lifetime)
}
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
walk_explicit_self(self, es)
}
fn visit_mac(&mut self, _mac: &'v Mac) {
{
::std::rt::begin_unwind("visit_mac disabled by default",
{
static _FILE_LINE:
(&'static str, u32) =
("src/visit.rs", 106u32);
&_FILE_LINE
})
};
}
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
walk_path(self, path)
}
fn visit_path_list_item(&mut self, prefix: &'v Path,
item: &'v PathListItem) {
walk_path_list_item(self, prefix, item)
}
fn visit_path_segment(&mut self, path_span: Span,
path_segment: &'v PathSegment) {
walk_path_segment(self, path_span, path_segment)
}
fn visit_path_parameters(&mut self, path_span: Span,
path_parameters: &'v PathParameters) {
walk_path_parameters(self, path_span, path_parameters)
}
fn visit_assoc_type_binding(&mut self,
type_binding: &'v TypeBinding) {
walk_assoc_type_binding(self, type_binding)
}
fn visit_attribute(&mut self, _attr: &'v Attribute) { }
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
walk_macro_def(self, macro_def)
}
}
pub fn walk_opt_name<'v,
V: Visitor<'v>>(visitor: &mut V, span: Span,
opt_name: Option<Name>) {
for name in opt_name { visitor.visit_name(span, name); }
}
pub fn walk_opt_ident<'v,
V: Visitor<'v>>(visitor: &mut V, span: Span,
opt_ident: Option<Ident>) {
for ident in opt_ident { visitor.visit_ident(span, ident); }
}
pub fn walk_ident<'v,
V: Visitor<'v>>(visitor: &mut V, span: Span,
ident: Ident) {
visitor.visit_name(span, ident.name);
}
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) {
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
for elem in &krate.attrs { visitor.visit_attribute(elem) };
for elem in &krate.exported_macros { visitor.visit_macro_def(elem) };
}
pub fn walk_macro_def<'v,
V: Visitor<'v>>(visitor: &mut V,
macro_def: &'v MacroDef) {
visitor.visit_ident(macro_def.span, macro_def.ident);
walk_opt_ident(visitor, macro_def.span, macro_def.imported_from);
for elem in ¯o_def.attrs { visitor.visit_attribute(elem) };
}
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) {
for elem in &module.items { visitor.visit_item(elem) };
}
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
visitor.visit_pat(&local.pat);
if let Some(ref elem) = *&local.ty { visitor.visit_ty(elem) };
if let Some(ref elem) = *&local.init { visitor.visit_expr(elem) };
}
pub fn walk_lifetime<'v,
V: Visitor<'v>>(visitor: &mut V,
lifetime: &'v Lifetime) {
visitor.visit_name(lifetime.span, lifetime.name);
}
pub fn walk_lifetime_def<'v,
V: Visitor<'v>>(visitor: &mut V,
lifetime_def: &'v LifetimeDef) {
visitor.visit_lifetime(&lifetime_def.lifetime);
for elem in &lifetime_def.bounds { visitor.visit_lifetime(elem) };
}
pub fn walk_explicit_self<'v,
V: Visitor<'v>>(visitor: &mut V,
explicit_self:
&'v ExplicitSelf) {
match explicit_self.node {
SelfStatic => { }
SelfValue(ident) => {
visitor.visit_ident(explicit_self.span, ident)
}
SelfRegion(ref opt_lifetime, _, ident) => {
visitor.visit_ident(explicit_self.span, ident);
if let Some(ref elem) = *opt_lifetime {
visitor.visit_lifetime(elem)
};
}
SelfExplicit(ref typ, ident) => {
visitor.visit_ident(explicit_self.span, ident);
visitor.visit_ty(typ)
}
}
}
pub fn walk_poly_trait_ref<'v,
V>(visitor: &mut V,
trait_ref: &'v PolyTraitRef,
_modifier: &'v TraitBoundModifier) where
V: Visitor<'v> {
for elem in &trait_ref.bound_lifetimes {
visitor.visit_lifetime_def(elem)
};
visitor.visit_trait_ref(&trait_ref.trait_ref);
}
pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
where V: Visitor<'v> {
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
}
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_ident(item.span, item.ident);
match item.node {
ItemExternCrate(opt_name) => {
walk_opt_name(visitor, item.span, opt_name)
}
ItemUse(ref vp) => {
match vp.node {
ViewPathSimple(ident, ref path) => {
visitor.visit_ident(vp.span, ident);
visitor.visit_path(path, item.id);
}
ViewPathGlob(ref path) => {
visitor.visit_path(path, item.id);
}
ViewPathList(ref prefix, ref list) => {
if !list.is_empty() {
for item in list {
visitor.visit_path_list_item(prefix, item)
}
} else { visitor.visit_path(prefix, item.id); }
}
}
}
ItemStatic(ref typ, _, ref expr) | ItemConst(ref typ, ref expr) =>
{
visitor.visit_ty(typ);
visitor.visit_expr(expr);
}
ItemFn(ref declaration, unsafety, constness, abi, ref generics,
ref body) => {
visitor.visit_fn(FnKind::ItemFn(item.ident, generics,
unsafety, constness, abi,
item.vis), declaration, body,
item.span, item.id)
}
ItemMod(ref module) => {
visitor.visit_mod(module, item.span, item.id)
}
ItemForeignMod(ref foreign_module) => {
for elem in &foreign_module.items {
visitor.visit_foreign_item(elem)
};
}
ItemTy(ref typ, ref type_parameters) => {
visitor.visit_ty(typ);
visitor.visit_generics(type_parameters)
}
ItemEnum(ref enum_definition, ref type_parameters) => {
visitor.visit_generics(type_parameters);
visitor.visit_enum_def(enum_definition, type_parameters,
item.id, item.span)
}
ItemDefaultImpl(_, ref trait_ref) => {
visitor.visit_trait_ref(trait_ref)
}
ItemImpl(_, _, ref type_parameters, ref opt_trait_reference,
ref typ, ref impl_items) => {
visitor.visit_generics(type_parameters);
if let Some(ref elem) = *opt_trait_reference {
visitor.visit_trait_ref(elem)
};
visitor.visit_ty(typ);
for elem in impl_items { visitor.visit_impl_item(elem) };
}
ItemStruct(ref struct_definition, ref generics) => {
visitor.visit_generics(generics);
visitor.visit_variant_data(struct_definition, item.ident,
generics, item.id, item.span);
}
ItemTrait(_, ref generics, ref bounds, ref methods) => {
visitor.visit_generics(generics);
for elem in bounds { visitor.visit_ty_param_bound(elem) };
for elem in methods { visitor.visit_trait_item(elem) };
}
ItemMac(ref mac) => visitor.visit_mac(mac),
}
for elem in &item.attrs { visitor.visit_attribute(elem) };
}
pub fn walk_enum_def<'v,
V: Visitor<'v>>(visitor: &mut V,
enum_definition: &'v EnumDef,
generics: &'v Generics,
item_id: NodeId) {
for elem in &enum_definition.variants {
visitor.visit_variant(elem, generics, item_id)
};
}
pub fn walk_variant<'v,
V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant,
generics: &'v Generics,
item_id: NodeId) {
visitor.visit_ident(variant.span, variant.node.name);
visitor.visit_variant_data(&variant.node.data, variant.node.name,
generics, item_id, variant.span);
if let Some(ref elem) = *&variant.node.disr_expr {
visitor.visit_expr(elem)
};
for elem in &variant.node.attrs { visitor.visit_attribute(elem) };
}
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
match typ.node {
TyVec(ref ty) | TyParen(ref ty) => { visitor.visit_ty(ty) }
TyPtr(ref mutable_type) => { visitor.visit_ty(&mutable_type.ty) }
TyRptr(ref opt_lifetime, ref mutable_type) => {
if let Some(ref elem) = *opt_lifetime {
visitor.visit_lifetime(elem)
};
visitor.visit_ty(&mutable_type.ty)
}
TyTup(ref tuple_element_types) => {
for elem in tuple_element_types { visitor.visit_ty(elem) };
}
TyBareFn(ref function_declaration) => {
walk_fn_decl(visitor, &function_declaration.decl);
for elem in &function_declaration.lifetimes {
visitor.visit_lifetime_def(elem)
};
}
TyPath(ref maybe_qself, ref path) => {
if let Some(ref qself) = *maybe_qself {
visitor.visit_ty(&qself.ty);
}
visitor.visit_path(path, typ.id);
}
TyObjectSum(ref ty, ref bounds) => {
visitor.visit_ty(ty);
for elem in bounds { visitor.visit_ty_param_bound(elem) };
}
TyFixedLengthVec(ref ty, ref expression) => {
visitor.visit_ty(ty);
visitor.visit_expr(expression)
}
TyPolyTraitRef(ref bounds) => {
for elem in bounds { visitor.visit_ty_param_bound(elem) };
}
TyTypeof(ref expression) => { visitor.visit_expr(expression) }
TyInfer => { }
TyMac(ref mac) => { visitor.visit_mac(mac) }
}
}
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
for segment in &path.segments {
visitor.visit_path_segment(path.span, segment);
}
}
pub fn walk_path_list_item<'v,
V: Visitor<'v>>(visitor: &mut V,
prefix: &'v Path,
item: &'v PathListItem) {
for segment in &prefix.segments {
visitor.visit_path_segment(prefix.span, segment);
}
walk_opt_ident(visitor, item.span, item.node.name());
walk_opt_ident(visitor, item.span, item.node.rename());
}
pub fn walk_path_segment<'v,
V: Visitor<'v>>(visitor: &mut V, path_span: Span,
segment: &'v PathSegment) {
visitor.visit_ident(path_span, segment.identifier);
visitor.visit_path_parameters(path_span, &segment.parameters);
}
pub fn walk_path_parameters<'v,
V: Visitor<'v>>(visitor: &mut V,
_path_span: Span,
path_parameters:
&'v PathParameters) {
match *path_parameters {
PathParameters::AngleBracketed(ref data) => {
for elem in &data.types { visitor.visit_ty(elem) };
for elem in &data.lifetimes { visitor.visit_lifetime(elem) };
for elem in &data.bindings {
visitor.visit_assoc_type_binding(elem)
};
}
PathParameters::Parenthesized(ref data) => {
for elem in &data.inputs { visitor.visit_ty(elem) };
if let Some(ref elem) = *&data.output {
visitor.visit_ty(elem)
};
}
}
}
pub fn walk_assoc_type_binding<'v,
V: Visitor<'v>>(visitor: &mut V,
type_binding:
&'v TypeBinding) {
visitor.visit_ident(type_binding.span, type_binding.ident);
visitor.visit_ty(&type_binding.ty);
}
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
match pattern.node {
PatEnum(ref path, ref opt_children) => {
visitor.visit_path(path, pattern.id);
if let Some(ref children) = *opt_children {
for elem in children { visitor.visit_pat(elem) };
}
}
PatQPath(ref qself, ref path) => {
visitor.visit_ty(&qself.ty);
visitor.visit_path(path, pattern.id)
}
PatStruct(ref path, ref fields, _) => {
visitor.visit_path(path, pattern.id);
for field in fields {
visitor.visit_ident(field.span, field.node.ident);
visitor.visit_pat(&field.node.pat)
}
}
PatTup(ref tuple_elements) => {
for elem in tuple_elements { visitor.visit_pat(elem) };
}
PatBox(ref subpattern) | PatRegion(ref subpattern, _) => {
visitor.visit_pat(subpattern)
}
PatIdent(_, ref pth1, ref optional_subpattern) => {
visitor.visit_ident(pth1.span, pth1.node);
if let Some(ref elem) = *optional_subpattern {
visitor.visit_pat(elem)
};
}
PatLit(ref expression) => visitor.visit_expr(expression),
PatRange(ref lower_bound, ref upper_bound) => {
visitor.visit_expr(lower_bound);
visitor.visit_expr(upper_bound)
}
PatWild => (),
PatVec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
for elem in prepatterns { visitor.visit_pat(elem) };
if let Some(ref elem) = *slice_pattern {
visitor.visit_pat(elem)
};
for elem in postpatterns { visitor.visit_pat(elem) };
}
PatMac(ref mac) => visitor.visit_mac(mac),
}
}
pub fn walk_foreign_item<'v,
V: Visitor<'v>>(visitor: &mut V,
foreign_item: &'v ForeignItem) {
visitor.visit_ident(foreign_item.span, foreign_item.ident);
match foreign_item.node {
ForeignItemFn(ref function_declaration, ref generics) => {
walk_fn_decl(visitor, function_declaration);
visitor.visit_generics(generics)
}
ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ),
}
for elem in &foreign_item.attrs { visitor.visit_attribute(elem) };
}
pub fn walk_ty_param_bound<'v,
V: Visitor<'v>>(visitor: &mut V,
bound: &'v TyParamBound) {
match *bound {
TraitTyParamBound(ref typ, ref modifier) => {
visitor.visit_poly_trait_ref(typ, modifier);
}
RegionTyParamBound(ref lifetime) => {
visitor.visit_lifetime(lifetime);
}
}
}
pub fn walk_generics<'v,
V: Visitor<'v>>(visitor: &mut V,
generics: &'v Generics) {
for param in &generics.ty_params {
visitor.visit_ident(param.span, param.ident);
for elem in ¶m.bounds { visitor.visit_ty_param_bound(elem) };
if let Some(ref elem) = *¶m.default {
visitor.visit_ty(elem)
};
}
for elem in &generics.lifetimes { visitor.visit_lifetime_def(elem) };
for predicate in &generics.where_clause.predicates {
match *predicate {
WherePredicate::BoundPredicate(WhereBoundPredicate {
ref bounded_ty,
ref bounds,
ref bound_lifetimes, .. }) => {
visitor.visit_ty(bounded_ty);
for elem in bounds { visitor.visit_ty_param_bound(elem) };
for elem in bound_lifetimes {
visitor.visit_lifetime_def(elem)
};
}
WherePredicate::RegionPredicate(WhereRegionPredicate {
ref lifetime, ref bounds, ..
}) => {
visitor.visit_lifetime(lifetime);
for elem in bounds { visitor.visit_lifetime(elem) };
}
WherePredicate::EqPredicate(WhereEqPredicate {
id, ref path, ref ty, .. }) => {
visitor.visit_path(path, id);
visitor.visit_ty(ty);
}
}
}
}
pub fn walk_fn_ret_ty<'v,
V: Visitor<'v>>(visitor: &mut V,
ret_ty: &'v FunctionRetTy) {
if let Return(ref output_ty) = *ret_ty { visitor.visit_ty(output_ty) }
}
pub fn walk_fn_decl<'v,
V: Visitor<'v>>(visitor: &mut V,
function_declaration: &'v FnDecl) {
for argument in &function_declaration.inputs {
visitor.visit_pat(&argument.pat);
visitor.visit_ty(&argument.ty)
}
walk_fn_ret_ty(visitor, &function_declaration.output)
}
pub fn walk_fn_kind<'v,
V: Visitor<'v>>(visitor: &mut V,
function_kind: FnKind<'v>) {
match function_kind {
FnKind::ItemFn(_, generics, _, _, _, _) => {
visitor.visit_generics(generics);
}
FnKind::Method(_, sig, _) => {
visitor.visit_generics(&sig.generics);
visitor.visit_explicit_self(&sig.explicit_self);
}
FnKind::Closure => { }
}
}
pub fn walk_fn<'v,
V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>,
function_declaration: &'v FnDecl,
function_body: &'v Block, _span: Span) {
walk_fn_decl(visitor, function_declaration);
walk_fn_kind(visitor, function_kind);
visitor.visit_block(function_body)
}
pub fn walk_trait_item<'v,
V: Visitor<'v>>(visitor: &mut V,
trait_item: &'v TraitItem) {
visitor.visit_ident(trait_item.span, trait_item.ident);
for elem in &trait_item.attrs { visitor.visit_attribute(elem) };
match trait_item.node {
ConstTraitItem(ref ty, ref default) => {
visitor.visit_ty(ty);
if let Some(ref elem) = *default { visitor.visit_expr(elem) };
}
MethodTraitItem(ref sig, None) => {
visitor.visit_explicit_self(&sig.explicit_self);
visitor.visit_generics(&sig.generics);
walk_fn_decl(visitor, &sig.decl);
}
MethodTraitItem(ref sig, Some(ref body)) => {
visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None),
&sig.decl, body, trait_item.span,
trait_item.id);
}
TypeTraitItem(ref bounds, ref default) => {
for elem in bounds { visitor.visit_ty_param_bound(elem) };
if let Some(ref elem) = *default { visitor.visit_ty(elem) };
}
}
}
pub fn walk_impl_item<'v,
V: Visitor<'v>>(visitor: &mut V,
impl_item: &'v ImplItem) {
visitor.visit_ident(impl_item.span, impl_item.ident);
for elem in &impl_item.attrs { visitor.visit_attribute(elem) };
match impl_item.node {
ImplItemKind::Const(ref ty, ref expr) => {
visitor.visit_ty(ty);
visitor.visit_expr(expr);
}
ImplItemKind::Method(ref sig, ref body) => {
visitor.visit_fn(FnKind::Method(impl_item.ident, sig,
Some(impl_item.vis)),
&sig.decl, body, impl_item.span,
impl_item.id);
}
ImplItemKind::Type(ref ty) => { visitor.visit_ty(ty); }
ImplItemKind::Macro(ref mac) => { visitor.visit_mac(mac); }
}
}
pub fn walk_struct_def<'v,
V: Visitor<'v>>(visitor: &mut V,
struct_definition:
&'v VariantData) {
for elem in struct_definition.fields() {
visitor.visit_struct_field(elem)
};
}
pub fn walk_struct_field<'v,
V: Visitor<'v>>(visitor: &mut V,
struct_field: &'v StructField) {
walk_opt_ident(visitor, struct_field.span, struct_field.node.ident());
visitor.visit_ty(&struct_field.node.ty);
for elem in &struct_field.node.attrs {
visitor.visit_attribute(elem)
};
}
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
for elem in &block.stmts { visitor.visit_stmt(elem) };
if let Some(ref elem) = *&block.expr { visitor.visit_expr(elem) };
}
pub fn walk_stmt<'v,
V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
match statement.node {
StmtDecl(ref declaration, _) => visitor.visit_decl(declaration),
StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
visitor.visit_expr(expression)
}
StmtMac(ref mac, _, ref attrs) => {
visitor.visit_mac(mac);
for attr in attrs.as_attr_slice() {
visitor.visit_attribute(attr);
}
}
}
}
pub fn walk_decl<'v,
V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) {
match declaration.node {
DeclLocal(ref local) => visitor.visit_local(local),
DeclItem(ref item) => visitor.visit_item(item),
}
}
pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) { }
pub fn walk_expr<'v,
V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
match expression.node {
ExprBox(ref subexpression) => {
visitor.visit_expr(subexpression)
}
ExprInPlace(ref place, ref subexpression) => {
visitor.visit_expr(place);
visitor.visit_expr(subexpression)
}
ExprVec(ref subexpressions) => {
for elem in subexpressions { visitor.visit_expr(elem) };
}
ExprRepeat(ref element, ref count) => {
visitor.visit_expr(element);
visitor.visit_expr(count)
}
ExprStruct(ref path, ref fields, ref optional_base) => {
visitor.visit_path(path, expression.id);
for field in fields {
visitor.visit_ident(field.ident.span, field.ident.node);
visitor.visit_expr(&field.expr)
}
if let Some(ref elem) = *optional_base {
visitor.visit_expr(elem)
};
}
ExprTup(ref subexpressions) => {
for elem in subexpressions { visitor.visit_expr(elem) };
}
ExprCall(ref callee_expression, ref arguments) => {
for elem in arguments { visitor.visit_expr(elem) };
visitor.visit_expr(callee_expression)
}
ExprMethodCall(ref ident, ref types, ref arguments) => {
visitor.visit_ident(ident.span, ident.node);
for elem in arguments { visitor.visit_expr(elem) };
for elem in types { visitor.visit_ty(elem) };
}
ExprBinary(_, ref left_expression, ref right_expression) => {
visitor.visit_expr(left_expression);
visitor.visit_expr(right_expression)
}
ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression)
=> {
visitor.visit_expr(subexpression)
}
ExprLit(_) => { }
ExprCast(ref subexpression, ref typ) |
ExprType(ref subexpression, ref typ) => {
visitor.visit_expr(subexpression);
visitor.visit_ty(typ)
}
ExprIf(ref head_expression, ref if_block, ref optional_else) => {
visitor.visit_expr(head_expression);
visitor.visit_block(if_block);
if let Some(ref elem) = *optional_else {
visitor.visit_expr(elem)
};
}
ExprWhile(ref subexpression, ref block, opt_ident) => {
visitor.visit_expr(subexpression);
visitor.visit_block(block);
walk_opt_ident(visitor, expression.span, opt_ident)
}
ExprIfLet(ref pattern, ref subexpression, ref if_block,
ref optional_else) => {
visitor.visit_pat(pattern);
visitor.visit_expr(subexpression);
visitor.visit_block(if_block);
if let Some(ref elem) = *optional_else {
visitor.visit_expr(elem)
};
}
ExprWhileLet(ref pattern, ref subexpression, ref block, opt_ident)
=> {
visitor.visit_pat(pattern);
visitor.visit_expr(subexpression);
visitor.visit_block(block);
walk_opt_ident(visitor, expression.span, opt_ident)
}
ExprForLoop(ref pattern, ref subexpression, ref block, opt_ident)
=> {
visitor.visit_pat(pattern);
visitor.visit_expr(subexpression);
visitor.visit_block(block);
walk_opt_ident(visitor, expression.span, opt_ident)
}
ExprLoop(ref block, opt_ident) => {
visitor.visit_block(block);
walk_opt_ident(visitor, expression.span, opt_ident)
}
ExprMatch(ref subexpression, ref arms) => {
visitor.visit_expr(subexpression);
for elem in arms { visitor.visit_arm(elem) };
}
ExprClosure(_, ref function_declaration, ref body) => {
visitor.visit_fn(FnKind::Closure, function_declaration, body,
expression.span, expression.id)
}
ExprBlock(ref block) => visitor.visit_block(block),
ExprAssign(ref left_hand_expression, ref right_hand_expression) =>
{
visitor.visit_expr(right_hand_expression);
visitor.visit_expr(left_hand_expression)
}
ExprAssignOp(_, ref left_expression, ref right_expression) => {
visitor.visit_expr(right_expression);
visitor.visit_expr(left_expression)
}
ExprField(ref subexpression, ref ident) => {
visitor.visit_expr(subexpression);
visitor.visit_ident(ident.span, ident.node);
}
ExprTupField(ref subexpression, _) => {
visitor.visit_expr(subexpression);
}
ExprIndex(ref main_expression, ref index_expression) => {
visitor.visit_expr(main_expression);
visitor.visit_expr(index_expression)
}
ExprRange(ref start, ref end) => {
if let Some(ref elem) = *start { visitor.visit_expr(elem) };
if let Some(ref elem) = *end { visitor.visit_expr(elem) };
}
ExprPath(ref maybe_qself, ref path) => {
if let Some(ref qself) = *maybe_qself {
visitor.visit_ty(&qself.ty);
}
visitor.visit_path(path, expression.id)
}
ExprBreak(ref opt_sp_ident) | ExprAgain(ref opt_sp_ident) => {
match *opt_sp_ident {
Some(sp_ident) => {
visitor.visit_ident(sp_ident.span, sp_ident.node);
}
None => { }
}
}
ExprRet(ref optional_expression) => {
if let Some(ref elem) = *optional_expression {
visitor.visit_expr(elem)
};
}
ExprMac(ref mac) => visitor.visit_mac(mac),
ExprParen(ref subexpression) => {
visitor.visit_expr(subexpression)
}
ExprInlineAsm(ref ia) => {
for &(_, ref input) in &ia.inputs {
visitor.visit_expr(&input)
}
for output in &ia.outputs { visitor.visit_expr(&output.expr) }
}
}
visitor.visit_expr_post(expression)
}
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
for elem in &arm.pats { visitor.visit_pat(elem) };
if let Some(ref elem) = *&arm.guard { visitor.visit_expr(elem) };
visitor.visit_expr(&arm.body);
for elem in &arm.attrs { visitor.visit_attribute(elem) };
}
}
pub mod print {
#[prelude_import]
use std::prelude::v1::*;
pub mod pp {
//! This pretty-printer is a direct reimplementation of Philip Karlton's
//! Mesa pretty-printer, as described in appendix A of
//!
//! ````ignore
//! STAN-CS-79-770: "Pretty Printing", by Derek C. Oppen.
//! Stanford Department of Computer Science, 1979.
//! ````
//!
//! The algorithm's aim is to break a stream into as few lines as possible
//! while respecting the indentation-consistency requirements of the enclosing
//! block, and avoiding breaking at silly places on block boundaries, for
//! example, between "x" and ")" in "x)".
//!
//! I am implementing this algorithm because it comes with 20 pages of
//! documentation explaining its theory, and because it addresses the set of
//! concerns I've seen other pretty-printers fall down on. Weirdly. Even though
//! it's 32 years old. What can I say?
//!
//! Despite some redundancies and quirks in the way it's implemented in that
//! paper, I've opted to keep the implementation here as similar as I can,
//! changing only what was blatantly wrong, a typo, or sufficiently
//! non-idiomatic rust that it really stuck out.
//!
//! In particular you'll see a certain amount of churn related to INTEGER vs.
//! CARDINAL in the Mesa implementation. Mesa apparently interconverts the two
//! somewhat readily? In any case, I've used usize for indices-in-buffers and
//! ints for character-sizes-and-indentation-offsets. This respects the need
//! for ints to "go negative" while carrying a pending-calculation balance, and
//! helps differentiate all the numbers flying around internally (slightly).
//!
//! I also inverted the indentation arithmetic used in the print stack, since
//! the Mesa implementation (somewhat randomly) stores the offset on the print
//! stack in terms of margin-col rather than col itself. I store col.
//!
//! I also implemented a small change in the String token, in that I store an
//! explicit length for the string. For most tokens this is just the length of
//! the accompanying string. But it's necessary to permit it to differ, for
//! encoding things that are supposed to "go on their own line" -- certain
//! classes of comment and blank-line -- where relying on adjacent
//! hardbreak-like Break tokens with long blankness indication doesn't actually
//! work. To see why, consider when there is a "thing that should be on its own
//! line" between two long blocks, say functions. If you put a hardbreak after
//! each function (or before each) and the breaking algorithm decides to break
//! there anyways (because the functions themselves are long) you wind up with
//! extra blank lines. If you don't put hardbreaks you can wind up with the
//! "thing which should be on its own line" not getting its own line in the
//! rare case of "really small functions" or such. This re-occurs with comments
//! and explicit blank lines. So in those cases we use a string with a payload
//! we want isolated to a line and an explicit length that's huge, surrounded
//! by two zero-length breaks. The algorithm will try its best to fit it on a
//! line (which it can't) and so naturally place the content on its own line to
//! avoid combining it with other lines and making matters even worse.
#[prelude_import]
use std::prelude::v1::*;
use std::io;
use std::string;
pub enum Breaks { Consistent, Inconsistent, }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for Breaks {
#[inline]
fn eq(&self, __arg_0: &Breaks) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Breaks::Consistent, &Breaks::Consistent) =>
true,
(&Breaks::Inconsistent, &Breaks::Inconsistent) =>
true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &Breaks) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&Breaks::Consistent, &Breaks::Consistent) =>
false,
(&Breaks::Inconsistent, &Breaks::Inconsistent) =>
false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for Breaks { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Breaks {
#[inline]
fn clone(&self) -> Breaks {
match (&*self,) {
(&Breaks::Consistent,) => Breaks::Consistent,
(&Breaks::Inconsistent,) => Breaks::Inconsistent,
}
}
}
pub struct BreakToken {
offset: isize,
blank_space: isize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BreakToken { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BreakToken {
#[inline]
fn clone(&self) -> BreakToken {
match *self {
BreakToken {
offset: ref __self_0_0, blank_space: ref __self_0_1 } =>
BreakToken{offset:
::std::clone::Clone::clone(&(*__self_0_0)),
blank_space:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct BeginToken {
offset: isize,
breaks: Breaks,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for BeginToken { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for BeginToken {
#[inline]
fn clone(&self) -> BeginToken {
match *self {
BeginToken {
offset: ref __self_0_0, breaks: ref __self_0_1 } =>
BeginToken{offset:
::std::clone::Clone::clone(&(*__self_0_0)),
breaks:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub enum Token {
String(String, isize),
Break(BreakToken),
Begin(BeginToken),
End,
Eof,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Token {
#[inline]
fn clone(&self) -> Token {
match (&*self,) {
(&Token::String(ref __self_0, ref __self_1),) =>
Token::String(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&Token::Break(ref __self_0),) =>
Token::Break(::std::clone::Clone::clone(&(*__self_0))),
(&Token::Begin(ref __self_0),) =>
Token::Begin(::std::clone::Clone::clone(&(*__self_0))),
(&Token::End,) => Token::End,
(&Token::Eof,) => Token::Eof,
}
}
}
impl Token {
pub fn is_eof(&self) -> bool {
match *self { Token::Eof => true, _ => false, }
}
pub fn is_hardbreak_tok(&self) -> bool {
match *self {
Token::Break(BreakToken { offset: 0, blank_space: bs }) if
bs == SIZE_INFINITY => true,
_ => false,
}
}
}
pub fn tok_str(token: &Token) -> String {
match *token {
Token::String(ref s, len) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["STR(",
",",
")"];
__STATIC_FMTSTR
},
&match (&s,
&len)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})),
Token::Break(_) => "BREAK".to_string(),
Token::Begin(_) => "BEGIN".to_string(),
Token::End => "END".to_string(),
Token::Eof => "EOF".to_string(),
}
}
pub fn buf_str(toks: &[Token], szs: &[isize], left: usize,
right: usize, lim: usize) -> String {
let n = toks.len();
{
match (&(n), &(szs.len())) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["assertion failed: `(left == right)` (left: `",
"`, right: `",
"`)"];
__STATIC_FMTSTR
},
&match (&left_val,
&right_val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pp.rs",
132u32);
&_FILE_LINE
})
}
}
}
}
};
let mut i = left;
let mut l = lim;
let mut s = string::String::from("[");
while i != right && l != 0 {
l -= 1;
if i != left { s.push_str(", "); }
s.push_str(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"="];
__STATIC_FMTSTR
},
&match (&szs[i],
&tok_str(&toks[i]))
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
i += 1;
i %= n;
}
s.push(']');
s
}
pub enum PrintStackBreak { Fits, Broken(Breaks), }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PrintStackBreak {
#[inline]
fn clone(&self) -> PrintStackBreak {
match (&*self,) {
(&PrintStackBreak::Fits,) => PrintStackBreak::Fits,
(&PrintStackBreak::Broken(ref __self_0),) =>
PrintStackBreak::Broken(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for PrintStackBreak { }
pub struct PrintStackElem {
offset: isize,
pbreak: PrintStackBreak,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PrintStackElem {
#[inline]
fn clone(&self) -> PrintStackElem {
match *self {
PrintStackElem {
offset: ref __self_0_0, pbreak: ref __self_0_1 } =>
PrintStackElem{offset:
::std::clone::Clone::clone(&(*__self_0_0)),
pbreak:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for PrintStackElem { }
const SIZE_INFINITY: isize = 65535;
pub fn mk_printer<'a>(out: Box<io::Write+ 'a>, linewidth: usize)
-> Printer<'a> {
let n: usize = 3 * linewidth;
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 169u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["mk_printer "];
__STATIC_FMTSTR
},
&match (&linewidth,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let token = ::std::vec::from_elem(Token::Eof, n);
let size = ::std::vec::from_elem(0isize, n);
let scan_stack = ::std::vec::from_elem(0usize, n);
Printer{out: out,
buf_len: n,
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
token: token,
size: size,
left_total: 0,
right_total: 0,
scan_stack: scan_stack,
scan_stack_empty: true,
top: 0,
bottom: 0,
print_stack: Vec::new(),
pending_indentation: 0,}
}
/// In case you do not have the paper, here is an explanation of what's going
/// on.
///
/// There is a stream of input tokens flowing through this printer.
///
/// The printer buffers up to 3N tokens inside itself, where N is linewidth.
/// Yes, linewidth is chars and tokens are multi-char, but in the worst
/// case every token worth buffering is 1 char long, so it's ok.
///
/// Tokens are String, Break, and Begin/End to delimit blocks.
///
/// Begin tokens can carry an offset, saying "how far to indent when you break
/// inside here", as well as a flag indicating "consistent" or "inconsistent"
/// breaking. Consistent breaking means that after the first break, no attempt
/// will be made to flow subsequent breaks together onto lines. Inconsistent
/// is the opposite. Inconsistent breaking example would be, say:
///
/// foo(hello, there, good, friends)
///
/// breaking inconsistently to become
///
/// foo(hello, there
/// good, friends);
///
/// whereas a consistent breaking would yield:
///
/// foo(hello,
/// there
/// good,
/// friends);
///
/// That is, in the consistent-break blocks we value vertical alignment
/// more than the ability to cram stuff onto a line. But in all cases if it
/// can make a block a one-liner, it'll do so.
///
/// Carrying on with high-level logic:
///
/// The buffered tokens go through a ring-buffer, 'tokens'. The 'left' and
/// 'right' indices denote the active portion of the ring buffer as well as
/// describing hypothetical points-in-the-infinite-stream at most 3N tokens
/// apart (i.e. "not wrapped to ring-buffer boundaries"). The paper will switch
/// between using 'left' and 'right' terms to denote the wrapped-to-ring-buffer
/// and point-in-infinite-stream senses freely.
///
/// There is a parallel ring buffer, 'size', that holds the calculated size of
/// each token. Why calculated? Because for Begin/End pairs, the "size"
/// includes everything between the pair. That is, the "size" of Begin is
/// actually the sum of the sizes of everything between Begin and the paired
/// End that follows. Since that is arbitrarily far in the future, 'size' is
/// being rewritten regularly while the printer runs; in fact most of the
/// machinery is here to work out 'size' entries on the fly (and give up when
/// they're so obviously over-long that "infinity" is a good enough
/// approximation for purposes of line breaking).
///
/// The "input side" of the printer is managed as an abstract process called
/// SCAN, which uses 'scan_stack', 'scan_stack_empty', 'top' and 'bottom', to
/// manage calculating 'size'. SCAN is, in other words, the process of
/// calculating 'size' entries.
///
/// The "output side" of the printer is managed by an abstract process called
/// PRINT, which uses 'print_stack', 'margin' and 'space' to figure out what to
/// do with each token/size pair it consumes as it goes. It's trying to consume
/// the entire buffered window, but can't output anything until the size is >=
/// 0 (sizes are set to negative while they're pending calculation).
///
/// So SCAN takes input and buffers tokens and pending calculations, while
/// PRINT gobbles up completed calculations and tokens from the buffer. The
/// theory is that the two can never get more than 3N tokens apart, because
/// once there's "obviously" too much data to fit on a line, in a size
/// calculation, SCAN will write "infinity" to the size and let PRINT consume
/// it.
///
/// In this implementation (following the paper, again) the SCAN process is
/// the method called 'pretty_print', and the 'PRINT' process is the method
/// called 'print'.
pub struct Printer<'a> {
pub out: Box<io::Write+ 'a>,
buf_len: usize,
/// Width of lines we're constrained to
margin: isize,
/// Number of spaces left on line
space: isize,
/// Index of left side of input stream
left: usize,
/// Index of right side of input stream
right: usize,
/// Ring-buffer stream goes through
token: Vec<Token>,
/// Ring-buffer of calculated sizes
size: Vec<isize>,
/// Running size of stream "...left"
left_total: isize,
/// Running size of stream "...right"
right_total: isize,
/// Pseudo-stack, really a ring too. Holds the
/// primary-ring-buffers index of the Begin that started the
/// current block, possibly with the most recent Break after that
/// Begin (if there is any) on top of it. Stuff is flushed off the
/// bottom as it becomes irrelevant due to the primary ring-buffer
/// advancing.
scan_stack: Vec<usize>,
/// Top==bottom disambiguator
scan_stack_empty: bool,
/// Index of top of scan_stack
top: usize,
/// Index of bottom of scan_stack
bottom: usize,
/// Stack of blocks-in-progress being flushed by print
print_stack: Vec<PrintStackElem>,
/// Buffered indentation to avoid writing trailing whitespace
pending_indentation: isize,
}
impl <'a> Printer<'a> {
pub fn last_token(&mut self) -> Token {
self.token[self.right].clone()
}
pub fn replace_last_token(&mut self, t: Token) {
self.token[self.right] = t;
}
pub fn pretty_print(&mut self, token: Token) -> io::Result<()> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 316u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&self.left,
&self.right)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
match token {
Token::Eof => {
if !self.scan_stack_empty {
self.check_stack(0);
match self.advance_left() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.indent(0);
Ok(())
}
Token::Begin(b) => {
if self.scan_stack_empty {
self.left_total = 1;
self.right_total = 1;
self.left = 0;
self.right = 0;
} else { self.advance_right(); }
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 333u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp Begin(",
")/buffer Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&b.offset,
&self.left,
&self.right)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
}
};
self.token[self.right] = token;
self.size[self.right] = -self.right_total;
let right = self.right;
self.scan_push(right);
Ok(())
}
Token::End => {
if self.scan_stack_empty {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 343u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp End/print Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&self.left,
&self.right)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
self.print(token, 0)
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 346u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp End/buffer Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&self.left,
&self.right)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
self.advance_right();
self.token[self.right] = token;
self.size[self.right] = -1;
let right = self.right;
self.scan_push(right);
Ok(())
}
}
Token::Break(b) => {
if self.scan_stack_empty {
self.left_total = 1;
self.right_total = 1;
self.left = 0;
self.right = 0;
} else { self.advance_right(); }
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 362u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp Break(",
")/buffer Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&b.offset,
&self.left,
&self.right)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
}
};
self.check_stack(0);
let right = self.right;
self.scan_push(right);
self.token[self.right] = token;
self.size[self.right] = -self.right_total;
self.right_total += b.blank_space;
Ok(())
}
Token::String(s, len) => {
if self.scan_stack_empty {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 374u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp String(\'",
"\')/print Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&s,
&self.left,
&self.right)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
}
};
self.print(Token::String(s, len), len)
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 378u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pp String(\'",
"\')/buffer Vec<",
",",
">"];
__STATIC_FMTSTR
},
&match (&s,
&self.left,
&self.right)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
}
};
self.advance_right();
self.token[self.right] = Token::String(s, len);
self.size[self.right] = len;
self.right_total += len;
self.check_stream()
}
}
}
}
pub fn check_stream(&mut self) -> io::Result<()> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 390u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["check_stream Vec<",
", ",
"> with left_total=",
", right_total="];
__STATIC_FMTSTR
},
&match (&self.left,
&self.right,
&self.left_total,
&self.right_total)
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt)],
}))
}
};
if self.right_total - self.left_total > self.space {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 393u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["scan window is ",
", longer than space on line (",
")"];
__STATIC_FMTSTR
},
&match (&(self.right_total
-
self.left_total),
&self.space)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
if !self.scan_stack_empty {
if self.left == self.scan_stack[self.bottom] {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 397u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["setting ",
" to infinity and popping"];
__STATIC_FMTSTR
},
&match (&self.left,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let scanned = self.scan_pop_bottom();
self.size[scanned] = SIZE_INFINITY;
}
}
match self.advance_left() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.left != self.right {
match self.check_stream() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
Ok(())
}
pub fn scan_push(&mut self, x: usize) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 410u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["scan_push "];
__STATIC_FMTSTR
},
&match (&x,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
if self.scan_stack_empty {
self.scan_stack_empty = false;
} else {
self.top += 1;
self.top %= self.buf_len;
if !(self.top != self.bottom) {
{
::std::rt::begin_unwind("assertion failed: (self.top != self.bottom)",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pp.rs",
416u32);
&_FILE_LINE
})
}
};
}
self.scan_stack[self.top] = x;
}
pub fn scan_pop(&mut self) -> usize {
if !(!self.scan_stack_empty) {
{
::std::rt::begin_unwind("assertion failed: (!self.scan_stack_empty)",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/print/pp.rs",
421u32);
&_FILE_LINE
})
}
};
let x = self.scan_stack[self.top];
if self.top == self.bottom {
self.scan_stack_empty = true;
} else {
self.top += self.buf_len - 1;
self.top %= self.buf_len;
}
return x;
}
pub fn scan_top(&mut self) -> usize {
if !(!self.scan_stack_empty) {
{
::std::rt::begin_unwind("assertion failed: (!self.scan_stack_empty)",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/print/pp.rs",
431u32);
&_FILE_LINE
})
}
};
return self.scan_stack[self.top];
}
pub fn scan_pop_bottom(&mut self) -> usize {
if !(!self.scan_stack_empty) {
{
::std::rt::begin_unwind("assertion failed: (!self.scan_stack_empty)",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/print/pp.rs",
435u32);
&_FILE_LINE
})
}
};
let x = self.scan_stack[self.bottom];
if self.top == self.bottom {
self.scan_stack_empty = true;
} else { self.bottom += 1; self.bottom %= self.buf_len; }
return x;
}
pub fn advance_right(&mut self) {
self.right += 1;
self.right %= self.buf_len;
if !(self.right != self.left) {
{
::std::rt::begin_unwind("assertion failed: (self.right != self.left)",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/print/pp.rs",
447u32);
&_FILE_LINE
})
}
};
}
pub fn advance_left(&mut self) -> io::Result<()> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 450u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["advance_left Vec<",
",",
">, sizeof(",
")="];
__STATIC_FMTSTR
},
&match (&self.left,
&self.right,
&self.left,
&self.size[self.left])
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt)],
}))
}
};
let mut left_size = self.size[self.left];
while left_size >= 0 {
let left = self.token[self.left].clone();
let len =
match left {
Token::Break(b) => b.blank_space,
Token::String(_, len) => {
{
match (&(len), &(left_size)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["assertion failed: `(left == right)` (left: `",
"`, right: `",
"`)"];
__STATIC_FMTSTR
},
&match (&left_val,
&right_val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/print/pp.rs",
461u32);
&_FILE_LINE
})
}
}
}
}
};
len
}
_ => 0,
};
match self.print(left, left_size) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.left_total += len;
if self.left == self.right { break ; }
self.left += 1;
self.left %= self.buf_len;
left_size = self.size[self.left];
}
Ok(())
}
pub fn check_stack(&mut self, k: isize) {
if !self.scan_stack_empty {
let x = self.scan_top();
match self.token[x] {
Token::Begin(_) => {
if k > 0 {
let popped = self.scan_pop();
self.size[popped] =
self.size[x] + self.right_total;
self.check_stack(k - 1);
}
}
Token::End => {
let popped = self.scan_pop();
self.size[popped] = 1;
self.check_stack(k + 1);
}
_ => {
let popped = self.scan_pop();
self.size[popped] =
self.size[x] + self.right_total;
if k > 0 { self.check_stack(k); }
}
}
}
}
pub fn print_newline(&mut self, amount: isize) -> io::Result<()> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 511u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["NEWLINE "];
__STATIC_FMTSTR
},
&match (&amount,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
let ret =
self.out.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\n"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}));
self.pending_indentation = 0;
self.indent(amount);
return ret;
}
pub fn indent(&mut self, amount: isize) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 518u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["INDENT "];
__STATIC_FMTSTR
},
&match (&amount,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
self.pending_indentation += amount;
}
pub fn get_top(&mut self) -> PrintStackElem {
let print_stack = &mut self.print_stack;
let n = print_stack.len();
if n != 0 {
(*print_stack)[n - 1]
} else {
PrintStackElem{offset: 0,
pbreak:
PrintStackBreak::Broken(Breaks::Inconsistent),}
}
}
pub fn print_str(&mut self, s: &str) -> io::Result<()> {
while self.pending_indentation > 0 {
match self.out.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[" "];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.pending_indentation -= 1;
}
self.out.write_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
pub fn print(&mut self, token: Token, l: isize)
-> io::Result<()> {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 541u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print ",
" ",
" (remaining line space=",
")"];
__STATIC_FMTSTR
},
&match (&tok_str(&token),
&l,
&self.space)
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
}))
}
};
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 543u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&buf_str(&self.token,
&self.size,
self.left,
self.right,
6),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
match token {
Token::Begin(b) => {
if l > self.space {
let col = self.margin - self.space + b.offset;
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 552u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print Begin -> push broken block at col "];
__STATIC_FMTSTR
},
&match (&col,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
self.print_stack.push(PrintStackElem{offset: col,
pbreak:
PrintStackBreak::Broken(b.breaks),});
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 558u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print Begin -> push fitting block"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
self.print_stack.push(PrintStackElem{offset: 0,
pbreak:
PrintStackBreak::Fits,});
}
Ok(())
}
Token::End => {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 567u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print End -> pop End"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}))
}
};
let print_stack = &mut self.print_stack;
if !(!print_stack.is_empty()) {
{
::std::rt::begin_unwind("assertion failed: (!print_stack.is_empty())",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pp.rs",
569u32);
&_FILE_LINE
})
}
};
print_stack.pop().unwrap();
Ok(())
}
Token::Break(b) => {
let top = self.get_top();
match top.pbreak {
PrintStackBreak::Fits => {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 577u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print Break(",
") in fitting block"];
__STATIC_FMTSTR
},
&match (&b.blank_space,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
self.space -= b.blank_space;
self.indent(b.blank_space);
Ok(())
}
PrintStackBreak::Broken(Breaks::Consistent) => {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 583u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print Break(",
"+",
") in consistent block"];
__STATIC_FMTSTR
},
&match (&top.offset,
&b.offset)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
let ret =
self.print_newline(top.offset + b.offset);
self.space =
self.margin - (top.offset + b.offset);
ret
}
PrintStackBreak::Broken(Breaks::Inconsistent) => {
if l > self.space {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 591u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level()
&&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print Break(",
"+",
") w/ newline in inconsistent"];
__STATIC_FMTSTR
},
&match (&top.offset,
&b.offset)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
};
let ret =
self.print_newline(top.offset +
b.offset);
self.space =
self.margin - (top.offset + b.offset);
ret
} else {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 597u32,
__file:
"src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level()
&&
lvl <= ::log::max_log_level() {
::log::__log(lvl,
"syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print Break(",
") w/o newline in inconsistent"];
__STATIC_FMTSTR
},
&match (&b.blank_space,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
self.indent(b.blank_space);
self.space -= b.blank_space;
Ok(())
}
}
}
}
Token::String(s, len) => {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 607u32,
__file: "src/print/pp.rs",
__module_path:
"syntex_syntax::print::pp",};
let lvl = ::log::LogLevel::Debug;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::print::pp",
&_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["print String(",
")"];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))
}
};
{
match (&(l), &(len)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["assertion failed: `(left == right)` (left: `",
"`, right: `",
"`)"];
__STATIC_FMTSTR
},
&match (&left_val,
&right_val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/print/pp.rs",
608u32);
&_FILE_LINE
})
}
}
}
}
};
self.space -= len;
self.print_str(&s[..])
}
Token::Eof => {
{
{
::std::rt::begin_unwind("explicit panic",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pp.rs",
615u32);
&_FILE_LINE
})
}
};
}
}
}
}
pub fn rbox(p: &mut Printer, indent: usize, b: Breaks)
-> io::Result<()> {
p.pretty_print(Token::Begin(BeginToken{offset: indent as isize,
breaks: b,}))
}
pub fn ibox(p: &mut Printer, indent: usize) -> io::Result<()> {
rbox(p, indent, Breaks::Inconsistent)
}
pub fn cbox(p: &mut Printer, indent: usize) -> io::Result<()> {
rbox(p, indent, Breaks::Consistent)
}
pub fn break_offset(p: &mut Printer, n: usize, off: isize)
-> io::Result<()> {
p.pretty_print(Token::Break(BreakToken{offset: off,
blank_space: n as isize,}))
}
pub fn end(p: &mut Printer) -> io::Result<()> {
p.pretty_print(Token::End)
}
pub fn eof(p: &mut Printer) -> io::Result<()> {
p.pretty_print(Token::Eof)
}
pub fn word(p: &mut Printer, wrd: &str) -> io::Result<()> {
p.pretty_print(Token::String(wrd.to_string(), wrd.len() as isize))
}
pub fn huge_word(p: &mut Printer, wrd: &str) -> io::Result<()> {
p.pretty_print(Token::String(wrd.to_string(), SIZE_INFINITY))
}
pub fn zero_word(p: &mut Printer, wrd: &str) -> io::Result<()> {
p.pretty_print(Token::String(wrd.to_string(), 0))
}
pub fn spaces(p: &mut Printer, n: usize) -> io::Result<()> {
break_offset(p, n, 0)
}
pub fn zerobreak(p: &mut Printer) -> io::Result<()> { spaces(p, 0) }
pub fn space(p: &mut Printer) -> io::Result<()> { spaces(p, 1) }
pub fn hardbreak(p: &mut Printer) -> io::Result<()> {
spaces(p, SIZE_INFINITY as usize)
}
pub fn hardbreak_tok_offset(off: isize) -> Token {
Token::Break(BreakToken{offset: off, blank_space: SIZE_INFINITY,})
}
pub fn hardbreak_tok() -> Token { hardbreak_tok_offset(0) }
}
pub mod pprust {
#[prelude_import]
use std::prelude::v1::*;
pub use self::AnnNode::*;
use abi;
use ast::{self, TokenTree};
use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::Attribute;
use attr::ThinAttributesExt;
use util::parser::AssocOp;
use attr;
use attr::{AttrMetaMethods, AttributeMethods};
use codemap::{self, CodeMap, BytePos};
use errors;
use parse::token::{self, BinOpToken, Token, InternedString};
use parse::lexer::comments;
use parse;
use print::pp::{self, break_offset, word, space, zerobreak,
hardbreak};
use print::pp::{Breaks, eof};
use print::pp::Breaks::{Consistent, Inconsistent};
use ptr::P;
use std_inject;
use str::slice_shift_char;
use std::ascii;
use std::io::{self, Write, Read};
use std::iter;
pub enum AnnNode<'a> {
NodeIdent(&'a ast::Ident),
NodeName(&'a ast::Name),
NodeBlock(&'a ast::Block),
NodeItem(&'a ast::Item),
NodeSubItem(ast::NodeId),
NodeExpr(&'a ast::Expr),
NodePat(&'a ast::Pat),
}
pub trait PpAnn {
fn pre(&self, _state: &mut State, _node: AnnNode)
-> io::Result<()> {
Ok(())
}
fn post(&self, _state: &mut State, _node: AnnNode)
-> io::Result<()> {
Ok(())
}
}
pub struct NoAnn;
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for NoAnn {
#[inline]
fn clone(&self) -> NoAnn { match *self { NoAnn => NoAnn, } }
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for NoAnn { }
impl PpAnn for NoAnn { }
pub struct CurrentCommentAndLiteral {
pub cur_cmnt: usize,
pub cur_lit: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for CurrentCommentAndLiteral {
#[inline]
fn clone(&self) -> CurrentCommentAndLiteral {
match *self {
CurrentCommentAndLiteral {
cur_cmnt: ref __self_0_0, cur_lit: ref __self_0_1 } =>
CurrentCommentAndLiteral{cur_cmnt:
::std::clone::Clone::clone(&(*__self_0_0)),
cur_lit:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for CurrentCommentAndLiteral { }
pub struct State<'a> {
pub s: pp::Printer<'a>,
cm: Option<&'a CodeMap>,
comments: Option<Vec<comments::Comment>>,
literals: Option<Vec<comments::Literal>>,
cur_cmnt_and_lit: CurrentCommentAndLiteral,
boxes: Vec<pp::Breaks>,
ann: &'a (PpAnn+ 'a),
}
pub fn rust_printer<'a>(writer: Box<Write+ 'a>) -> State<'a> {
static NO_ANN: NoAnn = NoAnn;
rust_printer_annotated(writer, &NO_ANN)
}
pub fn rust_printer_annotated<'a>(writer: Box<Write+ 'a>,
ann: &'a PpAnn) -> State<'a> {
State{s: pp::mk_printer(writer, DEFAULT_COLUMNS),
cm: None,
comments: None,
literals: None,
cur_cmnt_and_lit:
CurrentCommentAndLiteral{cur_cmnt: 0, cur_lit: 0,},
boxes: Vec::new(),
ann: ann,}
}
pub const INDENT_UNIT: usize = 4;
pub const DEFAULT_COLUMNS: usize = 78;
/// Requires you to pass an input filename and reader so that
/// 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,
krate: &ast::Crate, filename: String,
input: &mut Read, out: Box<Write+ 'a>,
ann: &'a PpAnn, is_expanded: bool)
-> io::Result<()> {
let mut s =
State::new_from_input(cm, span_diagnostic, filename, input,
out, ann, is_expanded);
if is_expanded && !std_inject::no_std(krate) {
let prelude_import_meta =
attr::mk_word_item(InternedString::new("prelude_import"));
let list =
attr::mk_list_item(InternedString::new("feature"),
<[_]>::into_vec(::std::boxed::Box::new([prelude_import_meta])));
let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), list);
match s.print_attribute(&fake_attr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let no_std_meta =
attr::mk_word_item(InternedString::new("no_std"));
let fake_attr =
attr::mk_attr_inner(attr::mk_attr_id(), no_std_meta);
match s.print_attribute(&fake_attr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match s.print_mod(&krate.module, &krate.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_remaining_comments() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
eof(&mut s.s)
}
impl <'a> State<'a> {
pub fn new_from_input(cm: &'a CodeMap,
span_diagnostic: &errors::Handler,
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);
State::new(cm, out, ann, Some(cmnts),
if is_expanded { None } else { Some(lits) })
}
pub fn new(cm: &'a CodeMap, out: Box<Write+ 'a>, ann: &'a PpAnn,
comments: Option<Vec<comments::Comment>>,
literals: Option<Vec<comments::Literal>>)
-> State<'a> {
State{s: pp::mk_printer(out, DEFAULT_COLUMNS),
cm: Some(cm),
comments: comments,
literals: literals,
cur_cmnt_and_lit:
CurrentCommentAndLiteral{cur_cmnt: 0, cur_lit: 0,},
boxes: Vec::new(),
ann: ann,}
}
}
pub fn to_string<F>(f: F) -> String where F: FnOnce(&mut State) ->
io::Result<()> {
let mut wr = Vec::new();
{
let mut printer = rust_printer(Box::new(&mut wr));
f(&mut printer).unwrap();
eof(&mut printer.s).unwrap();
}
String::from_utf8(wr).unwrap()
}
pub fn binop_to_string(op: BinOpToken) -> &'static str {
match op {
token::Plus => "+",
token::Minus => "-",
token::Star => "*",
token::Slash => "/",
token::Percent => "%",
token::Caret => "^",
token::And => "&",
token::Or => "|",
token::Shl => "<<",
token::Shr => ">>",
}
}
pub fn token_to_string(tok: &Token) -> String {
match *tok {
token::Eq => "=".to_string(),
token::Lt => "<".to_string(),
token::Le => "<=".to_string(),
token::EqEq => "==".to_string(),
token::Ne => "!=".to_string(),
token::Ge => ">=".to_string(),
token::Gt => ">".to_string(),
token::Not => "!".to_string(),
token::Tilde => "~".to_string(),
token::OrOr => "||".to_string(),
token::AndAnd => "&&".to_string(),
token::BinOp(op) => binop_to_string(op).to_string(),
token::BinOpEq(op) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"="];
__STATIC_FMTSTR
},
&match (&binop_to_string(op),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::At => "@".to_string(),
token::Dot => ".".to_string(),
token::DotDot => "..".to_string(),
token::DotDotDot => "...".to_string(),
token::Comma => ",".to_string(),
token::Semi => ";".to_string(),
token::Colon => ":".to_string(),
token::ModSep => "::".to_string(),
token::RArrow => "->".to_string(),
token::LArrow => "<-".to_string(),
token::FatArrow => "=>".to_string(),
token::OpenDelim(token::Paren) => "(".to_string(),
token::CloseDelim(token::Paren) => ")".to_string(),
token::OpenDelim(token::Bracket) => "[".to_string(),
token::CloseDelim(token::Bracket) => "]".to_string(),
token::OpenDelim(token::Brace) => "{".to_string(),
token::CloseDelim(token::Brace) => "}".to_string(),
token::Pound => "#".to_string(),
token::Dollar => "$".to_string(),
token::Question => "?".to_string(),
token::Literal(lit, suf) => {
let mut out =
match lit {
token::Byte(b) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["b\'",
"\'"];
__STATIC_FMTSTR
},
&match (&b,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::Char(c) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\'",
"\'"];
__STATIC_FMTSTR
},
&match (&c,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::Float(c) => c.to_string(),
token::Integer(c) => c.to_string(),
token::Str_(s) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\"",
"\""];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::StrRaw(s, n) =>
::std::fmt::format(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["r",
"\"",
"\""];
__STATIC_FMTSTR
},
&match (&repeat("#",
n),
&s)
{
(__argdelim,
__argstring)
=>
[::std::fmt::ArgumentV1::new(__argdelim,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__argstring,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
})),
token::ByteStr(v) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["b\"",
"\""];
__STATIC_FMTSTR
},
&match (&v,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::ByteStrRaw(s, n) =>
::std::fmt::format(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["br",
"\"",
"\""];
__STATIC_FMTSTR
},
&match (&repeat("#",
n),
&s)
{
(__argdelim,
__argstring)
=>
[::std::fmt::ArgumentV1::new(__argdelim,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__argstring,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
})),
};
if let Some(s) = suf { out.push_str(&s.as_str()) }
out
}
token::Ident(s, _) => s.to_string(),
token::Lifetime(s) => s.to_string(),
token::Underscore => "_".to_string(),
token::DocComment(s) => s.to_string(),
token::SubstNt(s, _) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["$"];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::MatchNt(s, t, _, _) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["$",
":"];
__STATIC_FMTSTR
},
&match (&s,
&t) {
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})),
token::Eof => "<eof>".to_string(),
token::Whitespace => " ".to_string(),
token::Comment => "/* */".to_string(),
token::Shebang(s) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["/* shebang: ",
"*/"];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::SpecialVarNt(var) =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["$"];
__STATIC_FMTSTR
},
&match (&var.as_str(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
token::Interpolated(ref nt) =>
match *nt {
token::NtExpr(ref e) => expr_to_string(&**e),
token::NtMeta(ref e) => meta_item_to_string(&**e),
token::NtTy(ref e) => ty_to_string(&**e),
token::NtPath(ref e) => path_to_string(&**e),
token::NtItem(ref e) => item_to_string(&**e),
token::NtBlock(ref e) => block_to_string(&**e),
token::NtStmt(ref e) => stmt_to_string(&**e),
token::NtPat(ref e) => pat_to_string(&**e),
token::NtIdent(ref e, _) => ident_to_string(e.node),
token::NtTT(ref e) => tt_to_string(&**e),
token::NtArm(ref e) => arm_to_string(&*e),
token::NtImplItem(ref e) => impl_item_to_string(&**e),
token::NtTraitItem(ref e) => trait_item_to_string(&**e),
token::NtGenerics(ref e) => generics_to_string(&*e),
token::NtWhereClause(ref e) =>
where_clause_to_string(&*e),
token::NtArg(ref e) => arg_to_string(&*e),
},
}
}
pub fn ty_to_string(ty: &ast::Ty) -> String {
to_string(|s| s.print_type(ty))
}
pub fn ty_param_to_string(param: &ast::TyParam) -> String {
to_string(|s| s.print_ty_param(param))
}
pub fn bounds_to_string(bounds: &[ast::TyParamBound]) -> String {
to_string(|s| s.print_bounds("", bounds))
}
pub fn pat_to_string(pat: &ast::Pat) -> String {
to_string(|s| s.print_pat(pat))
}
pub fn arm_to_string(arm: &ast::Arm) -> String {
to_string(|s| s.print_arm(arm))
}
pub fn expr_to_string(e: &ast::Expr) -> String {
to_string(|s| s.print_expr(e))
}
pub fn lifetime_to_string(e: &ast::Lifetime) -> String {
to_string(|s| s.print_lifetime(e))
}
pub fn tt_to_string(tt: &ast::TokenTree) -> String {
to_string(|s| s.print_tt(tt))
}
pub fn tts_to_string(tts: &[ast::TokenTree]) -> String {
to_string(|s| s.print_tts(tts))
}
pub fn stmt_to_string(stmt: &ast::Stmt) -> String {
to_string(|s| s.print_stmt(stmt))
}
pub fn attr_to_string(attr: &ast::Attribute) -> String {
to_string(|s| s.print_attribute(attr))
}
pub fn item_to_string(i: &ast::Item) -> String {
to_string(|s| s.print_item(i))
}
pub fn impl_item_to_string(i: &ast::ImplItem) -> String {
to_string(|s| s.print_impl_item(i))
}
pub fn trait_item_to_string(i: &ast::TraitItem) -> String {
to_string(|s| s.print_trait_item(i))
}
pub fn generics_to_string(generics: &ast::Generics) -> String {
to_string(|s| s.print_generics(generics))
}
pub fn where_clause_to_string(i: &ast::WhereClause) -> String {
to_string(|s| s.print_where_clause(i))
}
pub fn fn_block_to_string(p: &ast::FnDecl) -> String {
to_string(|s| s.print_fn_block_args(p))
}
pub fn path_to_string(p: &ast::Path) -> String {
to_string(|s| s.print_path(p, false, 0))
}
pub fn ident_to_string(id: ast::Ident) -> String {
to_string(|s| s.print_ident(id))
}
pub fn fun_to_string(decl: &ast::FnDecl, unsafety: ast::Unsafety,
constness: ast::Constness, name: ast::Ident,
opt_explicit_self: Option<&ast::ExplicitSelf_>,
generics: &ast::Generics) -> String {
to_string(|s| {
match s.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_fn(decl, unsafety, constness, abi::Rust,
Some(name), generics,
opt_explicit_self, ast::Inherited) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; s.end() })
}
pub fn block_to_string(blk: &ast::Block) -> String {
to_string(|s| {
match s.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; s.print_block(blk) })
}
pub fn meta_item_to_string(mi: &ast::MetaItem) -> String {
to_string(|s| s.print_meta_item(mi))
}
pub fn attribute_to_string(attr: &ast::Attribute) -> String {
to_string(|s| s.print_attribute(attr))
}
pub fn lit_to_string(l: &ast::Lit) -> String {
to_string(|s| s.print_literal(l))
}
pub fn explicit_self_to_string(explicit_self: &ast::ExplicitSelf_)
-> String {
to_string(|s|
s.print_explicit_self(explicit_self,
ast::MutImmutable).map(|_| {
}))
}
pub fn variant_to_string(var: &ast::Variant) -> String {
to_string(|s| s.print_variant(var))
}
pub fn arg_to_string(arg: &ast::Arg) -> String {
to_string(|s| s.print_arg(arg))
}
pub fn mac_to_string(arg: &ast::Mac) -> String {
to_string(|s| s.print_mac(arg, ::parse::token::Paren))
}
pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String {
match vis {
ast::Public =>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["pub "];
__STATIC_FMTSTR
},
&match (&s,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
ast::Inherited => s.to_string(),
}
}
fn needs_parentheses(expr: &ast::Expr) -> bool {
match expr.node {
ast::ExprAssign(..) | ast::ExprBinary(..) |
ast::ExprClosure(..) | ast::ExprAssignOp(..) |
ast::ExprCast(..) | ast::ExprInPlace(..) | ast::ExprType(..)
=> true,
_ => false,
}
}
pub trait PrintState<'a> {
fn writer(&mut self)
-> &mut pp::Printer<'a>;
fn boxes(&mut self)
-> &mut Vec<pp::Breaks>;
fn comments(&mut self)
-> &mut Option<Vec<comments::Comment>>;
fn cur_cmnt_and_lit(&mut self)
-> &mut CurrentCommentAndLiteral;
fn literals(&self)
-> &Option<Vec<comments::Literal>>;
fn word_space(&mut self, w: &str) -> io::Result<()> {
match word(self.writer(), w) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
space(self.writer())
}
fn popen(&mut self) -> io::Result<()> { word(self.writer(), "(") }
fn pclose(&mut self) -> io::Result<()> {
word(self.writer(), ")")
}
fn is_begin(&mut self) -> bool {
match self.writer().last_token() {
pp::Token::Begin(_) => true,
_ => false,
}
}
fn is_end(&mut self) -> bool {
match self.writer().last_token() {
pp::Token::End => true,
_ => false,
}
}
fn is_bol(&mut self) -> bool {
self.writer().last_token().is_eof() ||
self.writer().last_token().is_hardbreak_tok()
}
fn hardbreak_if_not_bol(&mut self) -> io::Result<()> {
if !self.is_bol() {
match hardbreak(self.writer()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
Ok(())
}
fn rbox(&mut self, u: usize, b: pp::Breaks) -> io::Result<()> {
self.boxes().push(b);
pp::rbox(self.writer(), u, b)
}
fn ibox(&mut self, u: usize) -> io::Result<()> {
self.boxes().push(pp::Breaks::Inconsistent);
pp::ibox(self.writer(), u)
}
fn end(&mut self) -> io::Result<()> {
self.boxes().pop().unwrap();
pp::end(self.writer())
}
fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F)
-> io::Result<()> where F: FnMut(&mut Self, &T) ->
io::Result<()> {
match self.rbox(0, b) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut first = true;
for elt in elts {
if first {
first = false;
} else {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match op(self, elt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.end()
}
fn next_lit(&mut self, pos: BytePos)
-> Option<comments::Literal> {
let mut cur_lit = self.cur_cmnt_and_lit().cur_lit;
let mut result = None;
if let &Some(ref lits) = self.literals() {
while cur_lit < lits.len() {
let ltrl = (*lits)[cur_lit].clone();
if ltrl.pos > pos { break ; }
cur_lit += 1;
if ltrl.pos == pos { result = Some(ltrl); break ; }
}
}
self.cur_cmnt_and_lit().cur_lit = cur_lit;
result
}
fn maybe_print_comment(&mut self, pos: BytePos)
-> io::Result<()> {
loop {
match self.next_comment() {
Some(ref cmnt) => {
if (*cmnt).pos < pos {
match self.print_comment(cmnt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.cur_cmnt_and_lit().cur_cmnt += 1;
} else { break ; }
}
_ => break ,
}
}
Ok(())
}
fn print_comment(&mut self, cmnt: &comments::Comment)
-> io::Result<()> {
match cmnt.style {
comments::Mixed => {
{
match (&(cmnt.lines.len()), &(1)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["assertion failed: `(left == right)` (left: `",
"`, right: `",
"`)"];
__STATIC_FMTSTR
},
&match (&left_val,
&right_val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/print/pprust.rs",
568u32);
&_FILE_LINE
})
}
}
}
}
};
match zerobreak(self.writer()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(self.writer(), &cmnt.lines[0]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
zerobreak(self.writer())
}
comments::Isolated => {
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for line in &cmnt.lines {
if !line.is_empty() {
match word(self.writer(), &line[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match hardbreak(self.writer()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
comments::Trailing => {
match word(self.writer(), " ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if cmnt.lines.len() == 1 {
match word(self.writer(), &cmnt.lines[0]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
hardbreak(self.writer())
} else {
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for line in &cmnt.lines {
if !line.is_empty() {
match word(self.writer(), &line[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match hardbreak(self.writer()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.end()
}
}
comments::BlankLine => {
let is_semi =
match self.writer().last_token() {
pp::Token::String(s, _) => ";" == s,
_ => false,
};
if is_semi || self.is_begin() || self.is_end() {
match hardbreak(self.writer()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
hardbreak(self.writer())
}
}
}
fn next_comment(&mut self) -> Option<comments::Comment> {
let cur_cmnt = self.cur_cmnt_and_lit().cur_cmnt;
match *self.comments() {
Some(ref cmnts) => {
if cur_cmnt < cmnts.len() {
Some(cmnts[cur_cmnt].clone())
} else { None }
}
_ => None,
}
}
fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> {
match self.maybe_print_comment(lit.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.next_lit(lit.span.lo) {
Some(ref ltrl) => {
return word(self.writer(), &(*ltrl).lit);
}
_ => (),
}
match lit.node {
ast::LitStr(ref st, style) =>
self.print_string(&st, style),
ast::LitByte(byte) => {
let mut res = String::from("b\'");
res.extend(ascii::escape_default(byte).map(|c|
c as
char));
res.push('\'');
word(self.writer(), &res[..])
}
ast::LitChar(ch) => {
let mut res = String::from("\'");
res.extend(ch.escape_default());
res.push('\'');
word(self.writer(), &res[..])
}
ast::LitInt(i, t) => {
match t {
ast::SignedIntLit(st, ast::Plus) => {
word(self.writer(),
&st.val_to_string(i as i64))
}
ast::SignedIntLit(st, ast::Minus) => {
let istr = st.val_to_string(-(i as i64));
word(self.writer(),
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["-"];
__STATIC_FMTSTR
},
&match (&istr,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
ast::UnsignedIntLit(ut) => {
word(self.writer(), &ut.val_to_string(i))
}
ast::UnsuffixedIntLit(ast::Plus) => {
word(self.writer(),
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&i,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
ast::UnsuffixedIntLit(ast::Minus) => {
word(self.writer(),
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["-"];
__STATIC_FMTSTR
},
&match (&i,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
}
}
ast::LitFloat(ref f, t) => {
word(self.writer(),
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
""];
__STATIC_FMTSTR
},
&match (&&f,
&t.ty_to_string())
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})))
}
ast::LitFloatUnsuffixed(ref f) =>
word(self.writer(), &f[..]),
ast::LitBool(val) => {
if val {
word(self.writer(), "true")
} else { word(self.writer(), "false") }
}
ast::LitByteStr(ref v) => {
let mut escaped: String = String::new();
for &ch in v.iter() {
escaped.extend(ascii::escape_default(ch).map(|c|
c
as
char));
}
word(self.writer(),
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["b\"",
"\""];
__STATIC_FMTSTR
},
&match (&escaped,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
}
}
fn print_string(&mut self, st: &str, style: ast::StrStyle)
-> io::Result<()> {
let st =
match style {
ast::CookedStr => {
(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\"",
"\""];
__STATIC_FMTSTR
},
&match (&st.chars().flat_map(char::escape_default).collect::<String>(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
ast::RawStr(n) => {
(::std::fmt::format(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["r",
"\"",
"\""];
__STATIC_FMTSTR
},
&match (&repeat("#",
n),
&st)
{
(__argdelim,
__argstring)
=>
[::std::fmt::ArgumentV1::new(__argdelim,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__argstring,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
})))
}
};
word(self.writer(), &st[..])
}
fn print_inner_attributes(&mut self, attrs: &[ast::Attribute])
-> io::Result<()> {
self.print_either_attributes(attrs, ast::AttrStyle::Inner,
false, true)
}
fn print_inner_attributes_no_trailing_hardbreak(&mut self,
attrs:
&[ast::Attribute])
-> io::Result<()> {
self.print_either_attributes(attrs, ast::AttrStyle::Inner,
false, false)
}
fn print_outer_attributes(&mut self, attrs: &[ast::Attribute])
-> io::Result<()> {
self.print_either_attributes(attrs, ast::AttrStyle::Outer,
false, true)
}
fn print_inner_attributes_inline(&mut self,
attrs: &[ast::Attribute])
-> io::Result<()> {
self.print_either_attributes(attrs, ast::AttrStyle::Inner,
true, true)
}
fn print_outer_attributes_inline(&mut self,
attrs: &[ast::Attribute])
-> io::Result<()> {
self.print_either_attributes(attrs, ast::AttrStyle::Outer,
true, true)
}
fn print_either_attributes(&mut self, attrs: &[ast::Attribute],
kind: ast::AttrStyle, is_inline: bool,
trailing_hardbreak: bool)
-> io::Result<()> {
let mut count = 0;
for attr in attrs {
if attr.node.style == kind {
match self.print_attribute_inline(attr, is_inline) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if is_inline {
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
count += 1;
}
}
if count > 0 && trailing_hardbreak && !is_inline {
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
fn print_attribute(&mut self, attr: &ast::Attribute)
-> io::Result<()> {
self.print_attribute_inline(attr, false)
}
fn print_attribute_inline(&mut self, attr: &ast::Attribute,
is_inline: bool) -> io::Result<()> {
if !is_inline {
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.maybe_print_comment(attr.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if attr.node.is_sugared_doc {
word(self.writer(), &attr.value_str().unwrap())
} else {
match attr.node.style {
ast::AttrStyle::Inner =>
match word(self.writer(), "#![") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::AttrStyle::Outer =>
match word(self.writer(), "#[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
match self.print_meta_item(&*attr.meta()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
word(self.writer(), "]")
}
}
fn print_meta_item(&mut self, item: &ast::MetaItem)
-> io::Result<()> {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match item.node {
ast::MetaWord(ref name) => {
match word(self.writer(), &name) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::MetaNameValue(ref name, ref value) => {
match self.word_space(&name[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_literal(value) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::MetaList(ref name, ref items) => {
match word(self.writer(), &name) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Consistent, &items[..],
|s, i| s.print_meta_item(&**i)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.end()
}
fn space_if_not_bol(&mut self) -> io::Result<()> {
if !self.is_bol() {
match space(self.writer()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
fn nbsp(&mut self) -> io::Result<()> { word(self.writer(), " ") }
}
impl <'a> PrintState<'a> for State<'a> {
fn writer(&mut self) -> &mut pp::Printer<'a> { &mut self.s }
fn boxes(&mut self) -> &mut Vec<pp::Breaks> { &mut self.boxes }
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
&mut self.comments
}
fn cur_cmnt_and_lit(&mut self) -> &mut CurrentCommentAndLiteral {
&mut self.cur_cmnt_and_lit
}
fn literals(&self) -> &Option<Vec<comments::Literal>> {
&self.literals
}
}
impl <'a> State<'a> {
pub fn cbox(&mut self, u: usize) -> io::Result<()> {
self.boxes.push(pp::Breaks::Consistent);
pp::cbox(&mut self.s, u)
}
pub fn word_nbsp(&mut self, w: &str) -> io::Result<()> {
match word(&mut self.s, w) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.nbsp()
}
pub fn head(&mut self, w: &str) -> io::Result<()> {
match self.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(w.len() + 1) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !w.is_empty() {
match self.word_nbsp(w) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
pub fn bopen(&mut self) -> io::Result<()> {
match word(&mut self.s, "{") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
pub fn bclose_(&mut self, span: codemap::Span, indented: usize)
-> io::Result<()> {
self.bclose_maybe_open(span, indented, true)
}
pub fn bclose_maybe_open(&mut self, span: codemap::Span,
indented: usize, close_box: bool)
-> io::Result<()> {
match self.maybe_print_comment(span.hi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.break_offset_if_not_bol(1, -(indented as isize)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "}") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if close_box {
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
pub fn bclose(&mut self, span: codemap::Span) -> io::Result<()> {
self.bclose_(span, INDENT_UNIT)
}
pub fn in_cbox(&self) -> bool {
match self.boxes.last() {
Some(&last_box) => last_box == pp::Breaks::Consistent,
None => false,
}
}
pub fn break_offset_if_not_bol(&mut self, n: usize, off: isize)
-> io::Result<()> {
if !self.is_bol() {
break_offset(&mut self.s, n, off)
} else {
if off != 0 && self.s.last_token().is_hardbreak_tok() {
self.s.replace_last_token(pp::hardbreak_tok_offset(off));
}
Ok(())
}
}
pub fn synth_comment(&mut self, text: String) -> io::Result<()> {
match word(&mut self.s, "/*") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, &text[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
word(&mut self.s, "*/")
}
pub fn commasep_cmnt<T, F,
G>(&mut self, b: Breaks, elts: &[T],
mut op: F, mut get_span: G)
-> io::Result<()> where F: FnMut(&mut State, &T) ->
io::Result<()>, G: FnMut(&T) -> codemap::Span {
match self.rbox(0, b) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let len = elts.len();
let mut i = 0;
for elt in elts {
match self.maybe_print_comment(get_span(elt).hi) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match op(self, elt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
i += 1;
if i < len {
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_trailing_comment(get_span(elt),
Some(get_span(&elts[i]).hi))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.end()
}
pub fn commasep_exprs(&mut self, b: Breaks,
exprs: &[P<ast::Expr>]) -> io::Result<()> {
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&**e),
|e| e.span)
}
pub fn print_mod(&mut self, _mod: &ast::Mod,
attrs: &[ast::Attribute]) -> io::Result<()> {
match self.print_inner_attributes(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for item in &_mod.items {
match self.print_item(&**item) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
pub fn print_foreign_mod(&mut self, nmod: &ast::ForeignMod,
attrs: &[ast::Attribute])
-> io::Result<()> {
match self.print_inner_attributes(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for item in &nmod.items {
match self.print_foreign_item(&**item) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
pub fn print_opt_lifetime(&mut self,
lifetime: &Option<ast::Lifetime>)
-> io::Result<()> {
if let Some(l) = *lifetime {
match self.print_lifetime(&l) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
pub fn print_type(&mut self, ty: &ast::Ty) -> io::Result<()> {
match self.maybe_print_comment(ty.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match ty.node {
ast::TyVec(ref ty) => {
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "]") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyPtr(ref mt) => {
match word(&mut self.s, "*") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match mt.mutbl {
ast::MutMutable =>
match self.word_nbsp("mut") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::MutImmutable =>
match self.word_nbsp("const") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
match self.print_type(&*mt.ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyRptr(ref lifetime, ref mt) => {
match word(&mut self.s, "&") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_opt_lifetime(lifetime) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_mt(mt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyTup(ref elts) => {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &elts[..],
|s, ty| s.print_type(&**ty)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if elts.len() == 1 {
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyParen(ref typ) => {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**typ) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyBareFn(ref f) => {
let generics =
ast::Generics{lifetimes: f.lifetimes.clone(),
ty_params: P::empty(),
where_clause:
ast::WhereClause{id:
ast::DUMMY_NODE_ID,
predicates:
Vec::new(),},};
match self.print_ty_fn(f.abi, f.unsafety, &*f.decl,
None, &generics, None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyPath(None, ref path) => {
match self.print_path(path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyPath(Some(ref qself), ref path) => {
match self.print_qpath(path, qself, false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
ast::TyObjectSum(ref ty, ref bounds) => {
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_bounds("+", &bounds[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyPolyTraitRef(ref bounds) => {
match self.print_bounds("", &bounds[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyFixedLengthVec(ref ty, ref v) => {
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "; ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**v) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "]") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyTypeof(ref e) => {
match word(&mut self.s, "typeof(") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**e) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ")") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyInfer => {
match word(&mut self.s, "_") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::TyMac(ref m) => {
match self.print_mac(m, token::Paren) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.end()
}
pub fn print_foreign_item(&mut self, item: &ast::ForeignItem)
-> io::Result<()> {
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_comment(item.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&item.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match item.node {
ast::ForeignItemFn(ref decl, ref generics) => {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_fn(decl, ast::Unsafety::Normal,
ast::Constness::NotConst,
abi::Rust, Some(item.ident),
generics, None, item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
ast::ForeignItemStatic(ref t, m) => {
match self.head(&visibility_qualified(item.vis,
"static")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if m {
match self.word_space("mut") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**t) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
}
}
fn print_associated_const(&mut self, ident: ast::Ident,
ty: &ast::Ty,
default: Option<&ast::Expr>,
vis: ast::Visibility)
-> io::Result<()> {
match word(&mut self.s, &visibility_qualified(vis, "")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("const") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(expr) = default {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
word(&mut self.s, ";")
}
fn print_associated_type(&mut self, ident: ast::Ident,
bounds: Option<&ast::TyParamBounds>,
ty: Option<&ast::Ty>) -> io::Result<()> {
match self.word_space("type") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(bounds) = bounds {
match self.print_bounds(":", bounds) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if let Some(ty) = ty {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
word(&mut self.s, ";")
}
/// Pretty-print an item
pub fn print_item(&mut self, item: &ast::Item) -> io::Result<()> {
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_comment(item.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&item.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ann.pre(self, NodeItem(item)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match item.node {
ast::ItemExternCrate(ref optional_path) => {
match self.head(&visibility_qualified(item.vis,
"extern crate"))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(p) = *optional_path {
let val = p.as_str();
if val.contains("-") {
match self.print_string(&val, ast::CookedStr)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match self.print_name(p) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "as") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemUse(ref vp) => {
match self.head(&visibility_qualified(item.vis,
"use")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_view_path(&**vp) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemStatic(ref ty, m, ref expr) => {
match self.head(&visibility_qualified(item.vis,
"static")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if m == ast::MutMutable {
match self.word_space("mut") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemConst(ref ty, ref expr) => {
match self.head(&visibility_qualified(item.vis,
"const")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemFn(ref decl, unsafety, constness, abi,
ref typarams, ref body) => {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_fn(decl, unsafety, constness, abi,
Some(item.ident), typarams, None,
item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, " ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(&**body,
&item.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemMod(ref _mod) => {
match self.head(&visibility_qualified(item.vis,
"mod")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if _mod.items.is_empty() {
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_mod(_mod, &item.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bclose(item.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
ast::ItemForeignMod(ref nmod) => {
match self.head("extern") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp(&nmod.abi.to_string()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_foreign_mod(nmod, &item.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bclose(item.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemTy(ref ty, ref params) => {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp(&visibility_qualified(item.vis,
"type")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_generics(params) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_where_clause(¶ms.where_clause) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemEnum(ref enum_definition, ref params) => {
match self.print_enum_def(enum_definition, params,
item.ident, item.span,
item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemStruct(ref struct_def, ref generics) => {
match self.head(&visibility_qualified(item.vis,
"struct")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_struct(&struct_def, generics,
item.ident, item.span, true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemDefaultImpl(unsafety, ref trait_ref) => {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_visibility(item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_unsafety(unsafety) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp("impl") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_trait_ref(trait_ref) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("for") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("..") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bclose(item.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemImpl(unsafety, polarity, ref generics,
ref opt_trait, ref ty, ref impl_items) => {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_visibility(item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_unsafety(unsafety) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp("impl") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if generics.is_parameterized() {
match self.print_generics(generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match polarity {
ast::ImplPolarity::Negative => {
match word(&mut self.s, "!") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
_ => { }
}
match *opt_trait {
Some(ref t) => {
match self.print_trait_ref(t) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("for") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
None => { }
}
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_where_clause(&generics.where_clause)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes(&item.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for impl_item in impl_items {
match self.print_impl_item(impl_item) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.bclose(item.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemTrait(unsafety, ref generics, ref bounds,
ref trait_items) => {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_visibility(item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_unsafety(unsafety) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp("trait") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_generics(generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut real_bounds =
Vec::with_capacity(bounds.len());
for b in bounds.iter() {
if let TraitTyParamBound(ref ptr,
ast::TraitBoundModifier::Maybe)
= *b {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("for ?") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_trait_ref(&ptr.trait_ref) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else { real_bounds.push(b.clone()); }
}
match self.print_bounds(":", &real_bounds[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_where_clause(&generics.where_clause)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, " ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for trait_item in trait_items {
match self.print_trait_item(trait_item) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.bclose(item.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ItemMac(codemap::Spanned { ref node, .. }) => {
match self.print_visibility(item.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_path(&node.path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "! ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(item.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_tts(&node.tts[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.ann.post(self, NodeItem(item))
}
fn print_trait_ref(&mut self, t: &ast::TraitRef)
-> io::Result<()> {
self.print_path(&t.path, false, 0)
}
fn print_formal_lifetime_list(&mut self,
lifetimes: &[ast::LifetimeDef])
-> io::Result<()> {
if !lifetimes.is_empty() {
match word(&mut self.s, "for<") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut comma = false;
for lifetime_def in lifetimes {
if comma {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
match self.print_lifetime_def(lifetime_def) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
comma = true;
}
match word(&mut self.s, ">") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef)
-> io::Result<()> {
match self.print_formal_lifetime_list(&t.bound_lifetimes) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_trait_ref(&t.trait_ref)
}
pub fn print_enum_def(&mut self, enum_definition: &ast::EnumDef,
generics: &ast::Generics, ident: ast::Ident,
span: codemap::Span,
visibility: ast::Visibility)
-> io::Result<()> {
match self.head(&visibility_qualified(visibility, "enum")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_generics(generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_where_clause(&generics.where_clause) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_variants(&enum_definition.variants, span)
}
pub fn print_variants(&mut self, variants: &[P<ast::Variant>],
span: codemap::Span) -> io::Result<()> {
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for v in variants {
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_comment(v.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&v.node.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_variant(&**v) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_trailing_comment(v.span, None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.bclose(span)
}
pub fn print_visibility(&mut self, vis: ast::Visibility)
-> io::Result<()> {
match vis {
ast::Public => self.word_nbsp("pub"),
ast::Inherited => Ok(()),
}
}
pub fn print_struct(&mut self, struct_def: &ast::VariantData,
generics: &ast::Generics, ident: ast::Ident,
span: codemap::Span, print_finalizer: bool)
-> io::Result<()> {
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_generics(generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !struct_def.is_struct() {
if struct_def.is_tuple() {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, struct_def.fields(),
|s, field| {
match field.node.kind {
ast::NamedField(..) => {
::std::rt::begin_unwind("unexpected named field",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/print/pprust.rs",
1426u32);
&_FILE_LINE
})
}
ast::UnnamedField(vis) => {
match s.print_visibility(vis)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.maybe_print_comment(field.span.lo)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
s.print_type(&*field.node.ty)
}
} }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_where_clause(&generics.where_clause) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if print_finalizer {
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
} else {
match self.print_where_clause(&generics.where_clause) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for field in struct_def.fields() {
match field.node.kind {
ast::UnnamedField(..) => {
::std::rt::begin_unwind("unexpected unnamed field",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pprust.rs",
1455u32);
&_FILE_LINE
})
}
ast::NamedField(ident, visibility) => {
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_comment(field.span.lo)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&field.node.attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_visibility(visibility) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&*field.node.ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
self.bclose(span)
}
}
/// This doesn't deserve to be called "pretty" printing, but it should be
/// meaning-preserving. A quick hack that might help would be to look at the
/// spans embedded in the TTs to decide where to put spaces and newlines.
/// But it'd be better to parse these according to the grammar of the
/// appropriate macro, transcribe back into the grammar we just parsed from,
/// and then pretty-print the resulting AST nodes (so, e.g., we print
/// expression arguments as expressions). It can be done! I think.
pub fn print_tt(&mut self, tt: &ast::TokenTree)
-> io::Result<()> {
match *tt {
TokenTree::Token(_, ref tk) => {
match word(&mut self.s, &token_to_string(tk)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match *tk {
parse::token::DocComment(..) => {
hardbreak(&mut self.s)
}
_ => Ok(()),
}
}
TokenTree::Delimited(_, ref delimed) => {
match word(&mut self.s,
&token_to_string(&delimed.open_token())) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_tts(&delimed.tts) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
word(&mut self.s,
&token_to_string(&delimed.close_token()))
}
TokenTree::Sequence(_, ref seq) => {
match word(&mut self.s, "$(") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for tt_elt in &seq.tts {
match self.print_tt(tt_elt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match word(&mut self.s, ")") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match seq.separator {
Some(ref tk) => {
match word(&mut self.s, &token_to_string(tk))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
None => { }
}
match seq.op {
ast::ZeroOrMore => word(&mut self.s, "*"),
ast::OneOrMore => word(&mut self.s, "+"),
}
}
}
}
pub fn print_tts(&mut self, tts: &[ast::TokenTree])
-> io::Result<()> {
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut suppress_space = false;
for (i, tt) in tts.iter().enumerate() {
if i != 0 && !suppress_space {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_tt(tt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
suppress_space =
match *tt {
TokenTree::Token(_,
token::Ident(_, token::ModName))
|
TokenTree::Token(_,
token::MatchNt(_, _, _,
token::ModName)) |
TokenTree::Token(_,
token::SubstNt(_,
token::ModName))
=> true,
_ => false,
}
}
self.end()
}
pub fn print_variant(&mut self, v: &ast::Variant)
-> io::Result<()> {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let generics = ast::Generics::default();
match self.print_struct(&v.node.data, &generics, v.node.name,
v.span, false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match v.node.disr_expr {
Some(ref d) => {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_expr(&**d)
}
_ => Ok(()),
}
}
pub fn print_method_sig(&mut self, ident: ast::Ident,
m: &ast::MethodSig, vis: ast::Visibility)
-> io::Result<()> {
self.print_fn(&m.decl, m.unsafety, m.constness, m.abi,
Some(ident), &m.generics,
Some(&m.explicit_self.node), vis)
}
pub fn print_trait_item(&mut self, ti: &ast::TraitItem)
-> io::Result<()> {
match self.ann.pre(self, NodeSubItem(ti.id)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_comment(ti.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&ti.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match ti.node {
ast::ConstTraitItem(ref ty, ref default) => {
match self.print_associated_const(ti.ident, &ty,
default.as_ref().map(|expr|
&**expr),
ast::Inherited) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::MethodTraitItem(ref sig, ref body) => {
if body.is_some() {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_method_sig(ti.ident, sig,
ast::Inherited) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ref body) = *body {
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(body, &ti.attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
ast::TypeTraitItem(ref bounds, ref default) => {
match self.print_associated_type(ti.ident,
Some(bounds),
default.as_ref().map(|ty|
&**ty))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.ann.post(self, NodeSubItem(ti.id))
}
pub fn print_impl_item(&mut self, ii: &ast::ImplItem)
-> io::Result<()> {
match self.ann.pre(self, NodeSubItem(ii.id)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.hardbreak_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_comment(ii.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&ii.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match ii.node {
ast::ImplItemKind::Const(ref ty, ref expr) => {
match self.print_associated_const(ii.ident, &ty,
Some(&expr), ii.vis)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ImplItemKind::Method(ref sig, ref body) => {
match self.head("") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_method_sig(ii.ident, sig, ii.vis) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(body, &ii.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ImplItemKind::Type(ref ty) => {
match self.print_associated_type(ii.ident, None,
Some(ty)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ImplItemKind::Macro(codemap::Spanned { ref node, ..
}) => {
match self.print_path(&node.path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "! ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_tts(&node.tts[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
}
self.ann.post(self, NodeSubItem(ii.id))
}
pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> {
match self.maybe_print_comment(st.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match st.node {
ast::StmtDecl(ref decl, _) => {
match self.print_decl(&**decl) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::StmtExpr(ref expr, _) => {
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr_outer_attr_style(&**expr, false)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::StmtSemi(ref expr, _) => {
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr_outer_attr_style(&**expr, false)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::StmtMac(ref mac, style, ref attrs) => {
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(attrs.as_attr_slice())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let delim =
match style {
ast::MacStmtWithBraces => token::Brace,
_ => token::Paren,
};
match self.print_mac(&**mac, delim) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match style {
ast::MacStmtWithBraces => { }
_ =>
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
}
}
if parse::classify::stmt_ends_with_semi(&st.node) {
match word(&mut self.s, ";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.maybe_print_trailing_comment(st.span, None)
}
pub fn print_block(&mut self, blk: &ast::Block)
-> io::Result<()> {
self.print_block_with_attrs(blk, &[])
}
pub fn print_block_unclosed(&mut self, blk: &ast::Block)
-> io::Result<()> {
self.print_block_unclosed_indent(blk, INDENT_UNIT)
}
pub fn print_block_unclosed_with_attrs(&mut self,
blk: &ast::Block,
attrs: &[ast::Attribute])
-> io::Result<()> {
self.print_block_maybe_unclosed(blk, INDENT_UNIT, attrs,
false)
}
pub fn print_block_unclosed_indent(&mut self, blk: &ast::Block,
indented: usize)
-> io::Result<()> {
self.print_block_maybe_unclosed(blk, indented, &[], false)
}
pub fn print_block_with_attrs(&mut self, blk: &ast::Block,
attrs: &[ast::Attribute])
-> io::Result<()> {
self.print_block_maybe_unclosed(blk, INDENT_UNIT, attrs, true)
}
pub fn print_block_maybe_unclosed(&mut self, blk: &ast::Block,
indented: usize,
attrs: &[ast::Attribute],
close_box: bool)
-> io::Result<()> {
match blk.rules {
ast::UnsafeBlock(..) =>
match self.word_space("unsafe") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::DefaultBlock => (),
}
match self.maybe_print_comment(blk.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ann.pre(self, NodeBlock(blk)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for st in &blk.stmts {
match self.print_stmt(&**st) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match blk.expr {
Some(ref expr) => {
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr_outer_attr_style(&**expr, false)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.maybe_print_trailing_comment(expr.span,
Some(blk.span.hi))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
_ => (),
}
match self.bclose_maybe_open(blk.span, indented, close_box) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.ann.post(self, NodeBlock(blk))
}
fn print_else(&mut self, els: Option<&ast::Expr>)
-> io::Result<()> {
match els {
Some(_else) => {
match _else.node {
ast::ExprIf(ref i, ref then, ref e) => {
match self.cbox(INDENT_UNIT - 1) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, " else if ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**i) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block(&**then) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_else(e.as_ref().map(|e| &**e))
}
ast::ExprIfLet(ref pat, ref expr, ref then, ref e)
=> {
match self.cbox(INDENT_UNIT - 1) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, " else if let ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_pat(&**pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block(&**then) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_else(e.as_ref().map(|e| &**e))
}
ast::ExprBlock(ref b) => {
match self.cbox(INDENT_UNIT - 1) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, " else ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_block(&**b)
}
_ => {
{
::std::rt::begin_unwind("print_if saw if with weird alternative",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pprust.rs",
1758u32);
&_FILE_LINE
})
};
}
}
}
_ => Ok(()),
}
}
pub fn print_if(&mut self, test: &ast::Expr, blk: &ast::Block,
elseopt: Option<&ast::Expr>) -> io::Result<()> {
match self.head("if") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(test) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block(blk) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_else(elseopt)
}
pub fn print_if_let(&mut self, pat: &ast::Pat, expr: &ast::Expr,
blk: &ast::Block, elseopt: Option<&ast::Expr>)
-> io::Result<()> {
match self.head("if let") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_pat(pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block(blk) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_else(elseopt)
}
pub fn print_mac(&mut self, m: &ast::Mac,
delim: token::DelimToken) -> io::Result<()> {
match self.print_path(&m.node.path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "!") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match delim {
token::Paren =>
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
token::Bracket =>
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
token::Brace => {
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
}
match self.print_tts(&m.node.tts) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match delim {
token::Paren => self.pclose(),
token::Bracket => word(&mut self.s, "]"),
token::Brace => self.bclose(m.span),
}
}
fn print_call_post(&mut self, args: &[P<ast::Expr>])
-> io::Result<()> {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep_exprs(Inconsistent, args) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.pclose()
}
pub fn check_expr_bin_needs_paren(&mut self, sub_expr: &ast::Expr,
binop: ast::BinOp) -> bool {
match sub_expr.node {
ast::ExprBinary(ref sub_op, _, _) => {
if AssocOp::from_ast_binop(sub_op.node).precedence() <
AssocOp::from_ast_binop(binop.node).precedence()
{
true
} else { false }
}
_ => true,
}
}
pub fn print_expr_maybe_paren(&mut self, expr: &ast::Expr)
-> io::Result<()> {
let needs_par = needs_parentheses(expr);
if needs_par {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_expr(expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if needs_par {
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
fn print_expr_in_place(&mut self, place: &ast::Expr,
expr: &ast::Expr) -> io::Result<()> {
match self.print_expr_maybe_paren(place) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("<-") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_expr_maybe_paren(expr)
}
fn print_expr_vec(&mut self, exprs: &[P<ast::Expr>],
attrs: &[Attribute]) -> io::Result<()> {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes_inline(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep_exprs(Inconsistent, &exprs[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "]") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
fn print_expr_repeat(&mut self, element: &ast::Expr,
count: &ast::Expr, attrs: &[Attribute])
-> io::Result<()> {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes_inline(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(element) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(";") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(count) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "]") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
fn print_expr_struct(&mut self, path: &ast::Path,
fields: &[ast::Field],
wth: &Option<P<ast::Expr>>,
attrs: &[Attribute]) -> io::Result<()> {
match self.print_path(path, true, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "{") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes_inline(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep_cmnt(Consistent, &fields[..], |s, field| {
match s.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_ident(field.ident.node)
{
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.word_space(":") {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_expr(&*field.expr) {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; s.end() }, |f| f.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match *wth {
Some(ref expr) => {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !fields.is_empty() {
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match word(&mut self.s, "..") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
_ =>
if !fields.is_empty() {
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
},
}
match word(&mut self.s, "}") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(())
}
fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>],
attrs: &[Attribute]) -> io::Result<()> {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes_inline(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep_exprs(Inconsistent, &exprs[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if exprs.len() == 1 {
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.pclose()
}
fn print_expr_call(&mut self, func: &ast::Expr,
args: &[P<ast::Expr>]) -> io::Result<()> {
match self.print_expr_maybe_paren(func) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_call_post(args)
}
fn print_expr_method_call(&mut self, ident: ast::SpannedIdent,
tys: &[P<ast::Ty>],
args: &[P<ast::Expr>])
-> io::Result<()> {
let base_args = &args[1..];
match self.print_expr(&*args[0]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ".") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(ident.node) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !tys.is_empty() {
match word(&mut self.s, "::<") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, tys,
|s, ty| s.print_type(&**ty)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ">") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.print_call_post(base_args)
}
fn print_expr_binary(&mut self, op: ast::BinOp, lhs: &ast::Expr,
rhs: &ast::Expr) -> io::Result<()> {
if self.check_expr_bin_needs_paren(lhs, op) {
match self.print_expr_maybe_paren(lhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match self.print_expr(lhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(op.node.to_string()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if self.check_expr_bin_needs_paren(rhs, op) {
self.print_expr_maybe_paren(rhs)
} else { self.print_expr(rhs) }
}
fn print_expr_unary(&mut self, op: ast::UnOp, expr: &ast::Expr)
-> io::Result<()> {
match word(&mut self.s, ast::UnOp::to_string(op)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_expr_maybe_paren(expr)
}
fn print_expr_addr_of(&mut self, mutability: ast::Mutability,
expr: &ast::Expr) -> io::Result<()> {
match word(&mut self.s, "&") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_mutability(mutability) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_expr_maybe_paren(expr)
}
pub fn print_expr(&mut self, expr: &ast::Expr) -> io::Result<()> {
self.print_expr_outer_attr_style(expr, true)
}
fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr,
is_inline: bool)
-> io::Result<()> {
match self.maybe_print_comment(expr.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let attrs = expr.attrs.as_attr_slice();
if is_inline {
match self.print_outer_attributes_inline(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match self.print_outer_attributes(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ann.pre(self, NodeExpr(expr)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match expr.node {
ast::ExprBox(ref expr) => {
match self.word_space("box") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprInPlace(ref place, ref expr) => {
match self.print_expr_in_place(place, expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprVec(ref exprs) => {
match self.print_expr_vec(&exprs[..], attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprRepeat(ref element, ref count) => {
match self.print_expr_repeat(&**element, &**count,
attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprStruct(ref path, ref fields, ref wth) => {
match self.print_expr_struct(path, &fields[..], wth,
attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprTup(ref exprs) => {
match self.print_expr_tup(&exprs[..], attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprCall(ref func, ref args) => {
match self.print_expr_call(&**func, &args[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprMethodCall(ident, ref tys, ref args) => {
match self.print_expr_method_call(ident, &tys[..],
&args[..]) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprBinary(op, ref lhs, ref rhs) => {
match self.print_expr_binary(op, &**lhs, &**rhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprUnary(op, ref expr) => {
match self.print_expr_unary(op, &**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprAddrOf(m, ref expr) => {
match self.print_expr_addr_of(m, &**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprLit(ref lit) => {
match self.print_literal(&**lit) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprCast(ref expr, ref ty) => {
if let ast::ExprCast(..) = expr.node {
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match self.print_expr_maybe_paren(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("as") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprType(ref expr, ref ty) => {
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprIf(ref test, ref blk, ref elseopt) => {
match self.print_if(&**test, &**blk,
elseopt.as_ref().map(|e| &**e)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprIfLet(ref pat, ref expr, ref blk, ref elseopt) =>
{
match self.print_if_let(&**pat, &**expr, &**blk,
elseopt.as_ref().map(|e|
&**e))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprWhile(ref test, ref blk, opt_ident) => {
if let Some(ident) = opt_ident {
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.head("while") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**test) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(&**blk, attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprWhileLet(ref pat, ref expr, ref blk, opt_ident)
=> {
if let Some(ident) = opt_ident {
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.head("while let") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_pat(&**pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(&**blk, attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprForLoop(ref pat, ref iter, ref blk, opt_ident) =>
{
if let Some(ident) = opt_ident {
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.head("for") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_pat(&**pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("in") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**iter) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(&**blk, attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprLoop(ref blk, opt_ident) => {
if let Some(ident) = opt_ident {
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.head("loop") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(&**blk, attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprMatch(ref expr, ref arms) => {
match self.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(4) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp("match") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.bopen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes_no_trailing_hardbreak(attrs)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for arm in arms {
match self.print_arm(arm) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.bclose_(expr.span, INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprClosure(capture_clause, ref decl, ref body) => {
match self.print_capture_clause(capture_clause) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_fn_block_args(&**decl) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let default_return =
match decl.output {
ast::DefaultReturn(..) => true,
_ => false,
};
if !default_return || !body.stmts.is_empty() ||
body.expr.is_none() {
match self.print_block_unclosed(&**body) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
let i_expr = body.expr.as_ref().unwrap();
match i_expr.node {
ast::ExprBlock(ref blk) => {
match self.print_block_unclosed_with_attrs(&**blk,
i_expr.attrs.as_attr_slice())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
_ => {
match self.print_expr(&**i_expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprBlock(ref blk) => {
match self.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_block_with_attrs(&**blk, attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprAssign(ref lhs, ref rhs) => {
match self.print_expr(&**lhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**rhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprAssignOp(op, ref lhs, ref rhs) => {
match self.print_expr(&**lhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, op.node.to_string()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**rhs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprField(ref expr, id) => {
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ".") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(id.node) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprTupField(ref expr, id) => {
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ".") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_usize(id.node) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprIndex(ref expr, ref index) => {
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**index) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "]") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprRange(ref start, ref end) => {
if let &Some(ref e) = start {
match self.print_expr(&**e) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match word(&mut self.s, "..") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let &Some(ref e) = end {
match self.print_expr(&**e) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
ast::ExprPath(None, ref path) => {
match self.print_path(path, true, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
ast::ExprPath(Some(ref qself), ref path) => {
match self.print_qpath(path, qself, true) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
ast::ExprBreak(opt_ident) => {
match word(&mut self.s, "break") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ident) = opt_ident {
match self.print_ident(ident.node) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
ast::ExprAgain(opt_ident) => {
match word(&mut self.s, "continue") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ident) = opt_ident {
match self.print_ident(ident.node) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
}
ast::ExprRet(ref result) => {
match word(&mut self.s, "return") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match *result {
Some(ref expr) => {
match word(&mut self.s, " ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**expr) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
_ => (),
}
}
ast::ExprInlineAsm(ref a) => {
match word(&mut self.s, "asm!") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_string(&a.asm, a.asm_str_style) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &a.outputs,
|s, out| {
match slice_shift_char(&out.constraint)
{
Some(('=', operand)) if
out.is_rw => {
match s.print_string(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["+"];
__STATIC_FMTSTR
},
&match (&operand,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
ast::CookedStr)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
_ =>
match s.print_string(&out.constraint,
ast::CookedStr)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
match s.popen() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_expr(&*out.expr) {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.pclose() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; Ok(()) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &a.inputs,
|s, &(ref co, ref o)| {
match s.print_string(&co,
ast::CookedStr)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.popen() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_expr(&**o) {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.pclose() {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; Ok(()) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &a.clobbers,
|s, co| {
match s.print_string(&co,
ast::CookedStr)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; Ok(()) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut options =
<[_]>::into_vec(::std::boxed::Box::new([]));
if a.volatile { options.push("volatile"); }
if a.alignstack { options.push("alignstack"); }
if a.dialect == ast::AsmDialect::Intel {
options.push("intel");
}
if !options.is_empty() {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &*options,
|s, &co| {
match s.print_string(co,
ast::CookedStr)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; Ok(()) }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::ExprMac(ref m) =>
match self.print_mac(m, token::Paren) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::ExprParen(ref e) => {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_inner_attributes_inline(attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**e) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
match self.ann.post(self, NodeExpr(expr)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
pub fn print_local_decl(&mut self, loc: &ast::Local)
-> io::Result<()> {
match self.print_pat(&*loc.pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ref ty) = loc.ty {
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
pub fn print_decl(&mut self, decl: &ast::Decl) -> io::Result<()> {
match self.maybe_print_comment(decl.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match decl.node {
ast::DeclLocal(ref loc) => {
match self.print_outer_attributes(loc.attrs.as_attr_slice())
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp("let") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_local_decl(&**loc) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ref init) = loc.init {
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**init) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.end()
}
ast::DeclItem(ref item) => self.print_item(&**item),
}
}
pub fn print_ident(&mut self, ident: ast::Ident)
-> io::Result<()> {
match word(&mut self.s, &ident.name.as_str()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.ann.post(self, NodeIdent(&ident))
}
pub fn print_usize(&mut self, i: usize) -> io::Result<()> {
word(&mut self.s, &i.to_string())
}
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
match word(&mut self.s, &name.as_str()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.ann.post(self, NodeName(&name))
}
pub fn print_for_decl(&mut self, loc: &ast::Local,
coll: &ast::Expr) -> io::Result<()> {
match self.print_local_decl(loc) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("in") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_expr(coll)
}
fn print_path(&mut self, path: &ast::Path,
colons_before_params: bool, depth: usize)
-> io::Result<()> {
match self.maybe_print_comment(path.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut first = !path.global;
for segment in &path.segments[..path.segments.len() - depth] {
if first {
first = false
} else {
match word(&mut self.s, "::") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
match self.print_ident(segment.identifier) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_path_parameters(&segment.parameters,
colons_before_params) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
fn print_qpath(&mut self, path: &ast::Path, qself: &ast::QSelf,
colons_before_params: bool) -> io::Result<()> {
match word(&mut self.s, "<") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&qself.ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if qself.position > 0 {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("as") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let depth = path.segments.len() - qself.position;
match self.print_path(&path, false, depth) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match word(&mut self.s, ">") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "::") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let item_segment = path.segments.last().unwrap();
match self.print_ident(item_segment.identifier) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_path_parameters(&item_segment.parameters,
colons_before_params)
}
fn print_path_parameters(&mut self,
parameters: &ast::PathParameters,
colons_before_params: bool)
-> io::Result<()> {
if parameters.is_empty() { return Ok(()); }
if colons_before_params {
match word(&mut self.s, "::") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
match *parameters {
ast::PathParameters::AngleBracketed(ref data) => {
match word(&mut self.s, "<") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut comma = false;
for lifetime in &data.lifetimes {
if comma {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
match self.print_lifetime(lifetime) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
comma = true;
}
if !data.types.is_empty() {
if comma {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
match self.commasep(Inconsistent, &data.types,
|s, ty| s.print_type(&**ty)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
comma = true;
}
for binding in data.bindings.iter() {
if comma {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
match self.print_ident(binding.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&*binding.ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
comma = true;
}
match word(&mut self.s, ">") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
ast::PathParameters::Parenthesized(ref data) => {
match word(&mut self.s, "(") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &data.inputs,
|s, ty| s.print_type(&**ty)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ")") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match data.output {
None => { }
Some(ref ty) => {
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("->") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
}
Ok(())
}
pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
match self.maybe_print_comment(pat.span.lo) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ann.pre(self, NodePat(pat)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match pat.node {
ast::PatWild =>
match word(&mut self.s, "_") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::PatIdent(binding_mode, ref path1, ref sub) => {
match binding_mode {
ast::BindingMode::ByRef(mutbl) => {
match self.word_nbsp("ref") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_mutability(mutbl) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::BindingMode::ByValue(ast::MutImmutable) => {
}
ast::BindingMode::ByValue(ast::MutMutable) => {
match self.word_nbsp("mut") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
match self.print_ident(path1.node) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match *sub {
Some(ref p) => {
match word(&mut self.s, "@") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_pat(&**p) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
None => (),
}
}
ast::PatEnum(ref path, ref args_) => {
match self.print_path(path, true, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match *args_ {
None =>
match word(&mut self.s, "(..)") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
Some(ref args) => {
if !args.is_empty() {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent,
&args[..],
|s, p|
s.print_pat(&**p))
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
}
ast::PatQPath(ref qself, ref path) => {
match self.print_qpath(path, qself, false) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatStruct(ref path, ref fields, etc) => {
match self.print_path(path, true, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("{") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep_cmnt(Consistent, &fields[..],
|s, f| {
match s.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !f.node.is_shorthand {
match s.print_ident(f.node.ident)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.word_nbsp(":") {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match s.print_pat(&*f.node.pat)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}; s.end() },
|f| f.node.pat.span) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if etc {
if !fields.is_empty() {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match word(&mut self.s, "..") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "}") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatTup(ref elts) => {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &elts[..],
|s, p| s.print_pat(&**p)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if elts.len() == 1 {
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatBox(ref inner) => {
match word(&mut self.s, "box ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_pat(&**inner) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatRegion(ref inner, mutbl) => {
match word(&mut self.s, "&") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if mutbl == ast::MutMutable {
match word(&mut self.s, "mut ") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_pat(&**inner) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatLit(ref e) =>
match self.print_expr(&**e) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::PatRange(ref begin, ref end) => {
match self.print_expr(&**begin) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "...") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**end) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatVec(ref before, ref slice, ref after) => {
match word(&mut self.s, "[") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.commasep(Inconsistent, &before[..],
|s, p| s.print_pat(&**p)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ref p) = *slice {
if !before.is_empty() {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
if p.node != ast::PatWild {
match self.print_pat(&**p) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match word(&mut self.s, "..") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !after.is_empty() {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
match self.commasep(Inconsistent, &after[..],
|s, p| s.print_pat(&**p)) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "]") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::PatMac(ref m) =>
match self.print_mac(m, token::Paren) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
self.ann.post(self, NodePat(pat))
}
fn print_arm(&mut self, arm: &ast::Arm) -> io::Result<()> {
if arm.attrs.is_empty() {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.cbox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_outer_attributes(&arm.attrs) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut first = true;
for p in &arm.pats {
if first {
first = false;
} else {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("|") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_pat(&**p) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ref e) = arm.guard {
match self.word_space("if") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&**e) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.word_space("=>") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match arm.body.node {
ast::ExprBlock(ref blk) => {
match self.print_block_unclosed_indent(&**blk,
INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let ast::UnsafeBlock(ast::UserProvided) = blk.rules
{
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
_ => {
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_expr(&*arm.body) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.end()
}
fn print_explicit_self(&mut self,
explicit_self: &ast::ExplicitSelf_,
mutbl: ast::Mutability)
-> io::Result<bool> {
match self.print_mutability(mutbl) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match *explicit_self {
ast::SelfStatic => { return Ok(false); }
ast::SelfValue(_) => {
match word(&mut self.s, "self") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::SelfRegion(ref lt, m, _) => {
match word(&mut self.s, "&") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_opt_lifetime(lt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_mutability(m) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "self") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::SelfExplicit(ref typ, _) => {
match word(&mut self.s, "self") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space(":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**typ) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
return Ok(true);
}
pub fn print_fn(&mut self, decl: &ast::FnDecl,
unsafety: ast::Unsafety,
constness: ast::Constness, abi: abi::Abi,
name: Option<ast::Ident>,
generics: &ast::Generics,
opt_explicit_self: Option<&ast::ExplicitSelf_>,
vis: ast::Visibility) -> io::Result<()> {
match self.print_fn_header_info(unsafety, constness, abi, vis)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(name) = name {
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(name) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_generics(generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_fn_args_and_ret(decl, opt_explicit_self) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_where_clause(&generics.where_clause)
}
pub fn print_fn_args(&mut self, decl: &ast::FnDecl,
opt_explicit_self:
Option<&ast::ExplicitSelf_>)
-> io::Result<()> {
match self.rbox(0, Inconsistent) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut first = true;
if let Some(explicit_self) = opt_explicit_self {
let m =
match *explicit_self {
ast::SelfStatic => ast::MutImmutable,
_ =>
match decl.inputs[0].pat.node {
ast::PatIdent(ast::BindingMode::ByValue(m), _,
_) => m,
_ => ast::MutImmutable,
},
};
first =
!match self.print_explicit_self(explicit_self, m) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
let args =
if first { &decl.inputs[..] } else { &decl.inputs[1..] };
for arg in args {
if first {
first = false;
} else {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.print_arg(arg) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
self.end()
}
pub fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl,
opt_explicit_self:
Option<&ast::ExplicitSelf_>)
-> io::Result<()> {
match self.popen() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_fn_args(decl, opt_explicit_self) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if decl.variadic {
match word(&mut self.s, ", ...") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.pclose() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_fn_output(decl)
}
pub fn print_fn_block_args(&mut self, decl: &ast::FnDecl)
-> io::Result<()> {
match word(&mut self.s, "|") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_fn_args(decl, None) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "|") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let ast::DefaultReturn(..) = decl.output { return Ok(()); }
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("->") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match decl.output {
ast::Return(ref ty) => {
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.maybe_print_comment(ty.span.lo)
}
ast::DefaultReturn(..) => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pprust.rs",
2750u32);
&_FILE_LINE
})
}
}
ast::NoReturn(span) => {
match self.word_nbsp("!") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.maybe_print_comment(span.lo)
}
}
}
pub fn print_capture_clause(&mut self,
capture_clause: ast::CaptureClause)
-> io::Result<()> {
match capture_clause {
ast::CaptureByValue => self.word_space("move"),
ast::CaptureByRef => Ok(()),
}
}
pub fn print_bounds(&mut self, prefix: &str,
bounds: &[ast::TyParamBound])
-> io::Result<()> {
if !bounds.is_empty() {
match word(&mut self.s, prefix) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut first = true;
for bound in bounds {
match self.nbsp() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if first {
first = false;
} else {
match self.word_space("+") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match match *bound {
TraitTyParamBound(ref tref,
TraitBoundModifier::None)
=> {
self.print_poly_trait_ref(tref)
}
TraitTyParamBound(ref tref,
TraitBoundModifier::Maybe)
=> {
match word(&mut self.s, "?") {
::std::result::Result::Ok(val) =>
val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_poly_trait_ref(tref)
}
RegionTyParamBound(ref lt) => {
self.print_lifetime(lt)
}
} {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
Ok(())
} else { Ok(()) }
}
pub fn print_lifetime(&mut self, lifetime: &ast::Lifetime)
-> io::Result<()> {
self.print_name(lifetime.name)
}
pub fn print_lifetime_def(&mut self, lifetime: &ast::LifetimeDef)
-> io::Result<()> {
match self.print_lifetime(&lifetime.lifetime) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut sep = ":";
for v in &lifetime.bounds {
match word(&mut self.s, sep) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_lifetime(v) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
sep = "+";
}
Ok(())
}
pub fn print_generics(&mut self, generics: &ast::Generics)
-> io::Result<()> {
let total =
generics.lifetimes.len() + generics.ty_params.len();
if total == 0 { return Ok(()); }
match word(&mut self.s, "<") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
let mut ints = Vec::new();
for i in 0..total { ints.push(i); }
match self.commasep(Inconsistent, &ints[..], |s, &idx| {
if idx < generics.lifetimes.len() {
let lifetime =
&generics.lifetimes[idx];
s.print_lifetime_def(lifetime)
} else {
let idx =
idx - generics.lifetimes.len();
let param = &generics.ty_params[idx];
s.print_ty_param(param)
} }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ">") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
Ok(())
}
pub fn print_ty_param(&mut self, param: &ast::TyParam)
-> io::Result<()> {
match self.print_ident(param.ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_bounds(":", ¶m.bounds) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match param.default {
Some(ref default) => {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_type(&**default)
}
_ => Ok(()),
}
}
pub fn print_where_clause(&mut self,
where_clause: &ast::WhereClause)
-> io::Result<()> {
if where_clause.predicates.is_empty() { return Ok(()) }
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("where") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for (i, predicate) in
where_clause.predicates.iter().enumerate() {
if i != 0 {
match self.word_space(",") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match *predicate {
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
ref bound_lifetimes,
ref bounded_ty,
ref bounds, .. })
=> {
match self.print_formal_lifetime_list(bound_lifetimes)
{
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**bounded_ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_bounds(":", bounds) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
ref lifetime,
ref bounds, .. })
=> {
match self.print_lifetime(lifetime) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
for (i, bound) in bounds.iter().enumerate() {
match self.print_lifetime(bound) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if i != 0 {
match word(&mut self.s, ":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
ref path, ref ty, ..
}) => {
match self.print_path(path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("=") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
}
Ok(())
}
pub fn print_view_path(&mut self, vp: &ast::ViewPath)
-> io::Result<()> {
match vp.node {
ast::ViewPathSimple(ident, ref path) => {
match self.print_path(path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if path.segments.last().unwrap().identifier.name !=
ident.name {
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("as") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_ident(ident) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
ast::ViewPathGlob(ref path) => {
match self.print_path(path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
word(&mut self.s, "::*")
}
ast::ViewPathList(ref path, ref idents) => {
if path.segments.is_empty() {
match word(&mut self.s, "{") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
} else {
match self.print_path(path, false, 0) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, "::{") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
match self.commasep(Inconsistent, &idents[..],
|s, w| {
match w.node {
ast::PathListIdent {
name, rename, .. } => {
match s.print_ident(name)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ident) =
rename {
match space(&mut s.s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.word_space("as")
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_ident(ident)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
ast::PathListMod { rename, ..
} => {
match word(&mut s.s,
"self") {
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if let Some(ident) =
rename {
match space(&mut s.s)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.word_space("as")
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match s.print_ident(ident)
{
::std::result::Result::Ok(val)
=> val,
::std::result::Result::Err(err)
=> {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
Ok(())
}
} }) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
word(&mut self.s, "}")
}
}
}
pub fn print_mutability(&mut self, mutbl: ast::Mutability)
-> io::Result<()> {
match mutbl {
ast::MutMutable => self.word_nbsp("mut"),
ast::MutImmutable => Ok(()),
}
}
pub fn print_mt(&mut self, mt: &ast::MutTy) -> io::Result<()> {
match self.print_mutability(mt.mutbl) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.print_type(&*mt.ty)
}
pub fn print_arg(&mut self, input: &ast::Arg) -> io::Result<()> {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match input.ty.node {
ast::TyInfer =>
match self.print_pat(&*input.pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
_ => {
match input.pat.node {
ast::PatIdent(_, ref path1, _) if
path1.node.name ==
parse::token::special_idents::invalid.name =>
{
}
_ => {
match self.print_pat(&*input.pat) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match word(&mut self.s, ":") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match space(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
match self.print_type(&*input.ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
self.end()
}
pub fn print_fn_output(&mut self, decl: &ast::FnDecl)
-> io::Result<()> {
if let ast::DefaultReturn(..) = decl.output { return Ok(()); }
match self.space_if_not_bol() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_space("->") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match decl.output {
ast::NoReturn(_) =>
match self.word_nbsp("!") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
ast::DefaultReturn(..) => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/print/pprust.rs",
3015u32);
&_FILE_LINE
})
}
}
ast::Return(ref ty) =>
match self.print_type(&**ty) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
match self.end() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match decl.output {
ast::Return(ref output) =>
self.maybe_print_comment(output.span.lo),
_ => Ok(()),
}
}
pub fn print_ty_fn(&mut self, abi: abi::Abi,
unsafety: ast::Unsafety, decl: &ast::FnDecl,
name: Option<ast::Ident>,
generics: &ast::Generics,
opt_explicit_self: Option<&ast::ExplicitSelf_>)
-> io::Result<()> {
match self.ibox(INDENT_UNIT) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if !generics.lifetimes.is_empty() ||
!generics.ty_params.is_empty() {
match word(&mut self.s, "for") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.print_generics(generics) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
let generics =
ast::Generics{lifetimes: Vec::new(),
ty_params: P::empty(),
where_clause:
ast::WhereClause{id: ast::DUMMY_NODE_ID,
predicates:
Vec::new(),},};
match self.print_fn(decl, unsafety, ast::Constness::NotConst,
abi, name, &generics, opt_explicit_self,
ast::Inherited) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.end()
}
pub fn maybe_print_trailing_comment(&mut self,
span: codemap::Span,
next_pos: Option<BytePos>)
-> io::Result<()> {
let cm =
match self.cm { Some(cm) => cm, _ => return Ok(()), };
match self.next_comment() {
Some(ref cmnt) => {
if (*cmnt).style != comments::Trailing {
return Ok(())
}
let span_line = cm.lookup_char_pos(span.hi);
let comment_line = cm.lookup_char_pos((*cmnt).pos);
let mut next = (*cmnt).pos + BytePos(1);
match next_pos { None => (), Some(p) => next = p, }
if span.hi < (*cmnt).pos && (*cmnt).pos < next &&
span_line.line == comment_line.line {
match self.print_comment(cmnt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.cur_cmnt_and_lit.cur_cmnt += 1;
}
}
_ => (),
}
Ok(())
}
pub fn print_remaining_comments(&mut self) -> io::Result<()> {
if self.next_comment().is_none() {
match hardbreak(&mut self.s) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
loop {
match self.next_comment() {
Some(ref cmnt) => {
match self.print_comment(cmnt) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.cur_cmnt_and_lit.cur_cmnt += 1;
}
_ => break ,
}
}
Ok(())
}
pub fn print_opt_abi_and_extern_if_nondefault(&mut self,
opt_abi:
Option<abi::Abi>)
-> io::Result<()> {
match opt_abi {
Some(abi::Rust) => Ok(()),
Some(abi) => {
match self.word_nbsp("extern") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.word_nbsp(&abi.to_string())
}
None => Ok(()),
}
}
pub fn print_extern_opt_abi(&mut self, opt_abi: Option<abi::Abi>)
-> io::Result<()> {
match opt_abi {
Some(abi) => {
match self.word_nbsp("extern") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
self.word_nbsp(&abi.to_string())
}
None => Ok(()),
}
}
pub fn print_fn_header_info(&mut self, unsafety: ast::Unsafety,
constness: ast::Constness,
abi: abi::Abi, vis: ast::Visibility)
-> io::Result<()> {
match word(&mut self.s, &visibility_qualified(vis, "")) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match constness {
ast::Constness::NotConst => { }
ast::Constness::Const =>
match self.word_nbsp("const") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
},
}
match self.print_unsafety(unsafety) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
if abi != abi::Rust {
match self.word_nbsp("extern") {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
match self.word_nbsp(&abi.to_string()) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
word(&mut self.s, "fn")
}
pub fn print_unsafety(&mut self, s: ast::Unsafety)
-> io::Result<()> {
match s {
ast::Unsafety::Normal => Ok(()),
ast::Unsafety::Unsafe => self.word_nbsp("unsafe"),
}
}
}
fn repeat(s: &str, n: usize) -> String {
iter::repeat(s).take(n).collect()
}
}
}
pub mod ext {
#[prelude_import]
use std::prelude::v1::*;
pub mod base {
#[prelude_import]
use std::prelude::v1::*;
pub use self::SyntaxExtension::*;
use ast;
use ast::Name;
use codemap;
use codemap::{CodeMap, Span, ExpnId, ExpnInfo, NO_EXPANSION};
use errors::DiagnosticBuilder;
use ext;
use ext::expand;
use ext::tt::macro_rules;
use feature_gate::GatedCfgAttr;
use parse;
use parse::parser;
use parse::token;
use parse::token::{InternedString, intern, str_to_ident};
use ptr::P;
use util::small_vector::SmallVector;
use util::lev_distance::find_best_match_for_name;
use ext::mtwt;
use fold::Folder;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
use std::default::Default;
pub enum Annotatable {
Item(P<ast::Item>),
TraitItem(P<ast::TraitItem>),
ImplItem(P<ast::ImplItem>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for Annotatable {
#[inline]
fn clone(&self) -> Annotatable {
match (&*self,) {
(&Annotatable::Item(ref __self_0),) =>
Annotatable::Item(::std::clone::Clone::clone(&(*__self_0))),
(&Annotatable::TraitItem(ref __self_0),) =>
Annotatable::TraitItem(::std::clone::Clone::clone(&(*__self_0))),
(&Annotatable::ImplItem(ref __self_0),) =>
Annotatable::ImplItem(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Annotatable {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&Annotatable::Item(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("Item");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Annotatable::TraitItem(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("TraitItem");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
(&Annotatable::ImplItem(ref __self_0),) => {
let mut builder = __arg_0.debug_tuple("ImplItem");
let _ = builder.field(&&(*__self_0));
builder.finish()
}
}
}
}
impl Annotatable {
pub fn attrs(&self) -> &[ast::Attribute] {
match *self {
Annotatable::Item(ref i) => &i.attrs,
Annotatable::TraitItem(ref ti) => &ti.attrs,
Annotatable::ImplItem(ref ii) => &ii.attrs,
}
}
pub fn fold_attrs(self, attrs: Vec<ast::Attribute>)
-> Annotatable {
match self {
Annotatable::Item(i) =>
Annotatable::Item(i.map(|i|
ast::Item{attrs:
attrs, ..i})),
Annotatable::TraitItem(i) =>
Annotatable::TraitItem(i.map(|ti| {
ast::TraitItem{attrs:
attrs,
..ti}
})),
Annotatable::ImplItem(i) =>
Annotatable::ImplItem(i.map(|ii| {
ast::ImplItem{attrs:
attrs, ..ii}
})),
}
}
pub fn expect_item(self) -> P<ast::Item> {
match self {
Annotatable::Item(i) => i,
_ => {
::std::rt::begin_unwind("expected Item",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/base.rs",
71u32);
&_FILE_LINE
})
}
}
}
pub fn map_item_or<F, G>(self, mut f: F, mut or: G) -> Annotatable
where F: FnMut(P<ast::Item>) -> P<ast::Item>,
G: FnMut(Annotatable) -> Annotatable {
match self {
Annotatable::Item(i) => Annotatable::Item(f(i)),
_ => or(self),
}
}
pub fn expect_trait_item(self) -> P<ast::TraitItem> {
match self {
Annotatable::TraitItem(i) => i,
_ => {
::std::rt::begin_unwind("expected Item",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/base.rs",
88u32);
&_FILE_LINE
})
}
}
}
pub fn expect_impl_item(self) -> P<ast::ImplItem> {
match self {
Annotatable::ImplItem(i) => i,
_ => {
::std::rt::begin_unwind("expected Item",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/base.rs",
95u32);
&_FILE_LINE
})
}
}
}
}
pub trait MultiItemDecorator {
fn expand(&self, ecx: &mut ExtCtxt, sp: Span,
meta_item: &ast::MetaItem, item: &Annotatable,
push: &mut FnMut(Annotatable));
}
impl <F> MultiItemDecorator for F where
F: Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable,
&mut FnMut(Annotatable)) {
fn expand(&self, ecx: &mut ExtCtxt, sp: Span,
meta_item: &ast::MetaItem, item: &Annotatable,
push: &mut FnMut(Annotatable)) {
(*self)(ecx, sp, meta_item, item, push)
}
}
pub trait MultiItemModifier {
fn expand(&self, ecx: &mut ExtCtxt, span: Span,
meta_item: &ast::MetaItem, item: Annotatable)
-> Annotatable;
}
impl <F> MultiItemModifier for F where
F: Fn(&mut ExtCtxt, Span, &ast::MetaItem, Annotatable) -> Annotatable
{
fn expand(&self, ecx: &mut ExtCtxt, span: Span,
meta_item: &ast::MetaItem, item: Annotatable)
-> Annotatable {
(*self)(ecx, span, meta_item, item)
}
}
/// Represents a thing that maps token trees to Macro Results
pub trait TTMacroExpander {
fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span,
token_tree: &[ast::TokenTree])
-> Box<MacResult+ 'cx>;
}
pub type MacroExpanderFn =
for<'cx>fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree])
-> Box<MacResult+ 'cx>;
impl <F> TTMacroExpander for F where
F: for<'cx>Fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) ->
Box<MacResult+ 'cx> {
fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span,
token_tree: &[ast::TokenTree])
-> Box<MacResult+ 'cx> {
(*self)(ecx, span, token_tree)
}
}
pub trait IdentMacroExpander {
fn expand<'cx>(&self, cx: &'cx mut ExtCtxt, sp: Span,
ident: ast::Ident, token_tree: Vec<ast::TokenTree>)
-> Box<MacResult+ 'cx>;
}
pub type IdentMacroExpanderFn =
for<'cx>fn(&'cx mut ExtCtxt, Span, ast::Ident,
Vec<ast::TokenTree>) -> Box<MacResult+ 'cx>;
impl <F> IdentMacroExpander for F where
F: for<'cx>Fn(&'cx mut ExtCtxt, Span, ast::Ident,
Vec<ast::TokenTree>) -> Box<MacResult+ 'cx> {
fn expand<'cx>(&self, cx: &'cx mut ExtCtxt, sp: Span,
ident: ast::Ident, token_tree: Vec<ast::TokenTree>)
-> Box<MacResult+ 'cx> {
(*self)(cx, sp, ident, token_tree)
}
}
/// The result of a macro expansion. The return values of the various
/// methods are spliced into the AST at the callsite of the macro.
pub trait MacResult {
/// Create an expression.
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { None }
/// Create zero or more items.
fn make_items(self: Box<Self>)
-> Option<SmallVector<P<ast::Item>>> {
None
}
/// Create zero or more impl items.
fn make_impl_items(self: Box<Self>)
-> Option<SmallVector<P<ast::ImplItem>>> {
None
}
/// Create a pattern.
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> { None }
/// Create zero or more statements.
///
/// By default this attempts to create an expression statement,
/// returning None if that fails.
fn make_stmts(self: Box<Self>)
-> Option<SmallVector<P<ast::Stmt>>> {
self.make_expr().map(|e| {
SmallVector::one(P(codemap::respan(e.span,
ast::StmtExpr(e,
ast::DUMMY_NODE_ID))))
})
}
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { None }
}
/// `MacResult` implementation for the common case where you've already
/// built each form of AST that you might return.
pub struct MacEager {
pub expr: Option<P<ast::Expr>>,
pub pat: Option<P<ast::Pat>>,
pub items: Option<SmallVector<P<ast::Item>>>,
pub impl_items: Option<SmallVector<P<ast::ImplItem>>>,
pub stmts: Option<SmallVector<P<ast::Stmt>>>,
pub ty: Option<P<ast::Ty>>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::default::Default for MacEager {
#[inline]
fn default() -> MacEager {
MacEager{expr: ::std::default::Default::default(),
pat: ::std::default::Default::default(),
items: ::std::default::Default::default(),
impl_items: ::std::default::Default::default(),
stmts: ::std::default::Default::default(),
ty: ::std::default::Default::default(),}
}
}
impl MacEager {
pub fn expr(v: P<ast::Expr>) -> Box<MacResult> {
Box::new(MacEager{expr: Some(v), ..Default::default()})
}
pub fn pat(v: P<ast::Pat>) -> Box<MacResult> {
Box::new(MacEager{pat: Some(v), ..Default::default()})
}
pub fn items(v: SmallVector<P<ast::Item>>) -> Box<MacResult> {
Box::new(MacEager{items: Some(v), ..Default::default()})
}
pub fn impl_items(v: SmallVector<P<ast::ImplItem>>)
-> Box<MacResult> {
Box::new(MacEager{impl_items: Some(v), ..Default::default()})
}
pub fn stmts(v: SmallVector<P<ast::Stmt>>) -> Box<MacResult> {
Box::new(MacEager{stmts: Some(v), ..Default::default()})
}
pub fn ty(v: P<ast::Ty>) -> Box<MacResult> {
Box::new(MacEager{ty: Some(v), ..Default::default()})
}
}
impl MacResult for MacEager {
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
self.expr
}
fn make_items(self: Box<Self>)
-> Option<SmallVector<P<ast::Item>>> {
self.items
}
fn make_impl_items(self: Box<Self>)
-> Option<SmallVector<P<ast::ImplItem>>> {
self.impl_items
}
fn make_stmts(self: Box<Self>)
-> Option<SmallVector<P<ast::Stmt>>> {
match self.stmts.as_ref().map_or(0, |s| s.len()) {
0 =>
self.make_expr().map(|e| {
SmallVector::one(P(codemap::respan(e.span,
ast::StmtExpr(e,
ast::DUMMY_NODE_ID))))
}),
_ => self.stmts,
}
}
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
if let Some(p) = self.pat { return Some(p); }
if let Some(e) = self.expr {
if let ast::ExprLit(_) = e.node {
return Some(P(ast::Pat{id: ast::DUMMY_NODE_ID,
span: e.span,
node: ast::PatLit(e),}));
}
}
None
}
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { self.ty }
}
/// Fill-in macro expansion result, to allow compilation to continue
/// after hitting errors.
pub struct DummyResult {
expr_only: bool,
span: Span,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for DummyResult {
#[inline]
fn clone(&self) -> DummyResult {
match *self {
DummyResult {
expr_only: ref __self_0_0, span: ref __self_0_1 } =>
DummyResult{expr_only:
::std::clone::Clone::clone(&(*__self_0_0)),
span:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for DummyResult { }
impl DummyResult {
/// Create a default MacResult that can be anything.
///
/// Use this as a return value after hitting any errors and
/// calling `span_err`.
pub fn any(sp: Span) -> Box<MacResult+ 'static> {
Box::new(DummyResult{expr_only: false, span: sp,})
}
/// Create a default MacResult that can only be an expression.
///
/// Use this for macros that must expand to an expression, so even
/// if an error is encountered internally, the user will receive
/// an error that they also used it in the wrong place.
pub fn expr(sp: Span) -> Box<MacResult+ 'static> {
Box::new(DummyResult{expr_only: true, span: sp,})
}
/// A plain dummy expression.
pub fn raw_expr(sp: Span) -> P<ast::Expr> {
P(ast::Expr{id: ast::DUMMY_NODE_ID,
node:
ast::ExprLit(P(codemap::respan(sp,
ast::LitBool(false)))),
span: sp,
attrs: None,})
}
/// A plain dummy pattern.
pub fn raw_pat(sp: Span) -> ast::Pat {
ast::Pat{id: ast::DUMMY_NODE_ID,
node: ast::PatWild,
span: sp,}
}
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
P(ast::Ty{id: ast::DUMMY_NODE_ID,
node: ast::TyInfer,
span: sp,})
}
}
impl MacResult for DummyResult {
fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> {
Some(DummyResult::raw_expr(self.span))
}
fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
Some(P(DummyResult::raw_pat(self.span)))
}
fn make_items(self: Box<DummyResult>)
-> Option<SmallVector<P<ast::Item>>> {
if self.expr_only { None } else { Some(SmallVector::zero()) }
}
fn make_impl_items(self: Box<DummyResult>)
-> Option<SmallVector<P<ast::ImplItem>>> {
if self.expr_only { None } else { Some(SmallVector::zero()) }
}
fn make_stmts(self: Box<DummyResult>)
-> Option<SmallVector<P<ast::Stmt>>> {
Some(SmallVector::one(P(codemap::respan(self.span,
ast::StmtExpr(DummyResult::raw_expr(self.span),
ast::DUMMY_NODE_ID)))))
}
}
/// An enum representing the different kinds of syntax extensions.
pub enum SyntaxExtension {
/// A syntax extension that is attached to an item and creates new items
/// based upon it.
///
/// `#[derive(...)]` is a `MultiItemDecorator`.
MultiDecorator(Box<MultiItemDecorator+ 'static>),
/// A syntax extension that is attached to an item and modifies it
/// in-place. More flexible version than Modifier.
MultiModifier(Box<MultiItemModifier+ 'static>),
/// A normal, function-like syntax extension.
///
/// `bytes!` is a `NormalTT`.
///
/// The `bool` dictates whether the contents of the macro can
/// directly use `#[unstable]` things (true == yes).
NormalTT(Box<TTMacroExpander+ 'static>, Option<Span>, bool),
/// A function-like syntax extension that has an extra ident before
/// the block.
///
IdentTT(Box<IdentMacroExpander+ 'static>, Option<Span>, bool),
/// Represents `macro_rules!` itself.
MacroRulesTT,
}
pub type NamedSyntaxExtension = (Name, SyntaxExtension);
pub struct BlockInfo {
/// Should macros escape from this scope?
pub macros_escape: bool,
/// What are the pending renames?
pub pending_renames: mtwt::RenameList,
}
impl BlockInfo {
pub fn new() -> BlockInfo {
BlockInfo{macros_escape: false, pending_renames: Vec::new(),}
}
}
/// The base map of methods for expanding syntax extension
/// AST nodes into full ASTs
fn initial_syntax_expander_table<'feat>(_ecfg:
&expand::ExpansionConfig<'feat>)
-> SyntaxEnv {
fn builtin_normal_expander(f: MacroExpanderFn)
-> SyntaxExtension {
NormalTT(Box::new(f), None, false)
}
let mut syntax_expanders = SyntaxEnv::new();
ext::deriving::register_all(&mut syntax_expanders);
syntax_expanders.insert(intern("option_env"),
builtin_normal_expander(ext::env::expand_option_env));
syntax_expanders.insert(intern("env"),
builtin_normal_expander(ext::env::expand_env));
syntax_expanders.insert(intern("include"),
builtin_normal_expander(ext::source_util::expand_include));
syntax_expanders.insert(intern("include_str"),
builtin_normal_expander(ext::source_util::expand_include_str));
syntax_expanders.insert(intern("include_bytes"),
builtin_normal_expander(ext::source_util::expand_include_bytes));
syntax_expanders
}
/// One of these is made during expansion and incrementally updated as we go;
/// when a macro expansion occurs, the resulting nodes have the backtrace()
/// -> expn_info of their expansion context stored into their span.
pub struct ExtCtxt<'a> {
pub parse_sess: &'a parse::ParseSess,
pub cfg: ast::CrateConfig,
pub backtrace: ExpnId,
pub ecfg: expand::ExpansionConfig<'a>,
pub crate_root: Option<&'static str>,
pub feature_gated_cfgs: &'a mut Vec<GatedCfgAttr>,
pub mod_path: Vec<ast::Ident>,
pub exported_macros: Vec<ast::MacroDef>,
pub syntax_env: SyntaxEnv,
pub recursion_count: usize,
}
impl <'a> ExtCtxt<'a> {
pub fn new(parse_sess: &'a parse::ParseSess,
cfg: ast::CrateConfig,
ecfg: expand::ExpansionConfig<'a>,
feature_gated_cfgs: &'a mut Vec<GatedCfgAttr>)
-> ExtCtxt<'a> {
let env = initial_syntax_expander_table(&ecfg);
ExtCtxt{parse_sess: parse_sess,
cfg: cfg,
backtrace: NO_EXPANSION,
mod_path: Vec::new(),
ecfg: ecfg,
crate_root: None,
feature_gated_cfgs: feature_gated_cfgs,
exported_macros: Vec::new(),
syntax_env: env,
recursion_count: 0,}
}
/// Returns a `Folder` for deeply expanding all macros in an AST node.
pub fn expander<'b>(&'b mut self)
-> expand::MacroExpander<'b, 'a> {
expand::MacroExpander::new(self)
}
pub fn new_parser_from_tts(&self, tts: &[ast::TokenTree])
-> parser::Parser<'a> {
parse::tts_to_parser(self.parse_sess, tts.to_vec(),
self.cfg())
}
pub fn codemap(&self) -> &'a CodeMap { self.parse_sess.codemap() }
pub fn parse_sess(&self) -> &'a parse::ParseSess {
self.parse_sess
}
pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
pub fn call_site(&self) -> Span {
self.codemap().with_expn_info(self.backtrace,
|ei|
match ei {
Some(expn_info) =>
expn_info.call_site,
None =>
self.bug("missing top span"),
})
}
pub fn backtrace(&self) -> ExpnId { self.backtrace }
/// Original span that caused the current exapnsion to happen.
pub fn original_span(&self) -> Span {
let mut expn_id = self.backtrace;
let mut call_site = None;
loop {
match self.codemap().with_expn_info(expn_id,
|ei|
ei.map(|ei|
ei.call_site))
{
None => break ,
Some(cs) => {
call_site = Some(cs);
expn_id = cs.expn_id;
}
}
}
call_site.expect("missing expansion backtrace")
}
/// Returns span for the macro which originally caused the current expansion to happen.
///
/// Stops backtracing at include! boundary.
pub fn expansion_cause(&self) -> Span {
let mut expn_id = self.backtrace;
let mut last_macro = None;
loop {
if self.codemap().with_expn_info(expn_id, |info| {
info.map_or(None, |i| {
if i.callee.name().as_str()
==
"include"
{
return None;
}
expn_id =
i.call_site.expn_id;
last_macro =
Some(i.call_site);
return Some(());
}) }).is_none() {
break
}
}
last_macro.expect("missing expansion backtrace")
}
pub fn mod_push(&mut self, i: ast::Ident) {
self.mod_path.push(i);
}
pub fn mod_pop(&mut self) { self.mod_path.pop().unwrap(); }
pub fn mod_path(&self) -> Vec<ast::Ident> {
let mut v = Vec::new();
v.push(token::str_to_ident(&self.ecfg.crate_name));
v.extend(self.mod_path.iter().cloned());
return v;
}
pub fn bt_push(&mut self, ei: ExpnInfo) {
self.recursion_count += 1;
if self.recursion_count > self.ecfg.recursion_limit {
self.span_fatal(ei.call_site,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["recursion limit reached while expanding the macro `",
"`"];
__STATIC_FMTSTR
},
&match (&ei.callee.name(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
let mut call_site = ei.call_site;
call_site.expn_id = self.backtrace;
self.backtrace =
self.codemap().record_expansion(ExpnInfo{call_site:
call_site,
callee:
ei.callee,});
}
pub fn bt_pop(&mut self) {
match self.backtrace {
NO_EXPANSION => self.bug("tried to pop without a push"),
expn_id => {
self.recursion_count -= 1;
self.backtrace =
self.codemap().with_expn_info(expn_id,
|expn_info| {
expn_info.map_or(NO_EXPANSION,
|ei|
ei.call_site.expn_id)
});
}
}
}
pub fn insert_macro(&mut self, def: ast::MacroDef) {
if def.export { self.exported_macros.push(def.clone()); }
if def.use_locally {
let ext = macro_rules::compile(self, &def);
self.syntax_env.insert(def.ident.name, ext);
}
}
pub fn struct_span_warn(&self, sp: Span, msg: &str)
-> DiagnosticBuilder<'a> {
self.parse_sess.span_diagnostic.struct_span_warn(sp, msg)
}
pub fn struct_span_err(&self, sp: Span, msg: &str)
-> DiagnosticBuilder<'a> {
self.parse_sess.span_diagnostic.struct_span_err(sp, msg)
}
pub fn struct_span_fatal(&self, sp: Span, msg: &str)
-> DiagnosticBuilder<'a> {
self.parse_sess.span_diagnostic.struct_span_fatal(sp, msg)
}
/// Emit `msg` attached to `sp`, and stop compilation immediately.
///
/// `span_err` should be strongly preferred where-ever possible:
/// this should *only* be used when
/// - continuing has a high risk of flow-on errors (e.g. errors in
/// declaring a macro would cause all uses of that macro to
/// complain about "undefined macro"), or
/// - there is literally nothing else that can be done (however,
/// in most cases one can construct a dummy expression/item to
/// substitute; we never hit resolve/type-checking so the dummy
/// value doesn't have to match anything)
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
{
::std::rt::begin_unwind(self.parse_sess.span_diagnostic.span_fatal(sp,
msg),
{
static _FILE_LINE:
(&'static str, u32) =
("src/ext/base.rs",
731u32);
&_FILE_LINE
})
};
}
/// Emit `msg` attached to `sp`, without immediately stopping
/// compilation.
///
/// Compilation will be stopped in the near future (at the end of
/// the macro expansion phase).
pub fn span_err(&self, sp: Span, msg: &str) {
self.parse_sess.span_diagnostic.span_err(sp, msg);
}
pub fn span_warn(&self, sp: Span, msg: &str) {
self.parse_sess.span_diagnostic.span_warn(sp, msg);
}
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
}
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
self.parse_sess.span_diagnostic.span_bug(sp, msg);
}
pub fn bug(&self, msg: &str) -> ! {
self.parse_sess.span_diagnostic.bug(msg);
}
pub fn trace_macros(&self) -> bool { self.ecfg.trace_mac }
pub fn set_trace_macros(&mut self, x: bool) {
self.ecfg.trace_mac = x
}
pub fn ident_of(&self, st: &str) -> ast::Ident {
str_to_ident(st)
}
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
let mut v = Vec::new();
if let Some(s) = self.crate_root { v.push(self.ident_of(s)); }
v.extend(components.iter().map(|s| self.ident_of(s)));
return v
}
pub fn name_of(&self, st: &str) -> ast::Name { token::intern(st) }
pub fn suggest_macro_name(&mut self, name: &str, span: Span,
err: &mut DiagnosticBuilder<'a>) {
let names = &self.syntax_env.names;
if let Some(suggestion) =
find_best_match_for_name(names.iter(), name, None) {
err.fileline_help(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["did you mean `",
"!`?"];
__STATIC_FMTSTR
},
&match (&suggestion,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
}
}
/// Extract a string literal from the macro expanded version of `expr`,
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
/// compilation on error, merely emits a non-fatal error and returns None.
pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>,
err_msg: &str)
-> Option<(InternedString, ast::StrStyle)> {
let expr = cx.expander().fold_expr(expr);
match expr.node {
ast::ExprLit(ref l) =>
match l.node {
ast::LitStr(ref s, style) =>
return Some(((*s).clone(), style)),
_ => cx.span_err(l.span, err_msg),
},
_ => cx.span_err(expr.span, err_msg),
}
None
}
/// Non-fatally assert that `tts` is empty. Note that this function
/// returns even when `tts` is non-empty, macros that *need* to stop
/// compilation should call
/// `cx.parse_sess.span_diagnostic.abort_if_errors()` (this should be
/// done as rarely as possible).
pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree],
name: &str) {
if !tts.is_empty() {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" takes no arguments"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
}
/// Extract the string literal from the first token of `tts`. If this
/// is not a string literal, emit an error and return None.
pub fn get_single_str_from_tts(cx: &mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree], name: &str)
-> Option<String> {
let mut p = cx.new_parser_from_tts(tts);
if p.token == token::Eof {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" takes 1 argument"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return None
}
let ret =
cx.expander().fold_expr({
use std::result::Result::{Ok,
Err};
use errors::FatalError;
match p.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/base.rs",
829u32);
&_FILE_LINE
})
};
}
}
});
if p.token != token::Eof {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" takes 1 argument"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
}
expr_to_string(cx, ret,
"argument must be a string literal").map(|(s, _)| {
s.to_string()
})
}
/// Extract comma-separated expressions from `tts`. If there is a
/// parsing error, emit a non-fatal error and return None.
pub fn get_exprs_from_tts(cx: &mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Option<Vec<P<ast::Expr>>> {
let mut p = cx.new_parser_from_tts(tts);
let mut es = Vec::new();
while p.token != token::Eof {
es.push(cx.expander().fold_expr({
use std::result::Result::{Ok,
Err};
use errors::FatalError;
match p.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/base.rs",
846u32);
&_FILE_LINE
})
};
}
}
}));
if p.eat(&token::Comma) { continue ; }
if p.token != token::Eof {
cx.span_err(sp, "expected token: `,`");
return None;
}
}
Some(es)
}
/// In order to have some notion of scoping for macros,
/// we want to implement the notion of a transformation
/// environment.
///
/// This environment maps Names to SyntaxExtensions.
pub struct SyntaxEnv {
chain: Vec<MapChainFrame>,
/// All bang-style macro/extension names
/// encountered so far; to be used for diagnostics in resolve
pub names: HashSet<Name>,
}
struct MapChainFrame {
info: BlockInfo,
map: HashMap<Name, Rc<SyntaxExtension>>,
}
impl SyntaxEnv {
fn new() -> SyntaxEnv {
let mut map =
SyntaxEnv{chain: Vec::new(), names: HashSet::new(),};
map.push_frame();
map
}
pub fn push_frame(&mut self) {
self.chain.push(MapChainFrame{info: BlockInfo::new(),
map: HashMap::new(),});
}
pub fn pop_frame(&mut self) {
if !(self.chain.len() > 1) {
{
::std::rt::begin_unwind("too many pops on MapChain!",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/base.rs",
900u32);
&_FILE_LINE
})
}
};
self.chain.pop();
}
fn find_escape_frame(&mut self) -> &mut MapChainFrame {
for (i, frame) in self.chain.iter_mut().enumerate().rev() {
if !frame.info.macros_escape || i == 0 { return frame }
}
{
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/base.rs",
910u32);
&_FILE_LINE
})
}
}
}
pub fn find(&self, k: Name) -> Option<Rc<SyntaxExtension>> {
for frame in self.chain.iter().rev() {
match frame.map.get(&k) {
Some(v) => return Some(v.clone()),
None => { }
}
}
None
}
pub fn insert(&mut self, k: Name, v: SyntaxExtension) {
if let NormalTT(..) = v { self.names.insert(k); }
self.find_escape_frame().map.insert(k, Rc::new(v));
}
pub fn info(&mut self) -> &mut BlockInfo {
let last_chain_index = self.chain.len() - 1;
&mut self.chain[last_chain_index].info
}
}
}
pub mod build {
#[prelude_import]
use std::prelude::v1::*;
use abi;
use ast::{Ident, Generics, Expr};
use ast;
use attr;
use codemap::{Span, respan, Spanned, DUMMY_SP, Pos};
use ext::base::ExtCtxt;
use parse::token::special_idents;
use parse::token::InternedString;
use parse::token;
use ptr::P;
mod syntax {
#[prelude_import]
use std::prelude::v1::*;
pub use ext;
pub use parse;
}
pub trait AstBuilder {
fn path(&self, span: Span, strs: Vec<ast::Ident>)
-> ast::Path;
fn path_ident(&self, span: Span, id: ast::Ident)
-> ast::Path;
fn path_global(&self, span: Span, strs: Vec<ast::Ident>)
-> ast::Path;
fn path_all(&self, sp: Span, global: bool,
idents: Vec<ast::Ident>,
lifetimes: Vec<ast::Lifetime>, types: Vec<P<ast::Ty>>,
bindings: Vec<P<ast::TypeBinding>>)
-> ast::Path;
fn qpath(&self, self_type: P<ast::Ty>, trait_path: ast::Path,
ident: ast::Ident)
-> (ast::QSelf, ast::Path);
fn qpath_all(&self, self_type: P<ast::Ty>, trait_path: ast::Path,
ident: ast::Ident, lifetimes: Vec<ast::Lifetime>,
types: Vec<P<ast::Ty>>,
bindings: Vec<P<ast::TypeBinding>>)
-> (ast::QSelf, ast::Path);
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability)
-> ast::MutTy;
fn ty(&self, span: Span, ty: ast::Ty_)
-> P<ast::Ty>;
fn ty_path(&self, ast::Path)
-> P<ast::Ty>;
fn ty_sum(&self, ast::Path, ast::TyParamBounds)
-> P<ast::Ty>;
fn ty_ident(&self, span: Span, idents: ast::Ident)
-> P<ast::Ty>;
fn ty_rptr(&self, span: Span, ty: P<ast::Ty>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::Mutability)
-> P<ast::Ty>;
fn ty_ptr(&self, span: Span, ty: P<ast::Ty>,
mutbl: ast::Mutability)
-> P<ast::Ty>;
fn ty_option(&self, ty: P<ast::Ty>)
-> P<ast::Ty>;
fn ty_infer(&self, sp: Span)
-> P<ast::Ty>;
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>)
-> Vec<P<ast::Ty>>;
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>)
-> Vec<P<ast::Ty>>;
fn typaram(&self, span: Span, id: ast::Ident,
bounds: ast::TyParamBounds,
default: Option<P<ast::Ty>>)
-> ast::TyParam;
fn trait_ref(&self, path: ast::Path)
-> ast::TraitRef;
fn poly_trait_ref(&self, span: Span, path: ast::Path)
-> ast::PolyTraitRef;
fn typarambound(&self, path: ast::Path)
-> ast::TyParamBound;
fn lifetime(&self, span: Span, ident: ast::Name)
-> ast::Lifetime;
fn lifetime_def(&self, span: Span, name: ast::Name,
bounds: Vec<ast::Lifetime>)
-> ast::LifetimeDef;
fn stmt_expr(&self, expr: P<ast::Expr>)
-> P<ast::Stmt>;
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
ex: P<ast::Expr>)
-> P<ast::Stmt>;
fn stmt_let_typed(&self, sp: Span, mutbl: bool, ident: ast::Ident,
typ: P<ast::Ty>, ex: P<ast::Expr>)
-> P<ast::Stmt>;
fn stmt_item(&self, sp: Span, item: P<ast::Item>)
-> P<ast::Stmt>;
fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
expr: Option<P<ast::Expr>>)
-> P<ast::Block>;
fn block_expr(&self, expr: P<ast::Expr>)
-> P<ast::Block>;
fn block_all(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
expr: Option<P<ast::Expr>>)
-> P<ast::Block>;
fn expr(&self, span: Span, node: ast::Expr_)
-> P<ast::Expr>;
fn expr_path(&self, path: ast::Path)
-> P<ast::Expr>;
fn expr_qpath(&self, span: Span, qself: ast::QSelf,
path: ast::Path)
-> P<ast::Expr>;
fn expr_ident(&self, span: Span, id: ast::Ident)
-> P<ast::Expr>;
fn expr_self(&self, span: Span)
-> P<ast::Expr>;
fn expr_binary(&self, sp: Span, op: ast::BinOp_,
lhs: P<ast::Expr>, rhs: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_deref(&self, sp: Span, e: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_field_access(&self, span: Span, expr: P<ast::Expr>,
ident: ast::Ident)
-> P<ast::Expr>;
fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>,
idx: usize)
-> P<ast::Expr>;
fn expr_call(&self, span: Span, expr: P<ast::Expr>,
args: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_call_ident(&self, span: Span, id: ast::Ident,
args: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident>,
args: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_method_call(&self, span: Span, expr: P<ast::Expr>,
ident: ast::Ident, args: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_block(&self, b: P<ast::Block>)
-> P<ast::Expr>;
fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>)
-> P<ast::Expr>;
fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>)
-> ast::Field;
fn expr_struct(&self, span: Span, path: ast::Path,
fields: Vec<ast::Field>)
-> P<ast::Expr>;
fn expr_struct_ident(&self, span: Span, id: ast::Ident,
fields: Vec<ast::Field>)
-> P<ast::Expr>;
fn expr_lit(&self, sp: Span, lit: ast::Lit_)
-> P<ast::Expr>;
fn expr_usize(&self, span: Span, i: usize)
-> P<ast::Expr>;
fn expr_isize(&self, sp: Span, i: isize)
-> P<ast::Expr>;
fn expr_u8(&self, sp: Span, u: u8)
-> P<ast::Expr>;
fn expr_u32(&self, sp: Span, u: u32)
-> P<ast::Expr>;
fn expr_bool(&self, sp: Span, value: bool)
-> P<ast::Expr>;
fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_vec_ng(&self, sp: Span)
-> P<ast::Expr>;
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_str(&self, sp: Span, s: InternedString)
-> P<ast::Expr>;
fn expr_some(&self, sp: Span, expr: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_none(&self, sp: Span)
-> P<ast::Expr>;
fn expr_break(&self, sp: Span)
-> P<ast::Expr>;
fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_fail(&self, span: Span, msg: InternedString)
-> P<ast::Expr>;
fn expr_unreachable(&self, span: Span)
-> P<ast::Expr>;
fn expr_ok(&self, span: Span, expr: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_err(&self, span: Span, expr: P<ast::Expr>)
-> P<ast::Expr>;
fn expr_try(&self, span: Span, head: P<ast::Expr>)
-> P<ast::Expr>;
fn pat(&self, span: Span, pat: ast::Pat_)
-> P<ast::Pat>;
fn pat_wild(&self, span: Span)
-> P<ast::Pat>;
fn pat_lit(&self, span: Span, expr: P<ast::Expr>)
-> P<ast::Pat>;
fn pat_ident(&self, span: Span, ident: ast::Ident)
-> P<ast::Pat>;
fn pat_ident_binding_mode(&self, span: Span, ident: ast::Ident,
bm: ast::BindingMode)
-> P<ast::Pat>;
fn pat_enum(&self, span: Span, path: ast::Path,
subpats: Vec<P<ast::Pat>>)
-> P<ast::Pat>;
fn pat_struct(&self, span: Span, path: ast::Path,
field_pats: Vec<Spanned<ast::FieldPat>>)
-> P<ast::Pat>;
fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>)
-> P<ast::Pat>;
fn pat_some(&self, span: Span, pat: P<ast::Pat>)
-> P<ast::Pat>;
fn pat_none(&self, span: Span)
-> P<ast::Pat>;
fn pat_ok(&self, span: Span, pat: P<ast::Pat>)
-> P<ast::Pat>;
fn pat_err(&self, span: Span, pat: P<ast::Pat>)
-> P<ast::Pat>;
fn arm(&self, span: Span, pats: Vec<P<ast::Pat>>,
expr: P<ast::Expr>)
-> ast::Arm;
fn arm_unreachable(&self, span: Span)
-> ast::Arm;
fn expr_match(&self, span: Span, arg: P<ast::Expr>,
arms: Vec<ast::Arm>)
-> P<ast::Expr>;
fn expr_if(&self, span: Span, cond: P<ast::Expr>,
then: P<ast::Expr>, els: Option<P<ast::Expr>>)
-> P<ast::Expr>;
fn expr_loop(&self, span: Span, block: P<ast::Block>)
-> P<ast::Expr>;
fn lambda_fn_decl(&self, span: Span, fn_decl: P<ast::FnDecl>,
blk: P<ast::Block>)
-> P<ast::Expr>;
fn lambda(&self, span: Span, ids: Vec<ast::Ident>,
blk: P<ast::Block>)
-> P<ast::Expr>;
fn lambda0(&self, span: Span, blk: P<ast::Block>)
-> P<ast::Expr>;
fn lambda1(&self, span: Span, blk: P<ast::Block>,
ident: ast::Ident)
-> P<ast::Expr>;
fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident>,
blk: P<ast::Expr>)
-> P<ast::Expr>;
fn lambda_expr_0(&self, span: Span, expr: P<ast::Expr>)
-> P<ast::Expr>;
fn lambda_expr_1(&self, span: Span, expr: P<ast::Expr>,
ident: ast::Ident)
-> P<ast::Expr>;
fn lambda_stmts(&self, span: Span, ids: Vec<ast::Ident>,
blk: Vec<P<ast::Stmt>>)
-> P<ast::Expr>;
fn lambda_stmts_0(&self, span: Span, stmts: Vec<P<ast::Stmt>>)
-> P<ast::Expr>;
fn lambda_stmts_1(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
ident: ast::Ident)
-> P<ast::Expr>;
fn item(&self, span: Span, name: Ident,
attrs: Vec<ast::Attribute>, node: ast::Item_)
-> P<ast::Item>;
fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>)
-> ast::Arg;
fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>)
-> P<ast::FnDecl>;
fn item_fn_poly(&self, span: Span, name: Ident,
inputs: Vec<ast::Arg>, output: P<ast::Ty>,
generics: Generics, body: P<ast::Block>)
-> P<ast::Item>;
fn item_fn(&self, span: Span, name: Ident, inputs: Vec<ast::Arg>,
output: P<ast::Ty>, body: P<ast::Block>)
-> P<ast::Item>;
fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>>)
-> ast::Variant;
fn item_enum_poly(&self, span: Span, name: Ident,
enum_definition: ast::EnumDef,
generics: Generics)
-> P<ast::Item>;
fn item_enum(&self, span: Span, name: Ident,
enum_def: ast::EnumDef)
-> P<ast::Item>;
fn item_struct_poly(&self, span: Span, name: Ident,
struct_def: ast::VariantData,
generics: Generics)
-> P<ast::Item>;
fn item_struct(&self, span: Span, name: Ident,
struct_def: ast::VariantData)
-> P<ast::Item>;
fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
attrs: Vec<ast::Attribute>, items: Vec<P<ast::Item>>)
-> P<ast::Item>;
fn item_static(&self, span: Span, name: Ident, ty: P<ast::Ty>,
mutbl: ast::Mutability, expr: P<ast::Expr>)
-> P<ast::Item>;
fn item_const(&self, span: Span, name: Ident, ty: P<ast::Ty>,
expr: P<ast::Expr>)
-> P<ast::Item>;
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
generics: Generics)
-> P<ast::Item>;
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>)
-> P<ast::Item>;
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>)
-> ast::Attribute;
fn meta_word(&self, sp: Span, w: InternedString)
-> P<ast::MetaItem>;
fn meta_list(&self, sp: Span, name: InternedString,
mis: Vec<P<ast::MetaItem>>)
-> P<ast::MetaItem>;
fn meta_name_value(&self, sp: Span, name: InternedString,
value: ast::Lit_)
-> P<ast::MetaItem>;
fn item_use(&self, sp: Span, vis: ast::Visibility,
vp: P<ast::ViewPath>)
-> P<ast::Item>;
fn item_use_simple(&self, sp: Span, vis: ast::Visibility,
path: ast::Path)
-> P<ast::Item>;
fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path)
-> P<ast::Item>;
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>, imports: &[ast::Ident])
-> P<ast::Item>;
fn item_use_glob(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>)
-> P<ast::Item>;
}
impl <'a> AstBuilder for ExtCtxt<'a> {
fn path(&self, span: Span, strs: Vec<ast::Ident>) -> ast::Path {
self.path_all(span, false, strs, Vec::new(), Vec::new(),
Vec::new())
}
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
self.path(span, <[_]>::into_vec(::std::boxed::Box::new([id])))
}
fn path_global(&self, span: Span, strs: Vec<ast::Ident>)
-> ast::Path {
self.path_all(span, true, strs, Vec::new(), Vec::new(),
Vec::new())
}
fn path_all(&self, sp: Span, global: bool,
mut idents: Vec<ast::Ident>,
lifetimes: Vec<ast::Lifetime>, types: Vec<P<ast::Ty>>,
bindings: Vec<P<ast::TypeBinding>>) -> ast::Path {
let last_identifier = idents.pop().unwrap();
let mut segments: Vec<ast::PathSegment> =
idents.into_iter().map(|ident| {
ast::PathSegment{identifier: ident,
parameters:
ast::PathParameters::none(),}
}).collect();
segments.push(ast::PathSegment{identifier: last_identifier,
parameters:
ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData{lifetimes:
lifetimes,
types:
P::from_vec(types),
bindings:
P::from_vec(bindings),}),});
ast::Path{span: sp, global: global, segments: segments,}
}
/// Constructs a qualified path.
///
/// Constructs a path like `<self_type as trait_path>::ident`.
fn qpath(&self, self_type: P<ast::Ty>, trait_path: ast::Path,
ident: ast::Ident) -> (ast::QSelf, ast::Path) {
self.qpath_all(self_type, trait_path, ident,
<[_]>::into_vec(::std::boxed::Box::new([])),
<[_]>::into_vec(::std::boxed::Box::new([])),
<[_]>::into_vec(::std::boxed::Box::new([])))
}
/// Constructs a qualified path.
///
/// Constructs a path like `<self_type as trait_path>::ident<'a, T, A=Bar>`.
fn qpath_all(&self, self_type: P<ast::Ty>, trait_path: ast::Path,
ident: ast::Ident, lifetimes: Vec<ast::Lifetime>,
types: Vec<P<ast::Ty>>,
bindings: Vec<P<ast::TypeBinding>>)
-> (ast::QSelf, ast::Path) {
let mut path = trait_path;
path.segments.push(ast::PathSegment{identifier: ident,
parameters:
ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData{lifetimes:
lifetimes,
types:
P::from_vec(types),
bindings:
P::from_vec(bindings),}),});
(ast::QSelf{ty: self_type,
position: path.segments.len() - 1,}, path)
}
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability)
-> ast::MutTy {
ast::MutTy{ty: ty, mutbl: mutbl,}
}
fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> {
P(ast::Ty{id: ast::DUMMY_NODE_ID, span: span, node: ty,})
}
fn ty_path(&self, path: ast::Path) -> P<ast::Ty> {
self.ty(path.span, ast::TyPath(None, path))
}
fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds)
-> P<ast::Ty> {
self.ty(path.span,
ast::TyObjectSum(self.ty_path(path), bounds))
}
fn ty_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Ty> {
self.ty_path(self.path_ident(span, ident))
}
fn ty_rptr(&self, span: Span, ty: P<ast::Ty>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::Mutability) -> P<ast::Ty> {
self.ty(span, ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
}
fn ty_ptr(&self, span: Span, ty: P<ast::Ty>,
mutbl: ast::Mutability) -> P<ast::Ty> {
self.ty(span, ast::TyPtr(self.ty_mt(ty, mutbl)))
}
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
self.ty_path(self.path_all(DUMMY_SP, true,
self.std_path(&["option",
"Option"]),
Vec::new(),
<[_]>::into_vec(::std::boxed::Box::new([ty])),
Vec::new()))
}
fn ty_infer(&self, span: Span) -> P<ast::Ty> {
self.ty(span, ast::TyInfer)
}
fn typaram(&self, span: Span, id: ast::Ident,
bounds: ast::TyParamBounds,
default: Option<P<ast::Ty>>) -> ast::TyParam {
ast::TyParam{ident: id,
id: ast::DUMMY_NODE_ID,
bounds: bounds,
default: default,
span: span,}
}
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>)
-> Vec<P<ast::Ty>> {
ty_params.iter().map(|p|
self.ty_ident(DUMMY_SP,
p.ident)).collect()
}
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>)
-> Vec<P<ast::Ty>> {
ty_params.iter().map(|p|
self.ty_path(self.path_global(DUMMY_SP,
<[_]>::into_vec(::std::boxed::Box::new([p.ident]))))).collect()
}
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
ast::TraitRef{path: path, ref_id: ast::DUMMY_NODE_ID,}
}
fn poly_trait_ref(&self, span: Span, path: ast::Path)
-> ast::PolyTraitRef {
ast::PolyTraitRef{bound_lifetimes: Vec::new(),
trait_ref: self.trait_ref(path),
span: span,}
}
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound {
ast::TraitTyParamBound(self.poly_trait_ref(path.span, path),
ast::TraitBoundModifier::None)
}
fn lifetime(&self, span: Span, name: ast::Name) -> ast::Lifetime {
ast::Lifetime{id: ast::DUMMY_NODE_ID, span: span, name: name,}
}
fn lifetime_def(&self, span: Span, name: ast::Name,
bounds: Vec<ast::Lifetime>) -> ast::LifetimeDef {
ast::LifetimeDef{lifetime: self.lifetime(span, name),
bounds: bounds,}
}
fn stmt_expr(&self, expr: P<ast::Expr>) -> P<ast::Stmt> {
P(respan(expr.span, ast::StmtSemi(expr, ast::DUMMY_NODE_ID)))
}
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
ex: P<ast::Expr>) -> P<ast::Stmt> {
let pat =
if mutbl {
self.pat_ident_binding_mode(sp, ident,
ast::BindingMode::ByValue(ast::MutMutable))
} else { self.pat_ident(sp, ident) };
let local =
P(ast::Local{pat: pat,
ty: None,
init: Some(ex),
id: ast::DUMMY_NODE_ID,
span: sp,
attrs: None,});
let decl = respan(sp, ast::DeclLocal(local));
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
}
fn stmt_let_typed(&self, sp: Span, mutbl: bool, ident: ast::Ident,
typ: P<ast::Ty>, ex: P<ast::Expr>)
-> P<ast::Stmt> {
let pat =
if mutbl {
self.pat_ident_binding_mode(sp, ident,
ast::BindingMode::ByValue(ast::MutMutable))
} else { self.pat_ident(sp, ident) };
let local =
P(ast::Local{pat: pat,
ty: Some(typ),
init: Some(ex),
id: ast::DUMMY_NODE_ID,
span: sp,
attrs: None,});
let decl = respan(sp, ast::DeclLocal(local));
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
}
fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
expr: Option<P<Expr>>) -> P<ast::Block> {
self.block_all(span, stmts, expr)
}
fn stmt_item(&self, sp: Span, item: P<ast::Item>)
-> P<ast::Stmt> {
let decl = respan(sp, ast::DeclItem(item));
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
}
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
self.block_all(expr.span, Vec::new(), Some(expr))
}
fn block_all(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
expr: Option<P<ast::Expr>>) -> P<ast::Block> {
P(ast::Block{stmts: stmts,
expr: expr,
id: ast::DUMMY_NODE_ID,
rules: ast::DefaultBlock,
span: span,})
}
fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr> {
P(ast::Expr{id: ast::DUMMY_NODE_ID,
node: node,
span: span,
attrs: None,})
}
fn expr_path(&self, path: ast::Path) -> P<ast::Expr> {
self.expr(path.span, ast::ExprPath(None, path))
}
/// Constructs a QPath expression.
fn expr_qpath(&self, span: Span, qself: ast::QSelf,
path: ast::Path) -> P<ast::Expr> {
self.expr(span, ast::ExprPath(Some(qself), path))
}
fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr> {
self.expr_path(self.path_ident(span, id))
}
fn expr_self(&self, span: Span) -> P<ast::Expr> {
self.expr_ident(span, special_idents::self_)
}
fn expr_binary(&self, sp: Span, op: ast::BinOp_,
lhs: P<ast::Expr>, rhs: P<ast::Expr>)
-> P<ast::Expr> {
self.expr(sp,
ast::ExprBinary(Spanned{node: op, span: sp,}, lhs,
rhs))
}
fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
self.expr_unary(sp, ast::UnDeref, e)
}
fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>)
-> P<ast::Expr> {
self.expr(sp, ast::ExprUnary(op, e))
}
fn expr_field_access(&self, sp: Span, expr: P<ast::Expr>,
ident: ast::Ident) -> P<ast::Expr> {
let field_span =
Span{lo:
sp.lo -
Pos::from_usize(ident.name.as_str().len()),
hi: sp.hi,
expn_id: sp.expn_id,};
let id = Spanned{node: ident, span: field_span,};
self.expr(sp, ast::ExprField(expr, id))
}
fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>,
idx: usize) -> P<ast::Expr> {
let field_span =
Span{lo: sp.lo - Pos::from_usize(idx.to_string().len()),
hi: sp.hi,
expn_id: sp.expn_id,};
let id = Spanned{node: idx, span: field_span,};
self.expr(sp, ast::ExprTupField(expr, id))
}
fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>)
-> P<ast::Expr> {
self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e))
}
fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>)
-> P<ast::Expr> {
self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e))
}
fn expr_call(&self, span: Span, expr: P<ast::Expr>,
args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
self.expr(span, ast::ExprCall(expr, args))
}
fn expr_call_ident(&self, span: Span, id: ast::Ident,
args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
self.expr(span,
ast::ExprCall(self.expr_ident(span, id), args))
}
fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident>,
args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
let pathexpr = self.expr_path(self.path_global(sp, fn_path));
self.expr_call(sp, pathexpr, args)
}
fn expr_method_call(&self, span: Span, expr: P<ast::Expr>,
ident: ast::Ident,
mut args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
let id = Spanned{node: ident, span: span,};
args.insert(0, expr);
self.expr(span, ast::ExprMethodCall(id, Vec::new(), args))
}
fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> {
self.expr(b.span, ast::ExprBlock(b))
}
fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>)
-> ast::Field {
ast::Field{ident: respan(span, name), expr: e, span: span,}
}
fn expr_struct(&self, span: Span, path: ast::Path,
fields: Vec<ast::Field>) -> P<ast::Expr> {
self.expr(span, ast::ExprStruct(path, fields, None))
}
fn expr_struct_ident(&self, span: Span, id: ast::Ident,
fields: Vec<ast::Field>) -> P<ast::Expr> {
self.expr_struct(span, self.path_ident(span, id), fields)
}
fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr> {
self.expr(sp, ast::ExprLit(P(respan(sp, lit))))
}
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
self.expr_lit(span,
ast::LitInt(i as u64,
ast::UnsignedIntLit(ast::TyUs)))
}
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> {
self.expr_lit(sp,
ast::LitInt(i as u64,
ast::SignedIntLit(ast::TyIs,
ast::Sign::new(i))))
}
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
self.expr_lit(sp,
ast::LitInt(u as u64,
ast::UnsignedIntLit(ast::TyU32)))
}
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
self.expr_lit(sp,
ast::LitInt(u as u64,
ast::UnsignedIntLit(ast::TyU8)))
}
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitBool(value))
}
fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>)
-> P<ast::Expr> {
self.expr(sp, ast::ExprVec(exprs))
}
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
self.expr_call_global(sp,
self.std_path(&["vec", "Vec", "new"]),
Vec::new())
}
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>)
-> P<ast::Expr> {
self.expr_addr_of(sp, self.expr_vec(sp, exprs))
}
fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitStr(s, ast::CookedStr))
}
fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>)
-> P<ast::Expr> {
self.expr(sp, ast::ExprCast(expr, ty))
}
fn expr_some(&self, sp: Span, expr: P<ast::Expr>)
-> P<ast::Expr> {
let some = self.std_path(&["option", "Option", "Some"]);
self.expr_call_global(sp, some,
<[_]>::into_vec(::std::boxed::Box::new([expr])))
}
fn expr_none(&self, sp: Span) -> P<ast::Expr> {
let none = self.std_path(&["option", "Option", "None"]);
let none = self.path_global(sp, none);
self.expr_path(none)
}
fn expr_break(&self, sp: Span) -> P<ast::Expr> {
self.expr(sp, ast::ExprBreak(None))
}
fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>)
-> P<ast::Expr> {
self.expr(sp, ast::ExprTup(exprs))
}
fn expr_fail(&self, span: Span, msg: InternedString)
-> P<ast::Expr> {
let loc = self.codemap().lookup_char_pos(span.lo);
let expr_file =
self.expr_str(span,
token::intern_and_get_ident(&loc.file.name));
let expr_line = self.expr_u32(span, loc.line as u32);
let expr_file_line_tuple =
self.expr_tuple(span,
<[_]>::into_vec(::std::boxed::Box::new([expr_file,
expr_line])));
let expr_file_line_ptr =
self.expr_addr_of(span, expr_file_line_tuple);
self.expr_call_global(span,
self.std_path(&["rt", "begin_unwind"]),
<[_]>::into_vec(::std::boxed::Box::new([self.expr_str(span,
msg),
expr_file_line_ptr])))
}
fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
self.expr_fail(span,
InternedString::new("internal error: entered unreachable code"))
}
fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let ok = self.std_path(&["result", "Result", "Ok"]);
self.expr_call_global(sp, ok,
<[_]>::into_vec(::std::boxed::Box::new([expr])))
}
fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let err = self.std_path(&["result", "Result", "Err"]);
self.expr_call_global(sp, err,
<[_]>::into_vec(::std::boxed::Box::new([expr])))
}
fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
let ok = self.std_path(&["result", "Result", "Ok"]);
let ok_path = self.path_global(sp, ok);
let err = self.std_path(&["result", "Result", "Err"]);
let err_path = self.path_global(sp, err);
let binding_variable = self.ident_of("__try_var");
let binding_pat = self.pat_ident(sp, binding_variable);
let binding_expr = self.expr_ident(sp, binding_variable);
let ok_pat =
self.pat_enum(sp, ok_path,
<[_]>::into_vec(::std::boxed::Box::new([binding_pat.clone()])));
let err_pat =
self.pat_enum(sp, err_path.clone(),
<[_]>::into_vec(::std::boxed::Box::new([binding_pat])));
let err_inner_expr =
self.expr_call(sp, self.expr_path(err_path),
<[_]>::into_vec(::std::boxed::Box::new([binding_expr.clone()])));
let err_expr =
self.expr(sp, ast::ExprRet(Some(err_inner_expr)));
let ok_arm =
self.arm(sp,
<[_]>::into_vec(::std::boxed::Box::new([ok_pat])),
binding_expr);
let err_arm =
self.arm(sp,
<[_]>::into_vec(::std::boxed::Box::new([err_pat])),
err_expr);
self.expr_match(sp, head,
<[_]>::into_vec(::std::boxed::Box::new([ok_arm,
err_arm])))
}
fn pat(&self, span: Span, pat: ast::Pat_) -> P<ast::Pat> {
P(ast::Pat{id: ast::DUMMY_NODE_ID, node: pat, span: span,})
}
fn pat_wild(&self, span: Span) -> P<ast::Pat> {
self.pat(span, ast::PatWild)
}
fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
self.pat(span, ast::PatLit(expr))
}
fn pat_ident(&self, span: Span, ident: ast::Ident)
-> P<ast::Pat> {
self.pat_ident_binding_mode(span, ident,
ast::BindingMode::ByValue(ast::MutImmutable))
}
fn pat_ident_binding_mode(&self, span: Span, ident: ast::Ident,
bm: ast::BindingMode) -> P<ast::Pat> {
let pat =
ast::PatIdent(bm, Spanned{span: span, node: ident,},
None);
self.pat(span, pat)
}
fn pat_enum(&self, span: Span, path: ast::Path,
subpats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
let pat = ast::PatEnum(path, Some(subpats));
self.pat(span, pat)
}
fn pat_struct(&self, span: Span, path: ast::Path,
field_pats: Vec<Spanned<ast::FieldPat>>)
-> P<ast::Pat> {
let pat = ast::PatStruct(path, field_pats, false);
self.pat(span, pat)
}
fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>)
-> P<ast::Pat> {
self.pat(span, ast::PatTup(pats))
}
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = self.std_path(&["option", "Option", "Some"]);
let path = self.path_global(span, some);
self.pat_enum(span, path,
<[_]>::into_vec(::std::boxed::Box::new([pat])))
}
fn pat_none(&self, span: Span) -> P<ast::Pat> {
let some = self.std_path(&["option", "Option", "None"]);
let path = self.path_global(span, some);
self.pat_enum(span, path,
<[_]>::into_vec(::std::boxed::Box::new([])))
}
fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = self.std_path(&["result", "Result", "Ok"]);
let path = self.path_global(span, some);
self.pat_enum(span, path,
<[_]>::into_vec(::std::boxed::Box::new([pat])))
}
fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = self.std_path(&["result", "Result", "Err"]);
let path = self.path_global(span, some);
self.pat_enum(span, path,
<[_]>::into_vec(::std::boxed::Box::new([pat])))
}
fn arm(&self, _span: Span, pats: Vec<P<ast::Pat>>,
expr: P<ast::Expr>) -> ast::Arm {
ast::Arm{attrs: <[_]>::into_vec(::std::boxed::Box::new([])),
pats: pats,
guard: None,
body: expr,}
}
fn arm_unreachable(&self, span: Span) -> ast::Arm {
self.arm(span,
<[_]>::into_vec(::std::boxed::Box::new([self.pat_wild(span)])),
self.expr_unreachable(span))
}
fn expr_match(&self, span: Span, arg: P<ast::Expr>,
arms: Vec<ast::Arm>) -> P<Expr> {
self.expr(span, ast::ExprMatch(arg, arms))
}
fn expr_if(&self, span: Span, cond: P<ast::Expr>,
then: P<ast::Expr>, els: Option<P<ast::Expr>>)
-> P<ast::Expr> {
let els = els.map(|x| self.expr_block(self.block_expr(x)));
self.expr(span, ast::ExprIf(cond, self.block_expr(then), els))
}
fn expr_loop(&self, span: Span, block: P<ast::Block>)
-> P<ast::Expr> {
self.expr(span, ast::ExprLoop(block, None))
}
fn lambda_fn_decl(&self, span: Span, fn_decl: P<ast::FnDecl>,
blk: P<ast::Block>) -> P<ast::Expr> {
self.expr(span,
ast::ExprClosure(ast::CaptureByRef, fn_decl, blk))
}
fn lambda(&self, span: Span, ids: Vec<ast::Ident>,
blk: P<ast::Block>) -> P<ast::Expr> {
let fn_decl =
self.fn_decl(ids.iter().map(|id|
self.arg(span, *id,
self.ty_infer(span))).collect(),
self.ty_infer(span));
self.expr(span,
ast::ExprClosure(ast::CaptureByRef, fn_decl, blk))
}
fn lambda0(&self, span: Span, blk: P<ast::Block>)
-> P<ast::Expr> {
self.lambda(span, Vec::new(), blk)
}
fn lambda1(&self, span: Span, blk: P<ast::Block>,
ident: ast::Ident) -> P<ast::Expr> {
self.lambda(span,
<[_]>::into_vec(::std::boxed::Box::new([ident])),
blk)
}
fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident>,
expr: P<ast::Expr>) -> P<ast::Expr> {
self.lambda(span, ids, self.block_expr(expr))
}
fn lambda_expr_0(&self, span: Span, expr: P<ast::Expr>)
-> P<ast::Expr> {
self.lambda0(span, self.block_expr(expr))
}
fn lambda_expr_1(&self, span: Span, expr: P<ast::Expr>,
ident: ast::Ident) -> P<ast::Expr> {
self.lambda1(span, self.block_expr(expr), ident)
}
fn lambda_stmts(&self, span: Span, ids: Vec<ast::Ident>,
stmts: Vec<P<ast::Stmt>>) -> P<ast::Expr> {
self.lambda(span, ids, self.block(span, stmts, None))
}
fn lambda_stmts_0(&self, span: Span, stmts: Vec<P<ast::Stmt>>)
-> P<ast::Expr> {
self.lambda0(span, self.block(span, stmts, None))
}
fn lambda_stmts_1(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
ident: ast::Ident) -> P<ast::Expr> {
self.lambda1(span, self.block(span, stmts, None), ident)
}
fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>)
-> ast::Arg {
let arg_pat = self.pat_ident(span, ident);
ast::Arg{ty: ty, pat: arg_pat, id: ast::DUMMY_NODE_ID,}
}
fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>)
-> P<ast::FnDecl> {
P(ast::FnDecl{inputs: inputs,
output: ast::Return(output),
variadic: false,})
}
fn item(&self, span: Span, name: Ident,
attrs: Vec<ast::Attribute>, node: ast::Item_)
-> P<ast::Item> {
P(ast::Item{ident: name,
attrs: attrs,
id: ast::DUMMY_NODE_ID,
node: node,
vis: ast::Inherited,
span: span,})
}
fn item_fn_poly(&self, span: Span, name: Ident,
inputs: Vec<ast::Arg>, output: P<ast::Ty>,
generics: Generics, body: P<ast::Block>)
-> P<ast::Item> {
self.item(span, name, Vec::new(),
ast::ItemFn(self.fn_decl(inputs, output),
ast::Unsafety::Normal,
ast::Constness::NotConst, abi::Rust,
generics, body))
}
fn item_fn(&self, span: Span, name: Ident, inputs: Vec<ast::Arg>,
output: P<ast::Ty>, body: P<ast::Block>)
-> P<ast::Item> {
self.item_fn_poly(span, name, inputs, output,
Generics::default(), body)
}
fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>>)
-> ast::Variant {
let fields: Vec<_> =
tys.into_iter().map(|ty| {
Spanned{span: ty.span,
node:
ast::StructField_{ty: ty,
kind:
ast::UnnamedField(ast::Inherited),
attrs:
Vec::new(),
id:
ast::DUMMY_NODE_ID,},}
}).collect();
let vdata =
if fields.is_empty() {
ast::VariantData::Unit(ast::DUMMY_NODE_ID)
} else {
ast::VariantData::Tuple(fields, ast::DUMMY_NODE_ID)
};
respan(span,
ast::Variant_{name: name,
attrs: Vec::new(),
data: vdata,
disr_expr: None,})
}
fn item_enum_poly(&self, span: Span, name: Ident,
enum_definition: ast::EnumDef,
generics: Generics) -> P<ast::Item> {
self.item(span, name, Vec::new(),
ast::ItemEnum(enum_definition, generics))
}
fn item_enum(&self, span: Span, name: Ident,
enum_definition: ast::EnumDef) -> P<ast::Item> {
self.item_enum_poly(span, name, enum_definition,
Generics::default())
}
fn item_struct(&self, span: Span, name: Ident,
struct_def: ast::VariantData) -> P<ast::Item> {
self.item_struct_poly(span, name, struct_def,
Generics::default())
}
fn item_struct_poly(&self, span: Span, name: Ident,
struct_def: ast::VariantData,
generics: Generics) -> P<ast::Item> {
self.item(span, name, Vec::new(),
ast::ItemStruct(struct_def, generics))
}
fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
attrs: Vec<ast::Attribute>, items: Vec<P<ast::Item>>)
-> P<ast::Item> {
self.item(span, name, attrs,
ast::ItemMod(ast::Mod{inner: inner_span,
items: items,}))
}
fn item_static(&self, span: Span, name: Ident, ty: P<ast::Ty>,
mutbl: ast::Mutability, expr: P<ast::Expr>)
-> P<ast::Item> {
self.item(span, name, Vec::new(),
ast::ItemStatic(ty, mutbl, expr))
}
fn item_const(&self, span: Span, name: Ident, ty: P<ast::Ty>,
expr: P<ast::Expr>) -> P<ast::Item> {
self.item(span, name, Vec::new(), ast::ItemConst(ty, expr))
}
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
generics: Generics) -> P<ast::Item> {
self.item(span, name, Vec::new(), ast::ItemTy(ty, generics))
}
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>)
-> P<ast::Item> {
self.item_ty_poly(span, name, ty, Generics::default())
}
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>)
-> ast::Attribute {
respan(sp,
ast::Attribute_{id: attr::mk_attr_id(),
style: ast::AttrStyle::Outer,
value: mi,
is_sugared_doc: false,})
}
fn meta_word(&self, sp: Span, w: InternedString)
-> P<ast::MetaItem> {
P(respan(sp, ast::MetaWord(w)))
}
fn meta_list(&self, sp: Span, name: InternedString,
mis: Vec<P<ast::MetaItem>>) -> P<ast::MetaItem> {
P(respan(sp, ast::MetaList(name, mis)))
}
fn meta_name_value(&self, sp: Span, name: InternedString,
value: ast::Lit_) -> P<ast::MetaItem> {
P(respan(sp, ast::MetaNameValue(name, respan(sp, value))))
}
fn item_use(&self, sp: Span, vis: ast::Visibility,
vp: P<ast::ViewPath>) -> P<ast::Item> {
P(ast::Item{id: ast::DUMMY_NODE_ID,
ident: special_idents::invalid,
attrs:
<[_]>::into_vec(::std::boxed::Box::new([])),
node: ast::ItemUse(vp),
vis: vis,
span: sp,})
}
fn item_use_simple(&self, sp: Span, vis: ast::Visibility,
path: ast::Path) -> P<ast::Item> {
let last = path.segments.last().unwrap().identifier;
self.item_use_simple_(sp, vis, last, path)
}
fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path)
-> P<ast::Item> {
self.item_use(sp, vis,
P(respan(sp, ast::ViewPathSimple(ident, path))))
}
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>, imports: &[ast::Ident])
-> P<ast::Item> {
let imports =
imports.iter().map(|id| {
respan(sp,
ast::PathListIdent{name: *id,
rename: None,
id:
ast::DUMMY_NODE_ID,})
}).collect();
self.item_use(sp, vis,
P(respan(sp,
ast::ViewPathList(self.path(sp, path),
imports))))
}
fn item_use_glob(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>) -> P<ast::Item> {
self.item_use(sp, vis,
P(respan(sp,
ast::ViewPathGlob(self.path(sp,
path)))))
}
}
}
pub mod deriving {
//! The compiler code necessary to implement the `#[derive]` extensions.
//!
//! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is
//! the standard library, and "std" is the core library.
#[prelude_import]
use std::prelude::v1::*;
use ast::{MetaItem, MetaWord};
use attr::AttrMetaMethods;
use ext::base::{ExtCtxt, SyntaxEnv, MultiModifier, Annotatable};
use ext::build::AstBuilder;
use feature_gate;
use codemap::Span;
use parse::token::{intern, intern_and_get_ident};
fn expand_derive(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem,
annotatable: Annotatable) -> Annotatable {
annotatable.map_item_or(|item| {
item.map(|mut item| {
if mitem.value_str().is_some() {
cx.span_err(mitem.span,
"unexpected value in `derive`");
}
let traits =
mitem.meta_item_list().unwrap_or(&[]);
if traits.is_empty() {
cx.span_warn(mitem.span,
"empty trait list in `derive`");
}
for titem in traits.iter().rev()
{
let tname =
match titem.node {
MetaWord(ref tname)
=> tname,
_ => {
cx.span_err(titem.span,
"malformed `derive` entry");
continue ;
}
};
if !(is_builtin_trait(tname)
||
cx.ecfg.enable_custom_derive())
{
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,
"custom_derive",
titem.span,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CUSTOM_DERIVE);
continue ;
}
item.attrs.push(cx.attribute(titem.span,
cx.meta_word(titem.span,
intern_and_get_ident(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["derive_"];
__STATIC_FMTSTR
},
&match (&tname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))));
} item }) }, |a| {
cx.span_err(span,
"`derive` can only be applied to items");
a })
}
pub fn register_all(env: &mut SyntaxEnv) {
env.insert(intern("derive"),
MultiModifier(Box::new(expand_derive)));
}
fn is_builtin_trait(name: &str) -> bool {
match name {
"Clone" => true,
"Hash" => true,
"RustcEncodable" => true,
"RustcDecodable" => true,
"PartialEq" => true,
"Eq" => true,
"PartialOrd" => true,
"Ord" => true,
"Debug" => true,
"Default" => true,
"FromPrimitive" => true,
"Send" => true,
"Sync" => true,
"Copy" => true,
"Encodable" => true,
"Decodable" => true,
_ => false,
}
}
}
pub mod env {
#[prelude_import]
use std::prelude::v1::*;
use ast;
use codemap::Span;
use ext::base::*;
use ext::base;
use ext::build::AstBuilder;
use parse::token;
use std::env;
pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'cx> {
let var =
match get_single_str_from_tts(cx, sp, tts, "option_env!") {
None => return DummyResult::expr(sp),
Some(v) => v,
};
let e =
match env::var(&var[..]) {
Err(..) => {
cx.expr_path(cx.path_all(sp, true,
cx.std_path(&["option",
"Option",
"None"]),
Vec::new(),
<[_]>::into_vec(::std::boxed::Box::new([cx.ty_rptr(sp,
cx.ty_ident(sp,
cx.ident_of("str")),
Some(cx.lifetime(sp,
cx.ident_of("\'static").name)),
ast::MutImmutable)])),
Vec::new()))
}
Ok(s) => {
cx.expr_call_global(sp,
cx.std_path(&["option", "Option",
"Some"]),
<[_]>::into_vec(::std::boxed::Box::new([cx.expr_str(sp,
token::intern_and_get_ident(&s[..]))])))
}
};
MacEager::expr(e)
}
pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'cx> {
let mut exprs =
match get_exprs_from_tts(cx, sp, tts) {
Some(ref exprs) if exprs.is_empty() => {
cx.span_err(sp, "env! takes 1 or 2 arguments");
return DummyResult::expr(sp);
}
None => return DummyResult::expr(sp),
Some(exprs) => exprs.into_iter(),
};
let var =
match expr_to_string(cx, exprs.next().unwrap(),
"expected string literal") {
None => return DummyResult::expr(sp),
Some((v, _style)) => v,
};
let msg =
match exprs.next() {
None => {
token::intern_and_get_ident(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["environment variable `",
"` not defined"];
__STATIC_FMTSTR
},
&match (&var,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
}
Some(second) => {
match expr_to_string(cx, second,
"expected string literal") {
None => return DummyResult::expr(sp),
Some((s, _style)) => s,
}
}
};
match exprs.next() {
None => { }
Some(_) => {
cx.span_err(sp, "env! takes 1 or 2 arguments");
return DummyResult::expr(sp);
}
}
let e =
match env::var(&var[..]) {
Err(_) => { cx.span_err(sp, &msg); cx.expr_usize(sp, 0) }
Ok(s) => cx.expr_str(sp, token::intern_and_get_ident(&s)),
};
MacEager::expr(e)
}
}
pub mod expand {
#[prelude_import]
use std::prelude::v1::*;
use ast::{Block, Crate, DeclLocal, PatMac};
use ast::{Local, Ident, Mac_, Name};
use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtDecl,
StmtMac};
use ast::{StmtExpr, StmtSemi};
use ast::TokenTree;
use ast;
use ext::mtwt;
use ext::build::AstBuilder;
use attr;
use attr::{AttrMetaMethods, WithAttrs};
use codemap;
use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang,
MacroAttribute};
use ext::base::*;
use feature_gate::{self, Features};
use fold;
use fold::*;
use util::move_map::MoveMap;
use parse;
use parse::token::{fresh_mark, fresh_name, intern};
use ptr::P;
use util::small_vector::SmallVector;
use visit;
use visit::Visitor;
use std_inject;
use std::collections::HashSet;
pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander)
-> P<ast::Expr> {
let expr_span = e.span;
return e.clone().and_then(|ast::Expr { id, node, span, attrs }|
match node {
ast::ExprMac(mac) => {
drop(attrs);
let expanded_expr =
match expand_mac_invoc(mac,
span,
|r|
r.make_expr(),
mark_expr,
fld)
{
Some(expr) => expr,
None => {
return e;
}
};
let fully_expanded =
fld.fold_expr(expanded_expr);
let span =
fld.new_span(span);
fld.cx.bt_pop();
fully_expanded.map(|e|
ast::Expr{id:
ast::DUMMY_NODE_ID,
node:
e.node,
span:
span,
attrs:
e.attrs,})
}
ast::ExprInPlace(placer,
value_expr) =>
{
feature_gate::check_for_placement_in(fld.cx.ecfg.features,
&fld.cx.parse_sess.span_diagnostic,
expr_span);
let placer =
fld.fold_expr(placer);
let value_expr =
fld.fold_expr(value_expr);
fld.cx.expr(span,
ast::ExprInPlace(placer,
value_expr)).with_attrs(fold_thin_attrs(attrs,
fld))
}
ast::ExprWhile(cond, body,
opt_ident) => {
let cond =
fld.fold_expr(cond);
let (body, opt_ident) =
expand_loop_block(body,
opt_ident,
fld);
fld.cx.expr(span,
ast::ExprWhile(cond,
body,
opt_ident)).with_attrs(fold_thin_attrs(attrs,
fld))
}
ast::ExprWhileLet(pat, expr,
body,
opt_ident) =>
{
let pat = fld.fold_pat(pat);
let expr =
fld.fold_expr(expr);
let ((body, opt_ident),
mut rewritten_pats) =
rename_in_scope(<[_]>::into_vec(::std::boxed::Box::new([pat])),
fld,
(body,
opt_ident),
|rename_fld,
fld,
(body,
opt_ident)|
{
expand_loop_block(rename_fld.fold_block(body),
opt_ident,
fld)
});
if !(rewritten_pats.len() ==
1) {
{
::std::rt::begin_unwind("assertion failed: rewritten_pats.len() == 1",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
106u32);
&_FILE_LINE
})
}
};
fld.cx.expr(span,
ast::ExprWhileLet(rewritten_pats.remove(0),
expr,
body,
opt_ident)).with_attrs(fold_thin_attrs(attrs,
fld))
}
ast::ExprLoop(loop_block,
opt_ident) => {
let (loop_block,
opt_ident) =
expand_loop_block(loop_block,
opt_ident,
fld);
fld.cx.expr(span,
ast::ExprLoop(loop_block,
opt_ident)).with_attrs(fold_thin_attrs(attrs,
fld))
}
ast::ExprForLoop(pat, head,
body,
opt_ident) => {
let pat = fld.fold_pat(pat);
let ((body, opt_ident),
mut rewritten_pats) =
rename_in_scope(<[_]>::into_vec(::std::boxed::Box::new([pat])),
fld,
(body,
opt_ident),
|rename_fld,
fld,
(body,
opt_ident)|
{
expand_loop_block(rename_fld.fold_block(body),
opt_ident,
fld)
});
if !(rewritten_pats.len() ==
1) {
{
::std::rt::begin_unwind("assertion failed: rewritten_pats.len() == 1",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
129u32);
&_FILE_LINE
})
}
};
let head =
fld.fold_expr(head);
fld.cx.expr(span,
ast::ExprForLoop(rewritten_pats.remove(0),
head,
body,
opt_ident)).with_attrs(fold_thin_attrs(attrs,
fld))
}
ast::ExprIfLet(pat, sub_expr,
body, else_opt)
=> {
let pat = fld.fold_pat(pat);
let (body,
mut rewritten_pats) =
rename_in_scope(<[_]>::into_vec(::std::boxed::Box::new([pat])),
fld,
body,
|rename_fld,
fld,
body| {
fld.fold_block(rename_fld.fold_block(body))
});
if !(rewritten_pats.len() ==
1) {
{
::std::rt::begin_unwind("assertion failed: rewritten_pats.len() == 1",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
147u32);
&_FILE_LINE
})
}
};
let else_opt =
else_opt.map(|else_opt|
fld.fold_expr(else_opt));
let sub_expr =
fld.fold_expr(sub_expr);
fld.cx.expr(span,
ast::ExprIfLet(rewritten_pats.remove(0),
sub_expr,
body,
else_opt)).with_attrs(fold_thin_attrs(attrs,
fld))
}
ast::ExprClosure(capture_clause,
fn_decl, block)
=> {
let (rewritten_fn_decl,
rewritten_block) =
expand_and_rename_fn_decl_and_block(fn_decl,
block,
fld);
let new_node =
ast::ExprClosure(capture_clause,
rewritten_fn_decl,
rewritten_block);
P(ast::Expr{id: id,
node: new_node,
span:
fld.new_span(span),
attrs:
fold_thin_attrs(attrs,
fld),})
}
_ => {
P(noop_fold_expr(ast::Expr{id:
id,
node:
node,
span:
span,
attrs:
attrs,},
fld))
}
});
}
/// Expand a (not-ident-style) macro invocation. Returns the result
/// of expansion and the mark which must be applied to the result.
/// Our current interface doesn't allow us to apply the mark to the
/// result until after calling make_expr, make_items, etc.
fn expand_mac_invoc<T, F,
G>(mac: ast::Mac, span: codemap::Span,
parse_thunk: F, mark_thunk: G,
fld: &mut MacroExpander) -> Option<T> where
F: for<'a>FnOnce(Box<MacResult+ 'a>) -> Option<T>, G: FnOnce(T, Mrk)
-> T {
let Mac_ { path: pth, tts, .. } = mac.node;
if pth.segments.len() > 1 {
fld.cx.span_err(pth.span,
"expected macro name without module separators");
return None;
}
let extname = pth.segments[0].identifier.name;
match fld.cx.syntax_env.find(extname) {
None => { None }
Some(rc) =>
match *rc {
NormalTT(ref expandfun, exp_span, allow_internal_unstable)
=> {
fld.cx.bt_push(ExpnInfo{call_site: span,
callee:
NameAndSpan{format:
MacroBang(extname),
span:
exp_span,
allow_internal_unstable:
allow_internal_unstable,},});
let fm = fresh_mark();
let marked_before = mark_tts(&tts[..], fm);
let mac_span = fld.cx.original_span();
let opt_parsed =
{
let expanded =
expandfun.expand(fld.cx, mac_span,
&marked_before[..]);
parse_thunk(expanded)
};
let parsed =
match opt_parsed {
Some(e) => e,
None => {
fld.cx.span_err(pth.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["non-expression macro in expression position: "];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return None;
}
};
Some(mark_thunk(parsed, fm))
}
_ => {
fld.cx.span_err(pth.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["\'",
"\' is not a tt-style macro"];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
None
}
},
}
}
/// Rename loop label and expand its loop body
///
/// The renaming procedure for loop is different in the sense that the loop
/// body is in a block enclosed by loop head so the renaming of loop label
/// must be propagated to the enclosed context.
fn expand_loop_block(loop_block: P<Block>, opt_ident: Option<Ident>,
fld: &mut MacroExpander)
-> (P<Block>, Option<Ident>) {
match opt_ident {
Some(label) => {
let new_label = fresh_name(label);
let rename = (label, new_label);
let mut rename_list =
<[_]>::into_vec(::std::boxed::Box::new([rename]));
let mut rename_fld =
IdentRenamer{renames: &mut rename_list,};
let renamed_ident = rename_fld.fold_ident(label);
fld.cx.syntax_env.push_frame();
fld.cx.syntax_env.info().pending_renames.push(rename);
let expanded_block = expand_block_elts(loop_block, fld);
fld.cx.syntax_env.pop_frame();
(expanded_block, Some(renamed_ident))
}
None => (fld.fold_block(loop_block), opt_ident),
}
}
pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
-> SmallVector<P<ast::Item>> {
let it = expand_item_multi_modifier(Annotatable::Item(it), fld);
expand_annotatable(it,
fld).into_iter().map(|i|
i.expect_item()).collect()
}
/// Expand item_underscore
fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander)
-> ast::Item_ {
match item {
ast::ItemFn(decl, unsafety, constness, abi, generics, body) =>
{
let (rewritten_fn_decl, rewritten_body) =
expand_and_rename_fn_decl_and_block(decl, body, fld);
let expanded_generics =
fold::noop_fold_generics(generics, fld);
ast::ItemFn(rewritten_fn_decl, unsafety, constness, abi,
expanded_generics, rewritten_body)
}
_ => noop_fold_item_underscore(item, fld),
}
}
fn contains_macro_use(fld: &mut MacroExpander,
attrs: &[ast::Attribute]) -> bool {
for attr in attrs {
let mut is_use = attr.check_name("macro_use");
if attr.check_name("macro_escape") {
let mut err =
fld.cx.struct_span_warn(attr.span,
"macro_escape is a deprecated synonym for macro_use");
is_use = true;
if let ast::AttrStyle::Inner = attr.node.style {
err.fileline_help(attr.span,
"consider an outer attribute, #[macro_use] mod ...").emit();
} else { err.emit(); }
};
if is_use {
match attr.node.value.node {
ast::MetaWord(..) => (),
_ =>
fld.cx.span_err(attr.span,
"arguments to macro_use are not allowed here"),
}
return true;
}
}
false
}
pub fn expand_item_mac(it: P<ast::Item>, fld: &mut MacroExpander)
-> SmallVector<P<ast::Item>> {
let (extname, path_span, tts, span, attrs, ident) =
it.clone().and_then(|it|
match it.node {
ItemMac(codemap::Spanned {
node: Mac_ {
path, tts,
..
}, .. }) =>
(path.segments[0].identifier.name,
path.span, tts, it.span,
it.attrs, it.ident),
_ =>
fld.cx.span_bug(it.span,
"invalid item macro invocation"),
});
let fm = fresh_mark();
let items =
{
let expanded =
match fld.cx.syntax_env.find(extname) {
None => { return SmallVector::one(it); }
Some(rc) =>
match *rc {
NormalTT(ref expander, tt_span,
allow_internal_unstable) => {
if ident.name !=
parse::token::special_idents::invalid.name
{
fld.cx.span_err(path_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["macro ",
"! expects no ident argument, given \'",
"\'"];
__STATIC_FMTSTR
},
&match (&extname,
&ident)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
return SmallVector::zero();
}
fld.cx.bt_push(ExpnInfo{call_site: span,
callee:
NameAndSpan{format:
MacroBang(extname),
span:
tt_span,
allow_internal_unstable:
allow_internal_unstable,},});
let marked_before =
mark_tts(&tts[..], fm);
expander.expand(fld.cx, span,
&marked_before[..])
}
IdentTT(ref expander, tt_span,
allow_internal_unstable) => {
if ident.name ==
parse::token::special_idents::invalid.name
{
fld.cx.span_err(path_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["macro ",
"! expects an ident argument"];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return SmallVector::zero();
}
fld.cx.bt_push(ExpnInfo{call_site: span,
callee:
NameAndSpan{format:
MacroBang(extname),
span:
tt_span,
allow_internal_unstable:
allow_internal_unstable,},});
let marked_tts = mark_tts(&tts[..], fm);
expander.expand(fld.cx, span, ident,
marked_tts)
}
MacroRulesTT => {
if ident.name ==
parse::token::special_idents::invalid.name
{
fld.cx.span_err(path_span,
"macro_rules! expects an ident argument");
return SmallVector::zero();
}
fld.cx.bt_push(ExpnInfo{call_site: span,
callee:
NameAndSpan{format:
MacroBang(extname),
span:
None,
allow_internal_unstable:
false,},});
let allow_internal_unstable =
attr::contains_name(&attrs,
"allow_internal_unstable");
if allow_internal_unstable &&
!fld.cx.ecfg.enable_allow_internal_unstable()
{
feature_gate::emit_feature_err(&fld.cx.parse_sess.span_diagnostic,
"allow_internal_unstable",
span,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_ALLOW_INTERNAL_UNSTABLE)
}
let export =
attr::contains_name(&attrs,
"macro_export");
let def =
ast::MacroDef{ident: ident,
attrs: attrs,
id: ast::DUMMY_NODE_ID,
span: span,
imported_from: None,
export: export,
use_locally: true,
allow_internal_unstable:
allow_internal_unstable,
body: tts,};
fld.cx.insert_macro(def);
fld.cx.bt_pop();
return SmallVector::zero();
}
_ => {
fld.cx.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"! is not legal in item position"];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return SmallVector::zero();
}
},
};
expanded.make_items()
};
let items =
match items {
Some(items) => {
items.into_iter().map(|i|
mark_item(i,
fm)).flat_map(|i|
fld.fold_item(i).into_iter()).collect()
}
None => {
fld.cx.span_err(path_span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["non-item macro in item position: "];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return SmallVector::zero();
}
};
fld.cx.bt_pop();
items
}
/// Expand a stmt
fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander)
-> SmallVector<P<Stmt>> {
let stmt = stmt.and_then(|stmt| stmt);
let (mac, style, attrs) =
match stmt.clone().node {
StmtMac(mac, style, attrs) => (mac, style, attrs),
_ => return expand_non_macro_stmt(stmt, fld),
};
drop(attrs);
let maybe_new_items =
expand_mac_invoc(mac.and_then(|m| m), stmt.span,
|r| r.make_stmts(),
|stmts, mark|
stmts.move_map(|m| mark_stmt(m, mark)),
fld);
let mut fully_expanded =
match maybe_new_items {
Some(stmts) => {
let new_items =
stmts.into_iter().flat_map(|s| {
fld.fold_stmt(s).into_iter()
}).collect();
fld.cx.bt_pop();
new_items
}
None => { SmallVector::one(P(stmt)) }
};
if style == MacStmtWithSemicolon {
if let Some(stmt) = fully_expanded.pop() {
let new_stmt =
stmt.map(|Spanned { node, span }| {
Spanned{node:
match node {
StmtExpr(e, stmt_id) =>
StmtSemi(e, stmt_id),
_ => node,
},
span: span,} });
fully_expanded.push(new_stmt);
}
}
fully_expanded
}
fn expand_non_macro_stmt(Spanned { node, span: stmt_span }: Stmt,
fld: &mut MacroExpander)
-> SmallVector<P<Stmt>> {
match node {
StmtDecl(decl, node_id) =>
decl.and_then(|Spanned { node: decl, span }|
match decl {
DeclLocal(local) => {
let rewritten_local =
local.map(|Local {
id,
pat,
ty,
init,
span,
attrs }| {
let expanded_ty =
ty.map(|t|
fld.fold_ty(t));
let expanded_pat =
fld.fold_pat(pat);
let idents =
pattern_bindings(&expanded_pat);
let mut new_pending_renames =
idents.iter().map(|ident|
(*ident,
fresh_name(*ident))).collect();
let rewritten_pat =
{
let mut rename_fld =
IdentRenamer{renames:
&mut new_pending_renames,};
rename_fld.fold_pat(expanded_pat)
};
fld.cx.syntax_env.info().pending_renames.extend(new_pending_renames);
Local{id: id,
ty: expanded_ty,
pat:
rewritten_pat,
init:
init.map(|e|
fld.fold_expr(e)),
span: span,
attrs:
fold::fold_thin_attrs(attrs,
fld),}
});
SmallVector::one(P(Spanned{node:
StmtDecl(P(Spanned{node:
DeclLocal(rewritten_local),
span:
span,}),
node_id),
span:
stmt_span,}))
}
_ => {
noop_fold_stmt(Spanned{node:
StmtDecl(P(Spanned{node:
decl,
span:
span,}),
node_id),
span:
stmt_span,},
fld)
}
}),
_ => {
noop_fold_stmt(Spanned{node: node, span: stmt_span,}, fld)
}
}
}
fn expand_arm(arm: ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
let expanded_pats = arm.pats.move_map(|pat| fld.fold_pat(pat));
if expanded_pats.is_empty() {
{
::std::rt::begin_unwind("encountered match arm with 0 patterns",
{
static _FILE_LINE:
(&'static str, u32) =
("src/ext/expand.rs",
644u32);
&_FILE_LINE
})
};
}
let ((rewritten_guard, rewritten_body), rewritten_pats) =
rename_in_scope(expanded_pats, fld, (arm.guard, arm.body),
|rename_fld, fld, (ag, ab)| {
let rewritten_guard =
ag.map(|g|
fld.fold_expr(rename_fld.fold_expr(g)));
let rewritten_body =
fld.fold_expr(rename_fld.fold_expr(ab));
(rewritten_guard, rewritten_body) });
ast::Arm{attrs: fold::fold_attrs(arm.attrs, fld),
pats: rewritten_pats,
guard: rewritten_guard,
body: rewritten_body,}
}
fn rename_in_scope<X,
F>(pats: Vec<P<ast::Pat>>, fld: &mut MacroExpander,
x: X, f: F) -> (X, Vec<P<ast::Pat>>) where
F: Fn(&mut IdentRenamer, &mut MacroExpander, X) -> X {
let idents = pattern_bindings(&pats[0]);
let new_renames =
idents.into_iter().map(|id| (id, fresh_name(id))).collect();
let mut rename_pats_fld = PatIdentRenamer{renames: &new_renames,};
let rewritten_pats =
pats.move_map(|pat| rename_pats_fld.fold_pat(pat));
let mut rename_fld = IdentRenamer{renames: &new_renames,};
(f(&mut rename_fld, fld, x), rewritten_pats)
}
/// A visitor that extracts the PatIdent (binding) paths
/// from a given thingy and puts them in a mutable
/// array
struct PatIdentFinder {
ident_accumulator: Vec<ast::Ident>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for PatIdentFinder {
#[inline]
fn clone(&self) -> PatIdentFinder {
match *self {
PatIdentFinder { ident_accumulator: ref __self_0_0 } =>
PatIdentFinder{ident_accumulator:
::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
impl <'v> Visitor<'v> for PatIdentFinder {
fn visit_pat(&mut self, pattern: &ast::Pat) {
match *pattern {
ast::Pat {
id: _,
node: ast::PatIdent(_, ref path1, ref inner),
span: _ } => {
self.ident_accumulator.push(path1.node);
if let Some(ref subpat) = *inner {
self.visit_pat(subpat)
}
}
_ => visit::walk_pat(self, pattern),
}
}
}
/// find the PatIdent paths in a pattern
fn pattern_bindings(pat: &ast::Pat) -> Vec<ast::Ident> {
let mut name_finder =
PatIdentFinder{ident_accumulator: Vec::new(),};
name_finder.visit_pat(pat);
name_finder.ident_accumulator
}
/// find the PatIdent paths in a
fn fn_decl_arg_bindings(fn_decl: &ast::FnDecl) -> Vec<ast::Ident> {
let mut pat_idents =
PatIdentFinder{ident_accumulator: Vec::new(),};
for arg in &fn_decl.inputs { pat_idents.visit_pat(&arg.pat); }
pat_idents.ident_accumulator
}
pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander)
-> P<Block> {
{
fld.cx.syntax_env.push_frame();
fld.cx.syntax_env.info().macros_escape = false;
let result = expand_block_elts(blk, fld);
fld.cx.syntax_env.pop_frame();
result
}
}
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander)
-> P<Block> {
b.map(|Block { id, stmts, expr, rules, span }| {
let new_stmts =
stmts.into_iter().flat_map(|x| {
let renamed_stmt =
{
let pending_renames =
&mut fld.cx.syntax_env.info().pending_renames;
let mut rename_fld =
IdentRenamer{renames:
pending_renames,};
rename_fld.fold_stmt(x).expect_one("rename_fold didn\'t return one value")
};
fld.fold_stmt(renamed_stmt).into_iter()
}).collect();
let new_expr =
expr.map(|x| {
let expr =
{
let pending_renames =
&mut fld.cx.syntax_env.info().pending_renames;
let mut rename_fld =
IdentRenamer{renames:
pending_renames,};
rename_fld.fold_expr(x)
}; fld.fold_expr(expr) });
Block{id: fld.new_id(id),
stmts: new_stmts,
expr: new_expr,
rules: rules,
span: span,} })
}
fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander)
-> P<ast::Pat> {
match p.node {
PatMac(_) => { }
_ => return noop_fold_pat(p, fld),
}
p.clone().map(|ast::Pat { node, span, .. }| {
let (pth, tts) =
match node {
PatMac(mac) =>
(mac.node.path, mac.node.tts),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
771u32);
&_FILE_LINE
})
}
}
};
if pth.segments.len() > 1 {
fld.cx.span_err(pth.span,
"expected macro name without module separators");
return DummyResult::raw_pat(span);
} let extname = pth.segments[0].identifier.name;
let marked_after =
match fld.cx.syntax_env.find(extname) {
None => { return p.and_then(|p| p); }
Some(rc) =>
match *rc {
NormalTT(ref expander, tt_span,
allow_internal_unstable) => {
fld.cx.bt_push(ExpnInfo{call_site:
span,
callee:
NameAndSpan{format:
MacroBang(extname),
span:
tt_span,
allow_internal_unstable:
allow_internal_unstable,},});
let fm = fresh_mark();
let marked_before =
mark_tts(&tts[..], fm);
let mac_span =
fld.cx.original_span();
let pat =
expander.expand(fld.cx,
mac_span,
&marked_before[..]).make_pat();
let expanded =
match pat {
Some(e) => e,
None => {
fld.cx.span_err(pth.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["non-pattern macro in pattern position: "];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return DummyResult::raw_pat(span);
}
};
mark_pat(expanded, fm)
}
_ => {
fld.cx.span_err(span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"! is not legal in pattern position"];
__STATIC_FMTSTR
},
&match (&extname,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return DummyResult::raw_pat(span);
}
},
};
let fully_expanded =
fld.fold_pat(marked_after).node.clone();
fld.cx.bt_pop();
ast::Pat{id: ast::DUMMY_NODE_ID,
node: fully_expanded,
span: span,} })
}
/// A tree-folder that applies every rename in its (mutable) list
/// to every identifier, including both bindings and varrefs
/// (and lots of things that will turn out to be neither)
pub struct IdentRenamer<'a> {
renames: &'a mtwt::RenameList,
}
impl <'a> Folder for IdentRenamer<'a> {
fn fold_ident(&mut self, id: Ident) -> Ident {
Ident::new(id.name,
mtwt::apply_renames(self.renames, id.ctxt))
}
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self)
}
}
/// A tree-folder that applies every rename in its list to
/// the idents that are in PatIdent patterns. This is more narrowly
/// focused than IdentRenamer, and is needed for FnDecl,
/// where we want to rename the args but not the fn name or the generics etc.
pub struct PatIdentRenamer<'a> {
renames: &'a mtwt::RenameList,
}
impl <'a> Folder for PatIdentRenamer<'a> {
fn fold_pat(&mut self, pat: P<ast::Pat>) -> P<ast::Pat> {
match pat.node {
ast::PatIdent(..) => { }
_ => return noop_fold_pat(pat, self),
}
pat.map(|ast::Pat { id, node, span }|
match node {
ast::PatIdent(binding_mode, Spanned {
span: sp, node: ident }, sub) =>
{
let new_ident =
Ident::new(ident.name,
mtwt::apply_renames(self.renames,
ident.ctxt));
let new_node =
ast::PatIdent(binding_mode,
Spanned{span:
self.new_span(sp),
node:
new_ident,},
sub.map(|p|
self.fold_pat(p)));
ast::Pat{id: id,
node: new_node,
span: self.new_span(span),}
}
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
890u32);
&_FILE_LINE
})
}
}
})
}
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self)
}
}
fn expand_annotatable(a: Annotatable, fld: &mut MacroExpander)
-> SmallVector<Annotatable> {
let a = expand_item_multi_modifier(a, fld);
let mut decorator_items = SmallVector::zero();
let mut new_attrs = Vec::new();
expand_decorators(a.clone(), fld, &mut decorator_items,
&mut new_attrs);
let mut new_items: SmallVector<Annotatable> =
match a {
Annotatable::Item(it) =>
match it.node {
ast::ItemMac(..) => {
expand_item_mac(it,
fld).into_iter().map(|i|
Annotatable::Item(i)).collect()
}
ast::ItemMod(_) | ast::ItemForeignMod(_) => {
let valid_ident =
it.ident.name !=
parse::token::special_idents::invalid.name;
if valid_ident { fld.cx.mod_push(it.ident); }
let macro_use =
contains_macro_use(fld, &new_attrs[..]);
let result =
{
fld.cx.syntax_env.push_frame();
fld.cx.syntax_env.info().macros_escape =
macro_use;
let result = noop_fold_item(it, fld);
fld.cx.syntax_env.pop_frame();
result
};
if valid_ident { fld.cx.mod_pop(); }
result.into_iter().map(|i|
Annotatable::Item(i)).collect()
}
_ => {
let it =
P(ast::Item{attrs:
new_attrs, ..(*it).clone()});
noop_fold_item(it,
fld).into_iter().map(|i|
Annotatable::Item(i)).collect()
}
},
Annotatable::TraitItem(it) =>
match it.node {
ast::MethodTraitItem(_, Some(_)) =>
SmallVector::one(it.map(|ti|
ast::TraitItem{id: ti.id,
ident:
ti.ident,
attrs:
ti.attrs,
node:
match ti.node
{
ast::MethodTraitItem(sig,
Some(body))
=>
{
let (sig,
body) =
expand_and_rename_method(sig,
body,
fld);
ast::MethodTraitItem(sig,
Some(body))
}
_
=>
{
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
947u32);
&_FILE_LINE
})
}
}
},
span:
fld.new_span(ti.span),})),
_ => fold::noop_fold_trait_item(it, fld),
}.into_iter().map(Annotatable::TraitItem).collect(),
Annotatable::ImplItem(ii) => {
expand_impl_item(ii,
fld).into_iter().map(Annotatable::ImplItem).collect()
}
};
new_items.extend(decorator_items.into_iter());
new_items
}
fn multi_modifiers(attrs: &[ast::Attribute], fld: &MacroExpander)
-> (Vec<ast::Attribute>, Vec<ast::Attribute>) {
attrs.iter().cloned().partition(|attr| {
match fld.cx.syntax_env.find(intern(&attr.name()))
{
Some(rc) =>
match *rc {
MultiModifier(..) => true,
_ => false,
},
_ => false,
} })
}
fn expand_decorators(a: Annotatable, fld: &mut MacroExpander,
decorator_items: &mut SmallVector<Annotatable>,
new_attrs: &mut Vec<ast::Attribute>) {
for attr in a.attrs() {
let mname = intern(&attr.name());
match fld.cx.syntax_env.find(mname) {
Some(rc) =>
match *rc {
MultiDecorator(ref dec) => {
attr::mark_used(&attr);
fld.cx.bt_push(ExpnInfo{call_site: attr.span,
callee:
NameAndSpan{format:
MacroAttribute(mname),
span:
Some(attr.span),
allow_internal_unstable:
true,},});
let mut items: SmallVector<Annotatable> =
SmallVector::zero();
dec.expand(fld.cx, attr.span, &attr.node.value,
&a, &mut (|ann| items.push(ann)));
decorator_items.extend(items.into_iter().flat_map(|ann|
expand_annotatable(ann,
fld).into_iter()));
fld.cx.bt_pop();
}
_ => new_attrs.push((*attr).clone()),
},
_ => new_attrs.push((*attr).clone()),
}
}
}
fn expand_item_multi_modifier(mut it: Annotatable,
fld: &mut MacroExpander)
-> Annotatable {
let (modifiers, other_attrs) = multi_modifiers(it.attrs(), fld);
it = it.fold_attrs(other_attrs);
if modifiers.is_empty() { return it }
for attr in &modifiers {
let mname = intern(&attr.name());
match fld.cx.syntax_env.find(mname) {
Some(rc) =>
match *rc {
MultiModifier(ref mac) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo{call_site: attr.span,
callee:
NameAndSpan{format:
MacroAttribute(mname),
span:
Some(attr.span),
allow_internal_unstable:
true,},});
it =
mac.expand(fld.cx, attr.span,
&*attr.node.value, it);
fld.cx.bt_pop();
}
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/expand.rs",
1060u32);
&_FILE_LINE
})
}
}
},
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/expand.rs",
1062u32);
&_FILE_LINE
})
}
}
}
}
expand_item_multi_modifier(it, fld)
}
fn expand_impl_item(ii: P<ast::ImplItem>, fld: &mut MacroExpander)
-> SmallVector<P<ast::ImplItem>> {
match ii.node {
ast::ImplItemKind::Method(..) =>
SmallVector::one(ii.map(|ii|
ast::ImplItem{id: ii.id,
ident: ii.ident,
attrs: ii.attrs,
vis: ii.vis,
node:
match ii.node {
ast::ImplItemKind::Method(sig,
body)
=> {
let (sig,
body) =
expand_and_rename_method(sig,
body,
fld);
ast::ImplItemKind::Method(sig,
body)
}
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
1083u32);
&_FILE_LINE
})
}
}
},
span:
fld.new_span(ii.span),})),
ast::ImplItemKind::Macro(_) => {
let (span, mac) =
ii.clone().and_then(|ii|
match ii.node {
ast::ImplItemKind::Macro(mac)
=> (ii.span, mac),
_ => {
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/expand.rs",
1090u32);
&_FILE_LINE
})
}
}
});
let maybe_new_items =
expand_mac_invoc(mac, span, |r| r.make_impl_items(),
|meths, mark|
meths.move_map(|m|
mark_impl_item(m,
mark)),
fld);
match maybe_new_items {
Some(impl_items) => {
let new_items =
impl_items.into_iter().flat_map(|ii| {
expand_impl_item(ii,
fld).into_iter()
}).collect();
fld.cx.bt_pop();
new_items
}
None => { SmallVector::one(ii) }
}
}
_ => fold::noop_fold_impl_item(ii, fld),
}
}
/// Given a fn_decl and a block and a MacroExpander, expand the fn_decl, then use the
/// PatIdents in its arguments to perform renaming in the FnDecl and
/// the block, returning both the new FnDecl and the new Block.
fn expand_and_rename_fn_decl_and_block(fn_decl: P<ast::FnDecl>,
block: P<ast::Block>,
fld: &mut MacroExpander)
-> (P<ast::FnDecl>, P<ast::Block>) {
let expanded_decl = fld.fold_fn_decl(fn_decl);
let idents = fn_decl_arg_bindings(&expanded_decl);
let renames =
idents.iter().map(|id| (*id, fresh_name(*id))).collect();
let mut rename_pat_fld = PatIdentRenamer{renames: &renames,};
let rewritten_fn_decl =
rename_pat_fld.fold_fn_decl(expanded_decl);
let mut rename_fld = IdentRenamer{renames: &renames,};
let rewritten_body = fld.fold_block(rename_fld.fold_block(block));
(rewritten_fn_decl, rewritten_body)
}
fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>,
fld: &mut MacroExpander)
-> (ast::MethodSig, P<ast::Block>) {
let (rewritten_fn_decl, rewritten_body) =
expand_and_rename_fn_decl_and_block(sig.decl, body, fld);
(ast::MethodSig{generics: fld.fold_generics(sig.generics),
abi: sig.abi,
explicit_self:
fld.fold_explicit_self(sig.explicit_self),
unsafety: sig.unsafety,
constness: sig.constness,
decl: rewritten_fn_decl,}, rewritten_body)
}
pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander)
-> P<ast::Ty> {
let t =
match t.node.clone() {
ast::Ty_::TyMac(mac) => {
if fld.cx.ecfg.features.unwrap().type_macros {
let expanded_ty =
match expand_mac_invoc(mac, t.span,
|r| r.make_ty(),
mark_ty, fld) {
Some(ty) => ty,
None => {
return DummyResult::raw_ty(t.span);
}
};
let fully_expanded = fld.fold_ty(expanded_ty);
fld.cx.bt_pop();
fully_expanded.map(|t|
ast::Ty{id:
ast::DUMMY_NODE_ID,
node: t.node,
span: t.span,})
} else {
feature_gate::emit_feature_err(&fld.cx.parse_sess.span_diagnostic,
"type_macros",
t.span,
feature_gate::GateIssue::Language,
"type macros are experimental");
DummyResult::raw_ty(t.span)
}
}
_ => t,
};
fold::noop_fold_ty(t, fld)
}
/// A tree-folder that performs macro expansion
pub struct MacroExpander<'a, 'b:'a> {
pub cx: &'a mut ExtCtxt<'b>,
}
impl <'a, 'b> MacroExpander<'a, 'b> {
pub fn new(cx: &'a mut ExtCtxt<'b>) -> MacroExpander<'a, 'b> {
MacroExpander{cx: cx,}
}
}
impl <'a, 'b> Folder for MacroExpander<'a, 'b> {
fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
expand_expr(expr, self)
}
fn fold_pat(&mut self, pat: P<ast::Pat>) -> P<ast::Pat> {
expand_pat(pat, self)
}
fn fold_item(&mut self, item: P<ast::Item>)
-> SmallVector<P<ast::Item>> {
expand_item(item, self)
}
fn fold_item_underscore(&mut self, item: ast::Item_)
-> ast::Item_ {
expand_item_underscore(item, self)
}
fn fold_stmt(&mut self, stmt: P<ast::Stmt>)
-> SmallVector<P<ast::Stmt>> {
expand_stmt(stmt, self)
}
fn fold_block(&mut self, block: P<Block>) -> P<Block> {
expand_block(block, self)
}
fn fold_arm(&mut self, arm: ast::Arm) -> ast::Arm {
expand_arm(arm, self)
}
fn fold_trait_item(&mut self, i: P<ast::TraitItem>)
-> SmallVector<P<ast::TraitItem>> {
expand_annotatable(Annotatable::TraitItem(i),
self).into_iter().map(|i|
i.expect_trait_item()).collect()
}
fn fold_impl_item(&mut self, i: P<ast::ImplItem>)
-> SmallVector<P<ast::ImplItem>> {
expand_annotatable(Annotatable::ImplItem(i),
self).into_iter().map(|i|
i.expect_impl_item()).collect()
}
fn fold_ty(&mut self, ty: P<ast::Ty>) -> P<ast::Ty> {
expand_type(ty, self)
}
fn new_span(&mut self, span: Span) -> Span {
new_span(self.cx, span)
}
}
fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
Span{lo: sp.lo, hi: sp.hi, expn_id: cx.backtrace(),}
}
pub struct ExpansionConfig<'feat> {
pub crate_name: String,
pub features: Option<&'feat Features>,
pub recursion_limit: usize,
pub trace_mac: bool,
}
impl <'feat> ExpansionConfig<'feat> {
pub fn default(crate_name: String) -> ExpansionConfig<'static> {
ExpansionConfig{crate_name: crate_name,
features: None,
recursion_limit: 64,
trace_mac: false,}
}
pub fn enable_quotes(&self) -> bool {
match self.features {
Some(&Features { allow_quote: true, .. }) => true,
_ => false,
}
}
pub fn enable_asm(&self) -> bool {
match self.features {
Some(&Features { allow_asm: true, .. }) => true,
_ => false,
}
}
pub fn enable_log_syntax(&self) -> bool {
match self.features {
Some(&Features { allow_log_syntax: true, .. }) => true,
_ => false,
}
}
pub fn enable_concat_idents(&self) -> bool {
match self.features {
Some(&Features { allow_concat_idents: true, .. }) => true,
_ => false,
}
}
pub fn enable_trace_macros(&self) -> bool {
match self.features {
Some(&Features { allow_trace_macros: true, .. }) => true,
_ => false,
}
}
pub fn enable_allow_internal_unstable(&self) -> bool {
match self.features {
Some(&Features { allow_internal_unstable: true, .. }) =>
true,
_ => false,
}
}
pub fn enable_custom_derive(&self) -> bool {
match self.features {
Some(&Features { allow_custom_derive: true, .. }) => true,
_ => false,
}
}
pub fn enable_pushpop_unsafe(&self) -> bool {
match self.features {
Some(&Features { allow_pushpop_unsafe: true, .. }) =>
true,
_ => false,
}
}
}
pub fn expand_crate(mut cx: ExtCtxt,
imported_macros: Vec<ast::MacroDef>,
user_exts: Vec<NamedSyntaxExtension>, c: Crate)
-> (Crate, HashSet<Name>) {
if std_inject::no_core(&c) {
cx.crate_root = None;
} else if std_inject::no_std(&c) {
cx.crate_root = Some("core");
} else { cx.crate_root = Some("std"); }
let ret =
{
let mut expander = MacroExpander::new(&mut cx);
for def in imported_macros {
expander.cx.insert_macro(def);
}
for (name, extension) in user_exts {
expander.cx.syntax_env.insert(name, extension);
}
let mut ret = expander.fold_crate(c);
ret.exported_macros = expander.cx.exported_macros.clone();
cx.parse_sess.span_diagnostic.abort_if_errors();
ret
};
return (ret, cx.syntax_env.names);
}
struct Marker {
mark: Mrk,
}
impl Folder for Marker {
fn fold_ident(&mut self, id: Ident) -> Ident {
ast::Ident::new(id.name, mtwt::apply_mark(self.mark, id.ctxt))
}
fn fold_mac(&mut self, Spanned { node, span }: ast::Mac)
-> ast::Mac {
Spanned{node:
Mac_{path: self.fold_path(node.path),
tts: self.fold_tts(&node.tts),
ctxt:
mtwt::apply_mark(self.mark, node.ctxt),},
span: span,}
}
}
fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> {
noop_fold_tts(tts, &mut Marker{mark: m,})
}
fn mark_expr(expr: P<ast::Expr>, m: Mrk) -> P<ast::Expr> {
Marker{mark: m,}.fold_expr(expr)
}
fn mark_pat(pat: P<ast::Pat>, m: Mrk) -> P<ast::Pat> {
Marker{mark: m,}.fold_pat(pat)
}
fn mark_stmt(stmt: P<ast::Stmt>, m: Mrk) -> P<ast::Stmt> {
Marker{mark:
m,}.fold_stmt(stmt).expect_one("marking a stmt didn\'t return exactly one stmt")
}
fn mark_item(expr: P<ast::Item>, m: Mrk) -> P<ast::Item> {
Marker{mark:
m,}.fold_item(expr).expect_one("marking an item didn\'t return exactly one item")
}
fn mark_impl_item(ii: P<ast::ImplItem>, m: Mrk) -> P<ast::ImplItem> {
Marker{mark:
m,}.fold_impl_item(ii).expect_one("marking an impl item didn\'t return exactly one impl item")
}
fn mark_ty(ty: P<ast::Ty>, m: Mrk) -> P<ast::Ty> {
Marker{mark: m,}.fold_ty(ty)
}
/// Check that there are no macro invocations left in the AST:
pub fn check_for_macros(sess: &parse::ParseSess, krate: &ast::Crate) {
visit::walk_crate(&mut MacroExterminator{sess: sess,}, krate);
}
/// A visitor that ensures that no macro invocations remain in an AST.
struct MacroExterminator<'a> {
sess: &'a parse::ParseSess,
}
impl <'a, 'v> Visitor<'v> for MacroExterminator<'a> {
fn visit_mac(&mut self, mac: &ast::Mac) {
self.sess.span_diagnostic.span_bug(mac.span,
"macro exterminator: expected AST with no macro invocations");
}
}
}
pub mod mtwt {
//! Machinery for hygienic macros, as described in the MTWT[1] paper.
//!
//! [1] Matthew Flatt, Ryan Culpepper, David Darais, and Robert Bruce Findler.
//! 2012. *Macros that work together: Compile-time bindings, partial expansion,
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093
#[prelude_import]
use std::prelude::v1::*;
pub use self::SyntaxContext_::*;
use ast::{Ident, Mrk, Name, SyntaxContext};
use std::cell::RefCell;
use std::collections::HashMap;
/// The SCTable contains a table of SyntaxContext_'s. It
/// represents a flattened tree structure, to avoid having
/// managed pointers everywhere (that caused an ICE).
/// the mark_memo and rename_memo fields are side-tables
/// that ensure that adding the same mark to the same context
/// gives you back the same context as before. This shouldn't
/// change the semantics--everything here is immutable--but
/// it should cut down on memory use *a lot*; applying a mark
/// to a tree containing 50 identifiers would otherwise generate
/// 50 new contexts
pub struct SCTable {
table: RefCell<Vec<SyntaxContext_>>,
mark_memo: RefCell<HashMap<(SyntaxContext, Mrk), SyntaxContext>>,
rename_memo: RefCell<HashMap<(SyntaxContext,
(Name, SyntaxContext), Name),
SyntaxContext>>,
}
pub enum SyntaxContext_ {
EmptyCtxt,
Mark(Mrk, SyntaxContext),
/// flattening the name and syntaxcontext into the rename...
/// HIDDEN INVARIANTS:
/// 1) the first name in a Rename node
/// can only be a programmer-supplied name.
/// 2) Every Rename node with a given Name in the
/// "to" slot must have the same name and context
/// in the "from" slot. In essence, they're all
/// pointers to a single "rename" event node.
Rename(Ident, Name, SyntaxContext),
/// actually, IllegalCtxt may not be necessary.
IllegalCtxt,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for SyntaxContext_ {
#[inline]
fn clone(&self) -> SyntaxContext_ {
match (&*self,) {
(&SyntaxContext_::EmptyCtxt,) =>
SyntaxContext_::EmptyCtxt,
(&SyntaxContext_::Mark(ref __self_0, ref __self_1),) =>
SyntaxContext_::Mark(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&SyntaxContext_::Rename(ref __self_0, ref __self_1,
ref __self_2),) =>
SyntaxContext_::Rename(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1)),
::std::clone::Clone::clone(&(*__self_2))),
(&SyntaxContext_::IllegalCtxt,) =>
SyntaxContext_::IllegalCtxt,
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::marker::Copy for SyntaxContext_ { }
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for SyntaxContext_ {
fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
match (&*self,) {
(&SyntaxContext_::EmptyCtxt,) => {
let mut builder = __arg_0.debug_tuple("EmptyCtxt");
builder.finish()
}
(&SyntaxContext_::Mark(ref __self_0, ref __self_1),) => {
let mut builder = __arg_0.debug_tuple("Mark");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
builder.finish()
}
(&SyntaxContext_::Rename(ref __self_0, ref __self_1,
ref __self_2),) => {
let mut builder = __arg_0.debug_tuple("Rename");
let _ = builder.field(&&(*__self_0));
let _ = builder.field(&&(*__self_1));
let _ = builder.field(&&(*__self_2));
builder.finish()
}
(&SyntaxContext_::IllegalCtxt,) => {
let mut builder = __arg_0.debug_tuple("IllegalCtxt");
builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::hash::Hash for SyntaxContext_ {
fn hash<__H: ::std::hash::Hasher>(&self, __arg_0: &mut __H)
-> () {
match (&*self,) {
(&SyntaxContext_::EmptyCtxt,) => {
::std::hash::Hash::hash(&0usize, __arg_0);
}
(&SyntaxContext_::Mark(ref __self_0, ref __self_1),) => {
::std::hash::Hash::hash(&1usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
}
(&SyntaxContext_::Rename(ref __self_0, ref __self_1,
ref __self_2),) => {
::std::hash::Hash::hash(&2usize, __arg_0);
::std::hash::Hash::hash(&(*__self_0), __arg_0);
::std::hash::Hash::hash(&(*__self_1), __arg_0);
::std::hash::Hash::hash(&(*__self_2), __arg_0);
}
(&SyntaxContext_::IllegalCtxt,) => {
::std::hash::Hash::hash(&3usize, __arg_0);
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for SyntaxContext_ {
fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
-> ::std::result::Result<SyntaxContext_, __D::Error> {
__arg_0.read_enum("SyntaxContext_", |_d| -> _ {
_d.read_enum_variant(&["EmptyCtxt", "Mark",
"Rename",
"IllegalCtxt"],
|_d, i| -> _ {
::std::result::Result::Ok(match i
{
0usize
=>
SyntaxContext_::EmptyCtxt,
1usize
=>
SyntaxContext_::Mark(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
2usize
=>
SyntaxContext_::Rename(match _d.read_enum_variant_arg(0usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(1usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
},
match _d.read_enum_variant_arg(2usize,
::rustc_serialize::Decodable::decode)
{
::std::result::Result::Ok(__try_var)
=>
__try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
}),
3usize
=>
SyntaxContext_::IllegalCtxt,
_
=>
::std::rt::begin_unwind("internal error: entered unreachable code",
&("src/ext/mtwt.rs",
43u32)),
})
}) })
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for SyntaxContext_ {
fn encode<__S: ::rustc_serialize::Encoder>(&self,
__arg_0: &mut __S)
-> ::std::result::Result<(), __S::Error> {
match (&*self,) {
(&SyntaxContext_::EmptyCtxt,) => {
let _e = __arg_0;
_e.emit_enum("SyntaxContext_", |_e| -> _ {
_e.emit_enum_variant("EmptyCtxt", 0usize,
0usize, |_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
(&SyntaxContext_::Mark(ref __self_0, ref __self_1),) => {
let _e = __arg_0;
_e.emit_enum("SyntaxContext_", |_e| -> _ {
_e.emit_enum_variant("Mark", 1usize,
2usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
});
}) })
}
(&SyntaxContext_::Rename(ref __self_0, ref __self_1,
ref __self_2),) => {
let _e = __arg_0;
_e.emit_enum("SyntaxContext_", |_e| -> _ {
_e.emit_enum_variant("Rename", 2usize,
3usize, |_e| -> _ {
match _e.emit_enum_variant_arg(0usize,
|_e|
->
_
{
(*__self_0).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
match _e.emit_enum_variant_arg(1usize,
|_e|
->
_
{
(*__self_1).encode(_e)
})
{
::std::result::Result::Ok(__try_var)
=> __try_var,
::std::result::Result::Err(__try_var)
=>
return ::std::result::Result::Err(__try_var),
};
return _e.emit_enum_variant_arg(2usize,
|_e|
->
_
{
(*__self_2).encode(_e)
});
}) })
}
(&SyntaxContext_::IllegalCtxt,) => {
let _e = __arg_0;
_e.emit_enum("SyntaxContext_", |_e| -> _ {
_e.emit_enum_variant("IllegalCtxt",
3usize, 0usize,
|_e| -> _ {
return ::std::result::Result::Ok(());
}) })
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::cmp::PartialEq for SyntaxContext_ {
#[inline]
fn eq(&self, __arg_0: &SyntaxContext_) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&SyntaxContext_::EmptyCtxt,
&SyntaxContext_::EmptyCtxt) => true,
(&SyntaxContext_::Mark(ref __self_0,
ref __self_1),
&SyntaxContext_::Mark(ref __arg_1_0,
ref __arg_1_1)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1),
(&SyntaxContext_::Rename(ref __self_0,
ref __self_1,
ref __self_2),
&SyntaxContext_::Rename(ref __arg_1_0,
ref __arg_1_1,
ref __arg_1_2)) =>
true && (*__self_0) == (*__arg_1_0) &&
(*__self_1) == (*__arg_1_1) &&
(*__self_2) == (*__arg_1_2),
(&SyntaxContext_::IllegalCtxt,
&SyntaxContext_::IllegalCtxt) => true,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { false }
}
}
#[inline]
fn ne(&self, __arg_0: &SyntaxContext_) -> bool {
{
let __self_vi =
unsafe {
::std::intrinsics::discriminant_value(&*self)
} as i32;
let __arg_1_vi =
unsafe {
::std::intrinsics::discriminant_value(&*__arg_0)
} as i32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*__arg_0) {
(&SyntaxContext_::EmptyCtxt,
&SyntaxContext_::EmptyCtxt) => false,
(&SyntaxContext_::Mark(ref __self_0,
ref __self_1),
&SyntaxContext_::Mark(ref __arg_1_0,
ref __arg_1_1)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1),
(&SyntaxContext_::Rename(ref __self_0,
ref __self_1,
ref __self_2),
&SyntaxContext_::Rename(ref __arg_1_0,
ref __arg_1_1,
ref __arg_1_2)) =>
false || (*__self_0) != (*__arg_1_0) ||
(*__self_1) != (*__arg_1_1) ||
(*__self_2) != (*__arg_1_2),
(&SyntaxContext_::IllegalCtxt,
&SyntaxContext_::IllegalCtxt) => false,
_ => unsafe { ::std::intrinsics::unreachable() }
}
} else { true }
}
}
}
/// A list of ident->name renamings
pub type RenameList = Vec<(Ident, Name)>;
/// Extend a syntax context with a given mark
pub fn apply_mark(m: Mrk, ctxt: SyntaxContext) -> SyntaxContext {
with_sctable(|table| apply_mark_internal(m, ctxt, table))
}
/// Extend a syntax context with a given mark and sctable (explicit memoization)
fn apply_mark_internal(m: Mrk, ctxt: SyntaxContext, table: &SCTable)
-> SyntaxContext {
let key = (ctxt, m);
*table.mark_memo.borrow_mut().entry(key).or_insert_with(|| {
SyntaxContext(idx_push(&mut *table.table.borrow_mut(),
Mark(m,
ctxt)))
})
}
/// Extend a syntax context with a given rename
pub fn apply_rename(id: Ident, to: Name, ctxt: SyntaxContext)
-> SyntaxContext {
with_sctable(|table| apply_rename_internal(id, to, ctxt, table))
}
/// Extend a syntax context with a given rename and sctable (explicit memoization)
fn apply_rename_internal(id: Ident, to: Name, ctxt: SyntaxContext,
table: &SCTable) -> SyntaxContext {
let key = (ctxt, (id.name, id.ctxt), to);
*table.rename_memo.borrow_mut().entry(key).or_insert_with(|| {
SyntaxContext(idx_push(&mut *table.table.borrow_mut(),
Rename(id,
to,
ctxt)))
})
}
/// Apply a list of renamings to a context
pub fn apply_renames(renames: &RenameList, ctxt: SyntaxContext)
-> SyntaxContext {
renames.iter().fold(ctxt, |ctxt, &(from, to)| {
apply_rename(from, to, ctxt) })
}
/// Fetch the SCTable from TLS, create one if it doesn't yet exist.
pub fn with_sctable<T, F>(op: F) -> T where F: FnOnce(&SCTable) -> T {
static SCTABLE_KEY: ::std::thread::LocalKey<SCTable> =
{
fn __init() -> SCTable { new_sctable_internal() }
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<SCTable>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY:
::std::thread::__ElfLocalKeyInner<SCTable> =
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
SCTABLE_KEY.with(move |slot| op(slot))
}
fn new_sctable_internal() -> SCTable {
SCTable{table:
RefCell::new(<[_]>::into_vec(::std::boxed::Box::new([EmptyCtxt,
IllegalCtxt]))),
mark_memo: RefCell::new(HashMap::new()),
rename_memo: RefCell::new(HashMap::new()),}
}
/// Print out an SCTable for debugging
pub fn display_sctable(table: &SCTable) {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 124u32,
__file: "src/ext/mtwt.rs",
__module_path:
"syntex_syntax::ext::mtwt",};
let lvl = ::log::LogLevel::Error;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::ext::mtwt", &_LOC,
::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["SC table:"];
__STATIC_FMTSTR
},
&match () {
() => [],
}))
}
};
for (idx, val) in table.table.borrow().iter().enumerate() {
{
static _LOC: ::log::LogLocation =
::log::LogLocation{__line: 126u32,
__file: "src/ext/mtwt.rs",
__module_path:
"syntex_syntax::ext::mtwt",};
let lvl = ::log::LogLevel::Error;
if lvl <= ::log::__static_max_level() &&
lvl <= ::log::max_log_level() {
::log::__log(lvl, "syntex_syntax::ext::mtwt", &_LOC,
::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" : "];
__STATIC_FMTSTR
},
&match (&idx,
&val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::Next,
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Is(4usize),},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::Next,
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
}))
}
};
}
}
/// Clear the tables from TLD to reclaim memory.
pub fn clear_tables() {
with_sctable(|table| { *table.table.borrow_mut() = Vec::new();
*table.mark_memo.borrow_mut() = HashMap::new();
*table.rename_memo.borrow_mut() = HashMap::new(); });
with_resolve_table_mut(|table| *table = HashMap::new());
}
/// Reset the tables to their initial state
pub fn reset_tables() {
with_sctable(|table| {
*table.table.borrow_mut() =
<[_]>::into_vec(::std::boxed::Box::new([EmptyCtxt,
IllegalCtxt]));
*table.mark_memo.borrow_mut() = HashMap::new();
*table.rename_memo.borrow_mut() = HashMap::new(); });
with_resolve_table_mut(|table| *table = HashMap::new());
}
/// Add a value to the end of a vec, return its index
fn idx_push<T>(vec: &mut Vec<T>, val: T) -> u32 {
vec.push(val);
(vec.len() - 1) as u32
}
/// Resolve a syntax object to a name, per MTWT.
pub fn resolve(id: Ident) -> Name {
with_sctable(|sctable| {
with_resolve_table_mut(|resolve_table| {
resolve_internal(id, sctable,
resolve_table)
}) })
}
type ResolveTable = HashMap<(Name, SyntaxContext), Name>;
fn with_resolve_table_mut<T, F>(op: F) -> T where
F: FnOnce(&mut ResolveTable) -> T {
static RESOLVE_TABLE_KEY:
::std::thread::LocalKey<RefCell<ResolveTable>> =
{
fn __init() -> RefCell<ResolveTable> {
{ RefCell::new(HashMap::new()) }
}
unsafe fn __getit()
->
::std::option::Option<&'static ::std::cell::UnsafeCell<::std::option::Option<RefCell<ResolveTable>>>> {
#[thread_local]
#[cfg(target_thread_local)]
static __KEY:
::std::thread::__ElfLocalKeyInner<RefCell<ResolveTable>>
=
::std::thread::__ElfLocalKeyInner::new();
__KEY.get()
}
::std::thread::LocalKey::new(__getit, __init)
};
RESOLVE_TABLE_KEY.with(move |slot| op(&mut *slot.borrow_mut()))
}
/// Resolve a syntax object to a name, per MTWT.
/// adding memoization to resolve 500+ seconds in resolve for librustc (!)
fn resolve_internal(id: Ident, table: &SCTable,
resolve_table: &mut ResolveTable) -> Name {
let key = (id.name, id.ctxt);
match resolve_table.get(&key) {
Some(&name) => return name,
None => { }
}
let resolved =
{
let result = (*table.table.borrow())[id.ctxt.0 as usize];
match result {
EmptyCtxt => id.name,
Mark(_, subctxt) =>
resolve_internal(Ident::new(id.name, subctxt), table,
resolve_table),
Rename(Ident { name, ctxt }, toname, subctxt) => {
let resolvedfrom =
resolve_internal(Ident::new(name, ctxt),
table, resolve_table);
let resolvedthis =
resolve_internal(Ident::new(id.name, subctxt),
table, resolve_table);
if (resolvedthis == resolvedfrom) &&
(marksof_internal(ctxt, resolvedthis,
table) ==
marksof_internal(subctxt,
resolvedthis, table))
{
toname
} else { resolvedthis }
}
IllegalCtxt => {
::std::rt::begin_unwind("expected resolvable context, got IllegalCtxt",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/mtwt.rs",
215u32);
&_FILE_LINE
})
}
}
};
resolve_table.insert(key, resolved);
resolved
}
/// Compute the marks associated with a syntax context.
pub fn marksof(ctxt: SyntaxContext, stopname: Name) -> Vec<Mrk> {
with_sctable(|table| marksof_internal(ctxt, stopname, table))
}
fn marksof_internal(ctxt: SyntaxContext, stopname: Name,
table: &SCTable) -> Vec<Mrk> {
let mut result = Vec::new();
let mut loopvar = ctxt;
loop {
let table_entry = (*table.table.borrow())[loopvar.0 as usize];
match table_entry {
EmptyCtxt => { return result; }
Mark(mark, tl) => {
xor_push(&mut result, mark);
loopvar = tl;
}
Rename(_, name, tl) => {
if name == stopname {
return result;
} else { loopvar = tl; }
}
IllegalCtxt => {
::std::rt::begin_unwind("expected resolvable context, got IllegalCtxt",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/mtwt.rs",
254u32);
&_FILE_LINE
})
}
}
}
}
/// Return the outer mark for a context with a mark at the outside.
/// FAILS when outside is not a mark.
pub fn outer_mark(ctxt: SyntaxContext) -> Mrk {
with_sctable(|sctable| {
match (*sctable.table.borrow())[ctxt.0 as usize] {
Mark(mrk, _) => mrk,
_ => {
::std::rt::begin_unwind("can\'t retrieve outer mark when outside is not a mark",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/mtwt.rs",
265u32);
&_FILE_LINE
})
}
} })
}
/// Push a name... unless it matches the one on top, in which
/// case pop and discard (so two of the same marks cancel)
fn xor_push(marks: &mut Vec<Mrk>, mark: Mrk) {
if (!marks.is_empty()) && (*marks.last().unwrap() == mark) {
marks.pop().unwrap();
} else { marks.push(mark); }
}
}
pub mod quote {
#[prelude_import]
use std::prelude::v1::*;
use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, TokenTree,
Ty};
use codemap::Span;
use ext::base::ExtCtxt;
use ext::base;
use ext::build::AstBuilder;
use parse::parser::{Parser, PathParsingMode};
use parse::token::*;
use parse::token;
use ptr::P;
/// Quasiquoting works via token trees.
///
/// This is registered as a set of expression syntax extension called quote!
/// that lifts its argument token-tree to an AST representing the
/// construction of the same token tree, with token::SubstNt interpreted
/// as antiquotes (splices).
pub mod rt {
#[prelude_import]
use std::prelude::v1::*;
use ast;
use codemap::Spanned;
use ext::base::ExtCtxt;
use parse::{self, token, classify};
use ptr::P;
use std::rc::Rc;
use ast::TokenTree;
pub use parse::new_parser_from_tts;
pub use codemap::{BytePos, Span, dummy_spanned, DUMMY_SP};
pub trait ToTokens {
fn to_tokens(&self, _cx: &ExtCtxt)
-> Vec<TokenTree>;
}
impl ToTokens for TokenTree {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([self.clone()]))
}
}
impl <T: ToTokens> ToTokens for Vec<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
self.iter().flat_map(|t| t.to_tokens(cx)).collect()
}
}
impl <T: ToTokens> ToTokens for Spanned<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
self.node.to_tokens(cx)
}
}
impl <T: ToTokens> ToTokens for Option<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
match *self {
Some(ref t) => t.to_tokens(cx),
None => Vec::new(),
}
}
}
impl ToTokens for ast::Ident {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Ident(*self,
token::Plain))]))
}
}
impl ToTokens for ast::Path {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtPath(Box::new(self.clone()))))]))
}
}
impl ToTokens for ast::Ty {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtTy(P(self.clone()))))]))
}
}
impl ToTokens for ast::Block {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtBlock(P(self.clone()))))]))
}
}
impl ToTokens for ast::Generics {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtGenerics(self.clone())))]))
}
}
impl ToTokens for ast::WhereClause {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtWhereClause(self.clone())))]))
}
}
impl ToTokens for P<ast::Item> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtItem(self.clone())))]))
}
}
impl ToTokens for P<ast::ImplItem> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtImplItem(self.clone())))]))
}
}
impl ToTokens for P<ast::TraitItem> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtTraitItem(self.clone())))]))
}
}
impl ToTokens for P<ast::Stmt> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
let mut tts =
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtStmt(self.clone())))]));
if classify::stmt_ends_with_semi(&self.node) {
tts.push(TokenTree::Token(self.span, token::Semi));
}
tts
}
}
impl ToTokens for P<ast::Expr> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtExpr(self.clone())))]))
}
}
impl ToTokens for P<ast::Pat> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(self.span,
token::Interpolated(token::NtPat(self.clone())))]))
}
}
impl ToTokens for ast::Arm {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtArm(self.clone())))]))
}
}
impl ToTokens for ast::Arg {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtArg(self.clone())))]))
}
}
impl ToTokens for P<ast::Block> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtBlock(self.clone())))]))
}
}
impl ToTokens for [ast::Ty] {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let mut v = <[_]>::into_vec(::std::boxed::Box::new([]));
for (i, x) in self.iter().enumerate() {
if i > 0 {
v.extend([TokenTree::Token(DUMMY_SP,
token::Comma)].iter().cloned());
}
v.extend(x.to_tokens(cx));
}
v
}
}
impl ToTokens for [P<ast::Item>] {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let mut v = <[_]>::into_vec(::std::boxed::Box::new([]));
for (i, x) in self.iter().enumerate() {
if i > 0 { v.extend([].iter().cloned()); }
v.extend(x.to_tokens(cx));
}
v
}
}
impl ToTokens for [ast::Arg] {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let mut v = <[_]>::into_vec(::std::boxed::Box::new([]));
for (i, x) in self.iter().enumerate() {
if i > 0 {
v.extend([TokenTree::Token(DUMMY_SP,
token::Comma)].iter().cloned());
}
v.extend(x.to_tokens(cx));
}
v
}
}
impl ToTokens for P<ast::MetaItem> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Interpolated(token::NtMeta(self.clone())))]))
}
}
impl ToTokens for ast::Attribute {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let mut r = <[_]>::into_vec(::std::boxed::Box::new([]));
r.push(TokenTree::Token(self.span, token::Pound));
if self.node.style == ast::AttrStyle::Inner {
r.push(TokenTree::Token(self.span, token::Not));
}
r.push(TokenTree::Delimited(self.span,
Rc::new(ast::Delimited{delim:
token::Bracket,
open_span:
self.span,
tts:
self.node.value.to_tokens(cx),
close_span:
self.span,})));
r
}
}
impl ToTokens for str {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitStr(token::intern_and_get_ident(self),
ast::CookedStr);
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for () {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Delimited(DUMMY_SP,
Rc::new(ast::Delimited{delim:
token::Paren,
open_span:
DUMMY_SP,
tts:
<[_]>::into_vec(::std::boxed::Box::new([])),
close_span:
DUMMY_SP,}))]))
}
}
impl ToTokens for ast::Lit {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
P(ast::Expr{id: ast::DUMMY_NODE_ID,
node: ast::ExprLit(P(self.clone())),
span: DUMMY_SP,
attrs: None,}).to_tokens(cx)
}
}
impl ToTokens for bool {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
dummy_spanned(ast::LitBool(*self)).to_tokens(cx)
}
}
impl ToTokens for char {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
dummy_spanned(ast::LitChar(*self)).to_tokens(cx)
}
}
impl ToTokens for isize {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::SignedIntLit(ast::TyIs,
ast::Sign::new(*self)));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for i8 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::SignedIntLit(ast::TyI8,
ast::Sign::new(*self)));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for i16 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::SignedIntLit(ast::TyI16,
ast::Sign::new(*self)));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for i32 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::SignedIntLit(ast::TyI32,
ast::Sign::new(*self)));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for i64 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::SignedIntLit(ast::TyI64,
ast::Sign::new(*self)));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for usize {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::UnsignedIntLit(ast::TyUs));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for u8 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::UnsignedIntLit(ast::TyU8));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for u16 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::UnsignedIntLit(ast::TyU16));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for u32 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::UnsignedIntLit(ast::TyU32));
dummy_spanned(lit).to_tokens(cx)
}
}
impl ToTokens for u64 {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit =
ast::LitInt(*self as u64,
ast::UnsignedIntLit(ast::TyU64));
dummy_spanned(lit).to_tokens(cx)
}
}
pub trait ExtParseUtils {
fn parse_item(&self, s: String)
-> P<ast::Item>;
fn parse_expr(&self, s: String)
-> P<ast::Expr>;
fn parse_stmt(&self, s: String)
-> P<ast::Stmt>;
fn parse_tts(&self, s: String)
-> Vec<TokenTree>;
}
impl <'a> ExtParseUtils for ExtCtxt<'a> {
fn parse_item(&self, s: String) -> P<ast::Item> {
parse::parse_item_from_source_str("<quote expansion>".to_string(),
s, self.cfg(),
self.parse_sess()).expect("parse error")
}
fn parse_stmt(&self, s: String) -> P<ast::Stmt> {
parse::parse_stmt_from_source_str("<quote expansion>".to_string(),
s, self.cfg(),
self.parse_sess()).expect("parse error")
}
fn parse_expr(&self, s: String) -> P<ast::Expr> {
parse::parse_expr_from_source_str("<quote expansion>".to_string(),
s, self.cfg(),
self.parse_sess())
}
fn parse_tts(&self, s: String) -> Vec<TokenTree> {
parse::parse_tts_from_source_str("<quote expansion>".to_string(),
s, self.cfg(),
self.parse_sess())
}
}
}
pub fn parse_expr_panic(parser: &mut Parser) -> P<Expr> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
337u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_item_panic(parser: &mut Parser) -> Option<P<Item>> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
341u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_pat_panic(parser: &mut Parser) -> P<Pat> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_pat() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
345u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_arm_panic(parser: &mut Parser) -> Arm {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_arm() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
349u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_ty_panic(parser: &mut Parser) -> P<Ty> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_ty() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
353u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_stmt_panic(parser: &mut Parser) -> Option<P<Stmt>> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_stmt() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
357u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_attribute_panic(parser: &mut Parser, permit_inner: bool)
-> ast::Attribute {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_attribute(permit_inner) {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
361u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_arg_panic(parser: &mut Parser) -> Arg {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_arg() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
365u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_block_panic(parser: &mut Parser) -> P<Block> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_block() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
369u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_meta_item_panic(parser: &mut Parser)
-> P<ast::MetaItem> {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_meta_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
373u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn parse_path_panic(parser: &mut Parser, mode: PathParsingMode)
-> ast::Path {
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_path(mode) {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
377u32);
&_FILE_LINE
})
};
}
}
}
}
pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'cx> {
let (cx_expr, expr) = expand_tts(cx, sp, tts);
let expanded =
expand_wrapper(cx, sp, cx_expr, expr,
&[&["syntax", "ext", "quote", "rt"]]);
base::MacEager::expr(expanded)
}
pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'cx> {
let expanded =
expand_parse_call(cx, sp, "parse_expr_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'cx> {
let expanded =
expand_parse_call(cx, sp, "parse_item_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'cx> {
let expanded =
expand_parse_call(cx, sp, "parse_pat_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_arm(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_arm_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_ty(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_ty_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_stmt(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_stmt_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_attr(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_attribute_panic",
<[_]>::into_vec(::std::boxed::Box::new([cx.expr_bool(sp,
true)])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_arg(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_arg_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_block(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_block_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_meta_item(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let expanded =
expand_parse_call(cx, sp, "parse_meta_item_panic",
<[_]>::into_vec(::std::boxed::Box::new([])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_path(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let mode =
mk_parser_path(cx, sp, "LifetimeAndTypesWithoutColons");
let expanded =
expand_parse_call(cx, sp, "parse_path_panic",
<[_]>::into_vec(::std::boxed::Box::new([mode])),
tts);
base::MacEager::expr(expanded)
}
pub fn expand_quote_matcher(cx: &mut ExtCtxt, sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+ 'static> {
let (cx_expr, tts) = parse_arguments_to_quote(cx, tts);
let mut vector = mk_stmts_let(cx, sp);
vector.extend(statements_mk_tts(cx, &tts[..], true));
let block =
cx.expr_block(cx.block_all(sp, vector,
Some(cx.expr_ident(sp,
id_ext("tt")))));
let expanded =
expand_wrapper(cx, sp, cx_expr, block,
&[&["syntax", "ext", "quote", "rt"]]);
base::MacEager::expr(expanded)
}
fn ids_ext(strs: Vec<String>) -> Vec<ast::Ident> {
strs.iter().map(|str| str_to_ident(&(*str))).collect()
}
fn id_ext(str: &str) -> ast::Ident { str_to_ident(str) }
fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident)
-> P<ast::Expr> {
let e_str = cx.expr_str(sp, ident.name.as_str());
cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("ext_cx")),
id_ext("ident_of"),
<[_]>::into_vec(::std::boxed::Box::new([e_str])))
}
fn mk_name(cx: &ExtCtxt, sp: Span, ident: ast::Ident)
-> P<ast::Expr> {
let e_str = cx.expr_str(sp, ident.name.as_str());
cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("ext_cx")),
id_ext("name_of"),
<[_]>::into_vec(::std::boxed::Box::new([e_str])))
}
fn mk_tt_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> {
let idents =
<[_]>::into_vec(::std::boxed::Box::new([id_ext("syntax"),
id_ext("ast"),
id_ext("TokenTree"),
id_ext(name)]));
cx.expr_path(cx.path_global(sp, idents))
}
fn mk_ast_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> {
let idents =
<[_]>::into_vec(::std::boxed::Box::new([id_ext("syntax"),
id_ext("ast"),
id_ext(name)]));
cx.expr_path(cx.path_global(sp, idents))
}
fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> {
let idents =
<[_]>::into_vec(::std::boxed::Box::new([id_ext("syntax"),
id_ext("parse"),
id_ext("token"),
id_ext(name)]));
cx.expr_path(cx.path_global(sp, idents))
}
fn mk_parser_path(cx: &ExtCtxt, sp: Span, name: &str)
-> P<ast::Expr> {
let idents =
<[_]>::into_vec(::std::boxed::Box::new([id_ext("syntax"),
id_ext("parse"),
id_ext("parser"),
id_ext(name)]));
cx.expr_path(cx.path_global(sp, idents))
}
fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOpToken)
-> P<ast::Expr> {
let name =
match bop {
token::Plus => "Plus",
token::Minus => "Minus",
token::Star => "Star",
token::Slash => "Slash",
token::Percent => "Percent",
token::Caret => "Caret",
token::And => "And",
token::Or => "Or",
token::Shl => "Shl",
token::Shr => "Shr",
};
mk_token_path(cx, sp, name)
}
fn mk_delim(cx: &ExtCtxt, sp: Span, delim: token::DelimToken)
-> P<ast::Expr> {
let name =
match delim {
token::Paren => "Paren",
token::Bracket => "Bracket",
token::Brace => "Brace",
};
mk_token_path(cx, sp, name)
}
#[allow(non_upper_case_globals)]
fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token)
-> P<ast::Expr> {
match *tok {
token::BinOp(binop) => {
return cx.expr_call(sp, mk_token_path(cx, sp, "BinOp"),
<[_]>::into_vec(::std::boxed::Box::new([mk_binop(cx,
sp,
binop)])));
}
token::BinOpEq(binop) => {
return cx.expr_call(sp, mk_token_path(cx, sp, "BinOpEq"),
<[_]>::into_vec(::std::boxed::Box::new([mk_binop(cx,
sp,
binop)])));
}
token::OpenDelim(delim) => {
return cx.expr_call(sp,
mk_token_path(cx, sp, "OpenDelim"),
<[_]>::into_vec(::std::boxed::Box::new([mk_delim(cx,
sp,
delim)])));
}
token::CloseDelim(delim) => {
return cx.expr_call(sp,
mk_token_path(cx, sp, "CloseDelim"),
<[_]>::into_vec(::std::boxed::Box::new([mk_delim(cx,
sp,
delim)])));
}
token::Literal(token::Byte(i), suf) => {
let e_byte =
mk_name(cx, sp, ast::Ident::with_empty_ctxt(i));
return {
let inner =
cx.expr_call(sp,
mk_token_path(cx, sp, "Byte"),
<[_]>::into_vec(::std::boxed::Box::new([e_byte])));
let suffix =
match suf {
Some(name) =>
cx.expr_some(sp,
mk_name(cx, sp,
ast::Ident::with_empty_ctxt(name))),
None => cx.expr_none(sp),
};
cx.expr_call(sp,
mk_token_path(cx, sp, "Literal"),
<[_]>::into_vec(::std::boxed::Box::new([inner,
suffix])))
};
}
token::Literal(token::Char(i), suf) => {
let e_char =
mk_name(cx, sp, ast::Ident::with_empty_ctxt(i));
return {
let inner =
cx.expr_call(sp,
mk_token_path(cx, sp, "Char"),
<[_]>::into_vec(::std::boxed::Box::new([e_char])));
let suffix =
match suf {
Some(name) =>
cx.expr_some(sp,
mk_name(cx, sp,
ast::Ident::with_empty_ctxt(name))),
None => cx.expr_none(sp),
};
cx.expr_call(sp,
mk_token_path(cx, sp, "Literal"),
<[_]>::into_vec(::std::boxed::Box::new([inner,
suffix])))
};
}
token::Literal(token::Integer(i), suf) => {
let e_int =
mk_name(cx, sp, ast::Ident::with_empty_ctxt(i));
return {
let inner =
cx.expr_call(sp,
mk_token_path(cx, sp,
"Integer"),
<[_]>::into_vec(::std::boxed::Box::new([e_int])));
let suffix =
match suf {
Some(name) =>
cx.expr_some(sp,
mk_name(cx, sp,
ast::Ident::with_empty_ctxt(name))),
None => cx.expr_none(sp),
};
cx.expr_call(sp,
mk_token_path(cx, sp, "Literal"),
<[_]>::into_vec(::std::boxed::Box::new([inner,
suffix])))
};
}
token::Literal(token::Float(fident), suf) => {
let e_fident =
mk_name(cx, sp, ast::Ident::with_empty_ctxt(fident));
return {
let inner =
cx.expr_call(sp,
mk_token_path(cx, sp,
"Float"),
<[_]>::into_vec(::std::boxed::Box::new([e_fident])));
let suffix =
match suf {
Some(name) =>
cx.expr_some(sp,
mk_name(cx, sp,
ast::Ident::with_empty_ctxt(name))),
None => cx.expr_none(sp),
};
cx.expr_call(sp,
mk_token_path(cx, sp, "Literal"),
<[_]>::into_vec(::std::boxed::Box::new([inner,
suffix])))
};
}
token::Literal(token::Str_(ident), suf) => {
return {
let inner =
cx.expr_call(sp,
mk_token_path(cx, sp, "Str_"),
<[_]>::into_vec(::std::boxed::Box::new([mk_name(cx,
sp,
ast::Ident::with_empty_ctxt(ident))])));
let suffix =
match suf {
Some(name) =>
cx.expr_some(sp,
mk_name(cx, sp,
ast::Ident::with_empty_ctxt(name))),
None => cx.expr_none(sp),
};
cx.expr_call(sp,
mk_token_path(cx, sp, "Literal"),
<[_]>::into_vec(::std::boxed::Box::new([inner,
suffix])))
}
}
token::Literal(token::StrRaw(ident, n), suf) => {
return {
let inner =
cx.expr_call(sp,
mk_token_path(cx, sp,
"StrRaw"),
<[_]>::into_vec(::std::boxed::Box::new([mk_name(cx,
sp,
ast::Ident::with_empty_ctxt(ident)),
cx.expr_usize(sp,
n)])));
let suffix =
match suf {
Some(name) =>
cx.expr_some(sp,
mk_name(cx, sp,
ast::Ident::with_empty_ctxt(name))),
None => cx.expr_none(sp),
};
cx.expr_call(sp,
mk_token_path(cx, sp, "Literal"),
<[_]>::into_vec(::std::boxed::Box::new([inner,
suffix])))
}
}
token::Ident(ident, style) => {
return cx.expr_call(sp, mk_token_path(cx, sp, "Ident"),
<[_]>::into_vec(::std::boxed::Box::new([mk_ident(cx,
sp,
ident),
match style
{
ModName
=>
mk_token_path(cx,
sp,
"ModName"),
Plain
=>
mk_token_path(cx,
sp,
"Plain"),
}])));
}
token::Lifetime(ident) => {
return cx.expr_call(sp, mk_token_path(cx, sp, "Lifetime"),
<[_]>::into_vec(::std::boxed::Box::new([mk_ident(cx,
sp,
ident)])));
}
token::DocComment(ident) => {
return cx.expr_call(sp,
mk_token_path(cx, sp, "DocComment"),
<[_]>::into_vec(::std::boxed::Box::new([mk_name(cx,
sp,
ast::Ident::with_empty_ctxt(ident))])));
}
token::MatchNt(name, kind, namep, kindp) => {
return cx.expr_call(sp, mk_token_path(cx, sp, "MatchNt"),
<[_]>::into_vec(::std::boxed::Box::new([mk_ident(cx,
sp,
name),
mk_ident(cx,
sp,
kind),
match namep
{
ModName
=>
mk_token_path(cx,
sp,
"ModName"),
Plain
=>
mk_token_path(cx,
sp,
"Plain"),
},
match kindp
{
ModName
=>
mk_token_path(cx,
sp,
"ModName"),
Plain
=>
mk_token_path(cx,
sp,
"Plain"),
}])));
}
token::Interpolated(_) => {
::std::rt::begin_unwind("quote! with interpolated token",
{
static _FILE_LINE:
(&'static str, u32) =
("src/ext/quote.rs",
663u32);
&_FILE_LINE
})
}
_ => (),
}
let name =
match *tok {
token::Eq => "Eq",
token::Lt => "Lt",
token::Le => "Le",
token::EqEq => "EqEq",
token::Ne => "Ne",
token::Ge => "Ge",
token::Gt => "Gt",
token::AndAnd => "AndAnd",
token::OrOr => "OrOr",
token::Not => "Not",
token::Tilde => "Tilde",
token::At => "At",
token::Dot => "Dot",
token::DotDot => "DotDot",
token::Comma => "Comma",
token::Semi => "Semi",
token::Colon => "Colon",
token::ModSep => "ModSep",
token::RArrow => "RArrow",
token::LArrow => "LArrow",
token::FatArrow => "FatArrow",
token::Pound => "Pound",
token::Dollar => "Dollar",
token::Question => "Question",
token::Underscore => "Underscore",
token::Eof => "Eof",
_ => {
::std::rt::begin_unwind("unhandled token in quote!",
{
static _FILE_LINE:
(&'static str, u32)
=
("src/ext/quote.rs",
695u32);
&_FILE_LINE
})
}
};
mk_token_path(cx, sp, name)
}
fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool)
-> Vec<P<ast::Stmt>> {
match *tt {
TokenTree::Token(sp, SubstNt(ident, _)) => {
let e_to_toks =
cx.expr_method_call(sp, cx.expr_ident(sp, ident),
id_ext("to_tokens"),
<[_]>::into_vec(::std::boxed::Box::new([cx.expr_ident(sp,
id_ext("ext_cx"))])));
let e_to_toks =
cx.expr_method_call(sp, e_to_toks,
id_ext("into_iter"),
<[_]>::into_vec(::std::boxed::Box::new([])));
let e_push =
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext("tt")),
id_ext("extend"),
<[_]>::into_vec(::std::boxed::Box::new([e_to_toks])));
<[_]>::into_vec(::std::boxed::Box::new([cx.stmt_expr(e_push)]))
}
ref tt@TokenTree::Token(_, MatchNt(..)) if !matcher => {
let mut seq = <[_]>::into_vec(::std::boxed::Box::new([]));
for i in 0..tt.len() { seq.push(tt.get_tt(i)); }
statements_mk_tts(cx, &seq[..], matcher)
}
TokenTree::Token(sp, ref tok) => {
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
let e_tok =
cx.expr_call(sp, mk_tt_path(cx, sp, "Token"),
<[_]>::into_vec(::std::boxed::Box::new([e_sp,
expr_mk_token(cx,
sp,
tok)])));
let e_push =
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext("tt")),
id_ext("push"),
<[_]>::into_vec(::std::boxed::Box::new([e_tok])));
<[_]>::into_vec(::std::boxed::Box::new([cx.stmt_expr(e_push)]))
}
TokenTree::Delimited(_, ref delimed) => {
statements_mk_tt(cx, &delimed.open_tt(),
matcher).into_iter().chain(delimed.tts.iter().flat_map(|tt|
statements_mk_tt(cx,
tt,
matcher))).chain(statements_mk_tt(cx,
&delimed.close_tt(),
matcher)).collect()
}
TokenTree::Sequence(sp, ref seq) => {
if !matcher {
{
::std::rt::begin_unwind("TokenTree::Sequence in quote!",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
749u32);
&_FILE_LINE
})
};
}
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
let stmt_let_tt =
cx.stmt_let(sp, true, id_ext("tt"),
cx.expr_vec_ng(sp));
let mut tts_stmts =
<[_]>::into_vec(::std::boxed::Box::new([stmt_let_tt]));
tts_stmts.extend(statements_mk_tts(cx, &seq.tts[..],
matcher));
let e_tts =
cx.expr_block(cx.block(sp, tts_stmts,
Some(cx.expr_ident(sp,
id_ext("tt")))));
let e_separator =
match seq.separator {
Some(ref sep) =>
cx.expr_some(sp, expr_mk_token(cx, sp, sep)),
None => cx.expr_none(sp),
};
let e_op =
match seq.op {
ast::ZeroOrMore =>
mk_ast_path(cx, sp, "ZeroOrMore"),
ast::OneOrMore =>
mk_ast_path(cx, sp, "OneOrMore"),
};
let fields =
<[_]>::into_vec(::std::boxed::Box::new([cx.field_imm(sp,
id_ext("tts"),
e_tts),
cx.field_imm(sp,
id_ext("separator"),
e_separator),
cx.field_imm(sp,
id_ext("op"),
e_op),
cx.field_imm(sp,
id_ext("num_captures"),
cx.expr_usize(sp,
seq.num_captures))]));
let seq_path =
<[_]>::into_vec(::std::boxed::Box::new([id_ext("syntax"),
id_ext("ast"),
id_ext("SequenceRepetition")]));
let e_seq_struct =
cx.expr_struct(sp, cx.path_global(sp, seq_path),
fields);
let e_rc_new =
cx.expr_call_global(sp,
<[_]>::into_vec(::std::boxed::Box::new([id_ext("std"),
id_ext("rc"),
id_ext("Rc"),
id_ext("new")])),
<[_]>::into_vec(::std::boxed::Box::new([e_seq_struct])));
let e_tok =
cx.expr_call(sp, mk_tt_path(cx, sp, "Sequence"),
<[_]>::into_vec(::std::boxed::Box::new([e_sp,
e_rc_new])));
let e_push =
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext("tt")),
id_ext("push"),
<[_]>::into_vec(::std::boxed::Box::new([e_tok])));
<[_]>::into_vec(::std::boxed::Box::new([cx.stmt_expr(e_push)]))
}
}
}
fn parse_arguments_to_quote(cx: &ExtCtxt, tts: &[TokenTree])
-> (P<ast::Expr>, Vec<TokenTree>) {
let mut p = cx.new_parser_from_tts(tts);
p.quote_depth += 1;
let cx_expr =
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
803u32);
&_FILE_LINE
})
};
}
}
};
if !p.eat(&token::Comma) {
let _ = p.diagnostic().fatal("expected token `,`");
}
let tts =
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_all_token_trees() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/quote.rs",
808u32);
&_FILE_LINE
})
};
}
}
};
p.abort_if_errors();
(cx_expr, tts)
}
fn mk_stmts_let(cx: &ExtCtxt, sp: Span) -> Vec<P<ast::Stmt>> {
let e_sp =
cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("ext_cx")),
id_ext("call_site"), Vec::new());
let stmt_let_sp = cx.stmt_let(sp, false, id_ext("_sp"), e_sp);
let stmt_let_tt =
cx.stmt_let(sp, true, id_ext("tt"), cx.expr_vec_ng(sp));
<[_]>::into_vec(::std::boxed::Box::new([stmt_let_sp,
stmt_let_tt]))
}
fn statements_mk_tts(cx: &ExtCtxt, tts: &[TokenTree], matcher: bool)
-> Vec<P<ast::Stmt>> {
let mut ss = Vec::new();
for tt in tts { ss.extend(statements_mk_tt(cx, tt, matcher)); }
ss
}
fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[TokenTree])
-> (P<ast::Expr>, P<ast::Expr>) {
let (cx_expr, tts) = parse_arguments_to_quote(cx, tts);
let mut vector = mk_stmts_let(cx, sp);
vector.extend(statements_mk_tts(cx, &tts[..], false));
let block =
cx.expr_block(cx.block_all(sp, vector,
Some(cx.expr_ident(sp,
id_ext("tt")))));
(cx_expr, block)
}
fn expand_wrapper(cx: &ExtCtxt, sp: Span, cx_expr: P<ast::Expr>,
expr: P<ast::Expr>, imports: &[&[&str]])
-> P<ast::Expr> {
let cx_expr_borrow =
cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr));
let stmt_let_ext_cx =
cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow);
let stmts =
imports.iter().map(|path| {
let path =
path.iter().map(|s|
s.to_string()).collect();
cx.stmt_item(sp,
cx.item_use_glob(sp,
ast::Inherited,
ids_ext(path)))
}).chain(Some(stmt_let_ext_cx)).collect();
cx.expr_block(cx.block_all(sp, stmts, Some(expr)))
}
fn expand_parse_call(cx: &ExtCtxt, sp: Span, parse_method: &str,
arg_exprs: Vec<P<ast::Expr>>, tts: &[TokenTree])
-> P<ast::Expr> {
let (cx_expr, tts_expr) = expand_tts(cx, sp, tts);
let cfg_call =
||
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext("ext_cx")),
id_ext("cfg"), Vec::new());
let parse_sess_call =
||
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext("ext_cx")),
id_ext("parse_sess"), Vec::new());
let new_parser_call =
cx.expr_call(sp,
cx.expr_ident(sp, id_ext("new_parser_from_tts")),
<[_]>::into_vec(::std::boxed::Box::new([parse_sess_call(),
cfg_call(),
tts_expr])));
let path =
<[_]>::into_vec(::std::boxed::Box::new([id_ext("syntax"),
id_ext("ext"),
id_ext("quote"),
id_ext(parse_method)]));
let mut args =
<[_]>::into_vec(::std::boxed::Box::new([cx.expr_mut_addr_of(sp,
new_parser_call)]));
args.extend(arg_exprs);
let expr = cx.expr_call_global(sp, path, args);
if parse_method == "parse_attribute" {
expand_wrapper(cx, sp, cx_expr, expr,
&[&["syntax", "ext", "quote", "rt"],
&["syntax", "parse", "attr"]])
} else {
expand_wrapper(cx, sp, cx_expr, expr,
&[&["syntax", "ext", "quote", "rt"]])
}
}
}
pub mod source_util {
#[prelude_import]
use std::prelude::v1::*;
use ast;
use codemap::{Pos, Span};
use codemap;
use ext::base::*;
use ext::base;
use ext::build::AstBuilder;
use parse::token;
use parse;
use print::pprust;
use ptr::P;
use util::small_vector::SmallVector;
use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::rc::Rc;
/// line!(): expands to the current line number
pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
base::check_zero_tts(cx, sp, tts, "line!");
let topmost = cx.expansion_cause();
let loc = cx.codemap().lookup_char_pos(topmost.lo);
base::MacEager::expr(cx.expr_u32(topmost, loc.line as u32))
}
pub fn expand_column(cx: &mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
base::check_zero_tts(cx, sp, tts, "column!");
let topmost = cx.expansion_cause();
let loc = cx.codemap().lookup_char_pos(topmost.lo);
base::MacEager::expr(cx.expr_u32(topmost,
loc.col.to_usize() as u32))
}
/// file!(): expands to the current filename */
/// The filemap (`loc.file`) contains a bunch more information we could spit
/// out if we wanted.
pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
base::check_zero_tts(cx, sp, tts, "file!");
let topmost = cx.expansion_cause();
let loc = cx.codemap().lookup_char_pos(topmost.lo);
let filename = token::intern_and_get_ident(&loc.file.name);
base::MacEager::expr(cx.expr_str(topmost, filename))
}
pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
let s = pprust::tts_to_string(tts);
base::MacEager::expr(cx.expr_str(sp,
token::intern_and_get_ident(&s[..])))
}
pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
base::check_zero_tts(cx, sp, tts, "module_path!");
let string =
cx.mod_path().iter().map(|x|
x.to_string()).collect::<Vec<String>>().join("::");
base::MacEager::expr(cx.expr_str(sp,
token::intern_and_get_ident(&string[..])))
}
/// include! : parse the given file as an expr
/// This is generally a bad idea because it's going to behave
/// unhygienically.
pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'cx> {
let file =
match get_single_str_from_tts(cx, sp, tts, "include!") {
Some(f) => f,
None => return DummyResult::expr(sp),
};
let p =
parse::new_sub_parser_from_file(cx.parse_sess(), cx.cfg(),
&res_rel_file(cx, sp,
Path::new(&file)),
true, None, sp);
struct ExpandResult<'a> {
p: parse::parser::Parser<'a>,
}
impl <'a> base::MacResult for ExpandResult<'a> {
fn make_expr(mut self: Box<ExpandResult<'a>>)
-> Option<P<ast::Expr>> {
Some({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match self.p.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/source_util.rs",
112u32);
&_FILE_LINE
})
};
}
}
})
}
fn make_items(mut self: Box<ExpandResult<'a>>)
-> Option<SmallVector<P<ast::Item>>> {
let mut ret = SmallVector::zero();
while self.p.token != token::Eof {
match {
use std::result::Result::{Ok, Err};
use errors::FatalError;
match self.p.parse_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/source_util.rs",
118u32);
&_FILE_LINE
})
};
}
}
} {
Some(item) => ret.push(item),
None => {
::std::rt::begin_unwind(self.p.diagnostic().span_fatal(self.p.span,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected item, found `",
"`"];
__STATIC_FMTSTR
},
&match (&self.p.this_token_to_string(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/source_util.rs",
120u32);
&_FILE_LINE
})
}
}
}
Some(ret)
}
}
Box::new(ExpandResult{p: p,})
}
pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
let file =
match get_single_str_from_tts(cx, sp, tts, "include_str!") {
Some(f) => f,
None => return DummyResult::expr(sp),
};
let file = res_rel_file(cx, sp, Path::new(&file));
let mut bytes = Vec::new();
match File::open(&file).and_then(|mut f|
f.read_to_end(&mut bytes)) {
Ok(..) => { }
Err(e) => {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["couldn\'t read ",
": "];
__STATIC_FMTSTR
},
&match (&file.display(),
&e)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
return DummyResult::expr(sp);
}
};
match String::from_utf8(bytes) {
Ok(src) => {
let filename =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&file.display(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
let interned = token::intern_and_get_ident(&src[..]);
cx.codemap().new_filemap_and_lines(&filename, &src);
base::MacEager::expr(cx.expr_str(sp, interned))
}
Err(_) => {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" wasn\'t a utf-8 file"];
__STATIC_FMTSTR
},
&match (&file.display(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
return DummyResult::expr(sp);
}
}
}
pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+ 'static> {
let file =
match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
Some(f) => f,
None => return DummyResult::expr(sp),
};
let file = res_rel_file(cx, sp, Path::new(&file));
let mut bytes = Vec::new();
match File::open(&file).and_then(|mut f|
f.read_to_end(&mut bytes)) {
Err(e) => {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["couldn\'t read ",
": "];
__STATIC_FMTSTR
},
&match (&file.display(),
&e)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})));
return DummyResult::expr(sp);
}
Ok(..) => {
let filename =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&[""];
__STATIC_FMTSTR
},
&match (&file.display(),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
cx.codemap().new_filemap_and_lines(&filename, "");
base::MacEager::expr(cx.expr_lit(sp,
ast::LitByteStr(Rc::new(bytes))))
}
}
}
fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path)
-> PathBuf {
if !arg.is_absolute() {
let mut cu =
PathBuf::from(&cx.codemap().span_to_filename(sp));
cu.pop();
cu.push(arg);
cu
} else { arg.to_path_buf() }
}
}
pub mod tt {
#[prelude_import]
use std::prelude::v1::*;
pub mod transcribe {
#[prelude_import]
use std::prelude::v1::*;
use self::LockstepIterSize::*;
use ast;
use ast::{TokenTree, Ident, Name};
use codemap::{Span, DUMMY_SP};
use errors::Handler;
use ext::tt::macro_parser::{NamedMatch, MatchedSeq,
MatchedNonterminal};
use parse::token::{DocComment, MatchNt, SubstNt};
use parse::token::{Token, NtIdent, SpecialMacroVar};
use parse::token;
use parse::lexer::TokenAndSpan;
use std::rc::Rc;
use std::ops::Add;
use std::collections::HashMap;
///an unzipping of `TokenTree`s
struct TtFrame {
forest: TokenTree,
idx: usize,
dotdotdoted: bool,
sep: Option<Token>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TtFrame {
#[inline]
fn clone(&self) -> TtFrame {
match *self {
TtFrame {
forest: ref __self_0_0,
idx: ref __self_0_1,
dotdotdoted: ref __self_0_2,
sep: ref __self_0_3 } =>
TtFrame{forest:
::std::clone::Clone::clone(&(*__self_0_0)),
idx:
::std::clone::Clone::clone(&(*__self_0_1)),
dotdotdoted:
::std::clone::Clone::clone(&(*__self_0_2)),
sep:
::std::clone::Clone::clone(&(*__self_0_3)),},
}
}
}
pub struct TtReader<'a> {
pub sp_diag: &'a Handler,
/// the unzipped tree:
stack: Vec<TtFrame>,
interpolations: HashMap<Name, Rc<NamedMatch>>,
imported_from: Option<Ident>,
crate_name_next: Option<Span>,
repeat_idx: Vec<usize>,
repeat_len: Vec<usize>,
pub cur_tok: Token,
pub cur_span: Span,
/// Transform doc comments. Only useful in macro invocations
pub desugar_doc_comments: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl <'a> ::std::clone::Clone for TtReader<'a> {
#[inline]
fn clone(&self) -> TtReader<'a> {
match *self {
TtReader {
sp_diag: ref __self_0_0,
stack: ref __self_0_1,
interpolations: ref __self_0_2,
imported_from: ref __self_0_3,
crate_name_next: ref __self_0_4,
repeat_idx: ref __self_0_5,
repeat_len: ref __self_0_6,
cur_tok: ref __self_0_7,
cur_span: ref __self_0_8,
desugar_doc_comments: ref __self_0_9 } =>
TtReader{sp_diag:
::std::clone::Clone::clone(&(*__self_0_0)),
stack:
::std::clone::Clone::clone(&(*__self_0_1)),
interpolations:
::std::clone::Clone::clone(&(*__self_0_2)),
imported_from:
::std::clone::Clone::clone(&(*__self_0_3)),
crate_name_next:
::std::clone::Clone::clone(&(*__self_0_4)),
repeat_idx:
::std::clone::Clone::clone(&(*__self_0_5)),
repeat_len:
::std::clone::Clone::clone(&(*__self_0_6)),
cur_tok:
::std::clone::Clone::clone(&(*__self_0_7)),
cur_span:
::std::clone::Clone::clone(&(*__self_0_8)),
desugar_doc_comments:
::std::clone::Clone::clone(&(*__self_0_9)),},
}
}
}
/// This can do Macro-By-Example transcription. On the other hand, if
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
/// (and should) be None.
pub fn new_tt_reader<'a>(sp_diag: &'a Handler,
interp:
Option<HashMap<Name,
Rc<NamedMatch>>>,
imported_from: Option<Ident>,
src: Vec<ast::TokenTree>)
-> TtReader<'a> {
new_tt_reader_with_doc_flag(sp_diag, interp, imported_from,
src, false)
}
/// The extra `desugar_doc_comments` flag enables reading doc comments
/// like any other attribute which consists of `meta` and surrounding #[ ] tokens.
///
/// This can do Macro-By-Example transcription. On the other hand, if
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
/// (and should) be None.
pub fn new_tt_reader_with_doc_flag<'a>(sp_diag: &'a Handler,
interp:
Option<HashMap<Name,
Rc<NamedMatch>>>,
imported_from:
Option<Ident>,
src: Vec<ast::TokenTree>,
desugar_doc_comments: bool)
-> TtReader<'a> {
let mut r =
TtReader{sp_diag: sp_diag,
stack:
<[_]>::into_vec(::std::boxed::Box::new([TtFrame{forest:
TokenTree::Sequence(DUMMY_SP,
Rc::new(ast::SequenceRepetition{tts:
src,
separator:
None,
op:
ast::ZeroOrMore,
num_captures:
0,})),
idx:
0,
dotdotdoted:
false,
sep:
None,}])),
interpolations:
match interp {
None => HashMap::new(),
Some(x) => x,
},
imported_from: imported_from,
crate_name_next: None,
repeat_idx: Vec::new(),
repeat_len: Vec::new(),
desugar_doc_comments: desugar_doc_comments,
cur_tok: token::Eof,
cur_span: DUMMY_SP,};
tt_next_token(&mut r);
r
}
fn lookup_cur_matched_by_matched(r: &TtReader,
start: Rc<NamedMatch>)
-> Rc<NamedMatch> {
r.repeat_idx.iter().fold(start, |ad, idx| {
match *ad {
MatchedNonterminal(_) => {
ad.clone()
}
MatchedSeq(ref ads, _) =>
ads[*idx].clone(),
} })
}
fn lookup_cur_matched(r: &TtReader, name: Ident)
-> Option<Rc<NamedMatch>> {
let matched_opt = r.interpolations.get(&name.name).cloned();
matched_opt.map(|s| lookup_cur_matched_by_matched(r, s))
}
enum LockstepIterSize {
LisUnconstrained,
LisConstraint(usize, Ident),
LisContradiction(String),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for LockstepIterSize {
#[inline]
fn clone(&self) -> LockstepIterSize {
match (&*self,) {
(&LockstepIterSize::LisUnconstrained,) =>
LockstepIterSize::LisUnconstrained,
(&LockstepIterSize::LisConstraint(ref __self_0,
ref __self_1),) =>
LockstepIterSize::LisConstraint(::std::clone::Clone::clone(&(*__self_0)),
::std::clone::Clone::clone(&(*__self_1))),
(&LockstepIterSize::LisContradiction(ref __self_0),)
=>
LockstepIterSize::LisContradiction(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl Add for LockstepIterSize {
type
Output
=
LockstepIterSize;
fn add(self, other: LockstepIterSize) -> LockstepIterSize {
match self {
LisUnconstrained => other,
LisContradiction(_) => self,
LisConstraint(l_len, ref l_id) =>
match other {
LisUnconstrained => self.clone(),
LisContradiction(_) => other,
LisConstraint(r_len, _) if l_len == r_len =>
self.clone(),
LisConstraint(r_len, r_id) => {
LisContradiction(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["inconsistent lockstep iteration: \'",
"\' has ",
" items, but \'",
"\' has "];
__STATIC_FMTSTR
},
&match (&l_id,
&l_len,
&r_id,
&r_len)
{
(__arg0,
__arg1,
__arg2,
__arg3)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg3,
::std::fmt::Display::fmt)],
})))
}
},
}
}
}
fn lockstep_iter_size(t: &TokenTree, r: &TtReader)
-> LockstepIterSize {
match *t {
TokenTree::Delimited(_, ref delimed) => {
delimed.tts.iter().fold(LisUnconstrained, |size, tt| {
size +
lockstep_iter_size(tt, r)
})
}
TokenTree::Sequence(_, ref seq) => {
seq.tts.iter().fold(LisUnconstrained, |size, tt| {
size + lockstep_iter_size(tt, r)
})
}
TokenTree::Token(_, SubstNt(name, _)) |
TokenTree::Token(_, MatchNt(name, _, _, _)) =>
match lookup_cur_matched(r, name) {
Some(matched) =>
match *matched {
MatchedNonterminal(_) => LisUnconstrained,
MatchedSeq(ref ads, _) =>
LisConstraint(ads.len(), name),
},
_ => LisUnconstrained,
},
TokenTree::Token(..) => LisUnconstrained,
}
}
/// Return the next token from the TtReader.
/// EFFECT: advances the reader's token field
pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
let ret_val =
TokenAndSpan{tok: r.cur_tok.clone(),
sp: r.cur_span.clone(),};
loop {
match r.crate_name_next.take() {
None => (),
Some(sp) => {
r.cur_span = sp;
r.cur_tok =
token::Ident(r.imported_from.unwrap(),
token::Plain);
return ret_val;
}
}
let should_pop =
match r.stack.last() {
None => {
{
match (&(ret_val.tok), &(token::Eof)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_unwind_fmt(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["assertion failed: `(left == right)` (left: `",
"`, right: `",
"`)"];
__STATIC_FMTSTR
},
&match (&left_val,
&right_val)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Debug::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Debug::fmt)],
}),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/transcribe.rs",
195u32);
&_FILE_LINE
})
}
}
}
}
};
return ret_val;
}
Some(frame) => {
if frame.idx < frame.forest.len() { break ; }
!frame.dotdotdoted ||
*r.repeat_idx.last().unwrap() ==
*r.repeat_len.last().unwrap() - 1
}
};
if should_pop {
let prev = r.stack.pop().unwrap();
match r.stack.last_mut() {
None => {
r.cur_tok = token::Eof;
return ret_val;
}
Some(frame) => { frame.idx += 1; }
}
if prev.dotdotdoted {
r.repeat_idx.pop();
r.repeat_len.pop();
}
} else {
*r.repeat_idx.last_mut().unwrap() += 1;
r.stack.last_mut().unwrap().idx = 0;
match r.stack.last().unwrap().sep.clone() {
Some(tk) => { r.cur_tok = tk; return ret_val; }
None => { }
}
}
}
loop {
let t =
{
let frame = r.stack.last().unwrap();
frame.forest.get_tt(frame.idx)
};
match t {
TokenTree::Sequence(sp, seq) => {
match lockstep_iter_size(&TokenTree::Sequence(sp,
seq.clone()),
r) {
LisUnconstrained => {
{
::std::rt::begin_unwind(r.sp_diag.span_fatal(sp.clone(),
"attempted to repeat an expression containing no syntax variables matched as repeating at this depth"),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/transcribe.rs",
248u32);
&_FILE_LINE
})
};
}
LisContradiction(ref msg) => {
{
::std::rt::begin_unwind(r.sp_diag.span_fatal(sp.clone(),
&msg[..]),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/transcribe.rs",
256u32);
&_FILE_LINE
})
};
}
LisConstraint(len, _) => {
if len == 0 {
if seq.op == ast::OneOrMore {
{
::std::rt::begin_unwind(r.sp_diag.span_fatal(sp.clone(),
"this must repeat at least once"),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/transcribe.rs",
262u32);
&_FILE_LINE
})
};
}
r.stack.last_mut().unwrap().idx += 1;
return tt_next_token(r);
}
r.repeat_len.push(len);
r.repeat_idx.push(0);
r.stack.push(TtFrame{idx: 0,
dotdotdoted: true,
sep:
seq.separator.clone(),
forest:
TokenTree::Sequence(sp,
seq),});
}
}
}
TokenTree::Token(sp, SubstNt(ident, namep)) => {
r.stack.last_mut().unwrap().idx += 1;
match lookup_cur_matched(r, ident) {
None => {
r.cur_span = sp;
r.cur_tok = SubstNt(ident, namep);
return ret_val;
}
Some(cur_matched) => {
match *cur_matched {
MatchedNonterminal(NtIdent(ref sn, b))
=> {
r.cur_span = sn.span;
r.cur_tok =
token::Ident(sn.node, b);
return ret_val;
}
MatchedNonterminal(ref other_whole_nt)
=> {
r.cur_span = sp;
r.cur_tok =
token::Interpolated((*other_whole_nt).clone());
return ret_val;
}
MatchedSeq(..) => {
{
::std::rt::begin_unwind(r.sp_diag.span_fatal(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["variable \'",
"\' is still repeating at this depth"];
__STATIC_FMTSTR
},
&match (&ident,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))),
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/transcribe.rs",
307u32);
&_FILE_LINE
})
};
}
}
}
}
}
seq@TokenTree::Delimited(..) |
seq@TokenTree::Token(_, MatchNt(..)) => {
r.stack.push(TtFrame{forest: seq,
idx: 0,
dotdotdoted: false,
sep: None,});
}
TokenTree::Token(sp, DocComment(name)) if
r.desugar_doc_comments => {
r.stack.push(TtFrame{forest:
TokenTree::Token(sp,
DocComment(name)),
idx: 0,
dotdotdoted: false,
sep: None,});
}
TokenTree::Token(sp,
token::SpecialVarNt(SpecialMacroVar::CrateMacroVar))
=> {
r.stack.last_mut().unwrap().idx += 1;
if r.imported_from.is_some() {
r.cur_span = sp;
r.cur_tok = token::ModSep;
r.crate_name_next = Some(sp);
return ret_val;
}
}
TokenTree::Token(sp, tok) => {
r.cur_span = sp;
r.cur_tok = tok;
r.stack.last_mut().unwrap().idx += 1;
return ret_val;
}
}
}
}
}
pub mod macro_parser {
//! This is an Earley-like parser, without support for in-grammar nonterminals,
//! only by calling out to the main rust parser for named nonterminals (which it
//! commits to fully when it hits one in a grammar). This means that there are no
//! completer or predictor rules, and therefore no need to store one column per
//! token: instead, there's a set of current Earley items and a set of next
//! ones. Instead of NTs, we have a special case for Kleene star. The big-O, in
//! pathological cases, is worse than traditional Earley parsing, but it's an
//! easier fit for Macro-by-Example-style rules, and I think the overhead is
//! lower. (In order to prevent the pathological case, we'd need to lazily
//! construct the resulting `NamedMatch`es at the very end. It'd be a pain,
//! and require more memory to keep around old items, but it would also save
//! overhead)
//!
//! Quick intro to how the parser works:
//!
//! A 'position' is a dot in the middle of a matcher, usually represented as a
//! dot. For example `· a $( a )* a b` is a position, as is `a $( · a )* a b`.
//!
//! The parser walks through the input a character at a time, maintaining a list
//! of items consistent with the current position in the input string: `cur_eis`.
//!
//! As it processes them, it fills up `eof_eis` with items that would be valid if
//! the macro invocation is now over, `bb_eis` with items that are waiting on
//! a Rust nonterminal like `$e:expr`, and `next_eis` with items that are waiting
//! on a particular token. Most of the logic concerns moving the · through the
//! repetitions indicated by Kleene stars. It only advances or calls out to the
//! real Rust parser when no `cur_eis` items remain
//!
//! Example: Start parsing `a a a a b` against [· a $( a )* a b].
//!
//! Remaining input: `a a a a b`
//! next_eis: [· a $( a )* a b]
//!
//! - - - Advance over an `a`. - - -
//!
//! Remaining input: `a a a b`
//! cur: [a · $( a )* a b]
//! Descend/Skip (first item).
//! next: [a $( · a )* a b] [a $( a )* · a b].
//!
//! - - - Advance over an `a`. - - -
//!
//! Remaining input: `a a b`
//! cur: [a $( a · )* a b] next: [a $( a )* a · b]
//! Finish/Repeat (first item)
//! next: [a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b]
//!
//! - - - Advance over an `a`. - - - (this looks exactly like the last step)
//!
//! Remaining input: `a b`
//! cur: [a $( a · )* a b] next: [a $( a )* a · b]
//! Finish/Repeat (first item)
//! next: [a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b]
//!
//! - - - Advance over an `a`. - - - (this looks exactly like the last step)
//!
//! Remaining input: `b`
//! cur: [a $( a · )* a b] next: [a $( a )* a · b]
//! Finish/Repeat (first item)
//! next: [a $( a )* · a b] [a $( · a )* a b]
//!
//! - - - Advance over a `b`. - - -
//!
//! Remaining input: ``
//! eof: [a $( a )* a b ·]
#[prelude_import]
use std::prelude::v1::*;
pub use self::NamedMatch::*;
pub use self::ParseResult::*;
use self::TokenTreeOrTokenTreeVec::*;
use ast;
use ast::{TokenTree, Name, Ident};
use codemap::{BytePos, mk_sp, Span, Spanned};
use codemap;
use errors::FatalError;
use parse::lexer::*;
use parse::ParseSess;
use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
use parse::token::{DocComment, MatchNt, SubstNt};
use parse::token::{Token, Nonterminal};
use parse::token;
use print::pprust;
use ptr::P;
use std::mem;
use std::rc::Rc;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Vacant, Occupied};
enum TokenTreeOrTokenTreeVec {
Tt(ast::TokenTree),
TtSeq(Rc<Vec<ast::TokenTree>>),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for TokenTreeOrTokenTreeVec {
#[inline]
fn clone(&self) -> TokenTreeOrTokenTreeVec {
match (&*self,) {
(&TokenTreeOrTokenTreeVec::Tt(ref __self_0),) =>
TokenTreeOrTokenTreeVec::Tt(::std::clone::Clone::clone(&(*__self_0))),
(&TokenTreeOrTokenTreeVec::TtSeq(ref __self_0),) =>
TokenTreeOrTokenTreeVec::TtSeq(::std::clone::Clone::clone(&(*__self_0))),
}
}
}
impl TokenTreeOrTokenTreeVec {
fn len(&self) -> usize {
match *self {
TtSeq(ref v) => v.len(),
Tt(ref tt) => tt.len(),
}
}
fn get_tt(&self, index: usize) -> TokenTree {
match *self {
TtSeq(ref v) => v[index].clone(),
Tt(ref tt) => tt.get_tt(index),
}
}
}
/// an unzipping of `TokenTree`s
struct MatcherTtFrame {
elts: TokenTreeOrTokenTreeVec,
idx: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MatcherTtFrame {
#[inline]
fn clone(&self) -> MatcherTtFrame {
match *self {
MatcherTtFrame {
elts: ref __self_0_0, idx: ref __self_0_1 } =>
MatcherTtFrame{elts:
::std::clone::Clone::clone(&(*__self_0_0)),
idx:
::std::clone::Clone::clone(&(*__self_0_1)),},
}
}
}
pub struct MatcherPos {
stack: Vec<MatcherTtFrame>,
top_elts: TokenTreeOrTokenTreeVec,
sep: Option<Token>,
idx: usize,
up: Option<Box<MatcherPos>>,
matches: Vec<Vec<Rc<NamedMatch>>>,
match_lo: usize,
match_cur: usize,
match_hi: usize,
sp_lo: BytePos,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::clone::Clone for MatcherPos {
#[inline]
fn clone(&self) -> MatcherPos {
match *self {
MatcherPos {
stack: ref __self_0_0,
top_elts: ref __self_0_1,
sep: ref __self_0_2,
idx: ref __self_0_3,
up: ref __self_0_4,
matches: ref __self_0_5,
match_lo: ref __self_0_6,
match_cur: ref __self_0_7,
match_hi: ref __self_0_8,
sp_lo: ref __self_0_9 } =>
MatcherPos{stack:
::std::clone::Clone::clone(&(*__self_0_0)),
top_elts:
::std::clone::Clone::clone(&(*__self_0_1)),
sep:
::std::clone::Clone::clone(&(*__self_0_2)),
idx:
::std::clone::Clone::clone(&(*__self_0_3)),
up:
::std::clone::Clone::clone(&(*__self_0_4)),
matches:
::std::clone::Clone::clone(&(*__self_0_5)),
match_lo:
::std::clone::Clone::clone(&(*__self_0_6)),
match_cur:
::std::clone::Clone::clone(&(*__self_0_7)),
match_hi:
::std::clone::Clone::clone(&(*__self_0_8)),
sp_lo:
::std::clone::Clone::clone(&(*__self_0_9)),},
}
}
}
pub fn count_names(ms: &[TokenTree]) -> usize {
ms.iter().fold(0, |count, elt| {
count +
match *elt {
TokenTree::Sequence(_, ref seq) => {
seq.num_captures
}
TokenTree::Delimited(_, ref delim) => {
count_names(&delim.tts)
}
TokenTree::Token(_, MatchNt(..)) => {
1
}
TokenTree::Token(_, _) => 0,
} })
}
pub fn initial_matcher_pos(ms: Rc<Vec<TokenTree>>,
sep: Option<Token>, lo: BytePos)
-> Box<MatcherPos> {
let match_idx_hi = count_names(&ms[..]);
let matches: Vec<_> =
(0..match_idx_hi).map(|_| Vec::new()).collect();
Box::new(MatcherPos{stack:
<[_]>::into_vec(::std::boxed::Box::new([])),
top_elts: TtSeq(ms),
sep: sep,
idx: 0,
up: None,
matches: matches,
match_lo: 0,
match_cur: 0,
match_hi: match_idx_hi,
sp_lo: lo,})
}
/// NamedMatch is a pattern-match result for a single token::MATCH_NONTERMINAL:
/// so it is associated with a single ident in a parse, and all
/// `MatchedNonterminal`s in the NamedMatch have the same nonterminal type
/// (expr, item, etc). Each leaf in a single NamedMatch corresponds to a
/// single token::MATCH_NONTERMINAL in the TokenTree that produced it.
///
/// The in-memory structure of a particular NamedMatch represents the match
/// that occurred when a particular subset of a matcher was applied to a
/// particular token tree.
///
/// The width of each MatchedSeq in the NamedMatch, and the identity of the
/// `MatchedNonterminal`s, will depend on the token tree it was applied to:
/// each MatchedSeq corresponds to a single TTSeq in the originating
/// token tree. The depth of the NamedMatch structure will therefore depend
/// only on the nesting depth of `ast::TTSeq`s in the originating
/// token tree it was derived from.
pub enum NamedMatch {
MatchedSeq(Vec<Rc<NamedMatch>>, codemap::Span),
MatchedNonterminal(Nonterminal),
}
pub fn nameize(p_s: &ParseSess, ms: &[TokenTree],
res: &[Rc<NamedMatch>])
-> ParseResult<HashMap<Name, Rc<NamedMatch>>> {
fn n_rec(p_s: &ParseSess, m: &TokenTree,
res: &[Rc<NamedMatch>],
ret_val: &mut HashMap<Name, Rc<NamedMatch>>,
idx: &mut usize)
-> Result<(), (codemap::Span, String)> {
match *m {
TokenTree::Sequence(_, ref seq) => {
for next_m in &seq.tts {
match n_rec(p_s, next_m, res, ret_val, idx) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
}
}
}
TokenTree::Delimited(_, ref delim) => {
for next_m in &delim.tts {
match n_rec(p_s, next_m, res, ret_val, idx) {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
return ::std::result::Result::Err(::std::convert::From::from(err))
}
};
}
}
TokenTree::Token(sp, MatchNt(bind_name, _, _, _)) => {
match ret_val.entry(bind_name.name) {
Vacant(spot) => {
spot.insert(res[*idx].clone());
*idx += 1;
}
Occupied(..) => {
return Err((sp,
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["duplicated bind name: "];
__STATIC_FMTSTR
},
&match (&bind_name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))))
}
}
}
TokenTree::Token(sp, SubstNt(..)) => {
return Err((sp,
"missing fragment specifier".to_string()))
}
TokenTree::Token(_, _) => (),
}
Ok(())
}
let mut ret_val = HashMap::new();
let mut idx = 0;
for m in ms {
match n_rec(p_s, m, res, &mut ret_val, &mut idx) {
Ok(_) => { }
Err((sp, msg)) => return Error(sp, msg),
}
}
Success(ret_val)
}
pub enum ParseResult<T> {
Success(T),
/// Arm failed to match
Failure(codemap::Span, String),
/// Fatal error (malformed macro?). Abort compilation.
Error(codemap::Span, String),
}
pub type NamedParseResult =
ParseResult<HashMap<Name, Rc<NamedMatch>>>;
pub type PositionalParseResult = ParseResult<Vec<Rc<NamedMatch>>>;
/// Perform a token equality check, ignoring syntax context (that is, an
/// unhygienic comparison)
pub fn token_name_eq(t1: &Token, t2: &Token) -> bool {
match (t1, t2) {
(&token::Ident(id1, _), &token::Ident(id2, _)) |
(&token::Lifetime(id1), &token::Lifetime(id2)) =>
id1.name == id2.name,
_ => *t1 == *t2,
}
}
pub fn parse(sess: &ParseSess, cfg: ast::CrateConfig,
mut rdr: TtReader, ms: &[TokenTree])
-> NamedParseResult {
let mut cur_eis = Vec::new();
cur_eis.push(initial_matcher_pos(Rc::new(ms.iter().cloned().collect()),
None, rdr.peek().sp.lo));
loop {
let mut bb_eis = Vec::new();
let mut next_eis = Vec::new();
let mut eof_eis = Vec::new();
let TokenAndSpan { tok, sp } = rdr.peek();
loop {
let mut ei =
match cur_eis.pop() {
None => break ,
Some(ei) => ei,
};
while ei.idx >= ei.top_elts.len() {
match ei.stack.pop() {
Some(MatcherTtFrame { elts, idx }) => {
ei.top_elts = elts;
ei.idx = idx + 1;
}
None => break ,
}
}
let idx = ei.idx;
let len = ei.top_elts.len();
if idx >= len {
if ei.up.is_some() {
if idx == len {
let mut new_pos = ei.up.clone().unwrap();
for idx in ei.match_lo..ei.match_hi {
let sub = (ei.matches[idx]).clone();
(&mut new_pos.matches[idx]).push(Rc::new(MatchedSeq(sub,
mk_sp(ei.sp_lo,
sp.hi))));
}
new_pos.match_cur = ei.match_hi;
new_pos.idx += 1;
cur_eis.push(new_pos);
}
match ei.sep {
Some(ref t) if idx == len => {
if token_name_eq(&tok, t) {
let mut ei_t = ei.clone();
ei_t.idx += 1;
next_eis.push(ei_t);
}
}
_ => {
let mut ei_t = ei;
ei_t.match_cur = ei_t.match_lo;
ei_t.idx = 0;
cur_eis.push(ei_t);
}
}
} else { eof_eis.push(ei); }
} else {
match ei.top_elts.get_tt(idx) {
TokenTree::Sequence(sp, seq) => {
if seq.op == ast::ZeroOrMore {
let mut new_ei = ei.clone();
new_ei.match_cur += seq.num_captures;
new_ei.idx += 1;
for idx in
ei.match_cur..ei.match_cur +
seq.num_captures
{
(&mut new_ei.matches[idx]).push(Rc::new(MatchedSeq(<[_]>::into_vec(::std::boxed::Box::new([])),
sp)));
}
cur_eis.push(new_ei);
}
let matches: Vec<_> =
(0..ei.matches.len()).map(|_|
Vec::new()).collect();
let ei_t = ei;
cur_eis.push(Box::new(MatcherPos{stack:
<[_]>::into_vec(::std::boxed::Box::new([])),
sep:
seq.separator.clone(),
idx: 0,
matches:
matches,
match_lo:
ei_t.match_cur,
match_cur:
ei_t.match_cur,
match_hi:
ei_t.match_cur
+
seq.num_captures,
up:
Some(ei_t),
sp_lo:
sp.lo,
top_elts:
Tt(TokenTree::Sequence(sp,
seq)),}));
}
TokenTree::Token(_, MatchNt(..)) => {
match tok {
token::CloseDelim(_) => { }
_ => bb_eis.push(ei),
}
}
TokenTree::Token(sp, SubstNt(..)) => {
return Error(sp,
"missing fragment specifier".to_string())
}
seq@TokenTree::Delimited(..) |
seq@TokenTree::Token(_, DocComment(..)) => {
let lower_elts =
mem::replace(&mut ei.top_elts,
Tt(seq));
let idx = ei.idx;
ei.stack.push(MatcherTtFrame{elts:
lower_elts,
idx: idx,});
ei.idx = 0;
cur_eis.push(ei);
}
TokenTree::Token(_, ref t) => {
let mut ei_t = ei.clone();
if token_name_eq(t, &tok) {
ei_t.idx += 1;
next_eis.push(ei_t);
}
}
}
}
}
if token_name_eq(&tok, &token::Eof) {
if eof_eis.len() == 1 {
let mut v = Vec::new();
for dv in &mut (&mut eof_eis[0]).matches {
v.push(dv.pop().unwrap());
}
return nameize(sess, ms, &v[..]);
} else if eof_eis.len() > 1 {
return Error(sp,
"ambiguity: multiple successful parses".to_string());
} else {
return Failure(sp,
"unexpected end of macro invocation".to_string());
}
} else {
if (!bb_eis.is_empty() && !next_eis.is_empty()) ||
bb_eis.len() > 1 {
let nts =
bb_eis.iter().map(|ei|
match ei.top_elts.get_tt(ei.idx)
{
TokenTree::Token(_,
MatchNt(bind,
name,
_,
_))
=> {
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
" (\'",
"\')"];
__STATIC_FMTSTR
},
&match (&name,
&bind)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}))
}
_ => {
{
::std::rt::begin_unwind("explicit panic",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
457u32);
&_FILE_LINE
})
}
}
}).collect::<Vec<String>>().join(" or ");
return Error(sp,
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["local ambiguity: multiple parsing options: "];
__STATIC_FMTSTR
},
&match (&match next_eis.len()
{
0
=>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["built-in NTs ",
"."];
__STATIC_FMTSTR
},
&match (&nts,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
1
=>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["built-in NTs ",
" or 1 other option."];
__STATIC_FMTSTR
},
&match (&nts,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
n
=>
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["built-in NTs ",
" or ",
" other options."];
__STATIC_FMTSTR
},
&match (&nts,
&n)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
})),
},)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})))
} else if bb_eis.is_empty() && next_eis.is_empty() {
return Failure(sp,
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["no rules expected the token `",
"`"];
__STATIC_FMTSTR
},
&match (&pprust::token_to_string(&tok),)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})));
} else if !next_eis.is_empty() {
while !next_eis.is_empty() {
cur_eis.push(next_eis.pop().unwrap());
}
rdr.next_token();
} else {
let mut rust_parser =
Parser::new(sess, cfg.clone(),
Box::new(rdr.clone()));
let mut ei = bb_eis.pop().unwrap();
match ei.top_elts.get_tt(ei.idx) {
TokenTree::Token(span,
MatchNt(_, ident, _, _)) => {
let match_cur = ei.match_cur;
(&mut ei.matches[match_cur]).push(Rc::new(MatchedNonterminal(parse_nt(&mut rust_parser,
span,
&ident.name.as_str()))));
ei.idx += 1;
ei.match_cur += 1;
}
_ => {
{
::std::rt::begin_unwind("explicit panic",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
489u32);
&_FILE_LINE
})
}
}
}
cur_eis.push(ei);
for _ in 0..rust_parser.tokens_consumed {
let _ = rdr.next_token();
}
}
}
if !!cur_eis.is_empty() {
{
::std::rt::begin_unwind("assertion failed: !cur_eis.is_empty()",
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/tt/macro_parser.rs",
499u32);
&_FILE_LINE
})
}
};
}
}
pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str)
-> Nonterminal {
match name {
"tt" => {
p.quote_depth += 1;
let res: ::parse::PResult<'a, _> =
p.parse_token_tree();
let res =
token::NtTT(P({
use std::result::Result::{Ok,
Err};
use errors::FatalError;
match res {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
508u32);
&_FILE_LINE
})
};
}
}
}));
p.quote_depth -= 1;
return res;
}
_ => { }
}
p.check_unknown_macro_variable();
match name {
"item" =>
match {
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
517u32);
&_FILE_LINE
})
};
}
}
} {
Some(i) => token::NtItem(i),
None => {
p.fatal("expected an item keyword").emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/tt/macro_parser.rs",
521u32);
&_FILE_LINE
})
};
}
},
"block" =>
token::NtBlock({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_block() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
524u32);
&_FILE_LINE
})
};
}
}
}),
"stmt" =>
match {
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_stmt() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
525u32);
&_FILE_LINE
})
};
}
}
} {
Some(s) => token::NtStmt(s),
None => {
p.fatal("expected a statement").emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/tt/macro_parser.rs",
529u32);
&_FILE_LINE
})
};
}
},
"pat" =>
token::NtPat({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_pat() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
532u32);
&_FILE_LINE
})
};
}
}
}),
"expr" =>
token::NtExpr({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
533u32);
&_FILE_LINE
})
};
}
}
}),
"ty" =>
token::NtTy({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_ty() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
534u32);
&_FILE_LINE
})
};
}
}
}),
"ident" =>
match p.token {
token::Ident(sn, b) => {
p.bump();
token::NtIdent(Box::new(Spanned::<Ident>{node: sn,
span:
p.span,}),
b)
}
_ => {
let token_str = pprust::token_to_string(&p.token);
p.fatal(&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["expected ident, found "];
__STATIC_FMTSTR
},
&match (&&token_str[..],)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))).emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/tt/macro_parser.rs",
545u32);
&_FILE_LINE
})
}
}
},
"path" => {
token::NtPath(Box::new({
use std::result::Result::{Ok,
Err};
use errors::FatalError;
match p.parse_path(LifetimeAndTypesWithoutColons)
{
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
549u32);
&_FILE_LINE
})
};
}
}
}))
}
"meta" =>
token::NtMeta({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match p.parse_meta_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_parser.rs",
551u32);
&_FILE_LINE
})
};
}
}
}),
_ => {
p.span_fatal_help(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid fragment specifier `",
"`"];
__STATIC_FMTSTR
},
&match (&name,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
})),
"valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `path`, `meta`, `tt` and `item`").emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/tt/macro_parser.rs",
558u32);
&_FILE_LINE
})
};
}
}
}
}
pub mod macro_rules {
#[prelude_import]
use std::prelude::v1::*;
use ast::{self, TokenTree};
use codemap::{Span, DUMMY_SP};
use ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension};
use ext::base::{NormalTT, TTMacroExpander};
use ext::tt::macro_parser::{Success, Error, Failure};
use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
use ext::tt::macro_parser::parse;
use parse::lexer::new_tt_reader;
use parse::parser::Parser;
use parse::token::{self, special_idents, gensym_ident, NtTT,
Token};
use parse::token::Token::*;
use print;
use ptr::P;
use util::small_vector::SmallVector;
use std::cell::RefCell;
use std::rc::Rc;
use std::iter::once;
struct ParserAnyMacro<'a> {
parser: RefCell<Parser<'a>>,
/// Span of the expansion site of the macro this parser is for
site_span: Span,
/// The ident of the macro we're parsing
macro_ident: ast::Ident,
}
impl <'a> ParserAnyMacro<'a> {
/// Make sure we don't have any tokens left to parse, so we don't
/// silently drop anything. `allow_semi` is so that "optional"
/// semicolons at the end of normal expressions aren't complained
/// about e.g. the semicolon in `macro_rules! kapow { () => {
/// panic!(); } }` doesn't get picked up by .parse_expr(), but it's
/// allowed to be there.
fn ensure_complete_parse(&self, allow_semi: bool,
context: &str) {
let mut parser = self.parser.borrow_mut();
if allow_semi && parser.token == token::Semi {
parser.bump();
}
if parser.token != token::Eof {
let token_str = parser.this_token_to_string();
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["macro expansion ignores token `",
"` and any following"];
__STATIC_FMTSTR
},
&match (&token_str,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}));
let span = parser.span;
let mut err =
parser.diagnostic().struct_span_err(span,
&msg[..]);
let msg =
::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["caused by the macro expansion here; the usage of `",
"!` is likely invalid in ",
" context"];
__STATIC_FMTSTR
},
&match (&self.macro_ident,
&context)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
err.span_note(self.site_span, &msg[..]).emit();
}
}
}
impl <'a> MacResult for ParserAnyMacro<'a> {
fn make_expr(self: Box<ParserAnyMacro<'a>>)
-> Option<P<ast::Expr>> {
let ret =
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match self.parser.borrow_mut().parse_expr() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_rules.rs",
70u32);
&_FILE_LINE
})
};
}
}
};
self.ensure_complete_parse(true, "expression");
Some(ret)
}
fn make_pat(self: Box<ParserAnyMacro<'a>>)
-> Option<P<ast::Pat>> {
let ret =
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match self.parser.borrow_mut().parse_pat() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_rules.rs",
75u32);
&_FILE_LINE
})
};
}
}
};
self.ensure_complete_parse(false, "pattern");
Some(ret)
}
fn make_items(self: Box<ParserAnyMacro<'a>>)
-> Option<SmallVector<P<ast::Item>>> {
let mut ret = SmallVector::zero();
while let Some(item) =
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match self.parser.borrow_mut().parse_item()
{
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_rules.rs",
81u32);
&_FILE_LINE
})
};
}
}
} {
ret.push(item);
}
self.ensure_complete_parse(false, "item");
Some(ret)
}
fn make_impl_items(self: Box<ParserAnyMacro<'a>>)
-> Option<SmallVector<P<ast::ImplItem>>> {
let mut ret = SmallVector::zero();
loop {
let mut parser = self.parser.borrow_mut();
match parser.token {
token::Eof => break ,
_ =>
ret.push({
use std::result::Result::{Ok, Err};
use errors::FatalError;
match parser.parse_impl_item() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_rules.rs",
95u32);
&_FILE_LINE
})
};
}
}
}),
}
}
self.ensure_complete_parse(false, "item");
Some(ret)
}
fn make_stmts(self: Box<ParserAnyMacro<'a>>)
-> Option<SmallVector<P<ast::Stmt>>> {
let mut ret = SmallVector::zero();
loop {
let mut parser = self.parser.borrow_mut();
match parser.token {
token::Eof => break ,
_ =>
match parser.parse_stmt() {
Ok(maybe_stmt) =>
match maybe_stmt {
Some(stmt) => ret.push(stmt),
None => (),
},
Err(mut e) => { e.emit(); break ; }
},
}
}
self.ensure_complete_parse(false, "statement");
Some(ret)
}
fn make_ty(self: Box<ParserAnyMacro<'a>>)
-> Option<P<ast::Ty>> {
let ret =
{
use std::result::Result::{Ok, Err};
use errors::FatalError;
match self.parser.borrow_mut().parse_ty() {
Ok(e) => e,
Err(mut e) => {
e.emit();
{
::std::rt::begin_unwind(FatalError,
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_rules.rs",
126u32);
&_FILE_LINE
})
};
}
}
};
self.ensure_complete_parse(false, "type");
Some(ret)
}
}
struct MacroRulesMacroExpander {
name: ast::Ident,
imported_from: Option<ast::Ident>,
lhses: Vec<TokenTree>,
rhses: Vec<TokenTree>,
valid: bool,
}
impl TTMacroExpander for MacroRulesMacroExpander {
fn expand<'cx>(&self, cx: &'cx mut ExtCtxt, sp: Span,
arg: &[TokenTree]) -> Box<MacResult+ 'cx> {
if !self.valid { return DummyResult::any(sp); }
generic_extension(cx, sp, self.name, self.imported_from,
arg, &self.lhses, &self.rhses)
}
}
/// Given `lhses` and `rhses`, this is the new macro we create
fn generic_extension<'cx>(cx: &'cx ExtCtxt, sp: Span,
name: ast::Ident,
imported_from: Option<ast::Ident>,
arg: &[TokenTree], lhses: &[TokenTree],
rhses: &[TokenTree])
-> Box<MacResult+ 'cx> {
if cx.trace_macros() {
::std::io::_print(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["",
"! { ",
" }\n"];
__STATIC_FMTSTR
},
&match (&name,
&print::pprust::tts_to_string(arg))
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
}));
}
let mut best_fail_spot = DUMMY_SP;
let mut best_fail_msg =
"internal error: ran no matchers".to_string();
for (i, lhs) in lhses.iter().enumerate() {
let lhs_tt =
match *lhs {
TokenTree::Delimited(_, ref delim) =>
&delim.tts[..],
_ => cx.span_fatal(sp, "malformed macro lhs"),
};
match TokenTree::parse(cx, lhs_tt, arg) {
Success(named_matches) => {
let rhs =
match rhses[i] {
TokenTree::Delimited(_, ref delimed) =>
delimed.tts.clone(),
_ =>
cx.span_fatal(sp, "malformed macro rhs"),
};
let trncbr =
new_tt_reader(&cx.parse_sess().span_diagnostic,
Some(named_matches),
imported_from, rhs);
let mut p =
Parser::new(cx.parse_sess(), cx.cfg(),
Box::new(trncbr));
p.check_unknown_macro_variable();
return Box::new(ParserAnyMacro{parser:
RefCell::new(p),
site_span: sp,
macro_ident:
name,})
}
Failure(sp, ref msg) =>
if sp.lo >= best_fail_spot.lo {
best_fail_spot = sp;
best_fail_msg = (*msg).clone();
},
Error(err_sp, ref msg) => {
cx.span_fatal(err_sp.substitute_dummy(sp),
&msg[..])
}
}
}
cx.span_fatal(best_fail_spot.substitute_dummy(sp),
&best_fail_msg[..]);
}
/// Converts a `macro_rules!` invocation into a syntax extension.
pub fn compile<'cx>(cx: &'cx mut ExtCtxt, def: &ast::MacroDef)
-> SyntaxExtension {
let lhs_nm = gensym_ident("lhs");
let rhs_nm = gensym_ident("rhs");
let match_lhs_tok =
MatchNt(lhs_nm, special_idents::tt, token::Plain,
token::Plain);
let match_rhs_tok =
MatchNt(rhs_nm, special_idents::tt, token::Plain,
token::Plain);
let argument_gram =
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Sequence(DUMMY_SP,
Rc::new(ast::SequenceRepetition{tts:
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
match_lhs_tok),
TokenTree::Token(DUMMY_SP,
token::FatArrow),
TokenTree::Token(DUMMY_SP,
match_rhs_tok)])),
separator:
Some(token::Semi),
op:
ast::OneOrMore,
num_captures:
2,})),
TokenTree::Sequence(DUMMY_SP,
Rc::new(ast::SequenceRepetition{tts:
<[_]>::into_vec(::std::boxed::Box::new([TokenTree::Token(DUMMY_SP,
token::Semi)])),
separator:
None,
op:
ast::ZeroOrMore,
num_captures:
0,}))]));
let arg_reader =
new_tt_reader(&cx.parse_sess().span_diagnostic, None,
None, def.body.clone());
let argument_map =
match parse(cx.parse_sess(), cx.cfg(), arg_reader,
&argument_gram) {
Success(m) => m,
Failure(sp, str) | Error(sp, str) => {
{
::std::rt::begin_unwind(cx.parse_sess().span_diagnostic.span_fatal(sp.substitute_dummy(def.span),
&str[..]),
{
static _FILE_LINE:
(&'static str,
u32) =
("src/ext/tt/macro_rules.rs",
276u32);
&_FILE_LINE
})
};
}
};
let mut valid = true;
let lhses =
match **argument_map.get(&lhs_nm.name).unwrap() {
MatchedSeq(ref s, _) => {
s.iter().map(|m|
match **m {
MatchedNonterminal(NtTT(ref tt))
=> (**tt).clone(),
_ =>
cx.span_bug(def.span,
"wrong-structured lhs"),
}).collect()
}
_ => cx.span_bug(def.span, "wrong-structured lhs"),
};
for lhs in &lhses { check_lhs_nt_follows(cx, lhs, def.span); }
let rhses =
match **argument_map.get(&rhs_nm.name).unwrap() {
MatchedSeq(ref s, _) => {
s.iter().map(|m|
match **m {
MatchedNonterminal(NtTT(ref tt))
=> (**tt).clone(),
_ =>
cx.span_bug(def.span,
"wrong-structured rhs"),
}).collect()
}
_ => cx.span_bug(def.span, "wrong-structured rhs"),
};
for rhs in &rhses { valid &= check_rhs(cx, rhs); }
let exp: Box<_> =
Box::new(MacroRulesMacroExpander{name: def.ident,
imported_from:
def.imported_from,
lhses: lhses,
rhses: rhses,
valid: valid,});
NormalTT(exp, Some(def.span), def.allow_internal_unstable)
}
fn check_lhs_nt_follows(cx: &mut ExtCtxt, lhs: &TokenTree,
sp: Span) {
match lhs {
&TokenTree::Delimited(_, ref tts) => {
check_matcher(cx, tts.tts.iter(), &Eof);
}
tt@&TokenTree::Sequence(..) => {
check_matcher(cx, Some(tt).into_iter(), &Eof);
}
_ =>
cx.span_err(sp,
"invalid macro matcher; matchers must be contained in balanced delimiters or a repetition indicator"),
};
}
fn check_rhs(cx: &mut ExtCtxt, rhs: &TokenTree) -> bool {
match *rhs {
TokenTree::Delimited(..) => return true,
_ =>
cx.span_err(rhs.get_span(),
"macro rhs must be delimited"),
}
false
}
fn check_matcher<'a,
I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
-> Option<(Span, Token)> where I: Iterator<Item =
&'a TokenTree> {
use print::pprust::token_to_string;
let mut last = None;
let mut tokens = matcher.peekable();
while let Some(token) = tokens.next() {
last =
match *token {
TokenTree::Token(sp,
MatchNt(ref name, ref frag_spec,
_, _)) => {
if can_be_followed_by_any(&frag_spec.name.as_str())
{
continue
} else {
let next_token =
match tokens.peek() {
Some(&&TokenTree::Token(_,
CloseDelim(_)))
=> follow.clone(),
Some(&&TokenTree::Token(_,
ref tok))
=> tok.clone(),
Some(&&TokenTree::Sequence(sp, _))
=> {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["`$",
":",
"` is followed by a sequence repetition, which is not allowed for `",
"` fragments"];
__STATIC_FMTSTR
},
&match (&name,
&frag_spec)
{
(__arg0,
__arg1)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
})));
Eof
}
Some(&&TokenTree::Delimited(_,
ref delim))
=> delim.close_token(),
None => follow.clone(),
};
let tok =
if let TokenTree::Token(_, ref tok) =
*token {
tok
} else {
{
{
::std::rt::begin_unwind("internal error: entered unreachable code",
{
static _FILE_LINE:
(&'static str,
u32)
=
("src/ext/tt/macro_rules.rs",
395u32);
&_FILE_LINE
})
}
}
};
match (&next_token,
is_in_follow(cx, &next_token,
&frag_spec.name.as_str()))
{
(_, Err(msg)) => {
cx.span_err(sp, &msg);
continue
}
(&Eof, _) =>
return Some((sp, tok.clone())),
(_, Ok(true)) => continue ,
(next, Ok(false)) => {
cx.span_err(sp,
&::std::fmt::format(::std::fmt::Arguments::new_v1_formatted({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["`$",
":",
"` is followed by `",
"`, which is not allowed for `",
"` fragments"];
__STATIC_FMTSTR
},
&match (&name,
&frag_spec,
&token_to_string(next))
{
(__arg0,
__arg1,
__arg2)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1,
::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg2,
::std::fmt::Display::fmt)],
},
{
static __STATIC_FMTARGS:
&'static [::std::fmt::rt::v1::Argument]
=
&[::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(0usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(2usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},},
::std::fmt::rt::v1::Argument{position:
::std::fmt::rt::v1::Position::At(1usize),
format:
::std::fmt::rt::v1::FormatSpec{fill:
' ',
align:
::std::fmt::rt::v1::Alignment::Unknown,
flags:
0u32,
precision:
::std::fmt::rt::v1::Count::Implied,
width:
::std::fmt::rt::v1::Count::Implied,},}];
__STATIC_FMTARGS
})));
continue
}
}
}
}
TokenTree::Sequence(sp, ref seq) => {
match seq.separator {
Some(ref u) => {
let last =
check_matcher(cx, seq.tts.iter(),
u);
match last {
Some((span, tok)) => {
let fol =
match tokens.peek() {
Some(&&TokenTree::Token(_,
ref tok))
=> tok.clone(),
Some(&&TokenTree::Delimited(_,
ref delim))
=>
delim.close_token(),
Some(_) => {
cx.span_err(sp,
"sequence repetition followed by another sequence repetition, which is not allowed");
Eof
}
None => Eof,
};
check_matcher(cx,
once(&TokenTree::Token(span,
tok.clone())),
&fol)
}
None => last,
}
}
None => {
let fol =
match tokens.peek() {
Some(&&TokenTree::Token(_,
ref tok))
=> tok.clone(),
Some(&&TokenTree::Delimited(_,
ref delim))
=> delim.close_token(),
Some(_) => {
cx.span_err(sp,
"sequence repetition followed by another sequence repetition, which is not allowed");
Eof
}
None => Eof,
};
check_matcher(cx, seq.tts.iter(),
&fol)
}
}
}
TokenTree::Token(..) => { continue }
TokenTree::Delimited(_, ref tts) => {
check_matcher(cx, tts.tts.iter(),
&tts.close_token())
}
}
}
last
}
/// True if a fragment of type `frag` can be followed by any sort of
/// token. We use this (among other things) as a useful approximation
/// for when `frag` can be followed by a repetition like `$(...)*` or
/// `$(...)+`. In general, these can be a bit tricky to reason about,
/// so we adopt a conservative position that says that any fragment
/// specifier which consumes at most one token tree can be followed by
/// a fragment specifier (indeed, these fragments can be followed by
/// ANYTHING without fear of future compatibility hazards).
fn can_be_followed_by_any(frag: &str) -> bool {
match frag {
"item" | "block" | "ident" | "meta" | "tt" => true,
_ => false,
}
}
/// True if `frag` can legally be followed by the token `tok`. For
/// fragments that can consume an unbounded numbe of tokens, `tok`
/// must be within a well-defined follow set. This is intended to
/// guarantee future compatibility: for example, without this rule, if
/// we expanded `expr` to include a new binary operator, we might
/// break macros that were relying on that binary operator as a
/// separator.
fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str)
-> Result<bool, String> {
if let &CloseDelim(_) = tok {
Ok(true)
} else {
match frag {
"item" => { Ok(true) }
"block" => { Ok(true) }
"stmt" | "expr" => {
match *tok {
FatArrow | Comma | Semi => Ok(true),
_ => Ok(false),
}
}
"pat" => {
match *tok {
FatArrow | Comma | Eq => Ok(true),
Ident(i, _) if
i.name.as_str() == "if" ||
i.name.as_str() == "in" => Ok(true),
_ => Ok(false),
}
}
"path" | "ty" => {
match *tok {
Comma | FatArrow | Colon | Eq | Gt | Semi =>
Ok(true),
Ident(i, _) if i.name.as_str() == "as" =>
Ok(true),
_ => Ok(false),
}
}
"ident" => { Ok(true) }
"meta" | "tt" => { Ok(true) }
_ =>
Err(::std::fmt::format(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["invalid fragment specifier `",
"`"];
__STATIC_FMTSTR
},
&match (&frag,)
{
(__arg0,)
=>
[::std::fmt::ArgumentV1::new(__arg0,
::std::fmt::Display::fmt)],
}))),
}
}
}
}
}
}