Skip to content

Commit

Permalink
Check early on in typeck that types being implemented are actually if…
Browse files Browse the repository at this point in the history
…ace types

Closes #2330.
  • Loading branch information
catamorphism committed May 3, 2012
1 parent 74096a7 commit d8f28be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/rustc/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,27 @@ fn ast_path_to_ty<AC: ast_conv, RS: region_scope copy>(
/*
Instantiates the path for the given iface reference, assuming that
it's bound to a valid iface type. Returns the def_id for the defining
iface
iface. Fails if the type is a type other than an iface type.
*/
fn instantiate_iface_ref(ccx: @crate_ctxt, t: @ast::iface_ref,
rp: ast::region_param)
-> (ast::def_id, ty_param_substs_and_ty) {

let sp = t.path.span, err = "can only implement interface types",
sess = ccx.tcx.sess;

alt lookup_def_tcx(ccx.tcx, t.path.span, t.id) {
ast::def_ty(t_id) {
(t_id, ast_path_to_ty(ccx, type_rscope(rp), t_id, t.path, t.id))
let tpt = ast_path_to_ty(ccx, type_rscope(rp), t_id, t.path, t.id);
alt ty::get(tpt.ty).struct {
ty::ty_iface(*) {
(t_id, tpt)
}
_ { sess.span_fatal(sp, err); }
}
}
_ {
ccx.tcx.sess.span_fatal(
t.path.span,
"can only implement interface types");
sess.span_fatal(sp, err);
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/compile-fail/issue-2330.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum chan { }

iface channel<T> {
fn send(v: T);
}

// `chan` is not an iface, it's an enum
impl of chan for int { //! ERROR can only implement interface types
fn send(v: int) { fail }
}

fn main() {
}

0 comments on commit d8f28be

Please sign in to comment.