Skip to content

Commit

Permalink
Catch forward declarations in default type params at AST conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryman committed Apr 17, 2014
1 parent 52a53e8 commit f829d20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,24 @@ pub fn ty_generics(ccx: &CrateCtxt,
let param_ty = ty::param_ty {idx: base_index + offset,
def_id: local_def(param.id)};
let bounds = @compute_bounds(ccx, param_ty, &param.bounds);
let default = param.default.map(|x| ast_ty_to_ty(ccx, &ExplicitRscope, x));
let default = param.default.map(|path| {
let ty = ast_ty_to_ty(ccx, &ExplicitRscope, path);
let cur_idx = param_ty.idx;

ty::walk_ty(ty, |t| {
match ty::get(t).sty {
ty::ty_param(p) => if p.idx > cur_idx {
ccx.tcx.sess.span_err(path.span,
"type parameters with a default cannot use \
forward declared identifiers")
},
_ => {}
}
});

ty
});

let def = ty::TypeParameterDef {
ident: param.ident,
def_id: local_def(param.id),
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/generic-type-params-forward-mention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

// Ensure that we get an error and not an ICE for this problematic case.
struct Foo<T = Option<U>, U = bool>;

//~^ ERROR type parameters with a default cannot use forward declared identifiers
fn main() {
let x: Foo;
//~^ ERROR missing type param `U` in the substitution of `std::option::Option<U>`
}

5 comments on commit f829d20

@bors
Copy link
Contributor

@bors bors commented on f829d20 Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at Ryman@f829d20

@bors
Copy link
Contributor

@bors bors commented on f829d20 Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Ryman/rust/issue_5997 = f829d20 into auto

@bors
Copy link
Contributor

@bors bors commented on f829d20 Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors
Copy link
Contributor

@bors bors commented on f829d20 Apr 18, 2014

@bors
Copy link
Contributor

@bors bors commented on f829d20 Apr 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 29a3970

Please sign in to comment.