@@ -40,6 +40,7 @@ use syntax::codemap;
40
40
use syntax:: codemap:: { Span , DUMMY_SP } ;
41
41
use util:: nodemap:: { FnvHashMap , NodeMap } ;
42
42
43
+ use ast_map;
43
44
use self :: combine:: CombineFields ;
44
45
use self :: region_inference:: { RegionVarBindings , RegionSnapshot } ;
45
46
use self :: error_reporting:: ErrorReporting ;
@@ -72,7 +73,7 @@ pub struct InferCtxt<'a, 'tcx: 'a> {
72
73
// We instantiate UnificationTable with bounds<Ty> because the
73
74
// types that might instantiate a general type variable have an
74
75
// order, represented by its upper and lower bounds.
75
- type_variables : RefCell < type_variable:: TypeVariableTable < ' tcx > > ,
76
+ pub type_variables : RefCell < type_variable:: TypeVariableTable < ' tcx > > ,
76
77
77
78
// Map from integral variable to the kind of integer it represents
78
79
int_unification_table : RefCell < UnificationTable < ty:: IntVid > > ,
@@ -693,7 +694,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
693
694
variables. extend ( unbound_ty_vars) ;
694
695
variables. extend ( unbound_int_vars) ;
695
696
variables. extend ( unbound_float_vars) ;
696
-
697
+
697
698
return variables;
698
699
}
699
700
@@ -1048,15 +1049,36 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1048
1049
}
1049
1050
1050
1051
pub fn type_vars_for_defs ( & self ,
1052
+ span : Span ,
1053
+ // substs: Substs,
1051
1054
defs : & [ ty:: TypeParameterDef < ' tcx > ] )
1052
1055
-> Vec < ty:: Ty < ' tcx > > {
1056
+
1057
+ fn definition_span < ' tcx > ( tcx : & ty:: ctxt < ' tcx > , def_id : ast:: DefId ) -> Span {
1058
+ let parent = tcx. map . get_parent ( def_id. node ) ;
1059
+ debug ! ( "definition_span def_id={:?} parent={:?} node={:?} parent_node={:?}" ,
1060
+ def_id, parent, tcx. map. find( def_id. node) , tcx. map. find( parent) ) ;
1061
+ match tcx. map . find ( parent) {
1062
+ None => DUMMY_SP ,
1063
+ Some ( ref node) => match * node {
1064
+ ast_map:: NodeItem ( ref item) => item. span ,
1065
+ ast_map:: NodeForeignItem ( ref item) => item. span ,
1066
+ ast_map:: NodeTraitItem ( ref item) => item. span ,
1067
+ ast_map:: NodeImplItem ( ref item) => item. span ,
1068
+ _ => DUMMY_SP
1069
+ }
1070
+ }
1071
+ }
1072
+
1053
1073
let mut substs = Substs :: empty ( ) ;
1054
1074
let mut vars = Vec :: with_capacity ( defs. len ( ) ) ;
1055
1075
1056
1076
for def in defs. iter ( ) {
1057
1077
let default = def. default . map ( |default| {
1058
1078
type_variable:: Default {
1059
- ty : default
1079
+ ty : default,
1080
+ origin_span : span,
1081
+ definition_span : definition_span ( self . tcx , def. def_id )
1060
1082
}
1061
1083
} ) ;
1062
1084
//.subst(self.tcx, &substs)
@@ -1078,7 +1100,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1078
1100
let mut type_params = subst:: VecPerParamSpace :: empty ( ) ;
1079
1101
1080
1102
for space in subst:: ParamSpace :: all ( ) . iter ( ) {
1081
- type_params. replace ( * space, self . type_vars_for_defs ( generics. types . get_slice ( * space) ) )
1103
+ type_params. replace ( * space,
1104
+ self . type_vars_for_defs ( span, generics. types . get_slice ( * space) ) )
1082
1105
}
1083
1106
1084
1107
let region_params =
@@ -1103,7 +1126,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1103
1126
assert ! ( generics. regions. len( subst:: FnSpace ) == 0 ) ;
1104
1127
1105
1128
let type_parameter_defs = generics. types . get_slice ( subst:: TypeSpace ) ;
1106
- let type_parameters = self . type_vars_for_defs ( type_parameter_defs) ;
1129
+ let type_parameters = self . type_vars_for_defs ( span , type_parameter_defs) ;
1107
1130
1108
1131
let region_param_defs = generics. regions . get_slice ( subst:: TypeSpace ) ;
1109
1132
let regions = self . region_vars_for_defs ( span, region_param_defs) ;
@@ -1340,13 +1363,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1340
1363
1341
1364
pub fn report_conflicting_default_types ( & self ,
1342
1365
span : Span ,
1343
- expected : Ty < ' tcx > ,
1344
- actual : Ty < ' tcx > ) {
1366
+ expected : type_variable :: Default < ' tcx > ,
1367
+ actual : type_variable :: Default < ' tcx > ) {
1345
1368
let trace = TypeTrace {
1346
1369
origin : Misc ( span) ,
1347
1370
values : Types ( ty:: expected_found {
1348
- expected : expected,
1349
- found : actual
1371
+ expected : expected. ty ,
1372
+ found : actual. ty
1350
1373
} )
1351
1374
} ;
1352
1375
0 commit comments