@@ -1391,6 +1391,34 @@ fn type_contains_vars(@type_store tystore, t typ) -> bool {
1391
1391
ret * flag;
1392
1392
}
1393
1393
1394
+ fn type_contains_params( @type_store tystore, t typ) -> bool {
1395
+ fn checker( @type_store tystore, @mutable bool flag, t typ) {
1396
+ alt ( struct ( tystore, typ) ) {
1397
+ case ( ty_param( _) ) { * flag = true; }
1398
+ case ( _) { /* fall through */ }
1399
+ }
1400
+ }
1401
+
1402
+ let @mutable bool flag = @mutable false;
1403
+ auto f = bind checker( tystore, flag, _) ;
1404
+ walk_ty( tystore, f, typ) ;
1405
+ ret * flag;
1406
+ }
1407
+
1408
+ fn type_contains_bound_params( @type_store tystore, t typ) -> bool {
1409
+ fn checker( @type_store tystore, @mutable bool flag, t typ) {
1410
+ alt ( struct ( tystore, typ) ) {
1411
+ case ( ty_bound_param( _) ) { * flag = true; }
1412
+ case ( _) { /* fall through */ }
1413
+ }
1414
+ }
1415
+
1416
+ let @mutable bool flag = @mutable false;
1417
+ auto f = bind checker( tystore, flag, _) ;
1418
+ walk_ty( tystore, f, typ) ;
1419
+ ret * flag;
1420
+ }
1421
+
1394
1422
// Type accessors for substructures of types
1395
1423
1396
1424
fn ty_fn_args( @type_store tystore, t fty) -> vec[ arg] {
@@ -2495,6 +2523,9 @@ fn type_err_to_str(&ty.type_err err) -> str {
2495
2523
fn substitute_type_params( @type_store tystore,
2496
2524
vec[ t] bindings,
2497
2525
t typ) -> t {
2526
+ if ( !type_contains_bound_params( tystore, typ) ) {
2527
+ ret typ;
2528
+ }
2498
2529
fn replacer( @type_store tystore, vec[ t] bindings, t typ) -> t {
2499
2530
alt ( struct ( tystore, typ) ) {
2500
2531
case ( ty_bound_param( ?param_index) ) {
@@ -2510,6 +2541,9 @@ fn substitute_type_params(@type_store tystore,
2510
2541
2511
2542
// Converts type parameters in a type to bound type parameters.
2512
2543
fn bind_params_in_type( @type_store tystore, t typ) -> t {
2544
+ if ( !type_contains_params( tystore, typ) ) {
2545
+ ret typ;
2546
+ }
2513
2547
fn binder( @type_store tystore, t typ) -> t {
2514
2548
alt ( struct ( tystore, typ) ) {
2515
2549
case ( ty_bound_param( ?index) ) {
0 commit comments