From 3413346be26dbe059db01806016df864ff56daa0 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 21 Jul 2015 17:41:08 +0200 Subject: [PATCH] Sidestep warning about repeated E0045 `span_err!` invocation. (That is, take the two expressions with the same message and unify them into one subroutine.) --- src/librustc_typeck/astconv.rs | 6 ++---- src/librustc_typeck/check/mod.rs | 6 ++---- src/librustc_typeck/lib.rs | 10 ++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 07af1aa64ae..7b659c98a9b 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -58,6 +58,7 @@ use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs}; use middle::traits; use middle::ty::{self, RegionEscape, Ty, ToPredicate, HasTypeFlags}; use middle::ty_fold; +use require_c_abi_if_variadic; use rscope::{self, UnelidableRscope, RegionScope, ElidableRscope, ExplicitRscope, ObjectLifetimeDefaultRscope, ShiftedRscope, BindingRscope, ElisionFailureInfo, ElidedLifetime}; @@ -1574,10 +1575,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>, } ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ), ast::TyBareFn(ref bf) => { - if bf.decl.variadic && bf.abi != abi::C { - span_err!(tcx.sess, ast_ty.span, E0045, - "variadic function must have C calling convention"); - } + require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span); let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl); tcx.mk_fn(None, tcx.mk_bare_fn(bare_fn)) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a98f7a8678c..d417310a9f8 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -97,6 +97,7 @@ use middle::ty::{Disr, ParamTy, ParameterEnvironment}; use middle::ty::{self, HasTypeFlags, RegionEscape, ToPolyTraitRef, Ty}; use middle::ty::{MethodCall, MethodCallee}; use middle::ty_fold::{TypeFolder, TypeFoldable}; +use require_c_abi_if_variadic; use rscope::{ElisionFailureInfo, RegionScope}; use session::Session; use {CrateCtxt, lookup_full_def, require_same_types}; @@ -685,10 +686,7 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx ast::Item) { } if let ast::ForeignItemFn(ref fn_decl, _) = item.node { - if fn_decl.variadic && m.abi != abi::C { - span_err!(ccx.tcx.sess, item.span, E0045, - "variadic function must have C calling convention"); - } + require_c_abi_if_variadic(ccx.tcx, fn_decl, m.abi, item.span); } } } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 4260791e384..9c0e121e156 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -176,6 +176,16 @@ fn lookup_full_def(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def { } } +fn require_c_abi_if_variadic(tcx: &ty::ctxt, + decl: &ast::FnDecl, + abi: abi::Abi, + span: Span) { + if decl.variadic && abi != abi::C { + span_err!(tcx.sess, span, E0045, + "variadic function must have C calling convention"); + } +} + fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>, maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>, t1_is_expected: bool,