]> git.lizzy.rs Git - rust.git/commitdiff
Refactor ty::FnSig to privatize all fields
authorMark-Simulacrum <mark.simulacrum@gmail.com>
Tue, 29 Nov 2016 02:35:38 +0000 (19:35 -0700)
committerMark-Simulacrum <mark.simulacrum@gmail.com>
Tue, 6 Dec 2016 05:22:49 +0000 (22:22 -0700)
42 files changed:
src/librustc/middle/intrinsicck.rs
src/librustc/traits/object_safety.rs
src/librustc/traits/select.rs
src/librustc/traits/util.rs
src/librustc/ty/fast_reject.rs
src/librustc/ty/flags.rs
src/librustc/ty/relate.rs
src/librustc/ty/structural_impls.rs
src/librustc/ty/sty.rs
src/librustc/ty/util.rs
src/librustc/ty/walk.rs
src/librustc/util/ppaux.rs
src/librustc_lint/builtin.rs
src/librustc_lint/types.rs
src/librustc_mir/build/expr/into.rs
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/mir_map.rs
src/librustc_mir/transform/type_check.rs
src/librustc_trans/abi.rs
src/librustc_trans/base.rs
src/librustc_trans/callee.rs
src/librustc_trans/common.rs
src/librustc_trans/debuginfo/metadata.rs
src/librustc_trans/debuginfo/mod.rs
src/librustc_trans/debuginfo/type_names.rs
src/librustc_trans/declare.rs
src/librustc_trans/intrinsic.rs
src/librustc_trans/mir/block.rs
src/librustc_trans/trans_item.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/callee.rs
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/compare_method.rs
src/librustc_typeck/check/intrinsic.rs
src/librustc_typeck/check/method/mod.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/lib.rs
src/librustc_typeck/variance/constraints.rs
src/librustdoc/clean/mod.rs

index 6896c69d7db92249224b4f1a1adf23ca7878668d..2357549c82e081fedfaea3737221985ebe01a904 100644 (file)
@@ -178,8 +178,8 @@ fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
                 let typ = self.infcx.tcx.tables().node_id_to_type(expr.id);
                 match typ.sty {
                     ty::TyFnDef(.., ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
-                        let from = bare_fn_ty.sig.0.inputs[0];
-                        let to = bare_fn_ty.sig.0.output;
+                        let from = bare_fn_ty.sig.skip_binder().inputs()[0];
+                        let to = bare_fn_ty.sig.skip_binder().output();
                         self.check_transmute(expr.span, from, to, expr.id);
                     }
                     _ => {
index ceee6c236e4e3dba250c6364d3a5ef6e5fc796ab..0d5c9b98941dc086a78eee65d3cd55e87c597589 100644 (file)
@@ -241,12 +241,12 @@ fn virtual_call_violation_for_method(self,
         // The `Self` type is erased, so it should not appear in list of
         // arguments or return type apart from the receiver.
         let ref sig = self.item_type(method.def_id).fn_sig();
-        for &input_ty in &sig.0.inputs[1..] {
+        for input_ty in &sig.skip_binder().inputs()[1..] {
             if self.contains_illegal_self_type_reference(trait_def_id, input_ty) {
                 return Some(MethodViolationCode::ReferencesSelf);
             }
         }
-        if self.contains_illegal_self_type_reference(trait_def_id, sig.0.output) {
+        if self.contains_illegal_self_type_reference(trait_def_id, sig.output().skip_binder()) {
             return Some(MethodViolationCode::ReferencesSelf);
         }
 
index c54c0bf74ef7a36f07a95384f06558d2821639b6..23cfc2517590c1845b7a7f260dbc7a4a5a19d8c8 100644 (file)
@@ -1368,21 +1368,13 @@ fn assemble_fn_pointer_candidates(&mut self,
             ty::TyFnDef(.., &ty::BareFnTy {
                 unsafety: hir::Unsafety::Normal,
                 abi: Abi::Rust,
-                sig: ty::Binder(ty::FnSig {
-                    inputs: _,
-                    output: _,
-                    variadic: false
-                })
+                ref sig,
             }) |
             ty::TyFnPtr(&ty::BareFnTy {
                 unsafety: hir::Unsafety::Normal,
                 abi: Abi::Rust,
-                sig: ty::Binder(ty::FnSig {
-                    inputs: _,
-                    output: _,
-                    variadic: false
-                })
-            }) => {
+                ref sig
+            }) if !sig.variadic() => {
                 candidates.vec.push(FnPointerCandidate);
             }
 
index 321936fe54be15c37df649761dbfc2ebe66eb002..cebd8bf87d736cca88ae75bcf5917a22d5193da3 100644 (file)
@@ -487,14 +487,15 @@ pub fn closure_trait_ref_and_return_type(self,
         -> ty::Binder<(ty::TraitRef<'tcx>, Ty<'tcx>)>
     {
         let arguments_tuple = match tuple_arguments {
-            TupleArgumentsFlag::No => sig.0.inputs[0],
-            TupleArgumentsFlag::Yes => self.intern_tup(&sig.0.inputs[..]),
+            TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
+            TupleArgumentsFlag::Yes =>
+                self.intern_tup(sig.skip_binder().inputs()),
         };
         let trait_ref = ty::TraitRef {
             def_id: fn_trait_def_id,
             substs: self.mk_substs_trait(self_ty, &[arguments_tuple]),
         };
-        ty::Binder((trait_ref, sig.0.output))
+        ty::Binder((trait_ref, sig.skip_binder().output()))
     }
 }
 
index ade6cad6866df43a84ecb6341f48cbfce3ad58af..7b4d76ad4973e0ce7e3c635916cf559d025b07fd 100644 (file)
@@ -81,7 +81,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
             Some(TupleSimplifiedType(tys.len()))
         }
         ty::TyFnDef(.., ref f) | ty::TyFnPtr(ref f) => {
-            Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
+            Some(FunctionSimplifiedType(f.sig.skip_binder().inputs().len()))
         }
         ty::TyProjection(_) | ty::TyParam(_) => {
             if can_simplify_params {
index 2bcbccb7d0505933e55f6dddfe4ed61fd60a144f..a06d3ed6cf4fb093b6352f18a1ccd94111021dd6 100644 (file)
@@ -180,8 +180,8 @@ fn add_tys(&mut self, tys: &[Ty]) {
     fn add_fn_sig(&mut self, fn_sig: &ty::PolyFnSig) {
         let mut computation = FlagComputation::new();
 
-        computation.add_tys(&fn_sig.0.inputs);
-        computation.add_ty(fn_sig.0.output);
+        computation.add_tys(fn_sig.skip_binder().inputs());
+        computation.add_ty(fn_sig.skip_binder().output());
 
         self.add_bound_computation(&computation);
     }
index 8cb1483107ff119d3e0b5018fef3db5157a5a49b..171519b0664d9ff375ecfd680baa2a9379cf503e 100644 (file)
@@ -180,35 +180,22 @@ fn relate<'a, 'gcx, R>(relation: &mut R,
                            -> RelateResult<'tcx, ty::FnSig<'tcx>>
         where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
     {
-        if a.variadic != b.variadic {
+        if a.variadic() != b.variadic() {
             return Err(TypeError::VariadicMismatch(
-                expected_found(relation, &a.variadic, &b.variadic)));
+                expected_found(relation, &a.variadic(), &b.variadic())));
         }
 
-        let inputs = relate_arg_vecs(relation,
-                                     &a.inputs,
-                                     &b.inputs)?;
-        let output = relation.relate(&a.output, &b.output)?;
+        if a.inputs().len() != b.inputs().len() {
+            return Err(TypeError::ArgCount);
+        }
 
-        Ok(ty::FnSig {inputs: inputs,
-                      output: output,
-                      variadic: a.variadic})
-    }
-}
+        let inputs = a.inputs().iter().zip(b.inputs()).map(|(&a, &b)| {
+            relation.relate_with_variance(ty::Contravariant, &a, &b)
+        }).collect::<Result<Vec<_>, _>>()?;
+        let output = relation.relate(&a.output(), &b.output())?;
 
-fn relate_arg_vecs<'a, 'gcx, 'tcx, R>(relation: &mut R,
-                                      a_args: &[Ty<'tcx>],
-                                      b_args: &[Ty<'tcx>])
-                                      -> RelateResult<'tcx, Vec<Ty<'tcx>>>
-    where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
-{
-    if a_args.len() != b_args.len() {
-        return Err(TypeError::ArgCount);
+        Ok(ty::FnSig::new(inputs, output, a.variadic()))
     }
-
-    a_args.iter().zip(b_args)
-          .map(|(a, b)| relation.relate_with_variance(ty::Contravariant, a, b))
-          .collect()
 }
 
 impl<'tcx> Relate<'tcx> for ast::Unsafety {
index 88de3575274cc4a8ea22ea69e49f1e275c48238a..9ca30850bcda967f4e3f0f64186ba9406c7a6ff6 100644 (file)
@@ -232,13 +232,9 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
     type Lifted = ty::FnSig<'tcx>;
     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.inputs[..]).and_then(|inputs| {
-            tcx.lift(&self.output).map(|output| {
-                ty::FnSig {
-                    inputs: inputs,
-                    output: output,
-                    variadic: self.variadic
-                }
+        tcx.lift(self.inputs()).and_then(|inputs| {
+            tcx.lift(&self.output()).map(|output| {
+                ty::FnSig::new(inputs, output, self.variadic())
             })
         })
     }
@@ -589,9 +585,9 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
 
 impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
-        ty::FnSig { inputs: self.inputs.fold_with(folder),
-                    output: self.output.fold_with(folder),
-                    variadic: self.variadic }
+        ty::FnSig::new(self.inputs().to_owned().fold_with(folder),
+                    self.output().fold_with(folder),
+                    self.variadic())
     }
 
     fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
@@ -599,7 +595,7 @@ fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Se
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
-        self.inputs.visit_with(visitor) || self.output.visit_with(visitor)
+        self.inputs().to_owned().visit_with(visitor) || self.output().visit_with(visitor)
     }
 }
 
index 59f774b954cf9017ed508ea8a38f88f43e756172..6c54d558ab7899a41c7c660fc4a9db300ab90959 100644 (file)
@@ -563,16 +563,34 @@ pub struct ClosureTy<'tcx> {
 /// - `variadic` indicates whether this is a variadic function. (only true for foreign fns)
 #[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
 pub struct FnSig<'tcx> {
-    pub inputs: Vec<Ty<'tcx>>,
-    pub output: Ty<'tcx>,
-    pub variadic: bool
+    inputs: Vec<Ty<'tcx>>,
+    output: Ty<'tcx>,
+    variadic: bool
+}
+
+impl<'tcx> FnSig<'tcx> {
+    pub fn new(inputs: Vec<Ty<'tcx>>, output: Ty<'tcx>, variadic: bool) -> Self {
+        FnSig { inputs: inputs, output: output, variadic: variadic }
+    }
+
+    pub fn inputs(&self) -> &[Ty<'tcx>] {
+        &self.inputs
+    }
+
+    pub fn output(&self) -> Ty<'tcx> {
+        self.output
+    }
+
+    pub fn variadic(&self) -> bool {
+        self.variadic
+    }
 }
 
 pub type PolyFnSig<'tcx> = Binder<FnSig<'tcx>>;
 
 impl<'tcx> PolyFnSig<'tcx> {
-    pub fn inputs(&self) -> ty::Binder<Vec<Ty<'tcx>>> {
-        self.map_bound_ref(|fn_sig| fn_sig.inputs.clone())
+    pub fn inputs<'a>(&'a self) -> Binder<&[Ty<'tcx>]> {
+        Binder(self.0.inputs())
     }
     pub fn input(&self, index: usize) -> ty::Binder<Ty<'tcx>> {
         self.map_bound_ref(|fn_sig| fn_sig.inputs[index])
@@ -1244,7 +1262,7 @@ pub fn fn_abi(&self) -> abi::Abi {
 
     // Type accessors for substructures of types
     pub fn fn_args(&self) -> ty::Binder<Vec<Ty<'tcx>>> {
-        self.fn_sig().inputs()
+        ty::Binder(self.fn_sig().inputs().skip_binder().iter().cloned().collect::<Vec<_>>())
     }
 
     pub fn fn_ret(&self) -> Binder<Ty<'tcx>> {
index 6bb9d67db6f6579c2fca495fb01e162c22b8ee53..e6db35cc3f5447b9f44c3f8306947b9fd4cccca2 100644 (file)
@@ -530,7 +530,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
                 self.hash(f.unsafety);
                 self.hash(f.abi);
                 self.hash(f.sig.variadic());
-                self.hash(f.sig.inputs().skip_binder().len());
+                self.hash(f.sig.skip_binder().inputs().len());
             }
             TyDynamic(ref data, ..) => {
                 if let Some(p) = data.principal() {
index 0848dcd2c8d213ec4f37bf3e930e2aee6b50cba4..3fa7a803141d1d51eafd5993f3d84aff4f42fa43 100644 (file)
@@ -126,6 +126,6 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
 }
 
 fn push_sig_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, sig: &ty::PolyFnSig<'tcx>) {
-    stack.push(sig.0.output);
-    stack.extend(sig.0.inputs.iter().cloned().rev());
+    stack.push(sig.skip_binder().output());
+    stack.extend(sig.skip_binder().inputs().iter().cloned().rev());
 }
index b4c87e0ce426e18515c7b7bdcb6d7b252e3abd3f..3a973fe7bc53f0a57dcd4a2400e6cc1577fc17ed 100644 (file)
@@ -595,7 +595,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 impl<'tcx> fmt::Display for ty::FnSig<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "fn")?;
-        fn_sig(f, &self.inputs, self.variadic, self.output)
+        fn_sig(f, self.inputs(), self.variadic(), self.output())
     }
 }
 
@@ -625,7 +625,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "({:?}; variadic: {})->{:?}", self.inputs, self.variadic, self.output)
+        write!(f, "({:?}; variadic: {})->{:?}", self.inputs(), self.variadic(), self.output())
     }
 }
 
index f14fa7d4fdc23905040fae8defb277249456fcd1..ee6af643154fa9036b66eab463ef52dd099bb7ba 100644 (file)
@@ -1084,8 +1084,8 @@ fn get_transmute_from_to<'a, 'tcx>
                 let typ = cx.tcx.tables().node_id_to_type(expr.id);
                 match typ.sty {
                     ty::TyFnDef(.., ref bare_fn) if bare_fn.abi == RustIntrinsic => {
-                        let from = bare_fn.sig.0.inputs[0];
-                        let to = bare_fn.sig.0.output;
+                        let from = bare_fn.sig.skip_binder().inputs()[0];
+                        let to = bare_fn.sig.skip_binder().output();
                         return Some((&from.sty, &to.sty));
                     }
                     _ => (),
index bba31c8237d18a721a0881659995487125ee2ac9..6475166192a25a9fc199adbb97bd4aaa559fd781 100644 (file)
@@ -603,8 +603,8 @@ fn check_type_for_ffi(&self, cache: &mut FxHashSet<Ty<'tcx>>, ty: Ty<'tcx>) -> F
                 }
 
                 let sig = cx.erase_late_bound_regions(&bare_fn.sig);
-                if !sig.output.is_nil() {
-                    let r = self.check_type_for_ffi(cache, sig.output);
+                if !sig.output().is_nil() {
+                    let r = self.check_type_for_ffi(cache, sig.output());
                     match r {
                         FfiSafe => {}
                         _ => {
@@ -612,7 +612,7 @@ fn check_type_for_ffi(&self, cache: &mut FxHashSet<Ty<'tcx>>, ty: Ty<'tcx>) -> F
                         }
                     }
                 }
-                for arg in sig.inputs {
+                for arg in sig.inputs() {
                     let r = self.check_type_for_ffi(cache, arg);
                     match r {
                         FfiSafe => {}
@@ -678,12 +678,12 @@ fn check_foreign_fn(&mut self, id: ast::NodeId, decl: &hir::FnDecl) {
         let sig = self.cx.tcx.item_type(def_id).fn_sig();
         let sig = self.cx.tcx.erase_late_bound_regions(&sig);
 
-        for (&input_ty, input_hir) in sig.inputs.iter().zip(&decl.inputs) {
-            self.check_type_for_ffi_and_report_errors(input_hir.ty.span, &input_ty);
+        for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) {
+            self.check_type_for_ffi_and_report_errors(input_hir.ty.span, input_ty);
         }
 
         if let hir::Return(ref ret_hir) = decl.output {
-            let ret_ty = sig.output;
+            let ret_ty = sig.output();
             if !ret_ty.is_nil() {
                 self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty);
             }
index 5a77de08070281763ba800cc6796895a5cd353fb..ffd9525933b4e5d6f24f43ea414b2ed1db316f2f 100644 (file)
@@ -208,7 +208,7 @@ pub fn into_expr(&mut self,
                 let diverges = match ty.sty {
                     ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
                         // FIXME(canndrew): This is_never should probably be an is_uninhabited
-                        f.sig.0.output.is_never()
+                        f.sig.skip_binder().output().is_never()
                     }
                     _ => false
                 };
index e850f6c4b045cab7a9fcbdfa6d2921dc293dba0a..bd4724159b4cb9ac53a1e535c1a529bfb388bf90 100644 (file)
@@ -247,10 +247,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
                     span_bug!(expr.span, "method call has late-bound regions")
                 });
 
-                assert_eq!(sig.inputs.len(), 2);
+                assert_eq!(sig.inputs().len(), 2);
 
                 let tupled_args = Expr {
-                    ty: sig.inputs[1],
+                    ty: sig.inputs()[1],
                     temp_lifetime: temp_lifetime,
                     span: expr.span,
                     kind: ExprKind::Tuple {
index 88d02d7d004c9b6f20222122683b70a08202780a..e2a516edbc8354ff69a7108d3ba416f03b98d832 100644 (file)
@@ -238,14 +238,14 @@ fn visit_fn(&mut self,
                 .iter()
                 .enumerate()
                 .map(|(index, arg)| {
-                    (fn_sig.inputs[index], Some(&*arg.pat))
+                    (fn_sig.inputs()[index], Some(&*arg.pat))
                 });
 
         let body = self.tcx.map.expr(body_id);
 
         let arguments = implicit_argument.into_iter().chain(explicit_arguments);
         self.cx(MirSource::Fn(id)).build(|cx| {
-            build::construct_fn(cx, id, arguments, abi, fn_sig.output, body)
+            build::construct_fn(cx, id, arguments, abi, fn_sig.output(), body)
         });
 
         intravisit::walk_fn(self, fk, decl, body_id, span, id);
index 0ceed274b6da656f089e6c3d1d357acfbdf62f73..f65b4e55d4766bc573aa2cce0857c32395e1a49c 100644 (file)
@@ -506,15 +506,15 @@ fn check_call_dest(&mut self,
         match *destination {
             Some((ref dest, _)) => {
                 let dest_ty = dest.ty(mir, tcx).to_ty(tcx);
-                if let Err(terr) = self.sub_types(sig.output, dest_ty) {
+                if let Err(terr) = self.sub_types(sig.output(), dest_ty) {
                     span_mirbug!(self, term,
                                  "call dest mismatch ({:?} <- {:?}): {:?}",
-                                 dest_ty, sig.output, terr);
+                                 dest_ty, sig.output(), terr);
                 }
             },
             None => {
                 // FIXME(canndrew): This is_never should probably be an is_uninhabited
-                if !sig.output.is_never() {
+                if !sig.output().is_never() {
                     span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
                 }
             },
@@ -528,11 +528,11 @@ fn check_call_inputs(&mut self,
                          args: &[Operand<'tcx>])
     {
         debug!("check_call_inputs({:?}, {:?})", sig, args);
-        if args.len() < sig.inputs.len() ||
-           (args.len() > sig.inputs.len() && !sig.variadic) {
+        if args.len() < sig.inputs().len() ||
+           (args.len() > sig.inputs().len() && !sig.variadic()) {
             span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
         }
-        for (n, (fn_arg, op_arg)) in sig.inputs.iter().zip(args).enumerate() {
+        for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() {
             let op_arg_ty = op_arg.ty(mir, self.tcx());
             if let Err(terr) = self.sub_types(op_arg_ty, fn_arg) {
                 span_mirbug!(self, term, "bad arg #{:?} ({:?} <- {:?}): {:?}",
@@ -562,12 +562,12 @@ fn check_box_free_inputs(&mut self,
 
         // box_free takes a Box as a pointer. Allow for that.
 
-        if sig.inputs.len() != 1 {
+        if sig.inputs().len() != 1 {
             span_mirbug!(self, term, "box_free should take 1 argument");
             return;
         }
 
-        let pointee_ty = match sig.inputs[0].sty {
+        let pointee_ty = match sig.inputs()[0].sty {
             ty::TyRawPtr(mt) => mt.ty,
             _ => {
                 span_mirbug!(self, term, "box_free should take a raw ptr");
index 07f53466b4975e1769fc0a01beacfd5c0c9caff6..e780b8685e1ef4b066557a64e95d4fe6c64ef78a 100644 (file)
@@ -367,13 +367,13 @@ pub fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             Cdecl => llvm::CCallConv,
         };
 
-        let mut inputs = &sig.inputs[..];
+        let mut inputs = sig.inputs();
         let extra_args = if abi == RustCall {
-            assert!(!sig.variadic && extra_args.is_empty());
+            assert!(!sig.variadic() && extra_args.is_empty());
 
-            match inputs[inputs.len() - 1].sty {
+            match sig.inputs().last().unwrap().sty {
                 ty::TyTuple(ref tupled_arguments) => {
-                    inputs = &inputs[..inputs.len() - 1];
+                    inputs = &sig.inputs()[0..sig.inputs().len() - 1];
                     &tupled_arguments[..]
                 }
                 _ => {
@@ -382,7 +382,7 @@ pub fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                 }
             }
         } else {
-            assert!(sig.variadic || extra_args.is_empty());
+            assert!(sig.variadic() || extra_args.is_empty());
             extra_args
         };
 
@@ -428,7 +428,7 @@ pub fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             }
         };
 
-        let ret_ty = sig.output;
+        let ret_ty = sig.output();
         let mut ret = arg_of(ret_ty, true);
 
         if !type_is_fat_ptr(ccx.tcx(), ret_ty) {
@@ -525,7 +525,7 @@ pub fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         FnType {
             args: args,
             ret: ret,
-            variadic: sig.variadic,
+            variadic: sig.variadic(),
             cconv: cconv
         }
     }
@@ -569,7 +569,7 @@ pub fn adjust_for_abi<'a, 'tcx>(&mut self,
             };
             // Fat pointers are returned by-value.
             if !self.ret.is_ignore() {
-                if !type_is_fat_ptr(ccx.tcx(), sig.output) {
+                if !type_is_fat_ptr(ccx.tcx(), sig.output()) {
                     fixup(&mut self.ret);
                 }
             }
index a31b61e42c440a2434c0433a4eacc55dc25be3e4..8cc47dc81684a64e27607aad95c5696228f7700c 100644 (file)
@@ -1077,8 +1077,8 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         let dest_val = adt::MaybeSizedValue::sized(dest); // Can return unsized value
         let mut llarg_idx = fcx.fn_ty.ret.is_indirect() as usize;
         let mut arg_idx = 0;
-        for (i, arg_ty) in sig.inputs.into_iter().enumerate() {
-            let lldestptr = adt::trans_field_ptr(bcx, sig.output, dest_val, Disr::from(disr), i);
+        for (i, arg_ty) in sig.inputs().into_iter().enumerate() {
+            let lldestptr = adt::trans_field_ptr(bcx, sig.output(), dest_val, Disr::from(disr), i);
             let arg = &fcx.fn_ty.args[arg_idx];
             arg_idx += 1;
             let b = &bcx.build();
@@ -1091,7 +1091,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                 arg.store_fn_arg(b, &mut llarg_idx, lldestptr);
             }
         }
-        adt::trans_set_discr(bcx, sig.output, dest, disr);
+        adt::trans_set_discr(bcx, sig.output(), dest, disr);
     }
 
     fcx.finish(bcx, DebugLoc::None);
index df56e27128c7ec65d01f303c0b936f1f27249a6f..0d1fd4d69b178f3e868433a8cf8ffb8cba1de1c4 100644 (file)
@@ -329,7 +329,14 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
 
     // Make a version with the type of by-ref closure.
     let ty::ClosureTy { unsafety, abi, mut sig } = tcx.closure_type(def_id, substs);
-    sig.0.inputs.insert(0, ref_closure_ty); // sig has no self type as of yet
+    sig.0 = ty::FnSig::new({
+            let mut inputs = sig.0.inputs().to_owned();
+            inputs.insert(0, ref_closure_ty); // sig has no self type as of yet
+            inputs
+        },
+        sig.0.output(),
+        sig.0.variadic()
+    );
     let llref_fn_ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
         unsafety: unsafety,
         abi: abi,
@@ -342,7 +349,15 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
     // Make a version of the closure type with the same arguments, but
     // with argument #0 being by value.
     assert_eq!(abi, Abi::RustCall);
-    sig.0.inputs[0] = closure_ty;
+    sig.0 = ty::FnSig::new(
+        {
+            let mut inputs = sig.0.inputs().to_owned();
+            inputs[0] = closure_ty;
+            inputs
+        },
+        sig.0.output(),
+        sig.0.variadic()
+    );
 
     let sig = tcx.erase_late_bound_regions_and_normalize(&sig);
     let fn_ty = FnType::new(ccx, abi, &sig, &[]);
@@ -491,13 +506,12 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
         }
     };
     let sig = tcx.erase_late_bound_regions_and_normalize(sig);
-    let tuple_input_ty = tcx.intern_tup(&sig.inputs[..]);
-    let sig = ty::FnSig {
-        inputs: vec![bare_fn_ty_maybe_ref,
-                     tuple_input_ty],
-        output: sig.output,
-        variadic: false
-    };
+    let tuple_input_ty = tcx.intern_tup(sig.inputs());
+    let sig = ty::FnSig::new(
+        vec![bare_fn_ty_maybe_ref, tuple_input_ty],
+        sig.output(),
+        false
+    );
     let fn_ty = FnType::new(ccx, Abi::RustCall, &sig, &[]);
     let tuple_fn_ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
         unsafety: hir::Unsafety::Normal,
index 29925d964da253d4b7a26ae008b72575bbf920a1..2682c37095a67c1aec0b16948acc5f154b33a9f1 100644 (file)
@@ -418,11 +418,11 @@ pub fn eh_unwind_resume(&self) -> Callee<'tcx> {
         let ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
             unsafety: hir::Unsafety::Unsafe,
             abi: Abi::C,
-            sig: ty::Binder(ty::FnSig {
-                inputs: vec![tcx.mk_mut_ptr(tcx.types.u8)],
-                output: tcx.types.never,
-                variadic: false
-            }),
+            sig: ty::Binder(ty::FnSig::new(
+                vec![tcx.mk_mut_ptr(tcx.types.u8)],
+                tcx.types.never,
+                false
+            )),
         }));
 
         let unwresume = ccx.eh_unwind_resume();
@@ -1091,10 +1091,11 @@ pub fn ty_fn_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                 ty::ClosureKind::FnOnce => ty,
             };
 
-            let sig = sig.map_bound(|sig| ty::FnSig {
-                inputs: iter::once(env_ty).chain(sig.inputs).collect(),
-                ..sig
-            });
+            let sig = sig.map_bound(|sig| ty::FnSig::new(
+                iter::once(env_ty).chain(sig.inputs().into_iter().cloned()).collect(),
+                sig.output(),
+                sig.variadic()
+            ));
             Cow::Owned(ty::BareFnTy { unsafety: unsafety, abi: abi, sig: sig })
         }
         _ => bug!("unexpected type {:?} to ty_fn_sig", ty)
index ca76211dc4c95ef48dbfe1ded565c529eda08dc1..cda9fa46f1754d91464fafddf61e493f834ba348 100644 (file)
@@ -390,16 +390,16 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 {
     let signature = cx.tcx().erase_late_bound_regions(signature);
 
-    let mut signature_metadata: Vec<DIType> = Vec::with_capacity(signature.inputs.len() + 1);
+    let mut signature_metadata: Vec<DIType> = Vec::with_capacity(signature.inputs().len() + 1);
 
     // return type
-    signature_metadata.push(match signature.output.sty {
+    signature_metadata.push(match signature.output().sty {
         ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(),
-        _ => type_metadata(cx, signature.output, span)
+        _ => type_metadata(cx, signature.output(), span)
     });
 
     // regular arguments
-    for &argument_type in &signature.inputs {
+    for &argument_type in signature.inputs() {
         signature_metadata.push(type_metadata(cx, argument_type, span));
     }
 
index e023e654d51ad696e62f42761725a513f5e51001..aab70ab252a7fb301980631f0b031970bede74bf 100644 (file)
@@ -308,18 +308,18 @@ fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             return create_DIArray(DIB(cx), &[]);
         }
 
-        let mut signature = Vec::with_capacity(sig.inputs.len() + 1);
+        let mut signature = Vec::with_capacity(sig.inputs().len() + 1);
 
         // Return type -- llvm::DIBuilder wants this at index 0
-        signature.push(match sig.output.sty {
+        signature.push(match sig.output().sty {
             ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(),
-            _ => type_metadata(cx, sig.output, syntax_pos::DUMMY_SP)
+            _ => type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP)
         });
 
         let inputs = if abi == Abi::RustCall {
-            &sig.inputs[..sig.inputs.len()-1]
+            &sig.inputs()[..sig.inputs().len() - 1]
         } else {
-            &sig.inputs[..]
+            sig.inputs()
         };
 
         // Arguments types
@@ -327,8 +327,8 @@ fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             signature.push(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP));
         }
 
-        if abi == Abi::RustCall && !sig.inputs.is_empty() {
-            if let ty::TyTuple(args) = sig.inputs[sig.inputs.len() - 1].sty {
+        if abi == Abi::RustCall && !sig.inputs().is_empty() {
+            if let ty::TyTuple(args) = sig.inputs()[sig.inputs().len() - 1].sty {
                 for &argument_type in args {
                     signature.push(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP));
                 }
index 80e6bd7aa29840528f16526205f4716a0d36cbad..5eb632f63abcb284fe531356ab35aaf43f4d00c9 100644 (file)
@@ -116,8 +116,8 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             output.push_str("fn(");
 
             let sig = cx.tcx().erase_late_bound_regions_and_normalize(sig);
-            if !sig.inputs.is_empty() {
-                for &parameter_type in &sig.inputs {
+            if !sig.inputs().is_empty() {
+                for &parameter_type in sig.inputs() {
                     push_debuginfo_type_name(cx, parameter_type, true, output);
                     output.push_str(", ");
                 }
@@ -125,8 +125,8 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                 output.pop();
             }
 
-            if sig.variadic {
-                if !sig.inputs.is_empty() {
+            if sig.variadic() {
+                if !sig.inputs().is_empty() {
                     output.push_str(", ...");
                 } else {
                     output.push_str("...");
@@ -135,9 +135,9 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
             output.push(')');
 
-            if !sig.output.is_nil() {
+            if !sig.output().is_nil() {
                 output.push_str(" -> ");
-                push_debuginfo_type_name(cx, sig.output, true, output);
+                push_debuginfo_type_name(cx, sig.output(), true, output);
             }
         },
         ty::TyClosure(..) => {
index eef3b9b11474bee1d9c6e2fc052ebdf437435834..9bf023fc18936e4ca0517df93df0d92db8316408 100644 (file)
@@ -124,7 +124,7 @@ pub fn declare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
     let llfn = declare_raw_fn(ccx, name, fty.cconv, fty.llvm_type(ccx));
 
     // FIXME(canndrew): This is_never should really be an is_uninhabited
-    if sig.output.is_never() {
+    if sig.output().is_never() {
         llvm::Attribute::NoReturn.apply_llfn(Function, llfn);
     }
 
index 016a76a72531b4c783292281927e621e605029c4..cf1dddf0f49c2144077cb61902fe99f5151422f6 100644 (file)
@@ -105,8 +105,8 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
     };
 
     let sig = tcx.erase_late_bound_regions_and_normalize(&fty.sig);
-    let arg_tys = sig.inputs;
-    let ret_ty = sig.output;
+    let arg_tys = sig.inputs();
+    let ret_ty = sig.output();
     let name = &*tcx.item_name(def_id).as_str();
 
     let span = match call_debug_location {
@@ -674,7 +674,7 @@ fn modify_as_needed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                 // again to find them and extract the arguments
                 intr.inputs.iter()
                            .zip(llargs)
-                           .zip(&arg_tys)
+                           .zip(arg_tys)
                            .flat_map(|((t, llarg), ty)| modify_as_needed(bcx, t, ty, *llarg))
                            .collect()
             };
@@ -1012,11 +1012,7 @@ fn gen_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
                     trans: &mut for<'b> FnMut(Block<'b, 'tcx>))
                     -> ValueRef {
     let ccx = fcx.ccx;
-    let sig = ty::FnSig {
-        inputs: inputs,
-        output: output,
-        variadic: false,
-    };
+    let sig = ty::FnSig::new(inputs, output, false);
     let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
 
     let rust_fn_ty = ccx.tcx().mk_fn_ptr(ccx.tcx().mk_bare_fn(ty::BareFnTy {
@@ -1051,11 +1047,7 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
     let fn_ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
         unsafety: hir::Unsafety::Unsafe,
         abi: Abi::Rust,
-        sig: ty::Binder(ty::FnSig {
-            inputs: vec![i8p],
-            output: tcx.mk_nil(),
-            variadic: false,
-        }),
+        sig: ty::Binder(ty::FnSig::new(vec![i8p], tcx.mk_nil(), false)),
     }));
     let output = tcx.types.i32;
     let rust_try = gen_fn(fcx, "__rust_try", vec![fn_ty, i8p, i8p], output, trans);
@@ -1108,7 +1100,7 @@ macro_rules! require_simd {
 
     let tcx = bcx.tcx();
     let sig = tcx.erase_late_bound_regions_and_normalize(callee_ty.fn_sig());
-    let arg_tys = sig.inputs;
+    let arg_tys = sig.inputs();
 
     // every intrinsic takes a SIMD vector as its first argument
     require_simd!(arg_tys[0], "input");
index 29e6f6af416bcead29174057122ef460d6c69b38..76f5f32b5dcff70b93c6bfface74d8d80b47803c 100644 (file)
@@ -453,7 +453,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock) {
                     return;
                 }
 
-                let extra_args = &args[sig.inputs.len()..];
+                let extra_args = &args[sig.inputs().len()..];
                 let extra_args = extra_args.iter().map(|op_arg| {
                     let op_ty = op_arg.ty(&self.mir, bcx.tcx());
                     bcx.monomorphize(&op_ty)
@@ -546,7 +546,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock) {
                             // Make a fake operand for store_return
                             let op = OperandRef {
                                 val: Ref(dst),
-                                ty: sig.output,
+                                ty: sig.output(),
                             };
                             self.store_return(&bcx, ret_dest, fn_ty.ret, op);
                         }
@@ -584,7 +584,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock) {
                             debug_loc.apply_to_bcx(ret_bcx);
                             let op = OperandRef {
                                 val: Immediate(invokeret),
-                                ty: sig.output,
+                                ty: sig.output(),
                             };
                             self.store_return(&ret_bcx, ret_dest, fn_ty.ret, op);
                         });
@@ -595,7 +595,7 @@ pub fn trans_block(&mut self, bb: mir::BasicBlock) {
                     if let Some((_, target)) = *destination {
                         let op = OperandRef {
                             val: Immediate(llret),
-                            ty: sig.output,
+                            ty: sig.output(),
                         };
                         self.store_return(&bcx, ret_dest, fn_ty.ret, op);
                         funclet_br(self, bcx, target);
index 322c5eb6e182a135c7397849b0c645cb9930517f..3ae97d0cfcf3cbebafe51cdac623f442d207fdf8 100644 (file)
@@ -187,11 +187,7 @@ fn predefine_drop_glue(ccx: &CrateContext<'a, 'tcx>,
         assert_eq!(dg.ty(), glue::get_drop_glue_type(tcx, dg.ty()));
         let t = dg.ty();
 
-        let sig = ty::FnSig {
-            inputs: vec![tcx.mk_mut_ptr(tcx.types.i8)],
-            output: tcx.mk_nil(),
-            variadic: false,
-        };
+        let sig = ty::FnSig::new(vec![tcx.mk_mut_ptr(tcx.types.i8)], tcx.mk_nil(), false);
 
         // Create a FnType for fn(*mut i8) and substitute the real type in
         // later - that prevents FnType from splitting fat pointers up.
@@ -480,14 +476,10 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
 
                 output.push_str("fn(");
 
-                let ty::FnSig {
-                    inputs: sig_inputs,
-                    output: sig_output,
-                    variadic: sig_variadic
-                } = self.tcx.erase_late_bound_regions_and_normalize(sig);
+                let sig = self.tcx.erase_late_bound_regions_and_normalize(sig);
 
-                if !sig_inputs.is_empty() {
-                    for &parameter_type in &sig_inputs {
+                if !sig.inputs().is_empty() {
+                    for &parameter_type in sig.inputs() {
                         self.push_type_name(parameter_type, output);
                         output.push_str(", ");
                     }
@@ -495,8 +487,8 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
                     output.pop();
                 }
 
-                if sig_variadic {
-                    if !sig_inputs.is_empty() {
+                if sig.variadic() {
+                    if !sig.inputs().is_empty() {
                         output.push_str(", ...");
                     } else {
                         output.push_str("...");
@@ -505,9 +497,9 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) {
 
                 output.push(')');
 
-                if !sig_output.is_nil() {
+                if !sig.output().is_nil() {
                     output.push_str(" -> ");
-                    self.push_type_name(sig_output, output);
+                    self.push_type_name(sig.output(), output);
                 }
             },
             ty::TyClosure(def_id, ref closure_substs) => {
index b5531b8bb9ec97e627f74645c0f0674e89489bca..1fd0b7944411c585135943efcd719c7828d399fe 100644 (file)
@@ -1595,7 +1595,8 @@ pub fn ast_ty_to_ty(&self, rscope: &RegionScope, ast_ty: &hir::Ty) -> Ty<'tcx> {
                 // checking for here would be considered early bound
                 // anyway.)
                 let inputs = bare_fn_ty.sig.inputs();
-                let late_bound_in_args = tcx.collect_constrained_late_bound_regions(&inputs);
+                let late_bound_in_args = tcx.collect_constrained_late_bound_regions(
+                    &inputs.map_bound(|i| i.to_owned()));
                 let output = bare_fn_ty.sig.output();
                 let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output);
                 for br in late_bound_in_ret.difference(&late_bound_in_args) {
@@ -1803,11 +1804,7 @@ fn ty_of_method_or_bare_fn(&self,
         self.tcx().mk_bare_fn(ty::BareFnTy {
             unsafety: unsafety,
             abi: abi,
-            sig: ty::Binder(ty::FnSig {
-                inputs: input_tys,
-                output: output_ty,
-                variadic: decl.variadic
-            }),
+            sig: ty::Binder(ty::FnSig::new(input_tys, output_ty, decl.variadic)),
         })
     }
 
@@ -1853,8 +1850,8 @@ pub fn ty_of_closure(&self,
             let expected_arg_ty = expected_sig.as_ref().and_then(|e| {
                 // no guarantee that the correct number of expected args
                 // were supplied
-                if i < e.inputs.len() {
-                    Some(e.inputs[i])
+                if i < e.inputs().len() {
+                    Some(e.inputs()[i])
                 } else {
                     None
                 }
@@ -1862,7 +1859,7 @@ pub fn ty_of_closure(&self,
             self.ty_of_arg(&rb, a, expected_arg_ty)
         }).collect();
 
-        let expected_ret_ty = expected_sig.map(|e| e.output);
+        let expected_ret_ty = expected_sig.map(|e| e.output());
 
         let is_infer = match decl.output {
             hir::Return(ref output) if output.node == hir::TyInfer => true,
@@ -1885,9 +1882,7 @@ pub fn ty_of_closure(&self,
         ty::ClosureTy {
             unsafety: unsafety,
             abi: abi,
-            sig: ty::Binder(ty::FnSig {inputs: input_tys,
-                                       output: output_ty,
-                                       variadic: decl.variadic}),
+            sig: ty::Binder(ty::FnSig::new(input_tys, output_ty, decl.variadic)),
         }
     }
 
index 5b17b37e2795abc9f4245a5df1ddba029d2ea571..a49a15b2aa900b1428699d9fd662954b8b739a5c 100644 (file)
@@ -237,11 +237,11 @@ fn confirm_builtin_call(&self,
                 // This is the "default" function signature, used in case of error.
                 // In that case, we check each argument against "error" in order to
                 // set up all the node type bindings.
-                error_fn_sig = ty::Binder(ty::FnSig {
-                    inputs: self.err_args(arg_exprs.len()),
-                    output: self.tcx.types.err,
-                    variadic: false,
-                });
+                error_fn_sig = ty::Binder(ty::FnSig::new(
+                    self.err_args(arg_exprs.len()),
+                    self.tcx.types.err,
+                    false,
+                ));
 
                 (&error_fn_sig, None)
             }
@@ -261,17 +261,17 @@ fn confirm_builtin_call(&self,
         let expected_arg_tys =
             self.expected_types_for_fn_args(call_expr.span,
                                             expected,
-                                            fn_sig.output,
-                                            &fn_sig.inputs);
+                                            fn_sig.output(),
+                                            fn_sig.inputs());
         self.check_argument_types(call_expr.span,
-                                  &fn_sig.inputs,
+                                  fn_sig.inputs(),
                                   &expected_arg_tys[..],
                                   arg_exprs,
-                                  fn_sig.variadic,
+                                  fn_sig.variadic(),
                                   TupleArgumentsFlag::DontTupleArguments,
                                   def_span);
 
-        fn_sig.output
+        fn_sig.output()
     }
 
     fn confirm_deferred_closure_call(&self,
@@ -287,18 +287,18 @@ fn confirm_deferred_closure_call(&self,
 
         let expected_arg_tys = self.expected_types_for_fn_args(call_expr.span,
                                                                expected,
-                                                               fn_sig.output.clone(),
-                                                               &fn_sig.inputs);
+                                                               fn_sig.output().clone(),
+                                                               fn_sig.inputs());
 
         self.check_argument_types(call_expr.span,
-                                  &fn_sig.inputs,
+                                  fn_sig.inputs(),
                                   &expected_arg_tys,
                                   arg_exprs,
-                                  fn_sig.variadic,
+                                  fn_sig.variadic(),
                                   TupleArgumentsFlag::TupleArguments,
                                   None);
 
-        fn_sig.output
+        fn_sig.output()
     }
 
     fn confirm_overloaded_call(&self,
@@ -365,12 +365,12 @@ fn resolve<'a>(&mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) {
 
                 debug!("attempt_resolution: method_callee={:?}", method_callee);
 
-                for (&method_arg_ty, &self_arg_ty) in
-                    method_sig.inputs[1..].iter().zip(&self.fn_sig.inputs) {
-                    fcx.demand_eqtype(self.call_expr.span, self_arg_ty, method_arg_ty);
+                for (method_arg_ty, self_arg_ty) in
+                    method_sig.inputs().into_iter().skip(1).zip(self.fn_sig.inputs()) {
+                    fcx.demand_eqtype(self.call_expr.span, &self_arg_ty, &method_arg_ty);
                 }
 
-                fcx.demand_eqtype(self.call_expr.span, method_sig.output, self.fn_sig.output);
+                fcx.demand_eqtype(self.call_expr.span, method_sig.output(), self.fn_sig.output());
 
                 fcx.write_overloaded_call_method_map(self.call_expr, method_callee);
             }
index 486f8fc25bb32d7b8419cd5ae4a478ac4bf0eb5e..d0bc3f691873aceb290b27362750d208bad17305 100644 (file)
@@ -86,7 +86,10 @@ fn check_closure(&self,
 
         // Tuple up the arguments and insert the resulting function type into
         // the `closures` table.
-        fn_ty.sig.0.inputs = vec![self.tcx.intern_tup(&fn_ty.sig.0.inputs[..])];
+        fn_ty.sig.0 = ty::FnSig::new(vec![self.tcx.intern_tup(fn_ty.sig.skip_binder().inputs())],
+            fn_ty.sig.skip_binder().output(),
+            fn_ty.sig.variadic()
+        );
 
         debug!("closure for {:?} --> sig={:?} opt_kind={:?}",
                expr_def_id,
@@ -224,11 +227,7 @@ fn deduce_sig_from_projection(&self,
         debug!("deduce_sig_from_projection: ret_param_ty {:?}",
                ret_param_ty);
 
-        let fn_sig = ty::FnSig {
-            inputs: input_tys,
-            output: ret_param_ty,
-            variadic: false,
-        };
+        let fn_sig = ty::FnSig::new(input_tys, ret_param_ty, false);
         debug!("deduce_sig_from_projection: fn_sig {:?}", fn_sig);
 
         Some(fn_sig)
index 2602ff05badd44e0a4d6bcc5389e6245235ae21e..e85dac1a44c4438f8dc932febbf45b60dadf61fa 100644 (file)
@@ -495,8 +495,8 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
                         _ => bug!("{:?} is not a MethodTraitItem", trait_m),
                     };
 
-                let impl_iter = impl_sig.inputs.iter();
-                let trait_iter = trait_sig.inputs.iter();
+                let impl_iter = impl_sig.inputs().iter();
+                let trait_iter = trait_sig.inputs().iter();
                 impl_iter.zip(trait_iter)
                          .zip(impl_m_iter)
                          .zip(trait_m_iter)
@@ -508,7 +508,8 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
                          })
                          .next()
                          .unwrap_or_else(|| {
-                             if infcx.sub_types(false, &cause, impl_sig.output, trait_sig.output)
+                             if infcx.sub_types(false, &cause, impl_sig.output(),
+                                                trait_sig.output())
                                      .is_err() {
                                          (impl_m_output.span(), Some(trait_m_output.span()))
                                      } else {
@@ -681,9 +682,9 @@ fn compare_number_of_method_arguments<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     };
     let impl_m_fty = m_fty(impl_m);
     let trait_m_fty = m_fty(trait_m);
-    if impl_m_fty.sig.0.inputs.len() != trait_m_fty.sig.0.inputs.len() {
-        let trait_number_args = trait_m_fty.sig.0.inputs.len();
-        let impl_number_args = impl_m_fty.sig.0.inputs.len();
+    let trait_number_args = trait_m_fty.sig.inputs().skip_binder().len();
+    let impl_number_args = impl_m_fty.sig.inputs().skip_binder().len();
+    if trait_number_args != impl_number_args {
         let trait_m_node_id = tcx.map.as_local_node_id(trait_m.def_id);
         let trait_span = if let Some(trait_id) = trait_m_node_id {
             match tcx.map.expect_trait_item(trait_id).node {
index a07573a7b9eab08c9578f7bfa36d835b412dc060..23915880167fed2acd56ad17e0fbb8b5b1fa7606 100644 (file)
@@ -42,11 +42,7 @@ fn equate_intrinsic_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     let fty = tcx.mk_fn_def(def_id, substs, tcx.mk_bare_fn(ty::BareFnTy {
         unsafety: hir::Unsafety::Unsafe,
         abi: abi,
-        sig: ty::Binder(FnSig {
-            inputs: inputs,
-            output: output,
-            variadic: false,
-        }),
+        sig: ty::Binder(FnSig::new(inputs, output, false)),
     }));
     let i_n_tps = tcx.item_generics(def_id).types.len();
     if i_n_tps != n_tps {
@@ -299,11 +295,7 @@ fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
                 let fn_ty = tcx.mk_bare_fn(ty::BareFnTy {
                     unsafety: hir::Unsafety::Normal,
                     abi: Abi::Rust,
-                    sig: ty::Binder(FnSig {
-                        inputs: vec![mut_u8],
-                        output: tcx.mk_nil(),
-                        variadic: false,
-                    }),
+                    sig: ty::Binder(FnSig::new(vec![mut_u8], tcx.mk_nil(), false)),
                 });
                 (0, vec![tcx.mk_fn_ptr(fn_ty), mut_u8, mut_u8], tcx.types.i32)
             }
@@ -377,21 +369,21 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
 
                     let sig = tcx.item_type(def_id).fn_sig();
                     let sig = tcx.no_late_bound_regions(sig).unwrap();
-                    if intr.inputs.len() != sig.inputs.len() {
+                    if intr.inputs.len() != sig.inputs().len() {
                         span_err!(tcx.sess, it.span, E0444,
                                   "platform-specific intrinsic has invalid number of \
                                    arguments: found {}, expected {}",
-                                  sig.inputs.len(), intr.inputs.len());
+                                  sig.inputs().len(), intr.inputs.len());
                         return
                     }
-                    let input_pairs = intr.inputs.iter().zip(&sig.inputs);
+                    let input_pairs = intr.inputs.iter().zip(sig.inputs());
                     for (i, (expected_arg, arg)) in input_pairs.enumerate() {
                         match_intrinsic_type_to_type(ccx, &format!("argument {}", i + 1), it.span,
                                                      &mut structural_to_nomimal, expected_arg, arg);
                     }
                     match_intrinsic_type_to_type(ccx, "return value", it.span,
                                                  &mut structural_to_nomimal,
-                                                 &intr.output, sig.output);
+                                                 &intr.output, sig.output());
                     return
                 }
                 None => {
index 2e66f6290a022deb523097ab40adfbc17bdadd20..b29eab780e0355df72e290dc5d79dfea719ac727 100644 (file)
@@ -246,7 +246,7 @@ pub fn lookup_method_in_trait_adjusted(&self,
                                                                     infer::FnCall,
                                                                     &fty.sig).0;
         let fn_sig = self.instantiate_type_scheme(span, trait_ref.substs, &fn_sig);
-        let transformed_self_ty = fn_sig.inputs[0];
+        let transformed_self_ty = fn_sig.inputs()[0];
         let method_ty = tcx.mk_fn_def(def_id, trait_ref.substs,
                                       tcx.mk_bare_fn(ty::BareFnTy {
             sig: ty::Binder(fn_sig),
index 1950adf832977e19f6c2c5a9c4e9904dd905ddf6..058bb9254d82b2b4f9ab92f8cc46b42c69fc2c3a 100644 (file)
@@ -785,18 +785,18 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
 
     // Create the function context.  This is either derived from scratch or,
     // in the case of function expressions, based on the outer context.
-    let mut fcx = FnCtxt::new(inherited, fn_sig.output, body.id);
+    let mut fcx = FnCtxt::new(inherited, fn_sig.output(), body.id);
     *fcx.ps.borrow_mut() = UnsafetyState::function(unsafety, unsafety_id);
 
     fcx.require_type_is_sized(fcx.ret_ty, decl.output.span(), traits::ReturnType);
     fcx.ret_ty = fcx.instantiate_anon_types(&fcx.ret_ty);
-    fn_sig.output = fcx.ret_ty;
+    fn_sig = ty::FnSig::new(fn_sig.inputs().to_owned(), fcx.ret_ty, fn_sig.variadic());
 
     {
         let mut visit = GatherLocalsVisitor { fcx: &fcx, };
 
         // Add formal parameters.
-        for (arg_ty, input) in fn_sig.inputs.iter().zip(&decl.inputs) {
+        for (arg_ty, input) in fn_sig.inputs().iter().zip(&decl.inputs) {
             // The type of the argument must be well-formed.
             //
             // NB -- this is now checked in wfcheck, but that
@@ -2474,13 +2474,12 @@ fn check_method_argument_types(&self,
                 ty::TyFnDef(def_id, .., ref fty) => {
                     // HACK(eddyb) ignore self in the definition (see above).
                     let expected_arg_tys = self.expected_types_for_fn_args(sp, expected,
-                                                                           fty.sig.0.output,
-                                                                           &fty.sig.0.inputs[1..]);
-
-                    self.check_argument_types(sp, &fty.sig.0.inputs[1..], &expected_arg_tys[..],
-                                              args_no_rcvr, fty.sig.0.variadic, tuple_arguments,
+                                                                           fty.sig.0.output(),
+                                                                           &fty.sig.0.inputs()[1..]);
+                    self.check_argument_types(sp, &fty.sig.0.inputs()[1..], &expected_arg_tys[..],
+                                              args_no_rcvr, fty.sig.0.variadic(), tuple_arguments,
                                               self.tcx.map.span_if_local(def_id));
-                    fty.sig.0.output
+                    fty.sig.0.output()
                 }
                 _ => {
                     span_bug!(callee_expr.span, "method without bare fn type");
index c0bf5773ed56ab3de33d500caada73b8f34e7a70..eb08e70d4c3e445d0a4da8ae9be41a0f98020fcc 100644 (file)
@@ -296,10 +296,7 @@ fn visit_fn_body(&mut self,
         //
         // FIXME(#27579) return types should not be implied bounds
         let fn_sig_tys: Vec<_> =
-            fn_sig.inputs.iter()
-                         .cloned()
-                         .chain(Some(fn_sig.output))
-                         .collect();
+            fn_sig.inputs().iter().cloned().chain(Some(fn_sig.output())).collect();
 
         let old_body_id = self.set_body_id(body_id.node_id());
         self.relate_free_regions(&fn_sig_tys[..], body_id.node_id(), span);
@@ -940,7 +937,7 @@ fn constrain_autoderefs(&mut self,
                     let fn_sig = method.ty.fn_sig();
                     let fn_sig = // late-bound regions should have been instantiated
                         self.tcx.no_late_bound_regions(fn_sig).unwrap();
-                    let self_ty = fn_sig.inputs[0];
+                    let self_ty = fn_sig.inputs()[0];
                     let (m, r) = match self_ty.sty {
                         ty::TyRef(r, ref m) => (m.mutbl, r),
                         _ => {
@@ -967,8 +964,8 @@ fn constrain_autoderefs(&mut self,
                     self.type_must_outlive(infer::CallRcvr(deref_expr.span),
                                            self_ty, r_deref_expr);
                     self.type_must_outlive(infer::CallReturn(deref_expr.span),
-                                           fn_sig.output, r_deref_expr);
-                    fn_sig.output
+                                           fn_sig.output(), r_deref_expr);
+                    fn_sig.output()
                 }
                 None => derefd_ty
             };
index 7870b3677d0d0b53d3e1b2fa30886bdeadcc9095..7f35c8efeff41fa68a3b6ba485104959992ac2c6 100644 (file)
@@ -449,15 +449,15 @@ fn check_fn_or_method<'fcx, 'tcx>(&mut self,
         let fty = fcx.instantiate_type_scheme(span, free_substs, &fty);
         let sig = fcx.tcx.liberate_late_bound_regions(free_id_outlive, &fty.sig);
 
-        for &input_ty in &sig.inputs {
-            fcx.register_wf_obligation(input_ty, span, self.code.clone());
+        for input_ty in sig.inputs() {
+            fcx.register_wf_obligation(&input_ty, span, self.code.clone());
         }
-        implied_bounds.extend(sig.inputs);
+        implied_bounds.extend(sig.inputs());
 
-        fcx.register_wf_obligation(sig.output, span, self.code.clone());
+        fcx.register_wf_obligation(sig.output(), span, self.code.clone());
 
         // FIXME(#25759) return types should not be implied bounds
-        implied_bounds.push(sig.output);
+        implied_bounds.push(sig.output());
 
         self.check_where_clauses(fcx, span, predicates);
     }
@@ -487,7 +487,7 @@ fn check_method_receiver<'fcx, 'tcx>(&mut self,
 
         debug!("check_method_receiver: sig={:?}", sig);
 
-        let self_arg_ty = sig.inputs[0];
+        let self_arg_ty = sig.inputs()[0];
         let rcvr_ty = match ExplicitSelf::determine(self_ty, self_arg_ty) {
             ExplicitSelf::ByValue => self_ty,
             ExplicitSelf::ByReference(region, mutbl) => {
index 3bb7d6a77ba5c2efef02019d9e9ca79d9d305121..a965753a9c14371479ca32f3c1ee7333e950c804 100644 (file)
@@ -930,11 +930,7 @@ fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
             tcx.mk_fn_def(def_id, substs, tcx.mk_bare_fn(ty::BareFnTy {
                 unsafety: hir::Unsafety::Normal,
                 abi: abi::Abi::Rust,
-                sig: ty::Binder(ty::FnSig {
-                    inputs: inputs,
-                    output: ty,
-                    variadic: false
-                })
+                sig: ty::Binder(ty::FnSig::new(inputs, ty, false))
             }))
         }
     };
@@ -2085,9 +2081,7 @@ fn compute_type_of_foreign_fn_decl<'a, 'tcx>(
     ccx.tcx.mk_fn_def(def_id, substs, ccx.tcx.mk_bare_fn(ty::BareFnTy {
         abi: abi,
         unsafety: hir::Unsafety::Unsafe,
-        sig: ty::Binder(ty::FnSig {inputs: input_tys,
-                                    output: output,
-                                    variadic: decl.variadic}),
+        sig: ty::Binder(ty::FnSig::new(input_tys, output, decl.variadic)),
     }))
 }
 
index dfa662590297f2c3349792d4397061a0f0135e4e..0017676dae426e58d322abc7199428e81ccd7cc4 100644 (file)
@@ -222,11 +222,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
                                       tcx.mk_bare_fn(ty::BareFnTy {
                 unsafety: hir::Unsafety::Normal,
                 abi: Abi::Rust,
-                sig: ty::Binder(ty::FnSig {
-                    inputs: Vec::new(),
-                    output: tcx.mk_nil(),
-                    variadic: false
-                })
+                sig: ty::Binder(ty::FnSig::new(Vec::new(), tcx.mk_nil(), false))
             }));
 
             require_same_types(
@@ -274,14 +270,14 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
                                       tcx.mk_bare_fn(ty::BareFnTy {
                 unsafety: hir::Unsafety::Normal,
                 abi: Abi::Rust,
-                sig: ty::Binder(ty::FnSig {
-                    inputs: vec![
+                sig: ty::Binder(ty::FnSig::new(
+                    vec![
                         tcx.types.isize,
                         tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))
                     ],
-                    output: tcx.types.isize,
-                    variadic: false,
-                }),
+                    tcx.types.isize,
+                    false,
+                )),
             }));
 
             require_same_types(
index ded9df25d5c665e96472c6c476931ec3892c7feb..39f996ee62b541e4d7cc003a54227908c7f73c77 100644 (file)
@@ -467,10 +467,10 @@ fn add_constraints_from_sig(&mut self,
                                 sig: &ty::PolyFnSig<'tcx>,
                                 variance: VarianceTermPtr<'a>) {
         let contra = self.contravariant(variance);
-        for &input in &sig.0.inputs {
+        for &input in sig.0.inputs() {
             self.add_constraints_from_ty(generics, input, contra);
         }
-        self.add_constraints_from_ty(generics, sig.0.output, variance);
+        self.add_constraints_from_ty(generics, sig.0.output(), variance);
     }
 
     /// Adds constraints appropriate for a region appearing in a
index bc8472bb6b76023654fe002daf73b62d2c73b7d1..28ca92f5db6f69e7ed80460d958fade26386261f 100644 (file)
@@ -1152,11 +1152,11 @@ fn clean(&self, cx: &DocContext) -> FnDecl {
             cx.tcx.sess.cstore.fn_arg_names(did).into_iter()
         }.peekable();
         FnDecl {
-            output: Return(sig.0.output.clean(cx)),
+            output: Return(sig.skip_binder().output().clean(cx)),
             attrs: Attributes::default(),
-            variadic: sig.0.variadic,
+            variadic: sig.skip_binder().variadic,
             inputs: Arguments {
-                values: sig.0.inputs.iter().map(|t| {
+                values: sig.skip_binder().inputs().iter().map(|t| {
                     Argument {
                         type_: t.clean(cx),
                         id: ast::CRATE_NODE_ID,