Skip to content

Commit f2a1efe

Browse files
committed
auto merge of #18752 : jakub-/rust/remove-unit, r=eddyb
Closes #18614.
2 parents 40fb87d + b621b8d commit f2a1efe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+415
-524
lines changed

src/doc/reference.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,9 @@ Examples of floating-point literals of various forms:
458458
12E+99_f64; // type f64
459459
```
460460

461-
##### Unit and boolean literals
461+
##### Boolean literals
462462

463-
The _unit value_, the only value of the type that has the same name, is written
464-
as `()`. The two values of the boolean type are written `true` and `false`.
463+
The two values of the boolean type are written `true` and `false`.
465464

466465
### Symbols
467466

@@ -2716,7 +2715,7 @@ or an item. Path expressions are [lvalues](#lvalues,-rvalues-and-temporaries).
27162715

27172716
### Tuple expressions
27182717

2719-
Tuples are written by enclosing one or more comma-separated expressions in
2718+
Tuples are written by enclosing zero or more comma-separated expressions in
27202719
parentheses. They are used to create [tuple-typed](#tuple-types) values.
27212720

27222721
```{.tuple}
@@ -2725,6 +2724,11 @@ parentheses. They are used to create [tuple-typed](#tuple-types) values.
27252724
("a", 4u, true);
27262725
```
27272726

2727+
### Unit expressions
2728+
2729+
The expression `()` denotes the _unit value_, the only value of the type with
2730+
the same name.
2731+
27282732
### Structure expressions
27292733

27302734
```{.ebnf .gram}

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,

src/librustc/lint/builtin.rs

+5-2
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,7 +737,8 @@ impl LintPass for UnusedResults {
735737
let t = ty::expr_ty(cx.tcx, expr);
736738
let mut warned = false;
737739
match ty::get(t).sty {
738-
ty::ty_nil | ty::ty_bool => return,
740+
ty::ty_tup(ref tys) if tys.is_empty() => return,
741+
ty::ty_bool => return,
739742
ty::ty_struct(did, _) |
740743
ty::ty_enum(did, _) => {
741744
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

+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};
@@ -331,7 +331,6 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
331331
fn const_val_to_expr(value: &const_val) -> P<Expr> {
332332
let node = match value {
333333
&const_bool(b) => LitBool(b),
334-
&const_nil => LitNil,
335334
_ => unreachable!()
336335
};
337336
P(Expr {
@@ -496,9 +495,6 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t,
496495
ty::ty_bool =>
497496
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),
498497

499-
ty::ty_nil =>
500-
vec!(ConstantValue(const_nil)),
501-
502498
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
503499
ty::ty_vec(_, None) =>
504500
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
@@ -551,7 +547,7 @@ fn is_useful(cx: &MatchCheckCtxt,
551547
None => v[0]
552548
};
553549
let left_ty = if real_pat.id == DUMMY_NODE_ID {
554-
ty::mk_nil()
550+
ty::mk_nil(cx.tcx)
555551
} else {
556552
ty::pat_ty(cx.tcx, &*real_pat)
557553
};

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
}

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

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));

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};
@@ -529,7 +529,7 @@ pub fn get_res_dtor(ccx: &CrateContext,
529529
let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
530530
let llty = type_of_dtor(ccx, class_ty);
531531
let dtor_ty = ty::mk_ctor_fn(ccx.tcx(), ast::DUMMY_NODE_ID,
532-
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil());
532+
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil(ccx.tcx()));
533533
get_extern_fn(ccx,
534534
&mut *ccx.externs().borrow_mut(),
535535
name.as_slice(),
@@ -563,7 +563,7 @@ pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
563563
let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op));
564564

565565
match ty::get(t).sty {
566-
ty::ty_nil => f(nil_type),
566+
ty::ty_tup(ref tys) if tys.is_empty() => f(nil_type),
567567
ty::ty_bool | ty::ty_uint(_) | ty::ty_char => f(unsigned_int),
568568
ty::ty_ptr(mt) if ty::type_is_sized(cx.tcx(), mt.ty) => f(unsigned_int),
569569
ty::ty_int(_) => f(signed_int),
@@ -1590,12 +1590,6 @@ fn create_datums_for_fn_args_under_call_abi(
15901590
"argtuple"));
15911591
result.push(tuple);
15921592
}
1593-
ty::ty_nil => {
1594-
let mode = datum::Rvalue::new(datum::ByValue);
1595-
result.push(datum::Datum::new(C_nil(bcx.ccx()),
1596-
ty::mk_nil(),
1597-
mode))
1598-
}
15991593
_ => {
16001594
bcx.tcx().sess.bug("last argument of a function with \
16011595
`rust-call` ABI isn't a tuple?!")
@@ -1659,10 +1653,8 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>(
16591653
arg_datum.to_lvalue_datum_in_scope(bcx,
16601654
"argtuple",
16611655
arg_scope_id));
1662-
let empty = Vec::new();
16631656
let untupled_arg_types = match ty::get(monomorphized_arg_types[0]).sty {
16641657
ty::ty_tup(ref types) => types.as_slice(),
1665-
ty::ty_nil => empty.as_slice(),
16661658
_ => {
16671659
bcx.tcx().sess.span_bug(args[0].pat.span,
16681660
"first arg to `rust-call` ABI function \
@@ -1836,7 +1828,7 @@ pub fn trans_closure(ccx: &CrateContext,
18361828
NotUnboxedClosure => monomorphized_arg_types,
18371829

18381830
// Tuple up closure argument types for the "rust-call" ABI.
1839-
IsUnboxedClosure => vec![ty::mk_tup_or_nil(ccx.tcx(), monomorphized_arg_types)]
1831+
IsUnboxedClosure => vec![ty::mk_tup(ccx.tcx(), monomorphized_arg_types)]
18401832
};
18411833
for monomorphized_arg_type in monomorphized_arg_types.iter() {
18421834
debug!("trans_closure: monomorphized_arg_type: {}",
@@ -2392,7 +2384,6 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
23922384
assert!(abi == RustCall);
23932385

23942386
match ty::get(fn_sig.inputs[0]).sty {
2395-
ty::ty_nil => Vec::new(),
23962387
ty::ty_tup(ref inputs) => inputs.clone(),
23972388
_ => ccx.sess().bug("expected tuple'd inputs")
23982389
}
@@ -2401,7 +2392,6 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
24012392
let mut inputs = vec![fn_sig.inputs[0]];
24022393

24032394
match ty::get(fn_sig.inputs[1]).sty {
2404-
ty::ty_nil => inputs,
24052395
ty::ty_tup(ref t_in) => {
24062396
inputs.push_all(t_in.as_slice());
24072397
inputs
@@ -2544,7 +2534,7 @@ pub fn register_fn_llvmty(ccx: &CrateContext,
25442534
llfty: Type) -> ValueRef {
25452535
debug!("register_fn_llvmty id={} sym={}", node_id, sym);
25462536

2547-
let llfn = decl_fn(ccx, sym.as_slice(), cc, llfty, ty::FnConverging(ty::mk_nil()));
2537+
let llfn = decl_fn(ccx, sym.as_slice(), cc, llfty, ty::FnConverging(ty::mk_nil(ccx.tcx())));
25482538
finish_register_fn(ccx, sp, sym, node_id, llfn);
25492539
llfn
25502540
}
@@ -2576,7 +2566,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
25762566
let llfty = Type::func([ccx.int_type(), Type::i8p(ccx).ptr_to()],
25772567
&ccx.int_type());
25782568

2579-
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil());
2569+
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil(ccx.tcx()));
25802570

25812571
// FIXME: #16581: Marking a symbol in the executable with `dllexport`
25822572
// 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
@@ -763,7 +763,7 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
763763
expr::Ignore => {
764764
let ret_ty = match ret_ty {
765765
ty::FnConverging(ret_ty) => ret_ty,
766-
ty::FnDiverging => ty::mk_nil()
766+
ty::FnDiverging => ty::mk_nil(ccx.tcx())
767767
};
768768
if !is_rust_fn ||
769769
type_of::return_uses_outptr(ccx, ret_ty) ||
@@ -956,7 +956,6 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
956956
llargs.push(arg_datum.add_clean(bcx.fcx, arg_cleanup_scope));
957957
}
958958
}
959-
ty::ty_nil => {}
960959
_ => {
961960
bcx.sess().span_bug(tuple_expr.span,
962961
"argument to `.call()` wasn't a tuple?!")
@@ -1003,7 +1002,6 @@ fn trans_overloaded_call_args<'blk, 'tcx>(
10031002
}))
10041003
}
10051004
}
1006-
ty::ty_nil => {}
10071005
_ => {
10081006
bcx.sess().span_bug(arg_exprs[0].span,
10091007
"argument to `.call()` wasn't a tuple?!")

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
}

src/librustc/middle/trans/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,17 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
719719
macro_rules! ifn (
720720
($name:expr fn() -> $ret:expr) => (
721721
if *key == $name {
722-
let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil());
722+
let f = base::decl_cdecl_fn(
723+
ccx, $name, Type::func([], &$ret),
724+
ty::mk_nil(ccx.tcx()));
723725
ccx.intrinsics().borrow_mut().insert($name, f.clone());
724726
return Some(f);
725727
}
726728
);
727729
($name:expr fn($($arg:expr),*) -> $ret:expr) => (
728730
if *key == $name {
729731
let f = base::decl_cdecl_fn(ccx, $name,
730-
Type::func([$($arg),*], &$ret), ty::mk_nil());
732+
Type::func([$($arg),*], &$ret), ty::mk_nil(ccx.tcx()));
731733
ccx.intrinsics().borrow_mut().insert($name, f.clone());
732734
return Some(f);
733735
}
@@ -864,7 +866,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
864866
} else if *key == $name {
865867
let f = base::decl_cdecl_fn(ccx, stringify!($cname),
866868
Type::func([$($arg),*], &$ret),
867-
ty::mk_nil());
869+
ty::mk_nil(ccx.tcx()));
868870
ccx.intrinsics().borrow_mut().insert($name, f.clone());
869871
return Some(f);
870872
}

0 commit comments

Comments
 (0)