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

Lines changed: 8 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 17 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
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(..) |

0 commit comments

Comments
 (0)