]> git.lizzy.rs Git - rust.git/commitdiff
Centralize on using `Binder` to introduce new binding levels, rather than having...
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 12 Dec 2014 16:28:35 +0000 (11:28 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Fri, 19 Dec 2014 08:29:30 +0000 (03:29 -0500)
48 files changed:
src/librustc/metadata/decoder.rs
src/librustc/metadata/tydecode.rs
src/librustc/metadata/tyencode.rs
src/librustc/middle/astencode.rs
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/fast_reject.rs
src/librustc/middle/infer/combine.rs
src/librustc/middle/infer/equate.rs
src/librustc/middle/infer/error_reporting.rs
src/librustc/middle/infer/glb.rs
src/librustc/middle/infer/higher_ranked/mod.rs
src/librustc/middle/infer/lub.rs
src/librustc/middle/infer/mod.rs
src/librustc/middle/infer/sub.rs
src/librustc/middle/intrinsicck.rs
src/librustc/middle/liveness.rs
src/librustc/middle/privacy.rs
src/librustc/middle/traits/coherence.rs
src/librustc/middle/traits/select.rs
src/librustc/middle/traits/util.rs
src/librustc/middle/ty.rs
src/librustc/middle/ty_fold.rs
src/librustc/util/ppaux.rs
src/librustc_driver/test.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/closure.rs
src/librustc_trans/trans/debuginfo.rs
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/foreign.rs
src/librustc_trans/trans/glue.rs
src/librustc_trans/trans/intrinsic.rs
src/librustc_trans/trans/meth.rs
src/librustc_trans/trans/type_of.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/method/mod.rs
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/check/vtable.rs
src/librustc_typeck/check/wf.rs
src/librustc_typeck/coherence/mod.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/lib.rs
src/librustc_typeck/variance.rs
src/librustdoc/clean/mod.rs

index 1b3a6c0e6ba39d0ad164ea946a18eee991198ce0..0625c50d6721f4910b7482f83c7fbcdf2174052b 100644 (file)
@@ -429,7 +429,7 @@ pub fn get_impl_trait<'tcx>(cdata: Cmd,
 {
     let item_doc = lookup_item(id, cdata.data());
     reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| {
-        Rc::new(ty::bind(doc_trait_ref(tp, tcx, cdata)))
+        Rc::new(ty::Binder(doc_trait_ref(tp, tcx, cdata)))
     })
 }
 
@@ -704,7 +704,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
         let name = item_name(&*intr, item);
         let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
             ty::ty_bare_fn(ref f) =>
-                (Some(ctor_ty), f.sig.inputs.clone(), None),
+                (Some(ctor_ty), f.sig.0.inputs.clone(), None),
             _ => { // Nullary or struct enum variant.
                 let mut arg_names = Vec::new();
                 let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
index 3d0b63139e4bc312dd9f08a19220dc397065471f..f3d700f013d815bfb0960f142c651082dad90cb1 100644 (file)
@@ -414,7 +414,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
       }
       'x' => {
         assert_eq!(next(st), '[');
-        let trait_ref = ty::bind(parse_trait_ref(st, |x,y| conv(x,y)));
+        let trait_ref = ty::Binder(parse_trait_ref(st, |x,y| conv(x,y)));
         let bounds = parse_existential_bounds(st, |x,y| conv(x,y));
         assert_eq!(next(st), ']');
         return ty::mk_trait(st.tcx, trait_ref, bounds);
@@ -603,7 +603,7 @@ fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
     }
 }
 
-fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::FnSig<'tcx> {
+fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::PolyFnSig<'tcx> {
     assert_eq!(next(st), '[');
     let mut inputs = Vec::new();
     while peek(st) != ']' {
@@ -622,9 +622,9 @@ fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::FnSig<'
         }
         _ => ty::FnConverging(parse_ty(st, |x,y| conv(x,y)))
     };
-    ty::FnSig {inputs: inputs,
-               output: output,
-               variadic: variadic}
+    ty::Binder(ty::FnSig {inputs: inputs,
+                        output: output,
+                        variadic: variadic})
 }
 
 // Rust metadata parsing
@@ -669,7 +669,7 @@ pub fn parse_predicate<'a,'tcx>(st: &mut PState<'a, 'tcx>,
                                 -> ty::Predicate<'tcx>
 {
     match next(st) {
-        't' => ty::Predicate::Trait(Rc::new(ty::bind(parse_trait_ref(st, conv)))),
+        't' => ty::Predicate::Trait(Rc::new(ty::Binder(parse_trait_ref(st, conv)))),
         'e' => ty::Predicate::Equate(parse_ty(st, |x,y| conv(x,y)),
                                      parse_ty(st, |x,y| conv(x,y))),
         'r' => ty::Predicate::RegionOutlives(parse_region(st, |x,y| conv(x,y)),
@@ -764,7 +764,7 @@ fn parse_bounds<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
             }
             'I' => {
                 param_bounds.trait_bounds.push(
-                    Rc::new(ty::bind(parse_trait_ref(st, |x,y| conv(x,y)))));
+                    Rc::new(ty::Binder(parse_trait_ref(st, |x,y| conv(x,y)))));
             }
             '.' => {
                 return param_bounds;
index fd13ea57e6be0d2814e3af67290e41e8e727fb58..c6218e6fe94782bdd87cbbc80a79583993e12fac 100644 (file)
@@ -251,7 +251,7 @@ fn enc_sty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
         ty::ty_trait(box ty::TyTrait { ref principal,
                                        ref bounds }) => {
             mywrite!(w, "x[");
-            enc_trait_ref(w, cx, &principal.value);
+            enc_trait_ref(w, cx, &principal.0);
             enc_existential_bounds(w, cx, bounds);
             mywrite!(w, "]");
         }
@@ -351,18 +351,18 @@ pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
 }
 
 fn enc_fn_sig<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
-                        fsig: &ty::FnSig<'tcx>) {
+                        fsig: &ty::PolyFnSig<'tcx>) {
     mywrite!(w, "[");
-    for ty in fsig.inputs.iter() {
+    for ty in fsig.0.inputs.iter() {
         enc_ty(w, cx, *ty);
     }
     mywrite!(w, "]");
-    if fsig.variadic {
+    if fsig.0.variadic {
         mywrite!(w, "V");
     } else {
         mywrite!(w, "N");
     }
-    match fsig.output {
+    match fsig.0.output {
         ty::FnConverging(result_type) => {
             enc_ty(w, cx, result_type);
         }
@@ -401,7 +401,7 @@ pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
 
     for tp in bs.trait_bounds.iter() {
         mywrite!(w, "I");
-        enc_trait_ref(w, cx, &tp.value);
+        enc_trait_ref(w, cx, &tp.0);
     }
 
     mywrite!(w, ".");
@@ -425,7 +425,7 @@ pub fn enc_predicate<'a, 'tcx>(w: &mut SeekableMemWriter,
     match *p {
         ty::Predicate::Trait(ref trait_ref) => {
             mywrite!(w, "t");
-            enc_trait_ref(w, cx, &trait_ref.value);
+            enc_trait_ref(w, cx, &trait_ref.0);
         }
         ty::Predicate::Equate(a, b) => {
             mywrite!(w, "e");
index 3f0e28589fc5467354db55bfda1096271d434dcf..0021533a2bbe6f914e69388e57ccbad943083346 100644 (file)
@@ -887,7 +887,7 @@ fn emit_method_origin<'b>(&mut self,
                     this.emit_enum_variant("MethodTypeParam", 2, 1, |this| {
                         this.emit_struct("MethodParam", 2, |this| {
                             try!(this.emit_struct_field("trait_ref", 0, |this| {
-                                Ok(this.emit_trait_ref(ecx, &p.trait_ref.value))
+                                Ok(this.emit_trait_ref(ecx, &p.trait_ref.0))
                             }));
                             try!(this.emit_struct_field("method_num", 0, |this| {
                                 this.emit_uint(p.method_num)
@@ -901,7 +901,7 @@ fn emit_method_origin<'b>(&mut self,
                     this.emit_enum_variant("MethodTraitObject", 3, 1, |this| {
                         this.emit_struct("MethodObject", 2, |this| {
                             try!(this.emit_struct_field("trait_ref", 0, |this| {
-                                Ok(this.emit_trait_ref(ecx, &o.trait_ref.value))
+                                Ok(this.emit_trait_ref(ecx, &o.trait_ref.0))
                             }));
                             try!(this.emit_struct_field("object_trait_id", 0, |this| {
                                 Ok(this.emit_def_id(o.object_trait_id))
@@ -1113,7 +1113,7 @@ fn emit_unsize_kind<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
                     this.emit_enum_variant("UnsizeVtable", 2, 4, |this| {
                         this.emit_enum_variant_arg(0, |this| {
                             try!(this.emit_struct_field("principal", 0, |this| {
-                                Ok(this.emit_trait_ref(ecx, &principal.value))
+                                Ok(this.emit_trait_ref(ecx, &principal.0))
                             }));
                             this.emit_struct_field("bounds", 1, |this| {
                                 Ok(this.emit_existential_bounds(ecx, b))
@@ -1277,7 +1277,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
         rbml_w.tag(c::tag_table_object_cast_map, |rbml_w| {
             rbml_w.id(id);
             rbml_w.tag(c::tag_table_val, |rbml_w| {
-                rbml_w.emit_trait_ref(ecx, &trait_ref.value);
+                rbml_w.emit_trait_ref(ecx, &trait_ref.0);
             })
         })
     }
@@ -1552,7 +1552,7 @@ fn read_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
 
     fn read_poly_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
                                    -> Rc<ty::PolyTraitRef<'tcx>> {
-        Rc::new(ty::bind(self.read_opaque(|this, doc| {
+        Rc::new(ty::Binder(self.read_opaque(|this, doc| {
             let ty = tydecode::parse_trait_ref_data(
                 doc.data,
                 dcx.cdata.cnum,
index 41020df63995e3d3efc2340fa04b0aab056af580..8b0df4e69cd8e61c91643c0501956ecaa0f7dc8b 100644 (file)
@@ -265,7 +265,7 @@ fn from_method_id(tcx: &ty::ctxt, method_id: ast::DefId)
             }
             Some(ref trait_ref) => (*trait_ref).clone(),
         };
-        OverloadedCallType::from_trait_id(tcx, trait_ref.value.def_id)
+        OverloadedCallType::from_trait_id(tcx, trait_ref.def_id())
     }
 
     fn from_unboxed_closure(tcx: &ty::ctxt, closure_did: ast::DefId)
index 2be5e46fcbb68deea643661bee0da493ad0b28c7..5c0d4b4841ee385377969dfb3db65c0ddb7be444 100644 (file)
@@ -60,7 +60,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
         ty::ty_vec(..) => Some(VecSimplifiedType),
         ty::ty_ptr(_) => Some(PtrSimplifiedType),
         ty::ty_trait(ref trait_info) => {
-            Some(TraitSimplifiedType(trait_info.principal.value.def_id))
+            Some(TraitSimplifiedType(trait_info.principal.def_id()))
         }
         ty::ty_struct(def_id, _) => {
             Some(StructSimplifiedType(def_id))
@@ -83,10 +83,10 @@ pub fn simplify_type(tcx: &ty::ctxt,
             Some(TupleSimplifiedType(tys.len()))
         }
         ty::ty_closure(ref f) => {
-            Some(FunctionSimplifiedType(f.sig.inputs.len()))
+            Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
         }
         ty::ty_bare_fn(ref f) => {
-            Some(FunctionSimplifiedType(f.sig.inputs.len()))
+            Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
         }
         ty::ty_param(_) => {
             if can_simplify_params {
index 1681731005db8712538812d000efd1fea8ede6d0..82ddbcee5a72e50a44a5f5cd010e9119e42e8ef6 100644 (file)
@@ -195,7 +195,7 @@ fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>,
                    b: &ty::BareFnTy<'tcx>) -> cres<'tcx, ty::BareFnTy<'tcx>> {
         let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
         let abi = try!(self.abi(a.abi, b.abi));
-        let sig = try!(self.fn_sigs(&a.sig, &b.sig));
+        let sig = try!(self.binders(&a.sig, &b.sig));
         Ok(ty::BareFnTy {unsafety: unsafety,
                          abi: abi,
                          sig: sig})
@@ -222,7 +222,7 @@ fn closure_tys(&self, a: &ty::ClosureTy<'tcx>,
         let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
         let onceness = try!(self.oncenesses(a.onceness, b.onceness));
         let bounds = try!(self.existential_bounds(a.bounds, b.bounds));
-        let sig = try!(self.fn_sigs(&a.sig, &b.sig));
+        let sig = try!(self.binders(&a.sig, &b.sig));
         let abi = try!(self.abi(a.abi, b.abi));
         Ok(ty::ClosureTy {
             unsafety: unsafety,
@@ -234,7 +234,43 @@ fn closure_tys(&self, a: &ty::ClosureTy<'tcx>,
         })
     }
 
-    fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::FnSig<'tcx>>;
+    fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::FnSig<'tcx>> {
+        if a.variadic != b.variadic {
+            return Err(ty::terr_variadic_mismatch(expected_found(self, a.variadic, b.variadic)));
+        }
+
+        let inputs = try!(argvecs(self,
+                                  a.inputs.as_slice(),
+                                  b.inputs.as_slice()));
+
+        let output = try!(match (a.output, b.output) {
+            (ty::FnConverging(a_ty), ty::FnConverging(b_ty)) =>
+                Ok(ty::FnConverging(try!(self.tys(a_ty, b_ty)))),
+            (ty::FnDiverging, ty::FnDiverging) =>
+                Ok(ty::FnDiverging),
+            (a, b) =>
+                Err(ty::terr_convergence_mismatch(
+                    expected_found(self, a != ty::FnDiverging, b != ty::FnDiverging))),
+        });
+
+        return Ok(ty::FnSig {inputs: inputs,
+                             output: output,
+                             variadic: a.variadic});
+
+
+        fn argvecs<'tcx, C: Combine<'tcx>>(combiner: &C,
+                                           a_args: &[Ty<'tcx>],
+                                           b_args: &[Ty<'tcx>])
+                                           -> cres<'tcx, Vec<Ty<'tcx>>>
+        {
+            if a_args.len() == b_args.len() {
+                a_args.iter().zip(b_args.iter())
+                    .map(|(a, b)| combiner.args(*a, *b)).collect()
+            } else {
+                Err(ty::terr_arg_count)
+            }
+        }
+    }
 
     fn args(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
         self.contratys(a, b).and_then(|t| Ok(t))
@@ -312,14 +348,36 @@ fn trait_refs(&self,
         }
     }
 
-    fn poly_trait_refs(&self,
-                       a: &ty::PolyTraitRef<'tcx>,
-                       b: &ty::PolyTraitRef<'tcx>)
-                       -> cres<'tcx, ty::PolyTraitRef<'tcx>>;
+    fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
+        where T : Combineable<'tcx>;
     // this must be overridden to do correctly, so as to account for higher-ranked
     // behavior
 }
 
+pub trait Combineable<'tcx> : Repr<'tcx> + TypeFoldable<'tcx> {
+    fn combine<C:Combine<'tcx>>(combiner: &C, a: &Self, b: &Self) -> cres<'tcx, Self>;
+}
+
+impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> {
+    fn combine<C:Combine<'tcx>>(combiner: &C,
+                                a: &ty::TraitRef<'tcx>,
+                                b: &ty::TraitRef<'tcx>)
+                                -> cres<'tcx, ty::TraitRef<'tcx>>
+    {
+        combiner.trait_refs(a, b)
+    }
+}
+
+impl<'tcx> Combineable<'tcx> for ty::FnSig<'tcx> {
+    fn combine<C:Combine<'tcx>>(combiner: &C,
+                                a: &ty::FnSig<'tcx>,
+                                b: &ty::FnSig<'tcx>)
+                                -> cres<'tcx, ty::FnSig<'tcx>>
+    {
+        combiner.fn_sigs(a, b)
+    }
+}
+
 #[deriving(Clone)]
 pub struct CombineFields<'a, 'tcx: 'a> {
     pub infcx: &'a InferCtxt<'a, 'tcx>,
@@ -424,7 +482,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C,
       (&ty::ty_trait(ref a_),
        &ty::ty_trait(ref b_)) => {
           debug!("Trying to match traits {} and {}", a, b);
-          let principal = try!(this.poly_trait_refs(&a_.principal, &b_.principal));
+          let principal = try!(this.binders(&a_.principal, &b_.principal));
           let bounds = try!(this.existential_bounds(a_.bounds, b_.bounds));
           Ok(ty::mk_trait(tcx, principal, bounds))
       }
index 79fbc33f2a1dfca77982b688e80acba1672e287f..2a4d20f4dd3799ccdbe7b0fac6dad97333e92d4c 100644 (file)
@@ -133,17 +133,10 @@ fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
         }
     }
 
-    fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>)
-               -> cres<'tcx, ty::FnSig<'tcx>>
+    fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
+        where T : Combineable<'tcx>
     {
-        try!(self.sub().fn_sigs(a, b));
-        self.sub().fn_sigs(b, a)
-    }
-
-    fn poly_trait_refs(&self, a: &ty::PolyTraitRef<'tcx>, b: &ty::PolyTraitRef<'tcx>)
-                       -> cres<'tcx, ty::PolyTraitRef<'tcx>>
-    {
-        try!(self.sub().poly_trait_refs(a, b));
-        self.sub().poly_trait_refs(b, a)
+        try!(self.sub().binders(a, b));
+        self.sub().binders(b, a)
     }
 }
index 89d6a7df05098535f620bf7100a0976e6fd92af4..d1253e0b6976bbfb79328be4dc97de5766ecf271 100644 (file)
@@ -1653,7 +1653,7 @@ fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>)
         Rc::new(infcx.resolve_type_vars_if_possible(&**self))
     }
     fn contains_error(&self) -> bool {
-        ty::trait_ref_contains_error(&self.value)
+        ty::trait_ref_contains_error(&self.0)
     }
 }
 
index f751931a9412ee856a53c2c50a213d4c2ac63a8a..434be32fe5fa70162c642c910e716ca9c7acf0e5 100644 (file)
@@ -121,13 +121,9 @@ fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
         super_lattice_tys(self, a, b)
     }
 
-    fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>)
-               -> cres<'tcx, ty::FnSig<'tcx>> {
-        self.higher_ranked_glb(a, b)
-    }
-
-    fn poly_trait_refs(&self, a: &ty::PolyTraitRef<'tcx>, b: &ty::PolyTraitRef<'tcx>)
-                       -> cres<'tcx, ty::PolyTraitRef<'tcx>> {
+    fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
+        where T : Combineable<'tcx>
+    {
         self.higher_ranked_glb(a, b)
     }
 }
index 93a4d7c2f46d9bb42cce5af65c64bc6abd95491d..dcc365fad18eebf75b3b6ec9b75d5b85f4068105 100644 (file)
 //! Helper routines for higher-ranked things. See the `doc` module at
 //! the end of the file for details.
 
-use super::{combine, CombinedSnapshot, cres, InferCtxt, HigherRankedType};
-use super::combine::Combine;
+use super::{CombinedSnapshot, cres, InferCtxt, HigherRankedType};
+use super::combine::{Combine, Combineable};
 
-use middle::ty::{mod, Ty, replace_late_bound_regions};
-use middle::ty_fold::{mod, HigherRankedFoldable, TypeFoldable};
+use middle::ty::{mod, Binder};
+use middle::ty_fold::{mod, TypeFoldable};
 use syntax::codemap::Span;
 use util::nodemap::{FnvHashMap, FnvHashSet};
-use util::ppaux::{bound_region_to_string, Repr};
-
-pub trait HigherRankedCombineable<'tcx>: HigherRankedFoldable<'tcx> +
-                                         TypeFoldable<'tcx> + Repr<'tcx> {
-    fn super_combine<C:Combine<'tcx>>(combiner: &C, a: &Self, b: &Self) -> cres<'tcx, Self>;
-}
+use util::ppaux::Repr;
 
 pub trait HigherRankedRelations<'tcx> {
-    fn higher_ranked_sub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
-        where T : HigherRankedCombineable<'tcx>;
+    fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>) -> cres<'tcx, Binder<T>>
+        where T : Combineable<'tcx>;
 
-    fn higher_ranked_lub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
-        where T : HigherRankedCombineable<'tcx>;
+    fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>) -> cres<'tcx, Binder<T>>
+        where T : Combineable<'tcx>;
 
-    fn higher_ranked_glb<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
-        where T : HigherRankedCombineable<'tcx>;
+    fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>) -> cres<'tcx, Binder<T>>
+        where T : Combineable<'tcx>;
 }
 
 trait InferCtxtExt<'tcx> {
@@ -47,8 +42,9 @@ fn region_vars_confined_to_snapshot(&self,
 impl<'tcx,C> HigherRankedRelations<'tcx> for C
     where C : Combine<'tcx>
 {
-    fn higher_ranked_sub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
-        where T : HigherRankedCombineable<'tcx>
+    fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>)
+                            -> cres<'tcx, Binder<T>>
+        where T : Combineable<'tcx>
     {
         debug!("higher_ranked_sub(a={}, b={})",
                a.repr(self.tcx()), b.repr(self.tcx()));
@@ -74,13 +70,14 @@ fn higher_ranked_sub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
 
             // Second, we instantiate each bound region in the supertype with a
             // fresh concrete region.
-            let (b_prime, skol_map) = skolemize_regions(self.infcx(), b, snapshot);
+            let (b_prime, skol_map) =
+                self.infcx().skolemize_late_bound_regions(b, snapshot);
 
             debug!("a_prime={}", a_prime.repr(self.tcx()));
             debug!("b_prime={}", b_prime.repr(self.tcx()));
 
             // Compare types now that bound regions have been replaced.
-            let result = try!(HigherRankedCombineable::super_combine(self, &a_prime, &b_prime));
+            let result = try!(Combineable::combine(self, &a_prime, &b_prime));
 
             // Presuming type comparison succeeds, we need to check
             // that the skolemized regions do not "leak".
@@ -102,12 +99,12 @@ fn higher_ranked_sub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
             debug!("higher_ranked_sub: OK result={}",
                    result.repr(self.tcx()));
 
-            Ok(result)
+            Ok(ty::Binder(result))
         });
     }
 
-    fn higher_ranked_lub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
-        where T : HigherRankedCombineable<'tcx>
+    fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>) -> cres<'tcx, Binder<T>>
+        where T : Combineable<'tcx>
     {
         // Start a snapshot so we can examine "all bindings that were
         // created as part of this type comparison".
@@ -123,7 +120,7 @@ fn higher_ranked_lub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
 
             // Collect constraints.
             let result0 =
-                try!(HigherRankedCombineable::super_combine(self, &a_with_fresh, &b_with_fresh));
+                try!(Combineable::combine(self, &a_with_fresh, &b_with_fresh));
             let result0 =
                 self.infcx().resolve_type_vars_if_possible(&result0);
             debug!("lub result0 = {}", result0.repr(self.tcx()));
@@ -143,7 +140,7 @@ fn higher_ranked_lub<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
                    b.repr(self.tcx()),
                    result1.repr(self.tcx()));
 
-            Ok(result1)
+            Ok(ty::Binder(result1))
         });
 
         fn generalize_region(infcx: &InferCtxt,
@@ -196,8 +193,8 @@ fn generalize_region(infcx: &InferCtxt,
         }
     }
 
-    fn higher_ranked_glb<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
-        where T : HigherRankedCombineable<'tcx>
+    fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>) -> cres<'tcx, Binder<T>>
+        where T : Combineable<'tcx>
     {
         debug!("{}.higher_ranked_glb({}, {})",
                self.tag(), a.repr(self.tcx()), b.repr(self.tcx()));
@@ -217,7 +214,7 @@ fn higher_ranked_glb<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
 
             // Collect constraints.
             let result0 =
-                try!(HigherRankedCombineable::super_combine(self, &a_with_fresh, &b_with_fresh));
+                try!(Combineable::combine(self, &a_with_fresh, &b_with_fresh));
             let result0 =
                 self.infcx().resolve_type_vars_if_possible(&result0);
             debug!("glb result0 = {}", result0.repr(self.tcx()));
@@ -239,7 +236,7 @@ fn higher_ranked_glb<T>(&self, a: &T, b: &T) -> cres<'tcx, T>
                    b.repr(self.tcx()),
                    result1.repr(self.tcx()));
 
-            Ok(result1)
+            Ok(ty::Binder(result1))
         });
 
         fn generalize_region(infcx: &InferCtxt,
@@ -334,59 +331,6 @@ fn fresh_bound_variable(infcx: &InferCtxt, debruijn: ty::DebruijnIndex) -> ty::R
     }
 }
 
-impl<'tcx> HigherRankedCombineable<'tcx> for ty::FnSig<'tcx> {
-    fn super_combine<C:Combine<'tcx>>(combiner: &C, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>)
-                                      -> cres<'tcx, ty::FnSig<'tcx>>
-    {
-        if a.variadic != b.variadic {
-            return Err(ty::terr_variadic_mismatch(
-                combine::expected_found(combiner, a.variadic, b.variadic)));
-        }
-
-        let inputs = try!(argvecs(combiner,
-                                  a.inputs.as_slice(),
-                                  b.inputs.as_slice()));
-
-        let output = try!(match (a.output, b.output) {
-            (ty::FnConverging(a_ty), ty::FnConverging(b_ty)) =>
-                Ok(ty::FnConverging(try!(combiner.tys(a_ty, b_ty)))),
-            (ty::FnDiverging, ty::FnDiverging) =>
-                Ok(ty::FnDiverging),
-            (a, b) =>
-                Err(ty::terr_convergence_mismatch(
-                    combine::expected_found(combiner, a != ty::FnDiverging, b != ty::FnDiverging))),
-        });
-
-        return Ok(ty::FnSig {inputs: inputs,
-                             output: output,
-                             variadic: a.variadic});
-
-
-        fn argvecs<'tcx, C: Combine<'tcx>>(combiner: &C,
-                                           a_args: &[Ty<'tcx>],
-                                           b_args: &[Ty<'tcx>])
-                                           -> cres<'tcx, Vec<Ty<'tcx>>>
-        {
-            if a_args.len() == b_args.len() {
-                a_args.iter().zip(b_args.iter())
-                    .map(|(a, b)| combiner.args(*a, *b)).collect()
-            } else {
-                Err(ty::terr_arg_count)
-            }
-        }
-    }
-}
-
-impl<'tcx> HigherRankedCombineable<'tcx> for ty::PolyTraitRef<'tcx> {
-    fn super_combine<C:Combine<'tcx>>(combiner: &C,
-                                      a: &ty::PolyTraitRef<'tcx>,
-                                      b: &ty::PolyTraitRef<'tcx>)
-                                      -> cres<'tcx, ty::PolyTraitRef<'tcx>>
-    {
-        Ok(ty::bind(try!(combiner.trait_refs(&a.value, &b.value))))
-    }
-}
-
 fn var_ids<'tcx, T: Combine<'tcx>>(combiner: &T,
                                    map: &FnvHashMap<ty::BoundRegion, ty::Region>)
                                    -> Vec<ty::RegionVid> {
@@ -407,11 +351,14 @@ fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool {
     }
 }
 
-fn fold_regions_in<'tcx, T, F>(tcx: &ty::ctxt<'tcx>, value: &T, mut fldr: F) -> T where
-    T: HigherRankedFoldable<'tcx>,
-    F: FnMut(ty::Region, ty::DebruijnIndex) -> ty::Region,
+fn fold_regions_in<'tcx, T, F>(tcx: &ty::ctxt<'tcx>,
+                               unbound_value: &T,
+                               mut fldr: F)
+                               -> T
+    where T : Combineable<'tcx>,
+          F : FnMut(ty::Region, ty::DebruijnIndex) -> ty::Region,
 {
-    value.fold_contents(&mut ty_fold::RegionFolder::new(tcx, |region, current_depth| {
+    unbound_value.fold_with(&mut ty_fold::RegionFolder::new(tcx, |region, current_depth| {
         // we should only be encountering "escaping" late-bound regions here,
         // because the ones at the current level should have been replaced
         // with fresh variables
@@ -508,26 +455,6 @@ fn region_vars_confined_to_snapshot(&self,
     }
 }
 
-fn skolemize_regions<'a,'tcx,HR>(infcx: &InferCtxt<'a,'tcx>,
-                                 value: &HR,
-                                 snapshot: &CombinedSnapshot)
-                                 -> (HR, FnvHashMap<ty::BoundRegion,ty::Region>)
-    where HR : HigherRankedFoldable<'tcx>
-{
-    replace_late_bound_regions(infcx.tcx, value, |br, _| {
-        let skol =
-            infcx.region_vars.new_skolemized(
-                br,
-                &snapshot.region_vars_snapshot);
-
-        debug!("Bound region {} skolemized to {}",
-               bound_region_to_string(infcx.tcx, "", false, br),
-               skol);
-
-        skol
-    })
-}
-
 fn leak_check<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
                        skol_map: &FnvHashMap<ty::BoundRegion,ty::Region>,
                        snapshot: &CombinedSnapshot)
index e142e3dbe443b07aa8aa0cd59803b1b777a6b936..f4909b2889163c73217538da16a65489c0375da9 100644 (file)
@@ -113,17 +113,13 @@ fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> {
         Ok(self.infcx().region_vars.lub_regions(Subtype(self.trace()), a, b))
     }
 
-    fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>)
-               -> cres<'tcx, ty::FnSig<'tcx>> {
-        self.higher_ranked_lub(a, b)
-    }
-
     fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
         super_lattice_tys(self, a, b)
     }
 
-    fn poly_trait_refs(&self, a: &ty::PolyTraitRef<'tcx>, b: &ty::PolyTraitRef<'tcx>)
-                       -> cres<'tcx, ty::PolyTraitRef<'tcx>> {
+    fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
+        where T : Combineable<'tcx>
+    {
         self.higher_ranked_lub(a, b)
     }
 }
index 4eda0d01ebb7ba87227c44125a6cfbc3e476350c..edd5c8b854e1fa73abb7f679748ef9dae242f763 100644 (file)
@@ -26,7 +26,7 @@
 use middle::ty::{TyVid, IntVid, FloatVid, RegionVid};
 use middle::ty::replace_late_bound_regions;
 use middle::ty::{mod, Ty};
-use middle::ty_fold::{HigherRankedFoldable, TypeFolder, TypeFoldable};
+use middle::ty_fold::{TypeFolder, TypeFoldable};
 use std::cell::{RefCell};
 use std::rc::Rc;
 use syntax::ast;
@@ -35,7 +35,7 @@
 use util::common::indent;
 use util::nodemap::FnvHashMap;
 use util::ppaux::{ty_to_string};
-use util::ppaux::{trait_ref_to_string, Repr};
+use util::ppaux::{Repr, UserString};
 
 use self::coercion::Coerce;
 use self::combine::{Combine, CombineFields};
@@ -699,26 +699,26 @@ pub fn sub_poly_trait_refs(&self,
                 values: TraitRefs(expected_found(a_is_expected,
                                                  a.clone(), b.clone()))
             };
-            self.sub(a_is_expected, trace).poly_trait_refs(&*a, &*b).to_ures()
+            self.sub(a_is_expected, trace).binders(&*a, &*b).to_ures()
         })
     }
 
-    pub fn skolemize_bound_regions<T>(&self,
-                                      value: &ty::Binder<T>,
-                                      snapshot: &CombinedSnapshot)
-                                      -> (T, SkolemizationMap)
-        where T : TypeFoldable<'tcx>
+    pub fn skolemize_late_bound_regions<T>(&self,
+                                           value: &ty::Binder<T>,
+                                           snapshot: &CombinedSnapshot)
+                                           -> (T, SkolemizationMap)
+        where T : TypeFoldable<'tcx> + Repr<'tcx>
     {
-        let (result_binder, map) = replace_late_bound_regions(self.tcx, value, |br, _| {
+        let (result, map) = replace_late_bound_regions(self.tcx, value, |br, _| {
             self.region_vars.new_skolemized(br, &snapshot.region_vars_snapshot)
         });
 
         debug!("skolemize_bound_regions(value={}, result={}, map={})",
                value.repr(self.tcx),
-               result_binder.value.repr(self.tcx),
+               result.repr(self.tcx),
                map.repr(self.tcx));
 
-        (result_binder.value, map)
+        (result, map)
     }
 
     pub fn next_ty_var_id(&self, diverging: bool) -> TyVid {
@@ -828,7 +828,7 @@ pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {
 
     pub fn trait_ref_to_string(&self, t: &Rc<ty::TraitRef<'tcx>>) -> String {
         let t = self.resolve_type_vars_if_possible(&**t);
-        trait_ref_to_string(self.tcx, &t)
+        t.user_string(self.tcx)
     }
 
     pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
@@ -982,9 +982,9 @@ pub fn replace_late_bound_regions_with_fresh_var<T>(
         &self,
         span: Span,
         lbrct: LateBoundRegionConversionTime,
-        value: &T)
+        value: &ty::Binder<T>)
         -> (T, FnvHashMap<ty::BoundRegion,ty::Region>)
-        where T : HigherRankedFoldable<'tcx>
+        where T : TypeFoldable<'tcx> + Repr<'tcx>
     {
         ty::replace_late_bound_regions(
             self.tcx,
index e7b7791cc2a843d5a32c2928cd41a42730f4e074..2b8adfb7c1eeb880d1d48663d93c74d23646fa81 100644 (file)
@@ -155,13 +155,9 @@ fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
         }
     }
 
-    fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>)
-               -> cres<'tcx, ty::FnSig<'tcx>> {
-        self.higher_ranked_sub(a, b)
-    }
-
-    fn poly_trait_refs(&self, a: &ty::PolyTraitRef<'tcx>, b: &ty::PolyTraitRef<'tcx>)
-                       -> cres<'tcx, ty::PolyTraitRef<'tcx>> {
+    fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
+        where T : Combineable<'tcx>
+    {
         self.higher_ranked_sub(a, b)
     }
 }
index acfdf6fefb55f0a8c80a8c3c11c32cd92c1be2a5..ea19111ce3d670f08125320dea1786588396a9d6 100644 (file)
@@ -124,8 +124,8 @@ fn visit_expr(&mut self, expr: &ast::Expr) {
                     let typ = ty::node_id_to_type(self.tcx, expr.id);
                     match typ.sty {
                         ty_bare_fn(ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
-                            if let ty::FnConverging(to) = bare_fn_ty.sig.output {
-                                let from = bare_fn_ty.sig.inputs[0];
+                            if let ty::FnConverging(to) = bare_fn_ty.sig.0.output {
+                                let from = bare_fn_ty.sig.0.inputs[0];
                                 self.check_transmute(expr.span, from, to, expr.id);
                             }
                         }
index c76d9bc6b1faabf03a21ec1d5e9db4fd2b5d93d1..4df655882b1551dc71442c1c6ddf6725e3cc9ff9 100644 (file)
@@ -1534,6 +1534,7 @@ fn fn_ret(&self, id: NodeId) -> ty::FnOutput<'tcx> {
                     .unwrap()
                     .closure_type
                     .sig
+                    .0
                     .output,
             _ => ty::ty_fn_ret(fn_ty)
         }
index b0d62644ca510e5ef057b9ad287e803309fdf46c..67e9d2fee58f48a516e59100381176f536a4d8a6 100644 (file)
@@ -257,8 +257,8 @@ fn visit_item(&mut self, item: &ast::Item) {
                 };
                 let tr = ty::impl_trait_ref(self.tcx, local_def(item.id));
                 let public_trait = tr.clone().map_or(false, |tr| {
-                    !is_local(tr.value.def_id) ||
-                     self.exported_items.contains(&tr.value.def_id.node)
+                    !is_local(tr.def_id()) ||
+                     self.exported_items.contains(&tr.def_id().node)
                 });
 
                 if public_ty || public_trait {
@@ -407,7 +407,7 @@ fn def_privacy(&self, did: ast::DefId) -> PrivacyResult {
                             match ty::impl_trait_ref(self.tcx, id) {
                                 Some(t) => {
                                     debug!("privacy - impl of trait {}", id);
-                                    self.def_privacy(t.value.def_id)
+                                    self.def_privacy(t.def_id())
                                 }
                                 None => {
                                     debug!("privacy - found a method {}",
@@ -432,7 +432,7 @@ fn def_privacy(&self, did: ast::DefId) -> PrivacyResult {
                             match ty::impl_trait_ref(self.tcx, id) {
                                 Some(t) => {
                                     debug!("privacy - impl of trait {}", id);
-                                    self.def_privacy(t.value.def_id)
+                                    self.def_privacy(t.def_id())
                                 }
                                 None => {
                                     debug!("privacy - found a typedef {}",
index 011f86e2810ae5a4de19db0e9a87496f7420f242..3b759b042f2acd83b671bee6189052b7c3344f60 100644 (file)
@@ -18,6 +18,7 @@
 use middle::subst::Subst;
 use middle::ty::{mod, Ty};
 use middle::infer::{mod, InferCtxt};
+use std::rc::Rc;
 use syntax::ast;
 use syntax::codemap::DUMMY_SP;
 use util::ppaux::Repr;
@@ -42,13 +43,14 @@ pub fn impl_can_satisfy(infcx: &InferCtxt,
     let impl1_trait_ref =
         infcx.replace_late_bound_regions_with_fresh_var(DUMMY_SP,
                                                         infer::FnCall,
-                                                        &impl1_trait_ref).0;
+                                                        &*impl1_trait_ref).0;
 
     // Determine whether `impl2` can provide an implementation for those
     // same types.
     let param_env = ty::empty_parameter_environment();
     let mut selcx = SelectionContext::intercrate(infcx, &param_env, infcx.tcx);
-    let obligation = Obligation::new(ObligationCause::dummy(), impl1_trait_ref);
+    let obligation = Obligation::new(ObligationCause::dummy(),
+                                     Rc::new(ty::Binder(impl1_trait_ref)));
     debug!("impl_can_satisfy(obligation={})", obligation.repr(infcx.tcx));
     selcx.evaluate_impl(impl2_def_id, &obligation)
 }
@@ -65,15 +67,15 @@ pub fn impl_is_local(tcx: &ty::ctxt,
     debug!("trait_ref={}", trait_ref.repr(tcx));
 
     // If the trait is local to the crate, ok.
-    if trait_ref.value.def_id.krate == ast::LOCAL_CRATE {
+    if trait_ref.def_id().krate == ast::LOCAL_CRATE {
         debug!("trait {} is local to current crate",
-               trait_ref.value.def_id.repr(tcx));
+               trait_ref.def_id().repr(tcx));
         return true;
     }
 
     // Otherwise, at least one of the input types must be local to the
     // crate.
-    trait_ref.value.input_types().iter().any(|&t| ty_is_local(tcx, t))
+    trait_ref.0.input_types().iter().any(|&t| ty_is_local(tcx, t))
 }
 
 pub fn ty_is_local<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
@@ -143,7 +145,7 @@ pub fn ty_is_local<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
         }
 
         ty::ty_trait(ref tt) => {
-            tt.principal.value.def_id.krate == ast::LOCAL_CRATE
+            tt.principal.def_id().krate == ast::LOCAL_CRATE
         }
 
         // Type parameters may be bound to types that are not local to
index ce59f5285dbc7b94ad08938c561459f1648b601d..e0a40901ee8517d8bac0aca9db79154f91375232 100644 (file)
@@ -347,13 +347,13 @@ fn evaluate_stack<'o>(&mut self,
         // This suffices to allow chains like `FnMut` implemented in
         // terms of `Fn` etc, but we could probably make this more
         // precise still.
-        let input_types = stack.fresh_trait_ref.value.input_types();
+        let input_types = stack.fresh_trait_ref.0.input_types();
         let unbound_input_types = input_types.iter().any(|&t| ty::type_is_fresh(t));
         if
             unbound_input_types &&
              (self.intercrate ||
               stack.iter().skip(1).any(
-                  |prev| stack.fresh_trait_ref.value.def_id == prev.fresh_trait_ref.value.def_id))
+                  |prev| stack.fresh_trait_ref.def_id() == prev.fresh_trait_ref.def_id()))
         {
             debug!("evaluate_stack({}) --> unbound argument, recursion -->  ambiguous",
                    stack.fresh_trait_ref.repr(self.tcx()));
@@ -591,7 +591,7 @@ fn pick_candidate_cache(&self,
         // If the trait refers to any parameters in scope, then use
         // the cache of the param-environment.
         if
-            cache_fresh_trait_ref.value.input_types().iter().any(
+            cache_fresh_trait_ref.0.input_types().iter().any(
                 |&t| ty::type_has_self(t) || ty::type_has_params(t))
         {
             return &self.param_env.selection_cache;
@@ -604,7 +604,7 @@ fn pick_candidate_cache(&self,
         // See the discussion in doc.rs for more details.
         if
             !self.param_env.caller_bounds.is_empty() &&
-            cache_fresh_trait_ref.value.input_types().iter().any(
+            cache_fresh_trait_ref.0.input_types().iter().any(
                 |&t| ty::type_has_ty_infer(t))
         {
             return &self.param_env.selection_cache;
@@ -648,7 +648,7 @@ fn assemble_candidates<'o>(&mut self,
         // Other bounds. Consider both in-scope bounds from fn decl
         // and applicable impls. There is a certain set of precedence rules here.
 
-        match self.tcx().lang_items.to_builtin_kind(obligation.trait_ref.value.def_id) {
+        match self.tcx().lang_items.to_builtin_kind(obligation.trait_ref.def_id()) {
             Some(ty::BoundCopy) => {
                 debug!("obligation self ty is {}",
                        obligation.self_ty().repr(self.tcx()));
@@ -731,7 +731,7 @@ fn assemble_unboxed_closure_candidates(&mut self,
                                            candidates: &mut CandidateSet<'tcx>)
                                            -> Result<(),SelectionError<'tcx>>
     {
-        let kind = match self.fn_family_trait_kind(obligation.trait_ref.value.def_id) {
+        let kind = match self.fn_family_trait_kind(obligation.trait_ref.def_id()) {
             Some(k) => k,
             None => { return Ok(()); }
         };
@@ -779,7 +779,7 @@ fn assemble_fn_pointer_candidates(&mut self,
         // We provide a `Fn` impl for fn pointers. There is no need to provide
         // the other traits (e.g. `FnMut`) since those are provided by blanket
         // impls.
-        if Some(obligation.trait_ref.value.def_id) != self.tcx().lang_items.fn_trait() {
+        if Some(obligation.trait_ref.def_id()) != self.tcx().lang_items.fn_trait() {
             return Ok(());
         }
 
@@ -793,11 +793,11 @@ fn assemble_fn_pointer_candidates(&mut self,
             ty::ty_bare_fn(ty::BareFnTy {
                 unsafety: ast::Unsafety::Normal,
                 abi: abi::Rust,
-                sig: ty::FnSig {
+                sig: ty::Binder(ty::FnSig {
                     inputs: _,
                     output: ty::FnConverging(_),
                     variadic: false
-                }
+                })
             }) => {
                 candidates.vec.push(FnPointerCandidate);
             }
@@ -814,7 +814,7 @@ fn assemble_candidates_from_impls(&mut self,
                                       candidates: &mut CandidateSet<'tcx>)
                                       -> Result<(), SelectionError<'tcx>>
     {
-        let all_impls = self.all_impls(obligation.trait_ref.value.def_id);
+        let all_impls = self.all_impls(obligation.trait_ref.def_id());
         for &impl_def_id in all_impls.iter() {
             self.infcx.probe(|| {
                 match self.match_impl(impl_def_id, obligation) {
@@ -1083,7 +1083,7 @@ fn builtin_bound(&mut self,
                             // bounds are required and thus we must fulfill.
                             let tmp_tr = data.principal_trait_ref_with_self_ty(ty::mk_err());
                             for tr in util::supertraits(self.tcx(), tmp_tr) {
-                                let td = ty::lookup_trait_def(self.tcx(), tr.value.def_id);
+                                let td = ty::lookup_trait_def(self.tcx(), tr.def_id());
 
                                 if td.bounds.builtin_bounds.contains(&bound) {
                                     return Ok(If(Vec::new()))
@@ -1519,15 +1519,15 @@ fn confirm_fn_pointer_candidate(&mut self,
             }
         };
 
-        let arguments_tuple = ty::mk_tup(self.tcx(), sig.inputs.to_vec());
-        let output_type = sig.output.unwrap();
+        let arguments_tuple = ty::mk_tup(self.tcx(), sig.0.inputs.to_vec());
+        let output_type = sig.0.output.unwrap();
         let substs =
             Substs::new_trait(
                 vec![arguments_tuple, output_type],
                 vec![],
                 vec![],
                 self_ty);
-        let trait_ref = Rc::new(ty::bind(ty::TraitRef {
+        let trait_ref = Rc::new(ty::Binder(ty::TraitRef {
             def_id: obligation.trait_ref.def_id(),
             substs: substs,
         }));
@@ -1562,15 +1562,15 @@ fn confirm_unboxed_closure_candidate(&mut self,
         };
 
         let closure_sig = &closure_type.sig;
-        let arguments_tuple = closure_sig.inputs[0];
+        let arguments_tuple = closure_sig.0.inputs[0];
         let substs =
             Substs::new_trait(
                 vec![arguments_tuple.subst(self.tcx(), substs),
-                     closure_sig.output.unwrap().subst(self.tcx(), substs)],
+                     closure_sig.0.output.unwrap().subst(self.tcx(), substs)],
                 vec![],
                 vec![],
                 obligation.self_ty());
-        let trait_ref = Rc::new(ty::bind(ty::TraitRef {
+        let trait_ref = Rc::new(ty::Binder(ty::TraitRef {
             def_id: obligation.trait_ref.def_id(),
             substs: substs,
         }));
index 2daf5453745b51638d58ef0100589c26389701b8..27824ba5c6e77b13b6b0043615692e924927462b 100644 (file)
@@ -274,7 +274,7 @@ pub fn poly_trait_ref_for_builtin_bound<'tcx>(
 {
     match tcx.lang_items.from_builtin_kind(builtin_bound) {
         Ok(def_id) => {
-            Ok(Rc::new(ty::bind(ty::TraitRef {
+            Ok(Rc::new(ty::Binder(ty::TraitRef {
                 def_id: def_id,
                 substs: Substs::empty().with_self_ty(param_ty)
             })))
index a25e4087905dde5bd3e162890f750d87545d9086..a24992e89e35dc632aa7bc7a9c3fd2887d536a6e 100644 (file)
@@ -60,7 +60,7 @@
 use middle::traits::ObligationCause;
 use middle::traits;
 use middle::ty;
-use middle::ty_fold::{mod, TypeFoldable, TypeFolder, HigherRankedFoldable};
+use middle::ty_fold::{mod, TypeFoldable, TypeFolder};
 use util::ppaux::{note_and_explain_region, bound_region_ptr_to_string};
 use util::ppaux::{trait_store_to_string, ty_to_string};
 use util::ppaux::{Repr, UserString};
@@ -908,7 +908,7 @@ pub fn type_escapes_depth(ty: Ty, depth: uint) -> bool {
 pub struct BareFnTy<'tcx> {
     pub unsafety: ast::Unsafety,
     pub abi: abi::Abi,
-    pub sig: FnSig<'tcx>,
+    pub sig: PolyFnSig<'tcx>,
 }
 
 #[deriving(Clone, PartialEq, Eq, Hash, Show)]
@@ -917,7 +917,7 @@ pub struct ClosureTy<'tcx> {
     pub onceness: ast::Onceness,
     pub store: TraitStore,
     pub bounds: ExistentialBounds,
-    pub sig: FnSig<'tcx>,
+    pub sig: PolyFnSig<'tcx>,
     pub abi: abi::Abi,
 }
 
@@ -944,10 +944,6 @@ impl<'tcx> Copy for FnOutput<'tcx> {}
 /// - `inputs` is the list of arguments and their modes.
 /// - `output` is the return type.
 /// - `variadic` indicates whether this is a varidic function. (only true for foreign fns)
-///
-/// Note that a `FnSig` introduces a level of region binding, to
-/// account for late-bound parameters that appear in the types of the
-/// fn's arguments or the fn's return type.
 #[deriving(Clone, PartialEq, Eq, Hash)]
 pub struct FnSig<'tcx> {
     pub inputs: Vec<Ty<'tcx>>,
@@ -955,6 +951,8 @@ pub struct FnSig<'tcx> {
     pub variadic: bool
 }
 
+pub type PolyFnSig<'tcx> = Binder<FnSig<'tcx>>;
+
 #[deriving(Clone, PartialEq, Eq, Hash, Show)]
 pub struct ParamTy {
     pub space: subst::ParamSpace,
@@ -1318,9 +1316,9 @@ impl<'tcx> TyTrait<'tcx> {
     /// you must give *some* self-type. A common choice is `mk_err()`
     /// or some skolemized type.
     pub fn principal_trait_ref_with_self_ty(&self, self_ty: Ty<'tcx>) -> Rc<ty::PolyTraitRef<'tcx>> {
-        Rc::new(ty::bind(ty::TraitRef {
-            def_id: self.principal.value.def_id,
-            substs: self.principal.value.substs.with_self_ty(self_ty),
+        Rc::new(ty::Binder(ty::TraitRef {
+            def_id: self.principal.def_id(),
+            substs: self.principal.substs().with_self_ty(self_ty),
         }))
     }
 }
@@ -1350,19 +1348,19 @@ pub struct TraitRef<'tcx> {
 
 impl<'tcx> PolyTraitRef<'tcx> {
     pub fn self_ty(&self) -> Ty<'tcx> {
-        self.value.self_ty()
+        self.0.self_ty()
     }
 
     pub fn def_id(&self) -> ast::DefId {
-        self.value.def_id
+        self.0.def_id
     }
 
     pub fn substs(&self) -> &Substs<'tcx> {
-        &self.value.substs
+        &self.0.substs
     }
 
     pub fn input_types(&self) -> &[Ty<'tcx>] {
-        self.value.input_types()
+        self.0.input_types()
     }
 }
 
@@ -1373,13 +1371,7 @@ pub fn input_types(&self) -> &[Ty<'tcx>] {
 /// by the binder supplied to it; but a type is not a binder, so you
 /// must introduce an artificial one).
 #[deriving(Clone, PartialEq, Eq, Hash, Show)]
-pub struct Binder<T> {
-    pub value: T
-}
-
-pub fn bind<T>(value: T) -> Binder<T> {
-    Binder { value: value }
-}
+pub struct Binder<T>(pub T);
 
 #[deriving(Clone, PartialEq)]
 pub enum IntVarValue {
@@ -2237,12 +2229,12 @@ fn add_tys(&mut self, tys: &[Ty]) {
         }
     }
 
-    fn add_fn_sig(&mut self, fn_sig: &FnSig) {
+    fn add_fn_sig(&mut self, fn_sig: &PolyFnSig) {
         let mut computation = FlagComputation::new();
 
-        computation.add_tys(fn_sig.inputs[]);
+        computation.add_tys(fn_sig.0.inputs[]);
 
-        if let ty::FnConverging(output) = fn_sig.output {
+        if let ty::FnConverging(output) = fn_sig.0.output {
             computation.add_ty(output);
         }
 
@@ -2385,11 +2377,11 @@ pub fn mk_ctor_fn<'tcx>(cx: &ctxt<'tcx>,
                BareFnTy {
                    unsafety: ast::Unsafety::Normal,
                    abi: abi::Rust,
-                   sig: FnSig {
+                   sig: ty::Binder(FnSig {
                     inputs: input_args,
                     output: ty::FnConverging(output),
                     variadic: false
-                   }
+                   })
                 })
 }
 
@@ -2481,14 +2473,14 @@ pub fn maybe_walk_ty<'tcx>(ty: Ty<'tcx>, f: |Ty<'tcx>| -> bool) {
         }
         ty_tup(ref ts) => { for tt in ts.iter() { maybe_walk_ty(*tt, |x| f(x)); } }
         ty_bare_fn(ref ft) => {
-            for a in ft.sig.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
-            if let ty::FnConverging(output) = ft.sig.output {
+            for a in ft.sig.0.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
+            if let ty::FnConverging(output) = ft.sig.0.output {
                 maybe_walk_ty(output, f);
             }
         }
         ty_closure(ref ft) => {
-            for a in ft.sig.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
-            if let ty::FnConverging(output) = ft.sig.output {
+            for a in ft.sig.0.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
+            if let ty::FnConverging(output) = ft.sig.0.output {
                 maybe_walk_ty(output, f);
             }
         }
@@ -3857,15 +3849,15 @@ pub fn node_id_item_substs<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> ItemSubsts
 
 pub fn fn_is_variadic(fty: Ty) -> bool {
     match fty.sty {
-        ty_bare_fn(ref f) => f.sig.variadic,
-        ty_closure(ref f) => f.sig.variadic,
+        ty_bare_fn(ref f) => f.sig.0.variadic,
+        ty_closure(ref f) => f.sig.0.variadic,
         ref s => {
             panic!("fn_is_variadic() called on non-fn type: {}", s)
         }
     }
 }
 
-pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx FnSig<'tcx> {
+pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx PolyFnSig<'tcx> {
     match fty.sty {
         ty_bare_fn(ref f) => &f.sig,
         ty_closure(ref f) => &f.sig,
@@ -3886,7 +3878,7 @@ pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
 
 // Type accessors for substructures of types
 pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> &'tcx [Ty<'tcx>] {
-    ty_fn_sig(fty).inputs.as_slice()
+    ty_fn_sig(fty).0.inputs.as_slice()
 }
 
 pub fn ty_closure_store(fty: Ty) -> TraitStore {
@@ -3905,8 +3897,8 @@ pub fn ty_closure_store(fty: Ty) -> TraitStore {
 
 pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> {
     match fty.sty {
-        ty_bare_fn(ref f) => f.sig.output,
-        ty_closure(ref f) => f.sig.output,
+        ty_bare_fn(ref f) => f.sig.0.output,
+        ty_closure(ref f) => f.sig.0.output,
         ref s => {
             panic!("ty_fn_ret() called on non-fn type: {}", s)
         }
@@ -4801,7 +4793,7 @@ pub fn impl_trait_ref<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
                                 &Some(ref t) => {
                                     let trait_ref =
                                         (*ty::node_id_to_trait_ref(cx, t.ref_id)).clone();
-                                    Some(Rc::new(ty::bind(trait_ref)))
+                                    Some(Rc::new(ty::Binder(trait_ref)))
                                 }
                                 &None => None
                             }
@@ -5180,7 +5172,7 @@ pub fn predicates_for_trait_ref<'tcx>(tcx: &ctxt<'tcx>,
         trait_def.bounds.trait_bounds
         .iter()
         .map(|bound_trait_ref| {
-            ty::bind(
+            ty::Binder(
                 ty::TraitRef::new(bound_trait_ref.def_id(),
                                   bound_trait_ref.substs().subst(tcx, trait_ref.substs())))
         })
@@ -5515,18 +5507,6 @@ fn fold_substs(&mut self,
             subst::Substs { regions: subst::ErasedRegions,
                             types: substs.types.fold_with(self) }
         }
-
-        fn fold_fn_sig(&mut self,
-                       sig: &ty::FnSig<'tcx>)
-                       -> ty::FnSig<'tcx> {
-            // The binder-id is only relevant to bound regions, which
-            // are erased at trans time.
-            ty::FnSig {
-                inputs: sig.inputs.fold_with(self),
-                output: sig.output.fold_with(self),
-                variadic: sig.variadic,
-            }
-        }
     }
 }
 
@@ -5602,7 +5582,7 @@ pub fn object_region_bounds<'tcx>(tcx: &ctxt<'tcx>,
 
     let opt_trait_ref = opt_principal.map_or(Vec::new(), |principal| {
         let substs = principal.substs().with_self_ty(open_ty);
-        vec!(Rc::new(ty::bind(ty::TraitRef::new(principal.def_id(), substs))))
+        vec!(Rc::new(ty::Binder(ty::TraitRef::new(principal.def_id(), substs))))
     });
 
     let param_bounds = ty::ParamBounds {
@@ -5856,12 +5836,12 @@ pub fn trait_item_of_item(tcx: &ctxt, def_id: ast::DefId)
 
 /// Creates a hash of the type `Ty` which will be the same no matter what crate
 /// context it's calculated within. This is used by the `type_id` intrinsic.
-pub fn hash_crate_independent(tcx: &ctxt, ty: Ty, svh: &Svh) -> u64 {
+pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -> u64 {
     let mut state = sip::SipState::new();
     helper(tcx, ty, svh, &mut state);
     return state.result();
 
-    fn helper(tcx: &ctxt, ty: Ty, svh: &Svh, state: &mut sip::SipState) {
+    fn helper<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh, state: &mut sip::SipState) {
         macro_rules! byte( ($b:expr) => { ($b as u8).hash(state) } );
         macro_rules! hash( ($e:expr) => { $e.hash(state) } );
 
@@ -5894,7 +5874,7 @@ fn helper(tcx: &ctxt, ty: Ty, svh: &Svh, state: &mut sip::SipState) {
         let mt = |state: &mut sip::SipState, mt: mt| {
             mt.mutbl.hash(state);
         };
-        let fn_sig = |state: &mut sip::SipState, sig: &FnSig| {
+        let fn_sig = |state: &mut sip::SipState, sig: &Binder<FnSig<'tcx>>| {
             let sig = anonymize_late_bound_regions(tcx, sig);
             for a in sig.inputs.iter() { helper(tcx, *a, svh, state); }
             if let ty::FnConverging(output) = sig.output {
@@ -5974,7 +5954,7 @@ fn helper(tcx: &ctxt, ty: Ty, svh: &Svh, state: &mut sip::SipState) {
                     hash!(bounds);
 
                     let principal = anonymize_late_bound_regions(tcx, principal);
-                    for subty in principal.substs().types.iter() {
+                    for subty in principal.substs.types.iter() {
                         helper(tcx, *subty, svh, state);
                     }
 
@@ -6065,7 +6045,7 @@ pub fn construct_parameter_environment<'tcx>(
     //
 
     let bounds = generics.to_bounds(tcx, &free_substs);
-    let bounds = liberate_late_bound_regions(tcx, free_id_scope, &bind(bounds)).value;
+    let bounds = liberate_late_bound_regions(tcx, free_id_scope, &ty::Binder(bounds));
 
     //
     // Compute region bounds. For now, these relations are stored in a
@@ -6321,12 +6301,12 @@ pub fn is_identity(&self) -> bool {
 
 /// Replace any late-bound regions bound in `value` with free variants attached to scope-id
 /// `scope_id`.
-pub fn liberate_late_bound_regions<'tcx, HR>(
+pub fn liberate_late_bound_regions<'tcx, T>(
     tcx: &ty::ctxt<'tcx>,
     scope: region::CodeExtent,
-    value: &HR)
-    -> HR
-    where HR : HigherRankedFoldable<'tcx>
+    value: &Binder<T>)
+    -> T
+    where T : TypeFoldable<'tcx> + Repr<'tcx>
 {
     replace_late_bound_regions(
         tcx, value,
@@ -6335,11 +6315,11 @@ pub fn liberate_late_bound_regions<'tcx, HR>(
 
 /// Replace any late-bound regions bound in `value` with `'static`. Useful in trans but also
 /// method lookup and a few other places where precise region relationships are not required.
-pub fn erase_late_bound_regions<'tcx, HR>(
+pub fn erase_late_bound_regions<'tcx, T>(
     tcx: &ty::ctxt<'tcx>,
-    value: &HR)
-    -> HR
-    where HR : HigherRankedFoldable<'tcx>
+    value: &Binder<T>)
+    -> T
+    where T : TypeFoldable<'tcx> + Repr<'tcx>
 {
     replace_late_bound_regions(tcx, value, |_, _| ty::ReStatic).0
 }
@@ -6352,8 +6332,12 @@ pub fn erase_late_bound_regions<'tcx, HR>(
 /// `FnSig`s or `TraitRef`s which are equivalent up to region naming will become
 /// structurally identical.  For example, `for<'a, 'b> fn(&'a int, &'b int)` and
 /// `for<'a, 'b> fn(&'b int, &'a int)` will become identical after anonymization.
-pub fn anonymize_late_bound_regions<'tcx, HR>(tcx: &ctxt<'tcx>, sig: &HR) -> HR
-                                              where HR: HigherRankedFoldable<'tcx> {
+pub fn anonymize_late_bound_regions<'tcx, T>(
+    tcx: &ctxt<'tcx>,
+    sig: &Binder<T>)
+    -> T
+    where T : TypeFoldable<'tcx> + Repr<'tcx>,
+{
     let mut counter = 0;
     replace_late_bound_regions(tcx, sig, |_, db| {
         counter += 1;
@@ -6362,15 +6346,15 @@ pub fn anonymize_late_bound_regions<'tcx, HR>(tcx: &ctxt<'tcx>, sig: &HR) -> HR
 }
 
 /// Replaces the late-bound-regions in `value` that are bound by `value`.
-pub fn replace_late_bound_regions<'tcx, HR, F>(
+pub fn replace_late_bound_regions<'tcx, T, F>(
     tcx: &ty::ctxt<'tcx>,
-    value: &HR,
+    binder: &Binder<T>,
     mut mapf: F)
--> (HR, FnvHashMap<ty::BoundRegion, ty::Region>) where
-    HR : HigherRankedFoldable<'tcx>,
-    F: FnMut(BoundRegion, DebruijnIndex) -> ty::Region,
+    -> (T, FnvHashMap<ty::BoundRegion,ty::Region>)
+    where T : TypeFoldable<'tcx> + Repr<'tcx>,
+          F : FnMut(BoundRegion, DebruijnIndex) -> ty::Region,
 {
-    debug!("replace_late_bound_regions({})", value.repr(tcx));
+    debug!("replace_late_bound_regions({})", binder.repr(tcx));
 
     let mut map = FnvHashMap::new();
     let value = {
@@ -6389,11 +6373,9 @@ pub fn replace_late_bound_regions<'tcx, HR, F>(
             }
         });
 
-        // Note: use `fold_contents` not `fold_with`. If we used
-        // `fold_with`, it would consider the late-bound regions bound
-        // by `value` to be bound, but we want to consider them as
-        // `free`.
-        value.fold_contents(&mut f)
+        // Note: fold the field `0`, not the binder, so that late-bound
+        // regions bound by `binder` are considered free.
+        binder.0.fold_with(&mut f)
     };
     debug!("resulting map: {} value: {}", map, value.repr(tcx));
     (value, map)
@@ -6600,13 +6582,13 @@ fn has_regions_escaping_depth(&self, depth: uint) -> bool {
 
 impl<'tcx,T:RegionEscape> RegionEscape for Binder<T> {
     fn has_regions_escaping_depth(&self, depth: uint) -> bool {
-        self.value.has_regions_escaping_depth(depth + 1)
+        self.0.has_regions_escaping_depth(depth + 1)
     }
 }
 
 impl<T:RegionEscape> Binder<T> {
     pub fn has_bound_regions(&self) -> bool {
-        self.value.has_regions_escaping_depth(0)
+        self.0.has_regions_escaping_depth(0)
     }
 }
 
index da6ddf7461b35e232c5f8cedc1693684631f2230..6d6dc1d426ad6b40a4f3a11d0e02c18c0dee6ded 100644 (file)
@@ -93,8 +93,8 @@ fn fold_substs(&mut self,
     }
 
     fn fold_fn_sig(&mut self,
-                sig: &ty::FnSig<'tcx>)
-                -> ty::FnSig<'tcx> {
+                   sig: &ty::FnSig<'tcx>)
+                   -> ty::FnSig<'tcx> {
         super_fold_fn_sig(self, sig)
     }
 
@@ -183,7 +183,7 @@ fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Vec<T> {
 impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
     fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Binder<T> {
         folder.enter_region_binder();
-        let result = ty::bind(self.value.fold_with(folder));
+        let result = ty::Binder(self.0.fold_with(folder));
         folder.exit_region_binder();
         result
     }
@@ -532,16 +532,6 @@ pub fn super_fold_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
 pub fn super_fold_fn_sig<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
                                                     sig: &ty::FnSig<'tcx>)
                                                     -> ty::FnSig<'tcx>
-{
-    this.enter_region_binder();
-    let result = super_fold_fn_sig_contents(this, sig);
-    this.exit_region_binder();
-    result
-}
-
-pub fn super_fold_fn_sig_contents<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
-                                                             sig: &ty::FnSig<'tcx>)
-                                                             -> ty::FnSig<'tcx>
 {
     ty::FnSig { inputs: sig.inputs.fold_with(this),
                 output: sig.output.fold_with(this),
@@ -696,34 +686,6 @@ pub fn super_fold_item_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
     }
 }
 
-///////////////////////////////////////////////////////////////////////////
-// Higher-ranked things
-
-/// Designates a "binder" for late-bound regions.
-pub trait HigherRankedFoldable<'tcx>: Repr<'tcx> {
-    /// Folds the contents of `self`, ignoring the region binder created
-    /// by `self`.
-    fn fold_contents<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self;
-}
-
-impl<'tcx> HigherRankedFoldable<'tcx> for ty::FnSig<'tcx> {
-    fn fold_contents<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::FnSig<'tcx> {
-        super_fold_fn_sig_contents(folder, self)
-    }
-}
-
-impl<'tcx, T:TypeFoldable<'tcx>+Repr<'tcx>> HigherRankedFoldable<'tcx> for ty::Binder<T> {
-    fn fold_contents<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Binder<T> {
-        ty::bind(self.value.fold_with(folder))
-    }
-}
-
-impl<'tcx, T:HigherRankedFoldable<'tcx>> HigherRankedFoldable<'tcx> for Rc<T> {
-    fn fold_contents<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Rc<T> {
-        Rc::new((**self).fold_contents(folder))
-    }
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // Some sample folders
 
@@ -754,10 +716,6 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
 /// regions (aka "lifetimes") that are bound within a type are not
 /// visited by this folder; only regions that occur free will be
 /// visited by `fld_r`.
-///
-/// (The distinction between "free" and "bound" is represented by
-/// keeping track of each `FnSig` in the lexical context of the
-/// current position of the fold.)
 pub struct RegionFolder<'a, 'tcx: 'a, F> where F: FnMut(ty::Region, uint) -> ty::Region {
     tcx: &'a ty::ctxt<'tcx>,
     current_depth: uint,
index 6c00aa546f3874164bd971f95db58f8a86e451d7..134006bef0b75f088399230813365741e6038750 100644 (file)
 use middle::ty::{ty_unboxed_closure};
 use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
 use middle::ty;
+use middle::ty_fold::TypeFoldable;
 
+use std::collections::HashMap;
+use std::hash::{Hash, Hasher};
 use std::rc::Rc;
 use syntax::abi;
 use syntax::ast_map;
@@ -40,7 +43,7 @@ pub trait Repr<'tcx> for Sized? {
 }
 
 /// Produces a string suitable for showing to the user.
-pub trait UserString<'tcx> {
+pub trait UserString<'tcx> : Repr<'tcx> {
     fn user_string(&self, tcx: &ctxt<'tcx>) -> String;
 }
 
@@ -248,21 +251,12 @@ pub fn vec_map_to_string<T, F>(ts: &[T], f: F) -> String where
     format!("[{}]", tstrs.connect(", "))
 }
 
-pub fn fn_sig_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::FnSig<'tcx>) -> String {
-    format!("fn{} -> {}", typ.inputs.repr(cx), typ.output.repr(cx))
-}
-
-pub fn trait_ref_to_string<'tcx>(cx: &ctxt<'tcx>,
-                                 trait_ref: &ty::TraitRef<'tcx>) -> String {
-    trait_ref.user_string(cx).to_string()
-}
-
 pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
     fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
                                unsafety: ast::Unsafety,
                                abi: abi::Abi,
                                ident: Option<ast::Ident>,
-                               sig: &ty::FnSig<'tcx>)
+                               sig: &ty::PolyFnSig<'tcx>)
                                -> String {
         let mut s = String::new();
         match unsafety {
@@ -336,15 +330,15 @@ fn push_sig_to_string<'tcx>(cx: &ctxt<'tcx>,
                                 s: &mut String,
                                 bra: char,
                                 ket: char,
-                                sig: &ty::FnSig<'tcx>,
+                                sig: &ty::PolyFnSig<'tcx>,
                                 bounds: &str) {
         s.push(bra);
-        let strs = sig.inputs
+        let strs = sig.0.inputs
             .iter()
             .map(|a| ty_to_string(cx, *a))
             .collect::<Vec<_>>();
         s.push_str(strs.connect(", ").as_slice());
-        if sig.variadic {
+        if sig.0.variadic {
             s.push_str(", ...");
         }
         s.push(ket);
@@ -354,7 +348,7 @@ fn push_sig_to_string<'tcx>(cx: &ctxt<'tcx>,
             s.push_str(bounds);
         }
 
-        match sig.output {
+        match sig.0.output {
             ty::FnConverging(t) => {
                 if !ty::type_is_nil(t) {
                    s.push_str(" -> ");
@@ -1013,7 +1007,7 @@ fn repr(&self, tcx: &ctxt<'tcx>) -> String {
 
 impl<'tcx> Repr<'tcx> for ty::FnSig<'tcx> {
     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
-        fn_sig_to_string(tcx, self)
+        format!("fn{} -> {}", self.inputs.repr(tcx), self.output.repr(tcx))
     }
 }
 
@@ -1156,7 +1150,9 @@ fn user_string(&self, tcx: &ctxt) -> String {
     }
 }
 
-impl<'tcx> UserString<'tcx> for ty::PolyTraitRef<'tcx> {
+impl<'tcx, T> UserString<'tcx> for ty::Binder<T>
+    where T : UserString<'tcx> + TypeFoldable<'tcx>
+{
     fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
         // Replace any anonymous late-bound regions with named
         // variants, using gensym'd identifiers, so that we can
@@ -1164,7 +1160,7 @@ fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
         // the output. We'll probably want to tweak this over time to
         // decide just how much information to give.
         let mut names = Vec::new();
-        let (trait_ref, _) = ty::replace_late_bound_regions(tcx, self, |br, debruijn| {
+        let (unbound_value, _) = ty::replace_late_bound_regions(tcx, self, |br, debruijn| {
             ty::ReLateBound(debruijn, match br {
                 ty::BrNamed(_, name) => {
                     names.push(token::get_name(name));
@@ -1181,11 +1177,11 @@ fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
         });
         let names: Vec<_> = names.iter().map(|s| s.get()).collect();
 
-        let trait_ref_str = trait_ref.value.user_string(tcx);
+        let value_str = unbound_value.user_string(tcx);
         if names.len() == 0 {
-            trait_ref_str
+            value_str
         } else {
-            format!("for<{}> {}", names.connect(","), trait_ref_str)
+            format!("for<{}> {}", names.connect(","), value_str)
         }
     }
 }
@@ -1337,6 +1333,20 @@ fn repr(&self, tcx: &ctxt<'tcx>) -> String {
 
 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for ty::Binder<T> {
     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
-        format!("Binder({})", self.value.repr(tcx))
+        format!("Binder({})", self.0.repr(tcx))
+    }
+}
+
+impl<'tcx, S, H, K, V> Repr<'tcx> for HashMap<K,V,H>
+    where K : Hash<S> + Eq + Repr<'tcx>,
+          V : Repr<'tcx>,
+          H : Hasher<S>
+{
+    fn repr(&self, tcx: &ctxt<'tcx>) -> String {
+        format!("HashMap({})",
+                self.iter()
+                    .map(|(k,v)| format!("{} => {}", k.repr(tcx), v.repr(tcx)))
+                    .collect::<Vec<String>>()
+                    .connect(", "))
     }
 }
index 14d36432afaa8df6f5025976a01de220bf76ca89..b2c661cc58aa40ef035d6b9412bb892858e1ce60 100644 (file)
@@ -275,11 +275,11 @@ pub fn t_closure(&self,
             onceness: ast::Many,
             store: ty::RegionTraitStore(region_bound, ast::MutMutable),
             bounds: ty::region_existential_bound(region_bound),
-            sig: ty::FnSig {
+            sig: ty::Binder(ty::FnSig {
                 inputs: input_tys.to_vec(),
                 output: ty::FnConverging(output_ty),
                 variadic: false,
-            },
+            }),
             abi: abi::Rust,
         })
     }
index f1d839e916d564011c99ae8d0beb2d86a5585bcb..b947b1746fcab26b35dfd012cac62ac8ca3595d9 100644 (file)
@@ -282,10 +282,10 @@ pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                               fn_ty: Ty<'tcx>, name: &str) -> ValueRef {
     let (inputs, output, abi, env) = match fn_ty.sty {
         ty::ty_bare_fn(ref f) => {
-            (f.sig.inputs.clone(), f.sig.output, f.abi, None)
+            (f.sig.0.inputs.clone(), f.sig.0.output, f.abi, None)
         }
         ty::ty_closure(ref f) => {
-            (f.sig.inputs.clone(), f.sig.output, f.abi, Some(Type::i8p(ccx)))
+            (f.sig.0.inputs.clone(), f.sig.0.output, f.abi, Some(Type::i8p(ccx)))
         }
         ty::ty_unboxed_closure(closure_did, _, ref substs) => {
             let unboxed_closures = ccx.tcx().unboxed_closures.borrow();
@@ -293,8 +293,8 @@ pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             let function_type = unboxed_closure.closure_type.clone();
             let self_type = self_type_for_unboxed_closure(ccx, closure_did, fn_ty);
             let llenvironment_type = type_of_explicit_arg(ccx, self_type);
-            (function_type.sig.inputs.iter().map(|t| t.subst(ccx.tcx(), substs)).collect(),
-             function_type.sig.output.subst(ccx.tcx(), substs),
+            (function_type.sig.0.inputs.iter().map(|t| t.subst(ccx.tcx(), substs)).collect(),
+             function_type.sig.0.output.subst(ccx.tcx(), substs),
              RustCall,
              Some(llenvironment_type))
         }
@@ -1998,7 +1998,7 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
     let tcx = ccx.tcx();
 
     let result_ty = match ctor_ty.sty {
-        ty::ty_bare_fn(ref bft) => bft.sig.output.unwrap(),
+        ty::ty_bare_fn(ref bft) => bft.sig.0.output.unwrap(),
         _ => ccx.sess().bug(
             format!("trans_enum_variant_constructor: \
                      unexpected ctor return type {}",
@@ -2070,7 +2070,7 @@ fn trans_enum_variant_or_tuple_like_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx
     let ctor_ty = ctor_ty.subst(ccx.tcx(), param_substs);
 
     let result_ty = match ctor_ty.sty {
-        ty::ty_bare_fn(ref bft) => bft.sig.output,
+        ty::ty_bare_fn(ref bft) => bft.sig.0.output,
         _ => ccx.sess().bug(
             format!("trans_enum_variant_or_tuple_like_struct: \
                      unexpected ctor return type {}",
@@ -2439,7 +2439,7 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
     // at either 1 or 2 depending on whether there's an env slot or not
     let mut first_arg_offset = if has_env { 2 } else { 1 };
     let mut attrs = llvm::AttrBuilder::new();
-    let ret_ty = fn_sig.output;
+    let ret_ty = fn_sig.0.output;
 
     // These have an odd calling convention, so we need to manually
     // unpack the input ty's
@@ -2447,15 +2447,15 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
         ty::ty_unboxed_closure(_, _, _) => {
             assert!(abi == RustCall);
 
-            match fn_sig.inputs[0].sty {
+            match fn_sig.0.inputs[0].sty {
                 ty::ty_tup(ref inputs) => inputs.clone(),
                 _ => ccx.sess().bug("expected tuple'd inputs")
             }
         },
         ty::ty_bare_fn(_) if abi == RustCall => {
-            let mut inputs = vec![fn_sig.inputs[0]];
+            let mut inputs = vec![fn_sig.0.inputs[0]];
 
-            match fn_sig.inputs[1].sty {
+            match fn_sig.0.inputs[1].sty {
                 ty::ty_tup(ref t_in) => {
                     inputs.push_all(t_in.as_slice());
                     inputs
@@ -2463,7 +2463,7 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<
                 _ => ccx.sess().bug("expected tuple'd inputs")
             }
         }
-        _ => fn_sig.inputs.clone()
+        _ => fn_sig.0.inputs.clone()
     };
 
     if let ty::FnConverging(ret_ty) = ret_ty {
index 7c2f719611632ba78e8788adf4f67168de9e946d..192b0d6342100e08c79950675a08db8847ecc3d6 100644 (file)
@@ -280,9 +280,9 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
         match bare_fn_ty.sty {
             ty::ty_bare_fn(ty::BareFnTy { unsafety: ast::Unsafety::Normal,
                                           abi: synabi::Rust,
-                                          sig: ty::FnSig { inputs: ref input_tys,
-                                                           output: output_ty,
-                                                           variadic: false }}) =>
+                                          sig: ty::Binder(ty::FnSig { inputs: ref input_tys,
+                                                                      output: output_ty,
+                                                                      variadic: false })}) =>
             {
                 (input_tys, output_ty)
             }
@@ -296,12 +296,12 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
     let tuple_fn_ty = ty::mk_bare_fn(tcx,
                                      ty::BareFnTy { unsafety: ast::Unsafety::Normal,
                                                     abi: synabi::RustCall,
-                                                    sig: ty::FnSig {
+                                                    sig: ty::Binder(ty::FnSig {
                                                         inputs: vec![bare_fn_ty_ref,
                                                                      tuple_input_ty],
                                                         output: output_ty,
                                                         variadic: false
-                                                    }});
+                                                    })});
     debug!("tuple_fn_ty: {}", tuple_fn_ty.repr(tcx));
 
     //
@@ -421,12 +421,12 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>(
             let impl_or_trait_item = ty::impl_or_trait_item(tcx, source_id);
             match impl_or_trait_item {
                 ty::MethodTraitItem(method) => {
-                    let trait_ref = ty::impl_trait_ref(tcx, impl_id).unwrap();
-                    let trait_ref = ty::erase_late_bound_regions(tcx, &trait_ref);
+                    let poly_trait_ref = ty::impl_trait_ref(tcx, impl_id).unwrap();
+                    let trait_ref = ty::erase_late_bound_regions(tcx, &*poly_trait_ref);
 
                     // Compute the first substitution
                     let first_subst =
-                        ty::make_substs_for_receiver_types(tcx, &trait_ref.value, &*method)
+                        ty::make_substs_for_receiver_types(tcx, &trait_ref, &*method)
                         .erase_regions();
 
                     // And compose them
@@ -435,7 +435,7 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>(
                     debug!("trans_fn_with_vtables - default method: \
                             substs = {}, trait_subst = {}, \
                             first_subst = {}, new_subst = {}",
-                           substs.repr(tcx), trait_ref.substs().repr(tcx),
+                           substs.repr(tcx), trait_ref.substs.repr(tcx),
                            first_subst.repr(tcx), new_substs.repr(tcx));
 
                     (true, source_id, new_substs)
@@ -657,8 +657,8 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
     let mut bcx = callee.bcx;
 
     let (abi, ret_ty) = match callee_ty.sty {
-        ty::ty_bare_fn(ref f) => (f.abi, f.sig.output),
-        ty::ty_closure(ref f) => (f.abi, f.sig.output),
+        ty::ty_bare_fn(ref f) => (f.abi, f.sig.0.output),
+        ty::ty_closure(ref f) => (f.abi, f.sig.0.output),
         _ => panic!("expected bare rust fn or closure in trans_call_inner")
     };
 
index 1811388662c45f1ef4e77d897b3b3b582964c3c5..af3daf224e3265afb21e5dc3d440d80189dce8bc 100644 (file)
@@ -658,9 +658,9 @@ pub fn get_wrapper_for_bare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 
     let arena = TypedArena::new();
     let empty_param_substs = Substs::trans_empty();
-    let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.output,
+    let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.0.output,
                           &empty_param_substs, None, &arena);
-    let bcx = init_function(&fcx, true, f.sig.output);
+    let bcx = init_function(&fcx, true, f.sig.0.output);
 
     let args = create_datums_for_fn_args(&fcx,
                                          ty::ty_fn_args(closure_ty)
@@ -676,7 +676,7 @@ pub fn get_wrapper_for_bare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     llargs.extend(args.iter().map(|arg| arg.val));
 
     let retval = Call(bcx, fn_ptr, llargs.as_slice(), None);
-    match f.sig.output {
+    match f.sig.0.output {
         ty::FnConverging(output_type) => {
             if return_type_is_void(ccx, output_type) || fcx.llretslotptr.get().is_some() {
                 RetVoid(bcx);
index 8fcab0a3144d1c84d2682db8a0063281a5131301..96c39b5796ec4ccb7a0f5b010d85350d1195d13d 100644 (file)
@@ -442,7 +442,7 @@ fn get_unique_type_id_of_type<'a>(&mut self, cx: &CrateContext<'a, 'tcx>,
 
                 unique_type_id.push_str(" fn(");
 
-                for &parameter_type in sig.inputs.iter() {
+                for &parameter_type in sig.0.inputs.iter() {
                     let parameter_type_id =
                         self.get_unique_type_id_of_type(cx, parameter_type);
                     let parameter_type_id =
@@ -451,12 +451,12 @@ fn get_unique_type_id_of_type<'a>(&mut self, cx: &CrateContext<'a, 'tcx>,
                     unique_type_id.push(',');
                 }
 
-                if sig.variadic {
+                if sig.0.variadic {
                     unique_type_id.push_str("...");
                 }
 
                 unique_type_id.push_str(")->");
-                match sig.output {
+                match sig.0.output {
                     ty::FnConverging(ret_ty) => {
                         let return_type_id = self.get_unique_type_id_of_type(cx, ret_ty);
                         let return_type_id = self.get_unique_type_id_as_string(return_type_id);
@@ -575,7 +575,7 @@ fn get_unique_type_id_of_closure_type<'a>(&mut self,
             }
         };
 
-        for &parameter_type in sig.inputs.iter() {
+        for &parameter_type in sig.0.inputs.iter() {
             let parameter_type_id =
                 self.get_unique_type_id_of_type(cx, parameter_type);
             let parameter_type_id =
@@ -584,13 +584,13 @@ fn get_unique_type_id_of_closure_type<'a>(&mut self,
             unique_type_id.push(',');
         }
 
-        if sig.variadic {
+        if sig.0.variadic {
             unique_type_id.push_str("...");
         }
 
         unique_type_id.push_str("|->");
 
-        match sig.output {
+        match sig.0.output {
             ty::FnConverging(ret_ty) => {
                 let return_type_id = self.get_unique_type_id_of_type(cx, ret_ty);
                 let return_type_id = self.get_unique_type_id_as_string(return_type_id);
@@ -2787,13 +2787,13 @@ fn slice_layout_is_correct<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
 fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                                       unique_type_id: UniqueTypeId,
-                                      signature: &ty::FnSig<'tcx>,
+                                      signature: &ty::PolyFnSig<'tcx>,
                                       span: Span)
                                       -> MetadataCreationResult {
-    let mut signature_metadata: Vec<DIType> = Vec::with_capacity(signature.inputs.len() + 1);
+    let mut signature_metadata: Vec<DIType> = Vec::with_capacity(signature.0.inputs.len() + 1);
 
     // return type
-    signature_metadata.push(match signature.output {
+    signature_metadata.push(match signature.0.output {
         ty::FnConverging(ret_ty) => match ret_ty.sty {
             ty::ty_tup(ref tys) if tys.is_empty() => ptr::null_mut(),
             _ => type_metadata(cx, ret_ty, span)
@@ -2802,7 +2802,7 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     });
 
     // regular arguments
-    for &argument_type in signature.inputs.iter() {
+    for &argument_type in signature.0.inputs.iter() {
         signature_metadata.push(type_metadata(cx, argument_type, span));
     }
 
@@ -3781,8 +3781,8 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
             output.push_str("fn(");
 
-            if sig.inputs.len() > 0 {
-                for &parameter_type in sig.inputs.iter() {
+            if sig.0.inputs.len() > 0 {
+                for &parameter_type in sig.0.inputs.iter() {
                     push_debuginfo_type_name(cx, parameter_type, true, output);
                     output.push_str(", ");
                 }
@@ -3790,8 +3790,8 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                 output.pop();
             }
 
-            if sig.variadic {
-                if sig.inputs.len() > 0 {
+            if sig.0.variadic {
+                if sig.0.inputs.len() > 0 {
                     output.push_str(", ...");
                 } else {
                     output.push_str("...");
@@ -3800,7 +3800,7 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
             output.push(')');
 
-            match sig.output {
+            match sig.0.output {
                 ty::FnConverging(result_type) if ty::type_is_nil(result_type) => {}
                 ty::FnConverging(result_type) => {
                     output.push_str(" -> ");
@@ -3841,8 +3841,8 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                 }
             };
 
-            if sig.inputs.len() > 0 {
-                for &parameter_type in sig.inputs.iter() {
+            if sig.0.inputs.len() > 0 {
+                for &parameter_type in sig.0.inputs.iter() {
                     push_debuginfo_type_name(cx, parameter_type, true, output);
                     output.push_str(", ");
                 }
@@ -3850,8 +3850,8 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                 output.pop();
             }
 
-            if sig.variadic {
-                if sig.inputs.len() > 0 {
+            if sig.0.variadic {
+                if sig.0.inputs.len() > 0 {
                     output.push_str(", ...");
                 } else {
                     output.push_str("...");
@@ -3860,7 +3860,7 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
             output.push(param_list_closing_char);
 
-            match sig.output {
+            match sig.0.output {
                 ty::FnConverging(result_type) if ty::type_is_nil(result_type) => {}
                 ty::FnConverging(result_type) => {
                     output.push_str(" -> ");
index 0bcca6c80ff0d32723eec81fb453fdc528b68a1d..db44e0ce27197c9a99be286d0625e2f8e381947f 100644 (file)
@@ -318,8 +318,8 @@ fn unsized_info<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
             &ty::UnsizeVtable(ty::TyTrait { ref principal, .. }, _) => {
                 let substs = principal.substs().with_self_ty(unadjusted_ty).erase_regions();
                 let trait_ref =
-                    Rc::new(ty::bind(ty::TraitRef { def_id: principal.def_id(),
-                                                    substs: substs }));
+                    Rc::new(ty::Binder(ty::TraitRef { def_id: principal.def_id(),
+                                                      substs: substs }));
                 let trait_ref = trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs);
                 let box_ty = mk_ty(unadjusted_ty);
                 PointerCast(bcx,
index 615d5467f8464541f1d5c6199305761b40792a6e..d07203199305097d3cf85d48fc7afe301543bb5d 100644 (file)
@@ -22,7 +22,6 @@
 use trans::type_::Type;
 use trans::type_of::*;
 use trans::type_of;
-use middle::ty::FnSig;
 use middle::ty::{mod, Ty};
 use middle::subst::{Subst, Substs};
 use std::cmp;
@@ -41,7 +40,7 @@
 
 struct ForeignTypes<'tcx> {
     /// Rust signature of the function
-    fn_sig: ty::FnSig<'tcx>,
+    fn_sig: ty::PolyFnSig<'tcx>,
 
     /// Adapter object for handling native ABI rules (trust me, you
     /// don't want to know)
@@ -179,7 +178,7 @@ pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 
     // Make sure the calling convention is right for variadic functions
     // (should've been caught if not in typeck)
-    if tys.fn_sig.variadic {
+    if tys.fn_sig.0.variadic {
         assert!(cc == llvm::CCallConv);
     }
 
@@ -386,7 +385,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         debug!("llforeign_ret_ty={}", ccx.tn().type_to_string(llforeign_ret_ty));
 
         if llrust_ret_ty == llforeign_ret_ty {
-            match fn_sig.output {
+            match fn_sig.0.output {
                 ty::FnConverging(result_ty) => {
                     base::store_ty(bcx, llforeign_retval, llretptr, result_ty)
                 }
@@ -632,7 +631,7 @@ unsafe fn build_wrap_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         };
 
         // Push Rust return pointer, using null if it will be unused.
-        let rust_uses_outptr = match tys.fn_sig.output {
+        let rust_uses_outptr = match tys.fn_sig.0.output {
             ty::FnConverging(ret_ty) => type_of::return_uses_outptr(ccx, ret_ty),
             ty::FnDiverging => false
         };
@@ -665,7 +664,7 @@ unsafe fn build_wrap_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                             return_ty={}",
                            ccx.tn().val_to_string(slot),
                            ccx.tn().type_to_string(llrust_ret_ty),
-                           tys.fn_sig.output.repr(tcx));
+                           tys.fn_sig.0.output.repr(tcx));
                     llrust_args.push(slot);
                     return_alloca = Some(slot);
                 }
@@ -680,8 +679,8 @@ unsafe fn build_wrap_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         // Build up the arguments to the call to the rust function.
         // Careful to adapt for cases where the native convention uses
         // a pointer and Rust does not or vice versa.
-        for i in range(0, tys.fn_sig.inputs.len()) {
-            let rust_ty = tys.fn_sig.inputs[i];
+        for i in range(0, tys.fn_sig.0.inputs.len()) {
+            let rust_ty = tys.fn_sig.0.inputs[i];
             let llrust_ty = tys.llsig.llarg_tys[i];
             let rust_indirect = type_of::arg_is_indirect(ccx, rust_ty);
             let llforeign_arg_ty = tys.fn_ty.arg_tys[i];
@@ -826,10 +825,10 @@ pub fn link_name(i: &ast::ForeignItem) -> InternedString {
 /// because foreign functions just plain ignore modes. They also don't pass aggregate values by
 /// pointer like we do.
 fn foreign_signature<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-                               fn_sig: &ty::FnSig<'tcx>, arg_tys: &[Ty<'tcx>])
+                               fn_sig: &ty::PolyFnSig<'tcx>, arg_tys: &[Ty<'tcx>])
                                -> LlvmSignature {
     let llarg_tys = arg_tys.iter().map(|&arg| arg_type_of(ccx, arg)).collect();
-    let (llret_ty, ret_def) = match fn_sig.output {
+    let (llret_ty, ret_def) = match fn_sig.0.output {
         ty::FnConverging(ret_ty) =>
             (type_of::arg_type_of(ccx, ret_ty), !return_type_is_void(ccx, ret_ty)),
         ty::FnDiverging =>
@@ -853,7 +852,7 @@ fn foreign_types_for_fn_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         ty::ty_bare_fn(ref fn_ty) => fn_ty.sig.clone(),
         _ => ccx.sess().bug("foreign_types_for_fn_ty called on non-function type")
     };
-    let llsig = foreign_signature(ccx, &fn_sig, fn_sig.inputs.as_slice());
+    let llsig = foreign_signature(ccx, &fn_sig, fn_sig.0.inputs.as_slice());
     let fn_ty = cabi::compute_abi_info(ccx,
                                        llsig.llarg_tys.as_slice(),
                                        llsig.llret_ty,
@@ -913,7 +912,7 @@ fn lltype_for_fn_from_foreign_types(ccx: &CrateContext, tys: &ForeignTypes) -> T
         llargument_tys.push(llarg_ty);
     }
 
-    if tys.fn_sig.variadic {
+    if tys.fn_sig.0.variadic {
         Type::variadic_func(llargument_tys.as_slice(), &llreturn_ty)
     } else {
         Type::func(llargument_tys.as_slice(), &llreturn_ty)
index 4575d8a41e52a389aea96e8c127dea99ca84bb43..dea095ecaf594c558a39ad752f86d928e8265a69 100644 (file)
@@ -227,8 +227,8 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
     let fty = ty::lookup_item_type(bcx.tcx(), dtor_did).ty.subst(bcx.tcx(), substs);
     let self_ty = match fty.sty {
         ty::ty_bare_fn(ref f) => {
-            assert!(f.sig.inputs.len() == 1);
-            f.sig.inputs[0]
+            assert!(f.sig.0.inputs.len() == 1);
+            f.sig.0.inputs[0]
         }
         _ => bcx.sess().bug(format!("Expected function type, found {}",
                                     bcx.ty_to_string(fty)).as_slice())
index 890652401d7eb11cfe9605be74e14133d2dd8ac7..a6f7c849f4d95ab8e390a7d00573bfda08225a1e 100644 (file)
@@ -150,7 +150,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
     let tcx = bcx.tcx();
 
     let ret_ty = match callee_ty.sty {
-        ty::ty_bare_fn(ref f) => f.sig.output,
+        ty::ty_bare_fn(ref f) => f.sig.0.output,
         _ => panic!("expected bare_fn in trans_intrinsic_call")
     };
     let foreign_item = tcx.map.expect_foreign_item(node);
index b386df85d627eaafcc6f4950d3cc1ffb9a8bbeae..a8f7323b4ae03c64927a5251c272aaeaa27167bd 100644 (file)
@@ -239,8 +239,8 @@ pub fn trans_static_method_callee(bcx: Block,
                                              rcvr_assoc,
                                              Vec::new()));
     debug!("trait_substs={}", trait_substs.repr(bcx.tcx()));
-    let trait_ref = Rc::new(ty::bind(ty::TraitRef { def_id: trait_id,
-                                                    substs: trait_substs }));
+    let trait_ref = Rc::new(ty::Binder(ty::TraitRef { def_id: trait_id,
+                                                      substs: trait_substs }));
     let vtbl = fulfill_obligation(bcx.ccx(),
                                   DUMMY_SP,
                                   trait_ref);
@@ -480,8 +480,8 @@ pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         ty::ty_bare_fn(ref f) if f.abi == Rust || f.abi == RustCall => {
             type_of_rust_fn(ccx,
                             Some(Type::i8p(ccx)),
-                            f.sig.inputs.slice_from(1),
-                            f.sig.output,
+                            f.sig.0.inputs.slice_from(1),
+                            f.sig.0.output,
                             f.abi)
         }
         _ => {
index adc919c91bf36b8556b627d0ff71a81e47c6f809..aa6fd7f0b39417d1ec74bf32554b4d7f88579a40 100644 (file)
@@ -146,16 +146,16 @@ pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>)
         ty::ty_closure(ref f) => {
             type_of_rust_fn(cx,
                             Some(Type::i8p(cx)),
-                            f.sig.inputs.as_slice(),
-                            f.sig.output,
+                            f.sig.0.inputs.as_slice(),
+                            f.sig.0.output,
                             f.abi)
         }
         ty::ty_bare_fn(ref f) => {
             if f.abi == abi::Rust || f.abi == abi::RustCall {
                 type_of_rust_fn(cx,
                                 None,
-                                f.sig.inputs.as_slice(),
-                                f.sig.output,
+                                f.sig.0.inputs.as_slice(),
+                                f.sig.0.output,
                                 f.abi)
             } else {
                 foreign::lltype_for_foreign_fn(cx, fty)
index 1acd5684d169c3f68a0d99fe062d0da924a76e24..d6438c4062e3219b273ffe8328dae0b39501cd44 100644 (file)
@@ -535,7 +535,7 @@ pub fn instantiate_poly_trait_ref<'tcx,AC,RS>(
 {
     let trait_ref = instantiate_trait_ref(this, rscope, &ast_trait_ref.trait_ref, self_ty, allow_eq);
     let trait_ref = (*trait_ref).clone();
-    Rc::new(ty::bind(trait_ref)) // Ugh.
+    Rc::new(ty::Binder(trait_ref)) // Ugh.
 }
 
 /// Instantiates the path for the given trait reference, assuming that it's
@@ -778,12 +778,12 @@ fn ast_ty_to_trait_ref<'tcx,AC,RS>(this: &AC,
         ast::TyPath(ref path, id) => {
             match this.tcx().def_map.borrow().get(&id) {
                 Some(&def::DefTrait(trait_def_id)) => {
-                    return Ok(ty::bind(ast_path_to_trait_ref(this,
-                                                             rscope,
-                                                             trait_def_id,
-                                                             None,
-                                                             path,
-                                                             AllowEqConstraints::Allow)));
+                    return Ok(ty::Binder(ast_path_to_trait_ref(this,
+                                                               rscope,
+                                                               trait_def_id,
+                                                               None,
+                                                               path,
+                                                               AllowEqConstraints::Allow)));
                 }
                 _ => {
                     span_err!(this.tcx().sess, ty.span, E0172, "expected a reference to a trait");
@@ -993,12 +993,12 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
                     def::DefTrait(trait_def_id) => {
                         // N.B. this case overlaps somewhat with
                         // TyObjectSum, see that fn for details
-                        let result = ty::bind(ast_path_to_trait_ref(this,
-                                                                    rscope,
-                                                                    trait_def_id,
-                                                                    None,
-                                                                    path,
-                                                                    AllowEqConstraints::Allow));
+                        let result = ty::Binder(ast_path_to_trait_ref(this,
+                                                                      rscope,
+                                                                      trait_def_id,
+                                                                      None,
+                                                                      path,
+                                                                      AllowEqConstraints::Allow));
                         trait_ref_to_object_type(this, rscope, path.span, result, &[])
                     }
                     def::DefTy(did, _) | def::DefStruct(did) => {
@@ -1050,7 +1050,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
                                 let ty_param_defs = tcx.ty_param_defs.borrow();
                                 let tp_def = &(*ty_param_defs)[did.node];
                                 let assoc_tys = tp_def.bounds.trait_bounds.iter()
-                                    .filter_map(|b| find_assoc_ty(this, &b.value, assoc_ident))
+                                    .filter_map(|b| find_assoc_ty(this, &b.0, assoc_ident))
                                     .collect();
                                 (assoc_tys, token::get_name(tp_def.name).to_string())
                             }
@@ -1278,11 +1278,11 @@ fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>(
     (ty::BareFnTy {
         unsafety: unsafety,
         abi: abi,
-        sig: ty::FnSig {
+        sig: ty::Binder(ty::FnSig {
             inputs: self_and_input_tys,
             output: output_ty,
             variadic: decl.variadic
-        }
+        }),
     }, explicit_self_category_result)
 }
 
@@ -1420,9 +1420,9 @@ pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>(
         store: store,
         bounds: bounds,
         abi: abi,
-        sig: ty::FnSig {inputs: input_tys,
-                        output: output_ty,
-                        variadic: decl.variadic}
+        sig: ty::Binder(ty::FnSig {inputs: input_tys,
+                                   output: output_ty,
+                                   variadic: decl.variadic}),
     }
 }
 
index 6e5fdbfac9fd3e6e102809a9c2c58f45abf42525..2ade3040d6cff52e4b8382ce47c447b09bca0da8 100644 (file)
@@ -129,7 +129,7 @@ fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
 
     // Tuple up the arguments and insert the resulting function type into
     // the `unboxed_closures` table.
-    fn_ty.sig.inputs = vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)];
+    fn_ty.sig.0.inputs = vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.0.inputs)];
 
     debug!("unboxed_closure for {} --> sig={} kind={}",
            expr_def_id.repr(fcx.tcx()),
index 0d07957ba3d97413ab921c6c9b1d906f9c37f75f..8ac58736f54b496a94f07a397b4e43158d2fa6a0 100644 (file)
@@ -16,9 +16,9 @@
 use middle::ty::{mod, Ty};
 use middle::ty::{MethodCall, MethodCallee, MethodObject, MethodOrigin,
                  MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam};
+use middle::ty_fold::TypeFoldable;
 use middle::infer;
 use middle::infer::InferCtxt;
-use middle::ty_fold::HigherRankedFoldable;
 use syntax::ast;
 use syntax::codemap::Span;
 use std::rc::Rc;
@@ -114,7 +114,7 @@ fn confirm(&mut self,
 
         // Create the final `MethodCallee`.
         let fty = ty::mk_bare_fn(self.tcx(), ty::BareFnTy {
-            sig: method_sig,
+            sig: ty::Binder(method_sig),
             unsafety: pick.method_ty.fty.unsafety,
             abi: pick.method_ty.fty.abi.clone(),
         });
@@ -272,7 +272,8 @@ fn fresh_receiver_substs(&mut self,
                                                                  &trait_def.generics,
                                                                  self.infcx().next_ty_var());
 
-                let trait_ref = Rc::new(ty::bind(ty::TraitRef::new(trait_def_id, substs.clone())));
+                let trait_ref =
+                    Rc::new(ty::Binder(ty::TraitRef::new(trait_def_id, substs.clone())));
                 let origin = MethodTypeParam(MethodParam { trait_ref: trait_ref,
                                                            method_num: method_num });
                 (substs, origin)
@@ -388,9 +389,9 @@ fn instantiate_method_sig(&mut self,
         // The binder level here corresponds to the impl.
         let (all_substs, (method_sig, method_generics)) =
             self.replace_late_bound_regions_with_fresh_var(
-                &ty::bind((all_substs,
-                           (pick.method_ty.fty.sig.clone(),
-                            pick.method_ty.generics.clone())))).value;
+                &ty::Binder((all_substs,
+                             (pick.method_ty.fty.sig.clone(),
+                              pick.method_ty.generics.clone()))));
 
         debug!("late-bound lifetimes from impl instantiated, \
                 all_substs={} method_sig={} method_generics={}",
@@ -481,7 +482,7 @@ fn fixup_derefs_on_method_receiver_if_necessary(&self,
             _ => return,
         };
 
-        match sig.inputs[0].sty {
+        match sig.0.inputs[0].sty {
             ty::ty_rptr(_, ty::mt {
                 ty: _,
                 mutbl: ast::MutMutable,
@@ -654,8 +655,8 @@ fn upcast(&mut self,
                     target_trait_def_id.repr(self.tcx()))[]);
     }
 
-    fn replace_late_bound_regions_with_fresh_var<T>(&self, value: &T) -> T
-        where T : HigherRankedFoldable<'tcx>
+    fn replace_late_bound_regions_with_fresh_var<T>(&self, value: &ty::Binder<T>) -> T
+        where T : TypeFoldable<'tcx> + Repr<'tcx>
     {
         self.infcx().replace_late_bound_regions_with_fresh_var(
             self.span, infer::FnCall, value).0
index 14bd0edda1078971536954825202f976585f5cf4..451058e5e21a0b1d73ac363ccbad93041cde3600 100644 (file)
@@ -166,7 +166,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
 
     // Construct a trait-reference `self_ty : Trait<input_tys>`
     let substs = subst::Substs::new_trait(input_types, Vec::new(), assoc_types, self_ty);
-    let trait_ref = Rc::new(ty::bind(ty::TraitRef::new(trait_def_id, substs)));
+    let trait_ref = Rc::new(ty::Binder(ty::TraitRef::new(trait_def_id, substs)));
 
     // Construct an obligation
     let obligation = traits::Obligation::misc(span,
@@ -204,7 +204,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
                                                                        &fn_sig).0;
     let transformed_self_ty = fn_sig.inputs[0];
     let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
-        sig: fn_sig,
+        sig: ty::Binder(fn_sig),
         unsafety: bare_fn_ty.unsafety,
         abi: bare_fn_ty.abi.clone(),
     });
index 452d001fe8aa95fc42d8f577fd734f41b5a52f1d..fc1aa59c4deb3c4851cec7ce73f840fb1cf5e2b6 100644 (file)
@@ -20,7 +20,7 @@
 use middle::traits;
 use middle::ty::{mod, Ty};
 use middle::ty::{MethodObject};
-use middle::ty_fold::HigherRankedFoldable;
+use middle::ty_fold::TypeFoldable;
 use middle::infer;
 use middle::infer::InferCtxt;
 use syntax::ast;
@@ -308,8 +308,7 @@ fn assemble_inherent_candidates_from_object(&mut self,
             let vtable_index =
                 get_method_index(tcx, &*new_trait_ref, trait_ref.clone(), method_num);
 
-            let xform_self_ty =
-                this.xform_self_ty(&m, new_trait_ref.substs());
+            let xform_self_ty = this.xform_self_ty(&m, new_trait_ref.substs());
 
             this.inherent_candidates.push(Candidate {
                 xform_self_ty: xform_self_ty,
@@ -772,7 +771,7 @@ fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>) -> bool {
 
                     // Erase any late-bound regions bound in the impl
                     // which appear in the bounds.
-                    let impl_bounds = self.erase_late_bound_regions(&ty::bind(impl_bounds)).value;
+                    let impl_bounds = self.erase_late_bound_regions(&ty::Binder(impl_bounds));
 
                     // Convert the bounds into obligations.
                     let obligations =
@@ -874,9 +873,10 @@ fn record_static_candidate(&mut self, source: CandidateSource) {
     fn xform_self_ty(&self,
                      method: &Rc<ty::Method<'tcx>>,
                      substs: &subst::Substs<'tcx>)
-                     -> Ty<'tcx> {
+                     -> Ty<'tcx>
+    {
         debug!("xform_self_ty(self_ty={}, substs={})",
-               method.fty.sig.inputs[0].repr(self.tcx()),
+               method.fty.sig.0.inputs[0].repr(self.tcx()),
                substs.repr(self.tcx()));
 
         // It is possible for type parameters or early-bound lifetimes
@@ -909,15 +909,13 @@ fn xform_self_ty(&self,
         }
 
         // Replace early-bound regions and types.
-        let xform_self_ty = method.fty.sig.inputs[0].subst(self.tcx(), substs);
+        let xform_self_ty = method.fty.sig.0.inputs[0].subst(self.tcx(), substs);
 
         // Replace late-bound regions bound in the impl or
-        // where-clause (2 levels of binding).
-        let xform_self_ty =
-            self.erase_late_bound_regions(&ty::bind(ty::bind(xform_self_ty))).value.value;
-
-        // Replace late-bound regions bound in the method (1 level of binding).
-        self.erase_late_bound_regions(&ty::bind(xform_self_ty)).value
+        // where-clause (2 levels of binding) and method (1 level of binding).
+        self.erase_late_bound_regions(
+            &self.erase_late_bound_regions(
+                &ty::Binder(ty::Binder(xform_self_ty))))
     }
 
     fn impl_substs(&self,
@@ -955,8 +953,8 @@ fn impl_substs(&self,
     ///    region got replaced with the same variable, which requires a bit more coordination
     ///    and/or tracking the substitution and
     ///    so forth.
-    fn erase_late_bound_regions<T>(&self, value: &T) -> T
-        where T : HigherRankedFoldable<'tcx>
+    fn erase_late_bound_regions<T>(&self, value: &ty::Binder<T>) -> T
+        where T : TypeFoldable<'tcx> + Repr<'tcx>
     {
         ty::erase_late_bound_regions(self.tcx(), value)
     }
index 1e9f7992fb7423e86e72863c2235ce4af08629b2..18f009fe6c479f56ddfe169bc7bf16c93f3978fd 100644 (file)
@@ -506,7 +506,7 @@ fn visit_item(&mut self, _: &ast::Item) { }
 fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
                       unsafety: ast::Unsafety,
                       unsafety_id: ast::NodeId,
-                      fn_sig: &ty::FnSig<'tcx>,
+                      fn_sig: &ty::PolyFnSig<'tcx>,
                       decl: &ast::FnDecl,
                       fn_id: ast::NodeId,
                       body: &ast::Block,
@@ -723,7 +723,7 @@ fn check_method_body<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
 
     let body_id = method.pe_body().id;
     let fty = liberate_late_bound_regions(
-        ccx.tcx, CodeExtent::from_node_id(body_id), &ty::bind(fty)).value;
+        ccx.tcx, CodeExtent::from_node_id(body_id), &ty::Binder(fty));
     debug!("fty (liberated): {}", fty.repr(ccx.tcx));
 
     check_bare_fn(ccx,
@@ -924,7 +924,7 @@ fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
 
     let infcx = infer::new_infer_ctxt(tcx);
 
-    let trait_to_impl_substs = impl_trait_ref.substs();
+    let trait_to_impl_substs = impl_trait_ref.substs;
 
     // Try to give more informative error messages about self typing
     // mismatches.  Note that any mismatch will also be detected
@@ -975,15 +975,15 @@ fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
         return;
     }
 
-    if impl_m.fty.sig.inputs.len() != trait_m.fty.sig.inputs.len() {
+    if impl_m.fty.sig.0.inputs.len() != trait_m.fty.sig.0.inputs.len() {
         span_err!(tcx.sess, impl_m_span, E0050,
             "method `{}` has {} parameter{} \
              but the declaration in trait `{}` has {}",
             token::get_name(trait_m.name),
-            impl_m.fty.sig.inputs.len(),
-            if impl_m.fty.sig.inputs.len() == 1 {""} else {"s"},
+            impl_m.fty.sig.0.inputs.len(),
+            if impl_m.fty.sig.0.inputs.len() == 1 {""} else {"s"},
             ty::item_path_str(tcx, trait_m.def_id),
-            trait_m.fty.sig.inputs.len());
+            trait_m.fty.sig.0.inputs.len());
         return;
     }
 
@@ -1085,7 +1085,7 @@ fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
     // `Bound<&'a T>`, the lifetime `'a` will be late-bound with a
     // depth of 3 (it is nested within 3 binders: the impl, method,
     // and trait-ref itself). So when we do the liberation, we have
-    // two introduce two `ty::bind` scopes, one for the impl and one
+    // two introduce two `ty::Binder` scopes, one for the impl and one
     // the method.
     //
     // The only late-bounded regions that can possibly appear here are
@@ -1103,7 +1103,7 @@ fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
              liberate_late_bound_regions(
                  tcx,
                  impl_m_body_scope,
-                 &ty::bind(ty::bind(impl_param_def.bounds.clone()))).value.value);
+                 &ty::Binder(ty::Binder(impl_param_def.bounds.clone()))).0);
     for (i, (trait_param_bounds, impl_param_bounds)) in
         trait_bounds.zip(impl_bounds).enumerate()
     {
@@ -1169,7 +1169,7 @@ fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
     let impl_fty = ty::mk_bare_fn(tcx, impl_m.fty.clone());
     let impl_fty = impl_fty.subst(tcx, &impl_to_skol_substs);
     let impl_fty = liberate_late_bound_regions(
-        tcx, impl_m_body_scope, &ty::bind(impl_fty)).value;
+        tcx, impl_m_body_scope, &ty::Binder(impl_fty));
     let trait_fty = ty::mk_bare_fn(tcx, trait_m.fty.clone());
     let trait_fty = trait_fty.subst(tcx, &trait_to_skol_substs);
 
@@ -1289,7 +1289,7 @@ fn check_region_bounds_on_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
             // impl, and the method.
             let impl_bounds =
                 ty::liberate_late_bound_regions(
-                    tcx, impl_m_body_scope, &ty::bind(ty::bind(impl_bounds))).value.value;
+                    tcx, impl_m_body_scope, &ty::Binder(ty::Binder(impl_bounds))).0;
 
             debug!("check_region_bounds_on_impl_method: \
                    trait_param={} \
@@ -2546,13 +2546,13 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                 // HACK(eddyb) ignore self in the definition (see above).
                 check_argument_types(fcx,
                                      sp,
-                                     fty.sig.inputs.slice_from(1),
+                                     fty.sig.0.inputs.slice_from(1),
                                      callee_expr,
                                      args_no_rcvr,
                                      autoref_args,
-                                     fty.sig.variadic,
+                                     fty.sig.0.variadic,
                                      tuple_arguments);
-                fty.sig.output
+                fty.sig.0.output
             }
             _ => {
                 fcx.tcx().sess.span_bug(callee_expr.span,
@@ -2966,11 +2966,11 @@ fn check_call(fcx: &FnCtxt,
         // 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.
-        let error_fn_sig = FnSig {
+        let error_fn_sig = ty::Binder(FnSig {
             inputs: err_args(args.len()),
             output: ty::FnConverging(ty::mk_err()),
             variadic: false
-        };
+        });
 
         let fn_sig = match *fn_sty {
             ty::ty_bare_fn(ty::BareFnTy {ref sig, ..}) |
@@ -5070,7 +5070,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
         fcx.infcx().replace_late_bound_regions_with_fresh_var(
             span,
             infer::FnCall,
-            &ty::bind((polytype.ty, bounds))).0.value;
+            &ty::Binder((polytype.ty, bounds))).0;
 
     debug!("after late-bounds have been replaced: ty_late_bound={}", ty_late_bound.repr(fcx.tcx()));
     debug!("after late-bounds have been replaced: bounds={}", bounds.repr(fcx.tcx()));
@@ -5686,11 +5686,11 @@ fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: uint) -> Ty<'tcx> {
     let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
         unsafety: ast::Unsafety::Unsafe,
         abi: abi::RustIntrinsic,
-        sig: FnSig {
+        sig: ty::Binder(FnSig {
             inputs: inputs,
             output: output,
             variadic: false,
-        }
+        }),
     });
     let i_ty = ty::lookup_item_type(ccx.tcx, local_def(it.id));
     let i_n_tps = i_ty.generics.types.len(subst::FnSpace);
index ad6ba0a1d55710fb53814b889e6e4477fe3935ad..33c015a9a081cba3cf9895cbc97f531cb14bd7d6 100644 (file)
@@ -1181,7 +1181,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
                 // Treat overloaded autoderefs as if an AutoRef adjustment
                 // was applied on the base type, as that is always the case.
                 let fn_sig = ty::ty_fn_sig(method.ty);
-                let self_ty = fn_sig.inputs[0];
+                let self_ty = fn_sig.0.inputs[0];
                 let (m, r) = match self_ty.sty {
                     ty::ty_rptr(r, ref m) => (m.mutbl, r),
                     _ => rcx.tcx().sess.span_bug(deref_expr.span,
@@ -1198,7 +1198,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
                 // Specialized version of constrain_call.
                 type_must_outlive(rcx, infer::CallRcvr(deref_expr.span),
                                   self_ty, r_deref_expr);
-                match fn_sig.output {
+                match fn_sig.0.output {
                     ty::FnConverging(return_type) => {
                         type_must_outlive(rcx, infer::CallReturn(deref_expr.span),
                                           return_type, r_deref_expr);
index 4a10c698f7d1fd956acf046ca3ae7e91037f4384..ff91093ab5f7224f372aafa8ffc38324afe3af8b 100644 (file)
@@ -207,12 +207,12 @@ fn check_object_safety_of_method<'tcx>(tcx: &ty::ctxt<'tcx>,
             }
         };
         let ref sig = method.fty.sig;
-        for &input_ty in sig.inputs[1..].iter() {
+        for &input_ty in sig.0.inputs[1..].iter() {
             if let Some(msg) = check_for_self_ty(input_ty) {
                 msgs.push(msg);
             }
         }
-        if let ty::FnConverging(result_type) = sig.output {
+        if let ty::FnConverging(result_type) = sig.0.output {
             if let Some(msg) = check_for_self_ty(result_type) {
                 msgs.push(msg);
             }
index e11f388b1160d427ef56606e9679d9798917d1d5..a90422cd309745a51c48d8a592288900ed0b9ff9 100644 (file)
@@ -170,8 +170,7 @@ fn check_impl(&mut self,
             // liberated.
             let self_ty = ty::node_id_to_type(fcx.tcx(), item.id);
             let self_ty = self_ty.subst(fcx.tcx(), &fcx.inh.param_env.free_substs);
-            let self_ty = liberate_late_bound_regions(
-                fcx.tcx(), item_scope, &ty::bind(self_ty)).value;
+            let self_ty = liberate_late_bound_regions(fcx.tcx(), item_scope, &ty::Binder(self_ty));
 
             bounds_checker.check_traits_in_ty(self_ty);
 
@@ -186,7 +185,7 @@ fn check_impl(&mut self,
 
             // There are special rules that apply to drop.
             if
-                fcx.tcx().lang_items.drop_trait() == Some(trait_ref.def_id()) &&
+                fcx.tcx().lang_items.drop_trait() == Some(trait_ref.def_id) &&
                 !attr::contains_name(item.attrs.as_slice(), "unsafe_destructor")
             {
                 match self_ty.sty {
@@ -200,7 +199,7 @@ fn check_impl(&mut self,
                 }
             }
 
-            if fcx.tcx().lang_items.copy_trait() == Some(trait_ref.def_id()) {
+            if fcx.tcx().lang_items.copy_trait() == Some(trait_ref.def_id) {
                 // This is checked in coherence.
                 return
             }
@@ -219,10 +218,11 @@ fn check_impl(&mut self,
                 traits::ObligationCause::new(
                     item.span,
                     fcx.body_id,
-                    traits::ItemObligation(trait_ref.def_id()));
+                    traits::ItemObligation(trait_ref.def_id));
 
             // Find the supertrait bounds. This will add `int:Bar`.
-            let predicates = ty::predicates_for_trait_ref(fcx.tcx(), &trait_ref);
+            let poly_trait_ref = ty::Binder(trait_ref);
+            let predicates = ty::predicates_for_trait_ref(fcx.tcx(), &poly_trait_ref);
             for predicate in predicates.into_iter() {
                 fcx.register_predicate(traits::Obligation::new(cause, predicate));
             }
@@ -264,18 +264,18 @@ pub fn new(fcx: &'cx FnCtxt<'cx,'tcx>,
     ///
     /// Note that it does not (currently, at least) check that `A : Copy` (that check is delegated
     /// to the point where impl `A : Trait<B>` is implemented).
-    pub fn check_trait_ref(&mut self, trait_ref: &ty::PolyTraitRef<'tcx>) {
-        let trait_def = ty::lookup_trait_def(self.fcx.tcx(), trait_ref.def_id());
+    pub fn check_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>) {
+        let trait_def = ty::lookup_trait_def(self.fcx.tcx(), trait_ref.def_id);
 
-        let bounds = trait_def.generics.to_bounds(self.tcx(), trait_ref.substs());
+        let bounds = trait_def.generics.to_bounds(self.tcx(), &trait_ref.substs);
         self.fcx.add_obligations_for_parameters(
             traits::ObligationCause::new(
                 self.span,
                 self.fcx.body_id,
-                traits::ItemObligation(trait_ref.def_id())),
+                traits::ItemObligation(trait_ref.def_id)),
             &bounds);
 
-        for &ty in trait_ref.substs().types.iter() {
+        for &ty in trait_ref.substs.types.iter() {
             self.check_traits_in_ty(ty);
         }
     }
index e9a3db1b0e6aa8ef9567e323c73c52332a95d4cc..e79eac90508e9f0ee3f2292e1cb85520dd4a691b 100644 (file)
@@ -477,7 +477,7 @@ fn check_implementations_of_copy(&self) {
             let self_type =
                 ty::liberate_late_bound_regions(tcx,
                                                 item_scope,
-                                                &ty::bind(self_type)).value;
+                                                &ty::Binder(self_type));
 
             debug!("can_type_implement_copy(self_type={})",
                    self_type.repr(tcx));
index 8930ae0116052d154493180d7b9db45ff741f67a..e4d93123a269169f05bd5c2613db0c5e0255ad02 100644 (file)
@@ -1638,8 +1638,8 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     let param_id = trait_id;
 
     let self_trait_ref =
-        Rc::new(ty::bind(ty::TraitRef { def_id: local_def(trait_id),
-                                        substs: (*substs).clone() }));
+        Rc::new(ty::Binder(ty::TraitRef { def_id: local_def(trait_id),
+                                          substs: (*substs).clone() }));
 
     let def = ty::TypeParameterDef {
         space: subst::SelfSpace,
@@ -2155,9 +2155,9 @@ pub fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
         ty::BareFnTy {
             abi: abi,
             unsafety: ast::Unsafety::Unsafe,
-            sig: ty::FnSig {inputs: input_tys,
-                            output: output,
-                            variadic: decl.variadic}
+            sig: ty::Binder(ty::FnSig {inputs: input_tys,
+                                       output: output,
+                                       variadic: decl.variadic}),
         });
     let pty = Polytype {
         generics: ty_generics_for_fn_or_method,
@@ -2209,16 +2209,16 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
         assert!(!ty::type_escapes_depth(required_type, 1));
         let required_type_free =
             ty::liberate_late_bound_regions(
-                crate_context.tcx, body_scope, &ty::bind(required_type)).value;
+                crate_context.tcx, body_scope, &ty::Binder(required_type));
 
         // The "base type" comes from the impl. It may have late-bound
         // regions from the impl or the method.
-        let base_type_free = // liberate impl regions:
-            ty::liberate_late_bound_regions(
-                crate_context.tcx, body_scope, &ty::bind(ty::bind(base_type))).value.value;
-        let base_type_free = // liberate method regions:
-            ty::liberate_late_bound_regions(
-                crate_context.tcx, body_scope, &ty::bind(base_type_free)).value;
+        let base_type_free =
+            ty::liberate_late_bound_regions( // liberate impl regions:
+                crate_context.tcx, body_scope,
+                &ty::liberate_late_bound_regions( // liberate method regions:
+                    crate_context.tcx, body_scope,
+                    &ty::Binder(ty::Binder(base_type))));
 
         debug!("required_type={} required_type_free={} \
                 base_type={} base_type_free={}",
index d55d642f746514709a6616e3a3fb7f3bcb5164cf..5fc2466674ebe61dc9ba1bd5c51a7cf2364b1b6c 100644 (file)
@@ -228,11 +228,11 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
             let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
                 unsafety: ast::Unsafety::Normal,
                 abi: abi::Rust,
-                sig: ty::FnSig {
+                sig: ty::Binder(ty::FnSig {
                     inputs: Vec::new(),
                     output: ty::FnConverging(ty::mk_nil(tcx)),
                     variadic: false
-                }
+                })
             });
 
             require_same_types(tcx, None, false, main_span, main_t, se_ty,
@@ -276,14 +276,14 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
             let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
                 unsafety: ast::Unsafety::Normal,
                 abi: abi::Rust,
-                sig: ty::FnSig {
+                sig: ty::Binder(ty::FnSig {
                     inputs: vec!(
                         ty::mk_int(),
                         ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
                     ),
                     output: ty::FnConverging(ty::mk_int()),
                     variadic: false
-                }
+                }),
             });
 
             require_same_types(tcx, None, false, start_span, start_t, se_ty,
index a70058b977ead451f886f61750b1e92025b991f8..67478e0bfa77eadab2d48057af08363b8a69f06b 100644 (file)
@@ -878,13 +878,13 @@ fn add_constraints_from_substs(&mut self,
     /// Adds constraints appropriate for a function with signature
     /// `sig` appearing in a context with ambient variance `variance`
     fn add_constraints_from_sig(&mut self,
-                                sig: &ty::FnSig<'tcx>,
+                                sig: &ty::PolyFnSig<'tcx>,
                                 variance: VarianceTermPtr<'a>) {
         let contra = self.contravariant(variance);
-        for &input in sig.inputs.iter() {
+        for &input in sig.0.inputs.iter() {
             self.add_constraints_from_ty(input, contra);
         }
-        if let ty::FnConverging(result_type) = sig.output {
+        if let ty::FnConverging(result_type) = sig.0.output {
             self.add_constraints_from_ty(result_type, variance);
         }
     }
index 9509986af4787ae9647da9d96071ce0ffe07dc4d..661d6ec241ade42319c3342065ef803954c6dfcc 100644 (file)
@@ -577,7 +577,7 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
 
 impl<'tcx> Clean<TyParamBound> for ty::PolyTraitRef<'tcx> {
     fn clean(&self, cx: &DocContext) -> TyParamBound {
-        self.value.clean(cx)
+        self.0.clean(cx)
     }
 }
 
@@ -919,7 +919,7 @@ fn clean(&self, cx: &DocContext) -> Type {
     }
 }
 
-impl<'a, 'tcx> Clean<FnDecl> for (ast::DefId, &'a ty::FnSig<'tcx>) {
+impl<'a, 'tcx> Clean<FnDecl> for (ast::DefId, &'a ty::PolyFnSig<'tcx>) {
     fn clean(&self, cx: &DocContext) -> FnDecl {
         let (did, sig) = *self;
         let mut names = if did.node != 0 {
@@ -931,10 +931,10 @@ fn clean(&self, cx: &DocContext) -> FnDecl {
             let _ = names.next();
         }
         FnDecl {
-            output: Return(sig.output.clean(cx)),
+            output: Return(sig.0.output.clean(cx)),
             attrs: Vec::new(),
             inputs: Arguments {
-                values: sig.inputs.iter().map(|t| {
+                values: sig.0.inputs.iter().map(|t| {
                     Argument {
                         type_: t.clean(cx),
                         id: 0,
@@ -1088,14 +1088,14 @@ fn clean(&self, cx: &DocContext) -> Item {
             ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(cx),
                                                self.fty.sig.clone()),
             s => {
-                let sig = ty::FnSig {
-                    inputs: self.fty.sig.inputs[1..].to_vec(),
-                    ..self.fty.sig.clone()
-                };
+                let sig = ty::Binder(ty::FnSig {
+                    inputs: self.fty.sig.0.inputs[1..].to_vec(),
+                    ..self.fty.sig.0.clone()
+                });
                 let s = match s {
                     ty::ByValueExplicitSelfCategory => SelfValue,
                     ty::ByReferenceExplicitSelfCategory(..) => {
-                        match self.fty.sig.inputs[0].sty {
+                        match self.fty.sig.0.inputs[0].sty {
                             ty::ty_rptr(r, mt) => {
                                 SelfBorrowed(r.clean(cx), mt.mutbl.clean(cx))
                             }
@@ -1103,7 +1103,7 @@ fn clean(&self, cx: &DocContext) -> Item {
                         }
                     }
                     ty::ByBoxExplicitSelfCategory => {
-                        SelfExplicit(self.fty.sig.inputs[0].clean(cx))
+                        SelfExplicit(self.fty.sig.0.inputs[0].clean(cx))
                     }
                     ty::StaticExplicitSelfCategory => unreachable!(),
                 };
@@ -1398,7 +1398,7 @@ fn clean(&self, cx: &DocContext) -> Type {
             ty::ty_struct(did, ref substs) |
             ty::ty_enum(did, ref substs) |
             ty::ty_trait(box ty::TyTrait {
-                principal: ty::Binder { value: ty::TraitRef { def_id: did, ref substs } },
+                principal: ty::Binder(ty::TraitRef { def_id: did, ref substs }),
                 .. }) =>
             {
                 let fqn = csearch::get_item_path(cx.tcx(), did);