Skip to content

Commit eb01b17

Browse files
author
Jakub Bukaj
committed
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.
1 parent 08d6774 commit eb01b17

34 files changed

+350
-407
lines changed

Diff for: src/librustc/diagnostics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ register_diagnostics!(
6666
E0055,
6767
E0056,
6868
E0057,
69-
E0058,
7069
E0059,
7170
E0060,
7271
E0061,

Diff for: src/librustc/lint/builtin.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ impl LintPass for ImproperCTypes {
447447
for input in decl.inputs.iter() {
448448
check_ty(cx, &*input.ty);
449449
}
450-
check_ty(cx, &*decl.output)
450+
if let ast::Return(ref ret_ty) = decl.output {
451+
check_ty(cx, &**ret_ty);
452+
}
451453
}
452454

453455
match it.node {
@@ -735,6 +737,7 @@ impl LintPass for UnusedResults {
735737
let t = ty::expr_ty(cx.tcx, expr);
736738
let mut warned = false;
737739
match ty::get(t).sty {
740+
ty::ty_tup(ref tys) if tys.is_empty() => return,
738741
ty::ty_bool => return,
739742
ty::ty_struct(did, _) |
740743
ty::ty_enum(did, _) => {

Diff for: src/librustc/middle/check_match.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use middle::const_eval::{compare_const_vals, const_bool, const_float, const_nil, const_val};
11+
use middle::const_eval::{compare_const_vals, const_bool, const_float, const_val};
1212
use middle::const_eval::{const_expr_to_pat, eval_const_expr, lookup_const_by_id};
1313
use middle::def::*;
1414
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
@@ -332,7 +332,6 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
332332
fn const_val_to_expr(value: &const_val) -> P<Expr> {
333333
let node = match value {
334334
&const_bool(b) => LitBool(b),
335-
&const_nil => LitNil,
336335
_ => unreachable!()
337336
};
338337
P(Expr {
@@ -402,7 +401,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
402401
let pats_len = pats.len();
403402
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
404403
let pat = match ty::get(left_ty).sty {
405-
ty::ty_tup(ref tys) if !tys.is_empty() => PatTup(pats.collect()),
404+
ty::ty_tup(_) => PatTup(pats.collect()),
406405

407406
ty::ty_enum(cid, _) | ty::ty_struct(cid, _) => {
408407
let (vid, is_structure) = match ctor {
@@ -497,9 +496,6 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t,
497496
ty::ty_bool =>
498497
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),
499498

500-
ty::ty_tup(ref tys) if tys.is_empty() =>
501-
vec!(ConstantValue(const_nil)),
502-
503499
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
504500
ty::ty_vec(_, None) =>
505501
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),

Diff for: src/librustc/middle/const_eval.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ pub enum const_val {
311311
const_uint(u64),
312312
const_str(InternedString),
313313
const_binary(Rc<Vec<u8> >),
314-
const_bool(bool),
315-
const_nil
314+
const_bool(bool)
316315
}
317316

318317
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 {
589588
LitFloatUnsuffixed(ref n) => {
590589
const_float(from_str::<f64>(n.get()).unwrap() as f64)
591590
}
592-
LitNil => const_nil,
593591
LitBool(b) => const_bool(b)
594592
}
595593
}
@@ -605,7 +603,6 @@ pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option<int> {
605603
(&const_str(ref a), &const_str(ref b)) => compare_vals(a, b),
606604
(&const_bool(a), &const_bool(b)) => compare_vals(a, b),
607605
(&const_binary(ref a), &const_binary(ref b)) => compare_vals(a, b),
608-
(&const_nil, &const_nil) => compare_vals((), ()),
609606
_ => None
610607
}
611608
}

Diff for: src/librustc/middle/resolve.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -4285,7 +4285,9 @@ impl<'a> Resolver<'a> {
42854285
_ => {}
42864286
}
42874287

4288-
this.resolve_type(&*ty_m.decl.output);
4288+
if let ast::Return(ref ret_ty) = ty_m.decl.output {
4289+
this.resolve_type(&**ret_ty);
4290+
}
42894291
});
42904292
}
42914293
ast::ProvidedMethod(ref m) => {
@@ -4467,7 +4469,9 @@ impl<'a> Resolver<'a> {
44674469
debug!("(resolving function) recorded argument");
44684470
}
44694471

4470-
this.resolve_type(&*declaration.output);
4472+
if let ast::Return(ref ret_ty) = declaration.output {
4473+
this.resolve_type(&**ret_ty);
4474+
}
44714475
}
44724476
}
44734477

Diff for: src/librustc/middle/save/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
383383
for arg in method.pe_fn_decl().inputs.iter() {
384384
self.visit_ty(&*arg.ty);
385385
}
386-
self.visit_ty(&*method.pe_fn_decl().output);
386+
387+
if let ast::Return(ref ret_ty) = method.pe_fn_decl().output {
388+
self.visit_ty(&**ret_ty);
389+
}
390+
387391
// walk the fn body
388392
self.nest(method.id, |v| v.visit_block(&*method.pe_body()));
389393

@@ -491,7 +495,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
491495
for arg in decl.inputs.iter() {
492496
self.visit_ty(&*arg.ty);
493497
}
494-
self.visit_ty(&*decl.output);
498+
499+
if let ast::Return(ref ret_ty) = decl.output {
500+
self.visit_ty(&**ret_ty);
501+
}
495502

496503
// walk the body
497504
self.nest(item.id, |v| v.visit_block(&*body));
@@ -1136,7 +1143,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
11361143
for arg in method_type.decl.inputs.iter() {
11371144
self.visit_ty(&*arg.ty);
11381145
}
1139-
self.visit_ty(&*method_type.decl.output);
1146+
1147+
if let ast::Return(ref ret_ty) = method_type.decl.output {
1148+
self.visit_ty(&**ret_ty);
1149+
}
11401150

11411151
self.process_generic_params(&method_type.generics,
11421152
method_type.span,
@@ -1352,7 +1362,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
13521362
for arg in decl.inputs.iter() {
13531363
self.visit_ty(&*arg.ty);
13541364
}
1355-
self.visit_ty(&*decl.output);
1365+
1366+
if let ast::Return(ref ret_ty) = decl.output {
1367+
self.visit_ty(&**ret_ty);
1368+
}
13561369

13571370
// walk the body
13581371
self.nest(ex.id, |v| v.visit_block(&**body));

Diff for: src/librustc/middle/trans/consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit)
8181
}
8282
}
8383
ast::LitBool(b) => C_bool(cx, b),
84-
ast::LitNil => C_nil(cx),
8584
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
8685
ast::LitBinary(ref data) => C_binary_slice(cx, data.as_slice()),
8786
}

Diff for: src/librustc/middle/trans/context.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,9 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
718718
macro_rules! ifn (
719719
($name:expr fn() -> $ret:expr) => (
720720
if *key == $name {
721-
let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil(ccx.tcx()));
721+
let f = base::decl_cdecl_fn(
722+
ccx, $name, Type::func([], &$ret),
723+
ty::mk_nil(ccx.tcx()));
722724
ccx.intrinsics().borrow_mut().insert($name, f.clone());
723725
return Some(f);
724726
}

Diff for: src/librustc/middle/trans/debuginfo.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,9 @@ pub fn create_function_debug_context(cx: &CrateContext,
13741374
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
13751375

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

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

17401739
let (name, encoding) = match ty::get(t).sty {
1740+
ty::ty_tup(ref elements) if elements.is_empty() =>
1741+
("()".to_string(), DW_ATE_unsigned),
17411742
ty::ty_bool => ("bool".to_string(), DW_ATE_boolean),
17421743
ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char),
17431744
ty::ty_int(int_ty) => match int_ty {
@@ -2888,6 +2889,9 @@ fn type_metadata(cx: &CrateContext,
28882889
ty::ty_float(_) => {
28892890
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
28902891
}
2892+
ty::ty_tup(ref elements) if elements.is_empty() => {
2893+
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
2894+
}
28912895
ty::ty_enum(def_id, _) => {
28922896
prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
28932897
}
@@ -3669,7 +3673,7 @@ fn compute_debuginfo_type_name(cx: &CrateContext,
36693673
fn push_debuginfo_type_name(cx: &CrateContext,
36703674
t: ty::t,
36713675
qualified: bool,
3672-
output:&mut String) {
3676+
output: &mut String) {
36733677
match ty::get(t).sty {
36743678
ty::ty_bool => output.push_str("bool"),
36753679
ty::ty_char => output.push_str("char"),
@@ -3697,8 +3701,10 @@ fn push_debuginfo_type_name(cx: &CrateContext,
36973701
push_debuginfo_type_name(cx, component_type, true, output);
36983702
output.push_str(", ");
36993703
}
3700-
output.pop();
3701-
output.pop();
3704+
if !component_types.is_empty() {
3705+
output.pop();
3706+
output.pop();
3707+
}
37023708
output.push(')');
37033709
},
37043710
ty::ty_uniq(inner_type) => {

Diff for: src/librustc/middle/ty.rs

+37-47
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,7 @@ pub fn type_is_scalar(ty: t) -> bool {
21312131
ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) |
21322132
ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) |
21332133
ty_bare_fn(..) | ty_ptr(_) => true,
2134+
ty_tup(ref tys) if tys.is_empty() => true,
21342135
_ => false
21352136
}
21362137
}
@@ -3777,6 +3778,7 @@ pub fn ty_sort_string(cx: &ctxt, t: t) -> String {
37773778
ty_uint(_) | ty_float(_) | ty_str => {
37783779
::util::ppaux::ty_to_string(cx, t)
37793780
}
3781+
ty_tup(ref tys) if tys.is_empty() => ::util::ppaux::ty_to_string(cx, t),
37803782

37813783
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
37823784
ty_uniq(_) => "box".to_string(),
@@ -4771,54 +4773,42 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t {
47714773
// Returns the repeat count for a repeating vector expression.
47724774
pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
47734775
match const_eval::eval_const_expr_partial(tcx, count_expr) {
4774-
Ok(ref const_val) => match *const_val {
4775-
const_eval::const_int(count) => if count < 0 {
4776-
tcx.sess.span_err(count_expr.span,
4777-
"expected positive integer for \
4778-
repeat count, found negative integer");
4779-
0
4780-
} else {
4781-
count as uint
4782-
},
4783-
const_eval::const_uint(count) => count as uint,
4784-
const_eval::const_float(count) => {
4785-
tcx.sess.span_err(count_expr.span,
4786-
"expected positive integer for \
4787-
repeat count, found float");
4788-
count as uint
4789-
}
4790-
const_eval::const_str(_) => {
4791-
tcx.sess.span_err(count_expr.span,
4792-
"expected positive integer for \
4793-
repeat count, found string");
4794-
0
4795-
}
4796-
const_eval::const_bool(_) => {
4797-
tcx.sess.span_err(count_expr.span,
4798-
"expected positive integer for \
4799-
repeat count, found boolean");
4800-
0
4801-
}
4802-
const_eval::const_binary(_) => {
4803-
tcx.sess.span_err(count_expr.span,
4804-
"expected positive integer for \
4805-
repeat count, found binary array");
4806-
0
4807-
}
4808-
const_eval::const_nil => {
4809-
tcx.sess.span_err(count_expr.span,
4810-
"expected positive integer for \
4811-
repeat count, found ()");
4812-
0
4813-
}
4814-
},
4815-
Err(..) => {
4816-
tcx.sess.span_err(count_expr.span,
4817-
"expected constant integer for repeat count, \
4818-
found variable");
4819-
0
4820-
}
4776+
Ok(val) => {
4777+
let found = match val {
4778+
const_eval::const_uint(count) => return count as uint,
4779+
const_eval::const_int(count) if count >= 0 => return count as uint,
4780+
const_eval::const_int(_) =>
4781+
"negative integer",
4782+
const_eval::const_float(_) =>
4783+
"float",
4784+
const_eval::const_str(_) =>
4785+
"string",
4786+
const_eval::const_bool(_) =>
4787+
"boolean",
4788+
const_eval::const_binary(_) =>
4789+
"binary array"
4790+
};
4791+
tcx.sess.span_err(count_expr.span, format!(
4792+
"expected positive integer for repeat count, found {}",
4793+
found).as_slice());
4794+
}
4795+
Err(_) => {
4796+
let found = match count_expr.node {
4797+
ast::ExprPath(ast::Path {
4798+
global: false,
4799+
ref segments,
4800+
..
4801+
}) if segments.len() == 1 =>
4802+
"variable",
4803+
_ =>
4804+
"non-constant expression"
4805+
};
4806+
tcx.sess.span_err(count_expr.span, format!(
4807+
"expected constant integer for repeat count, found {}",
4808+
found).as_slice());
4809+
}
48214810
}
4811+
0
48224812
}
48234813

48244814
// Iterate over a type parameter's bounded traits and any supertraits

0 commit comments

Comments
 (0)