(index<- )        ./librustc/middle/typeck/infer/mod.rs

    git branch:    * master           5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
    modified:    Fri May  9 13:02:28 2014
   1  // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
   2  // file at the top-level directory of this distribution and at
   3  // http://rust-lang.org/COPYRIGHT.
   4  //
   5  // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
   6  // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
   7  // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
   8  // option. This file may not be copied, modified, or distributed
   9  // except according to those terms.
  10  
  11  /*! See doc.rs for documentation */
  12  
  13  #![allow(non_camel_case_types)]
  14  
  15  pub use middle::ty::IntVarValue;
  16  pub use middle::typeck::infer::resolve::resolve_and_force_all_but_regions;
  17  pub use middle::typeck::infer::resolve::{force_all, not_regions};
  18  pub use middle::typeck::infer::resolve::{force_ivar};
  19  pub use middle::typeck::infer::resolve::{force_tvar, force_rvar};
  20  pub use middle::typeck::infer::resolve::{resolve_ivar, resolve_all};
  21  pub use middle::typeck::infer::resolve::{resolve_nested_tvar};
  22  pub use middle::typeck::infer::resolve::{resolve_rvar};
  23  
  24  use collections::HashMap;
  25  use collections::SmallIntMap;
  26  use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, Vid};
  27  use middle::ty;
  28  use middle::ty_fold;
  29  use middle::ty_fold::TypeFolder;
  30  use middle::typeck::check::regionmanip::replace_late_bound_regions_in_fn_sig;
  31  use middle::typeck::infer::coercion::Coerce;
  32  use middle::typeck::infer::combine::{Combine, CombineFields, eq_tys};
  33  use middle::typeck::infer::region_inference::{RegionVarBindings};
  34  use middle::typeck::infer::resolve::{resolver};
  35  use middle::typeck::infer::sub::Sub;
  36  use middle::typeck::infer::lub::Lub;
  37  use middle::typeck::infer::to_str::InferStr;
  38  use middle::typeck::infer::unify::{ValsAndBindings, Root};
  39  use middle::typeck::infer::error_reporting::ErrorReporting;
  40  use std::cell::{Cell, RefCell};
  41  use std::rc::Rc;
  42  use syntax::ast::{MutImmutable, MutMutable};
  43  use syntax::ast;
  44  use syntax::codemap;
  45  use syntax::codemap::Span;
  46  use syntax::owned_slice::OwnedSlice;
  47  use util::common::indent;
  48  use util::ppaux::{bound_region_to_str, ty_to_str, trait_ref_to_str, Repr};
  49  
  50  pub mod doc;
  51  pub mod macros;
  52  pub mod combine;
  53  pub mod glb;
  54  pub mod lattice;
  55  pub mod lub;
  56  pub mod region_inference;
  57  pub mod resolve;
  58  pub mod sub;
  59  pub mod to_str;
  60  pub mod unify;
  61  pub mod coercion;
  62  pub mod error_reporting;
  63  
  64  pub type Bound<T> = Option<T>;
  65  
  66  #[deriving(Clone)]
  67  pub struct Bounds<T> {
  68      lb: Bound<T>,
  69      ub: Bound<T>
  70  }
  71  
  72  pub type cres<T> = Result<T,ty::type_err>// "combine result"
  73  pub type ures = cres<()>; // "unify result"
  74  pub type fres<T> = Result<T, fixup_err>// "fixup result"
  75  pub type CoerceResult = cres<Option<ty::AutoAdjustment>>;
  76  
  77  pub struct InferCtxt<'a> {
  78      pub tcx: &'a ty::ctxt,
  79  
  80      // We instantiate ValsAndBindings with bounds<ty::t> because the
  81      // types that might instantiate a general type variable have an
  82      // order, represented by its upper and lower bounds.
  83      pub ty_var_bindings: RefCell<ValsAndBindings<ty::TyVid, Bounds<ty::t>>>,
  84      pub ty_var_counter: Cell<uint>,
  85  
  86      // Map from integral variable to the kind of integer it represents
  87      pub int_var_bindings: RefCell<ValsAndBindings<ty::IntVid,
  88                                                Option<IntVarValue>>>,
  89      pub int_var_counter: Cell<uint>,
  90  
  91      // Map from floating variable to the kind of float it represents
  92      pub float_var_bindings: RefCell<ValsAndBindings<ty::FloatVid,
  93                                                  Option<ast::FloatTy>>>,
  94      pub float_var_counter: Cell<uint>,
  95  
  96      // For region variables.
  97      pub region_vars: RegionVarBindings<'a>,
  98  }
  99  
 100  /// Why did we require that the two types be related?
 101  ///
 102  /// See `error_reporting.rs` for more details
 103  #[deriving(Clone)]
 104  pub enum TypeOrigin {
 105      // Not yet categorized in a better way
 106      Misc(Span),
 107  
 108      // Checking that method of impl is compatible with trait
 109      MethodCompatCheck(Span),
 110  
 111      // Checking that this expression can be assigned where it needs to be
 112      // FIXME(eddyb) #11161 is the original Expr required?
 113      ExprAssignable(Span),
 114  
 115      // Relating trait refs when resolving vtables
 116      RelateTraitRefs(Span),
 117  
 118      // Relating trait refs when resolving vtables
 119      RelateSelfType(Span),
 120  
 121      // Computing common supertype in a match expression
 122      MatchExpression(Span),
 123  
 124      // Computing common supertype in an if expression
 125      IfExpression(Span),
 126  }
 127  
 128  /// See `error_reporting.rs` for more details
 129  #[deriving(Clone)]
 130  pub enum ValuePairs {
 131      Types(ty::expected_found<ty::t>),
 132      TraitRefs(ty::expected_found<Rc<ty::TraitRef>>),
 133  }
 134  
 135  /// The trace designates the path through inference that we took to
 136  /// encounter an error or subtyping constraint.
 137  ///
 138  /// See `error_reporting.rs` for more details.
 139  #[deriving(Clone)]
 140  pub struct TypeTrace {
 141      origin: TypeOrigin,
 142      values: ValuePairs,
 143  }
 144  
 145  /// The origin of a `r1 <= r2` constraint.
 146  ///
 147  /// See `error_reporting.rs` for more details
 148  #[deriving(Clone)]
 149  pub enum SubregionOrigin {
 150      // Arose from a subtyping relation
 151      Subtype(TypeTrace),
 152  
 153      // Stack-allocated closures cannot outlive innermost loop
 154      // or function so as to ensure we only require finite stack
 155      InfStackClosure(Span),
 156  
 157      // Invocation of closure must be within its lifetime
 158      InvokeClosure(Span),
 159  
 160      // Dereference of reference must be within its lifetime
 161      DerefPointer(Span),
 162  
 163      // Closure bound must not outlive captured free variables
 164      FreeVariable(Span, ast::NodeId),
 165  
 166      // Index into slice must be within its lifetime
 167      IndexSlice(Span),
 168  
 169      // When casting `&'a T` to an `&'b Trait` object,
 170      // relating `'a` to `'b`
 171      RelateObjectBound(Span),
 172  
 173      // Creating a pointer `b` to contents of another reference
 174      Reborrow(Span),
 175  
 176      // Creating a pointer `b` to contents of an upvar
 177      ReborrowUpvar(Span, ty::UpvarId),
 178  
 179      // (&'a &'b T) where a >= b
 180      ReferenceOutlivesReferent(ty::t, Span),
 181  
 182      // A `ref b` whose region does not enclose the decl site
 183      BindingTypeIsNotValidAtDecl(Span),
 184  
 185      // Regions appearing in a method receiver must outlive method call
 186      CallRcvr(Span),
 187  
 188      // Regions appearing in a function argument must outlive func call
 189      CallArg(Span),
 190  
 191      // Region in return type of invoked fn must enclose call
 192      CallReturn(Span),
 193  
 194      // Region resulting from a `&` expr must enclose the `&` expr
 195      AddrOf(Span),
 196  
 197      // An auto-borrow that does not enclose the expr where it occurs
 198      AutoBorrow(Span),
 199  }
 200  
 201  /// Reasons to create a region inference variable
 202  ///
 203  /// See `error_reporting.rs` for more details
 204  #[deriving(Clone)]
 205  pub enum RegionVariableOrigin {
 206      // Region variables created for ill-categorized reasons,
 207      // mostly indicates places in need of refactoring
 208      MiscVariable(Span),
 209  
 210      // Regions created by a `&P` or `[...]` pattern
 211      PatternRegion(Span),
 212  
 213      // Regions created by `&` operator
 214      AddrOfRegion(Span),
 215  
 216      // Regions created by `&[...]` literal
 217      AddrOfSlice(Span),
 218  
 219      // Regions created as part of an autoref of a method receiver
 220      Autoref(Span),
 221  
 222      // Regions created as part of an automatic coercion
 223      Coercion(TypeTrace),
 224  
 225      // Region variables created as the values for early-bound regions
 226      EarlyBoundRegion(Span, ast::Name),
 227  
 228      // Region variables created for bound regions
 229      // in a function or method that is called
 230      LateBoundRegion(Span, ty::BoundRegion),
 231  
 232      // Region variables created for bound regions
 233      // when doing subtyping/lub/glb computations
 234      BoundRegionInFnType(Span, ty::BoundRegion),
 235  
 236      UpvarRegion(ty::UpvarId, Span),
 237  
 238      BoundRegionInCoherence(ast::Name),
 239  }
 240  
 241  pub enum fixup_err {
 242      unresolved_int_ty(IntVid),
 243      unresolved_ty(TyVid),
 244      cyclic_ty(TyVid),
 245      unresolved_region(RegionVid),
 246      region_var_bound_by_region_var(RegionVid, RegionVid)
 247  }
 248  
 249  pub fn fixup_err_to_str(ffixup_err) -> ~str {
 250      match f {
 251        unresolved_int_ty(_) => "unconstrained integral type".to_owned(),
 252        unresolved_ty(_) => "unconstrained type".to_owned(),
 253        cyclic_ty(_) => "cyclic type of infinite size".to_owned(),
 254        unresolved_region(_) => "unconstrained region".to_owned(),
 255        region_var_bound_by_region_var(r1, r2) => {
 256          format!("region var {:?} bound by another region var {:?}; this is \
 257                a bug in rustc", r1, r2)
 258        }
 259      }
 260  }
 261  
 262  fn new_ValsAndBindings<V:Clone,T:Clone>() -> ValsAndBindings<V, T> {
 263      ValsAndBindings {
 264          vals: SmallIntMap::new(),
 265          bindings: Vec::new()
 266      }
 267  }
 268  
 269  pub fn new_infer_ctxt<'a>(tcx: &'a ty::ctxt) -> InferCtxt<'a> {
 270      InferCtxt {
 271          tcx: tcx,
 272  
 273          ty_var_bindings: RefCell::new(new_ValsAndBindings()),
 274          ty_var_counter: Cell::new(0),
 275  
 276          int_var_bindings: RefCell::new(new_ValsAndBindings()),
 277          int_var_counter: Cell::new(0),
 278  
 279          float_var_bindings: RefCell::new(new_ValsAndBindings()),
 280          float_var_counter: Cell::new(0),
 281  
 282          region_vars: RegionVarBindings(tcx),
 283      }
 284  }
 285  
 286  pub fn common_supertype(cx: &InferCtxt,
 287                          originTypeOrigin,
 288                          a_is_expected: bool,
 289                          aty::t,
 290                          bty::t)
 291                          -> ty::t {
 292      /*!
 293       * Computes the least upper-bound of `a` and `b`. If this is
 294       * not possible, reports an error and returns ty::err.
 295       */
 296  
 297      debug!("common_supertype({}, {})", a.inf_str(cx), b.inf_str(cx));
 298  
 299      let trace = TypeTrace {
 300          origin: origin,
 301          values: Types(expected_found(a_is_expected, a, b))
 302      };
 303  
 304      let result = cx.commit(|| cx.lub(a_is_expected, trace.clone()).tys(a, b));
 305      match result {
 306          Ok(t) => t,
 307          Err(ref err) => {
 308              cx.report_and_explain_type_error(trace, err);
 309              ty::mk_err()
 310          }
 311      }
 312  }
 313  
 314  pub fn mk_subty(cx: &InferCtxt,
 315                  a_is_expected: bool,
 316                  originTypeOrigin,
 317                  aty::t,
 318                  bty::t)
 319               -> ures {
 320      debug!("mk_subty({} <: {})", a.inf_str(cx), b.inf_str(cx));
 321      indent(|| {
 322          cx.commit(|| {
 323              let trace = TypeTrace {
 324                  origin: origin,
 325                  values: Types(expected_found(a_is_expected, a, b))
 326              };
 327              cx.sub(a_is_expected, trace).tys(a, b)
 328          })
 329      }).to_ures()
 330  }
 331  
 332  pub fn can_mk_subty(cx: &InferCtxt, aty::t, bty::t) -> ures {
 333      debug!("can_mk_subty({} <: {})", a.inf_str(cx), b.inf_str(cx));
 334      indent(|| {
 335          cx.probe(|| {
 336              let trace = TypeTrace {
 337                  origin: Misc(codemap::DUMMY_SP),
 338                  values: Types(expected_found(true, a, b))
 339              };
 340              cx.sub(true, trace).tys(a, b)
 341          })
 342      }).to_ures()
 343  }
 344  
 345  pub fn mk_subr(cx: &InferCtxt,
 346                 _a_is_expected: bool,
 347                 originSubregionOrigin,
 348                 aty::Region,
 349                 bty::Region) {
 350      debug!("mk_subr({} <: {})", a.inf_str(cx), b.inf_str(cx));
 351      cx.region_vars.start_snapshot();
 352      cx.region_vars.make_subregion(origin, a, b);
 353      cx.region_vars.commit();
 354  }
 355  
 356  pub fn mk_eqty(cx: &InferCtxt,
 357                 a_is_expected: bool,
 358                 originTypeOrigin,
 359                 aty::t,
 360                 bty::t)
 361              -> ures {
 362      debug!("mk_eqty({} <: {})", a.inf_str(cx), b.inf_str(cx));
 363      indent(|| {
 364          cx.commit(|| {
 365              let trace = TypeTrace {
 366                  origin: origin,
 367                  values: Types(expected_found(a_is_expected, a, b))
 368              };
 369              let suber = cx.sub(a_is_expected, trace);
 370              eq_tys(&suber, a, b)
 371          })
 372      }).to_ures()
 373  }
 374  
 375  pub fn mk_sub_trait_refs(cx: &InferCtxt,
 376                           a_is_expected: bool,
 377                           originTypeOrigin,
 378                           aRc<ty::TraitRef>,
 379                           bRc<ty::TraitRef>)
 380      -> ures
 381  {
 382      debug!("mk_sub_trait_refs({} <: {})",
 383             a.inf_str(cx), b.inf_str(cx));
 384      indent(|| {
 385          cx.commit(|| {
 386              let trace = TypeTrace {
 387                  origin: origin,
 388                  values: TraitRefs(expected_found(a_is_expected, a.clone(), b.clone()))
 389              };
 390              let suber = cx.sub(a_is_expected, trace);
 391              suber.trait_refs(&*a, &*b)
 392          })
 393      }).to_ures()
 394  }
 395  
 396  fn expected_found<T>(a_is_expected: bool,
 397                       aT,
 398                       bT) -> ty::expected_found<T> {
 399      if a_is_expected {
 400          ty::expected_found {expected: a, found: b}
 401      } else {
 402          ty::expected_found {expected: b, found: a}
 403      }
 404  }
 405  
 406  pub fn mk_coercety(cx: &InferCtxt,
 407                     a_is_expected: bool,
 408                     originTypeOrigin,
 409                     aty::t,
 410                     bty::t)
 411                  -> CoerceResult {
 412      debug!("mk_coercety({} -> {})", a.inf_str(cx), b.inf_str(cx));
 413      indent(|| {
 414          cx.commit(|| {
 415              let trace = TypeTrace {
 416                  origin: origin,
 417                  values: Types(expected_found(a_is_expected, a, b))
 418              };
 419              Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
 420          })
 421      })
 422  }
 423  
 424  // See comment on the type `resolve_state` below
 425  pub fn resolve_type(cx: &InferCtxt,
 426                      aty::t,
 427                      modes: uint)
 428                   -> fres<ty::t> {
 429      let mut resolver = resolver(cx, modes);
 430      resolver.resolve_type_chk(a)
 431  }
 432  
 433  pub fn resolve_region(cx: &InferCtxt, rty::Region, modes: uint)
 434                     -> fres<ty::Region> {
 435      let mut resolver = resolver(cx, modes);
 436      resolver.resolve_region_chk(r)
 437  }
 438  
 439  trait then {
 440      fn then<T:Clone>(&self, f: || -> Result<T,ty::type_err>)
 441          -> Result<T,ty::type_err>;
 442  }
 443  
 444  impl then for ures {
 445      fn then<T:Clone>(&self, f|| -> Result<T,ty::type_err>)
 446          -> Result<T,ty::type_err> {
 447          self.and_then(|_i| f())
 448      }
 449  }
 450  
 451  trait ToUres {
 452      fn to_ures(&self) -> ures;
 453  }
 454  
 455  impl<T> ToUres for cres<T> {
 456      fn to_ures(&self) -> ures {
 457          match *self {
 458            Ok(ref _v) => Ok(()),
 459            Err(ref e) => Err((*e))
 460          }
 461      }
 462  }
 463  
 464  trait CresCompare<T> {
 465      fn compare(&self, t: T, f: || -> ty::type_err) -> cres<T>;
 466  }
 467  
 468  impl<T:Clone + Eq> CresCompare<T> for cres<T> {
 469      fn compare(&self, tT, f|| -> ty::type_err) -> cres<T> {
 470          (*self).clone().and_then(|s| {
 471              if s == t {
 472                  (*self).clone()
 473              } else {
 474                  Err(f())
 475              }
 476          })
 477      }
 478  }
 479  
 480  pub fn uok() -> ures {
 481      Ok(())
 482  }
 483  
 484  fn rollback_to<V:Clone + Vid,T:Clone>(vb: &mut ValsAndBindings<V, T>,
 485                                        len: uint) {
 486      while vb.bindings.len() != len {
 487          let (vid, old_v) = vb.bindings.pop().unwrap();
 488          vb.vals.insert(vid.to_uint(), old_v);
 489      }
 490  }
 491  
 492  pub struct Snapshot {
 493      ty_var_bindings_len: uint,
 494      int_var_bindings_len: uint,
 495      float_var_bindings_len: uint,
 496      region_vars_snapshot: uint,
 497  }
 498  
 499  impl<'a> InferCtxt<'a> {
 500      pub fn combine_fields<'a>(&'a self, a_is_expectedbool, traceTypeTrace)
 501                                -> CombineFields<'a> {
 502          CombineFields {infcx: self,
 503                         a_is_expected: a_is_expected,
 504                         trace: trace}
 505      }
 506  
 507      pub fn sub<'a>(&'a self, a_is_expectedbool, traceTypeTrace) -> Sub<'a> {
 508          Sub(self.combine_fields(a_is_expected, trace))
 509      }
 510  
 511      pub fn lub<'a>(&'a self, a_is_expectedbool, traceTypeTrace) -> Lub<'a> {
 512          Lub(self.combine_fields(a_is_expected, trace))
 513      }
 514  
 515      pub fn in_snapshot(&self) -> bool {
 516          self.region_vars.in_snapshot()
 517      }
 518  
 519      pub fn start_snapshot(&self) -> Snapshot {
 520          Snapshot {
 521              ty_var_bindings_len: self.ty_var_bindings.borrow().bindings.len(),
 522              int_var_bindings_len: self.int_var_bindings.borrow().bindings.len(),
 523              float_var_bindings_len: self.float_var_bindings.borrow().bindings.len(),
 524              region_vars_snapshot: self.region_vars.start_snapshot(),
 525          }
 526      }
 527  
 528      pub fn rollback_to(&self, snapshot&Snapshot) {
 529          debug!("rollback!");
 530          rollback_to(&mut *self.ty_var_bindings.borrow_mut(),
 531                      snapshot.ty_var_bindings_len);
 532          rollback_to(&mut *self.int_var_bindings.borrow_mut(),
 533                      snapshot.int_var_bindings_len);
 534          rollback_to(&mut *self.float_var_bindings.borrow_mut(),
 535                      snapshot.float_var_bindings_len);
 536  
 537          self.region_vars.rollback_to(snapshot.region_vars_snapshot);
 538      }
 539  
 540      /// Execute `f` and commit the bindings if successful
 541      pub fn commit<T,E>(&self, f|| -> Result<T,E>) -> Result<T,E> {
 542          assert!(!self.in_snapshot());
 543  
 544          debug!("commit()");
 545          indent(|| {
 546              let r = self.try(|| f());
 547  
 548              self.ty_var_bindings.borrow_mut().bindings.truncate(0);
 549              self.int_var_bindings.borrow_mut().bindings.truncate(0);
 550              self.region_vars.commit();
 551              r
 552          })
 553      }
 554  
 555      /// Execute `f`, unroll bindings on failure
 556      pub fn try<T,E>(&self, f|| -> Result<T,E>) -> Result<T,E> {
 557          debug!("try()");
 558          let snapshot = self.start_snapshot();
 559          let r = f();
 560          match r {
 561              Ok(_) => { debug!("success"); }
 562              Err(ref e) => {
 563                  debug!("error: {:?}", *e);
 564                  self.rollback_to(&snapshot)
 565              }
 566          }
 567          r
 568      }
 569  
 570      /// Execute `f` then unroll any bindings it creates
 571      pub fn probe<T,E>(&self, f|| -> Result<T,E>) -> Result<T,E> {
 572          debug!("probe()");
 573          indent(|| {
 574              let snapshot = self.start_snapshot();
 575              let r = f();
 576              self.rollback_to(&snapshot);
 577              r
 578          })
 579      }
 580  }
 581  
 582  fn next_simple_var<V:Clone,T:Clone>(counter: &mut uint,
 583                                      bindings: &mut ValsAndBindings<V,
 584                                                                     Option<T>>)
 585                                      -> uint {
 586      let id = *counter;
 587      *counter += 1;
 588      bindings.vals.insert(id, Root(None, 0));
 589      return id;
 590  }
 591  
 592  impl<'a> InferCtxt<'a> {
 593      pub fn next_ty_var_id(&self) -> TyVid {
 594          let id = self.ty_var_counter.get();
 595          self.ty_var_counter.set(id + 1);
 596          {
 597              let mut ty_var_bindings = self.ty_var_bindings.borrow_mut();
 598              let vals = &mut ty_var_bindings.vals;
 599              vals.insert(id, Root(Bounds { lb: None, ub: None }, 0u));
 600          }
 601          return TyVid(id);
 602      }
 603  
 604      pub fn next_ty_var(&self) -> ty::t {
 605          ty::mk_var(self.tcx, self.next_ty_var_id())
 606      }
 607  
 608      pub fn next_ty_vars(&self, nuint) -> Vec<ty::t> {
 609          Vec::from_fn(n, |_i| self.next_ty_var())
 610      }
 611  
 612      pub fn next_int_var_id(&self) -> IntVid {
 613          let mut int_var_counter = self.int_var_counter.get();
 614          let mut int_var_bindings = self.int_var_bindings.borrow_mut();
 615          let result = IntVid(next_simple_var(&mut int_var_counter,
 616                                              &mut *int_var_bindings));
 617          self.int_var_counter.set(int_var_counter);
 618          result
 619      }
 620  
 621      pub fn next_float_var_id(&self) -> FloatVid {
 622          let mut float_var_counter = self.float_var_counter.get();
 623          let mut float_var_bindings = self.float_var_bindings.borrow_mut();
 624          let result = FloatVid(next_simple_var(&mut float_var_counter,
 625                                                &mut *float_var_bindings));
 626          self.float_var_counter.set(float_var_counter);
 627          result
 628      }
 629  
 630      pub fn next_region_var(&self, originRegionVariableOrigin) -> ty::Region {
 631          ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin)))
 632      }
 633  
 634      pub fn region_vars_for_defs(&self,
 635                                  spanSpan,
 636                                  defs&[ty::RegionParameterDef])
 637                                  -> OwnedSlice<ty::Region> {
 638          defs.iter()
 639              .map(|d| self.next_region_var(EarlyBoundRegion(span, d.name)))
 640              .collect()
 641      }
 642  
 643      pub fn fresh_bound_region(&self, binder_idast::NodeId) -> ty::Region {
 644          self.region_vars.new_bound(binder_id)
 645      }
 646  
 647      pub fn resolve_regions(&self) {
 648          let errors = self.region_vars.resolve_regions();
 649          self.report_region_errors(&errors); // see error_reporting.rs
 650      }
 651  
 652      pub fn ty_to_str(&self, tty::t) -> ~str {
 653          ty_to_str(self.tcx,
 654                    self.resolve_type_vars_if_possible(t))
 655      }
 656  
 657      pub fn tys_to_str(&self, ts&[ty::t]) -> ~str {
 658          let tstrsVec<~str> = ts.iter().map(|t| self.ty_to_str(*t)).collect();
 659          format!("({})", tstrs.connect(", "))
 660      }
 661  
 662      pub fn trait_ref_to_str(&self, t&ty::TraitRef) -> ~str {
 663          let t = self.resolve_type_vars_in_trait_ref_if_possible(t);
 664          trait_ref_to_str(self.tcx, &t)
 665      }
 666  
 667      pub fn resolve_type_vars_if_possible(&self, typty::t) -> ty::t {
 668          match resolve_type(self, typ, resolve_nested_tvar | resolve_ivar) {
 669              Ok(new_type) => new_type,
 670              Err(_) => typ
 671          }
 672      }
 673  
 674      pub fn resolve_type_vars_in_trait_ref_if_possible(&self,
 675                                                        trait_ref:
 676                                                        &ty::TraitRef)
 677                                                        -> ty::TraitRef {
 678          // make up a dummy type just to reuse/abuse the resolve machinery
 679          let dummy0 = ty::mk_trait(self.tcx,
 680                                    trait_ref.def_id,
 681                                    trait_ref.substs.clone(),
 682                                    ty::UniqTraitStore,
 683                                    ty::EmptyBuiltinBounds());
 684          let dummy1 = self.resolve_type_vars_if_possible(dummy0);
 685          match ty::get(dummy1).sty {
 686              ty::ty_trait(box ty::TyTrait { ref def_id, ref substs, .. }) => {
 687                  ty::TraitRef {
 688                      def_id: *def_id,
 689                      substs: (*substs).clone(),
 690                  }
 691              }
 692              _ => {
 693                  self.tcx.sess.bug(
 694                      format!("resolve_type_vars_if_possible() yielded {} \
 695                            when supplied with {}",
 696                           self.ty_to_str(dummy0),
 697                           self.ty_to_str(dummy1)));
 698              }
 699          }
 700      }
 701  
 702      // [Note-Type-error-reporting]
 703      // An invariant is that anytime the expected or actual type is ty_err (the special
 704      // error type, meaning that an error occurred when typechecking this expression),
 705      // this is a derived error. The error cascaded from another error (that was already
 706      // reported), so it's not useful to display it to the user.
 707      // The following four methods -- type_error_message_str, type_error_message_str_with_expected,
 708      // type_error_message, and report_mismatched_types -- implement this logic.
 709      // They check if either the actual or expected type is ty_err, and don't print the error
 710      // in this case. The typechecker should only ever report type errors involving mismatched
 711      // types using one of these four methods, and should not call span_err directly for such
 712      // errors.
 713      pub fn type_error_message_str(&self,
 714                                    spSpan,
 715                                    mk_msg|Option<~str>, ~str| -> ~str,
 716                                    actual_ty~str,
 717                                    errOption<&ty::type_err>) {
 718          self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err)
 719      }
 720  
 721      pub fn type_error_message_str_with_expected(&self,
 722                                                  spSpan,
 723                                                  mk_msg|Option<~str>,
 724                                                           ~str|
 725                                                           -> ~str,
 726                                                  expected_tyOption<ty::t>,
 727                                                  actual_ty~str,
 728                                                  errOption<&ty::type_err>) {
 729          debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
 730  
 731          let error_str = err.map_or("".to_owned(), |t_err| {
 732              format!(({})", ty::type_err_to_str(self.tcx, t_err))
 733          });
 734          let resolved_expected = expected_ty.map(|e_ty| {
 735              self.resolve_type_vars_if_possible(e_ty)
 736          });
 737          if !resolved_expected.map_or(false, |e| { ty::type_is_error(e) }) {
 738              match resolved_expected {
 739                  None => self.tcx.sess.span_err(sp,
 740                              format!("{}{}", mk_msg(None, actual_ty), error_str)),
 741                  Some(e) => {
 742                      self.tcx.sess.span_err(sp,
 743                          format!("{}{}", mk_msg(Some(self.ty_to_str(e)), actual_ty), error_str));
 744                  }
 745              }
 746              for err in err.iter() {
 747                  ty::note_and_explain_type_err(self.tcx, *err)
 748              }
 749          }
 750      }
 751  
 752      pub fn type_error_message(&self,
 753                                spSpan,
 754                                mk_msg|~str| -> ~str,
 755                                actual_tyty::t,
 756                                errOption<&ty::type_err>) {
 757          let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
 758  
 759          // Don't report an error if actual type is ty_err.
 760          if ty::type_is_error(actual_ty) {
 761              return;
 762          }
 763  
 764          self.type_error_message_str(sp, |_e, a| { mk_msg(a) }, self.ty_to_str(actual_ty), err);
 765      }
 766  
 767      pub fn report_mismatched_types(&self,
 768                                     spSpan,
 769                                     ety::t,
 770                                     aty::t,
 771                                     err&ty::type_err) {
 772          let resolved_expected =
 773              self.resolve_type_vars_if_possible(e);
 774          let mk_msg = match ty::get(resolved_expected).sty {
 775              // Don't report an error if expected is ty_err
 776              ty::ty_err => return,
 777              _ => {
 778                  // if I leave out : ~str, it infers &str and complains
 779                  |actual~str{
 780                      format!("mismatched types: expected `{}` but found `{}`",
 781                           self.ty_to_str(resolved_expected), actual)
 782                  }
 783              }
 784          };
 785          self.type_error_message(sp, mk_msg, a, Some(err));
 786      }
 787  
 788      pub fn replace_late_bound_regions_with_fresh_regions(&self,
 789                                                           traceTypeTrace,
 790                                                           fsig&ty::FnSig)
 791                                                      -> (ty::FnSig,
 792                                                          HashMap<ty::BoundRegion,
 793                                                                  ty::Region>) {
 794          let (map, fn_sig) =
 795              replace_late_bound_regions_in_fn_sig(self.tcx, fsig, |br| {
 796                  let rvar = self.next_region_var(
 797                      BoundRegionInFnType(trace.origin.span(), br));
 798                  debug!("Bound region {} maps to {:?}",
 799                         bound_region_to_str(self.tcx, "", false, br),
 800                         rvar);
 801                  rvar
 802              });
 803          (fn_sig, map)
 804      }
 805  }
 806  
 807  pub fn fold_regions_in_sig(tcx: &ty::ctxt,
 808                             fn_sig: &ty::FnSig,
 809                             fldr: |r: ty::Region-> ty::Region)
 810                             -> ty::FnSig {
 811      ty_fold::RegionFolder::regions(tcx, fldr).fold_sig(fn_sig)
 812  }
 813  
 814  impl TypeTrace {
 815      pub fn span(&self) -> Span {
 816          self.origin.span()
 817      }
 818  }
 819  
 820  impl Repr for TypeTrace {
 821      fn repr(&self, tcx&ty::ctxt) -> ~str {
 822          format!("TypeTrace({})", self.origin.repr(tcx))
 823      }
 824  }
 825  
 826  impl TypeOrigin {
 827      pub fn span(&self) -> Span {
 828          match *self {
 829              MethodCompatCheck(span) => span,
 830              ExprAssignable(span) => span,
 831              Misc(span) => span,
 832              RelateTraitRefs(span) => span,
 833              RelateSelfType(span) => span,
 834              MatchExpression(span) => span,
 835              IfExpression(span) => span,
 836          }
 837      }
 838  }
 839  
 840  impl Repr for TypeOrigin {
 841      fn repr(&self, tcx&ty::ctxt) -> ~str {
 842          match *self {
 843              MethodCompatCheck(a) => format!("MethodCompatCheck({})", a.repr(tcx)),
 844              ExprAssignable(a) => format!("ExprAssignable({})", a.repr(tcx)),
 845              Misc(a) => format!("Misc({})", a.repr(tcx)),
 846              RelateTraitRefs(a) => format!("RelateTraitRefs({})", a.repr(tcx)),
 847              RelateSelfType(a) => format!("RelateSelfType({})", a.repr(tcx)),
 848              MatchExpression(a) => format!("MatchExpression({})", a.repr(tcx)),
 849              IfExpression(a) => format!("IfExpression({})", a.repr(tcx)),
 850          }
 851      }
 852  }
 853  
 854  impl SubregionOrigin {
 855      pub fn span(&self) -> Span {
 856          match *self {
 857              Subtype(ref a) => a.span(),
 858              InfStackClosure(a) => a,
 859              InvokeClosure(a) => a,
 860              DerefPointer(a) => a,
 861              FreeVariable(a, _) => a,
 862              IndexSlice(a) => a,
 863              RelateObjectBound(a) => a,
 864              Reborrow(a) => a,
 865              ReborrowUpvar(a, _) => a,
 866              ReferenceOutlivesReferent(_, a) => a,
 867              BindingTypeIsNotValidAtDecl(a) => a,
 868              CallRcvr(a) => a,
 869              CallArg(a) => a,
 870              CallReturn(a) => a,
 871              AddrOf(a) => a,
 872              AutoBorrow(a) => a,
 873          }
 874      }
 875  }
 876  
 877  impl Repr for SubregionOrigin {
 878      fn repr(&self, tcx&ty::ctxt) -> ~str {
 879          match *self {
 880              Subtype(ref a) => format!("Subtype({})", a.repr(tcx)),
 881              InfStackClosure(a) => format!("InfStackClosure({})", a.repr(tcx)),
 882              InvokeClosure(a) => format!("InvokeClosure({})", a.repr(tcx)),
 883              DerefPointer(a) => format!("DerefPointer({})", a.repr(tcx)),
 884              FreeVariable(a, b) => format!("FreeVariable({}, {})", a.repr(tcx), b),
 885              IndexSlice(a) => format!("IndexSlice({})", a.repr(tcx)),
 886              RelateObjectBound(a) => format!("RelateObjectBound({})", a.repr(tcx)),
 887              Reborrow(a) => format!("Reborrow({})", a.repr(tcx)),
 888              ReborrowUpvar(a, b) => format!("ReborrowUpvar({},{:?})", a.repr(tcx), b),
 889              ReferenceOutlivesReferent(_, a) =>
 890                  format!("ReferenceOutlivesReferent({})", a.repr(tcx)),
 891              BindingTypeIsNotValidAtDecl(a) =>
 892                  format!("BindingTypeIsNotValidAtDecl({})", a.repr(tcx)),
 893              CallRcvr(a) => format!("CallRcvr({})", a.repr(tcx)),
 894              CallArg(a) => format!("CallArg({})", a.repr(tcx)),
 895              CallReturn(a) => format!("CallReturn({})", a.repr(tcx)),
 896              AddrOf(a) => format!("AddrOf({})", a.repr(tcx)),
 897              AutoBorrow(a) => format!("AutoBorrow({})", a.repr(tcx)),
 898          }
 899      }
 900  }
 901  
 902  impl RegionVariableOrigin {
 903      pub fn span(&self) -> Span {
 904          match *self {
 905              MiscVariable(a) => a,
 906              PatternRegion(a) => a,
 907              AddrOfRegion(a) => a,
 908              AddrOfSlice(a) => a,
 909              Autoref(a) => a,
 910              Coercion(ref a) => a.span(),
 911              EarlyBoundRegion(a, _) => a,
 912              LateBoundRegion(a, _) => a,
 913              BoundRegionInFnType(a, _) => a,
 914              BoundRegionInCoherence(_) => codemap::DUMMY_SP,
 915              UpvarRegion(_, a) => a
 916          }
 917      }
 918  }
 919  
 920  impl Repr for RegionVariableOrigin {
 921      fn repr(&self, tcx&ty::ctxt) -> ~str {
 922          match *self {
 923              MiscVariable(a) => format!("MiscVariable({})", a.repr(tcx)),
 924              PatternRegion(a) => format!("PatternRegion({})", a.repr(tcx)),
 925              AddrOfRegion(a) => format!("AddrOfRegion({})", a.repr(tcx)),
 926              AddrOfSlice(a) => format!("AddrOfSlice({})", a.repr(tcx)),
 927              Autoref(a) => format!("Autoref({})", a.repr(tcx)),
 928              Coercion(ref a) => format!("Coercion({})", a.repr(tcx)),
 929              EarlyBoundRegion(a, b) => format!("EarlyBoundRegion({},{})",
 930                                                a.repr(tcx), b.repr(tcx)),
 931              LateBoundRegion(a, b) => format!("LateBoundRegion({},{})",
 932                                               a.repr(tcx), b.repr(tcx)),
 933              BoundRegionInFnType(a, b) => format!("bound_regionInFnType({},{})",
 934                                                a.repr(tcx), b.repr(tcx)),
 935              BoundRegionInCoherence(a) => format!("bound_regionInCoherence({})",
 936                                                   a.repr(tcx)),
 937              UpvarRegion(a, b) => format!("UpvarRegion({}, {})",
 938                                           a.repr(tcx),
 939                                           b.repr(tcx)),
 940          }
 941      }
 942  }


librustc/middle/typeck/infer/mod.rs:268:1-268:1 -fn- definition:
pub fn new_infer_ctxt<'a>(tcx: &'a ty::ctxt) -> InferCtxt<'a> {
    InferCtxt {
        tcx: tcx,
references:- 8
librustc/middle/typeck/coherence.rs:
781:         crate_context: crate_context,
782:         inference_context: new_infer_ctxt(crate_context.tcx),
783:     }.check(krate);
librustc/middle/lint.rs:
702:         ast::ExprCast(expr, ty) => {
703:             let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), ty);
704:             if  ty::get(ty::expr_ty(cx.tcx, expr)).sty == ty::get(t_t).sty {
librustc/middle/typeck/mod.rs:
296:         None => {
297:             let infcx = infer::new_infer_ctxt(tcx);
298:             infer::mk_eqty(&infcx, t1_is_expected, infer::Misc(span), t1, t2)
librustc/middle/typeck/check/mod.rs:
869:     debug!("compare_impl_method()");
870:     let infcx = infer::new_infer_ctxt(tcx);
librustc/middle/typeck/check/vtable.rs:
794:         let vcx = VtableContext {
795:             infcx: &infer::new_infer_ctxt(tcx),
796:             param_env: &ty::construct_parameter_environment(tcx, None, [], [], [], [], id)
librustc/middle/lint.rs:
694:     fn ty_infer(&self, _span: Span) -> ty::t {
695:         infer::new_infer_ctxt(self.tcx).next_ty_var()
696:     }


librustc/middle/typeck/infer/mod.rs:248:1-248:1 -fn- definition:
pub fn fixup_err_to_str(f: fixup_err) -> ~str {
    match f {
      unresolved_int_ty(_) => "unconstrained integral type".to_owned(),
references:- 5
librustc/middle/typeck/check/vtable.rs:
494:                       for this bounded type parameter: {}",
495:                      fixup_err_to_str(e)))
496:         }
librustc/middle/typeck/check/writeback.rs:
451:                                     upvar_id.var_id).get().to_str(),
452:                                 infer::fixup_err_to_str(e)));
453:                 }


librustc/middle/typeck/infer/mod.rs:240:1-240:1 -enum- definition:
pub enum fixup_err {
    unresolved_int_ty(IntVid),
    unresolved_ty(TyVid),
references:- 4
249: pub fn fixup_err_to_str(f: fixup_err) -> ~str {
250:     match f {
librustc/middle/typeck/check/writeback.rs:
415:     fn report_error(&self, e: infer::fixup_err) {
416:         self.fcx.writeback_errors.set(true);
librustc/middle/typeck/infer/resolve.rs:
82:     modes: uint,
83:     err: Option<fixup_err>,
84:     v_seen: Vec<TyVid> ,


librustc/middle/typeck/infer/mod.rs:483:1-483:1 -fn- definition:
fn rollback_to<V:Clone + Vid,T:Clone>(vb: &mut ValsAndBindings<V, T>,
                                      len: uint) {
    while vb.bindings.len() != len {
references:- 3
533:                     snapshot.int_var_bindings_len);
534:         rollback_to(&mut *self.float_var_bindings.borrow_mut(),
535:                     snapshot.float_var_bindings_len);


librustc/middle/typeck/infer/mod.rs:581:1-581:1 -fn- definition:
fn next_simple_var<V:Clone,T:Clone>(counter: &mut uint,
                                    bindings: &mut ValsAndBindings<V,
                                                                   Option<T>>)
references:- 2
623:         let mut float_var_bindings = self.float_var_bindings.borrow_mut();
624:         let result = FloatVid(next_simple_var(&mut float_var_counter,
625:                                               &mut *float_var_bindings));


librustc/middle/typeck/infer/mod.rs:72:63-72:63 -NK_AS_STR_TODO- definition:
pub type cres<T> = Result<T,ty::type_err>; // "combine result"
pub type ures = cres<()>; // "unify result"
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
references:- 27
480: pub fn uok() -> ures {
481:     Ok(())
librustc/middle/typeck/infer/combine.rs:
326: pub fn eq_regions<C:Combine>(this: &C, a: ty::Region, b: ty::Region)
327:                           -> ures {
328:     debug!("eq_regions({}, {})",
librustc/middle/typeck/infer/lattice.rs:
50: trait LatticeValue {
51:     fn sub(cf: CombineFields, a: &Self, b: &Self) -> ures;
52:     fn lub(cf: CombineFields, a: &Self, b: &Self) -> cres<Self>;
--
246:                                 rank: uint)
247:                                 -> ures {
248:         /*!
--
304:                                                b: &Bound<T>)
305:                                                -> ures {
306:         debug!("bnds({} <: {})", a.inf_str(self.infcx),
librustc/middle/typeck/infer/unify.rs:
197:                     b: T)
198:                     -> ures;
199: }
--
207:                    b_id: V)
208:                    -> ures {
209:         /*!
--
247:                     b: T)
248:                     -> ures {
249:         /*!
librustc/middle/typeck/infer/lattice.rs:
104:                                 rank: uint)
105:                                 -> ures;
106:     fn bnds<T:Clone + InferStr + LatticeValue>(


librustc/middle/typeck/infer/mod.rs:355:1-355:1 -fn- definition:
pub fn mk_eqty(cx: &InferCtxt,
               a_is_expected: bool,
               origin: TypeOrigin,
references:- 5
librustc/middle/typeck/mod.rs:
297:             let infcx = infer::new_infer_ctxt(tcx);
298:             infer::mk_eqty(&infcx, t1_is_expected, infer::Misc(span), t1, t2)
299:         }
librustc/middle/typeck/check/mod.rs:
3121:                                                                    t1);
3122:                                 infer::mk_eqty(fcx.infcx(), false,
3123:                                                infer::Misc(sp), el, t2).is_ok()
librustc/middle/typeck/check/demand.rs:
49: pub fn eqtype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
50:     match infer::mk_eqty(fcx.infcx(), false, infer::Misc(sp), actual, expected) {
51:         Ok(()) => { /* ok */ }
librustc/middle/typeck/mod.rs:
300:         Some(infcx) => {
301:             infer::mk_eqty(infcx, t1_is_expected, infer::Misc(span), t1, t2)
302:         }


librustc/middle/typeck/infer/mod.rs:74:59-74:59 -NK_AS_STR_TODO- definition:
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
pub type CoerceResult = cres<Option<ty::AutoAdjustment>>;
pub struct InferCtxt<'a> {
references:- 13
410:                    b: ty::t)
411:                 -> CoerceResult {
412:     debug!("mk_coercety({} -> {})", a.inf_str(cx), b.inf_str(cx));
librustc/middle/typeck/infer/coercion.rs:
378:     fn coerce_from_bare_fn(&self, a: ty::t, fn_ty_a: &ty::BareFnTy, b: ty::t)
379:                            -> CoerceResult {
380:         /*!
--
415:                              mt_b: ty::mt)
416:                              -> CoerceResult {
417:         debug!("coerce_unsafe_ptr(a={}, sty_a={:?}, b={})",
--
447:                          trait_store: ty::TraitStore,
448:                          bounds: ty::BuiltinBounds) -> CoerceResult {


librustc/middle/typeck/infer/mod.rs:395:1-395:1 -fn- definition:
fn expected_found<T>(a_is_expected: bool,
                     a: T,
                     b: T) -> ty::expected_found<T> {
references:- 6
387:                 origin: origin,
388:                 values: TraitRefs(expected_found(a_is_expected, a.clone(), b.clone()))
389:             };
--
416:                 origin: origin,
417:                 values: Types(expected_found(a_is_expected, a, b))
418:             };


librustc/middle/typeck/infer/mod.rs:63:1-63:1 -NK_AS_STR_TODO- definition:
pub type Bound<T> = Option<T>;
pub struct Bounds<T> {
    lb: Bound<T>,
references:- 13
68:     lb: Bound<T>,
69:     ub: Bound<T>
70: }
librustc/middle/typeck/infer/lattice.rs:
219:                  lattice_op: LatticeOp<T>)
220:                  -> cres<Bound<T>> {
221:         /*!
--
303:                                                a: &Bound<T>,
304:                                                b: &Bound<T>)
305:                                                -> ures {
librustc/middle/typeck/infer/to_str.rs:
52: impl<V:InferStr> InferStr for Bound<V> {
53:     fn inf_str(&self, cx: &InferCtxt) -> ~str {
librustc/middle/typeck/infer/lattice.rs:
216:                  &self,
217:                  a: &Bound<T>,
218:                  b: &Bound<T>,


librustc/middle/typeck/infer/mod.rs:491:1-491:1 -struct- definition:
pub struct Snapshot {
    ty_var_bindings_len: uint,
    int_var_bindings_len: uint,
references:- 3
519:     pub fn start_snapshot(&self) -> Snapshot {
520:         Snapshot {
521:             ty_var_bindings_len: self.ty_var_bindings.borrow().bindings.len(),
--
528:     pub fn rollback_to(&self, snapshot: &Snapshot) {
529:         debug!("rollback!");


librustc/middle/typeck/infer/mod.rs:204:19-204:19 -enum- definition:
pub enum RegionVariableOrigin {
    // Region variables created for ill-categorized reasons,
    // mostly indicates places in need of refactoring
references:- 18
630:     pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region {
631:         ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin)))
--
902: impl RegionVariableOrigin {
903:     pub fn span(&self) -> Span {
--
920: impl Repr for RegionVariableOrigin {
921:     fn repr(&self, tcx: &ty::ctxt) -> ~str {
librustc/middle/typeck/infer/region_inference/mod.rs:
87:     /// into `ProcessedErrors` before we do any reporting.
88:     ProcessedErrors(Vec<RegionVariableOrigin>,
89:                     Vec<(TypeTrace, ty::type_err)>,
--
213:     pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid {
214:         let id = self.num_vars();
librustc/middle/typeck/infer/error_reporting.rs:
132:     fn report_processed_errors(&self,
133:                                var_origin: &[RegionVariableOrigin],
134:                                trace_origin: &[(TypeTrace, ty::type_err)],
--
659:     fn report_processed_errors(&self,
660:                                var_origins: &[RegionVariableOrigin],
661:                                trace_origins: &[(TypeTrace, ty::type_err)],
--
1215:     fn report_inference_failure(&self,
1216:                                 var_origin: RegionVariableOrigin) {
1217:         let var_description = match var_origin {
librustc/middle/typeck/infer/region_inference/mod.rs:
123:     tcx: &'a ty::ctxt,
124:     var_origins: RefCell<Vec<RegionVariableOrigin>>,
125:     constraints: RefCell<HashMap<Constraint, SubregionOrigin>>,


librustc/middle/typeck/infer/mod.rs:66:19-66:19 -struct- definition:
pub struct Bounds<T> {
    lb: Bound<T>,
    ub: Bound<T>
references:- 41
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/typeck/infer/mod.rs:


librustc/middle/typeck/infer/mod.rs:261:1-261:1 -fn- definition:
fn new_ValsAndBindings<V:Clone,T:Clone>() -> ValsAndBindings<V, T> {
    ValsAndBindings {
        vals: SmallIntMap::new(),
references:- 3
279:         float_var_bindings: RefCell::new(new_ValsAndBindings()),
280:         float_var_counter: Cell::new(0),


librustc/middle/typeck/infer/mod.rs:103:19-103:19 -enum- definition:
pub enum TypeOrigin {
    // Not yet categorized in a better way
    Misc(Span),
references:- 12
286: pub fn common_supertype(cx: &InferCtxt,
287:                         origin: TypeOrigin,
288:                         a_is_expected: bool,
--
840: impl Repr for TypeOrigin {
841:     fn repr(&self, tcx: &ty::ctxt) -> ~str {
librustc/middle/typeck/check/mod.rs:
1215:                     a_is_expected: bool,
1216:                     origin: infer::TypeOrigin,
1217:                     sub: ty::t,
--
1248:                    a_is_expected: bool,
1249:                    origin: infer::TypeOrigin,
1250:                    sub: ty::t,
librustc/middle/typeck/infer/mod.rs:
407:                    a_is_expected: bool,
408:                    origin: TypeOrigin,
409:                    a: ty::t,


librustc/middle/typeck/infer/mod.rs:71:1-71:1 -NK_AS_STR_TODO- definition:
pub type cres<T> = Result<T,ty::type_err>; // "combine result"
pub type ures = cres<()>; // "unify result"
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
references:- 76
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/mod.rs:


librustc/middle/typeck/infer/mod.rs:806:1-806:1 -fn- definition:
pub fn fold_regions_in_sig(tcx: &ty::ctxt,
                           fn_sig: &ty::FnSig,
                           fldr: |r: ty::Region| -> ty::Region)
references:- 2
librustc/middle/typeck/infer/glb.rs:
153:         let sig1 =
154:             fold_regions_in_sig(
155:                 self.get_ref().infcx.tcx,
librustc/middle/typeck/infer/lub.rs:
137:         let sig1 =
138:             fold_regions_in_sig(
139:                 self.get_ref().infcx.tcx,


librustc/middle/typeck/infer/mod.rs:424:49-424:49 -fn- definition:
// See comment on the type `resolve_state` below
pub fn resolve_type(cx: &InferCtxt,
                    a: ty::t,
references:- 8
667:     pub fn resolve_type_vars_if_possible(&self, typ: ty::t) -> ty::t {
668:         match resolve_type(self, typ, resolve_nested_tvar | resolve_ivar) {
669:             Ok(new_type) => new_type,
librustc/middle/typeck/coherence.rs:
62:     let resolved_type;
63:     match resolve_type(inference_context,
64:                        original_type,
librustc/middle/typeck/check/mod.rs:
3977: pub fn structurally_resolved_type(fcx: &FnCtxt, sp: Span, tp: ty::t) -> ty::t {
3978:     match infer::resolve_type(fcx.infcx(), tp, force_tvar) {
3979:         Ok(t_s) if !ty::type_is_ty_var(t_s) => t_s,
librustc/middle/typeck/check/vtable.rs:
488:     let tcx = vcx.tcx();
489:     match resolve_type(vcx.infcx, ty, resolve_and_force_all_but_regions) {
490:         Ok(new_type) => Some(new_type),
librustc/middle/typeck/check/writeback.rs:
469:         match resolve_type(self.fcx.infcx(), t, resolve_all | force_all) {
470:             Ok(t) => t,
librustc/middle/typeck/check/regionck.rs:
230:          */
231:         match resolve_type(self.fcx.infcx(), unresolved_ty,
232:                            resolve_and_force_all_but_regions) {
librustc/middle/typeck/infer/coercion.rs:
206:                                -> CoerceResult {
207:         match resolve_type(self.get_ref().infcx, a, try_resolve_tvar_shallow) {
208:             Ok(t) => {


librustc/middle/typeck/infer/mod.rs:331:1-331:1 -fn- definition:
pub fn can_mk_subty(cx: &InferCtxt, a: ty::t, b: ty::t) -> ures {
    debug!("can_mk_subty({} <: {})", a.inf_str(cx), b.inf_str(cx));
    indent(|| {
references:- 2
librustc/middle/typeck/check/mod.rs:
1224:                         -> Result<(), ty::type_err> {
1225:         infer::can_mk_subty(self.infcx(), sub, sup)
1226:     }
librustc/middle/typeck/coherence.rs:
505:                                             -> bool {
506:         infer::can_mk_subty(&self.inference_context,
507:                             a.monotype,


librustc/middle/typeck/infer/mod.rs:139:19-139:19 -struct- definition:
pub struct TypeTrace {
    origin: TypeOrigin,
    values: ValuePairs,
references:- 30
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/infer/mod.rs:


librustc/middle/typeck/infer/mod.rs:344:1-344:1 -fn- definition:
pub fn mk_subr(cx: &InferCtxt,
               _a_is_expected: bool,
               origin: SubregionOrigin,
references:- 2
librustc/middle/typeck/check/mod.rs:
1260:                    sup: ty::Region) {
1261:         infer::mk_subr(self.infcx(), a_is_expected, origin, sub, sup)
1262:     }
librustc/middle/typeck/check/vtable.rs:
594:                            ty::RegionTraitStore(rb, _)) => {
595:                               infer::mk_subr(fcx.infcx(),
596:                                              false,


librustc/middle/typeck/infer/mod.rs:73:44-73:44 -NK_AS_STR_TODO- definition:
pub type ures = cres<()>; // "unify result"
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
pub type CoerceResult = cres<Option<ty::AutoAdjustment>>;
references:- 4
433: pub fn resolve_region(cx: &InferCtxt, r: ty::Region, modes: uint)
434:                    -> fres<ty::Region> {
435:     let mut resolver = resolver(cx, modes);
librustc/middle/typeck/infer/resolve.rs:
117:     pub fn resolve_type_chk(&mut self, typ: ty::t) -> fres<ty::t> {
118:         self.err = None;
--
142:     pub fn resolve_region_chk(&mut self, orig: ty::Region)
143:                               -> fres<ty::Region> {
144:         self.err = None;


librustc/middle/typeck/infer/mod.rs:479:1-479:1 -fn- definition:
pub fn uok() -> ures {
    Ok(())
}
references:- 7
librustc/middle/typeck/infer/lattice.rs:
138:         if a_id == b_id { return uok(); }
--
313:             (&None, &Some(_)) => {
314:                 uok()
315:             }
librustc/middle/typeck/infer/unify.rs:
238:         self.set(new_root, Root(combined, new_rank));
239:         return uok();
240:     }
--
261:                 self.set(a_id, Root(Some(b), node_a.rank));
262:                 return uok();
263:             }
--
266:                 if *a_t == b {
267:                     return uok();
268:                 } else {
librustc/middle/typeck/infer/lattice.rs:
298:         self.infcx.set(v_id, Root(bounds, rank));
299:         uok()
300:     }


librustc/middle/typeck/infer/mod.rs:313:1-313:1 -fn- definition:
pub fn mk_subty(cx: &InferCtxt,
                a_is_expected: bool,
                origin: TypeOrigin,
references:- 4
librustc/middle/typeck/check/mod.rs:
1035:     match infer::mk_subty(&infcx, false, infer::MethodCompatCheck(impl_m_span),
1036:                           impl_fty, trait_fty) {
--
1219:                     -> Result<(), ty::type_err> {
1220:         infer::mk_subty(self.infcx(), a_is_expected, origin, sub, sup)
1221:     }
librustc/middle/typeck/check/demand.rs:
39:     // n.b.: order of actual, expected is reversed
40:     match infer::mk_subty(fcx.infcx(), b_is_expected, infer::Misc(sp),
41:                           ty_b, ty_a) {
librustc/middle/typeck/check/vtable.rs:
366:         } = impl_self_ty(vcx, span, impl_did);
367:         match infer::mk_subty(vcx.infcx,
368:                               false,


librustc/middle/typeck/infer/mod.rs:129:19-129:19 -enum- definition:
pub enum ValuePairs {
    Types(ty::expected_found<ty::t>),
    TraitRefs(ty::expected_found<Rc<ty::TraitRef>>),
references:- 5
141:     origin: TypeOrigin,
142:     values: ValuePairs,
143: }
librustc/middle/typeck/infer/error_reporting.rs:
106:     fn values_str(&self, values: &ValuePairs) -> Option<~str>;
--
368:     fn values_str(&self, values: &ValuePairs) -> Option<~str> {
369:         /*!
librustc/middle/typeck/infer/mod.rs:
128: /// See `error_reporting.rs` for more details
130: pub enum ValuePairs {


librustc/middle/typeck/infer/mod.rs:76:1-76:1 -struct- definition:
pub struct InferCtxt<'a> {
    pub tcx: &'a ty::ctxt,
    // We instantiate ValsAndBindings with bounds<ty::t> because the
references:- 51
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/infer/unify.rs:


librustc/middle/typeck/infer/mod.rs:285:1-285:1 -fn- definition:
pub fn common_supertype(cx: &InferCtxt,
                        origin: TypeOrigin,
                        a_is_expected: bool,
references:- 2
librustc/middle/typeck/check/_match.rs:
87:         result_ty =
88:             infer::common_supertype(
89:                 fcx.infcx(),
librustc/middle/typeck/check/mod.rs:
2022:                 let else_ty = fcx.expr_ty(else_expr);
2023:                 infer::common_supertype(fcx.infcx(),
2024:                                         infer::IfExpression(sp),


librustc/middle/typeck/infer/mod.rs:148:19-148:19 -enum- definition:
pub enum SubregionOrigin {
    // Arose from a subtyping relation
    Subtype(TypeTrace),
references:- 32
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/infer/error_reporting.rs: