Skip to content

Commit 1eab19d

Browse files
Refactor ty::FnSig to privatize all fields
1 parent 0999124 commit 1eab19d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+237
-271
lines changed

src/librustc/middle/intrinsicck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for ExprVisitor<'a, 'gcx, 'tcx> {
178178
let typ = self.infcx.tcx.tables().node_id_to_type(expr.id);
179179
match typ.sty {
180180
ty::TyFnDef(.., ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
181-
let from = bare_fn_ty.sig.0.inputs[0];
182-
let to = bare_fn_ty.sig.0.output;
181+
let from = bare_fn_ty.sig.skip_binder().inputs()[0];
182+
let to = bare_fn_ty.sig.skip_binder().output();
183183
self.check_transmute(expr.span, from, to, expr.id);
184184
}
185185
_ => {

src/librustc/traits/object_safety.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
241241
// The `Self` type is erased, so it should not appear in list of
242242
// arguments or return type apart from the receiver.
243243
let ref sig = self.item_type(method.def_id).fn_sig();
244-
for &input_ty in &sig.0.inputs[1..] {
244+
for input_ty in &sig.skip_binder().inputs()[1..] {
245245
if self.contains_illegal_self_type_reference(trait_def_id, input_ty) {
246246
return Some(MethodViolationCode::ReferencesSelf);
247247
}
248248
}
249-
if self.contains_illegal_self_type_reference(trait_def_id, sig.0.output) {
249+
if self.contains_illegal_self_type_reference(trait_def_id, sig.output().skip_binder()) {
250250
return Some(MethodViolationCode::ReferencesSelf);
251251
}
252252

src/librustc/traits/select.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,21 +1368,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13681368
ty::TyFnDef(.., &ty::BareFnTy {
13691369
unsafety: hir::Unsafety::Normal,
13701370
abi: Abi::Rust,
1371-
sig: ty::Binder(ty::FnSig {
1372-
inputs: _,
1373-
output: _,
1374-
variadic: false
1375-
})
1371+
ref sig,
13761372
}) |
13771373
ty::TyFnPtr(&ty::BareFnTy {
13781374
unsafety: hir::Unsafety::Normal,
13791375
abi: Abi::Rust,
1380-
sig: ty::Binder(ty::FnSig {
1381-
inputs: _,
1382-
output: _,
1383-
variadic: false
1384-
})
1385-
}) => {
1376+
ref sig
1377+
}) if !sig.variadic() => {
13861378
candidates.vec.push(FnPointerCandidate);
13871379
}
13881380

src/librustc/traits/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
487487
-> ty::Binder<(ty::TraitRef<'tcx>, Ty<'tcx>)>
488488
{
489489
let arguments_tuple = match tuple_arguments {
490-
TupleArgumentsFlag::No => sig.0.inputs[0],
491-
TupleArgumentsFlag::Yes => self.intern_tup(&sig.0.inputs[..]),
490+
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
491+
TupleArgumentsFlag::Yes =>
492+
self.intern_tup(sig.skip_binder().inputs()),
492493
};
493494
let trait_ref = ty::TraitRef {
494495
def_id: fn_trait_def_id,
495496
substs: self.mk_substs_trait(self_ty, &[arguments_tuple]),
496497
};
497-
ty::Binder((trait_ref, sig.0.output))
498+
ty::Binder((trait_ref, sig.skip_binder().output()))
498499
}
499500
}
500501

src/librustc/ty/fast_reject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
8181
Some(TupleSimplifiedType(tys.len()))
8282
}
8383
ty::TyFnDef(.., ref f) | ty::TyFnPtr(ref f) => {
84-
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
84+
Some(FunctionSimplifiedType(f.sig.skip_binder().inputs().len()))
8585
}
8686
ty::TyProjection(_) | ty::TyParam(_) => {
8787
if can_simplify_params {

src/librustc/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ impl FlagComputation {
180180
fn add_fn_sig(&mut self, fn_sig: &ty::PolyFnSig) {
181181
let mut computation = FlagComputation::new();
182182

183-
computation.add_tys(&fn_sig.0.inputs);
184-
computation.add_ty(fn_sig.0.output);
183+
computation.add_tys(fn_sig.skip_binder().inputs());
184+
computation.add_ty(fn_sig.skip_binder().output());
185185

186186
self.add_bound_computation(&computation);
187187
}

src/librustc/ty/relate.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,35 +180,22 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
180180
-> RelateResult<'tcx, ty::FnSig<'tcx>>
181181
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
182182
{
183-
if a.variadic != b.variadic {
183+
if a.variadic() != b.variadic() {
184184
return Err(TypeError::VariadicMismatch(
185-
expected_found(relation, &a.variadic, &b.variadic)));
185+
expected_found(relation, &a.variadic(), &b.variadic())));
186186
}
187187

188-
let inputs = relate_arg_vecs(relation,
189-
&a.inputs,
190-
&b.inputs)?;
191-
let output = relation.relate(&a.output, &b.output)?;
188+
if a.inputs().len() != b.inputs().len() {
189+
return Err(TypeError::ArgCount);
190+
}
192191

193-
Ok(ty::FnSig {inputs: inputs,
194-
output: output,
195-
variadic: a.variadic})
196-
}
197-
}
192+
let inputs = a.inputs().iter().zip(b.inputs()).map(|(&a, &b)| {
193+
relation.relate_with_variance(ty::Contravariant, &a, &b)
194+
}).collect::<Result<Vec<_>, _>>()?;
195+
let output = relation.relate(&a.output(), &b.output())?;
198196

199-
fn relate_arg_vecs<'a, 'gcx, 'tcx, R>(relation: &mut R,
200-
a_args: &[Ty<'tcx>],
201-
b_args: &[Ty<'tcx>])
202-
-> RelateResult<'tcx, Vec<Ty<'tcx>>>
203-
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
204-
{
205-
if a_args.len() != b_args.len() {
206-
return Err(TypeError::ArgCount);
197+
Ok(ty::FnSig::new(inputs, output, a.variadic()))
207198
}
208-
209-
a_args.iter().zip(b_args)
210-
.map(|(a, b)| relation.relate_with_variance(ty::Contravariant, a, b))
211-
.collect()
212199
}
213200

214201
impl<'tcx> Relate<'tcx> for ast::Unsafety {

src/librustc/ty/structural_impls.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,9 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
232232
impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
233233
type Lifted = ty::FnSig<'tcx>;
234234
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
235-
tcx.lift(&self.inputs[..]).and_then(|inputs| {
236-
tcx.lift(&self.output).map(|output| {
237-
ty::FnSig {
238-
inputs: inputs,
239-
output: output,
240-
variadic: self.variadic
241-
}
235+
tcx.lift(self.inputs()).and_then(|inputs| {
236+
tcx.lift(&self.output()).map(|output| {
237+
ty::FnSig::new(inputs, output, self.variadic())
242238
})
243239
})
244240
}
@@ -589,17 +585,17 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
589585

590586
impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
591587
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
592-
ty::FnSig { inputs: self.inputs.fold_with(folder),
593-
output: self.output.fold_with(folder),
594-
variadic: self.variadic }
588+
ty::FnSig::new(self.inputs().to_owned().fold_with(folder),
589+
self.output().fold_with(folder),
590+
self.variadic())
595591
}
596592

597593
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
598594
folder.fold_fn_sig(self)
599595
}
600596

601597
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
602-
self.inputs.visit_with(visitor) || self.output.visit_with(visitor)
598+
self.inputs().to_owned().visit_with(visitor) || self.output().visit_with(visitor)
603599
}
604600
}
605601

src/librustc/ty/sty.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,34 @@ pub struct ClosureTy<'tcx> {
563563
/// - `variadic` indicates whether this is a variadic function. (only true for foreign fns)
564564
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
565565
pub struct FnSig<'tcx> {
566-
pub inputs: Vec<Ty<'tcx>>,
567-
pub output: Ty<'tcx>,
568-
pub variadic: bool
566+
inputs: Vec<Ty<'tcx>>,
567+
output: Ty<'tcx>,
568+
variadic: bool
569+
}
570+
571+
impl<'tcx> FnSig<'tcx> {
572+
pub fn new(inputs: Vec<Ty<'tcx>>, output: Ty<'tcx>, variadic: bool) -> Self {
573+
FnSig { inputs: inputs, output: output, variadic: variadic }
574+
}
575+
576+
pub fn inputs(&self) -> &[Ty<'tcx>] {
577+
&self.inputs
578+
}
579+
580+
pub fn output(&self) -> Ty<'tcx> {
581+
self.output
582+
}
583+
584+
pub fn variadic(&self) -> bool {
585+
self.variadic
586+
}
569587
}
570588

571589
pub type PolyFnSig<'tcx> = Binder<FnSig<'tcx>>;
572590

573591
impl<'tcx> PolyFnSig<'tcx> {
574-
pub fn inputs(&self) -> ty::Binder<Vec<Ty<'tcx>>> {
575-
self.map_bound_ref(|fn_sig| fn_sig.inputs.clone())
592+
pub fn inputs<'a>(&'a self) -> Binder<&[Ty<'tcx>]> {
593+
Binder(self.0.inputs())
576594
}
577595
pub fn input(&self, index: usize) -> ty::Binder<Ty<'tcx>> {
578596
self.map_bound_ref(|fn_sig| fn_sig.inputs[index])
@@ -1244,7 +1262,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
12441262

12451263
// Type accessors for substructures of types
12461264
pub fn fn_args(&self) -> ty::Binder<Vec<Ty<'tcx>>> {
1247-
self.fn_sig().inputs()
1265+
ty::Binder(self.fn_sig().inputs().skip_binder().iter().cloned().collect::<Vec<_>>())
12481266
}
12491267

12501268
pub fn fn_ret(&self) -> Binder<Ty<'tcx>> {

src/librustc/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
530530
self.hash(f.unsafety);
531531
self.hash(f.abi);
532532
self.hash(f.sig.variadic());
533-
self.hash(f.sig.inputs().skip_binder().len());
533+
self.hash(f.sig.skip_binder().inputs().len());
534534
}
535535
TyDynamic(ref data, ..) => {
536536
if let Some(p) = data.principal() {

0 commit comments

Comments
 (0)