2014-02-10 15:36:31 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 16:48:01 -08:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-02-09 20:23:16 -05:00
|
|
|
//! See the Book for more information.
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(non_camel_case_types)]
|
2013-05-17 15:28:44 -07:00
|
|
|
|
2014-11-17 15:25:37 -05:00
|
|
|
pub use self::LateBoundRegionConversionTime::*;
|
|
|
|
pub use self::RegionVariableOrigin::*;
|
|
|
|
pub use self::SubregionOrigin::*;
|
2014-11-06 00:05:53 -08:00
|
|
|
pub use self::TypeOrigin::*;
|
|
|
|
pub use self::ValuePairs::*;
|
|
|
|
pub use self::fixup_err::*;
|
2013-01-29 16:26:16 -08:00
|
|
|
pub use middle::ty::IntVarValue;
|
2014-12-12 06:13:42 -05:00
|
|
|
pub use self::freshen::TypeFreshener;
|
2015-01-03 04:40:33 -05:00
|
|
|
pub use self::region_inference::GenericKind;
|
2013-01-29 16:26:16 -08:00
|
|
|
|
2015-04-18 11:23:14 -04:00
|
|
|
use middle::free_region::FreeRegionMap;
|
2015-06-25 13:08:10 -07:00
|
|
|
use middle::mem_categorization as mc;
|
|
|
|
use middle::mem_categorization::McResult;
|
|
|
|
use middle::region::{self, CodeExtent};
|
2014-05-31 18:53:13 -04:00
|
|
|
use middle::subst;
|
|
|
|
use middle::subst::Substs;
|
2015-06-25 13:08:10 -07:00
|
|
|
use middle::subst::Subst;
|
|
|
|
use middle::traits;
|
2014-12-15 09:45:28 -05:00
|
|
|
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, UnconstrainedNumeric};
|
2015-06-24 02:54:32 +03:00
|
|
|
use middle::ty::{self, Ty, HasTypeFlags};
|
2015-06-06 02:06:14 +03:00
|
|
|
use middle::ty_fold::{self, TypeFolder, TypeFoldable};
|
2015-03-22 15:11:56 -04:00
|
|
|
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
|
2015-04-07 06:12:21 -04:00
|
|
|
use rustc_data_structures::unify::{self, UnificationTable};
|
2015-06-25 13:08:10 -07:00
|
|
|
use std::cell::{RefCell, Ref};
|
2015-03-19 14:49:28 -07:00
|
|
|
use std::fmt;
|
2013-01-08 19:37:25 -08:00
|
|
|
use syntax::ast;
|
2013-01-30 09:56:33 -08:00
|
|
|
use syntax::codemap;
|
2013-08-31 18:13:04 +02:00
|
|
|
use syntax::codemap::Span;
|
2015-06-25 13:08:10 -07:00
|
|
|
use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
use self::combine::CombineFields;
|
2014-10-09 17:19:50 -04:00
|
|
|
use self::region_inference::{RegionVarBindings, RegionSnapshot};
|
|
|
|
use self::error_reporting::ErrorReporting;
|
2015-04-07 06:12:21 -04:00
|
|
|
use self::unify_key::ToType;
|
2014-10-09 17:19:50 -04:00
|
|
|
|
2015-02-12 05:16:02 -05:00
|
|
|
pub mod bivariate;
|
2013-01-29 16:26:16 -08:00
|
|
|
pub mod combine;
|
2014-07-22 07:46:36 -04:00
|
|
|
pub mod equate;
|
|
|
|
pub mod error_reporting;
|
2013-01-29 16:26:16 -08:00
|
|
|
pub mod glb;
|
2014-12-12 14:55:07 -05:00
|
|
|
mod higher_ranked;
|
2013-01-29 16:26:16 -08:00
|
|
|
pub mod lattice;
|
|
|
|
pub mod lub;
|
|
|
|
pub mod region_inference;
|
|
|
|
pub mod resolve;
|
2014-12-12 06:13:42 -05:00
|
|
|
mod freshen;
|
2013-01-29 16:26:16 -08:00
|
|
|
pub mod sub;
|
2014-07-22 07:46:36 -04:00
|
|
|
pub mod type_variable;
|
2015-04-07 06:12:21 -04:00
|
|
|
pub mod unify_key;
|
2013-01-29 16:26:16 -08:00
|
|
|
|
|
|
|
pub type Bound<T> = Option<T>;
|
2015-03-22 15:11:56 -04:00
|
|
|
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
|
2013-01-29 16:26:16 -08:00
|
|
|
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
|
|
|
|
|
2014-04-22 15:56:37 +03:00
|
|
|
pub struct InferCtxt<'a, 'tcx: 'a> {
|
|
|
|
pub tcx: &'a ty::ctxt<'tcx>,
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2015-06-25 13:08:10 -07:00
|
|
|
pub tables: &'a RefCell<ty::Tables<'tcx>>,
|
|
|
|
|
2014-09-13 21:09:25 +03:00
|
|
|
// We instantiate UnificationTable with bounds<Ty> because the
|
2012-11-29 16:41:39 -08:00
|
|
|
// types that might instantiate a general type variable have an
|
|
|
|
// order, represented by its upper and lower bounds.
|
2014-09-29 22:11:30 +03:00
|
|
|
type_variables: RefCell<type_variable::TypeVariableTable<'tcx>>,
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2013-01-22 07:02:40 -08:00
|
|
|
// Map from integral variable to the kind of integer it represents
|
2015-01-21 20:25:24 -05:00
|
|
|
int_unification_table: RefCell<UnificationTable<ty::IntVid>>,
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2013-01-22 07:02:40 -08:00
|
|
|
// Map from floating variable to the kind of float it represents
|
2015-01-21 20:25:24 -05:00
|
|
|
float_unification_table: RefCell<UnificationTable<ty::FloatVid>>,
|
2012-11-29 16:41:39 -08:00
|
|
|
|
|
|
|
// For region variables.
|
2015-01-21 20:25:24 -05:00
|
|
|
region_vars: RegionVarBindings<'a, 'tcx>,
|
2015-06-24 13:40:54 -07:00
|
|
|
|
|
|
|
pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>,
|
|
|
|
|
2015-06-25 13:08:10 -07:00
|
|
|
normalize: bool,
|
|
|
|
|
|
|
|
err_count_on_creation: usize,
|
2013-01-08 14:00:45 -08:00
|
|
|
}
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2014-12-12 14:55:07 -05:00
|
|
|
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
|
2014-12-12 06:37:42 -05:00
|
|
|
/// region that each late-bound region was replaced with.
|
|
|
|
pub type SkolemizationMap = FnvHashMap<ty::BoundRegion,ty::Region>;
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
/// Why did we require that the two types be related?
|
|
|
|
///
|
|
|
|
/// See `error_reporting.rs` for more details
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
2013-06-05 21:04:07 -04:00
|
|
|
pub enum TypeOrigin {
|
2013-05-23 21:37:37 -04:00
|
|
|
// Not yet categorized in a better way
|
2013-08-31 18:13:04 +02:00
|
|
|
Misc(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Checking that method of impl is compatible with trait
|
2013-08-31 18:13:04 +02:00
|
|
|
MethodCompatCheck(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Checking that this expression can be assigned where it needs to be
|
2014-01-06 14:00:46 +02:00
|
|
|
// FIXME(eddyb) #11161 is the original Expr required?
|
|
|
|
ExprAssignable(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Relating trait refs when resolving vtables
|
2013-08-31 18:13:04 +02:00
|
|
|
RelateTraitRefs(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-09-12 10:53:35 -04:00
|
|
|
// Relating self types when resolving vtables
|
2013-08-31 18:13:04 +02:00
|
|
|
RelateSelfType(Span),
|
2013-06-05 21:04:07 -04:00
|
|
|
|
2014-09-12 10:53:35 -04:00
|
|
|
// Relating trait type parameters to those found in impl etc
|
|
|
|
RelateOutputImplTypes(Span),
|
|
|
|
|
2014-05-31 00:16:33 +02:00
|
|
|
// Computing common supertype in the arms of a match expression
|
|
|
|
MatchExpressionArm(Span, Span),
|
2013-06-05 21:04:07 -04:00
|
|
|
|
|
|
|
// Computing common supertype in an if expression
|
2013-08-31 18:13:04 +02:00
|
|
|
IfExpression(Span),
|
2014-10-13 22:26:23 +02:00
|
|
|
|
|
|
|
// Computing common supertype of an if expression with no else counter-part
|
2014-12-06 01:30:41 -05:00
|
|
|
IfExpressionWithNoElse(Span),
|
|
|
|
|
2014-12-16 16:25:33 +13:00
|
|
|
// Computing common supertype in a range expression
|
|
|
|
RangeExpression(Span),
|
|
|
|
|
2014-12-06 01:30:41 -05:00
|
|
|
// `where a == b`
|
|
|
|
EquatePredicate(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
|
2015-03-24 20:55:02 -07:00
|
|
|
impl TypeOrigin {
|
|
|
|
fn as_str(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
&TypeOrigin::Misc(_) |
|
|
|
|
&TypeOrigin::RelateSelfType(_) |
|
|
|
|
&TypeOrigin::RelateOutputImplTypes(_) |
|
2015-03-19 14:49:28 -07:00
|
|
|
&TypeOrigin::ExprAssignable(_) => "mismatched types",
|
|
|
|
&TypeOrigin::RelateTraitRefs(_) => "mismatched traits",
|
2015-03-24 20:55:02 -07:00
|
|
|
&TypeOrigin::MethodCompatCheck(_) => "method not compatible with trait",
|
2015-03-19 14:49:28 -07:00
|
|
|
&TypeOrigin::MatchExpressionArm(_, _) => "match arms have incompatible types",
|
|
|
|
&TypeOrigin::IfExpression(_) => "if and else have incompatible types",
|
|
|
|
&TypeOrigin::IfExpressionWithNoElse(_) => "if may be missing an else clause",
|
|
|
|
&TypeOrigin::RangeExpression(_) => "start and end of range have incompatible types",
|
|
|
|
&TypeOrigin::EquatePredicate(_) => "equality predicate not satisfied",
|
2015-03-24 20:55:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TypeOrigin {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error> {
|
|
|
|
fmt::Display::fmt(self.as_str(), f)
|
2015-03-19 14:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
/// See `error_reporting.rs` for more details
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, Debug)]
|
2014-09-29 22:11:30 +03:00
|
|
|
pub enum ValuePairs<'tcx> {
|
|
|
|
Types(ty::expected_found<Ty<'tcx>>),
|
2015-04-21 18:59:58 +03:00
|
|
|
TraitRefs(ty::expected_found<ty::TraitRef<'tcx>>),
|
2014-12-17 14:16:28 -05:00
|
|
|
PolyTraitRefs(ty::expected_found<ty::PolyTraitRef<'tcx>>),
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The trace designates the path through inference that we took to
|
|
|
|
/// encounter an error or subtyping constraint.
|
|
|
|
///
|
|
|
|
/// See `error_reporting.rs` for more details.
|
2015-06-18 08:51:23 +03:00
|
|
|
#[derive(Clone)]
|
2014-09-29 22:11:30 +03:00
|
|
|
pub struct TypeTrace<'tcx> {
|
2013-06-05 21:04:07 -04:00
|
|
|
origin: TypeOrigin,
|
2014-09-29 22:11:30 +03:00
|
|
|
values: ValuePairs<'tcx>,
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The origin of a `r1 <= r2` constraint.
|
|
|
|
///
|
|
|
|
/// See `error_reporting.rs` for more details
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, Debug)]
|
2014-09-29 22:11:30 +03:00
|
|
|
pub enum SubregionOrigin<'tcx> {
|
2013-05-23 21:37:37 -04:00
|
|
|
// Arose from a subtyping relation
|
2014-09-29 22:11:30 +03:00
|
|
|
Subtype(TypeTrace<'tcx>),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2013-06-25 12:04:50 -04:00
|
|
|
// Stack-allocated closures cannot outlive innermost loop
|
|
|
|
// or function so as to ensure we only require finite stack
|
2013-08-31 18:13:04 +02:00
|
|
|
InfStackClosure(Span),
|
2013-06-25 12:04:50 -04:00
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
// Invocation of closure must be within its lifetime
|
2013-08-31 18:13:04 +02:00
|
|
|
InvokeClosure(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-01-07 18:49:13 -08:00
|
|
|
// Dereference of reference must be within its lifetime
|
2013-08-31 18:13:04 +02:00
|
|
|
DerefPointer(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Closure bound must not outlive captured free variables
|
2014-02-07 14:43:48 -05:00
|
|
|
FreeVariable(Span, ast::NodeId),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Index into slice must be within its lifetime
|
2013-08-31 18:13:04 +02:00
|
|
|
IndexSlice(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// When casting `&'a T` to an `&'b Trait` object,
|
|
|
|
// relating `'a` to `'b`
|
2013-08-31 18:13:04 +02:00
|
|
|
RelateObjectBound(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-11-15 17:25:05 -05:00
|
|
|
// Some type parameter was instantiated with the given type,
|
2014-08-27 21:46:52 -04:00
|
|
|
// and that type must outlive some region.
|
2014-09-29 22:11:30 +03:00
|
|
|
RelateParamBound(Span, Ty<'tcx>),
|
2014-08-27 21:46:52 -04:00
|
|
|
|
|
|
|
// The given region parameter was instantiated with a region
|
|
|
|
// that must outlive some other region.
|
|
|
|
RelateRegionParamBound(Span),
|
|
|
|
|
|
|
|
// A bound placed on type parameters that states that must outlive
|
|
|
|
// the moment of their instantiation.
|
2014-09-29 22:11:30 +03:00
|
|
|
RelateDefaultParamBound(Span, Ty<'tcx>),
|
2014-08-27 21:46:52 -04:00
|
|
|
|
2014-01-07 18:49:13 -08:00
|
|
|
// Creating a pointer `b` to contents of another reference
|
2013-08-31 18:13:04 +02:00
|
|
|
Reborrow(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-02-07 14:43:48 -05:00
|
|
|
// Creating a pointer `b` to contents of an upvar
|
|
|
|
ReborrowUpvar(Span, ty::UpvarId),
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
// (&'a &'b T) where a >= b
|
2014-09-29 22:11:30 +03:00
|
|
|
ReferenceOutlivesReferent(Ty<'tcx>, Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
// The type T of an expression E must outlive the lifetime for E.
|
2014-09-29 22:11:30 +03:00
|
|
|
ExprTypeIsNotInScope(Ty<'tcx>, Span),
|
2014-08-27 21:46:52 -04:00
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
// A `ref b` whose region does not enclose the decl site
|
2013-08-31 18:13:04 +02:00
|
|
|
BindingTypeIsNotValidAtDecl(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Regions appearing in a method receiver must outlive method call
|
2013-08-31 18:13:04 +02:00
|
|
|
CallRcvr(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Regions appearing in a function argument must outlive func call
|
2013-08-31 18:13:04 +02:00
|
|
|
CallArg(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Region in return type of invoked fn must enclose call
|
2013-08-31 18:13:04 +02:00
|
|
|
CallReturn(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2015-02-12 12:48:54 -05:00
|
|
|
// Operands must be in scope
|
|
|
|
Operand(Span),
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
// Region resulting from a `&` expr must enclose the `&` expr
|
2013-08-31 18:13:04 +02:00
|
|
|
AddrOf(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// An auto-borrow that does not enclose the expr where it occurs
|
2013-08-31 18:13:04 +02:00
|
|
|
AutoBorrow(Span),
|
2014-10-27 12:55:16 +01:00
|
|
|
|
|
|
|
// Region constraint arriving from destructor safety
|
|
|
|
SafeDestructor(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
|
2014-11-05 22:06:04 -05:00
|
|
|
/// Times when we replace late-bound regions with variables:
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
2014-11-05 22:06:04 -05:00
|
|
|
pub enum LateBoundRegionConversionTime {
|
|
|
|
/// when a fn is called
|
|
|
|
FnCall,
|
|
|
|
|
2014-11-15 16:22:22 -05:00
|
|
|
/// when two higher-ranked types are compared
|
|
|
|
HigherRankedType,
|
2014-12-17 14:16:28 -05:00
|
|
|
|
|
|
|
/// when projecting an associated type
|
|
|
|
AssocTypeProjection(ast::Name),
|
2014-11-05 22:06:04 -05:00
|
|
|
}
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
/// Reasons to create a region inference variable
|
|
|
|
///
|
|
|
|
/// See `error_reporting.rs` for more details
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, Debug)]
|
2015-03-10 07:02:27 -04:00
|
|
|
pub enum RegionVariableOrigin {
|
2013-05-23 21:37:37 -04:00
|
|
|
// Region variables created for ill-categorized reasons,
|
|
|
|
// mostly indicates places in need of refactoring
|
2013-08-31 18:13:04 +02:00
|
|
|
MiscVariable(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Regions created by a `&P` or `[...]` pattern
|
2013-08-31 18:13:04 +02:00
|
|
|
PatternRegion(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Regions created by `&` operator
|
2013-08-31 18:13:04 +02:00
|
|
|
AddrOfRegion(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Regions created as part of an autoref of a method receiver
|
2013-08-31 18:13:04 +02:00
|
|
|
Autoref(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
|
|
|
// Regions created as part of an automatic coercion
|
2015-03-10 07:02:27 -04:00
|
|
|
Coercion(Span),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-03-07 08:43:39 +01:00
|
|
|
// Region variables created as the values for early-bound regions
|
|
|
|
EarlyBoundRegion(Span, ast::Name),
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
// Region variables created for bound regions
|
|
|
|
// in a function or method that is called
|
2014-11-05 22:06:04 -05:00
|
|
|
LateBoundRegion(Span, ty::BoundRegion, LateBoundRegionConversionTime),
|
2013-05-23 21:37:37 -04:00
|
|
|
|
2014-02-07 14:43:48 -05:00
|
|
|
UpvarRegion(ty::UpvarId, Span),
|
|
|
|
|
2014-03-07 08:43:39 +01:00
|
|
|
BoundRegionInCoherence(ast::Name),
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
|
2015-03-30 09:38:44 -04:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2013-01-29 16:26:16 -08:00
|
|
|
pub enum fixup_err {
|
2012-11-29 16:41:39 -08:00
|
|
|
unresolved_int_ty(IntVid),
|
2014-04-21 17:58:52 -04:00
|
|
|
unresolved_float_ty(FloatVid),
|
2014-09-20 15:37:14 +02:00
|
|
|
unresolved_ty(TyVid)
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
pub fn fixup_err_to_string(f: fixup_err) -> String {
|
2012-11-29 16:41:39 -08:00
|
|
|
match f {
|
2014-06-27 12:30:25 -07:00
|
|
|
unresolved_int_ty(_) => {
|
|
|
|
"cannot determine the type of this integer; add a suffix to \
|
|
|
|
specify the type explicitly".to_string()
|
|
|
|
}
|
2014-04-21 17:58:52 -04:00
|
|
|
unresolved_float_ty(_) => {
|
2014-06-27 12:30:25 -07:00
|
|
|
"cannot determine the type of this number; add a suffix to specify \
|
|
|
|
the type explicitly".to_string()
|
2014-04-21 17:58:52 -04:00
|
|
|
}
|
2014-05-25 03:17:19 -07:00
|
|
|
unresolved_ty(_) => "unconstrained type".to_string(),
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:40:54 -07:00
|
|
|
pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
|
2015-06-25 13:08:10 -07:00
|
|
|
tables: &'a RefCell<ty::Tables<'tcx>>,
|
2015-06-24 13:40:54 -07:00
|
|
|
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>)
|
2014-04-22 15:56:37 +03:00
|
|
|
-> InferCtxt<'a, 'tcx> {
|
2014-02-07 00:38:33 +02:00
|
|
|
InferCtxt {
|
2013-01-08 14:00:45 -08:00
|
|
|
tcx: tcx,
|
2015-06-25 13:08:10 -07:00
|
|
|
tables: tables,
|
2014-07-22 07:46:36 -04:00
|
|
|
type_variables: RefCell::new(type_variable::TypeVariableTable::new()),
|
2014-06-20 06:35:06 -04:00
|
|
|
int_unification_table: RefCell::new(UnificationTable::new()),
|
|
|
|
float_unification_table: RefCell::new(UnificationTable::new()),
|
2014-05-28 20:36:05 +01:00
|
|
|
region_vars: RegionVarBindings::new(tcx),
|
2015-06-25 13:08:10 -07:00
|
|
|
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
|
|
|
|
normalize: true,
|
|
|
|
err_count_on_creation: tcx.sess.err_count()
|
2013-01-08 14:00:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 21:17:11 -05:00
|
|
|
/// Computes the least upper-bound of `a` and `b`. If this is not possible, reports an error and
|
|
|
|
/// returns ty::err.
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn common_supertype<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
|
|
|
|
origin: TypeOrigin,
|
|
|
|
a_is_expected: bool,
|
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
|
|
|
-> Ty<'tcx>
|
2014-06-20 06:35:06 -04:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("common_supertype({:?}, {:?})",
|
|
|
|
a, b);
|
2013-06-05 21:04:07 -04:00
|
|
|
|
|
|
|
let trace = TypeTrace {
|
|
|
|
origin: origin,
|
|
|
|
values: Types(expected_found(a_is_expected, a, b))
|
|
|
|
};
|
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
let result = cx.commit_if_ok(|_| cx.lub(a_is_expected, trace.clone()).relate(&a, &b));
|
2013-06-05 21:04:07 -04:00
|
|
|
match result {
|
|
|
|
Ok(t) => t,
|
|
|
|
Err(ref err) => {
|
|
|
|
cx.report_and_explain_type_error(trace, err);
|
2014-12-25 07:20:48 -05:00
|
|
|
cx.tcx.types.err
|
2013-06-05 21:04:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
|
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-09-12 10:53:35 -04:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("mk_subty({:?} <: {:?})", a, b);
|
2015-03-10 07:02:27 -04:00
|
|
|
cx.sub_types(a_is_expected, origin, a, b)
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
|
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx> {
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("can_mk_subty({:?} <: {:?})", a, b);
|
2014-12-14 07:17:23 -05:00
|
|
|
cx.probe(|_| {
|
2014-06-20 06:35:06 -04:00
|
|
|
let trace = TypeTrace {
|
|
|
|
origin: Misc(codemap::DUMMY_SP),
|
|
|
|
values: Types(expected_found(true, a, b))
|
|
|
|
};
|
2015-03-22 15:11:56 -04:00
|
|
|
cx.sub(true, trace).relate(&a, &b).map(|_| ())
|
2014-09-12 10:53:35 -04:00
|
|
|
})
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
pub fn can_mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>)
|
|
|
|
-> UnitResult<'tcx>
|
2015-01-05 21:50:01 -05:00
|
|
|
{
|
|
|
|
cx.can_equate(&a, &b)
|
2014-09-09 02:15:30 +02:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn mk_subr<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
|
|
|
|
origin: SubregionOrigin<'tcx>,
|
|
|
|
a: ty::Region,
|
|
|
|
b: ty::Region) {
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("mk_subr({:?} <: {:?})", a, b);
|
2014-06-20 06:35:06 -04:00
|
|
|
let snapshot = cx.region_vars.start_snapshot();
|
2013-05-23 21:37:37 -04:00
|
|
|
cx.region_vars.make_subregion(origin, a, b);
|
2014-06-20 06:35:06 -04:00
|
|
|
cx.region_vars.commit(snapshot);
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
|
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-06-20 06:35:06 -04:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("mk_eqty({:?} <: {:?})", a, b);
|
2015-03-10 07:02:27 -04:00
|
|
|
cx.commit_if_ok(|_| cx.eq_types(a_is_expected, origin, a, b))
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-12-11 13:37:37 -05:00
|
|
|
pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
|
2014-09-29 22:11:30 +03:00
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
2014-12-17 14:16:28 -05:00
|
|
|
a: ty::PolyTraitRef<'tcx>,
|
|
|
|
b: ty::PolyTraitRef<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2013-03-27 06:16:28 -04:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("mk_sub_trait_refs({:?} <: {:?})",
|
|
|
|
a, b);
|
2015-03-10 07:02:27 -04:00
|
|
|
cx.commit_if_ok(|_| cx.sub_poly_trait_refs(a_is_expected, origin, a.clone(), b.clone()))
|
2013-03-27 06:16:28 -04:00
|
|
|
}
|
|
|
|
|
2013-05-23 21:37:37 -04:00
|
|
|
fn expected_found<T>(a_is_expected: bool,
|
|
|
|
a: T,
|
2014-09-12 10:53:35 -04:00
|
|
|
b: T)
|
|
|
|
-> ty::expected_found<T>
|
|
|
|
{
|
2013-05-23 21:37:37 -04:00
|
|
|
if a_is_expected {
|
|
|
|
ty::expected_found {expected: a, found: b}
|
|
|
|
} else {
|
|
|
|
ty::expected_found {expected: b, found: a}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:11:59 -05:00
|
|
|
#[must_use = "once you start a snapshot, you should always consume it"]
|
2014-06-20 06:35:06 -04:00
|
|
|
pub struct CombinedSnapshot {
|
2014-07-22 07:46:36 -04:00
|
|
|
type_snapshot: type_variable::Snapshot,
|
|
|
|
int_snapshot: unify::Snapshot<ty::IntVid>,
|
|
|
|
float_snapshot: unify::Snapshot<ty::FloatVid>,
|
2014-06-20 06:35:06 -04:00
|
|
|
region_vars_snapshot: RegionSnapshot,
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-06-25 13:08:10 -07:00
|
|
|
impl<'a, 'tcx> mc::Typer<'tcx> for InferCtxt<'a, 'tcx> {
|
|
|
|
fn node_ty(&self, id: ast::NodeId) -> McResult<Ty<'tcx>> {
|
|
|
|
let ty = self.node_ty(id);
|
|
|
|
self.resolve_type_vars_or_error(&ty)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<Ty<'tcx>> {
|
|
|
|
let ty = self.adjust_expr_ty(expr, self.tables.borrow().adjustments.get(&expr.id));
|
|
|
|
self.resolve_type_vars_or_error(&ty)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
|
|
|
let ty = self.resolve_type_vars_if_possible(&ty);
|
|
|
|
!traits::type_known_to_meet_builtin_bound(self, self, ty, ty::BoundCopy, span)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn node_method_ty(&self, method_call: ty::MethodCall)
|
|
|
|
-> Option<Ty<'tcx>> {
|
|
|
|
self.tables
|
|
|
|
.borrow()
|
|
|
|
.method_map
|
|
|
|
.get(&method_call)
|
|
|
|
.map(|method| method.ty)
|
|
|
|
.map(|ty| self.resolve_type_vars_if_possible(&ty))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn node_method_origin(&self, method_call: ty::MethodCall)
|
|
|
|
-> Option<ty::MethodOrigin<'tcx>>
|
|
|
|
{
|
|
|
|
self.tables
|
|
|
|
.borrow()
|
|
|
|
.method_map
|
|
|
|
.get(&method_call)
|
|
|
|
.map(|method| method.origin.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
|
|
|
|
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
|
|
|
|
&tables.adjustments
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref::map(self.tables.borrow(), project_adjustments)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_method_call(&self, id: ast::NodeId) -> bool {
|
|
|
|
self.tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<CodeExtent> {
|
|
|
|
self.parameter_environment.temporary_scope(rvalue_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
|
|
|
|
self.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> ty::ClosureTyper<'tcx> for InferCtxt<'a, 'tcx> {
|
|
|
|
fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
|
|
|
|
&self.parameter_environment
|
|
|
|
}
|
|
|
|
|
|
|
|
fn closure_kind(&self,
|
|
|
|
def_id: ast::DefId)
|
|
|
|
-> Option<ty::ClosureKind>
|
|
|
|
{
|
|
|
|
self.tables.borrow().closure_kinds.get(&def_id).cloned()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn closure_type(&self,
|
|
|
|
def_id: ast::DefId,
|
|
|
|
substs: &subst::Substs<'tcx>)
|
|
|
|
-> ty::ClosureTy<'tcx>
|
|
|
|
{
|
|
|
|
self.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx, substs)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn closure_upvars(&self,
|
|
|
|
def_id: ast::DefId,
|
|
|
|
substs: &Substs<'tcx>)
|
|
|
|
-> Option<Vec<ty::ClosureUpvar<'tcx>>>
|
|
|
|
{
|
|
|
|
ty::ctxt::closure_upvars(self, def_id, substs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:56:37 +03:00
|
|
|
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
2014-12-12 06:13:42 -05:00
|
|
|
pub fn freshen<T:TypeFoldable<'tcx>>(&self, t: T) -> T {
|
|
|
|
t.fold_with(&mut self.freshener())
|
2014-10-09 17:19:50 -04:00
|
|
|
}
|
|
|
|
|
2014-09-13 21:09:25 +03:00
|
|
|
pub fn type_var_diverges(&'a self, ty: Ty) -> bool {
|
2014-10-31 10:51:16 +02:00
|
|
|
match ty.sty {
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(ty::TyVar(vid)) => self.type_variables.borrow().var_diverges(vid),
|
2014-10-24 21:14:37 +02:00
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:13:42 -05:00
|
|
|
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {
|
|
|
|
freshen::TypeFreshener::new(self)
|
2014-09-18 11:08:04 -04:00
|
|
|
}
|
|
|
|
|
2014-12-15 09:45:28 -05:00
|
|
|
pub fn type_is_unconstrained_numeric(&'a self, ty: Ty) -> UnconstrainedNumeric {
|
|
|
|
use middle::ty::UnconstrainedNumeric::{Neither, UnconstrainedInt, UnconstrainedFloat};
|
|
|
|
match ty.sty {
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(ty::IntVar(vid)) => {
|
2015-02-16 05:07:22 -05:00
|
|
|
if self.int_unification_table.borrow_mut().has_value(vid) {
|
|
|
|
Neither
|
|
|
|
} else {
|
|
|
|
UnconstrainedInt
|
2014-12-15 09:45:28 -05:00
|
|
|
}
|
|
|
|
},
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(ty::FloatVar(vid)) => {
|
2015-02-16 05:07:22 -05:00
|
|
|
if self.float_unification_table.borrow_mut().has_value(vid) {
|
|
|
|
Neither
|
|
|
|
} else {
|
|
|
|
UnconstrainedFloat
|
2014-12-15 09:45:28 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => Neither,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
fn combine_fields(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>)
|
|
|
|
-> CombineFields<'a, 'tcx> {
|
2013-03-12 17:33:54 -07:00
|
|
|
CombineFields {infcx: self,
|
2013-01-08 14:00:45 -08:00
|
|
|
a_is_expected: a_is_expected,
|
2013-05-23 21:37:37 -04:00
|
|
|
trace: trace}
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
// public so that it can be used from the rustc_driver unit tests
|
|
|
|
pub fn equate(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>)
|
|
|
|
-> equate::Equate<'a, 'tcx>
|
|
|
|
{
|
|
|
|
self.combine_fields(a_is_expected, trace).equate()
|
2014-07-22 07:46:36 -04:00
|
|
|
}
|
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
// public so that it can be used from the rustc_driver unit tests
|
|
|
|
pub fn sub(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>)
|
|
|
|
-> sub::Sub<'a, 'tcx>
|
|
|
|
{
|
|
|
|
self.combine_fields(a_is_expected, trace).sub()
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
// public so that it can be used from the rustc_driver unit tests
|
|
|
|
pub fn lub(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>)
|
|
|
|
-> lub::Lub<'a, 'tcx>
|
|
|
|
{
|
|
|
|
self.combine_fields(a_is_expected, trace).lub()
|
|
|
|
}
|
|
|
|
|
|
|
|
// public so that it can be used from the rustc_driver unit tests
|
|
|
|
pub fn glb(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>)
|
|
|
|
-> glb::Glb<'a, 'tcx>
|
|
|
|
{
|
|
|
|
self.combine_fields(a_is_expected, trace).glb()
|
2013-06-05 21:04:07 -04:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:35:06 -04:00
|
|
|
fn start_snapshot(&self) -> CombinedSnapshot {
|
|
|
|
CombinedSnapshot {
|
2014-07-22 07:46:36 -04:00
|
|
|
type_snapshot: self.type_variables.borrow_mut().snapshot(),
|
2014-06-20 06:35:06 -04:00
|
|
|
int_snapshot: self.int_unification_table.borrow_mut().snapshot(),
|
|
|
|
float_snapshot: self.float_unification_table.borrow_mut().snapshot(),
|
2013-12-19 20:35:14 -08:00
|
|
|
region_vars_snapshot: self.region_vars.start_snapshot(),
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:35:06 -04:00
|
|
|
fn rollback_to(&self, snapshot: CombinedSnapshot) {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("rollback!");
|
2014-06-20 06:35:06 -04:00
|
|
|
let CombinedSnapshot { type_snapshot,
|
|
|
|
int_snapshot,
|
|
|
|
float_snapshot,
|
|
|
|
region_vars_snapshot } = snapshot;
|
|
|
|
|
2014-07-22 07:46:36 -04:00
|
|
|
self.type_variables
|
2014-06-20 06:35:06 -04:00
|
|
|
.borrow_mut()
|
2014-07-22 07:40:51 -04:00
|
|
|
.rollback_to(type_snapshot);
|
2014-06-20 06:35:06 -04:00
|
|
|
self.int_unification_table
|
|
|
|
.borrow_mut()
|
2014-07-22 07:40:51 -04:00
|
|
|
.rollback_to(int_snapshot);
|
2014-06-20 06:35:06 -04:00
|
|
|
self.float_unification_table
|
|
|
|
.borrow_mut()
|
2014-07-22 07:40:51 -04:00
|
|
|
.rollback_to(float_snapshot);
|
2014-06-20 06:35:06 -04:00
|
|
|
self.region_vars
|
|
|
|
.rollback_to(region_vars_snapshot);
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:35:06 -04:00
|
|
|
fn commit_from(&self, snapshot: CombinedSnapshot) {
|
|
|
|
debug!("commit_from!");
|
|
|
|
let CombinedSnapshot { type_snapshot,
|
|
|
|
int_snapshot,
|
|
|
|
float_snapshot,
|
|
|
|
region_vars_snapshot } = snapshot;
|
|
|
|
|
2014-07-22 07:46:36 -04:00
|
|
|
self.type_variables
|
2014-06-20 06:35:06 -04:00
|
|
|
.borrow_mut()
|
|
|
|
.commit(type_snapshot);
|
|
|
|
self.int_unification_table
|
|
|
|
.borrow_mut()
|
|
|
|
.commit(int_snapshot);
|
|
|
|
self.float_unification_table
|
|
|
|
.borrow_mut()
|
|
|
|
.commit(float_snapshot);
|
|
|
|
self.region_vars
|
|
|
|
.commit(region_vars_snapshot);
|
|
|
|
}
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2014-06-20 06:35:06 -04:00
|
|
|
/// Execute `f` and commit the bindings
|
2014-12-08 20:26:43 -05:00
|
|
|
pub fn commit_unconditionally<R, F>(&self, f: F) -> R where
|
|
|
|
F: FnOnce() -> R,
|
|
|
|
{
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("commit()");
|
2014-06-20 06:35:06 -04:00
|
|
|
let snapshot = self.start_snapshot();
|
|
|
|
let r = f();
|
|
|
|
self.commit_from(snapshot);
|
|
|
|
r
|
|
|
|
}
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2015-03-10 07:02:27 -04:00
|
|
|
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`
|
2014-12-08 20:26:43 -05:00
|
|
|
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where
|
2015-03-10 07:02:27 -04:00
|
|
|
F: FnOnce(&CombinedSnapshot) -> Result<T, E>
|
2014-12-08 20:26:43 -05:00
|
|
|
{
|
2015-03-10 07:02:27 -04:00
|
|
|
debug!("commit_if_ok()");
|
|
|
|
let snapshot = self.start_snapshot();
|
|
|
|
let r = f(&snapshot);
|
|
|
|
debug!("commit_if_ok() -- r.is_ok() = {}", r.is_ok());
|
|
|
|
match r {
|
|
|
|
Ok(_) => { self.commit_from(snapshot); }
|
|
|
|
Err(_) => { self.rollback_to(snapshot); }
|
|
|
|
}
|
|
|
|
r
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-01-08 18:25:52 +02:00
|
|
|
/// Execute `f` and commit only the region bindings if successful.
|
|
|
|
/// The function f must be very careful not to leak any non-region
|
|
|
|
/// variables that get created.
|
|
|
|
pub fn commit_regions_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where
|
|
|
|
F: FnOnce() -> Result<T, E>
|
|
|
|
{
|
|
|
|
debug!("commit_regions_if_ok()");
|
|
|
|
let CombinedSnapshot { type_snapshot,
|
|
|
|
int_snapshot,
|
|
|
|
float_snapshot,
|
|
|
|
region_vars_snapshot } = self.start_snapshot();
|
|
|
|
|
2015-03-10 07:02:27 -04:00
|
|
|
let r = self.commit_if_ok(|_| f());
|
2015-01-08 18:25:52 +02:00
|
|
|
|
|
|
|
// Roll back any non-region bindings - they should be resolved
|
|
|
|
// inside `f`, with, e.g. `resolve_type_vars_if_possible`.
|
|
|
|
self.type_variables
|
|
|
|
.borrow_mut()
|
|
|
|
.rollback_to(type_snapshot);
|
|
|
|
self.int_unification_table
|
|
|
|
.borrow_mut()
|
|
|
|
.rollback_to(int_snapshot);
|
|
|
|
self.float_unification_table
|
|
|
|
.borrow_mut()
|
|
|
|
.rollback_to(float_snapshot);
|
|
|
|
|
|
|
|
// Commit region vars that may escape through resolved types.
|
|
|
|
self.region_vars
|
|
|
|
.commit(region_vars_snapshot);
|
|
|
|
|
|
|
|
r
|
|
|
|
}
|
|
|
|
|
2012-11-29 16:41:39 -08:00
|
|
|
/// Execute `f` then unroll any bindings it creates
|
2014-12-08 20:26:43 -05:00
|
|
|
pub fn probe<R, F>(&self, f: F) -> R where
|
2014-12-14 07:17:23 -05:00
|
|
|
F: FnOnce(&CombinedSnapshot) -> R,
|
2014-12-08 20:26:43 -05:00
|
|
|
{
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("probe()");
|
2014-06-20 06:35:06 -04:00
|
|
|
let snapshot = self.start_snapshot();
|
2014-12-14 07:17:23 -05:00
|
|
|
let r = f(&snapshot);
|
2014-06-20 06:35:06 -04:00
|
|
|
self.rollback_to(snapshot);
|
|
|
|
r
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
2014-08-27 21:46:52 -04:00
|
|
|
|
|
|
|
pub fn add_given(&self,
|
|
|
|
sub: ty::FreeRegion,
|
|
|
|
sup: ty::RegionVid)
|
|
|
|
{
|
|
|
|
self.region_vars.add_given(sub, sup);
|
|
|
|
}
|
2014-09-12 10:53:35 -04:00
|
|
|
|
|
|
|
pub fn sub_types(&self,
|
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
2014-09-29 22:11:30 +03:00
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-09-12 10:53:35 -04:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("sub_types({:?} <: {:?})", a, b);
|
2015-03-10 07:02:27 -04:00
|
|
|
self.commit_if_ok(|_| {
|
2015-01-16 05:48:15 +02:00
|
|
|
let trace = TypeTrace::types(origin, a_is_expected, a, b);
|
2015-03-22 15:11:56 -04:00
|
|
|
self.sub(a_is_expected, trace).relate(&a, &b).map(|_| ())
|
2014-10-09 17:19:50 -04:00
|
|
|
})
|
2014-09-12 10:53:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn eq_types(&self,
|
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
2014-09-29 22:11:30 +03:00
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-09-12 10:53:35 -04:00
|
|
|
{
|
2015-03-10 07:02:27 -04:00
|
|
|
self.commit_if_ok(|_| {
|
2015-01-16 05:48:15 +02:00
|
|
|
let trace = TypeTrace::types(origin, a_is_expected, a, b);
|
2015-03-22 15:11:56 -04:00
|
|
|
self.equate(a_is_expected, trace).relate(&a, &b).map(|_| ())
|
2014-10-09 17:19:50 -04:00
|
|
|
})
|
2014-09-12 10:53:35 -04:00
|
|
|
}
|
|
|
|
|
2014-12-14 07:17:23 -05:00
|
|
|
pub fn sub_trait_refs(&self,
|
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
2015-04-21 18:59:58 +03:00
|
|
|
a: ty::TraitRef<'tcx>,
|
|
|
|
b: ty::TraitRef<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-12-14 07:17:23 -05:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("sub_trait_refs({:?} <: {:?})",
|
|
|
|
a,
|
|
|
|
b);
|
2015-03-10 07:02:27 -04:00
|
|
|
self.commit_if_ok(|_| {
|
2014-12-14 07:17:23 -05:00
|
|
|
let trace = TypeTrace {
|
|
|
|
origin: origin,
|
|
|
|
values: TraitRefs(expected_found(a_is_expected, a.clone(), b.clone()))
|
|
|
|
};
|
2015-04-21 18:59:58 +03:00
|
|
|
self.sub(a_is_expected, trace).relate(&a, &b).map(|_| ())
|
2014-12-14 07:17:23 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-11 13:37:37 -05:00
|
|
|
pub fn sub_poly_trait_refs(&self,
|
|
|
|
a_is_expected: bool,
|
|
|
|
origin: TypeOrigin,
|
2014-12-17 14:16:28 -05:00
|
|
|
a: ty::PolyTraitRef<'tcx>,
|
|
|
|
b: ty::PolyTraitRef<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-09-12 10:53:35 -04:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("sub_poly_trait_refs({:?} <: {:?})",
|
|
|
|
a,
|
|
|
|
b);
|
2015-03-10 07:02:27 -04:00
|
|
|
self.commit_if_ok(|_| {
|
2014-10-09 17:19:50 -04:00
|
|
|
let trace = TypeTrace {
|
|
|
|
origin: origin,
|
2014-12-14 07:17:23 -05:00
|
|
|
values: PolyTraitRefs(expected_found(a_is_expected, a.clone(), b.clone()))
|
2014-10-09 17:19:50 -04:00
|
|
|
};
|
2015-03-22 15:11:56 -04:00
|
|
|
self.sub(a_is_expected, trace).relate(&a, &b).map(|_| ())
|
2014-10-09 17:19:50 -04:00
|
|
|
})
|
2014-09-12 10:53:35 -04:00
|
|
|
}
|
2012-11-29 16:41:39 -08:00
|
|
|
|
Reject specialized Drop impls.
See Issue 8142 for discussion.
This makes it illegal for a Drop impl to be more specialized than the
original item.
So for example, all of the following are now rejected (when they would
have been blindly accepted before):
```rust
struct S<A> { ... };
impl Drop for S<i8> { ... } // error: specialized to concrete type
struct T<'a> { ... };
impl Drop for T<'static> { ... } // error: specialized to concrete region
struct U<A> { ... };
impl<A:Clone> Drop for U<A> { ... } // error: added extra type requirement
struct V<'a,'b>;
impl<'a,'b:a> Drop for V<'a,'b> { ... } // error: added extra region requirement
```
Due to examples like the above, this is a [breaking-change].
(The fix is to either remove the specialization from the `Drop` impl,
or to transcribe the requirements into the struct/enum definition;
examples of both are shown in the PR's fixed to `libstd`.)
----
This is likely to be the last thing blocking the removal of the
`#[unsafe_destructor]` attribute.
Includes two new error codes for the new dropck check.
Update run-pass tests to accommodate new dropck pass.
Update tests and docs to reflect new destructor restriction.
----
Implementation notes:
We identify Drop impl specialization by not being as parametric as the
struct/enum definition via unification.
More specifically:
1. Attempt unification of a skolemized instance of the struct/enum
with an instance of the Drop impl's type expression where all of
the impl's generics (i.e. the free variables of the type
expression) have been replaced with unification variables.
2. If unification fails, then reject Drop impl as specialized.
3. If unification succeeds, check if any of the skolemized
variables "leaked" into the constraint set for the inference
context; if so, then reject Drop impl as specialized.
4. Otherwise, unification succeeded without leaking skolemized
variables: accept the Drop impl.
We identify whether a Drop impl is injecting new predicates by simply
looking whether the predicate, after an appropriate substitution,
appears on the struct/enum definition.
2015-03-21 13:12:08 +01:00
|
|
|
pub fn construct_skolemized_subst(&self,
|
|
|
|
generics: &ty::Generics<'tcx>,
|
|
|
|
snapshot: &CombinedSnapshot)
|
|
|
|
-> (subst::Substs<'tcx>, SkolemizationMap) {
|
|
|
|
/*! See `higher_ranked::construct_skolemized_subst` */
|
|
|
|
|
|
|
|
higher_ranked::construct_skolemized_substs(self, generics, snapshot)
|
|
|
|
}
|
|
|
|
|
2014-12-12 11:28:35 -05:00
|
|
|
pub fn skolemize_late_bound_regions<T>(&self,
|
|
|
|
value: &ty::Binder<T>,
|
|
|
|
snapshot: &CombinedSnapshot)
|
|
|
|
-> (T, SkolemizationMap)
|
2015-06-18 08:51:23 +03:00
|
|
|
where T : TypeFoldable<'tcx>
|
2014-12-12 06:37:42 -05:00
|
|
|
{
|
2014-12-12 14:55:07 -05:00
|
|
|
/*! See `higher_ranked::skolemize_late_bound_regions` */
|
2014-12-12 06:37:42 -05:00
|
|
|
|
2014-12-12 14:55:07 -05:00
|
|
|
higher_ranked::skolemize_late_bound_regions(self, value, snapshot)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn leak_check(&self,
|
|
|
|
skol_map: &SkolemizationMap,
|
|
|
|
snapshot: &CombinedSnapshot)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx>
|
2014-12-12 14:55:07 -05:00
|
|
|
{
|
|
|
|
/*! See `higher_ranked::leak_check` */
|
2014-12-12 06:37:42 -05:00
|
|
|
|
2014-12-13 05:34:34 -05:00
|
|
|
match higher_ranked::leak_check(self, skol_map, snapshot) {
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Err((br, r)) => Err(ty::terr_regions_insufficiently_polymorphic(br, r))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 07:17:23 -05:00
|
|
|
pub fn plug_leaks<T>(&self,
|
|
|
|
skol_map: SkolemizationMap,
|
|
|
|
snapshot: &CombinedSnapshot,
|
|
|
|
value: &T)
|
|
|
|
-> T
|
2015-06-18 08:51:23 +03:00
|
|
|
where T : TypeFoldable<'tcx>
|
2014-12-14 07:17:23 -05:00
|
|
|
{
|
2014-12-17 14:16:28 -05:00
|
|
|
/*! See `higher_ranked::plug_leaks` */
|
2014-12-14 07:17:23 -05:00
|
|
|
|
|
|
|
higher_ranked::plug_leaks(self, skol_map, snapshot, value)
|
|
|
|
}
|
|
|
|
|
2014-12-13 05:34:34 -05:00
|
|
|
pub fn equality_predicate(&self,
|
|
|
|
span: Span,
|
|
|
|
predicate: &ty::PolyEquatePredicate<'tcx>)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx> {
|
2015-03-10 07:02:27 -04:00
|
|
|
self.commit_if_ok(|snapshot| {
|
2014-12-13 05:34:34 -05:00
|
|
|
let (ty::EquatePredicate(a, b), skol_map) =
|
|
|
|
self.skolemize_late_bound_regions(predicate, snapshot);
|
|
|
|
let origin = EquatePredicate(span);
|
|
|
|
let () = try!(mk_eqty(self, false, origin, a, b));
|
|
|
|
self.leak_check(&skol_map, snapshot)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn region_outlives_predicate(&self,
|
|
|
|
span: Span,
|
|
|
|
predicate: &ty::PolyRegionOutlivesPredicate)
|
2015-03-09 16:39:50 -04:00
|
|
|
-> UnitResult<'tcx> {
|
2015-03-10 07:02:27 -04:00
|
|
|
self.commit_if_ok(|snapshot| {
|
2014-12-13 05:34:34 -05:00
|
|
|
let (ty::OutlivesPredicate(r_a, r_b), skol_map) =
|
|
|
|
self.skolemize_late_bound_regions(predicate, snapshot);
|
|
|
|
let origin = RelateRegionParamBound(span);
|
|
|
|
let () = mk_subr(self, origin, r_b, r_a); // `b : a` ==> `a <= b`
|
|
|
|
self.leak_check(&skol_map, snapshot)
|
|
|
|
})
|
2014-12-12 06:37:42 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 21:14:37 +02:00
|
|
|
pub fn next_ty_var_id(&self, diverging: bool) -> TyVid {
|
2014-07-22 07:46:36 -04:00
|
|
|
self.type_variables
|
2014-06-20 06:35:06 -04:00
|
|
|
.borrow_mut()
|
2014-10-24 21:14:37 +02:00
|
|
|
.new_var(diverging)
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn next_ty_var(&self) -> Ty<'tcx> {
|
2015-06-25 04:09:46 +03:00
|
|
|
self.tcx.mk_var(self.next_ty_var_id(false))
|
2014-10-24 21:14:37 +02:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn next_diverging_ty_var(&self) -> Ty<'tcx> {
|
2015-06-25 04:09:46 +03:00
|
|
|
self.tcx.mk_var(self.next_ty_var_id(true))
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
pub fn next_ty_vars(&self, n: usize) -> Vec<Ty<'tcx>> {
|
2015-01-26 15:44:22 -05:00
|
|
|
(0..n).map(|_i| self.next_ty_var()).collect()
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2013-12-20 16:29:57 -08:00
|
|
|
pub fn next_int_var_id(&self) -> IntVid {
|
2014-06-20 06:35:06 -04:00
|
|
|
self.int_unification_table
|
|
|
|
.borrow_mut()
|
|
|
|
.new_key(None)
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2013-12-20 16:29:57 -08:00
|
|
|
pub fn next_float_var_id(&self) -> FloatVid {
|
2014-06-20 06:35:06 -04:00
|
|
|
self.float_unification_table
|
|
|
|
.borrow_mut()
|
|
|
|
.new_key(None)
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2015-03-10 07:02:27 -04:00
|
|
|
pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region {
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin)))
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-03-07 08:43:39 +01:00
|
|
|
pub fn region_vars_for_defs(&self,
|
|
|
|
span: Span,
|
2014-07-04 16:39:28 +02:00
|
|
|
defs: &[ty::RegionParameterDef])
|
2014-05-13 11:35:42 -04:00
|
|
|
-> Vec<ty::Region> {
|
2014-03-07 08:43:39 +01:00
|
|
|
defs.iter()
|
|
|
|
.map(|d| self.next_region_var(EarlyBoundRegion(span, d.name)))
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2014-11-25 21:17:11 -05:00
|
|
|
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
|
|
|
|
/// type/region parameter to a fresh inference variable.
|
2014-09-12 10:53:35 -04:00
|
|
|
pub fn fresh_substs_for_generics(&self,
|
|
|
|
span: Span,
|
2014-09-29 22:11:30 +03:00
|
|
|
generics: &ty::Generics<'tcx>)
|
|
|
|
-> subst::Substs<'tcx>
|
2014-05-31 18:53:13 -04:00
|
|
|
{
|
2014-09-12 10:53:35 -04:00
|
|
|
let type_params =
|
|
|
|
generics.types.map(
|
|
|
|
|_| self.next_ty_var());
|
|
|
|
let region_params =
|
|
|
|
generics.regions.map(
|
|
|
|
|d| self.next_region_var(EarlyBoundRegion(span, d.name)));
|
|
|
|
subst::Substs::new(type_params, region_params)
|
|
|
|
}
|
|
|
|
|
2014-11-25 21:17:11 -05:00
|
|
|
/// Given a set of generics defined on a trait, returns a substitution mapping each output
|
|
|
|
/// type/region parameter to a fresh inference variable, and mapping the self type to
|
|
|
|
/// `self_ty`.
|
2014-09-12 10:53:35 -04:00
|
|
|
pub fn fresh_substs_for_trait(&self,
|
|
|
|
span: Span,
|
2014-09-29 22:11:30 +03:00
|
|
|
generics: &ty::Generics<'tcx>,
|
|
|
|
self_ty: Ty<'tcx>)
|
|
|
|
-> subst::Substs<'tcx>
|
2014-09-12 10:53:35 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
assert!(generics.types.len(subst::SelfSpace) == 1);
|
2014-05-31 18:53:13 -04:00
|
|
|
assert!(generics.types.len(subst::FnSpace) == 0);
|
|
|
|
assert!(generics.regions.len(subst::SelfSpace) == 0);
|
|
|
|
assert!(generics.regions.len(subst::FnSpace) == 0);
|
|
|
|
|
|
|
|
let type_parameter_count = generics.types.len(subst::TypeSpace);
|
2014-10-31 06:36:07 -04:00
|
|
|
let type_parameters = self.next_ty_vars(type_parameter_count);
|
|
|
|
|
2014-07-04 16:39:28 +02:00
|
|
|
let region_param_defs = generics.regions.get_slice(subst::TypeSpace);
|
2014-05-31 18:53:13 -04:00
|
|
|
let regions = self.region_vars_for_defs(span, region_param_defs);
|
2014-10-31 06:36:07 -04:00
|
|
|
|
2014-12-29 16:32:12 -05:00
|
|
|
subst::Substs::new_trait(type_parameters, regions, self_ty)
|
2014-05-31 18:53:13 -04:00
|
|
|
}
|
|
|
|
|
2014-11-15 16:47:59 -05:00
|
|
|
pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> ty::Region {
|
|
|
|
self.region_vars.new_bound(debruijn)
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
|
|
|
|
2015-06-25 13:08:10 -07:00
|
|
|
/// Apply `adjustment` to the type of `expr`
|
|
|
|
pub fn adjust_expr_ty(&self,
|
|
|
|
expr: &ast::Expr,
|
|
|
|
adjustment: Option<&ty::AutoAdjustment<'tcx>>)
|
|
|
|
-> Ty<'tcx>
|
|
|
|
{
|
|
|
|
let raw_ty = self.expr_ty(expr);
|
|
|
|
let raw_ty = self.shallow_resolve(raw_ty);
|
|
|
|
let resolve_ty = |ty: Ty<'tcx>| self.resolve_type_vars_if_possible(&ty);
|
|
|
|
raw_ty.adjust(self.tcx,
|
|
|
|
expr.span,
|
|
|
|
expr.id,
|
|
|
|
adjustment,
|
|
|
|
|method_call| self.tables
|
|
|
|
.borrow()
|
|
|
|
.method_map
|
|
|
|
.get(&method_call)
|
|
|
|
.map(|method| resolve_ty(method.ty)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx> {
|
|
|
|
match self.tables.borrow().node_types.get(&id) {
|
|
|
|
Some(&t) => t,
|
|
|
|
// FIXME
|
|
|
|
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 => self.tcx.types.err,
|
|
|
|
None => {
|
|
|
|
self.tcx.sess.bug(
|
|
|
|
&format!("no type for node {}: {} in fcx",
|
|
|
|
id, self.tcx.map.node_to_string(id)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expr_ty(&self, ex: &ast::Expr) -> Ty<'tcx> {
|
|
|
|
match self.tables.borrow().node_types.get(&ex.id) {
|
|
|
|
Some(&t) => t,
|
|
|
|
None => {
|
|
|
|
self.tcx.sess.bug(&format!("no type for expr in fcx"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 11:23:14 -04:00
|
|
|
pub fn resolve_regions_and_report_errors(&self,
|
|
|
|
free_regions: &FreeRegionMap,
|
|
|
|
subject_node_id: ast::NodeId) {
|
|
|
|
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
|
2013-05-23 21:37:37 -04:00
|
|
|
self.report_region_errors(&errors); // see error_reporting.rs
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
|
2015-06-18 20:25:05 +03:00
|
|
|
self.resolve_type_vars_if_possible(&t).to_string()
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {
|
2014-06-21 03:39:03 -07:00
|
|
|
let tstrs: Vec<String> = ts.iter().map(|t| self.ty_to_string(*t)).collect();
|
2014-05-27 20:44:58 -07:00
|
|
|
format!("({})", tstrs.connect(", "))
|
2013-07-18 17:20:58 -07:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:59:58 +03:00
|
|
|
pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String {
|
2015-06-18 20:25:05 +03:00
|
|
|
self.resolve_type_vars_if_possible(t).to_string()
|
2013-03-27 06:16:28 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
|
2014-10-31 10:51:16 +02:00
|
|
|
match typ.sty {
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(ty::TyVar(v)) => {
|
2014-12-01 12:27:27 -05:00
|
|
|
// Not entirely obvious: if `typ` is a type variable,
|
|
|
|
// it can be resolved to an int/float variable, which
|
|
|
|
// can then be recursively resolved, hence the
|
|
|
|
// recursion. Note though that we prevent type
|
|
|
|
// variables from unifying to other type variables
|
|
|
|
// directly (though they may be embedded
|
|
|
|
// structurally), and we prevent cycles in any case,
|
|
|
|
// so this recursion should always be of very limited
|
|
|
|
// depth.
|
2014-10-09 17:19:50 -04:00
|
|
|
self.type_variables.borrow()
|
|
|
|
.probe(v)
|
2014-12-01 12:27:27 -05:00
|
|
|
.map(|t| self.shallow_resolve(t))
|
2014-10-09 17:19:50 -04:00
|
|
|
.unwrap_or(typ)
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(ty::IntVar(v)) => {
|
2015-02-15 15:16:45 -05:00
|
|
|
self.int_unification_table
|
|
|
|
.borrow_mut()
|
2015-03-10 15:32:25 -04:00
|
|
|
.probe(v)
|
|
|
|
.map(|v| v.to_type(self.tcx))
|
2014-10-09 17:19:50 -04:00
|
|
|
.unwrap_or(typ)
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(ty::FloatVar(v)) => {
|
2015-02-15 15:16:45 -05:00
|
|
|
self.float_unification_table
|
|
|
|
.borrow_mut()
|
2015-03-10 15:32:25 -04:00
|
|
|
.probe(v)
|
|
|
|
.map(|v| v.to_type(self.tcx))
|
2014-10-09 17:19:50 -04:00
|
|
|
.unwrap_or(typ)
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
typ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:11:59 -05:00
|
|
|
pub fn resolve_type_vars_if_possible<T:TypeFoldable<'tcx>>(&self, value: &T) -> T {
|
2014-12-01 12:27:27 -05:00
|
|
|
/*!
|
|
|
|
* Where possible, replaces type/int/float variables in
|
|
|
|
* `value` with their final value. Note that region variables
|
|
|
|
* are unaffected. If a type variable has not been unified, it
|
|
|
|
* is left as is. This is an idempotent operation that does
|
|
|
|
* not affect inference state in any way and so you can do it
|
|
|
|
* at will.
|
|
|
|
*/
|
|
|
|
|
|
|
|
let mut r = resolve::OpportunisticTypeResolver::new(self);
|
2014-12-01 10:11:59 -05:00
|
|
|
value.fold_with(&mut r)
|
2013-03-27 06:16:28 -04:00
|
|
|
}
|
|
|
|
|
2015-06-25 13:08:10 -07:00
|
|
|
fn resolve_type_vars_or_error(&self, t: &Ty<'tcx>) -> mc::McResult<Ty<'tcx>> {
|
|
|
|
let ty = self.resolve_type_vars_if_possible(t);
|
|
|
|
if ty.has_infer_types() || ty.references_error() { Err(()) } else { Ok(ty) }
|
|
|
|
}
|
|
|
|
|
2014-12-01 12:27:27 -05:00
|
|
|
pub fn fully_resolve<T:TypeFoldable<'tcx>>(&self, value: &T) -> fres<T> {
|
|
|
|
/*!
|
|
|
|
* Attempts to resolve all type/region variables in
|
|
|
|
* `value`. Region inference must have been run already (e.g.,
|
|
|
|
* by calling `resolve_regions_and_report_errors`). If some
|
|
|
|
* variable was never unified, an `Err` results.
|
|
|
|
*
|
|
|
|
* This method is idempotent, but it not typically not invoked
|
|
|
|
* except during the writeback phase.
|
|
|
|
*/
|
|
|
|
|
|
|
|
resolve::fully_resolve(self, value)
|
|
|
|
}
|
|
|
|
|
2013-08-12 16:44:07 -07:00
|
|
|
// [Note-Type-error-reporting]
|
2015-06-11 16:21:46 -07:00
|
|
|
// An invariant is that anytime the expected or actual type is TyError (the special
|
2013-08-12 16:44:07 -07:00
|
|
|
// error type, meaning that an error occurred when typechecking this expression),
|
|
|
|
// this is a derived error. The error cascaded from another error (that was already
|
|
|
|
// reported), so it's not useful to display it to the user.
|
|
|
|
// The following four methods -- type_error_message_str, type_error_message_str_with_expected,
|
|
|
|
// type_error_message, and report_mismatched_types -- implement this logic.
|
2015-06-11 16:21:46 -07:00
|
|
|
// They check if either the actual or expected type is TyError, and don't print the error
|
2013-08-12 16:44:07 -07:00
|
|
|
// in this case. The typechecker should only ever report type errors involving mismatched
|
|
|
|
// types using one of these four methods, and should not call span_err directly for such
|
|
|
|
// errors.
|
2014-12-08 20:26:43 -05:00
|
|
|
pub fn type_error_message_str<M>(&self,
|
|
|
|
sp: Span,
|
|
|
|
mk_msg: M,
|
|
|
|
actual_ty: String,
|
|
|
|
err: Option<&ty::type_err<'tcx>>) where
|
|
|
|
M: FnOnce(Option<String>, String) -> String,
|
|
|
|
{
|
2013-05-11 17:51:00 -07:00
|
|
|
self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err)
|
|
|
|
}
|
|
|
|
|
2014-12-08 20:26:43 -05:00
|
|
|
pub fn type_error_message_str_with_expected<M>(&self,
|
|
|
|
sp: Span,
|
|
|
|
mk_msg: M,
|
|
|
|
expected_ty: Option<Ty<'tcx>>,
|
|
|
|
actual_ty: String,
|
|
|
|
err: Option<&ty::type_err<'tcx>>) where
|
|
|
|
M: FnOnce(Option<String>, String) -> String,
|
|
|
|
{
|
2014-12-20 00:09:35 -08:00
|
|
|
debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2014-12-01 10:11:59 -05:00
|
|
|
let resolved_expected = expected_ty.map(|e_ty| self.resolve_type_vars_if_possible(&e_ty));
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 22:35:19 +02:00
|
|
|
|
2015-06-24 02:54:32 +03:00
|
|
|
if !resolved_expected.references_error() {
|
|
|
|
let error_str = err.map_or("".to_string(), |t_err| {
|
|
|
|
format!(" ({})", t_err)
|
|
|
|
});
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 22:35:19 +02:00
|
|
|
|
2015-06-24 02:54:32 +03:00
|
|
|
self.tcx.sess.span_err(sp, &format!("{}{}",
|
|
|
|
mk_msg(resolved_expected.map(|t| self.ty_to_string(t)), actual_ty),
|
|
|
|
error_str));
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 22:35:19 +02:00
|
|
|
|
2015-06-24 02:54:32 +03:00
|
|
|
if let Some(err) = err {
|
2015-06-25 23:42:17 +03:00
|
|
|
self.tcx.note_and_explain_type_err(err, sp)
|
2013-05-11 17:51:00 -07:00
|
|
|
}
|
2013-03-03 07:33:39 -05:00
|
|
|
}
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-12-08 20:26:43 -05:00
|
|
|
pub fn type_error_message<M>(&self,
|
|
|
|
sp: Span,
|
|
|
|
mk_msg: M,
|
|
|
|
actual_ty: Ty<'tcx>,
|
|
|
|
err: Option<&ty::type_err<'tcx>>) where
|
|
|
|
M: FnOnce(String) -> String,
|
|
|
|
{
|
2014-12-01 10:11:59 -05:00
|
|
|
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
|
2013-04-17 19:36:59 -07:00
|
|
|
|
2015-06-11 16:21:46 -07:00
|
|
|
// Don't report an error if actual type is TyError.
|
2015-06-24 02:54:32 +03:00
|
|
|
if actual_ty.references_error() {
|
2013-04-17 19:36:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-08 20:26:43 -05:00
|
|
|
self.type_error_message_str(sp,
|
|
|
|
move |_e, a| { mk_msg(a) },
|
|
|
|
self.ty_to_string(actual_ty), err);
|
2013-04-17 19:36:59 -07:00
|
|
|
}
|
|
|
|
|
2014-02-07 00:38:33 +02:00
|
|
|
pub fn report_mismatched_types(&self,
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 22:35:19 +02:00
|
|
|
span: Span,
|
2014-09-29 22:11:30 +03:00
|
|
|
expected: Ty<'tcx>,
|
|
|
|
actual: Ty<'tcx>,
|
|
|
|
err: &ty::type_err<'tcx>) {
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 22:35:19 +02:00
|
|
|
let trace = TypeTrace {
|
|
|
|
origin: Misc(span),
|
|
|
|
values: Types(ty::expected_found {
|
|
|
|
expected: expected,
|
|
|
|
found: actual
|
|
|
|
})
|
2012-11-29 16:41:39 -08:00
|
|
|
};
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 22:35:19 +02:00
|
|
|
self.report_and_explain_type_error(trace, err);
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
|
|
|
|
2014-11-12 14:11:22 -05:00
|
|
|
pub fn replace_late_bound_regions_with_fresh_var<T>(
|
|
|
|
&self,
|
|
|
|
span: Span,
|
|
|
|
lbrct: LateBoundRegionConversionTime,
|
2014-12-12 11:28:35 -05:00
|
|
|
value: &ty::Binder<T>)
|
2014-11-12 14:11:22 -05:00
|
|
|
-> (T, FnvHashMap<ty::BoundRegion,ty::Region>)
|
2015-06-18 08:51:23 +03:00
|
|
|
where T : TypeFoldable<'tcx>
|
2014-11-05 22:06:04 -05:00
|
|
|
{
|
2015-06-06 02:06:14 +03:00
|
|
|
ty_fold::replace_late_bound_regions(
|
2014-11-15 16:47:59 -05:00
|
|
|
self.tcx,
|
|
|
|
value,
|
2015-01-07 14:05:32 -05:00
|
|
|
|br| self.next_region_var(LateBoundRegion(span, br, lbrct)))
|
2012-11-29 16:41:39 -08:00
|
|
|
}
|
2015-01-03 04:40:33 -05:00
|
|
|
|
|
|
|
/// See `verify_generic_bound` method in `region_inference`
|
|
|
|
pub fn verify_generic_bound(&self,
|
|
|
|
origin: SubregionOrigin<'tcx>,
|
|
|
|
kind: GenericKind<'tcx>,
|
|
|
|
a: ty::Region,
|
|
|
|
bs: Vec<ty::Region>) {
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("verify_generic_bound({:?}, {:?} <: {:?})",
|
|
|
|
kind,
|
|
|
|
a,
|
|
|
|
bs);
|
2015-01-03 04:40:33 -05:00
|
|
|
|
|
|
|
self.region_vars.verify_generic_bound(origin, kind, a, bs);
|
|
|
|
}
|
2015-01-05 21:50:01 -05:00
|
|
|
|
2015-03-22 15:11:56 -04:00
|
|
|
pub fn can_equate<'b,T>(&'b self, a: &T, b: &T) -> UnitResult<'tcx>
|
2015-06-18 20:25:05 +03:00
|
|
|
where T: Relate<'b,'tcx> + fmt::Debug
|
2015-01-05 21:50:01 -05:00
|
|
|
{
|
2015-06-18 20:25:05 +03:00
|
|
|
debug!("can_equate({:?}, {:?})", a, b);
|
2015-01-05 21:50:01 -05:00
|
|
|
self.probe(|_| {
|
|
|
|
// Gin up a dummy trace, since this won't be committed
|
|
|
|
// anyhow. We should make this typetrace stuff more
|
|
|
|
// generic so we don't have to do anything quite this
|
|
|
|
// terrible.
|
|
|
|
let e = self.tcx.types.err;
|
|
|
|
let trace = TypeTrace { origin: Misc(codemap::DUMMY_SP),
|
|
|
|
values: Types(expected_found(true, e, e)) };
|
2015-03-22 15:11:56 -04:00
|
|
|
self.equate(true, trace).relate(a, b)
|
2015-03-09 16:39:50 -04:00
|
|
|
}).map(|_| ())
|
2015-01-05 21:50:01 -05:00
|
|
|
}
|
2013-05-02 14:32:37 -04:00
|
|
|
}
|
2012-11-29 16:41:39 -08:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
impl<'tcx> TypeTrace<'tcx> {
|
2013-08-31 18:13:04 +02:00
|
|
|
pub fn span(&self) -> Span {
|
2013-05-23 21:37:37 -04:00
|
|
|
self.origin.span()
|
|
|
|
}
|
2014-11-15 20:30:33 -05:00
|
|
|
|
2015-01-16 05:48:15 +02:00
|
|
|
pub fn types(origin: TypeOrigin,
|
|
|
|
a_is_expected: bool,
|
|
|
|
a: Ty<'tcx>,
|
|
|
|
b: Ty<'tcx>)
|
|
|
|
-> TypeTrace<'tcx> {
|
|
|
|
TypeTrace {
|
|
|
|
origin: origin,
|
|
|
|
values: Types(expected_found(a_is_expected, a, b))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-25 07:20:48 -05:00
|
|
|
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
|
2014-11-15 20:30:33 -05:00
|
|
|
TypeTrace {
|
|
|
|
origin: Misc(codemap::DUMMY_SP),
|
|
|
|
values: Types(ty::expected_found {
|
2014-12-25 07:20:48 -05:00
|
|
|
expected: tcx.types.err,
|
|
|
|
found: tcx.types.err,
|
2014-11-15 20:30:33 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
|
2015-06-18 08:51:23 +03:00
|
|
|
impl<'tcx> fmt::Debug for TypeTrace<'tcx> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "TypeTrace({:?})", self.origin)
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 21:04:07 -04:00
|
|
|
impl TypeOrigin {
|
2013-08-31 18:13:04 +02:00
|
|
|
pub fn span(&self) -> Span {
|
2013-05-23 21:37:37 -04:00
|
|
|
match *self {
|
|
|
|
MethodCompatCheck(span) => span,
|
2014-01-06 14:00:46 +02:00
|
|
|
ExprAssignable(span) => span,
|
2013-05-23 21:37:37 -04:00
|
|
|
Misc(span) => span,
|
|
|
|
RelateTraitRefs(span) => span,
|
|
|
|
RelateSelfType(span) => span,
|
2014-09-12 10:53:35 -04:00
|
|
|
RelateOutputImplTypes(span) => span,
|
2014-05-31 00:16:33 +02:00
|
|
|
MatchExpressionArm(match_span, _) => match_span,
|
2013-06-05 21:04:07 -04:00
|
|
|
IfExpression(span) => span,
|
2014-12-06 01:30:41 -05:00
|
|
|
IfExpressionWithNoElse(span) => span,
|
2014-12-16 16:25:33 +13:00
|
|
|
RangeExpression(span) => span,
|
2014-12-06 01:30:41 -05:00
|
|
|
EquatePredicate(span) => span,
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
impl<'tcx> SubregionOrigin<'tcx> {
|
2013-08-31 18:13:04 +02:00
|
|
|
pub fn span(&self) -> Span {
|
2013-05-23 21:37:37 -04:00
|
|
|
match *self {
|
2014-04-22 02:21:52 +03:00
|
|
|
Subtype(ref a) => a.span(),
|
2013-06-25 12:04:50 -04:00
|
|
|
InfStackClosure(a) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
InvokeClosure(a) => a,
|
|
|
|
DerefPointer(a) => a,
|
2014-02-07 14:43:48 -05:00
|
|
|
FreeVariable(a, _) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
IndexSlice(a) => a,
|
|
|
|
RelateObjectBound(a) => a,
|
2014-11-15 17:25:05 -05:00
|
|
|
RelateParamBound(a, _) => a,
|
2014-08-27 21:46:52 -04:00
|
|
|
RelateRegionParamBound(a) => a,
|
|
|
|
RelateDefaultParamBound(a, _) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
Reborrow(a) => a,
|
2014-02-07 14:43:48 -05:00
|
|
|
ReborrowUpvar(a, _) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
ReferenceOutlivesReferent(_, a) => a,
|
2014-08-27 21:46:52 -04:00
|
|
|
ExprTypeIsNotInScope(_, a) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
BindingTypeIsNotValidAtDecl(a) => a,
|
|
|
|
CallRcvr(a) => a,
|
|
|
|
CallArg(a) => a,
|
|
|
|
CallReturn(a) => a,
|
2015-02-12 12:48:54 -05:00
|
|
|
Operand(a) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
AddrOf(a) => a,
|
|
|
|
AutoBorrow(a) => a,
|
2014-10-27 12:55:16 +01:00
|
|
|
SafeDestructor(a) => a,
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-10 07:02:27 -04:00
|
|
|
impl RegionVariableOrigin {
|
2013-08-31 18:13:04 +02:00
|
|
|
pub fn span(&self) -> Span {
|
2013-05-23 21:37:37 -04:00
|
|
|
match *self {
|
|
|
|
MiscVariable(a) => a,
|
|
|
|
PatternRegion(a) => a,
|
|
|
|
AddrOfRegion(a) => a,
|
|
|
|
Autoref(a) => a,
|
2015-03-10 07:02:27 -04:00
|
|
|
Coercion(a) => a,
|
2014-03-07 08:43:39 +01:00
|
|
|
EarlyBoundRegion(a, _) => a,
|
2014-11-05 22:06:04 -05:00
|
|
|
LateBoundRegion(a, _, _) => a,
|
2014-03-07 08:43:39 +01:00
|
|
|
BoundRegionInCoherence(_) => codemap::DUMMY_SP,
|
2014-02-07 14:43:48 -05:00
|
|
|
UpvarRegion(_, a) => a
|
2013-05-23 21:37:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|