Skip to content

Commit 9cf22ab

Browse files
committed
auto merge of #18752 : jakub-/rust/remove-unit, r=eddyb
Closes #18614.
2 parents 7e43f41 + 7132bd4 commit 9cf22ab

Some content is hidden

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

58 files changed

+448
-530
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

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

27182717
### Tuple expressions
27192718

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

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

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

27312735
```{.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};
@@ -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 {
@@ -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_nil =>
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(),
@@ -552,7 +548,7 @@ fn is_useful(cx: &MatchCheckCtxt,
552548
None => v[0]
553549
};
554550
let left_ty = if real_pat.id == DUMMY_NODE_ID {
555-
ty::mk_nil()
551+
ty::mk_nil(cx.tcx)
556552
} else {
557553
ty::pat_ty(cx.tcx, &*real_pat)
558554
};

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};
@@ -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/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
@@ -718,15 +718,17 @@ 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(
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
}
725727
);
726728
($name:expr fn($($arg:expr),*) -> $ret:expr) => (
727729
if *key == $name {
728730
let f = base::decl_cdecl_fn(ccx, $name,
729-
Type::func([$($arg),*], &$ret), ty::mk_nil());
731+
Type::func([$($arg),*], &$ret), ty::mk_nil(ccx.tcx()));
730732
ccx.intrinsics().borrow_mut().insert($name, f.clone());
731733
return Some(f);
732734
}
@@ -863,7 +865,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
863865
} else if *key == $name {
864866
let f = base::decl_cdecl_fn(ccx, stringify!($cname),
865867
Type::func([$($arg),*], &$ret),
866-
ty::mk_nil());
868+
ty::mk_nil(ccx.tcx()));
867869
ccx.intrinsics().borrow_mut().insert($name, f.clone());
868870
return Some(f);
869871
}

0 commit comments

Comments
 (0)