Skip to content

Commit ed7819e

Browse files
committed
---
yaml --- r: 2213 b: refs/heads/master c: 485399a h: refs/heads/master i: 2211: 3003dab v: v3
1 parent b08fc29 commit ed7819e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1b9e6b3ad28ce934f993f1bb8227f40d6f6d25e2
2+
refs/heads/master: 485399a8d5de8a8bb759feacd9e4915055e51cb5

trunk/src/comp/middle/ty.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,34 @@ fn type_contains_vars(@type_store tystore, t typ) -> bool {
13911391
ret *flag;
13921392
}
13931393

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+
13941422
// Type accessors for substructures of types
13951423

13961424
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 {
24952523
fn substitute_type_params(@type_store tystore,
24962524
vec[t] bindings,
24972525
t typ) -> t {
2526+
if (!type_contains_bound_params(tystore, typ)) {
2527+
ret typ;
2528+
}
24982529
fn replacer(@type_store tystore, vec[t] bindings, t typ) -> t {
24992530
alt (struct(tystore, typ)) {
25002531
case (ty_bound_param(?param_index)) {
@@ -2510,6 +2541,9 @@ fn substitute_type_params(@type_store tystore,
25102541

25112542
// Converts type parameters in a type to bound type parameters.
25122543
fn bind_params_in_type(@type_store tystore, t typ) -> t {
2544+
if (!type_contains_params(tystore, typ)) {
2545+
ret typ;
2546+
}
25132547
fn binder(@type_store tystore, t typ) -> t {
25142548
alt (struct(tystore, typ)) {
25152549
case (ty_bound_param(?index)) {

0 commit comments

Comments
 (0)