未验证 提交 9c0f946f 编写于 作者: K kennytm 提交者: GitHub

Rollup merge of #54095 - kenta7777:kenta7777#53719, r=davidtwco

Rename all mentions of `nil` to `unit`

Fixes #53719.

Renamed keywords nil to unit.
......@@ -661,7 +661,7 @@ pub fn report_selection_error(&self,
{
let predicate = trait_predicate.map_bound(|mut trait_pred| {
trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
self.tcx.mk_nil(),
self.tcx.mk_unit(),
&trait_pred.trait_ref.substs[1..],
);
trait_pred
......
......@@ -2492,7 +2492,7 @@ pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
}
pub fn mk_nil_ptr(self) -> Ty<'tcx> {
self.mk_imm_ptr(self.mk_nil())
self.mk_imm_ptr(self.mk_unit())
}
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
......@@ -2511,7 +2511,7 @@ pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
iter.intern_with(|ts| self.mk_ty(Tuple(self.intern_type_list(ts))))
}
pub fn mk_nil(self) -> Ty<'tcx> {
pub fn mk_unit(self) -> Ty<'tcx> {
self.intern_tup(&[])
}
......
......@@ -132,7 +132,7 @@ fn to_ty<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
Int(i, signed) => i.to_ty(tcx, signed),
Float(FloatTy::F32) => tcx.types.f32,
Float(FloatTy::F64) => tcx.types.f64,
Pointer => tcx.mk_mut_ptr(tcx.mk_nil()),
Pointer => tcx.mk_mut_ptr(tcx.mk_unit()),
}
}
}
......@@ -1606,7 +1606,7 @@ fn field(this: TyLayout<'tcx>, cx: C, i: usize) -> C::TyLayout {
// (which may have no non-DST form), and will work as long
// as the `Abi` or `FieldPlacement` is checked by users.
if i == 0 {
let nil = tcx.mk_nil();
let nil = tcx.mk_unit();
let ptr_ty = if this.ty.is_unsafe_ptr() {
tcx.mk_mut_ptr(nil)
} else {
......
......@@ -1020,7 +1020,7 @@ impl<'enc, 'a, 'tcx, E> Encoder for CacheEncoder<'enc, 'a, 'tcx, E>
{
type Error = E::Error;
fn emit_nil(&mut self) -> Result<(), Self::Error> {
fn emit_unit(&mut self) -> Result<(), Self::Error> {
Ok(())
}
......
......@@ -1458,7 +1458,7 @@ pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_, '_, '_>) -> DefId {
/// Type utilities
impl<'a, 'gcx, 'tcx> TyS<'tcx> {
pub fn is_nil(&self) -> bool {
pub fn is_unit(&self) -> bool {
match self.sty {
Tuple(ref tys) => tys.is_empty(),
_ => false,
......
......@@ -234,7 +234,7 @@ fn fn_sig<F: fmt::Write>(&mut self,
}
}
write!(f, ")")?;
if !output.is_nil() {
if !output.is_unit() {
print!(f, self, write(" -> "), print_display(output))?;
}
......
......@@ -160,7 +160,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
output.push(')');
if !sig.output().is_nil() {
if !sig.output().is_unit() {
output.push_str(" -> ");
push_debuginfo_type_name(cx, sig.output(), true, output);
}
......
......@@ -968,7 +968,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
let fn_ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
iter::once(i8p),
tcx.mk_nil(),
tcx.mk_unit(),
false,
hir::Unsafety::Unsafe,
Abi::Rust
......
......@@ -566,7 +566,7 @@ pub fn codegen_scalar_binop(
) -> &'ll Value {
let is_float = input_ty.is_fp();
let is_signed = input_ty.is_signed();
let is_nil = input_ty.is_nil();
let is_unit = input_ty.is_unit();
match op {
mir::BinOp::Add => if is_float {
bx.fadd(lhs, rhs)
......@@ -604,7 +604,7 @@ pub fn codegen_scalar_binop(
mir::BinOp::Shl => common::build_unchecked_lshift(bx, lhs, rhs),
mir::BinOp::Shr => common::build_unchecked_rshift(bx, input_ty, lhs, rhs),
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt |
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_nil {
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_unit {
C_bool(bx.cx, match op {
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt => false,
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => true,
......
......@@ -309,7 +309,7 @@ pub fn t_fn(&self, input_tys: &[Ty<'tcx>], output_ty: Ty<'tcx>) -> Ty<'tcx> {
}
pub fn t_nil(&self) -> Ty<'tcx> {
self.infcx.tcx.mk_nil()
self.infcx.tcx.mk_unit()
}
pub fn t_pair(&self, ty1: Ty<'tcx>, ty2: Ty<'tcx>) -> Ty<'tcx> {
......
......@@ -691,7 +691,7 @@ fn check_type_for_ffi(&self,
}
let sig = cx.erase_late_bound_regions(&sig);
if !sig.output().is_nil() {
if !sig.output().is_unit() {
let r = self.check_type_for_ffi(cache, sig.output());
match r {
FfiSafe => {}
......@@ -767,7 +767,7 @@ fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) {
if let hir::Return(ref ret_hir) = decl.output {
let ret_ty = sig.output();
if !ret_ty.is_nil() {
if !ret_ty.is_unit() {
self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty);
}
}
......
......@@ -75,7 +75,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
type Error = <opaque::Encoder as Encoder>::Error;
fn emit_nil(&mut self) -> Result<(), Self::Error> {
fn emit_unit(&mut self) -> Result<(), Self::Error> {
Ok(())
}
......
......@@ -167,7 +167,7 @@ fn ast_block_stmts(&mut self,
// the case of `!`, no return value is required, as the block will never return.
let tcx = this.hir.tcx();
let ty = destination.ty(&this.local_decls, tcx).to_ty(tcx);
if ty.is_nil() {
if ty.is_unit() {
// We only want to assign an implicit `()` as the return value of the block if the
// block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.)
this.cfg.push_assign_unit(block, source_info, destination);
......
......@@ -118,7 +118,7 @@ pub fn bool_ty(&mut self) -> Ty<'tcx> {
}
pub fn unit_ty(&mut self) -> Ty<'tcx> {
self.tcx.mk_nil()
self.tcx.mk_unit()
}
pub fn true_literal(&mut self) -> &'tcx ty::Const<'tcx> {
......
......@@ -436,7 +436,7 @@ fn drop_in_place(
layout: self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?,
};
let ty = self.tcx.mk_nil(); // return type is ()
let ty = self.tcx.mk_unit(); // return type is ()
let dest = PlaceTy::null(&self, self.layout_of(ty)?);
self.eval_fn_call(
......
......@@ -368,7 +368,7 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
output.push(')');
if !sig.output().is_nil() {
if !sig.output().is_unit() {
output.push_str(" -> ");
self.push_type_name(sig.output(), output);
}
......
......@@ -518,7 +518,7 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
let upvar_len = mir.upvar_decls.len();
let dummy_local = LocalDecl::new_internal(tcx.mk_nil(), mir.span);
let dummy_local = LocalDecl::new_internal(tcx.mk_unit(), mir.span);
// Gather live locals and their indices replacing values in mir.local_decls with a dummy
// to avoid changing local indices
......@@ -656,7 +656,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
// Replace the return variable
mir.local_decls[RETURN_PLACE] = LocalDecl {
mutability: Mutability::Mut,
ty: tcx.mk_nil(),
ty: tcx.mk_unit(),
user_ty: None,
name: None,
source_info,
......
......@@ -529,7 +529,7 @@ fn destructor_call_block<'a>(&mut self, (succ, unwind): (BasicBlock, Unwind))
mutbl: hir::Mutability::MutMutable
});
let ref_place = self.new_temp(ref_ty);
let unit_temp = Place::Local(self.new_temp(tcx.mk_nil()));
let unit_temp = Place::Local(self.new_temp(tcx.mk_unit()));
let result = BasicBlockData {
statements: vec![self.assign(
......@@ -891,7 +891,7 @@ fn unelaborated_free_block<'a>(
unwind: Unwind
) -> BasicBlock {
let tcx = self.tcx();
let unit_temp = Place::Local(self.new_temp(tcx.mk_nil()));
let unit_temp = Place::Local(self.new_temp(tcx.mk_unit()));
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem);
let args = adt.variants[0].fields.iter().enumerate().map(|(i, f)| {
let field = Field::new(i);
......
......@@ -1575,7 +1575,7 @@ pub fn ty_of_fn(&self,
let output_ty = match decl.output {
hir::Return(ref output) => self.ast_ty_to_ty(output),
hir::DefaultReturn(..) => tcx.mk_nil(),
hir::DefaultReturn(..) => tcx.mk_unit(),
};
debug!("ty_of_fn: output_ty={:?}", output_ty);
......
......@@ -666,7 +666,7 @@ pub fn check_match(&self,
// us to give better error messages (pointing to a usually better
// arm for inconsistent arms or to the whole match when a `()` type
// is required).
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_nil() => ety,
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_unit() => ety,
_ => self.next_ty_var(TypeVariableOrigin::MiscVariable(expr.span)),
};
CoerceMany::with_coercion_sites(coerce_first, arms)
......@@ -687,14 +687,14 @@ pub fn check_match(&self,
// Handle the fallback arm of a desugared if-let like a missing else.
let is_if_let_fallback = match match_src {
hir::MatchSource::IfLetDesugar { contains_else_clause: false } => {
i == arms.len() - 1 && arm_ty.is_nil()
i == arms.len() - 1 && arm_ty.is_unit()
}
_ => false
};
if is_if_let_fallback {
let cause = self.cause(expr.span, ObligationCauseCode::IfExpressionWithNoElse);
assert!(arm_ty.is_nil());
assert!(arm_ty.is_unit());
coercion.coerce_forced_unit(self, &cause, &mut |_| (), true);
} else {
let cause = self.cause(expr.span, ObligationCauseCode::MatchExpressionArm {
......
......@@ -1077,7 +1077,7 @@ pub fn coerce_forced_unit<'a>(&mut self,
self.coerce_inner(fcx,
cause,
None,
fcx.tcx.mk_nil(),
fcx.tcx.mk_unit(),
Some(augment_error),
label_unit_as_expected)
}
......@@ -1146,8 +1146,8 @@ fn coerce_inner<'a>(&mut self,
// `expression_ty` will be unit).
//
// Another example is `break` with no argument expression.
assert!(expression_ty.is_nil());
assert!(expression_ty.is_nil(), "if let hack without unit type");
assert!(expression_ty.is_unit());
assert!(expression_ty.is_unit(), "if let hack without unit type");
fcx.at(cause, fcx.param_env)
.eq_exp(label_expression_as_expected, expression_ty, self.merged_ty())
.map(|infer_ok| {
......
......@@ -94,7 +94,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"load" => (1, vec![tcx.mk_imm_ptr(param(0))],
param(0)),
"store" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)],
tcx.mk_nil()),
tcx.mk_unit()),
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" |
"min" | "umax" | "umin" => {
......@@ -102,7 +102,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
param(0))
}
"fence" | "singlethreadfence" => {
(0, Vec::new(), tcx.mk_nil())
(0, Vec::new(), tcx.mk_unit())
}
op => {
struct_span_err!(tcx.sess, it.span, E0092,
......@@ -121,7 +121,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_ => hir::Unsafety::Unsafe,
};
let (n_tps, inputs, output) = match &name[..] {
"breakpoint" => (0, Vec::new(), tcx.mk_nil()),
"breakpoint" => (0, Vec::new(), tcx.mk_unit()),
"size_of" |
"pref_align_of" | "min_align_of" => (1, Vec::new(), tcx.types.usize),
"size_of_val" | "min_align_of_val" => {
......@@ -141,7 +141,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.mk_mut_ptr(param(0)),
param(0)
],
tcx.mk_nil())
tcx.mk_unit())
}
"prefetch_read_data" | "prefetch_write_data" |
"prefetch_read_instruction" | "prefetch_write_instruction" => {
......@@ -149,10 +149,10 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: param(0),
mutbl: hir::MutImmutable
}), tcx.types.i32],
tcx.mk_nil())
tcx.mk_unit())
}
"drop_in_place" => {
(1, vec![tcx.mk_mut_ptr(param(0))], tcx.mk_nil())
(1, vec![tcx.mk_mut_ptr(param(0))], tcx.mk_unit())
}
"needs_drop" => (1, Vec::new(), tcx.types.bool),
......@@ -185,7 +185,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}),
tcx.types.usize,
],
tcx.mk_nil())
tcx.mk_unit())
}
"volatile_copy_memory" | "volatile_copy_nonoverlapping_memory" => {
(1,
......@@ -200,7 +200,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}),
tcx.types.usize,
],
tcx.mk_nil())
tcx.mk_unit())
}
"write_bytes" | "volatile_set_memory" => {
(1,
......@@ -212,7 +212,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.types.u8,
tcx.types.usize,
],
tcx.mk_nil())
tcx.mk_unit())
}
"sqrtf32" => (0, vec![ tcx.types.f32 ], tcx.types.f32),
"sqrtf64" => (0, vec![ tcx.types.f64 ], tcx.types.f64),
......@@ -280,7 +280,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"volatile_load" | "unaligned_volatile_load" =>
(1, vec![ tcx.mk_imm_ptr(param(0)) ], param(0)),
"volatile_store" | "unaligned_volatile_store" =>
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_nil()),
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_unit()),
"ctpop" | "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" |
"bswap" | "bitreverse" =>
......@@ -300,7 +300,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" =>
(1, vec![param(0), param(0)], param(0)),
"assume" => (0, vec![tcx.types.bool], tcx.mk_nil()),
"assume" => (0, vec![tcx.types.bool], tcx.mk_unit()),
"likely" => (0, vec![tcx.types.bool], tcx.types.bool),
"unlikely" => (0, vec![tcx.types.bool], tcx.types.bool),
......@@ -313,7 +313,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
let fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
iter::once(mut_u8),
tcx.mk_nil(),
tcx.mk_unit(),
false,
hir::Unsafety::Normal,
Abi::Rust,
......@@ -322,7 +322,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
"nontemporal_store" => {
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_nil())
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_unit())
}
ref other => {
......@@ -376,7 +376,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
(3, vec![param(0), param(1), param(2)], param(0))
}
"simd_scatter" => {
(3, vec![param(0), param(1), param(2)], tcx.mk_nil())
(3, vec![param(0), param(1), param(2)], tcx.mk_unit())
}
"simd_insert" => (2, vec![param(0), tcx.types.u32, param(1)], param(0)),
"simd_extract" => (2, vec![param(0), tcx.types.u32], param(1)),
......
......@@ -2808,9 +2808,9 @@ fn check_argument_types(&self,
} else {
// is the missing argument of type `()`?
let sugg_unit = if expected_arg_tys.len() == 1 && supplied_arg_count == 0 {
self.resolve_type_vars_if_possible(&expected_arg_tys[0]).is_nil()
self.resolve_type_vars_if_possible(&expected_arg_tys[0]).is_unit()
} else if fn_inputs.len() == 1 && supplied_arg_count == 0 {
self.resolve_type_vars_if_possible(&fn_inputs[0]).is_nil()
self.resolve_type_vars_if_possible(&fn_inputs[0]).is_unit()
} else {
false
};
......@@ -3918,7 +3918,7 @@ fn check_expr_kind(&self,
for input in inputs {
self.check_expr(input);
}
tcx.mk_nil()
tcx.mk_unit()
}
hir::ExprKind::Break(destination, ref expr_opt) => {
if let Ok(target_id) = destination.target_id {
......@@ -3945,7 +3945,7 @@ fn check_expr_kind(&self,
} else {
// Otherwise, this is a break *without* a value. That's
// always legal, and is equivalent to `break ()`.
e_ty = tcx.mk_nil();
e_ty = tcx.mk_unit();
cause = self.misc(expr.span);
}
......@@ -3958,7 +3958,7 @@ fn check_expr_kind(&self,
if let Some(ref e) = *expr_opt {
coerce.coerce(self, &cause, e, e_ty);
} else {
assert!(e_ty.is_nil());
assert!(e_ty.is_unit());
coerce.coerce_forced_unit(self, &cause, &mut |_| (), true);
}
} else {
......@@ -4052,7 +4052,7 @@ fn check_expr_kind(&self,
if lhs_ty.references_error() || rhs_ty.references_error() {
tcx.types.err
} else {
tcx.mk_nil()
tcx.mk_unit()
}
}
hir::ExprKind::If(ref cond, ref then_expr, ref opt_else_expr) => {
......@@ -4081,7 +4081,7 @@ fn check_expr_kind(&self,
self.diverges.set(Diverges::Maybe);
}
self.tcx.mk_nil()
self.tcx.mk_unit()
}
hir::ExprKind::Loop(ref body, _, source) => {
let coerce = match source {
......@@ -4121,7 +4121,7 @@ fn check_expr_kind(&self,
// [1]
self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break");
}
ctxt.coerce.map(|c| c.complete(self)).unwrap_or(self.tcx.mk_nil())
ctxt.coerce.map(|c| c.complete(self)).unwrap_or(self.tcx.mk_unit())
}
hir::ExprKind::Match(ref discrim, ref arms, match_src) => {
self.check_match(expr, &discrim, arms, expected, match_src)
......@@ -4352,7 +4352,7 @@ fn check_expr_kind(&self,
"yield statement outside of generator literal").emit();
}
}
tcx.mk_nil()
tcx.mk_unit()
}
}
}
......@@ -4516,7 +4516,7 @@ pub fn check_stmt(&self, stmt: &'gcx hir::Stmt) {
}
hir::StmtKind::Expr(ref expr, _) => {
// Check with expected type of ()
self.check_expr_has_type_or_error(&expr, self.tcx.mk_nil());
self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit());
}
hir::StmtKind::Semi(ref expr, _) => {
self.check_expr(&expr);
......@@ -4529,7 +4529,7 @@ pub fn check_stmt(&self, stmt: &'gcx hir::Stmt) {
}
pub fn check_block_no_value(&self, blk: &'gcx hir::Block) {
let unit = self.tcx.mk_nil();
let unit = self.tcx.mk_unit();
let ty = self.check_block_with_expected(blk, ExpectHasType(unit));
// if the block produces a `!` value, that can always be
......@@ -4752,7 +4752,7 @@ fn suggest_missing_semicolon(&self,
expression: &'gcx hir::Expr,
expected: Ty<'tcx>,
cause_span: Span) {
if expected.is_nil() {
if expected.is_unit() {
// `BlockTailExpression` only relevant if the tail expr would be
// useful on its own.
match expression.node {
......@@ -4795,7 +4795,7 @@ fn suggest_missing_return_type(&self,
can_suggest: bool) {
// Only suggest changing the return type for methods that
// haven't set a return type at all (and aren't `fn main()` or an impl).
match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_nil()) {
match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_unit()) {
(&hir::FunctionRetTy::DefaultReturn(span), true, true, true) => {
err.span_suggestion_with_applicability(
span,
......
......@@ -35,7 +35,7 @@ pub fn check_binop_assign(&self,
let ty = if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var()
&& is_builtin_binop(lhs_ty, rhs_ty, op) {
self.enforce_builtin_binop_types(lhs_expr, lhs_ty, rhs_expr, rhs_ty, op);
self.tcx.mk_nil()
self.tcx.mk_unit()
} else {
return_ty
};
......
......@@ -224,7 +224,7 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
actual.output().skip_binder()
} else {
// standard () main return type
tcx.mk_nil()
tcx.mk_unit()
};
let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(
......
......@@ -490,7 +490,7 @@ pub fn new(writer: &'a mut dyn fmt::Write) -> Encoder<'a> {
impl<'a> ::Encoder for Encoder<'a> {
type Error = EncoderError;
fn emit_nil(&mut self) -> EncodeResult {
fn emit_unit(&mut self) -> EncodeResult {
if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); }
write!(self.writer, "null")?;
Ok(())
......@@ -648,7 +648,7 @@ fn emit_option<F>(&mut self, f: F) -> EncodeResult where
}
fn emit_option_none(&mut self) -> EncodeResult {
if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); }
self.emit_nil()
self.emit_unit()
}
fn emit_option_some<F>(&mut self, f: F) -> EncodeResult where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
......@@ -740,7 +740,7 @@ pub fn set_indent(&mut self, indent: usize) {
impl<'a> ::Encoder for PrettyEncoder<'a> {
type Error = EncoderError;
fn emit_nil(&mut self) -> EncodeResult {
fn emit_unit(&mut self) -> EncodeResult {
if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); }
write!(self.writer, "null")?;
Ok(())
......@@ -923,7 +923,7 @@ fn emit_option<F>(&mut self, f: F) -> EncodeResult where
}
fn emit_option_none(&mut self) -> EncodeResult {
if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); }
self.emit_nil()
self.emit_unit()
}
fn emit_option_some<F>(&mut self, f: F) -> EncodeResult where
F: FnOnce(&mut PrettyEncoder<'a>) -> EncodeResult,
......@@ -1016,7 +1016,7 @@ fn encode<E: ::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
Json::Boolean(v) => v.encode(e),
Json::Array(ref v) => v.encode(e),
Json::Object(ref v) => v.encode(e),
Json::Null => e.emit_nil(),
Json::Null => e.emit_unit(),
}
}
}
......
......@@ -55,7 +55,7 @@ impl serialize::Encoder for Encoder {
type Error = !;
#[inline]
fn emit_nil(&mut self) -> EncodeResult {
fn emit_unit(&mut self) -> EncodeResult {
Ok(())
}
......
......@@ -25,7 +25,7 @@ pub trait Encoder {
type Error;
// Primitive types:
fn emit_nil(&mut self) -> Result<(), Self::Error>;
fn emit_unit(&mut self) -> Result<(), Self::Error>;
fn emit_usize(&mut self, v: usize) -> Result<(), Self::Error>;
fn emit_u128(&mut self, v: u128) -> Result<(), Self::Error>;
fn emit_u64(&mut self, v: u64) -> Result<(), Self::Error>;
......@@ -537,7 +537,7 @@ fn decode<D: Decoder>(d: &mut D) -> Result<char, D::Error> {
impl Encodable for () {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_nil()
s.emit_unit()
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册