Skip to content

Commit

Permalink
Add diagnostic code for generic associated const error.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantheory committed May 22, 2015
1 parent 98f41ff commit 8db699d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -3773,9 +3773,9 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
match def {
def::DefAssociatedConst(..) => {
if ty::type_has_params(ty) || ty::type_has_self(ty) {
fcx.sess().span_err(span,
"Associated consts cannot depend \
on type parameters or Self.");
span_err!(fcx.sess(), span, E0329,
"Associated consts cannot depend \
on type parameters or Self.");
fcx.write_error(node_id);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/diagnostics.rs
Expand Up @@ -771,6 +771,7 @@ register_diagnostics! {
E0326, // associated const implemented with different type from trait
E0327, // referred to method instead of constant in match pattern
E0328, // cannot implement Unsize explicitly
E0329, // associated const depends on type parameter or Self.
E0366, // dropck forbid specialization to concrete type or region
E0367, // dropck forbid specialization to predicate not in struct/enum
E0369, // binary operation `<op>` cannot be applied to types
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/associated-const-type-parameters.rs
Expand Up @@ -14,13 +14,13 @@ pub trait Foo {
const MIN: i32;

fn get_min() -> i32 {
Self::MIN //~ Associated consts cannot depend on type parameters or Self.
Self::MIN //~ ERROR E0329
}
}

fn get_min<T: Foo>() -> i32 {
T::MIN; //~ Associated consts cannot depend on type parameters or Self.
<T as Foo>::MIN //~ Associated consts cannot depend on type parameters or Self.
T::MIN; //~ ERROR E0329
<T as Foo>::MIN //~ ERROR E0329
}

fn main() {}

0 comments on commit 8db699d

Please sign in to comment.