mirror of
https://github.com/rust-lang/rust
synced 2024-09-18 16:02:39 +00:00
Check early on in typeck that types being implemented are actually iface types
Closes #2330.
This commit is contained in:
parent
74096a79d8
commit
d8f28be753
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
src/test/compile-fail/issue-2330.rs
Normal file
13
src/test/compile-fail/issue-2330.rs
Normal file
|
@ -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() {
|
||||
}
|
Loading…
Reference in a new issue