From 1205fd88df2b87c682f2e98e30ba9e2d8d44d656 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 12 Dec 2014 11:28:35 -0500 Subject: [PATCH] Centralize on using `Binder` to introduce new binding levels, rather than having FnSig carry an implicit binding level. This means that we be more typesafe in general, since things that instantiate bound regions can drop the Binder to reflect that. --- src/librustc/metadata/decoder.rs | 4 +- src/librustc/metadata/tydecode.rs | 14 +- src/librustc/metadata/tyencode.rs | 14 +- src/librustc/middle/astencode.rs | 10 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/fast_reject.rs | 6 +- src/librustc/middle/infer/combine.rs | 74 ++++++++- src/librustc/middle/infer/equate.rs | 15 +- src/librustc/middle/infer/error_reporting.rs | 2 +- src/librustc/middle/infer/glb.rs | 10 +- .../middle/infer/higher_ranked/mod.rs | 139 +++++------------ src/librustc/middle/infer/lub.rs | 10 +- src/librustc/middle/infer/mod.rs | 28 ++-- src/librustc/middle/infer/sub.rs | 10 +- src/librustc/middle/intrinsicck.rs | 4 +- src/librustc/middle/liveness.rs | 1 + src/librustc/middle/privacy.rs | 8 +- src/librustc/middle/traits/coherence.rs | 14 +- src/librustc/middle/traits/select.rs | 34 ++--- src/librustc/middle/traits/util.rs | 2 +- src/librustc/middle/ty.rs | 140 ++++++++---------- src/librustc/middle/ty_fold.rs | 48 +----- src/librustc/util/ppaux.rs | 54 ++++--- src/librustc_driver/test.rs | 4 +- src/librustc_trans/trans/base.rs | 22 +-- src/librustc_trans/trans/callee.rs | 22 +-- src/librustc_trans/trans/closure.rs | 6 +- src/librustc_trans/trans/debuginfo.rs | 40 ++--- src/librustc_trans/trans/expr.rs | 4 +- src/librustc_trans/trans/foreign.rs | 23 ++- src/librustc_trans/trans/glue.rs | 4 +- src/librustc_trans/trans/intrinsic.rs | 2 +- src/librustc_trans/trans/meth.rs | 8 +- src/librustc_trans/trans/type_of.rs | 8 +- src/librustc_typeck/astconv.rs | 38 ++--- src/librustc_typeck/check/closure.rs | 2 +- src/librustc_typeck/check/method/confirm.rs | 19 +-- src/librustc_typeck/check/method/mod.rs | 4 +- src/librustc_typeck/check/method/probe.rs | 28 ++-- src/librustc_typeck/check/mod.rs | 38 ++--- src/librustc_typeck/check/regionck.rs | 4 +- src/librustc_typeck/check/vtable.rs | 4 +- src/librustc_typeck/check/wf.rs | 22 +-- src/librustc_typeck/coherence/mod.rs | 2 +- src/librustc_typeck/collect.rs | 24 +-- src/librustc_typeck/lib.rs | 8 +- src/librustc_typeck/variance.rs | 6 +- src/librustdoc/clean/mod.rs | 22 +-- 48 files changed, 462 insertions(+), 545 deletions(-) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 1b3a6c0e6ba3..0625c50d6721 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -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, 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) diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 3d0b63139e4b..f3d700f013d8 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -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; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index fd13ea57e6be..c6218e6fe947 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -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"); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 3f0e28589fc5..0021533a2bbe 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -887,7 +887,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { 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 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { 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 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { 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 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { fn read_poly_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) -> Rc> { - 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, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 41020df63995..8b0df4e69cd8 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -265,7 +265,7 @@ impl OverloadedCallType { } 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) diff --git a/src/librustc/middle/fast_reject.rs b/src/librustc/middle/fast_reject.rs index 2be5e46fcbb6..5c0d4b4841ee 100644 --- a/src/librustc/middle/fast_reject.rs +++ b/src/librustc/middle/fast_reject.rs @@ -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 { diff --git a/src/librustc/middle/infer/combine.rs b/src/librustc/middle/infer/combine.rs index 1681731005db..82ddbcee5a72 100644 --- a/src/librustc/middle/infer/combine.rs +++ b/src/librustc/middle/infer/combine.rs @@ -195,7 +195,7 @@ pub trait Combine<'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 @@ pub trait Combine<'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 @@ pub trait Combine<'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>> + { + 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 @@ pub trait Combine<'tcx> { } } - fn poly_trait_refs(&self, - a: &ty::PolyTraitRef<'tcx>, - b: &ty::PolyTraitRef<'tcx>) - -> cres<'tcx, ty::PolyTraitRef<'tcx>>; + fn binders(&self, a: &ty::Binder, b: &ty::Binder) -> cres<'tcx, ty::Binder> + 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>(combiner: &C, a: &Self, b: &Self) -> cres<'tcx, Self>; +} + +impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> { + fn combine>(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>(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)) } diff --git a/src/librustc/middle/infer/equate.rs b/src/librustc/middle/infer/equate.rs index 79fbc33f2a1d..2a4d20f4dd37 100644 --- a/src/librustc/middle/infer/equate.rs +++ b/src/librustc/middle/infer/equate.rs @@ -133,17 +133,10 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { } } - fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) - -> cres<'tcx, ty::FnSig<'tcx>> + fn binders(&self, a: &ty::Binder, b: &ty::Binder) -> cres<'tcx, ty::Binder> + 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) } } diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 89d6a7df0509..d1253e0b6976 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -1653,7 +1653,7 @@ impl<'tcx> Resolvable<'tcx> for Rc> { 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) } } diff --git a/src/librustc/middle/infer/glb.rs b/src/librustc/middle/infer/glb.rs index f751931a9412..434be32fe5fa 100644 --- a/src/librustc/middle/infer/glb.rs +++ b/src/librustc/middle/infer/glb.rs @@ -121,13 +121,9 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, '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(&self, a: &ty::Binder, b: &ty::Binder) -> cres<'tcx, ty::Binder> + where T : Combineable<'tcx> + { self.higher_ranked_glb(a, b) } } diff --git a/src/librustc/middle/infer/higher_ranked/mod.rs b/src/librustc/middle/infer/higher_ranked/mod.rs index 93a4d7c2f46d..dcc365fad18e 100644 --- a/src/librustc/middle/infer/higher_ranked/mod.rs +++ b/src/librustc/middle/infer/higher_ranked/mod.rs @@ -11,29 +11,24 @@ //! 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>(combiner: &C, a: &Self, b: &Self) -> cres<'tcx, Self>; -} +use util::ppaux::Repr; pub trait HigherRankedRelations<'tcx> { - fn higher_ranked_sub(&self, a: &T, b: &T) -> cres<'tcx, T> - where T : HigherRankedCombineable<'tcx>; + fn higher_ranked_sub(&self, a: &Binder, b: &Binder) -> cres<'tcx, Binder> + where T : Combineable<'tcx>; - fn higher_ranked_lub(&self, a: &T, b: &T) -> cres<'tcx, T> - where T : HigherRankedCombineable<'tcx>; + fn higher_ranked_lub(&self, a: &Binder, b: &Binder) -> cres<'tcx, Binder> + where T : Combineable<'tcx>; - fn higher_ranked_glb(&self, a: &T, b: &T) -> cres<'tcx, T> - where T : HigherRankedCombineable<'tcx>; + fn higher_ranked_glb(&self, a: &Binder, b: &Binder) -> cres<'tcx, Binder> + where T : Combineable<'tcx>; } trait InferCtxtExt<'tcx> { @@ -47,8 +42,9 @@ trait InferCtxtExt<'tcx> { impl<'tcx,C> HigherRankedRelations<'tcx> for C where C : Combine<'tcx> { - fn higher_ranked_sub(&self, a: &T, b: &T) -> cres<'tcx, T> - where T : HigherRankedCombineable<'tcx> + fn higher_ranked_sub(&self, a: &Binder, b: &Binder) + -> cres<'tcx, Binder> + where T : Combineable<'tcx> { debug!("higher_ranked_sub(a={}, b={})", a.repr(self.tcx()), b.repr(self.tcx())); @@ -74,13 +70,14 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C // 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 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C debug!("higher_ranked_sub: OK result={}", result.repr(self.tcx())); - Ok(result) + Ok(ty::Binder(result)) }); } - fn higher_ranked_lub(&self, a: &T, b: &T) -> cres<'tcx, T> - where T : HigherRankedCombineable<'tcx> + fn higher_ranked_lub(&self, a: &Binder, b: &Binder) -> cres<'tcx, Binder> + 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 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C // 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 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C b.repr(self.tcx()), result1.repr(self.tcx())); - Ok(result1) + Ok(ty::Binder(result1)) }); fn generalize_region(infcx: &InferCtxt, @@ -196,8 +193,8 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C } } - fn higher_ranked_glb(&self, a: &T, b: &T) -> cres<'tcx, T> - where T : HigherRankedCombineable<'tcx> + fn higher_ranked_glb(&self, a: &Binder, b: &Binder) -> cres<'tcx, Binder> + where T : Combineable<'tcx> { debug!("{}.higher_ranked_glb({}, {})", self.tag(), a.repr(self.tcx()), b.repr(self.tcx())); @@ -217,7 +214,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C // 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 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C b.repr(self.tcx()), result1.repr(self.tcx())); - Ok(result1) + Ok(ty::Binder(result1)) }); fn generalize_region(infcx: &InferCtxt, @@ -334,59 +331,6 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C } } -impl<'tcx> HigherRankedCombineable<'tcx> for ty::FnSig<'tcx> { - fn super_combine>(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>> - { - 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>(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) -> Vec { @@ -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 @@ impl<'a,'tcx> InferCtxtExt<'tcx> for InferCtxt<'a,'tcx> { } } -fn skolemize_regions<'a,'tcx,HR>(infcx: &InferCtxt<'a,'tcx>, - value: &HR, - snapshot: &CombinedSnapshot) - -> (HR, FnvHashMap) - 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, snapshot: &CombinedSnapshot) diff --git a/src/librustc/middle/infer/lub.rs b/src/librustc/middle/infer/lub.rs index e142e3dbe443..f4909b288916 100644 --- a/src/librustc/middle/infer/lub.rs +++ b/src/librustc/middle/infer/lub.rs @@ -113,17 +113,13 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> { 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(&self, a: &ty::Binder, b: &ty::Binder) -> cres<'tcx, ty::Binder> + where T : Combineable<'tcx> + { self.higher_ranked_lub(a, b) } } diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index 4eda0d01ebb7..edd5c8b854e1 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -26,7 +26,7 @@ use middle::subst::Substs; 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 syntax::codemap::Span; 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 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { 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(&self, - value: &ty::Binder, - snapshot: &CombinedSnapshot) - -> (T, SkolemizationMap) - where T : TypeFoldable<'tcx> + pub fn skolemize_late_bound_regions(&self, + value: &ty::Binder, + 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 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn trait_ref_to_string(&self, t: &Rc>) -> 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 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, span: Span, lbrct: LateBoundRegionConversionTime, - value: &T) + value: &ty::Binder) -> (T, FnvHashMap) - where T : HigherRankedFoldable<'tcx> + where T : TypeFoldable<'tcx> + Repr<'tcx> { ty::replace_late_bound_regions( self.tcx, diff --git a/src/librustc/middle/infer/sub.rs b/src/librustc/middle/infer/sub.rs index e7b7791cc2a8..2b8adfb7c1ee 100644 --- a/src/librustc/middle/infer/sub.rs +++ b/src/librustc/middle/infer/sub.rs @@ -155,13 +155,9 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, '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(&self, a: &ty::Binder, b: &ty::Binder) -> cres<'tcx, ty::Binder> + where T : Combineable<'tcx> + { self.higher_ranked_sub(a, b) } } diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index acfdf6fefb55..ea19111ce3d6 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -124,8 +124,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> { 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); } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index c76d9bc6b1fa..4df655882b15 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1534,6 +1534,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { .unwrap() .closure_type .sig + .0 .output, _ => ty::ty_fn_ret(fn_ty) } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index b0d62644ca51..67e9d2fee58f 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -257,8 +257,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> { }; 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 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { 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 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { 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 {}", diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index 011f86e2810a..3b759b042f2a 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -18,6 +18,7 @@ use middle::subst; 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, ¶m_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 diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index ce59f5285dbc..e0a40901ee85 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -347,13 +347,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } }; - 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }; 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, })); diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 2daf5453745b..27824ba5c6e7 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -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) }))) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a25e4087905d..a24992e89e35 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -60,7 +60,7 @@ use middle::subst::{mod, Subst, Substs, VecPerParamSpace}; 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>, @@ -955,6 +951,8 @@ pub struct FnSig<'tcx> { pub variadic: bool } +pub type PolyFnSig<'tcx> = Binder>; + #[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> { - 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 type PolyTraitRef<'tcx> = Binder>; 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 @@ impl<'tcx> PolyTraitRef<'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 { - pub value: T -} - -pub fn bind(value: T) -> Binder { - Binder { value: value } -} +pub struct Binder(pub T); #[deriving(Clone, PartialEq)] pub enum IntVarValue { @@ -2237,12 +2229,12 @@ impl FlagComputation { } } - 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 @@ pub fn normalize_ty<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { 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 @@ pub fn hash_crate_independent(tcx: &ctxt, ty: Ty, svh: &Svh) -> u64 { 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>| { 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 @@ pub fn hash_crate_independent(tcx: &ctxt, ty: Ty, svh: &Svh) -> u64 { 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 @@ impl<'tcx> AutoDerefRef<'tcx> { /// 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 + 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 + 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 + 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, mut mapf: F) --> (HR, FnvHashMap) where - HR : HigherRankedFoldable<'tcx>, - F: FnMut(BoundRegion, DebruijnIndex) -> ty::Region, + -> (T, FnvHashMap) + 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 @@ impl<'tcx> RegionEscape for TraitRef<'tcx> { impl<'tcx,T:RegionEscape> RegionEscape for Binder { 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 Binder { pub fn has_bound_regions(&self) -> bool { - self.value.has_regions_escaping_depth(0) + self.0.has_regions_escaping_depth(0) } } diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index da6ddf7461b3..6d6dc1d426ad 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -93,8 +93,8 @@ pub trait TypeFolder<'tcx> { } 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 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec { impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder { fn fold_with>(&self, folder: &mut F) -> ty::Binder { 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>(&self, folder: &mut F) -> Self; -} - -impl<'tcx> HigherRankedFoldable<'tcx> for ty::FnSig<'tcx> { - fn fold_contents>(&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 { - fn fold_contents>(&self, folder: &mut F) -> ty::Binder { - ty::bind(self.value.fold_with(folder)) - } -} - -impl<'tcx, T:HigherRankedFoldable<'tcx>> HigherRankedFoldable<'tcx> for Rc { - fn fold_contents>(&self, folder: &mut F) -> Rc { - Rc::new((**self).fold_contents(folder)) - } -} - /////////////////////////////////////////////////////////////////////////// // Some sample folders @@ -754,10 +716,6 @@ impl<'a, 'tcx, F> TypeFolder<'tcx> for BottomUpFolder<'a, 'tcx, F> where /// 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, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 6c00aa546f38..134006bef0b7 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -23,7 +23,10 @@ use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open}; 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(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, - sig: &ty::FnSig<'tcx>) + sig: &ty::PolyFnSig<'tcx>) -> String { let mut s = String::new(); match unsafety { @@ -336,15 +330,15 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String { 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::>(); s.push_str(strs.connect(", ").as_slice()); - if sig.variadic { + if sig.0.variadic { s.push_str(", ..."); } s.push(ket); @@ -354,7 +348,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String { 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 @@ impl<'tcx> Repr<'tcx> for ty::BareFnTy<'tcx> { 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 @@ impl<'tcx> UserString<'tcx> for ty::BuiltinBounds { } } -impl<'tcx> UserString<'tcx> for ty::PolyTraitRef<'tcx> { +impl<'tcx, T> UserString<'tcx> for ty::Binder + 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 @@ impl<'tcx> UserString<'tcx> for ty::PolyTraitRef<'tcx> { // 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 @@ impl<'tcx> UserString<'tcx> for ty::PolyTraitRef<'tcx> { }); 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 @@ impl<'tcx, A:Repr<'tcx>, B:Repr<'tcx>> Repr<'tcx> for (A,B) { impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for ty::Binder { 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 + where K : Hash + Eq + Repr<'tcx>, + V : Repr<'tcx>, + H : Hasher +{ + fn repr(&self, tcx: &ctxt<'tcx>) -> String { + format!("HashMap({})", + self.iter() + .map(|(k,v)| format!("{} => {}", k.repr(tcx), v.repr(tcx))) + .collect::>() + .connect(", ")) } } diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 14d36432afaa..b2c661cc58aa 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -275,11 +275,11 @@ impl<'a, 'tcx> Env<'a, 'tcx> { 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, }) } diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index f1d839e916d5..b947b1746fca 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -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 { diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 7c2f71961163..192b0d634210 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -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") }; diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index 1811388662c4..af3daf224e32 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -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); diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 8fcab0a3144d..96c39b5796ec 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -442,7 +442,7 @@ impl<'tcx> TypeMap<'tcx> { unique_type_id.push_str(" fn("); - for ¶meter_type in sig.inputs.iter() { + for ¶meter_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 @@ impl<'tcx> TypeMap<'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 @@ impl<'tcx> TypeMap<'tcx> { } }; - for ¶meter_type in sig.inputs.iter() { + for ¶meter_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 @@ impl<'tcx> TypeMap<'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); @@ -2787,13 +2787,13 @@ fn vec_slice_metadata<'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 = Vec::with_capacity(signature.inputs.len() + 1); + let mut signature_metadata: Vec = 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 ¶meter_type in sig.inputs.iter() { + if sig.0.inputs.len() > 0 { + for ¶meter_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 ¶meter_type in sig.inputs.iter() { + if sig.0.inputs.len() > 0 { + for ¶meter_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(" -> "); diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 0bcca6c80ff0..db44e0ce2719 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -318,8 +318,8 @@ fn apply_adjustments<'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, diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs index 615d5467f846..d07203199305 100644 --- a/src/librustc_trans/trans/foreign.rs +++ b/src/librustc_trans/trans/foreign.rs @@ -22,7 +22,6 @@ use trans::machine; 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 @@ use util::ppaux::Repr; 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 @@ pub fn trans_rust_fn_with_foreign_abi<'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 @@ pub fn trans_rust_fn_with_foreign_abi<'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 @@ pub fn trans_rust_fn_with_foreign_abi<'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) diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs index 4575d8a41e52..dea095ecaf59 100644 --- a/src/librustc_trans/trans/glue.rs +++ b/src/librustc_trans/trans/glue.rs @@ -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()) diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 890652401d7e..a6f7c849f4d9 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -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); diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index b386df85d627..a8f7323b4ae0 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -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) } _ => { diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index adc919c91bf3..aa6fd7f0b394 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -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) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 1acd5684d169..d6438c4062e3 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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}), } } diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 6e5fdbfac9fd..2ade3040d6cf 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -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()), diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 0d07957ba3d9..8ac58736f54b 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -16,9 +16,9 @@ use middle::traits; 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 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { // 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 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { &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 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { // 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 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { _ => 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 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { target_trait_def_id.repr(self.tcx()))[]); } - fn replace_late_bound_regions_with_fresh_var(&self, value: &T) -> T - where T : HigherRankedFoldable<'tcx> + fn replace_late_bound_regions_with_fresh_var(&self, value: &ty::Binder) -> T + where T : TypeFoldable<'tcx> + Repr<'tcx> { self.infcx().replace_late_bound_regions_with_fresh_var( self.span, infer::FnCall, value).0 diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 14bd0edda107..451058e5e21a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -166,7 +166,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, // Construct a trait-reference `self_ty : Trait` 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(), }); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 452d001fe8aa..fc1aa59c4deb 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -20,7 +20,7 @@ use middle::subst::Subst; 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 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { 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 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { // 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 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { fn xform_self_ty(&self, method: &Rc>, 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 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } // 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 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { /// 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(&self, value: &T) -> T - where T : HigherRankedFoldable<'tcx> + fn erase_late_bound_regions(&self, value: &ty::Binder) -> T + where T : TypeFoldable<'tcx> + Repr<'tcx> { ty::erase_late_bound_regions(self.tcx(), value) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1e9f7992fb74..18f009fe6c47 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -506,7 +506,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> { 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 compare_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_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, // 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 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { 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); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index ad6ba0a1d557..33c015a9a081 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -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); diff --git a/src/librustc_typeck/check/vtable.rs b/src/librustc_typeck/check/vtable.rs index 4a10c698f7d1..ff91093ab5f7 100644 --- a/src/librustc_typeck/check/vtable.rs +++ b/src/librustc_typeck/check/vtable.rs @@ -207,12 +207,12 @@ fn check_object_safety_inner<'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); } diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index e11f388b1160..a90422cd3097 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -170,8 +170,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { // 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 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { // 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 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } } - 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 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { 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 @@ impl<'cx,'tcx> BoundsChecker<'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` 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); } } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index e9a3db1b0e6a..e79eac90508e 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -477,7 +477,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { 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)); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8930ae011605..e4d93123a269 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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={}", diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index d55d642f7465..5fc2466674eb 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -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, diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index a70058b977ea..67478e0bfa77 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -878,13 +878,13 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { /// 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); } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 9509986af478..661d6ec241ad 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -577,7 +577,7 @@ impl Clean for ty::BuiltinBound { impl<'tcx> Clean for ty::PolyTraitRef<'tcx> { fn clean(&self, cx: &DocContext) -> TyParamBound { - self.value.clean(cx) + self.0.clean(cx) } } @@ -919,7 +919,7 @@ impl<'tcx> Clean for ty::FnOutput<'tcx> { } } -impl<'a, 'tcx> Clean for (ast::DefId, &'a ty::FnSig<'tcx>) { +impl<'a, 'tcx> Clean 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 @@ impl<'a, 'tcx> Clean for (ast::DefId, &'a ty::FnSig<'tcx>) { 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 @@ impl<'tcx> Clean for ty::Method<'tcx> { 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 @@ impl<'tcx> Clean for ty::Method<'tcx> { } } 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 @@ impl<'tcx> Clean for ty::Ty<'tcx> { 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);