Skip to content

Commit 08d6774

Browse files
nikomatsakisJakub Bukaj
authored and
Jakub Bukaj
committed
Try to remove ty_nil, some kind of error in exhaustiveness checking
1 parent 0c7a3d6 commit 08d6774

27 files changed

+76
-114
lines changed

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl LintPass for UnusedResults {
735735
let t = ty::expr_ty(cx.tcx, expr);
736736
let mut warned = false;
737737
match ty::get(t).sty {
738-
ty::ty_nil | ty::ty_bool => return,
738+
ty::ty_bool => return,
739739
ty::ty_struct(did, _) |
740740
ty::ty_enum(did, _) => {
741741
if ast_util::is_local(did) {

src/librustc/metadata/tydecode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ fn parse_trait_ref(st: &mut PState, conv: conv_did) -> ty::TraitRef {
360360

361361
fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
362362
match next(st) {
363-
'n' => return ty::mk_nil(),
364363
'b' => return ty::mk_bool(),
365364
'i' => return ty::mk_int(),
366365
'u' => return ty::mk_uint(),

src/librustc/metadata/tyencode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore)
199199

200200
fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
201201
match *st {
202-
ty::ty_nil => mywrite!(w, "n"),
203202
ty::ty_bool => mywrite!(w, "b"),
204203
ty::ty_char => mywrite!(w, "c"),
205204
ty::ty_int(t) => {

src/librustc/middle/check_match.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
402402
let pats_len = pats.len();
403403
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
404404
let pat = match ty::get(left_ty).sty {
405-
ty::ty_tup(_) => PatTup(pats.collect()),
405+
ty::ty_tup(ref tys) if !tys.is_empty() => PatTup(pats.collect()),
406406

407407
ty::ty_enum(cid, _) | ty::ty_struct(cid, _) => {
408408
let (vid, is_structure) = match ctor {
@@ -497,7 +497,7 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t,
497497
ty::ty_bool =>
498498
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),
499499

500-
ty::ty_nil =>
500+
ty::ty_tup(ref tys) if tys.is_empty() =>
501501
vec!(ConstantValue(const_nil)),
502502

503503
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
@@ -552,7 +552,7 @@ fn is_useful(cx: &MatchCheckCtxt,
552552
None => v[0]
553553
};
554554
let left_ty = if real_pat.id == DUMMY_NODE_ID {
555-
ty::mk_nil()
555+
ty::mk_nil(cx.tcx)
556556
} else {
557557
ty::pat_ty(cx.tcx, &*real_pat)
558558
};

src/librustc/middle/traits/coherence.rs

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub fn ty_is_local(tcx: &ty::ctxt,
7979
debug!("ty_is_local({})", ty.repr(tcx));
8080

8181
match ty::get(ty).sty {
82-
ty::ty_nil |
8382
ty::ty_bool |
8483
ty::ty_char |
8584
ty::ty_int(..) |

src/librustc/middle/traits/select.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12271227
ty::ty_infer(ty::FloatVar(_)) |
12281228
ty::ty_uint(_) |
12291229
ty::ty_int(_) |
1230-
ty::ty_nil |
12311230
ty::ty_bool |
12321231
ty::ty_float(_) |
12331232
ty::ty_bare_fn(_) |

src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10121012
.unwrap_or(DUMMY_NODE_ID);
10131013

10141014
let left_ty = if pat_id == DUMMY_NODE_ID {
1015-
ty::mk_nil()
1015+
ty::mk_nil(tcx)
10161016
} else {
10171017
node_id_type(bcx, pat_id)
10181018
};

src/librustc/middle/trans/base.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use middle::trans::builder::{Builder, noname};
4747
use middle::trans::callee;
4848
use middle::trans::cleanup::{CleanupMethods, ScopeId};
4949
use middle::trans::cleanup;
50-
use middle::trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral, C_nil};
50+
use middle::trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral};
5151
use middle::trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef};
5252
use middle::trans::common::{CrateContext, ExternMap, FunctionContext};
5353
use middle::trans::common::{NodeInfo, Result, SubstP};
@@ -517,7 +517,7 @@ pub fn get_res_dtor(ccx: &CrateContext,
517517
let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
518518
let llty = type_of_dtor(ccx, class_ty);
519519
let dtor_ty = ty::mk_ctor_fn(ccx.tcx(), ast::DUMMY_NODE_ID,
520-
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil());
520+
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil(ccx.tcx()));
521521
get_extern_fn(ccx,
522522
&mut *ccx.externs().borrow_mut(),
523523
name.as_slice(),
@@ -551,7 +551,7 @@ pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
551551
let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op));
552552

553553
match ty::get(t).sty {
554-
ty::ty_nil => f(nil_type),
554+
ty::ty_tup(ref tys) if tys.is_empty() => f(nil_type),
555555
ty::ty_bool | ty::ty_uint(_) | ty::ty_char => f(unsigned_int),
556556
ty::ty_ptr(mt) if ty::type_is_sized(cx.tcx(), mt.ty) => f(unsigned_int),
557557
ty::ty_int(_) => f(signed_int),
@@ -1578,12 +1578,6 @@ fn create_datums_for_fn_args_under_call_abi(
15781578
"argtuple"));
15791579
result.push(tuple);
15801580
}
1581-
ty::ty_nil => {
1582-
let mode = datum::Rvalue::new(datum::ByValue);
1583-
result.push(datum::Datum::new(C_nil(bcx.ccx()),
1584-
ty::mk_nil(),
1585-
mode))
1586-
}
15871581
_ => {
15881582
bcx.tcx().sess.bug("last argument of a function with \
15891583
`rust-call` ABI isn't a tuple?!")
@@ -1647,10 +1641,8 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>(
16471641
arg_datum.to_lvalue_datum_in_scope(bcx,
16481642
"argtuple",
16491643
arg_scope_id));
1650-
let empty = Vec::new();
16511644
let untupled_arg_types = match ty::get(monomorphized_arg_types[0]).sty {
16521645
ty::ty_tup(ref types) => types.as_slice(),
1653-
ty::ty_nil => empty.as_slice(),
16541646
_ => {
16551647
bcx.tcx().sess.span_bug(args[0].pat.span,
16561648
"first arg to `rust-call` ABI function \
@@ -1824,7 +1816,7 @@ pub fn trans_closure(ccx: &CrateContext,
18241816
NotUnboxedClosure => monomorphized_arg_types,
18251817

18261818
// Tuple up closure argument types for the "rust-call" ABI.
1827-
IsUnboxedClosure => vec![ty::mk_tup_or_nil(ccx.tcx(), monomorphized_arg_types)]
1819+
IsUnboxedClosure => vec![ty::mk_tup(ccx.tcx(), monomorphized_arg_types)]
18281820
};
18291821
for monomorphized_arg_type in monomorphized_arg_types.iter() {
18301822
debug!("trans_closure: monomorphized_arg_type: {}",
@@ -2380,7 +2372,6 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
23802372
assert!(abi == RustCall);
23812373

23822374
match ty::get(fn_sig.inputs[0]).sty {
2383-
ty::ty_nil => Vec::new(),
23842375
ty::ty_tup(ref inputs) => inputs.clone(),
23852376
_ => ccx.sess().bug("expected tuple'd inputs")
23862377
}
@@ -2389,7 +2380,6 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
23892380
let mut inputs = vec![fn_sig.inputs[0]];
23902381

23912382
match ty::get(fn_sig.inputs[1]).sty {
2392-
ty::ty_nil => inputs,
23932383
ty::ty_tup(ref t_in) => {
23942384
inputs.push_all(t_in.as_slice());
23952385
inputs
@@ -2532,7 +2522,7 @@ pub fn register_fn_llvmty(ccx: &CrateContext,
25322522
llfty: Type) -> ValueRef {
25332523
debug!("register_fn_llvmty id={} sym={}", node_id, sym);
25342524

2535-
let llfn = decl_fn(ccx, sym.as_slice(), cc, llfty, ty::FnConverging(ty::mk_nil()));
2525+
let llfn = decl_fn(ccx, sym.as_slice(), cc, llfty, ty::FnConverging(ty::mk_nil(ccx.tcx())));
25362526
finish_register_fn(ccx, sp, sym, node_id, llfn);
25372527
llfn
25382528
}
@@ -2564,7 +2554,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
25642554
let llfty = Type::func([ccx.int_type(), Type::i8p(ccx).ptr_to()],
25652555
&ccx.int_type());
25662556

2567-
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil());
2557+
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil(ccx.tcx()));
25682558

25692559
// FIXME: #16581: Marking a symbol in the executable with `dllexport`
25702560
// linkage forces MinGW's linker to output a `.reloc` section for ASLR

src/librustc/middle/trans/callee.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
764764
expr::Ignore => {
765765
let ret_ty = match ret_ty {
766766
ty::FnConverging(ret_ty) => ret_ty,
767-
ty::FnDiverging => ty::mk_nil()
767+
ty::FnDiverging => ty::mk_nil(ccx.tcx())
768768
};
769769
if !is_rust_fn ||
770770
type_of::return_uses_outptr(ccx, ret_ty) ||
@@ -957,7 +957,6 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
957957
llargs.push(arg_datum.add_clean(bcx.fcx, arg_cleanup_scope));
958958
}
959959
}
960-
ty::ty_nil => {}
961960
_ => {
962961
bcx.sess().span_bug(tuple_expr.span,
963962
"argument to `.call()` wasn't a tuple?!")
@@ -1004,7 +1003,6 @@ fn trans_overloaded_call_args<'blk, 'tcx>(
10041003
}))
10051004
}
10061005
}
1007-
ty::ty_nil => {}
10081006
_ => {
10091007
bcx.sess().span_bug(arg_exprs[0].span,
10101008
"argument to `.call()` wasn't a tuple?!")

src/librustc/middle/trans/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,15 @@ 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());
721+
let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil(ccx.tcx()));
722722
ccx.intrinsics().borrow_mut().insert($name, f.clone());
723723
return Some(f);
724724
}
725725
);
726726
($name:expr fn($($arg:expr),*) -> $ret:expr) => (
727727
if *key == $name {
728728
let f = base::decl_cdecl_fn(ccx, $name,
729-
Type::func([$($arg),*], &$ret), ty::mk_nil());
729+
Type::func([$($arg),*], &$ret), ty::mk_nil(ccx.tcx()));
730730
ccx.intrinsics().borrow_mut().insert($name, f.clone());
731731
return Some(f);
732732
}
@@ -863,7 +863,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
863863
} else if *key == $name {
864864
let f = base::decl_cdecl_fn(ccx, stringify!($cname),
865865
Type::func([$($arg),*], &$ret),
866-
ty::mk_nil());
866+
ty::mk_nil(ccx.tcx()));
867867
ccx.intrinsics().borrow_mut().insert($name, f.clone());
868868
return Some(f);
869869
}

src/librustc/middle/trans/debuginfo.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ impl TypeMap {
350350
unique_type_id.push('{');
351351

352352
match ty::get(type_).sty {
353-
ty::ty_nil |
354353
ty::ty_bool |
355354
ty::ty_char |
356355
ty::ty_str |
@@ -367,6 +366,9 @@ impl TypeMap {
367366
unique_type_id.push_str("struct ");
368367
from_def_id_and_substs(self, cx, def_id, substs, &mut unique_type_id);
369368
},
369+
ty::ty_tup(ref component_types) if component_types.is_empty() => {
370+
push_debuginfo_type_name(cx, type_, false, &mut unique_type_id);
371+
},
370372
ty::ty_tup(ref component_types) => {
371373
unique_type_id.push_str("tuple ");
372374
for &component_type in component_types.iter() {
@@ -1736,7 +1738,6 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
17361738
debug!("basic_type_metadata: {}", ty::get(t));
17371739

17381740
let (name, encoding) = match ty::get(t).sty {
1739-
ty::ty_nil => ("()".to_string(), DW_ATE_unsigned),
17401741
ty::ty_bool => ("bool".to_string(), DW_ATE_boolean),
17411742
ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char),
17421743
ty::ty_int(int_ty) => match int_ty {
@@ -2773,7 +2774,7 @@ fn subroutine_type_metadata(cx: &CrateContext,
27732774
// return type
27742775
signature_metadata.push(match signature.output {
27752776
ty::FnConverging(ret_ty) => match ty::get(ret_ty).sty {
2776-
ty::ty_nil => ptr::null_mut(),
2777+
ty::ty_tup(ref tys) if tys.is_empty() => ptr::null_mut(),
27772778
_ => type_metadata(cx, ret_ty, span)
27782779
},
27792780
ty::FnDiverging => diverging_type_metadata(cx)
@@ -2880,7 +2881,6 @@ fn type_metadata(cx: &CrateContext,
28802881

28812882
let sty = &ty::get(t).sty;
28822883
let MetadataCreationResult { metadata, already_stored_in_typemap } = match *sty {
2883-
ty::ty_nil |
28842884
ty::ty_bool |
28852885
ty::ty_char |
28862886
ty::ty_int(_) |
@@ -3671,7 +3671,6 @@ fn push_debuginfo_type_name(cx: &CrateContext,
36713671
qualified: bool,
36723672
output:&mut String) {
36733673
match ty::get(t).sty {
3674-
ty::ty_nil => output.push_str("()"),
36753674
ty::ty_bool => output.push_str("bool"),
36763675
ty::ty_char => output.push_str("char"),
36773676
ty::ty_str => output.push_str("str"),

src/librustc/middle/trans/foreign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn decl_rust_fn_with_foreign_abi(ccx: &CrateContext,
520520
}
521521
_ => panic!("expected bare fn in decl_rust_fn_with_foreign_abi")
522522
};
523-
let llfn = base::decl_fn(ccx, name, cconv, llfn_ty, ty::FnConverging(ty::mk_nil()));
523+
let llfn = base::decl_fn(ccx, name, cconv, llfn_ty, ty::FnConverging(ty::mk_nil(ccx.tcx())));
524524
add_argument_attributes(&tys, llfn);
525525
debug!("decl_rust_fn_with_foreign_abi(llfn_ty={}, llfn={})",
526526
ccx.tn().type_to_string(llfn_ty), ccx.tn().val_to_string(llfn));

src/librustc/middle/trans/glue.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
159159

160160
let (glue, new_sym) = match ccx.available_drop_glues().borrow().get(&t) {
161161
Some(old_sym) => {
162-
let glue = decl_cdecl_fn(ccx, old_sym.as_slice(), llfnty, ty::mk_nil());
162+
let glue = decl_cdecl_fn(ccx, old_sym.as_slice(), llfnty, ty::mk_nil(ccx.tcx()));
163163
(glue, None)
164164
},
165165
None => {
@@ -288,7 +288,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
288288
}
289289

290290
let dtor_ty = ty::mk_ctor_fn(variant_cx.tcx(), ast::DUMMY_NODE_ID,
291-
[get_drop_glue_type(bcx.ccx(), t)], ty::mk_nil());
291+
[get_drop_glue_type(bcx.ccx(), t)], ty::mk_nil(bcx.tcx()));
292292
let (_, variant_cx) = invoke(variant_cx, dtor_addr, args, dtor_ty, None, false);
293293

294294
variant_cx.fcx.pop_and_trans_custom_cleanup_scope(variant_cx, field_scope);
@@ -520,7 +520,7 @@ fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
520520
ccx,
521521
t,
522522
format!("glue_{}", name).as_slice());
523-
let llfn = decl_cdecl_fn(ccx, fn_nm.as_slice(), llfnty, ty::mk_nil());
523+
let llfn = decl_cdecl_fn(ccx, fn_nm.as_slice(), llfnty, ty::mk_nil(ccx.tcx()));
524524
note_unique_llvm_symbol(ccx, fn_nm.clone());
525525
return (fn_nm, llfn);
526526
}
@@ -538,10 +538,11 @@ fn make_generic_glue(ccx: &CrateContext,
538538

539539
let arena = TypedArena::new();
540540
let empty_param_substs = param_substs::empty();
541-
let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false, ty::FnConverging(ty::mk_nil()),
541+
let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false,
542+
ty::FnConverging(ty::mk_nil(ccx.tcx())),
542543
&empty_param_substs, None, &arena);
543544

544-
let bcx = init_function(&fcx, false, ty::FnConverging(ty::mk_nil()));
545+
let bcx = init_function(&fcx, false, ty::FnConverging(ty::mk_nil(ccx.tcx())));
545546

546547
update_linkage(ccx, llfn, None, OriginalTranslation);
547548

@@ -556,7 +557,7 @@ fn make_generic_glue(ccx: &CrateContext,
556557

557558
let llrawptr0 = get_param(llfn, fcx.arg_pos(0) as c_uint);
558559
let bcx = helper(bcx, llrawptr0, t);
559-
finish_fn(&fcx, bcx, ty::FnConverging(ty::mk_nil()));
560+
finish_fn(&fcx, bcx, ty::FnConverging(ty::mk_nil(ccx.tcx())));
560561

561562
llfn
562563
}

src/librustc/middle/trans/meth.rs

-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,6 @@ pub fn get_vtable(bcx: Block,
594594
new_inputs.push(element.subst(bcx.tcx(), substs));
595595
}
596596
}
597-
ty::ty_nil => {}
598597
_ => {
599598
bcx.tcx().sess.bug("get_vtable(): closure \
600599
type wasn't a tuple")

src/librustc/middle/trans/type_of.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ pub fn untuple_arguments_if_necessary(ccx: &CrateContext,
8383
result.push(tupled_argument);
8484
}
8585
}
86-
ty::ty_nil => {}
8786
_ => {
8887
ccx.tcx().sess.bug("argument to function with \"rust-call\" ABI \
8988
is neither a tuple nor unit")
@@ -186,7 +185,6 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
186185
ppaux::ty_to_string(cx.tcx(), t)).as_slice())
187186
}
188187

189-
ty::ty_nil => Type::nil(cx),
190188
ty::ty_bool => Type::bool(cx),
191189
ty::ty_char => Type::char(cx),
192190
ty::ty_int(t) => Type::int_from_ty(cx, t),
@@ -211,6 +209,10 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
211209
Type::array(&llty, size)
212210
}
213211

212+
ty::ty_tup(ref tys) if tys.is_empty() => {
213+
Type::nil(cx)
214+
}
215+
214216
ty::ty_tup(..) | ty::ty_enum(..) | ty::ty_unboxed_closure(..) => {
215217
let repr = adt::represent_type(cx, t);
216218
adt::sizing_type_of(cx, &*repr, false)
@@ -298,7 +300,6 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
298300
}
299301

300302
let mut llty = match ty::get(t).sty {
301-
ty::ty_nil => Type::nil(cx),
302303
ty::ty_bool => Type::bool(cx),
303304
ty::ty_char => Type::char(cx),
304305
ty::ty_int(t) => Type::int_from_ty(cx, t),
@@ -365,6 +366,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
365366
let fn_ty = type_of_fn_from_ty(cx, t).ptr_to();
366367
Type::struct_(cx, [fn_ty, Type::i8p(cx)], false)
367368
}
369+
ty::ty_tup(ref tys) if tys.is_empty() => Type::nil(cx),
368370
ty::ty_tup(..) => {
369371
let repr = adt::represent_type(cx, t);
370372
adt::type_of(cx, &*repr)

0 commit comments

Comments
 (0)