Complete the removal of ty_nil, ast::LitNil, ast::TyBot and ast::TyUniq
[breaking-change] This will break any uses of macros that assumed () being a valid literal.
This commit is contained in:
parent
08d6774f39
commit
eb01b17b06
34 changed files with 348 additions and 405 deletions
|
@ -66,7 +66,6 @@ register_diagnostics!(
|
||||||
E0055,
|
E0055,
|
||||||
E0056,
|
E0056,
|
||||||
E0057,
|
E0057,
|
||||||
E0058,
|
|
||||||
E0059,
|
E0059,
|
||||||
E0060,
|
E0060,
|
||||||
E0061,
|
E0061,
|
||||||
|
|
|
@ -447,7 +447,9 @@ impl LintPass for ImproperCTypes {
|
||||||
for input in decl.inputs.iter() {
|
for input in decl.inputs.iter() {
|
||||||
check_ty(cx, &*input.ty);
|
check_ty(cx, &*input.ty);
|
||||||
}
|
}
|
||||||
check_ty(cx, &*decl.output)
|
if let ast::Return(ref ret_ty) = decl.output {
|
||||||
|
check_ty(cx, &**ret_ty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match it.node {
|
match it.node {
|
||||||
|
@ -735,6 +737,7 @@ impl LintPass for UnusedResults {
|
||||||
let t = ty::expr_ty(cx.tcx, expr);
|
let t = ty::expr_ty(cx.tcx, expr);
|
||||||
let mut warned = false;
|
let mut warned = false;
|
||||||
match ty::get(t).sty {
|
match ty::get(t).sty {
|
||||||
|
ty::ty_tup(ref tys) if tys.is_empty() => return,
|
||||||
ty::ty_bool => return,
|
ty::ty_bool => return,
|
||||||
ty::ty_struct(did, _) |
|
ty::ty_struct(did, _) |
|
||||||
ty::ty_enum(did, _) => {
|
ty::ty_enum(did, _) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use middle::const_eval::{compare_const_vals, const_bool, const_float, const_nil, const_val};
|
use middle::const_eval::{compare_const_vals, const_bool, const_float, const_val};
|
||||||
use middle::const_eval::{const_expr_to_pat, eval_const_expr, lookup_const_by_id};
|
use middle::const_eval::{const_expr_to_pat, eval_const_expr, lookup_const_by_id};
|
||||||
use middle::def::*;
|
use middle::def::*;
|
||||||
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
|
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
|
||||||
|
@ -332,7 +332,6 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
|
||||||
fn const_val_to_expr(value: &const_val) -> P<Expr> {
|
fn const_val_to_expr(value: &const_val) -> P<Expr> {
|
||||||
let node = match value {
|
let node = match value {
|
||||||
&const_bool(b) => LitBool(b),
|
&const_bool(b) => LitBool(b),
|
||||||
&const_nil => LitNil,
|
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
};
|
};
|
||||||
P(Expr {
|
P(Expr {
|
||||||
|
@ -402,7 +401,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
|
||||||
let pats_len = pats.len();
|
let pats_len = pats.len();
|
||||||
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
|
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
|
||||||
let pat = match ty::get(left_ty).sty {
|
let pat = match ty::get(left_ty).sty {
|
||||||
ty::ty_tup(ref tys) if !tys.is_empty() => PatTup(pats.collect()),
|
ty::ty_tup(_) => PatTup(pats.collect()),
|
||||||
|
|
||||||
ty::ty_enum(cid, _) | ty::ty_struct(cid, _) => {
|
ty::ty_enum(cid, _) | ty::ty_struct(cid, _) => {
|
||||||
let (vid, is_structure) = match ctor {
|
let (vid, is_structure) = match ctor {
|
||||||
|
@ -497,9 +496,6 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t,
|
||||||
ty::ty_bool =>
|
ty::ty_bool =>
|
||||||
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),
|
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),
|
||||||
|
|
||||||
ty::ty_tup(ref tys) if tys.is_empty() =>
|
|
||||||
vec!(ConstantValue(const_nil)),
|
|
||||||
|
|
||||||
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
|
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
|
||||||
ty::ty_vec(_, None) =>
|
ty::ty_vec(_, None) =>
|
||||||
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
|
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
|
||||||
|
|
|
@ -311,8 +311,7 @@ pub enum const_val {
|
||||||
const_uint(u64),
|
const_uint(u64),
|
||||||
const_str(InternedString),
|
const_str(InternedString),
|
||||||
const_binary(Rc<Vec<u8> >),
|
const_binary(Rc<Vec<u8> >),
|
||||||
const_bool(bool),
|
const_bool(bool)
|
||||||
const_nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
|
pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
|
||||||
|
@ -589,7 +588,6 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
|
||||||
LitFloatUnsuffixed(ref n) => {
|
LitFloatUnsuffixed(ref n) => {
|
||||||
const_float(from_str::<f64>(n.get()).unwrap() as f64)
|
const_float(from_str::<f64>(n.get()).unwrap() as f64)
|
||||||
}
|
}
|
||||||
LitNil => const_nil,
|
|
||||||
LitBool(b) => const_bool(b)
|
LitBool(b) => const_bool(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,7 +603,6 @@ pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option<int> {
|
||||||
(&const_str(ref a), &const_str(ref b)) => compare_vals(a, b),
|
(&const_str(ref a), &const_str(ref b)) => compare_vals(a, b),
|
||||||
(&const_bool(a), &const_bool(b)) => compare_vals(a, b),
|
(&const_bool(a), &const_bool(b)) => compare_vals(a, b),
|
||||||
(&const_binary(ref a), &const_binary(ref b)) => compare_vals(a, b),
|
(&const_binary(ref a), &const_binary(ref b)) => compare_vals(a, b),
|
||||||
(&const_nil, &const_nil) => compare_vals((), ()),
|
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4285,7 +4285,9 @@ impl<'a> Resolver<'a> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resolve_type(&*ty_m.decl.output);
|
if let ast::Return(ref ret_ty) = ty_m.decl.output {
|
||||||
|
this.resolve_type(&**ret_ty);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ast::ProvidedMethod(ref m) => {
|
ast::ProvidedMethod(ref m) => {
|
||||||
|
@ -4467,7 +4469,9 @@ impl<'a> Resolver<'a> {
|
||||||
debug!("(resolving function) recorded argument");
|
debug!("(resolving function) recorded argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resolve_type(&*declaration.output);
|
if let ast::Return(ref ret_ty) = declaration.output {
|
||||||
|
this.resolve_type(&**ret_ty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,11 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
|
||||||
for arg in method.pe_fn_decl().inputs.iter() {
|
for arg in method.pe_fn_decl().inputs.iter() {
|
||||||
self.visit_ty(&*arg.ty);
|
self.visit_ty(&*arg.ty);
|
||||||
}
|
}
|
||||||
self.visit_ty(&*method.pe_fn_decl().output);
|
|
||||||
|
if let ast::Return(ref ret_ty) = method.pe_fn_decl().output {
|
||||||
|
self.visit_ty(&**ret_ty);
|
||||||
|
}
|
||||||
|
|
||||||
// walk the fn body
|
// walk the fn body
|
||||||
self.nest(method.id, |v| v.visit_block(&*method.pe_body()));
|
self.nest(method.id, |v| v.visit_block(&*method.pe_body()));
|
||||||
|
|
||||||
|
@ -491,7 +495,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
|
||||||
for arg in decl.inputs.iter() {
|
for arg in decl.inputs.iter() {
|
||||||
self.visit_ty(&*arg.ty);
|
self.visit_ty(&*arg.ty);
|
||||||
}
|
}
|
||||||
self.visit_ty(&*decl.output);
|
|
||||||
|
if let ast::Return(ref ret_ty) = decl.output {
|
||||||
|
self.visit_ty(&**ret_ty);
|
||||||
|
}
|
||||||
|
|
||||||
// walk the body
|
// walk the body
|
||||||
self.nest(item.id, |v| v.visit_block(&*body));
|
self.nest(item.id, |v| v.visit_block(&*body));
|
||||||
|
@ -1136,7 +1143,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
|
||||||
for arg in method_type.decl.inputs.iter() {
|
for arg in method_type.decl.inputs.iter() {
|
||||||
self.visit_ty(&*arg.ty);
|
self.visit_ty(&*arg.ty);
|
||||||
}
|
}
|
||||||
self.visit_ty(&*method_type.decl.output);
|
|
||||||
|
if let ast::Return(ref ret_ty) = method_type.decl.output {
|
||||||
|
self.visit_ty(&**ret_ty);
|
||||||
|
}
|
||||||
|
|
||||||
self.process_generic_params(&method_type.generics,
|
self.process_generic_params(&method_type.generics,
|
||||||
method_type.span,
|
method_type.span,
|
||||||
|
@ -1352,7 +1362,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
|
||||||
for arg in decl.inputs.iter() {
|
for arg in decl.inputs.iter() {
|
||||||
self.visit_ty(&*arg.ty);
|
self.visit_ty(&*arg.ty);
|
||||||
}
|
}
|
||||||
self.visit_ty(&*decl.output);
|
|
||||||
|
if let ast::Return(ref ret_ty) = decl.output {
|
||||||
|
self.visit_ty(&**ret_ty);
|
||||||
|
}
|
||||||
|
|
||||||
// walk the body
|
// walk the body
|
||||||
self.nest(ex.id, |v| v.visit_block(&**body));
|
self.nest(ex.id, |v| v.visit_block(&**body));
|
||||||
|
|
|
@ -81,7 +81,6 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::LitBool(b) => C_bool(cx, b),
|
ast::LitBool(b) => C_bool(cx, b),
|
||||||
ast::LitNil => C_nil(cx),
|
|
||||||
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
|
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
|
||||||
ast::LitBinary(ref data) => C_binary_slice(cx, data.as_slice()),
|
ast::LitBinary(ref data) => C_binary_slice(cx, data.as_slice()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -718,7 +718,9 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
|
||||||
macro_rules! ifn (
|
macro_rules! ifn (
|
||||||
($name:expr fn() -> $ret:expr) => (
|
($name:expr fn() -> $ret:expr) => (
|
||||||
if *key == $name {
|
if *key == $name {
|
||||||
let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil(ccx.tcx()));
|
let f = base::decl_cdecl_fn(
|
||||||
|
ccx, $name, Type::func([], &$ret),
|
||||||
|
ty::mk_nil(ccx.tcx()));
|
||||||
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
||||||
return Some(f);
|
return Some(f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1374,10 +1374,9 @@ pub fn create_function_debug_context(cx: &CrateContext,
|
||||||
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
|
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
|
||||||
|
|
||||||
// Return type -- llvm::DIBuilder wants this at index 0
|
// Return type -- llvm::DIBuilder wants this at index 0
|
||||||
match fn_decl.output.node {
|
match fn_decl.output {
|
||||||
ast::TyNil => {
|
ast::Return(ref ret_ty) if ret_ty.node == ast::TyTup(vec![]) =>
|
||||||
signature.push(ptr::null_mut());
|
signature.push(ptr::null_mut()),
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
|
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
|
||||||
|
|
||||||
|
@ -1738,6 +1737,8 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
|
||||||
debug!("basic_type_metadata: {}", ty::get(t));
|
debug!("basic_type_metadata: {}", ty::get(t));
|
||||||
|
|
||||||
let (name, encoding) = match ty::get(t).sty {
|
let (name, encoding) = match ty::get(t).sty {
|
||||||
|
ty::ty_tup(ref elements) if elements.is_empty() =>
|
||||||
|
("()".to_string(), DW_ATE_unsigned),
|
||||||
ty::ty_bool => ("bool".to_string(), DW_ATE_boolean),
|
ty::ty_bool => ("bool".to_string(), DW_ATE_boolean),
|
||||||
ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char),
|
ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char),
|
||||||
ty::ty_int(int_ty) => match int_ty {
|
ty::ty_int(int_ty) => match int_ty {
|
||||||
|
@ -2888,6 +2889,9 @@ fn type_metadata(cx: &CrateContext,
|
||||||
ty::ty_float(_) => {
|
ty::ty_float(_) => {
|
||||||
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
|
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
|
||||||
}
|
}
|
||||||
|
ty::ty_tup(ref elements) if elements.is_empty() => {
|
||||||
|
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
|
||||||
|
}
|
||||||
ty::ty_enum(def_id, _) => {
|
ty::ty_enum(def_id, _) => {
|
||||||
prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
|
prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
|
||||||
}
|
}
|
||||||
|
@ -3669,7 +3673,7 @@ fn compute_debuginfo_type_name(cx: &CrateContext,
|
||||||
fn push_debuginfo_type_name(cx: &CrateContext,
|
fn push_debuginfo_type_name(cx: &CrateContext,
|
||||||
t: ty::t,
|
t: ty::t,
|
||||||
qualified: bool,
|
qualified: bool,
|
||||||
output:&mut String) {
|
output: &mut String) {
|
||||||
match ty::get(t).sty {
|
match ty::get(t).sty {
|
||||||
ty::ty_bool => output.push_str("bool"),
|
ty::ty_bool => output.push_str("bool"),
|
||||||
ty::ty_char => output.push_str("char"),
|
ty::ty_char => output.push_str("char"),
|
||||||
|
@ -3697,8 +3701,10 @@ fn push_debuginfo_type_name(cx: &CrateContext,
|
||||||
push_debuginfo_type_name(cx, component_type, true, output);
|
push_debuginfo_type_name(cx, component_type, true, output);
|
||||||
output.push_str(", ");
|
output.push_str(", ");
|
||||||
}
|
}
|
||||||
|
if !component_types.is_empty() {
|
||||||
output.pop();
|
output.pop();
|
||||||
output.pop();
|
output.pop();
|
||||||
|
}
|
||||||
output.push(')');
|
output.push(')');
|
||||||
},
|
},
|
||||||
ty::ty_uniq(inner_type) => {
|
ty::ty_uniq(inner_type) => {
|
||||||
|
|
|
@ -2131,6 +2131,7 @@ pub fn type_is_scalar(ty: t) -> bool {
|
||||||
ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) |
|
ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) |
|
||||||
ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) |
|
ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) |
|
||||||
ty_bare_fn(..) | ty_ptr(_) => true,
|
ty_bare_fn(..) | ty_ptr(_) => true,
|
||||||
|
ty_tup(ref tys) if tys.is_empty() => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3777,6 +3778,7 @@ pub fn ty_sort_string(cx: &ctxt, t: t) -> String {
|
||||||
ty_uint(_) | ty_float(_) | ty_str => {
|
ty_uint(_) | ty_float(_) | ty_str => {
|
||||||
::util::ppaux::ty_to_string(cx, t)
|
::util::ppaux::ty_to_string(cx, t)
|
||||||
}
|
}
|
||||||
|
ty_tup(ref tys) if tys.is_empty() => ::util::ppaux::ty_to_string(cx, t),
|
||||||
|
|
||||||
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
|
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
|
||||||
ty_uniq(_) => "box".to_string(),
|
ty_uniq(_) => "box".to_string(),
|
||||||
|
@ -4771,54 +4773,42 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t {
|
||||||
// Returns the repeat count for a repeating vector expression.
|
// Returns the repeat count for a repeating vector expression.
|
||||||
pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
|
pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
|
||||||
match const_eval::eval_const_expr_partial(tcx, count_expr) {
|
match const_eval::eval_const_expr_partial(tcx, count_expr) {
|
||||||
Ok(ref const_val) => match *const_val {
|
Ok(val) => {
|
||||||
const_eval::const_int(count) => if count < 0 {
|
let found = match val {
|
||||||
tcx.sess.span_err(count_expr.span,
|
const_eval::const_uint(count) => return count as uint,
|
||||||
"expected positive integer for \
|
const_eval::const_int(count) if count >= 0 => return count as uint,
|
||||||
repeat count, found negative integer");
|
const_eval::const_int(_) =>
|
||||||
|
"negative integer",
|
||||||
|
const_eval::const_float(_) =>
|
||||||
|
"float",
|
||||||
|
const_eval::const_str(_) =>
|
||||||
|
"string",
|
||||||
|
const_eval::const_bool(_) =>
|
||||||
|
"boolean",
|
||||||
|
const_eval::const_binary(_) =>
|
||||||
|
"binary array"
|
||||||
|
};
|
||||||
|
tcx.sess.span_err(count_expr.span, format!(
|
||||||
|
"expected positive integer for repeat count, found {}",
|
||||||
|
found).as_slice());
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
let found = match count_expr.node {
|
||||||
|
ast::ExprPath(ast::Path {
|
||||||
|
global: false,
|
||||||
|
ref segments,
|
||||||
|
..
|
||||||
|
}) if segments.len() == 1 =>
|
||||||
|
"variable",
|
||||||
|
_ =>
|
||||||
|
"non-constant expression"
|
||||||
|
};
|
||||||
|
tcx.sess.span_err(count_expr.span, format!(
|
||||||
|
"expected constant integer for repeat count, found {}",
|
||||||
|
found).as_slice());
|
||||||
|
}
|
||||||
|
}
|
||||||
0
|
0
|
||||||
} else {
|
|
||||||
count as uint
|
|
||||||
},
|
|
||||||
const_eval::const_uint(count) => count as uint,
|
|
||||||
const_eval::const_float(count) => {
|
|
||||||
tcx.sess.span_err(count_expr.span,
|
|
||||||
"expected positive integer for \
|
|
||||||
repeat count, found float");
|
|
||||||
count as uint
|
|
||||||
}
|
|
||||||
const_eval::const_str(_) => {
|
|
||||||
tcx.sess.span_err(count_expr.span,
|
|
||||||
"expected positive integer for \
|
|
||||||
repeat count, found string");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
const_eval::const_bool(_) => {
|
|
||||||
tcx.sess.span_err(count_expr.span,
|
|
||||||
"expected positive integer for \
|
|
||||||
repeat count, found boolean");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
const_eval::const_binary(_) => {
|
|
||||||
tcx.sess.span_err(count_expr.span,
|
|
||||||
"expected positive integer for \
|
|
||||||
repeat count, found binary array");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
const_eval::const_nil => {
|
|
||||||
tcx.sess.span_err(count_expr.span,
|
|
||||||
"expected positive integer for \
|
|
||||||
repeat count, found ()");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(..) => {
|
|
||||||
tcx.sess.span_err(count_expr.span,
|
|
||||||
"expected constant integer for repeat count, \
|
|
||||||
found variable");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over a type parameter's bounded traits and any supertraits
|
// Iterate over a type parameter's bounded traits and any supertraits
|
||||||
|
|
|
@ -385,7 +385,7 @@ fn ast_path_substs<'tcx,AC,RS>(
|
||||||
let inputs = data.inputs.iter()
|
let inputs = data.inputs.iter()
|
||||||
.map(|a_t| ast_ty_to_ty(this, &binding_rscope, &**a_t))
|
.map(|a_t| ast_ty_to_ty(this, &binding_rscope, &**a_t))
|
||||||
.collect();
|
.collect();
|
||||||
let input_ty = ty::mk_tup_or_nil(this.tcx(), inputs);
|
let input_ty = ty::mk_tup(this.tcx(), inputs);
|
||||||
|
|
||||||
let output = match data.output {
|
let output = match data.output {
|
||||||
Some(ref output_ty) => ast_ty_to_ty(this, &binding_rscope, &**output_ty),
|
Some(ref output_ty) => ast_ty_to_ty(this, &binding_rscope, &**output_ty),
|
||||||
|
@ -652,12 +652,6 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Show)]
|
|
||||||
enum PointerTy {
|
|
||||||
RPtr(ty::Region),
|
|
||||||
Uniq
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle `~`, `Box`, and `&` being able to mean strs and vecs.
|
// Handle `~`, `Box`, and `&` being able to mean strs and vecs.
|
||||||
// If a_seq_ty is a str or a vec, make it a str/vec.
|
// If a_seq_ty is a str or a vec, make it a str/vec.
|
||||||
// Also handle first-class trait types.
|
// Also handle first-class trait types.
|
||||||
|
@ -666,14 +660,14 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
||||||
rscope: &RS,
|
rscope: &RS,
|
||||||
a_seq_mutbl: ast::Mutability,
|
a_seq_mutbl: ast::Mutability,
|
||||||
a_seq_ty: &ast::Ty,
|
a_seq_ty: &ast::Ty,
|
||||||
ptr_ty: PointerTy,
|
region: ty::Region,
|
||||||
constr: |ty::t| -> ty::t)
|
constr: |ty::t| -> ty::t)
|
||||||
-> ty::t
|
-> ty::t
|
||||||
{
|
{
|
||||||
let tcx = this.tcx();
|
let tcx = this.tcx();
|
||||||
|
|
||||||
debug!("mk_pointer(ptr_ty={}, a_seq_ty={})",
|
debug!("mk_pointer(region={}, a_seq_ty={})",
|
||||||
ptr_ty,
|
region,
|
||||||
a_seq_ty.repr(tcx));
|
a_seq_ty.repr(tcx));
|
||||||
|
|
||||||
match a_seq_ty.node {
|
match a_seq_ty.node {
|
||||||
|
@ -688,14 +682,7 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
||||||
match tcx.def_map.borrow().get(&id) {
|
match tcx.def_map.borrow().get(&id) {
|
||||||
Some(&def::DefPrimTy(ast::TyStr)) => {
|
Some(&def::DefPrimTy(ast::TyStr)) => {
|
||||||
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
|
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
|
||||||
match ptr_ty {
|
return ty::mk_str_slice(tcx, region, a_seq_mutbl);
|
||||||
Uniq => {
|
|
||||||
return constr(ty::mk_str(tcx));
|
|
||||||
}
|
|
||||||
RPtr(r) => {
|
|
||||||
return ty::mk_str_slice(tcx, r, a_seq_mutbl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(&def::DefTrait(trait_def_id)) => {
|
Some(&def::DefTrait(trait_def_id)) => {
|
||||||
let result = ast_path_to_trait_ref(this,
|
let result = ast_path_to_trait_ref(this,
|
||||||
|
@ -716,14 +703,7 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
||||||
let tr = ty::mk_trait(tcx,
|
let tr = ty::mk_trait(tcx,
|
||||||
result,
|
result,
|
||||||
existential_bounds);
|
existential_bounds);
|
||||||
return match ptr_ty {
|
return ty::mk_rptr(tcx, region, ty::mt{mutbl: a_seq_mutbl, ty: tr});
|
||||||
Uniq => {
|
|
||||||
return ty::mk_uniq(tcx, tr);
|
|
||||||
}
|
|
||||||
RPtr(r) => {
|
|
||||||
return ty::mk_rptr(tcx, r, ty::mt{mutbl: a_seq_mutbl, ty: tr});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -824,12 +804,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
||||||
|
|
||||||
let typ = ast_ty_to_builtin_ty(this, rscope, ast_ty).unwrap_or_else(|| {
|
let typ = ast_ty_to_builtin_ty(this, rscope, ast_ty).unwrap_or_else(|| {
|
||||||
match ast_ty.node {
|
match ast_ty.node {
|
||||||
ast::TyNil => ty::mk_nil(this.tcx()),
|
|
||||||
ast::TyBot => unreachable!(),
|
|
||||||
ast::TyUniq(ref ty) => {
|
|
||||||
mk_pointer(this, rscope, ast::MutImmutable, &**ty, Uniq,
|
|
||||||
|ty| ty::mk_uniq(tcx, ty))
|
|
||||||
}
|
|
||||||
ast::TyVec(ref ty) => {
|
ast::TyVec(ref ty) => {
|
||||||
ty::mk_vec(tcx, ast_ty_to_ty(this, rscope, &**ty), None)
|
ty::mk_vec(tcx, ast_ty_to_ty(this, rscope, &**ty), None)
|
||||||
}
|
}
|
||||||
|
@ -842,7 +816,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
||||||
ast::TyRptr(ref region, ref mt) => {
|
ast::TyRptr(ref region, ref mt) => {
|
||||||
let r = opt_ast_region_to_region(this, rscope, ast_ty.span, region);
|
let r = opt_ast_region_to_region(this, rscope, ast_ty.span, region);
|
||||||
debug!("ty_rptr r={}", r.repr(this.tcx()));
|
debug!("ty_rptr r={}", r.repr(this.tcx()));
|
||||||
mk_pointer(this, rscope, mt.mutbl, &*mt.ty, RPtr(r),
|
mk_pointer(this, rscope, mt.mutbl, &*mt.ty, r,
|
||||||
|ty| ty::mk_rptr(tcx, r, ty::mt {ty: ty, mutbl: mt.mutbl}))
|
|ty| ty::mk_rptr(tcx, r, ty::mt {ty: ty, mutbl: mt.mutbl}))
|
||||||
}
|
}
|
||||||
ast::TyTup(ref fields) => {
|
ast::TyTup(ref fields) => {
|
||||||
|
@ -1208,22 +1182,24 @@ fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>(
|
||||||
.filter(|&(_, l)| l != 0)
|
.filter(|&(_, l)| l != 0)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let output_ty = match decl.output.node {
|
let output_ty = match decl.output {
|
||||||
ast::TyBot => ty::FnDiverging,
|
ast::Return(ref output) if output.node == ast::TyInfer =>
|
||||||
ast::TyInfer => ty::FnConverging(this.ty_infer(decl.output.span)),
|
ty::FnConverging(this.ty_infer(output.span)),
|
||||||
_ => ty::FnConverging(match implied_output_region {
|
ast::Return(ref output) =>
|
||||||
|
ty::FnConverging(match implied_output_region {
|
||||||
Some(implied_output_region) => {
|
Some(implied_output_region) => {
|
||||||
let rb = SpecificRscope::new(implied_output_region);
|
let rb = SpecificRscope::new(implied_output_region);
|
||||||
ast_ty_to_ty(this, &rb, &*decl.output)
|
ast_ty_to_ty(this, &rb, &**output)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// All regions must be explicitly specified in the output
|
// All regions must be explicitly specified in the output
|
||||||
// if the lifetime elision rules do not apply. This saves
|
// if the lifetime elision rules do not apply. This saves
|
||||||
// the user from potentially-confusing errors.
|
// the user from potentially-confusing errors.
|
||||||
let rb = UnelidableRscope::new(param_lifetimes);
|
let rb = UnelidableRscope::new(param_lifetimes);
|
||||||
ast_ty_to_ty(this, &rb, &*decl.output)
|
ast_ty_to_ty(this, &rb, &**output)
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
|
ast::NoReturn(_) => ty::FnDiverging
|
||||||
};
|
};
|
||||||
|
|
||||||
(ty::BareFnTy {
|
(ty::BareFnTy {
|
||||||
|
@ -1346,11 +1322,14 @@ pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>(
|
||||||
|
|
||||||
let expected_ret_ty = expected_sig.map(|e| e.output);
|
let expected_ret_ty = expected_sig.map(|e| e.output);
|
||||||
|
|
||||||
let output_ty = match decl.output.node {
|
let output_ty = match decl.output {
|
||||||
ast::TyBot => ty::FnDiverging,
|
ast::Return(ref output) if output.node == ast::TyInfer && expected_ret_ty.is_some() =>
|
||||||
ast::TyInfer if expected_ret_ty.is_some() => expected_ret_ty.unwrap(),
|
expected_ret_ty.unwrap(),
|
||||||
ast::TyInfer => ty::FnConverging(this.ty_infer(decl.output.span)),
|
ast::Return(ref output) if output.node == ast::TyInfer =>
|
||||||
_ => ty::FnConverging(ast_ty_to_ty(this, &rb, &*decl.output))
|
ty::FnConverging(this.ty_infer(output.span)),
|
||||||
|
ast::Return(ref output) =>
|
||||||
|
ty::FnConverging(ast_ty_to_ty(this, &rb, &**output)),
|
||||||
|
ast::NoReturn(_) => ty::FnDiverging
|
||||||
};
|
};
|
||||||
|
|
||||||
ty::ClosureTy {
|
ty::ClosureTy {
|
||||||
|
|
|
@ -556,7 +556,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if let ty::FnConverging(ret_ty) = ret_ty {
|
if let ty::FnConverging(ret_ty) = ret_ty {
|
||||||
fcx.require_type_is_sized(ret_ty, decl.output.span, traits::ReturnType);
|
fcx.require_type_is_sized(ret_ty, decl.output.span(), traits::ReturnType);
|
||||||
fn_sig_tys.push(ret_ty);
|
fn_sig_tys.push(ret_ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2854,7 +2854,6 @@ fn check_lit(fcx: &FnCtxt,
|
||||||
opt_ty.unwrap_or_else(
|
opt_ty.unwrap_or_else(
|
||||||
|| ty::mk_float_var(tcx, fcx.infcx().next_float_var_id()))
|
|| ty::mk_float_var(tcx, fcx.infcx().next_float_var_id()))
|
||||||
}
|
}
|
||||||
ast::LitNil => ty::mk_nil(tcx),
|
|
||||||
ast::LitBool(_) => ty::mk_bool()
|
ast::LitBool(_) => ty::mk_bool()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5486,7 +5485,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
||||||
data.inputs.iter().map(|ty| fcx.to_ty(&**ty)).collect();
|
data.inputs.iter().map(|ty| fcx.to_ty(&**ty)).collect();
|
||||||
|
|
||||||
let tuple_ty =
|
let tuple_ty =
|
||||||
ty::mk_tup_or_nil(fcx.tcx(), input_tys);
|
ty::mk_tup(fcx.tcx(), input_tys);
|
||||||
|
|
||||||
if type_count >= 1 {
|
if type_count >= 1 {
|
||||||
substs.types.push(space, tuple_ty);
|
substs.types.push(space, tuple_ty);
|
||||||
|
|
|
@ -2096,9 +2096,11 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
|
||||||
.map(|a| ty_of_arg(ccx, &rb, a, None))
|
.map(|a| ty_of_arg(ccx, &rb, a, None))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let output = match decl.output.node {
|
let output = match decl.output {
|
||||||
ast::TyBot => ty::FnDiverging,
|
ast::Return(ref ty) =>
|
||||||
_ => ty::FnConverging(ast_ty_to_ty(ccx, &rb, &*decl.output))
|
ty::FnConverging(ast_ty_to_ty(ccx, &rb, &**ty)),
|
||||||
|
ast::NoReturn(_) =>
|
||||||
|
ty::FnDiverging
|
||||||
};
|
};
|
||||||
|
|
||||||
let t_fn = ty::mk_bare_fn(
|
let t_fn = ty::mk_bare_fn(
|
||||||
|
|
|
@ -539,9 +539,11 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres<t
|
||||||
.map(|(a, b)| this.tys(*a, *b))
|
.map(|(a, b)| this.tys(*a, *b))
|
||||||
.collect::<Result<_, _>>()
|
.collect::<Result<_, _>>()
|
||||||
.map(|ts| ty::mk_tup(tcx, ts))
|
.map(|ts| ty::mk_tup(tcx, ts))
|
||||||
} else {
|
} else if as_.len() != 0 && bs.len() != 0 {
|
||||||
Err(ty::terr_tuple_size(
|
Err(ty::terr_tuple_size(
|
||||||
expected_found(this, as_.len(), bs.len())))
|
expected_found(this, as_.len(), bs.len())))
|
||||||
|
} else {
|
||||||
|
Err(ty::terr_sorts(expected_found(this, a, b)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -973,8 +973,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||||
&anon_nums, ®ion_names);
|
&anon_nums, ®ion_names);
|
||||||
inputs = self.rebuild_args_ty(inputs.as_slice(), lifetime,
|
inputs = self.rebuild_args_ty(inputs.as_slice(), lifetime,
|
||||||
&anon_nums, ®ion_names);
|
&anon_nums, ®ion_names);
|
||||||
output = self.rebuild_arg_ty_or_output(&*output, lifetime,
|
output = self.rebuild_output(&output, lifetime, &anon_nums, ®ion_names);
|
||||||
&anon_nums, ®ion_names);
|
|
||||||
ty_params = self.rebuild_ty_params(ty_params, lifetime,
|
ty_params = self.rebuild_ty_params(ty_params, lifetime,
|
||||||
®ion_names);
|
®ion_names);
|
||||||
}
|
}
|
||||||
|
@ -989,7 +988,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||||
let new_fn_decl = ast::FnDecl {
|
let new_fn_decl = ast::FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: output,
|
output: output,
|
||||||
cf: self.fn_decl.cf,
|
|
||||||
variadic: self.fn_decl.variadic
|
variadic: self.fn_decl.variadic
|
||||||
};
|
};
|
||||||
(new_fn_decl, expl_self_opt, generics)
|
(new_fn_decl, expl_self_opt, generics)
|
||||||
|
@ -1206,6 +1204,18 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||||
new_inputs
|
new_inputs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rebuild_output(&self, ty: &ast::FunctionRetTy,
|
||||||
|
lifetime: ast::Lifetime,
|
||||||
|
anon_nums: &HashSet<uint>,
|
||||||
|
region_names: &HashSet<ast::Name>) -> ast::FunctionRetTy {
|
||||||
|
match *ty {
|
||||||
|
ast::Return(ref ret_ty) => ast::Return(
|
||||||
|
self.rebuild_arg_ty_or_output(&**ret_ty, lifetime, anon_nums, region_names)
|
||||||
|
),
|
||||||
|
ast::NoReturn(span) => ast::NoReturn(span)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn rebuild_arg_ty_or_output(&self,
|
fn rebuild_arg_ty_or_output(&self,
|
||||||
ty: &ast::Ty,
|
ty: &ast::Ty,
|
||||||
lifetime: ast::Lifetime,
|
lifetime: ast::Lifetime,
|
||||||
|
@ -1301,7 +1311,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||||
ty_queue.push(&*mut_ty.ty);
|
ty_queue.push(&*mut_ty.ty);
|
||||||
}
|
}
|
||||||
ast::TyVec(ref ty) |
|
ast::TyVec(ref ty) |
|
||||||
ast::TyUniq(ref ty) |
|
|
||||||
ast::TyFixedLengthVec(ref ty, _) => {
|
ast::TyFixedLengthVec(ref ty, _) => {
|
||||||
ty_queue.push(&**ty);
|
ty_queue.push(&**ty);
|
||||||
}
|
}
|
||||||
|
@ -1338,7 +1347,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ast::TyVec(ty) => ast::TyVec(build_to(ty, to)),
|
ast::TyVec(ty) => ast::TyVec(build_to(ty, to)),
|
||||||
ast::TyUniq(ty) => ast::TyUniq(build_to(ty, to)),
|
|
||||||
ast::TyFixedLengthVec(ty, e) => {
|
ast::TyFixedLengthVec(ty, e) => {
|
||||||
ast::TyFixedLengthVec(build_to(ty, to), e)
|
ast::TyFixedLengthVec(build_to(ty, to), e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -710,8 +710,7 @@ impl Clean<Item> for ast::Method {
|
||||||
inputs: Arguments {
|
inputs: Arguments {
|
||||||
values: inputs.iter().map(|x| x.clean(cx)).collect(),
|
values: inputs.iter().map(|x| x.clean(cx)).collect(),
|
||||||
},
|
},
|
||||||
output: (self.pe_fn_decl().output.clean(cx)),
|
output: self.pe_fn_decl().output.clean(cx),
|
||||||
cf: self.pe_fn_decl().cf.clean(cx),
|
|
||||||
attrs: Vec::new()
|
attrs: Vec::new()
|
||||||
};
|
};
|
||||||
Item {
|
Item {
|
||||||
|
@ -749,8 +748,7 @@ impl Clean<Item> for ast::TypeMethod {
|
||||||
inputs: Arguments {
|
inputs: Arguments {
|
||||||
values: inputs.iter().map(|x| x.clean(cx)).collect(),
|
values: inputs.iter().map(|x| x.clean(cx)).collect(),
|
||||||
},
|
},
|
||||||
output: (self.decl.output.clean(cx)),
|
output: self.decl.output.clean(cx),
|
||||||
cf: self.decl.cf.clean(cx),
|
|
||||||
attrs: Vec::new()
|
attrs: Vec::new()
|
||||||
};
|
};
|
||||||
Item {
|
Item {
|
||||||
|
@ -840,8 +838,7 @@ impl Clean<ClosureDecl> for ast::ClosureTy {
|
||||||
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
||||||
pub struct FnDecl {
|
pub struct FnDecl {
|
||||||
pub inputs: Arguments,
|
pub inputs: Arguments,
|
||||||
pub output: Type,
|
pub output: FunctionRetTy,
|
||||||
pub cf: RetStyle,
|
|
||||||
pub attrs: Vec<Attribute>,
|
pub attrs: Vec<Attribute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +854,6 @@ impl Clean<FnDecl> for ast::FnDecl {
|
||||||
values: self.inputs.clean(cx),
|
values: self.inputs.clean(cx),
|
||||||
},
|
},
|
||||||
output: self.output.clean(cx),
|
output: self.output.clean(cx),
|
||||||
cf: self.cf.clean(cx),
|
|
||||||
attrs: Vec::new()
|
attrs: Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -884,8 +880,7 @@ impl<'a> Clean<FnDecl> for (ast::DefId, &'a ty::FnSig) {
|
||||||
let _ = names.next();
|
let _ = names.next();
|
||||||
}
|
}
|
||||||
FnDecl {
|
FnDecl {
|
||||||
output: sig.output.clean(cx),
|
output: Return(sig.output.clean(cx)),
|
||||||
cf: Return,
|
|
||||||
attrs: Vec::new(),
|
attrs: Vec::new(),
|
||||||
inputs: Arguments {
|
inputs: Arguments {
|
||||||
values: sig.inputs.iter().map(|t| {
|
values: sig.inputs.iter().map(|t| {
|
||||||
|
@ -918,16 +913,16 @@ impl Clean<Argument> for ast::Arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
||||||
pub enum RetStyle {
|
pub enum FunctionRetTy {
|
||||||
NoReturn,
|
Return(Type),
|
||||||
Return
|
NoReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<RetStyle> for ast::RetStyle {
|
impl Clean<FunctionRetTy> for ast::FunctionRetTy {
|
||||||
fn clean(&self, _: &DocContext) -> RetStyle {
|
fn clean(&self, cx: &DocContext) -> FunctionRetTy {
|
||||||
match *self {
|
match *self {
|
||||||
ast::Return => Return,
|
ast::Return(ref typ) => Return(typ.clean(cx)),
|
||||||
ast::NoReturn => NoReturn
|
ast::NoReturn(_) => NoReturn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1124,7 +1119,6 @@ pub enum PrimitiveType {
|
||||||
F32, F64,
|
F32, F64,
|
||||||
Char,
|
Char,
|
||||||
Bool,
|
Bool,
|
||||||
Unit,
|
|
||||||
Str,
|
Str,
|
||||||
Slice,
|
Slice,
|
||||||
PrimitiveTuple,
|
PrimitiveTuple,
|
||||||
|
@ -1156,7 +1150,6 @@ impl PrimitiveType {
|
||||||
"u32" => Some(U32),
|
"u32" => Some(U32),
|
||||||
"u64" => Some(U64),
|
"u64" => Some(U64),
|
||||||
"bool" => Some(Bool),
|
"bool" => Some(Bool),
|
||||||
"unit" => Some(Unit),
|
|
||||||
"char" => Some(Char),
|
"char" => Some(Char),
|
||||||
"str" => Some(Str),
|
"str" => Some(Str),
|
||||||
"f32" => Some(F32),
|
"f32" => Some(F32),
|
||||||
|
@ -1205,17 +1198,13 @@ impl PrimitiveType {
|
||||||
Str => "str",
|
Str => "str",
|
||||||
Bool => "bool",
|
Bool => "bool",
|
||||||
Char => "char",
|
Char => "char",
|
||||||
Unit => "()",
|
|
||||||
Slice => "slice",
|
Slice => "slice",
|
||||||
PrimitiveTuple => "tuple",
|
PrimitiveTuple => "tuple",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_url_str(&self) -> &'static str {
|
pub fn to_url_str(&self) -> &'static str {
|
||||||
match *self {
|
self.to_string()
|
||||||
Unit => "unit",
|
|
||||||
other => other.to_string(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a rustdoc-specific node id for primitive types.
|
/// Creates a rustdoc-specific node id for primitive types.
|
||||||
|
@ -1230,12 +1219,10 @@ impl Clean<Type> for ast::Ty {
|
||||||
fn clean(&self, cx: &DocContext) -> Type {
|
fn clean(&self, cx: &DocContext) -> Type {
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
match self.node {
|
match self.node {
|
||||||
TyNil => Primitive(Unit),
|
|
||||||
TyPtr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
|
TyPtr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
|
||||||
TyRptr(ref l, ref m) =>
|
TyRptr(ref l, ref m) =>
|
||||||
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
|
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
|
||||||
type_: box m.ty.clean(cx)},
|
type_: box m.ty.clean(cx)},
|
||||||
TyUniq(ref ty) => Unique(box ty.clean(cx)),
|
|
||||||
TyVec(ref ty) => Vector(box ty.clean(cx)),
|
TyVec(ref ty) => Vector(box ty.clean(cx)),
|
||||||
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
|
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
|
||||||
e.span.to_src(cx)),
|
e.span.to_src(cx)),
|
||||||
|
@ -1247,7 +1234,6 @@ impl Clean<Type> for ast::Ty {
|
||||||
TyProc(ref c) => Proc(box c.clean(cx)),
|
TyProc(ref c) => Proc(box c.clean(cx)),
|
||||||
TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
|
TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
|
||||||
TyParen(ref ty) => ty.clean(cx),
|
TyParen(ref ty) => ty.clean(cx),
|
||||||
TyBot => Bottom,
|
|
||||||
ref x => panic!("Unimplemented type {}", x),
|
ref x => panic!("Unimplemented type {}", x),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1256,7 +1242,6 @@ impl Clean<Type> for ast::Ty {
|
||||||
impl Clean<Type> for ty::t {
|
impl Clean<Type> for ty::t {
|
||||||
fn clean(&self, cx: &DocContext) -> Type {
|
fn clean(&self, cx: &DocContext) -> Type {
|
||||||
match ty::get(*self).sty {
|
match ty::get(*self).sty {
|
||||||
ty::ty_nil => Primitive(Unit),
|
|
||||||
ty::ty_bool => Primitive(Bool),
|
ty::ty_bool => Primitive(Bool),
|
||||||
ty::ty_char => Primitive(Char),
|
ty::ty_char => Primitive(Char),
|
||||||
ty::ty_int(ast::TyI) => Primitive(Int),
|
ty::ty_int(ast::TyI) => Primitive(Int),
|
||||||
|
@ -1342,7 +1327,7 @@ impl Clean<Type> for ty::t {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::ty_unboxed_closure(..) => Primitive(Unit), // FIXME(pcwalton)
|
ty::ty_unboxed_closure(..) => Tuple(vec![]), // FIXME(pcwalton)
|
||||||
|
|
||||||
ty::ty_infer(..) => panic!("ty_infer"),
|
ty::ty_infer(..) => panic!("ty_infer"),
|
||||||
ty::ty_open(..) => panic!("ty_open"),
|
ty::ty_open(..) => panic!("ty_open"),
|
||||||
|
@ -2041,7 +2026,6 @@ fn lit_to_string(lit: &ast::Lit) -> String {
|
||||||
ast::LitFloat(ref f, _t) => f.get().to_string(),
|
ast::LitFloat(ref f, _t) => f.get().to_string(),
|
||||||
ast::LitFloatUnsuffixed(ref f) => f.get().to_string(),
|
ast::LitFloatUnsuffixed(ref f) => f.get().to_string(),
|
||||||
ast::LitBool(b) => b.to_string(),
|
ast::LitBool(b) => b.to_string(),
|
||||||
ast::LitNil => "".to_string(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -393,10 +393,7 @@ impl fmt::Show for clean::Type {
|
||||||
format!("<{:#}>", decl.lifetimes)
|
format!("<{:#}>", decl.lifetimes)
|
||||||
},
|
},
|
||||||
args = decl.decl.inputs,
|
args = decl.decl.inputs,
|
||||||
arrow = match decl.decl.output {
|
arrow = decl.decl.output,
|
||||||
clean::Primitive(clean::Unit) => "".to_string(),
|
|
||||||
_ => format!(" -> {}", decl.decl.output),
|
|
||||||
},
|
|
||||||
bounds = {
|
bounds = {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
for bound in decl.bounds.iter() {
|
for bound in decl.bounds.iter() {
|
||||||
|
@ -435,10 +432,7 @@ impl fmt::Show for clean::Type {
|
||||||
": {}",
|
": {}",
|
||||||
m.collect::<Vec<String>>().connect(" + "))
|
m.collect::<Vec<String>>().connect(" + "))
|
||||||
},
|
},
|
||||||
arrow = match decl.decl.output {
|
arrow = decl.decl.output)
|
||||||
clean::Primitive(clean::Unit) => "".to_string(),
|
|
||||||
_ => format!(" -> {}", decl.decl.output)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
clean::BareFunction(ref decl) => {
|
clean::BareFunction(ref decl) => {
|
||||||
write!(f, "{}{}fn{}{}",
|
write!(f, "{}{}fn{}{}",
|
||||||
|
@ -514,14 +508,19 @@ impl fmt::Show for clean::Arguments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Show for clean::FunctionRetTy {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
|
||||||
|
clean::Return(ref ty) => write!(f, " -> {}", ty),
|
||||||
|
clean::NoReturn => write!(f, " -> !")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::FnDecl {
|
impl fmt::Show for clean::FnDecl {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "({args}){arrow}",
|
write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
|
||||||
args = self.inputs,
|
|
||||||
arrow = match self.output {
|
|
||||||
clean::Primitive(clean::Unit) => "".to_string(),
|
|
||||||
_ => format!(" -> {}", self.output),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,12 +550,7 @@ impl<'a> fmt::Show for Method<'a> {
|
||||||
}
|
}
|
||||||
args.push_str(format!("{}", input.type_).as_slice());
|
args.push_str(format!("{}", input.type_).as_slice());
|
||||||
}
|
}
|
||||||
write!(f, "({args}){arrow}",
|
write!(f, "({args}){arrow}", args = args, arrow = d.output)
|
||||||
args = args,
|
|
||||||
arrow = match d.output {
|
|
||||||
clean::Primitive(clean::Unit) => "".to_string(),
|
|
||||||
_ => format!(" -> {}", d.output),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -893,7 +893,6 @@ pub enum Lit_ {
|
||||||
LitInt(u64, LitIntType),
|
LitInt(u64, LitIntType),
|
||||||
LitFloat(InternedString, FloatTy),
|
LitFloat(InternedString, FloatTy),
|
||||||
LitFloatUnsuffixed(InternedString),
|
LitFloatUnsuffixed(InternedString),
|
||||||
LitNil,
|
|
||||||
LitBool(bool),
|
LitBool(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1086,12 +1085,6 @@ pub struct BareFnTy {
|
||||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||||
/// The different kinds of types recognized by the compiler
|
/// The different kinds of types recognized by the compiler
|
||||||
pub enum Ty_ {
|
pub enum Ty_ {
|
||||||
/// The unit type (`()`)
|
|
||||||
TyNil,
|
|
||||||
/// The bottom type (`!`)
|
|
||||||
TyBot,
|
|
||||||
TyUniq(P<Ty>),
|
|
||||||
/// An array (`[T]`)
|
|
||||||
TyVec(P<Ty>),
|
TyVec(P<Ty>),
|
||||||
/// A fixed length array (`[T, ..n]`)
|
/// A fixed length array (`[T, ..n]`)
|
||||||
TyFixedLengthVec(P<Ty>, P<Expr>),
|
TyFixedLengthVec(P<Ty>, P<Expr>),
|
||||||
|
@ -1175,8 +1168,7 @@ impl Arg {
|
||||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||||
pub struct FnDecl {
|
pub struct FnDecl {
|
||||||
pub inputs: Vec<Arg>,
|
pub inputs: Vec<Arg>,
|
||||||
pub output: P<Ty>,
|
pub output: FunctionRetTy,
|
||||||
pub cf: RetStyle,
|
|
||||||
pub variadic: bool
|
pub variadic: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1198,12 +1190,21 @@ impl fmt::Show for FnStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||||
pub enum RetStyle {
|
pub enum FunctionRetTy {
|
||||||
/// Functions with return type ! that always
|
/// Functions with return type ! that always
|
||||||
/// raise an error or exit (i.e. never return to the caller)
|
/// raise an error or exit (i.e. never return to the caller)
|
||||||
NoReturn,
|
NoReturn(Span),
|
||||||
/// Everything else
|
/// Everything else
|
||||||
Return,
|
Return(P<Ty>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FunctionRetTy {
|
||||||
|
pub fn span(&self) -> Span {
|
||||||
|
match *self {
|
||||||
|
NoReturn(span) => span,
|
||||||
|
Return(ref ty) => ty.span
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the kind of 'self' associated with a method
|
/// Represents the kind of 'self' associated with a method
|
||||||
|
|
|
@ -248,7 +248,7 @@ impl DummyResult {
|
||||||
pub fn raw_expr(sp: Span) -> P<ast::Expr> {
|
pub fn raw_expr(sp: Span) -> P<ast::Expr> {
|
||||||
P(ast::Expr {
|
P(ast::Expr {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::ExprLit(P(codemap::respan(sp, ast::LitNil))),
|
node: ast::ExprLit(P(codemap::respan(sp, ast::LitBool(false)))),
|
||||||
span: sp,
|
span: sp,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,11 +54,9 @@ pub trait AstBuilder {
|
||||||
fn ty_ptr(&self, span: Span,
|
fn ty_ptr(&self, span: Span,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
mutbl: ast::Mutability) -> P<ast::Ty>;
|
mutbl: ast::Mutability) -> P<ast::Ty>;
|
||||||
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty>;
|
|
||||||
|
|
||||||
fn ty_option(&self, ty: P<ast::Ty>) -> 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_infer(&self, sp: Span) -> P<ast::Ty>;
|
||||||
fn ty_nil(&self) -> P<ast::Ty>;
|
|
||||||
|
|
||||||
fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ;
|
fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ;
|
||||||
fn ty_vars_global(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ;
|
fn ty_vars_global(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ;
|
||||||
|
@ -377,9 +375,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.ty(span,
|
self.ty(span,
|
||||||
ast::TyPtr(self.ty_mt(ty, mutbl)))
|
ast::TyPtr(self.ty_mt(ty, mutbl)))
|
||||||
}
|
}
|
||||||
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
|
|
||||||
self.ty(span, ast::TyUniq(ty))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
|
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
|
||||||
self.ty_path(
|
self.ty_path(
|
||||||
|
@ -406,14 +401,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.ty(span, ast::TyInfer)
|
self.ty(span, ast::TyInfer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_nil(&self) -> P<ast::Ty> {
|
|
||||||
P(ast::Ty {
|
|
||||||
id: ast::DUMMY_NODE_ID,
|
|
||||||
node: ast::TyNil,
|
|
||||||
span: DUMMY_SP,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn typaram(&self,
|
fn typaram(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: ast::Ident,
|
id: ast::Ident,
|
||||||
|
@ -809,8 +796,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.pat(span, pat)
|
self.pat(span, pat)
|
||||||
}
|
}
|
||||||
fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
|
fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
|
||||||
let pat = ast::PatTup(pats);
|
self.pat(span, ast::PatTup(pats))
|
||||||
self.pat(span, pat)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
|
||||||
|
@ -931,11 +917,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME unused self
|
// FIXME unused self
|
||||||
fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl> {
|
fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> {
|
||||||
P(ast::FnDecl {
|
P(ast::FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: output,
|
output: ast::Return(output),
|
||||||
cf: ast::Return,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
|
||||||
ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => {
|
ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => {
|
||||||
accumulator.push_str(format!("-{}", i).as_slice());
|
accumulator.push_str(format!("-{}", i).as_slice());
|
||||||
}
|
}
|
||||||
ast::LitNil => {}
|
|
||||||
ast::LitBool(b) => {
|
ast::LitBool(b) => {
|
||||||
accumulator.push_str(format!("{}", b).as_slice());
|
accumulator.push_str(format!("{}", b).as_slice());
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use ast::{MetaItem, Item, Expr, ExprRet, MutMutable, LitNil};
|
use ast::{MetaItem, Item, Expr, ExprRet, MutMutable};
|
||||||
use codemap::Span;
|
use codemap::Span;
|
||||||
use ext::base::ExtCtxt;
|
use ext::base::ExtCtxt;
|
||||||
use ext::build::AstBuilder;
|
use ext::build::AstBuilder;
|
||||||
|
@ -186,7 +186,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
if stmts.is_empty() {
|
if stmts.is_empty() {
|
||||||
let ret_ok = cx.expr(trait_span,
|
let ret_ok = cx.expr(trait_span,
|
||||||
ExprRet(Some(cx.expr_ok(trait_span,
|
ExprRet(Some(cx.expr_ok(trait_span,
|
||||||
cx.expr_lit(trait_span, LitNil)))));
|
cx.expr_tuple(trait_span, vec![])))));
|
||||||
stmts.push(cx.stmt_expr(ret_ok));
|
stmts.push(cx.stmt_expr(ret_ok));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
if stmts.len() == 0 {
|
if stmts.len() == 0 {
|
||||||
let ret_ok = cx.expr(trait_span,
|
let ret_ok = cx.expr(trait_span,
|
||||||
ExprRet(Some(cx.expr_ok(trait_span,
|
ExprRet(Some(cx.expr_ok(trait_span,
|
||||||
cx.expr_lit(trait_span, LitNil)))));
|
cx.expr_tuple(trait_span, vec![])))));
|
||||||
stmts.push(cx.stmt_expr(ret_ok));
|
stmts.push(cx.stmt_expr(ret_ok));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -922,7 +922,7 @@ impl<'a> MethodDef<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here is the pat = `(&VariantK, &VariantK, ...)`
|
// Here is the pat = `(&VariantK, &VariantK, ...)`
|
||||||
let single_pat = cx.pat(sp, ast::PatTup(subpats));
|
let single_pat = cx.pat_tuple(sp, subpats);
|
||||||
|
|
||||||
// For the BodyK, we need to delegate to our caller,
|
// For the BodyK, we need to delegate to our caller,
|
||||||
// passing it an EnumMatching to indicate which case
|
// passing it an EnumMatching to indicate which case
|
||||||
|
|
|
@ -152,14 +152,9 @@ impl<'a> Ty<'a> {
|
||||||
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
|
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
|
||||||
}
|
}
|
||||||
Tuple(ref fields) => {
|
Tuple(ref fields) => {
|
||||||
let ty = if fields.is_empty() {
|
let ty = ast::TyTup(fields.iter()
|
||||||
ast::TyNil
|
|
||||||
} else {
|
|
||||||
ast::TyTup(fields.iter()
|
|
||||||
.map(|f| f.to_ty(cx, span, self_ty, self_generics))
|
.map(|f| f.to_ty(cx, span, self_ty, self_generics))
|
||||||
.collect())
|
.collect());
|
||||||
};
|
|
||||||
|
|
||||||
cx.ty(span, ty)
|
cx.ty(span, ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
|
||||||
// `_ => [<elseopt> | ()]`
|
// `_ => [<elseopt> | ()]`
|
||||||
let else_arm = {
|
let else_arm = {
|
||||||
let pat_under = fld.cx.pat_wild(span);
|
let pat_under = fld.cx.pat_wild(span);
|
||||||
let else_expr = elseopt.unwrap_or_else(|| fld.cx.expr_lit(span, ast::LitNil));
|
let else_expr = elseopt.unwrap_or_else(|| fld.cx.expr_tuple(span, vec![]));
|
||||||
fld.cx.arm(span, vec![pat_under], else_expr)
|
fld.cx.arm(span, vec![pat_under], else_expr)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -654,7 +654,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
//
|
//
|
||||||
// But the nested match expression is proved to perform not as well
|
// But the nested match expression is proved to perform not as well
|
||||||
// as series of let's; the first approach does.
|
// as series of let's; the first approach does.
|
||||||
let pat = self.ecx.pat(self.fmtsp, ast::PatTup(pats));
|
let pat = self.ecx.pat_tuple(self.fmtsp, pats);
|
||||||
let arm = self.ecx.arm(self.fmtsp, vec!(pat), body);
|
let arm = self.ecx.arm(self.fmtsp, vec!(pat), body);
|
||||||
let head = self.ecx.expr(self.fmtsp, ast::ExprTup(heads));
|
let head = self.ecx.expr(self.fmtsp, ast::ExprTup(heads));
|
||||||
self.ecx.expr_match(self.fmtsp, head, vec!(arm))
|
self.ecx.expr_match(self.fmtsp, head, vec!(arm))
|
||||||
|
|
|
@ -391,8 +391,7 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
||||||
t.map(|Ty {id, node, span}| Ty {
|
t.map(|Ty {id, node, span}| Ty {
|
||||||
id: fld.new_id(id),
|
id: fld.new_id(id),
|
||||||
node: match node {
|
node: match node {
|
||||||
TyNil | TyBot | TyInfer => node,
|
TyInfer => node,
|
||||||
TyUniq(ty) => TyUniq(fld.fold_ty(ty)),
|
|
||||||
TyVec(ty) => TyVec(fld.fold_ty(ty)),
|
TyVec(ty) => TyVec(fld.fold_ty(ty)),
|
||||||
TyPtr(mt) => TyPtr(fld.fold_mt(mt)),
|
TyPtr(mt) => TyPtr(fld.fold_mt(mt)),
|
||||||
TyRptr(region, mt) => {
|
TyRptr(region, mt) => {
|
||||||
|
@ -706,10 +705,12 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
|
pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
|
||||||
decl.map(|FnDecl {inputs, output, cf, variadic}| FnDecl {
|
decl.map(|FnDecl {inputs, output, variadic}| FnDecl {
|
||||||
inputs: inputs.move_map(|x| fld.fold_arg(x)),
|
inputs: inputs.move_map(|x| fld.fold_arg(x)),
|
||||||
output: fld.fold_ty(output),
|
output: match output {
|
||||||
cf: cf,
|
Return(ty) => Return(fld.fold_ty(ty)),
|
||||||
|
NoReturn(span) => NoReturn(span)
|
||||||
|
},
|
||||||
variadic: variadic
|
variadic: variadic
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1146,10 +1147,12 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
|
||||||
attrs: attrs.move_map(|x| folder.fold_attribute(x)),
|
attrs: attrs.move_map(|x| folder.fold_attribute(x)),
|
||||||
node: match node {
|
node: match node {
|
||||||
ForeignItemFn(fdec, generics) => {
|
ForeignItemFn(fdec, generics) => {
|
||||||
ForeignItemFn(fdec.map(|FnDecl {inputs, output, cf, variadic}| FnDecl {
|
ForeignItemFn(fdec.map(|FnDecl {inputs, output, variadic}| FnDecl {
|
||||||
inputs: inputs.move_map(|a| folder.fold_arg(a)),
|
inputs: inputs.move_map(|a| folder.fold_arg(a)),
|
||||||
output: folder.fold_ty(output),
|
output: match output {
|
||||||
cf: cf,
|
Return(ty) => Return(folder.fold_ty(ty)),
|
||||||
|
NoReturn(span) => NoReturn(span)
|
||||||
|
},
|
||||||
variadic: variadic
|
variadic: variadic
|
||||||
}), folder.fold_generics(generics))
|
}), folder.fold_generics(generics))
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||||
|
|
||||||
#![allow(unknown_features)]
|
#![allow(unknown_features)]
|
||||||
#![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)]
|
#![feature(if_let, macro_rules, globs, default_type_params, phase, slicing_syntax)]
|
||||||
#![feature(quote, struct_variant, unsafe_destructor, import_shadowing)]
|
#![feature(quote, struct_variant, unsafe_destructor, import_shadowing)]
|
||||||
|
|
||||||
extern crate arena;
|
extern crate arena;
|
||||||
|
|
|
@ -1037,10 +1037,9 @@ mod test {
|
||||||
}),
|
}),
|
||||||
id: ast::DUMMY_NODE_ID
|
id: ast::DUMMY_NODE_ID
|
||||||
}),
|
}),
|
||||||
output: P(ast::Ty{id: ast::DUMMY_NODE_ID,
|
output: ast::Return(P(ast::Ty{id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::TyNil,
|
node: ast::TyTup(vec![]),
|
||||||
span:sp(15,15)}), // not sure
|
span:sp(15,15)})), // not sure
|
||||||
cf: ast::Return,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
}),
|
}),
|
||||||
ast::NormalFn,
|
ast::NormalFn,
|
||||||
|
|
|
@ -17,8 +17,8 @@ Obsolete syntax that becomes too hard to parse can be
|
||||||
removed.
|
removed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use ast::{Expr, ExprLit, LitNil};
|
use ast::{Expr, ExprTup};
|
||||||
use codemap::{Span, respan};
|
use codemap::Span;
|
||||||
use parse::parser;
|
use parse::parser;
|
||||||
use parse::token;
|
use parse::token;
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
|
@ -96,7 +96,7 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
|
||||||
/// a placeholder expression
|
/// a placeholder expression
|
||||||
fn obsolete_expr(&mut self, sp: Span, kind: ObsoleteSyntax) -> P<Expr> {
|
fn obsolete_expr(&mut self, sp: Span, kind: ObsoleteSyntax) -> P<Expr> {
|
||||||
self.obsolete(sp, kind);
|
self.obsolete(sp, kind);
|
||||||
self.mk_expr(sp.lo, sp.hi, ExprLit(P(respan(sp, LitNil))))
|
self.mk_expr(sp.lo, sp.hi, ExprTup(vec![]))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report(&mut self,
|
fn report(&mut self,
|
||||||
|
|
|
@ -30,13 +30,13 @@ use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field, FnDecl};
|
||||||
use ast::{Once, Many};
|
use ast::{Once, Many};
|
||||||
use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
|
use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
|
||||||
use ast::{FnOnceUnboxedClosureKind};
|
use ast::{FnOnceUnboxedClosureKind};
|
||||||
use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod};
|
use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod, FunctionRetTy};
|
||||||
use ast::{Ident, NormalFn, Inherited, ImplItem, Item, Item_, ItemStatic};
|
use ast::{Ident, NormalFn, Inherited, ImplItem, Item, Item_, ItemStatic};
|
||||||
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
|
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
|
||||||
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy};
|
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy};
|
||||||
use ast::{LifetimeDef, Lit, Lit_};
|
use ast::{LifetimeDef, Lit, Lit_};
|
||||||
use ast::{LitBool, LitChar, LitByte, LitBinary};
|
use ast::{LitBool, LitChar, LitByte, LitBinary};
|
||||||
use ast::{LitNil, LitStr, LitInt, Local, LocalLet};
|
use ast::{LitStr, LitInt, Local, LocalLet};
|
||||||
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchNormal};
|
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchNormal};
|
||||||
use ast::{Method, MutTy, BiMul, Mutability};
|
use ast::{Method, MutTy, BiMul, Mutability};
|
||||||
use ast::{MethodImplItem, NamedField, UnNeg, NoReturn, UnNot};
|
use ast::{MethodImplItem, NamedField, UnNeg, NoReturn, UnNot};
|
||||||
|
@ -44,18 +44,18 @@ use ast::{Pat, PatEnum, PatIdent, PatLit, PatRange, PatRegion, PatStruct};
|
||||||
use ast::{PatTup, PatBox, PatWild, PatWildMulti, PatWildSingle};
|
use ast::{PatTup, PatBox, PatWild, PatWildMulti, PatWildSingle};
|
||||||
use ast::{PolyTraitRef};
|
use ast::{PolyTraitRef};
|
||||||
use ast::{QPath, RequiredMethod};
|
use ast::{QPath, RequiredMethod};
|
||||||
use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl};
|
use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
|
||||||
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
|
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
|
||||||
use ast::{StructVariantKind, BiSub};
|
use ast::{StructVariantKind, BiSub};
|
||||||
use ast::StrStyle;
|
use ast::StrStyle;
|
||||||
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
|
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
|
||||||
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
|
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
|
||||||
use ast::{TtDelimited, TtSequence, TtToken};
|
use ast::{TtDelimited, TtSequence, TtToken};
|
||||||
use ast::{TupleVariantKind, Ty, Ty_, TyBot};
|
use ast::{TupleVariantKind, Ty, Ty_};
|
||||||
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
|
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
|
||||||
use ast::{TyTypeof, TyInfer, TypeMethod};
|
use ast::{TyTypeof, TyInfer, TypeMethod};
|
||||||
use ast::{TyNil, TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath};
|
use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath};
|
||||||
use ast::{TyRptr, TyTup, TyU32, TyUniq, TyVec, UnUniq};
|
use ast::{TyRptr, TyTup, TyU32, TyVec, UnUniq};
|
||||||
use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind};
|
use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind};
|
||||||
use ast::{UnnamedField, UnsafeBlock};
|
use ast::{UnnamedField, UnsafeBlock};
|
||||||
use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
|
use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
|
||||||
|
@ -1066,11 +1066,10 @@ impl<'a> Parser<'a> {
|
||||||
self.expect_keyword(keywords::Fn);
|
self.expect_keyword(keywords::Fn);
|
||||||
let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
|
let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
|
||||||
let (inputs, variadic) = self.parse_fn_args(false, true);
|
let (inputs, variadic) = self.parse_fn_args(false, true);
|
||||||
let (ret_style, ret_ty) = self.parse_ret_ty();
|
let ret_ty = self.parse_ret_ty();
|
||||||
let decl = P(FnDecl {
|
let decl = P(FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: ret_ty,
|
output: ret_ty,
|
||||||
cf: ret_style,
|
|
||||||
variadic: variadic
|
variadic: variadic
|
||||||
});
|
});
|
||||||
TyBareFn(P(BareFnTy {
|
TyBareFn(P(BareFnTy {
|
||||||
|
@ -1100,11 +1099,10 @@ impl<'a> Parser<'a> {
|
||||||
let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
|
let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
|
||||||
let (inputs, variadic) = self.parse_fn_args(false, false);
|
let (inputs, variadic) = self.parse_fn_args(false, false);
|
||||||
let bounds = self.parse_colon_then_ty_param_bounds();
|
let bounds = self.parse_colon_then_ty_param_bounds();
|
||||||
let (ret_style, ret_ty) = self.parse_ret_ty();
|
let ret_ty = self.parse_ret_ty();
|
||||||
let decl = P(FnDecl {
|
let decl = P(FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: ret_ty,
|
output: ret_ty,
|
||||||
cf: ret_style,
|
|
||||||
variadic: variadic
|
variadic: variadic
|
||||||
});
|
});
|
||||||
TyProc(P(ClosureTy {
|
TyProc(P(ClosureTy {
|
||||||
|
@ -1200,11 +1198,10 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let bounds = self.parse_colon_then_ty_param_bounds();
|
let bounds = self.parse_colon_then_ty_param_bounds();
|
||||||
|
|
||||||
let (return_style, output) = self.parse_ret_ty();
|
let output = self.parse_ret_ty();
|
||||||
let decl = P(FnDecl {
|
let decl = P(FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: output,
|
output: output,
|
||||||
cf: return_style,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1384,31 +1381,20 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse optional return type [ -> TY ] in function decl
|
/// Parse optional return type [ -> TY ] in function decl
|
||||||
pub fn parse_ret_ty(&mut self) -> (RetStyle, P<Ty>) {
|
pub fn parse_ret_ty(&mut self) -> FunctionRetTy {
|
||||||
return if self.eat(&token::RArrow) {
|
if self.eat(&token::RArrow) {
|
||||||
let lo = self.span.lo;
|
|
||||||
if self.eat(&token::Not) {
|
if self.eat(&token::Not) {
|
||||||
(
|
NoReturn(self.span)
|
||||||
NoReturn,
|
|
||||||
P(Ty {
|
|
||||||
id: ast::DUMMY_NODE_ID,
|
|
||||||
node: TyBot,
|
|
||||||
span: mk_sp(lo, self.last_span.hi)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
(Return, self.parse_ty(true))
|
Return(self.parse_ty(true))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let pos = self.span.lo;
|
let pos = self.span.lo;
|
||||||
(
|
Return(P(Ty {
|
||||||
Return,
|
|
||||||
P(Ty {
|
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: TyNil,
|
node: TyTup(vec![]),
|
||||||
span: mk_sp(pos, pos),
|
span: mk_sp(pos, pos),
|
||||||
})
|
}))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1423,33 +1409,28 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let t = if self.token == token::OpenDelim(token::Paren) {
|
let t = if self.token == token::OpenDelim(token::Paren) {
|
||||||
self.bump();
|
self.bump();
|
||||||
if self.token == token::CloseDelim(token::Paren) {
|
|
||||||
self.bump();
|
|
||||||
TyNil
|
|
||||||
} else {
|
|
||||||
// (t) is a parenthesized ty
|
// (t) is a parenthesized ty
|
||||||
// (t,) is the type of a tuple with only one field,
|
// (t,) is the type of a tuple with only one field,
|
||||||
// of type t
|
// of type t
|
||||||
let mut ts = vec!(self.parse_ty(true));
|
let mut ts = vec![];
|
||||||
let mut one_tuple = false;
|
let mut last_comma = false;
|
||||||
while self.token == token::Comma {
|
while self.token != token::CloseDelim(token::Paren) {
|
||||||
self.bump();
|
|
||||||
if self.token != token::CloseDelim(token::Paren) {
|
|
||||||
ts.push(self.parse_ty(true));
|
ts.push(self.parse_ty(true));
|
||||||
}
|
if self.token == token::Comma {
|
||||||
else {
|
last_comma = true;
|
||||||
one_tuple = true;
|
self.bump();
|
||||||
|
} else {
|
||||||
|
last_comma = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ts.len() == 1 && !one_tuple {
|
|
||||||
self.expect(&token::CloseDelim(token::Paren));
|
self.expect(&token::CloseDelim(token::Paren));
|
||||||
|
if ts.len() == 1 && !last_comma {
|
||||||
TyParen(ts.into_iter().nth(0).unwrap())
|
TyParen(ts.into_iter().nth(0).unwrap())
|
||||||
} else {
|
} else {
|
||||||
let t = TyTup(ts);
|
TyTup(ts)
|
||||||
self.expect(&token::CloseDelim(token::Paren));
|
|
||||||
t
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if self.token == token::Tilde {
|
} else if self.token == token::Tilde {
|
||||||
// OWNED POINTER
|
// OWNED POINTER
|
||||||
|
@ -1459,7 +1440,7 @@ impl<'a> Parser<'a> {
|
||||||
token::OpenDelim(token::Bracket) => self.obsolete(last_span, ObsoleteOwnedVector),
|
token::OpenDelim(token::Bracket) => self.obsolete(last_span, ObsoleteOwnedVector),
|
||||||
_ => self.obsolete(last_span, ObsoleteOwnedType)
|
_ => self.obsolete(last_span, ObsoleteOwnedType)
|
||||||
}
|
}
|
||||||
TyUniq(self.parse_ty(false))
|
TyTup(vec![self.parse_ty(false)])
|
||||||
} else if self.token == token::BinOp(token::Star) {
|
} else if self.token == token::BinOp(token::Star) {
|
||||||
// STAR POINTER (bare pointer?)
|
// STAR POINTER (bare pointer?)
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1662,10 +1643,6 @@ impl<'a> Parser<'a> {
|
||||||
LitBinary(parse::binary_lit(i.as_str())),
|
LitBinary(parse::binary_lit(i.as_str())),
|
||||||
token::LitBinaryRaw(i, _) =>
|
token::LitBinaryRaw(i, _) =>
|
||||||
LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect())),
|
LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect())),
|
||||||
token::OpenDelim(token::Paren) => {
|
|
||||||
self.expect(&token::CloseDelim(token::Paren));
|
|
||||||
LitNil
|
|
||||||
},
|
|
||||||
_ => { self.unexpected_last(tok); }
|
_ => { self.unexpected_last(tok); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2126,31 +2103,27 @@ impl<'a> Parser<'a> {
|
||||||
match self.token {
|
match self.token {
|
||||||
token::OpenDelim(token::Paren) => {
|
token::OpenDelim(token::Paren) => {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
|
||||||
// (e) is parenthesized e
|
// (e) is parenthesized e
|
||||||
// (e,) is a tuple with only one field, e
|
// (e,) is a tuple with only one field, e
|
||||||
|
let mut es = vec![];
|
||||||
let mut trailing_comma = false;
|
let mut trailing_comma = false;
|
||||||
if self.token == token::CloseDelim(token::Paren) {
|
while self.token != token::CloseDelim(token::Paren) {
|
||||||
hi = self.span.hi;
|
|
||||||
self.bump();
|
|
||||||
let lit = P(spanned(lo, hi, LitNil));
|
|
||||||
return self.mk_expr(lo, hi, ExprLit(lit));
|
|
||||||
}
|
|
||||||
let mut es = vec!(self.parse_expr());
|
|
||||||
self.commit_expr(&**es.last().unwrap(), &[],
|
|
||||||
&[token::Comma, token::CloseDelim(token::Paren)]);
|
|
||||||
while self.token == token::Comma {
|
|
||||||
self.bump();
|
|
||||||
if self.token != token::CloseDelim(token::Paren) {
|
|
||||||
es.push(self.parse_expr());
|
es.push(self.parse_expr());
|
||||||
self.commit_expr(&**es.last().unwrap(), &[],
|
self.commit_expr(&**es.last().unwrap(), &[],
|
||||||
&[token::Comma, token::CloseDelim(token::Paren)]);
|
&[token::Comma, token::CloseDelim(token::Paren)]);
|
||||||
} else {
|
if self.token == token::Comma {
|
||||||
trailing_comma = true;
|
trailing_comma = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
hi = self.span.hi;
|
|
||||||
self.commit_expr_expecting(&**es.last().unwrap(), token::CloseDelim(token::Paren));
|
|
||||||
|
|
||||||
|
self.bump();
|
||||||
|
} else {
|
||||||
|
trailing_comma = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.bump();
|
||||||
|
|
||||||
|
hi = self.span.hi;
|
||||||
return if es.len() == 1 && !trailing_comma {
|
return if es.len() == 1 && !trailing_comma {
|
||||||
self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap()))
|
self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap()))
|
||||||
} else {
|
} else {
|
||||||
|
@ -3293,13 +3266,8 @@ impl<'a> Parser<'a> {
|
||||||
// parse (pat,pat,pat,...) as tuple
|
// parse (pat,pat,pat,...) as tuple
|
||||||
self.bump();
|
self.bump();
|
||||||
if self.token == token::CloseDelim(token::Paren) {
|
if self.token == token::CloseDelim(token::Paren) {
|
||||||
hi = self.span.hi;
|
|
||||||
self.bump();
|
self.bump();
|
||||||
let lit = P(codemap::Spanned {
|
pat = PatTup(vec![]);
|
||||||
node: LitNil,
|
|
||||||
span: mk_sp(lo, hi)});
|
|
||||||
let expr = self.mk_expr(lo, hi, ExprLit(lit));
|
|
||||||
pat = PatLit(expr);
|
|
||||||
} else {
|
} else {
|
||||||
let mut fields = vec!(self.parse_pat());
|
let mut fields = vec!(self.parse_pat());
|
||||||
if self.look_ahead(1, |t| *t != token::CloseDelim(token::Paren)) {
|
if self.look_ahead(1, |t| *t != token::CloseDelim(token::Paren)) {
|
||||||
|
@ -4137,12 +4105,11 @@ impl<'a> Parser<'a> {
|
||||||
pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> P<FnDecl> {
|
pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> P<FnDecl> {
|
||||||
|
|
||||||
let (args, variadic) = self.parse_fn_args(true, allow_variadic);
|
let (args, variadic) = self.parse_fn_args(true, allow_variadic);
|
||||||
let (ret_style, ret_ty) = self.parse_ret_ty();
|
let ret_ty = self.parse_ret_ty();
|
||||||
|
|
||||||
P(FnDecl {
|
P(FnDecl {
|
||||||
inputs: args,
|
inputs: args,
|
||||||
output: ret_ty,
|
output: ret_ty,
|
||||||
cf: ret_style,
|
|
||||||
variadic: variadic
|
variadic: variadic
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4337,12 +4304,11 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let hi = self.span.hi;
|
let hi = self.span.hi;
|
||||||
|
|
||||||
let (ret_style, ret_ty) = self.parse_ret_ty();
|
let ret_ty = self.parse_ret_ty();
|
||||||
|
|
||||||
let fn_decl = P(FnDecl {
|
let fn_decl = P(FnDecl {
|
||||||
inputs: fn_inputs,
|
inputs: fn_inputs,
|
||||||
output: ret_ty,
|
output: ret_ty,
|
||||||
cf: ret_style,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4368,10 +4334,10 @@ impl<'a> Parser<'a> {
|
||||||
(optional_unboxed_closure_kind, args)
|
(optional_unboxed_closure_kind, args)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let (style, output) = if self.token == token::RArrow {
|
let output = if self.token == token::RArrow {
|
||||||
self.parse_ret_ty()
|
self.parse_ret_ty()
|
||||||
} else {
|
} else {
|
||||||
(Return, P(Ty {
|
Return(P(Ty {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: TyInfer,
|
node: TyInfer,
|
||||||
span: self.span,
|
span: self.span,
|
||||||
|
@ -4381,7 +4347,6 @@ impl<'a> Parser<'a> {
|
||||||
(P(FnDecl {
|
(P(FnDecl {
|
||||||
inputs: inputs_captures,
|
inputs: inputs_captures,
|
||||||
output: output,
|
output: output,
|
||||||
cf: style,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
}), optional_unboxed_closure_kind)
|
}), optional_unboxed_closure_kind)
|
||||||
}
|
}
|
||||||
|
@ -4394,10 +4359,10 @@ impl<'a> Parser<'a> {
|
||||||
seq_sep_trailing_allowed(token::Comma),
|
seq_sep_trailing_allowed(token::Comma),
|
||||||
|p| p.parse_fn_block_arg());
|
|p| p.parse_fn_block_arg());
|
||||||
|
|
||||||
let (style, output) = if self.token == token::RArrow {
|
let output = if self.token == token::RArrow {
|
||||||
self.parse_ret_ty()
|
self.parse_ret_ty()
|
||||||
} else {
|
} else {
|
||||||
(Return, P(Ty {
|
Return(P(Ty {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: TyInfer,
|
node: TyInfer,
|
||||||
span: self.span,
|
span: self.span,
|
||||||
|
@ -4407,7 +4372,6 @@ impl<'a> Parser<'a> {
|
||||||
P(FnDecl {
|
P(FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: output,
|
output: output,
|
||||||
cf: style,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,12 +645,6 @@ impl<'a> State<'a> {
|
||||||
try!(self.maybe_print_comment(ty.span.lo));
|
try!(self.maybe_print_comment(ty.span.lo));
|
||||||
try!(self.ibox(0u));
|
try!(self.ibox(0u));
|
||||||
match ty.node {
|
match ty.node {
|
||||||
ast::TyNil => try!(word(&mut self.s, "()")),
|
|
||||||
ast::TyBot => try!(word(&mut self.s, "!")),
|
|
||||||
ast::TyUniq(ref ty) => {
|
|
||||||
try!(word(&mut self.s, "~"));
|
|
||||||
try!(self.print_type(&**ty));
|
|
||||||
}
|
|
||||||
ast::TyVec(ref ty) => {
|
ast::TyVec(ref ty) => {
|
||||||
try!(word(&mut self.s, "["));
|
try!(word(&mut self.s, "["));
|
||||||
try!(self.print_type(&**ty));
|
try!(self.print_type(&**ty));
|
||||||
|
@ -2307,15 +2301,7 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
try!(self.pclose());
|
try!(self.pclose());
|
||||||
|
|
||||||
try!(self.maybe_print_comment(decl.output.span.lo));
|
self.print_fn_output(decl)
|
||||||
match decl.output.node {
|
|
||||||
ast::TyNil => Ok(()),
|
|
||||||
_ => {
|
|
||||||
try!(self.space_if_not_bol());
|
|
||||||
try!(self.word_space("->"));
|
|
||||||
self.print_type(&*decl.output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_fn_block_args(
|
pub fn print_fn_block_args(
|
||||||
|
@ -2333,16 +2319,24 @@ impl<'a> State<'a> {
|
||||||
try!(self.print_fn_args(decl, None));
|
try!(self.print_fn_args(decl, None));
|
||||||
try!(word(&mut self.s, "|"));
|
try!(word(&mut self.s, "|"));
|
||||||
|
|
||||||
match decl.output.node {
|
if let ast::Return(ref ty) = decl.output {
|
||||||
ast::TyInfer => {}
|
if ty.node == ast::TyInfer {
|
||||||
_ => {
|
return self.maybe_print_comment(ty.span.lo);
|
||||||
try!(self.space_if_not_bol());
|
|
||||||
try!(self.word_space("->"));
|
|
||||||
try!(self.print_type(&*decl.output));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.maybe_print_comment(decl.output.span.lo)
|
try!(self.space_if_not_bol());
|
||||||
|
try!(self.word_space("->"));
|
||||||
|
match decl.output {
|
||||||
|
ast::Return(ref ty) => {
|
||||||
|
try!(self.print_type(&**ty));
|
||||||
|
self.maybe_print_comment(ty.span.lo)
|
||||||
|
}
|
||||||
|
ast::NoReturn(span) => {
|
||||||
|
try!(self.word_nbsp("!"));
|
||||||
|
self.maybe_print_comment(span.lo)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause)
|
pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause)
|
||||||
|
@ -2359,16 +2353,24 @@ impl<'a> State<'a> {
|
||||||
try!(self.print_fn_args(decl, None));
|
try!(self.print_fn_args(decl, None));
|
||||||
try!(word(&mut self.s, ")"));
|
try!(word(&mut self.s, ")"));
|
||||||
|
|
||||||
match decl.output.node {
|
if let ast::Return(ref ty) = decl.output {
|
||||||
ast::TyInfer => {}
|
if ty.node == ast::TyInfer {
|
||||||
_ => {
|
return self.maybe_print_comment(ty.span.lo);
|
||||||
try!(self.space_if_not_bol());
|
|
||||||
try!(self.word_space("->"));
|
|
||||||
try!(self.print_type(&*decl.output));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.maybe_print_comment(decl.output.span.lo)
|
try!(self.space_if_not_bol());
|
||||||
|
try!(self.word_space("->"));
|
||||||
|
match decl.output {
|
||||||
|
ast::Return(ref ty) => {
|
||||||
|
try!(self.print_type(&**ty));
|
||||||
|
self.maybe_print_comment(ty.span.lo)
|
||||||
|
}
|
||||||
|
ast::NoReturn(span) => {
|
||||||
|
try!(self.word_nbsp("!"));
|
||||||
|
self.maybe_print_comment(span.lo)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_bounds(&mut self,
|
pub fn print_bounds(&mut self,
|
||||||
|
@ -2627,19 +2629,29 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> IoResult<()> {
|
pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> IoResult<()> {
|
||||||
match decl.output.node {
|
if let ast::Return(ref ty) = decl.output {
|
||||||
ast::TyNil => Ok(()),
|
match ty.node {
|
||||||
_ => {
|
ast::TyTup(ref tys) if tys.is_empty() => {
|
||||||
|
return self.maybe_print_comment(ty.span.lo);
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try!(self.space_if_not_bol());
|
try!(self.space_if_not_bol());
|
||||||
try!(self.ibox(indent_unit));
|
try!(self.ibox(indent_unit));
|
||||||
try!(self.word_space("->"));
|
try!(self.word_space("->"));
|
||||||
if decl.cf == ast::NoReturn {
|
match decl.output {
|
||||||
try!(self.word_nbsp("!"));
|
ast::NoReturn(_) =>
|
||||||
} else {
|
try!(self.word_nbsp("!")),
|
||||||
try!(self.print_type(&*decl.output));
|
ast::Return(ref ty) =>
|
||||||
}
|
try!(self.print_type(&**ty))
|
||||||
self.end()
|
|
||||||
}
|
}
|
||||||
|
try!(self.end());
|
||||||
|
|
||||||
|
match decl.output {
|
||||||
|
ast::Return(ref output) => self.maybe_print_comment(output.span.lo),
|
||||||
|
_ => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2700,8 +2712,6 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
try!(self.print_bounds(":", bounds));
|
try!(self.print_bounds(":", bounds));
|
||||||
|
|
||||||
try!(self.maybe_print_comment(decl.output.span.lo));
|
|
||||||
|
|
||||||
try!(self.print_fn_output(decl));
|
try!(self.print_fn_output(decl));
|
||||||
|
|
||||||
match generics {
|
match generics {
|
||||||
|
@ -2807,7 +2817,6 @@ impl<'a> State<'a> {
|
||||||
ast_util::float_ty_to_string(t).as_slice()).as_slice())
|
ast_util::float_ty_to_string(t).as_slice()).as_slice())
|
||||||
}
|
}
|
||||||
ast::LitFloatUnsuffixed(ref f) => word(&mut self.s, f.get()),
|
ast::LitFloatUnsuffixed(ref f) => word(&mut self.s, f.get()),
|
||||||
ast::LitNil => word(&mut self.s, "()"),
|
|
||||||
ast::LitBool(val) => {
|
ast::LitBool(val) => {
|
||||||
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
|
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
|
||||||
}
|
}
|
||||||
|
@ -3003,10 +3012,9 @@ mod test {
|
||||||
|
|
||||||
let decl = ast::FnDecl {
|
let decl = ast::FnDecl {
|
||||||
inputs: Vec::new(),
|
inputs: Vec::new(),
|
||||||
output: P(ast::Ty {id: 0,
|
output: ast::Return(P(ast::Ty {id: 0,
|
||||||
node: ast::TyNil,
|
node: ast::TyTup(vec![]),
|
||||||
span: codemap::DUMMY_SP}),
|
span: codemap::DUMMY_SP})),
|
||||||
cf: ast::Return,
|
|
||||||
variadic: false
|
variadic: false
|
||||||
};
|
};
|
||||||
let generics = ast_util::empty_generics();
|
let generics = ast_util::empty_generics();
|
||||||
|
|
|
@ -289,9 +289,12 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
|
||||||
fn has_test_signature(i: &ast::Item) -> HasTestSignature {
|
fn has_test_signature(i: &ast::Item) -> HasTestSignature {
|
||||||
match &i.node {
|
match &i.node {
|
||||||
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
|
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
|
||||||
let no_output = match decl.output.node {
|
let no_output = match decl.output {
|
||||||
ast::TyNil => true,
|
ast::Return(ref ret_ty) => match ret_ty.node {
|
||||||
|
ast::TyTup(ref tys) if tys.is_empty() => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
},
|
||||||
|
ast::NoReturn(_) => false
|
||||||
};
|
};
|
||||||
if decl.inputs.is_empty()
|
if decl.inputs.is_empty()
|
||||||
&& no_output
|
&& no_output
|
||||||
|
@ -325,9 +328,12 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
|
||||||
match i.node {
|
match i.node {
|
||||||
ast::ItemFn(ref decl, _, _, ref generics, _) => {
|
ast::ItemFn(ref decl, _, _, ref generics, _) => {
|
||||||
let input_cnt = decl.inputs.len();
|
let input_cnt = decl.inputs.len();
|
||||||
let no_output = match decl.output.node {
|
let no_output = match decl.output {
|
||||||
ast::TyNil => true,
|
ast::Return(ref ret_ty) => match ret_ty.node {
|
||||||
_ => false
|
ast::TyTup(ref tys) if tys.is_empty() => true,
|
||||||
|
_ => false,
|
||||||
|
},
|
||||||
|
ast::NoReturn(_) => false
|
||||||
};
|
};
|
||||||
let tparm_cnt = generics.ty_params.len();
|
let tparm_cnt = generics.ty_params.len();
|
||||||
// NB: inadequate check, but we're running
|
// NB: inadequate check, but we're running
|
||||||
|
|
|
@ -341,7 +341,7 @@ pub fn skip_ty<'v, V: Visitor<'v>>(_: &mut V, _: &'v Ty) {
|
||||||
|
|
||||||
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
match typ.node {
|
match typ.node {
|
||||||
TyUniq(ref ty) | TyVec(ref ty) | TyParen(ref ty) => {
|
TyVec(ref ty) | TyParen(ref ty) => {
|
||||||
visitor.visit_ty(&**ty)
|
visitor.visit_ty(&**ty)
|
||||||
}
|
}
|
||||||
TyPtr(ref mutable_type) => {
|
TyPtr(ref mutable_type) => {
|
||||||
|
@ -360,7 +360,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
for argument in function_declaration.decl.inputs.iter() {
|
for argument in function_declaration.decl.inputs.iter() {
|
||||||
visitor.visit_ty(&*argument.ty)
|
visitor.visit_ty(&*argument.ty)
|
||||||
}
|
}
|
||||||
visitor.visit_ty(&*function_declaration.decl.output);
|
walk_fn_ret_ty(visitor, &function_declaration.decl.output);
|
||||||
walk_ty_param_bounds(visitor, &function_declaration.bounds);
|
walk_ty_param_bounds(visitor, &function_declaration.bounds);
|
||||||
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
for argument in function_declaration.decl.inputs.iter() {
|
for argument in function_declaration.decl.inputs.iter() {
|
||||||
visitor.visit_ty(&*argument.ty)
|
visitor.visit_ty(&*argument.ty)
|
||||||
}
|
}
|
||||||
visitor.visit_ty(&*function_declaration.decl.output);
|
walk_fn_ret_ty(visitor, &function_declaration.decl.output);
|
||||||
walk_ty_param_bounds(visitor, &function_declaration.bounds);
|
walk_ty_param_bounds(visitor, &function_declaration.bounds);
|
||||||
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
for argument in function_declaration.decl.inputs.iter() {
|
for argument in function_declaration.decl.inputs.iter() {
|
||||||
visitor.visit_ty(&*argument.ty)
|
visitor.visit_ty(&*argument.ty)
|
||||||
}
|
}
|
||||||
visitor.visit_ty(&*function_declaration.decl.output);
|
walk_fn_ret_ty(visitor, &function_declaration.decl.output);
|
||||||
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
walk_lifetime_decls(visitor, &function_declaration.lifetimes);
|
||||||
}
|
}
|
||||||
TyPath(ref path, ref opt_bounds, id) => {
|
TyPath(ref path, ref opt_bounds, id) => {
|
||||||
|
@ -403,7 +403,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
TyTypeof(ref expression) => {
|
TyTypeof(ref expression) => {
|
||||||
visitor.visit_expr(&**expression)
|
visitor.visit_expr(&**expression)
|
||||||
}
|
}
|
||||||
TyNil | TyBot | TyInfer => {}
|
TyInfer => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,12 +538,18 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) {
|
||||||
for argument in function_declaration.inputs.iter() {
|
for argument in function_declaration.inputs.iter() {
|
||||||
visitor.visit_pat(&*argument.pat);
|
visitor.visit_pat(&*argument.pat);
|
||||||
visitor.visit_ty(&*argument.ty)
|
visitor.visit_ty(&*argument.ty)
|
||||||
}
|
}
|
||||||
visitor.visit_ty(&*function_declaration.output)
|
walk_fn_ret_ty(visitor, &function_declaration.output)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: there is no visit_method() method in the visitor, instead override
|
// Note: there is no visit_method() method in the visitor, instead override
|
||||||
|
@ -601,7 +607,7 @@ pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v Type
|
||||||
visitor.visit_ty(&*argument_type.ty)
|
visitor.visit_ty(&*argument_type.ty)
|
||||||
}
|
}
|
||||||
visitor.visit_generics(&method_type.generics);
|
visitor.visit_generics(&method_type.generics);
|
||||||
visitor.visit_ty(&*method_type.decl.output);
|
walk_fn_ret_ty(visitor, &method_type.decl.output);
|
||||||
for attr in method_type.attrs.iter() {
|
for attr in method_type.attrs.iter() {
|
||||||
visitor.visit_attribute(attr);
|
visitor.visit_attribute(attr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue