Skip to content

Remove unit #18752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from Nov 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
@@ -458,10 +458,9 @@ Examples of floating-point literals of various forms:
12E+99_f64; // type f64
```

##### Unit and boolean literals
##### Boolean literals

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

### Symbols

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

### Tuple expressions

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

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

### Unit expressions

The expression `()` denotes the _unit value_, the only value of the type with
the same name.

### Structure expressions

```{.ebnf .gram}
1 change: 0 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -66,7 +66,6 @@ register_diagnostics!(
E0055,
E0056,
E0057,
E0058,
E0059,
E0060,
E0061,
7 changes: 5 additions & 2 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -447,7 +447,9 @@ impl LintPass for ImproperCTypes {
for input in decl.inputs.iter() {
check_ty(cx, &*input.ty);
}
check_ty(cx, &*decl.output)
if let ast::Return(ref ret_ty) = decl.output {
check_ty(cx, &**ret_ty);
}
}

match it.node {
@@ -735,7 +737,8 @@ impl LintPass for UnusedResults {
let t = ty::expr_ty(cx.tcx, expr);
let mut warned = false;
match ty::get(t).sty {
ty::ty_nil | ty::ty_bool => return,
ty::ty_tup(ref tys) if tys.is_empty() => return,
ty::ty_bool => return,
ty::ty_struct(did, _) |
ty::ty_enum(did, _) => {
if ast_util::is_local(did) {
1 change: 0 additions & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
@@ -360,7 +360,6 @@ fn parse_trait_ref(st: &mut PState, conv: conv_did) -> ty::TraitRef {

fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
match next(st) {
'n' => return ty::mk_nil(),
'b' => return ty::mk_bool(),
'i' => return ty::mk_int(),
'u' => return ty::mk_uint(),
1 change: 0 additions & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
@@ -199,7 +199,6 @@ pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore)

fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
match *st {
ty::ty_nil => mywrite!(w, "n"),
ty::ty_bool => mywrite!(w, "b"),
ty::ty_char => mywrite!(w, "c"),
ty::ty_int(t) => {
8 changes: 2 additions & 6 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use middle::const_eval::{compare_const_vals, const_bool, const_float, const_nil, const_val};
use middle::const_eval::{compare_const_vals, const_bool, const_float, const_val};
use middle::const_eval::{const_expr_to_pat, eval_const_expr, lookup_const_by_id};
use middle::def::*;
use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
@@ -332,7 +332,6 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
fn const_val_to_expr(value: &const_val) -> P<Expr> {
let node = match value {
&const_bool(b) => LitBool(b),
&const_nil => LitNil,
_ => unreachable!()
};
P(Expr {
@@ -497,9 +496,6 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t,
ty::ty_bool =>
[true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(),

ty::ty_nil =>
vec!(ConstantValue(const_nil)),

ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
ty::ty_vec(_, None) =>
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
@@ -552,7 +548,7 @@ fn is_useful(cx: &MatchCheckCtxt,
None => v[0]
};
let left_ty = if real_pat.id == DUMMY_NODE_ID {
ty::mk_nil()
ty::mk_nil(cx.tcx)
} else {
ty::pat_ty(cx.tcx, &*real_pat)
};
5 changes: 1 addition & 4 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
@@ -311,8 +311,7 @@ pub enum const_val {
const_uint(u64),
const_str(InternedString),
const_binary(Rc<Vec<u8> >),
const_bool(bool),
const_nil
const_bool(bool)
}

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 {
LitFloatUnsuffixed(ref n) => {
const_float(from_str::<f64>(n.get()).unwrap() as f64)
}
LitNil => const_nil,
LitBool(b) => const_bool(b)
}
}
@@ -605,7 +603,6 @@ pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option<int> {
(&const_str(ref a), &const_str(ref b)) => compare_vals(a, b),
(&const_bool(a), &const_bool(b)) => compare_vals(a, b),
(&const_binary(ref a), &const_binary(ref b)) => compare_vals(a, b),
(&const_nil, &const_nil) => compare_vals((), ()),
_ => None
}
}
8 changes: 6 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
@@ -4285,7 +4285,9 @@ impl<'a> Resolver<'a> {
_ => {}
}

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

this.resolve_type(&*declaration.output);
if let ast::Return(ref ret_ty) = declaration.output {
this.resolve_type(&**ret_ty);
}
}
}

21 changes: 17 additions & 4 deletions src/librustc/middle/save/mod.rs
Original file line number Diff line number Diff line change
@@ -383,7 +383,11 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
for arg in method.pe_fn_decl().inputs.iter() {
self.visit_ty(&*arg.ty);
}
self.visit_ty(&*method.pe_fn_decl().output);

if let ast::Return(ref ret_ty) = method.pe_fn_decl().output {
self.visit_ty(&**ret_ty);
}

// walk the fn body
self.nest(method.id, |v| v.visit_block(&*method.pe_body()));

@@ -491,7 +495,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
for arg in decl.inputs.iter() {
self.visit_ty(&*arg.ty);
}
self.visit_ty(&*decl.output);

if let ast::Return(ref ret_ty) = decl.output {
self.visit_ty(&**ret_ty);
}

// walk the body
self.nest(item.id, |v| v.visit_block(&*body));
@@ -1136,7 +1143,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
for arg in method_type.decl.inputs.iter() {
self.visit_ty(&*arg.ty);
}
self.visit_ty(&*method_type.decl.output);

if let ast::Return(ref ret_ty) = method_type.decl.output {
self.visit_ty(&**ret_ty);
}

self.process_generic_params(&method_type.generics,
method_type.span,
@@ -1352,7 +1362,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
for arg in decl.inputs.iter() {
self.visit_ty(&*arg.ty);
}
self.visit_ty(&*decl.output);

if let ast::Return(ref ret_ty) = decl.output {
self.visit_ty(&**ret_ty);
}

// walk the body
self.nest(ex.id, |v| v.visit_block(&**body));
1 change: 0 additions & 1 deletion src/librustc/middle/traits/coherence.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,6 @@ pub fn ty_is_local(tcx: &ty::ctxt,
debug!("ty_is_local({})", ty.repr(tcx));

match ty::get(ty).sty {
ty::ty_nil |
ty::ty_bool |
ty::ty_char |
ty::ty_int(..) |
1 change: 0 additions & 1 deletion src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
@@ -1227,7 +1227,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::ty_infer(ty::FloatVar(_)) |
ty::ty_uint(_) |
ty::ty_int(_) |
ty::ty_nil |
ty::ty_bool |
ty::ty_float(_) |
ty::ty_bare_fn(_) |
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
@@ -1012,7 +1012,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
.unwrap_or(DUMMY_NODE_ID);

let left_ty = if pat_id == DUMMY_NODE_ID {
ty::mk_nil()
ty::mk_nil(tcx)
} else {
node_id_type(bcx, pat_id)
};
22 changes: 6 additions & 16 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ use middle::trans::builder::{Builder, noname};
use middle::trans::callee;
use middle::trans::cleanup::{CleanupMethods, ScopeId};
use middle::trans::cleanup;
use middle::trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral, C_nil};
use middle::trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral};
use middle::trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef};
use middle::trans::common::{CrateContext, ExternMap, FunctionContext};
use middle::trans::common::{NodeInfo, Result, SubstP};
@@ -517,7 +517,7 @@ pub fn get_res_dtor(ccx: &CrateContext,
let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
let llty = type_of_dtor(ccx, class_ty);
let dtor_ty = ty::mk_ctor_fn(ccx.tcx(), ast::DUMMY_NODE_ID,
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil());
[glue::get_drop_glue_type(ccx, t)], ty::mk_nil(ccx.tcx()));
get_extern_fn(ccx,
&mut *ccx.externs().borrow_mut(),
name.as_slice(),
@@ -551,7 +551,7 @@ pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op));

match ty::get(t).sty {
ty::ty_nil => f(nil_type),
ty::ty_tup(ref tys) if tys.is_empty() => f(nil_type),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used often enough to have it special-cased in the compiler?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In explicit code most likely not but I'd imagine it being used all over the place after monomorphization.

ty::ty_bool | ty::ty_uint(_) | ty::ty_char => f(unsigned_int),
ty::ty_ptr(mt) if ty::type_is_sized(cx.tcx(), mt.ty) => f(unsigned_int),
ty::ty_int(_) => f(signed_int),
@@ -1578,12 +1578,6 @@ fn create_datums_for_fn_args_under_call_abi(
"argtuple"));
result.push(tuple);
}
ty::ty_nil => {
let mode = datum::Rvalue::new(datum::ByValue);
result.push(datum::Datum::new(C_nil(bcx.ccx()),
ty::mk_nil(),
mode))
}
_ => {
bcx.tcx().sess.bug("last argument of a function with \
`rust-call` ABI isn't a tuple?!")
@@ -1647,10 +1641,8 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>(
arg_datum.to_lvalue_datum_in_scope(bcx,
"argtuple",
arg_scope_id));
let empty = Vec::new();
let untupled_arg_types = match ty::get(monomorphized_arg_types[0]).sty {
ty::ty_tup(ref types) => types.as_slice(),
ty::ty_nil => empty.as_slice(),
_ => {
bcx.tcx().sess.span_bug(args[0].pat.span,
"first arg to `rust-call` ABI function \
@@ -1824,7 +1816,7 @@ pub fn trans_closure(ccx: &CrateContext,
NotUnboxedClosure => monomorphized_arg_types,

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

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

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

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

let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil());
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil(ccx.tcx()));

// FIXME: #16581: Marking a symbol in the executable with `dllexport`
// linkage forces MinGW's linker to output a `.reloc` section for ASLR
4 changes: 1 addition & 3 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
@@ -764,7 +764,7 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
expr::Ignore => {
let ret_ty = match ret_ty {
ty::FnConverging(ret_ty) => ret_ty,
ty::FnDiverging => ty::mk_nil()
ty::FnDiverging => ty::mk_nil(ccx.tcx())
};
if !is_rust_fn ||
type_of::return_uses_outptr(ccx, ret_ty) ||
@@ -957,7 +957,6 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
llargs.push(arg_datum.add_clean(bcx.fcx, arg_cleanup_scope));
}
}
ty::ty_nil => {}
_ => {
bcx.sess().span_bug(tuple_expr.span,
"argument to `.call()` wasn't a tuple?!")
@@ -1004,7 +1003,6 @@ fn trans_overloaded_call_args<'blk, 'tcx>(
}))
}
}
ty::ty_nil => {}
_ => {
bcx.sess().span_bug(arg_exprs[0].span,
"argument to `.call()` wasn't a tuple?!")
1 change: 0 additions & 1 deletion src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit)
}
}
ast::LitBool(b) => C_bool(cx, b),
ast::LitNil => C_nil(cx),
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
ast::LitBinary(ref data) => C_binary_slice(cx, data.as_slice()),
}
8 changes: 5 additions & 3 deletions src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
@@ -718,15 +718,17 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
macro_rules! ifn (
($name:expr fn() -> $ret:expr) => (
if *key == $name {
let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil());
let f = base::decl_cdecl_fn(
ccx, $name, Type::func([], &$ret),
ty::mk_nil(ccx.tcx()));
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
}
);
($name:expr fn($($arg:expr),*) -> $ret:expr) => (
if *key == $name {
let f = base::decl_cdecl_fn(ccx, $name,
Type::func([$($arg),*], &$ret), ty::mk_nil());
Type::func([$($arg),*], &$ret), ty::mk_nil(ccx.tcx()));
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
}
@@ -863,7 +865,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
} else if *key == $name {
let f = base::decl_cdecl_fn(ccx, stringify!($cname),
Type::func([$($arg),*], &$ret),
ty::mk_nil());
ty::mk_nil(ccx.tcx()));
ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
}
Loading