@@ -202,7 +202,7 @@ pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
202
202
r
203
203
}
204
204
205
- fn ast_path_substs < ' tcx , AC , RS > (
205
+ fn ast_path_substs_for_ty < ' tcx , AC , RS > (
206
206
this : & AC ,
207
207
rscope : & RS ,
208
208
decl_def_id : ast:: DefId ,
@@ -233,12 +233,35 @@ fn ast_path_substs<'tcx,AC,RS>(
233
233
assert ! ( decl_generics. types. all( |d| d. space != FnSpace ) ) ;
234
234
235
235
let ( regions, types) = match path. segments . last ( ) . unwrap ( ) . parameters {
236
- ast:: AngleBracketedParameters ( ref data) =>
237
- angle_bracketed_parameters ( this, rscope, data) ,
238
- ast:: ParenthesizedParameters ( ref data) =>
239
- parenthesized_parameters ( this, binder_id, data) ,
236
+ ast:: AngleBracketedParameters ( ref data) => {
237
+ convert_angle_bracketed_parameters ( this, rscope, data)
238
+ }
239
+ ast:: ParenthesizedParameters ( ref data) => {
240
+ span_err ! ( tcx. sess, path. span, E0169 ,
241
+ "parenthesized parameters may only be used with a trait" ) ;
242
+ ( Vec :: new ( ) , convert_parenthesized_parameters ( this, data) )
243
+ }
240
244
} ;
241
245
246
+ create_substs_for_ast_path ( this, rscope, path. span , decl_def_id,
247
+ decl_generics, self_ty, types, regions, associated_ty)
248
+ }
249
+
250
+ fn create_substs_for_ast_path < ' tcx , AC , RS > (
251
+ this : & AC ,
252
+ rscope : & RS ,
253
+ span : Span ,
254
+ decl_def_id : ast:: DefId ,
255
+ decl_generics : & ty:: Generics ,
256
+ self_ty : Option < ty:: t > ,
257
+ types : Vec < ty:: t > ,
258
+ regions : Vec < ty:: Region > ,
259
+ associated_ty : Option < ty:: t > )
260
+ -> Substs
261
+ where AC : AstConv < ' tcx > , RS : RegionScope
262
+ {
263
+ let tcx = this. tcx ( ) ;
264
+
242
265
// If the type is parameterized by the this region, then replace this
243
266
// region with the current anon region binding (in other words,
244
267
// whatever & would get replaced with).
@@ -248,10 +271,10 @@ fn ast_path_substs<'tcx,AC,RS>(
248
271
regions
249
272
} else {
250
273
let anon_regions =
251
- rscope. anon_regions ( path . span , expected_num_region_params) ;
274
+ rscope. anon_regions ( span, expected_num_region_params) ;
252
275
253
276
if supplied_num_region_params != 0 || anon_regions. is_err ( ) {
254
- span_err ! ( tcx. sess, path . span, E0107 ,
277
+ span_err ! ( tcx. sess, span, E0107 ,
255
278
"wrong number of lifetime parameters: expected {}, found {}" ,
256
279
expected_num_region_params, supplied_num_region_params) ;
257
280
}
@@ -283,7 +306,7 @@ fn ast_path_substs<'tcx,AC,RS>(
283
306
} else {
284
307
"expected"
285
308
} ;
286
- this. tcx ( ) . sess . span_fatal ( path . span ,
309
+ this. tcx ( ) . sess . span_fatal ( span,
287
310
format ! ( "wrong number of type arguments: {} {}, found {}" ,
288
311
expected,
289
312
required_ty_param_count,
@@ -294,7 +317,7 @@ fn ast_path_substs<'tcx,AC,RS>(
294
317
} else {
295
318
"expected"
296
319
} ;
297
- this. tcx ( ) . sess . span_fatal ( path . span ,
320
+ this. tcx ( ) . sess . span_fatal ( span,
298
321
format ! ( "wrong number of type arguments: {} {}, found {}" ,
299
322
expected,
300
323
formal_ty_param_count,
@@ -303,9 +326,9 @@ fn ast_path_substs<'tcx,AC,RS>(
303
326
304
327
if supplied_ty_param_count > required_ty_param_count
305
328
&& !this. tcx ( ) . sess . features . borrow ( ) . default_type_params {
306
- span_err ! ( this. tcx( ) . sess, path . span, E0108 ,
329
+ span_err ! ( this. tcx( ) . sess, span, E0108 ,
307
330
"default type parameters are experimental and possibly buggy" ) ;
308
- span_help ! ( this. tcx( ) . sess, path . span,
331
+ span_help ! ( this. tcx( ) . sess, span,
309
332
"add #![feature(default_type_params)] to the crate attributes to enable" ) ;
310
333
}
311
334
@@ -331,66 +354,66 @@ fn ast_path_substs<'tcx,AC,RS>(
331
354
// This is a default type parameter.
332
355
let default = default. subst_spanned ( tcx,
333
356
& substs,
334
- Some ( path . span ) ) ;
357
+ Some ( span) ) ;
335
358
substs. types . push ( TypeSpace , default) ;
336
359
}
337
360
None => {
338
- tcx. sess . span_bug ( path. span ,
339
- "extra parameter without default" ) ;
361
+ tcx. sess . span_bug ( span, "extra parameter without default" ) ;
340
362
}
341
363
}
342
364
}
343
365
344
366
for param in decl_generics. types . get_slice ( AssocSpace ) . iter ( ) {
345
367
substs. types . push (
346
368
AssocSpace ,
347
- this. associated_type_binding ( path . span ,
369
+ this. associated_type_binding ( span,
348
370
associated_ty,
349
371
decl_def_id,
350
372
param. def_id ) )
351
373
}
352
374
353
375
return substs;
376
+ }
354
377
355
- fn angle_bracketed_parameters < ' tcx , AC , RS > ( this : & AC ,
356
- rscope : & RS ,
357
- data : & ast:: AngleBracketedParameterData )
358
- -> ( Vec < ty:: Region > , Vec < ty:: t > )
359
- where AC : AstConv < ' tcx > , RS : RegionScope
360
- {
361
- let regions: Vec < _ > =
362
- data. lifetimes . iter ( )
363
- . map ( |l| ast_region_to_region ( this. tcx ( ) , l) )
364
- . collect ( ) ;
365
-
366
- let types: Vec < _ > =
367
- data. types . iter ( )
368
- . map ( |t| ast_ty_to_ty ( this, rscope, & * * t) )
369
- . collect ( ) ;
370
-
371
- ( regions, types)
372
- }
378
+ fn convert_angle_bracketed_parameters < ' tcx , AC , RS > ( this : & AC ,
379
+ rscope : & RS ,
380
+ data : & ast:: AngleBracketedParameterData )
381
+ -> ( Vec < ty:: Region > , Vec < ty:: t > )
382
+ where AC : AstConv < ' tcx > , RS : RegionScope
383
+ {
384
+ let regions: Vec < _ > =
385
+ data. lifetimes . iter ( )
386
+ . map ( |l| ast_region_to_region ( this. tcx ( ) , l) )
387
+ . collect ( ) ;
373
388
374
- fn parenthesized_parameters < ' tcx , AC > ( this : & AC ,
375
- binder_id : ast:: NodeId ,
376
- data : & ast:: ParenthesizedParameterData )
377
- -> ( Vec < ty:: Region > , Vec < ty:: t > )
378
- where AC : AstConv < ' tcx >
379
- {
380
- let binding_rscope = BindingRscope :: new ( binder_id) ;
381
-
382
- let inputs = data. inputs . iter ( )
383
- . map ( |a_t| ast_ty_to_ty ( this, & binding_rscope, & * * a_t) )
384
- . collect ( ) ;
385
- let input_ty = ty:: mk_tup ( this. tcx ( ) , inputs) ;
386
-
387
- let output = match data. output {
388
- Some ( ref output_ty) => ast_ty_to_ty ( this, & binding_rscope, & * * output_ty) ,
389
- None => ty:: mk_nil ( this. tcx ( ) )
390
- } ;
389
+ let types: Vec < _ > =
390
+ data. types . iter ( )
391
+ . map ( |t| ast_ty_to_ty ( this, rscope, & * * t) )
392
+ . collect ( ) ;
393
+
394
+ ( regions, types)
395
+ }
396
+
397
+ fn convert_parenthesized_parameters < ' tcx , AC > ( this : & AC ,
398
+ data : & ast:: ParenthesizedParameterData )
399
+ -> Vec < ty:: t >
400
+ where AC : AstConv < ' tcx >
401
+ {
402
+ let binding_rscope = BindingRscope :: new ( ) ;
403
+
404
+ let inputs = data. inputs . iter ( )
405
+ . map ( |a_t| ast_ty_to_ty ( this, & binding_rscope, & * * a_t) )
406
+ . collect ( ) ;
407
+ let input_ty = ty:: mk_tup ( this. tcx ( ) , inputs) ;
408
+
409
+ let output = match data. output {
410
+ Some ( ref output_ty) => ast_ty_to_ty ( this, & binding_rscope, & * * output_ty) ,
411
+ None => ty:: mk_nil ( this. tcx ( ) ) ,
412
+ } ;
413
+
414
+ vec ! [ input_ty, output]
415
+ }
391
416
392
- ( Vec :: new ( ) , vec ! [ input_ty, output] )
393
- }
394
417
}
395
418
396
419
pub fn instantiate_trait_ref < ' tcx , AC , RS > ( this : & AC ,
0 commit comments