Skip to content

Commit

Permalink
Complete the removal of ty_nil, ast::LitNil, ast::TyBot and ast::TyUniq
Browse files Browse the repository at this point in the history
[breaking-change]

This will break any uses of macros that assumed () being a valid literal.
  • Loading branch information
Jakub Bukaj committed Nov 16, 2014
1 parent 08d6774 commit eb01b17
Show file tree
Hide file tree
Showing 34 changed files with 350 additions and 407 deletions.
1 change: 0 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ register_diagnostics!(
E0055,
E0056,
E0057,
E0058,
E0059,
E0060,
E0061,
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ impl LintPass for ImproperCTypes {
for input in decl.inputs.iter() {
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 {
Expand Down Expand Up @@ -735,6 +737,7 @@ impl LintPass for UnusedResults {
let t = ty::expr_ty(cx.tcx, expr);
let mut warned = false;
match ty::get(t).sty {
ty::ty_tup(ref tys) if tys.is_empty() => return,
ty::ty_bool => return,
ty::ty_struct(did, _) |
ty::ty_enum(did, _) => {
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// 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::def::*;
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
Expand Down Expand Up @@ -332,7 +332,6 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
fn const_val_to_expr(value: &const_val) -> P<Expr> {
let node = match value {
&const_bool(b) => LitBool(b),
&const_nil => LitNil,
_ => unreachable!()
};
P(Expr {
Expand Down Expand Up @@ -402,7 +401,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
let pats_len = pats.len();
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
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, _) => {
let (vid, is_structure) = match ctor {
Expand Down Expand Up @@ -497,9 +496,6 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t,
ty::ty_bool =>
[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_vec(_, None) =>
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ pub enum const_val {
const_uint(u64),
const_str(InternedString),
const_binary(Rc<Vec<u8> >),
const_bool(bool),
const_nil
const_bool(bool)
}

pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
Expand Down Expand Up @@ -589,7 +588,6 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
LitFloatUnsuffixed(ref n) => {
const_float(from_str::<f64>(n.get()).unwrap() as f64)
}
LitNil => const_nil,
LitBool(b) => const_bool(b)
}
}
Expand All @@ -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_bool(a), &const_bool(b)) => compare_vals(a, b),
(&const_binary(ref a), &const_binary(ref b)) => compare_vals(a, b),
(&const_nil, &const_nil) => compare_vals((), ()),
_ => None
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -4467,7 +4469,9 @@ impl<'a> Resolver<'a> {
debug!("(resolving function) recorded argument");
}

this.resolve_type(&*declaration.output);
if let ast::Return(ref ret_ty) = declaration.output {
this.resolve_type(&**ret_ty);
}
}
}

Expand Down
21 changes: 17 additions & 4 deletions src/librustc/middle/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
for arg in method.pe_fn_decl().inputs.iter() {
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
self.nest(method.id, |v| v.visit_block(&*method.pe_body()));

Expand Down Expand Up @@ -491,7 +495,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
for arg in decl.inputs.iter() {
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
self.nest(item.id, |v| v.visit_block(&*body));
Expand Down Expand Up @@ -1136,7 +1143,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
for arg in method_type.decl.inputs.iter() {
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,
method_type.span,
Expand Down Expand Up @@ -1352,7 +1362,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
for arg in decl.inputs.iter() {
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
self.nest(ex.id, |v| v.visit_block(&**body));
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit)
}
}
ast::LitBool(b) => C_bool(cx, b),
ast::LitNil => C_nil(cx),
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
ast::LitBinary(ref data) => C_binary_slice(cx, data.as_slice()),
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,9 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
macro_rules! ifn (
($name:expr fn() -> $ret:expr) => (
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());
return Some(f);
}
Expand Down
20 changes: 13 additions & 7 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,10 +1374,9 @@ pub fn create_function_debug_context(cx: &CrateContext,
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);

// Return type -- llvm::DIBuilder wants this at index 0
match fn_decl.output.node {
ast::TyNil => {
signature.push(ptr::null_mut());
}
match fn_decl.output {
ast::Return(ref ret_ty) if ret_ty.node == ast::TyTup(vec![]) =>
signature.push(ptr::null_mut()),
_ => {
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);

Expand Down Expand Up @@ -1738,6 +1737,8 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
debug!("basic_type_metadata: {}", ty::get(t));

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_char => ("char".to_string(), DW_ATE_unsigned_char),
ty::ty_int(int_ty) => match int_ty {
Expand Down Expand Up @@ -2888,6 +2889,9 @@ fn type_metadata(cx: &CrateContext,
ty::ty_float(_) => {
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, _) => {
prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
}
Expand Down Expand Up @@ -3669,7 +3673,7 @@ fn compute_debuginfo_type_name(cx: &CrateContext,
fn push_debuginfo_type_name(cx: &CrateContext,
t: ty::t,
qualified: bool,
output:&mut String) {
output: &mut String) {
match ty::get(t).sty {
ty::ty_bool => output.push_str("bool"),
ty::ty_char => output.push_str("char"),
Expand Down Expand Up @@ -3697,8 +3701,10 @@ fn push_debuginfo_type_name(cx: &CrateContext,
push_debuginfo_type_name(cx, component_type, true, output);
output.push_str(", ");
}
output.pop();
output.pop();
if !component_types.is_empty() {
output.pop();
output.pop();
}
output.push(')');
},
ty::ty_uniq(inner_type) => {
Expand Down
84 changes: 37 additions & 47 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@ pub fn type_is_scalar(ty: t) -> bool {
ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) |
ty_bare_fn(..) | ty_ptr(_) => true,
ty_tup(ref tys) if tys.is_empty() => true,
_ => false
}
}
Expand Down Expand Up @@ -3777,6 +3778,7 @@ pub fn ty_sort_string(cx: &ctxt, t: t) -> String {
ty_uint(_) | ty_float(_) | ty_str => {
::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_uniq(_) => "box".to_string(),
Expand Down Expand Up @@ -4771,54 +4773,42 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t {
// Returns the repeat count for a repeating vector expression.
pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
match const_eval::eval_const_expr_partial(tcx, count_expr) {
Ok(ref const_val) => match *const_val {
const_eval::const_int(count) => if count < 0 {
tcx.sess.span_err(count_expr.span,
"expected positive integer for \
repeat count, found negative integer");
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
}
Ok(val) => {
let found = match val {
const_eval::const_uint(count) => return count as uint,
const_eval::const_int(count) if count >= 0 => return count as uint,
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
}

// Iterate over a type parameter's bounded traits and any supertraits
Expand Down
Loading

0 comments on commit eb01b17

Please sign in to comment.