Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f829d20

Browse files
committedApr 17, 2014
Catch forward declarations in default type params at AST conversion.
1 parent 52a53e8 commit f829d20

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
 

‎src/librustc/middle/typeck/collect.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,24 @@ pub fn ty_generics(ccx: &CrateCtxt,
945945
let param_ty = ty::param_ty {idx: base_index + offset,
946946
def_id: local_def(param.id)};
947947
let bounds = @compute_bounds(ccx, param_ty, &param.bounds);
948-
let default = param.default.map(|x| ast_ty_to_ty(ccx, &ExplicitRscope, x));
948+
let default = param.default.map(|path| {
949+
let ty = ast_ty_to_ty(ccx, &ExplicitRscope, path);
950+
let cur_idx = param_ty.idx;
951+
952+
ty::walk_ty(ty, |t| {
953+
match ty::get(t).sty {
954+
ty::ty_param(p) => if p.idx > cur_idx {
955+
ccx.tcx.sess.span_err(path.span,
956+
"type parameters with a default cannot use \
957+
forward declared identifiers")
958+
},
959+
_ => {}
960+
}
961+
});
962+
963+
ty
964+
});
965+
949966
let def = ty::TypeParameterDef {
950967
ident: param.ident,
951968
def_id: local_def(param.id),

‎src/test/compile-fail/generic-type-params-forward-mention.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
// Ensure that we get an error and not an ICE for this problematic case.
1414
struct Foo<T = Option<U>, U = bool>;
15-
15+
//~^ ERROR type parameters with a default cannot use forward declared identifiers
1616
fn main() {
1717
let x: Foo;
18-
//~^ ERROR missing type param `U` in the substitution of `std::option::Option<U>`
1918
}

5 commit comments

Comments
 (5)

bors commented on Apr 18, 2014

@bors
Collaborator

saw approval from alexcrichton
at Ryman@f829d20

bors commented on Apr 18, 2014

@bors
Collaborator

Ryman/rust/issue_5997 = f829d20 merged ok, testing candidate = 29a3970

bors commented on Apr 18, 2014

@bors
Collaborator

merging Ryman/rust/issue_5997 = f829d20 into auto

bors commented on Apr 18, 2014

@bors
Collaborator

fast-forwarding master to auto = 29a3970

Please sign in to comment.