Skip to content

Commit 10ace11

Browse files
jroeschJared Roesch
authored andcommitted
---
yaml --- r: 235838 b: refs/heads/stable c: fbfbdd7 h: refs/heads/master v: v3
1 parent 69a9a17 commit 10ace11

File tree

7 files changed

+99
-62
lines changed

7 files changed

+99
-62
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: b75f215e8244ae742ac2e5b3cfd27ab4a761ed9e
32+
refs/heads/stable: fbfbdd7d1426d34b94223909eec2c9c009d9c731
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc/middle/infer/mod.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,12 +1047,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10471047
.collect()
10481048
}
10491049

1050+
// We have to take `&mut Substs` in order to provide the correct substitutions for defaults
1051+
// along the way, for this reason we don't return them.
10501052
pub fn type_vars_for_defs(&self,
10511053
span: Span,
1052-
// substs: Substs,
1053-
defs: &[ty::TypeParameterDef<'tcx>])
1054-
-> Vec<ty::Ty<'tcx>> {
1054+
space: subst::ParamSpace,
1055+
substs: &mut Substs<'tcx>,
1056+
defs: &[ty::TypeParameterDef<'tcx>]) {
10551057

1058+
// This doesn't work ...
10561059
fn definition_span<'tcx>(tcx: &ty::ctxt<'tcx>, def_id: ast::DefId) -> Span {
10571060
let parent = tcx.map.get_parent(def_id.node);
10581061
debug!("definition_span def_id={:?} parent={:?} node={:?} parent_node={:?}",
@@ -1069,24 +1072,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10691072
}
10701073
}
10711074

1072-
let mut substs = Substs::empty();
10731075
let mut vars = Vec::with_capacity(defs.len());
10741076

10751077
for def in defs.iter() {
1076-
let default = def.default.map(|default| {
1078+
let default = def.default.subst_spanned(self.tcx, substs, Some(span)).map(|default| {
10771079
type_variable::Default {
10781080
ty: default,
10791081
origin_span: span,
10801082
definition_span: definition_span(self.tcx, def.def_id)
10811083
}
10821084
});
1083-
//.subst(self.tcx, &substs)
1085+
10841086
let ty_var = self.next_ty_var_with_default(default);
1085-
substs.types.push(subst::ParamSpace::SelfSpace, ty_var);
1087+
substs.types.push(space, ty_var);
10861088
vars.push(ty_var)
10871089
}
1088-
1089-
vars
10901090
}
10911091

10921092
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
@@ -1096,17 +1096,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10961096
generics: &ty::Generics<'tcx>)
10971097
-> subst::Substs<'tcx>
10981098
{
1099-
let mut type_params = subst::VecPerParamSpace::empty();
1100-
1101-
for space in subst::ParamSpace::all().iter() {
1102-
type_params.replace(*space,
1103-
self.type_vars_for_defs(span, generics.types.get_slice(*space)))
1104-
}
1099+
let type_params = subst::VecPerParamSpace::empty();
11051100

11061101
let region_params =
11071102
generics.regions.map(
11081103
|d| self.next_region_var(EarlyBoundRegion(span, d.name)));
1109-
subst::Substs::new(type_params, region_params)
1104+
1105+
let mut substs = subst::Substs::new(type_params, region_params);
1106+
1107+
for space in subst::ParamSpace::all().iter() {
1108+
self.type_vars_for_defs(
1109+
span,
1110+
*space,
1111+
&mut substs,
1112+
generics.types.get_slice(*space));
1113+
}
1114+
1115+
return substs;
11101116
}
11111117

11121118
/// Given a set of generics defined on a trait, returns a substitution mapping each output
@@ -1124,13 +1130,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11241130
assert!(generics.regions.len(subst::SelfSpace) == 0);
11251131
assert!(generics.regions.len(subst::FnSpace) == 0);
11261132

1127-
let type_parameter_defs = generics.types.get_slice(subst::TypeSpace);
1128-
let type_parameters = self.type_vars_for_defs(span, type_parameter_defs);
1133+
let type_params = Vec::new();
11291134

11301135
let region_param_defs = generics.regions.get_slice(subst::TypeSpace);
11311136
let regions = self.region_vars_for_defs(span, region_param_defs);
11321137

1133-
subst::Substs::new_trait(type_parameters, regions, self_ty)
1138+
let mut substs = subst::Substs::new_trait(type_params, regions, self_ty);
1139+
1140+
let type_parameter_defs = generics.types.get_slice(subst::TypeSpace);
1141+
self.type_vars_for_defs(span, subst::TypeSpace, &mut substs, type_parameter_defs);
1142+
1143+
return substs;
11341144
}
11351145

11361146
pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> ty::Region {

branches/stable/src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'tcx> Substs<'tcx> {
154154
}
155155

156156
impl RegionSubsts {
157-
fn map<F>(self, op: F) -> RegionSubsts where
157+
pub fn map<F>(self, op: F) -> RegionSubsts where
158158
F: FnOnce(VecPerParamSpace<ty::Region>) -> VecPerParamSpace<ty::Region>,
159159
{
160160
match self {

branches/stable/src/librustc_typeck/check/method/confirm.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
8484

8585
// Create substitutions for the method's type parameters.
8686
let rcvr_substs = self.fresh_receiver_substs(self_ty, &pick);
87-
let (method_types, method_regions) =
88-
self.instantiate_method_substs(&pick, supplied_method_types);
89-
let all_substs = rcvr_substs.with_method(method_types, method_regions);
87+
let all_substs =
88+
self.instantiate_method_substs(
89+
&pick,
90+
supplied_method_types,
91+
rcvr_substs);
92+
9093
debug!("all_substs={:?}", all_substs);
9194

9295
// Create the final signature for the method, replacing late-bound regions.
@@ -302,8 +305,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
302305

303306
fn instantiate_method_substs(&mut self,
304307
pick: &probe::Pick<'tcx>,
305-
supplied_method_types: Vec<Ty<'tcx>>)
306-
-> (Vec<Ty<'tcx>>, Vec<ty::Region>)
308+
supplied_method_types: Vec<Ty<'tcx>>,
309+
substs: subst::Substs<'tcx>)
310+
-> subst::Substs<'tcx>
307311
{
308312
// Determine the values for the generic parameters of the method.
309313
// If they were not explicitly supplied, just construct fresh
@@ -313,21 +317,6 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
313317
let method_types = method.generics.types.get_slice(subst::FnSpace);
314318
let num_method_types = method_types.len();
315319

316-
let method_types = {
317-
if num_supplied_types == 0 {
318-
self.fcx.infcx().type_vars_for_defs(self.span, method_types)
319-
} else if num_method_types == 0 {
320-
span_err!(self.tcx().sess, self.span, E0035,
321-
"does not take type parameters");
322-
self.fcx.infcx().type_vars_for_defs(self.span, method_types)
323-
} else if num_supplied_types != num_method_types {
324-
span_err!(self.tcx().sess, self.span, E0036,
325-
"incorrect number of type parameters given for this method");
326-
vec![self.tcx().types.err; num_method_types]
327-
} else {
328-
supplied_method_types
329-
}
330-
};
331320

332321
// Create subst for early-bound lifetime parameters, combining
333322
// parameters from the type and those from the method.
@@ -339,7 +328,33 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
339328
pick.item.as_opt_method().unwrap()
340329
.generics.regions.get_slice(subst::FnSpace));
341330

342-
(method_types, method_regions)
331+
let subst::Substs { types, regions } = substs;
332+
let regions = regions.map(|r| r.with_vec(subst::FnSpace, method_regions));
333+
let mut final_substs = subst::Substs { types: types, regions: regions };
334+
335+
if num_supplied_types == 0 {
336+
self.fcx.infcx().type_vars_for_defs(
337+
self.span,
338+
subst::FnSpace,
339+
&mut final_substs,
340+
method_types);
341+
} else if num_method_types == 0 {
342+
span_err!(self.tcx().sess, self.span, E0035,
343+
"does not take type parameters");
344+
self.fcx.infcx().type_vars_for_defs(
345+
self.span,
346+
subst::FnSpace,
347+
&mut final_substs,
348+
method_types);
349+
} else if num_supplied_types != num_method_types {
350+
span_err!(self.tcx().sess, self.span, E0036,
351+
"incorrect number of type parameters given for this method");
352+
final_substs.types.replace(subst::FnSpace, vec![self.tcx().types.err; num_method_types]);
353+
} else {
354+
final_substs.types.replace(subst::FnSpace, supplied_method_types);
355+
}
356+
357+
return final_substs;
343358
}
344359

345360
fn unify_receivers(&mut self,

branches/stable/src/librustc_typeck/check/method/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,28 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
169169

170170
let type_parameter_defs = trait_def.generics.types.get_slice(subst::TypeSpace);
171171
let expected_number_of_input_types = type_parameter_defs.len();
172-
let input_types = match opt_input_types {
172+
173+
assert_eq!(trait_def.generics.types.len(subst::FnSpace), 0);
174+
assert!(trait_def.generics.regions.is_empty());
175+
176+
// Construct a trait-reference `self_ty : Trait<input_tys>`
177+
let mut substs = subst::Substs::new_trait(Vec::new(), Vec::new(), self_ty);
178+
179+
match opt_input_types {
173180
Some(input_types) => {
174181
assert_eq!(expected_number_of_input_types, input_types.len());
175-
input_types
182+
substs.types.replace(subst::ParamSpace::TypeSpace, input_types);
176183
}
177184

178185
None => {
179-
fcx.inh.infcx.type_vars_for_defs(span, type_parameter_defs)
186+
fcx.inh.infcx.type_vars_for_defs(
187+
span,
188+
subst::ParamSpace::TypeSpace,
189+
&mut substs,
190+
type_parameter_defs);
180191
}
181-
};
182-
183-
assert_eq!(trait_def.generics.types.len(subst::FnSpace), 0);
184-
assert!(trait_def.generics.regions.is_empty());
185-
186-
// Construct a trait-reference `self_ty : Trait<input_tys>`
187-
let substs = subst::Substs::new_trait(input_types, Vec::new(), self_ty);
192+
}
193+
188194
let trait_ref = ty::TraitRef::new(trait_def_id, fcx.tcx().mk_substs(substs));
189195

190196
// Construct an obligation

branches/stable/src/librustc_typeck/check/method/probe.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,16 +1200,12 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
12001200
return impl_ty;
12011201
}
12021202

1203-
let placeholder;
1203+
let mut placeholder;
12041204
let mut substs = substs;
12051205
if
12061206
!method.generics.types.is_empty_in(subst::FnSpace) ||
12071207
!method.generics.regions.is_empty_in(subst::FnSpace)
12081208
{
1209-
let method_types =
1210-
self.infcx().type_vars_for_defs(self.span,
1211-
method.generics.types.get_slice(subst::FnSpace));
1212-
12131209
// In general, during probe we erase regions. See
12141210
// `impl_self_ty()` for an explanation.
12151211
let method_regions =
@@ -1218,7 +1214,14 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
12181214
.map(|_| ty::ReStatic)
12191215
.collect();
12201216

1221-
placeholder = (*substs).clone().with_method(method_types, method_regions);
1217+
placeholder = (*substs).clone().with_method(Vec::new(), method_regions);
1218+
1219+
self.infcx().type_vars_for_defs(
1220+
self.span,
1221+
subst::FnSpace,
1222+
&mut placeholder,
1223+
method.generics.types.get_slice(subst::FnSpace));
1224+
12221225
substs = &placeholder;
12231226
}
12241227

branches/stable/src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,8 +2616,10 @@ pub fn impl_self_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26162616
debug!("impl_self_ty: tps={:?} rps={:?} raw_ty={:?}", tps, rps, raw_ty);
26172617

26182618
let rps = fcx.inh.infcx.region_vars_for_defs(span, rps);
2619-
let tps = fcx.inh.infcx.type_vars_for_defs(span, tps);
2620-
let substs = subst::Substs::new_type(tps, rps);
2619+
let mut substs = subst::Substs::new(
2620+
VecPerParamSpace::empty(),
2621+
VecPerParamSpace::new(rps, Vec::new(), Vec::new()));
2622+
fcx.inh.infcx.type_vars_for_defs(span, ParamSpace::TypeSpace, &mut substs, tps);
26212623
let substd_ty = fcx.instantiate_type_scheme(span, &substs, &raw_ty);
26222624

26232625
TypeAndSubsts { substs: substs, ty: substd_ty }
@@ -4611,6 +4613,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
46114613
}
46124614
}
46134615
}
4616+
46144617
if let Some(self_ty) = opt_self_ty {
46154618
if type_defs.len(subst::SelfSpace) == 1 {
46164619
substs.types.push(subst::SelfSpace, self_ty);
@@ -4623,7 +4626,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
46234626
// variables. If the user provided some types, we may still need
46244627
// to add defaults. If the user provided *too many* types, that's
46254628
// a problem.
4626-
for &space in &ParamSpace::all() {
4629+
for &space in &[subst::SelfSpace, subst::TypeSpace, subst::FnSpace] {
46274630
adjust_type_parameters(fcx, span, space, type_defs,
46284631
require_type_space, &mut substs);
46294632
assert_eq!(substs.types.len(space), type_defs.len(space));
@@ -4836,7 +4839,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
48364839
// Nothing specified at all: supply inference variables for
48374840
// everything.
48384841
if provided_len == 0 && !(require_type_space && space == subst::TypeSpace) {
4839-
substs.types.replace(space, fcx.infcx().type_vars_for_defs(span, &desired[..]));
4842+
fcx.infcx().type_vars_for_defs(span, space, substs, &desired[..]);
48404843
return;
48414844
}
48424845

0 commit comments

Comments
 (0)