Skip to content

Commit 8db699d

Browse files
committed
Add diagnostic code for generic associated const error.
1 parent 98f41ff commit 8db699d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3773,9 +3773,9 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
37733773
match def {
37743774
def::DefAssociatedConst(..) => {
37753775
if ty::type_has_params(ty) || ty::type_has_self(ty) {
3776-
fcx.sess().span_err(span,
3777-
"Associated consts cannot depend \
3778-
on type parameters or Self.");
3776+
span_err!(fcx.sess(), span, E0329,
3777+
"Associated consts cannot depend \
3778+
on type parameters or Self.");
37793779
fcx.write_error(node_id);
37803780
return true;
37813781
}

src/librustc_typeck/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ register_diagnostics! {
771771
E0326, // associated const implemented with different type from trait
772772
E0327, // referred to method instead of constant in match pattern
773773
E0328, // cannot implement Unsize explicitly
774+
E0329, // associated const depends on type parameter or Self.
774775
E0366, // dropck forbid specialization to concrete type or region
775776
E0367, // dropck forbid specialization to predicate not in struct/enum
776777
E0369, // binary operation `<op>` cannot be applied to types

src/test/compile-fail/associated-const-type-parameters.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pub trait Foo {
1414
const MIN: i32;
1515

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

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

2626
fn main() {}

0 commit comments

Comments
 (0)