Auto merge of #27188 - pnkfelix:sidestep-warning-for-E0045, r=alexcrichton

Sidestep warning about repeated E0045 `span_err!` invocation.

(That is, take the two expressions with the same message and unify them into one subroutine.)
This commit is contained in:
bors 2015-07-22 20:44:39 +00:00
commit 4234c4487a
3 changed files with 14 additions and 8 deletions

View File

@ -59,6 +59,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};
@ -1575,10 +1576,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))
}

View File

@ -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);
}
}
}

View File

@ -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,