Skip to content

Commit 3413346

Browse files
committed
Sidestep warning about repeated E0045 span_err! invocation.
(That is, take the two expressions with the same message and unify them into one subroutine.)
1 parent 2afe47d commit 3413346

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/librustc_typeck/astconv.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs};
5858
use middle::traits;
5959
use middle::ty::{self, RegionEscape, Ty, ToPredicate, HasTypeFlags};
6060
use middle::ty_fold;
61+
use require_c_abi_if_variadic;
6162
use rscope::{self, UnelidableRscope, RegionScope, ElidableRscope, ExplicitRscope,
6263
ObjectLifetimeDefaultRscope, ShiftedRscope, BindingRscope,
6364
ElisionFailureInfo, ElidedLifetime};
@@ -1574,10 +1575,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
15741575
}
15751576
ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
15761577
ast::TyBareFn(ref bf) => {
1577-
if bf.decl.variadic && bf.abi != abi::C {
1578-
span_err!(tcx.sess, ast_ty.span, E0045,
1579-
"variadic function must have C calling convention");
1580-
}
1578+
require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
15811579
let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl);
15821580
tcx.mk_fn(None, tcx.mk_bare_fn(bare_fn))
15831581
}

src/librustc_typeck/check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ use middle::ty::{Disr, ParamTy, ParameterEnvironment};
9797
use middle::ty::{self, HasTypeFlags, RegionEscape, ToPolyTraitRef, Ty};
9898
use middle::ty::{MethodCall, MethodCallee};
9999
use middle::ty_fold::{TypeFolder, TypeFoldable};
100+
use require_c_abi_if_variadic;
100101
use rscope::{ElisionFailureInfo, RegionScope};
101102
use session::Session;
102103
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) {
685686
}
686687

687688
if let ast::ForeignItemFn(ref fn_decl, _) = item.node {
688-
if fn_decl.variadic && m.abi != abi::C {
689-
span_err!(ccx.tcx.sess, item.span, E0045,
690-
"variadic function must have C calling convention");
691-
}
689+
require_c_abi_if_variadic(ccx.tcx, fn_decl, m.abi, item.span);
692690
}
693691
}
694692
}

src/librustc_typeck/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ fn lookup_full_def(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
176176
}
177177
}
178178

179+
fn require_c_abi_if_variadic(tcx: &ty::ctxt,
180+
decl: &ast::FnDecl,
181+
abi: abi::Abi,
182+
span: Span) {
183+
if decl.variadic && abi != abi::C {
184+
span_err!(tcx.sess, span, E0045,
185+
"variadic function must have C calling convention");
186+
}
187+
}
188+
179189
fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
180190
maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>,
181191
t1_is_expected: bool,

0 commit comments

Comments
 (0)