From ee55c1f1d2c427fecedd68e28a7dc4e6c68738b5 Mon Sep 17 00:00:00 2001 From: kadmin Date: Sun, 6 Sep 2020 04:34:20 +0000 Subject: [PATCH] Add regression test and help note --- compiler/rustc_typeck/src/impl_wf_check.rs | 18 +++++++++++----- .../ui/const-generics/issues/issue-68366.rs | 18 ++++++++++++++++ .../const-generics/issues/issue-68366.stderr | 21 +++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/const-generics/issues/issue-68366.rs create mode 100644 src/test/ui/const-generics/issues/issue-68366.stderr diff --git a/compiler/rustc_typeck/src/impl_wf_check.rs b/compiler/rustc_typeck/src/impl_wf_check.rs index 891e482b43133..4901d6041d6f0 100644 --- a/compiler/rustc_typeck/src/impl_wf_check.rs +++ b/compiler/rustc_typeck/src/impl_wf_check.rs @@ -187,7 +187,7 @@ fn enforce_impl_params_are_constrained( } // (*) This is a horrible concession to reality. I think it'd be - // better to just ban unconstrianed lifetimes outright, but in + // better to just ban unconstrained lifetimes outright, but in // practice people do non-hygenic macros like: // // ``` @@ -207,7 +207,7 @@ fn enforce_impl_params_are_constrained( } fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str) { - struct_span_err!( + let mut err = struct_span_err!( tcx.sess, span, E0207, @@ -215,9 +215,17 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str) impl trait, self type, or predicates", kind, name - ) - .span_label(span, format!("unconstrained {} parameter", kind)) - .emit(); + ); + err.span_label(span, format!("unconstrained {} parameter", kind)); + if kind == "const" { + err.note( + "expressions using a const parameter must map each value to a distinct output value", + ); + err.note( + "proving the result of expressions other than the parameter are unique is not supported", + ); + } + err.emit(); } /// Enforce that we do not have two items in an impl with the same name. diff --git a/src/test/ui/const-generics/issues/issue-68366.rs b/src/test/ui/const-generics/issues/issue-68366.rs new file mode 100644 index 0000000000000..a06b99d6645ec --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-68366.rs @@ -0,0 +1,18 @@ +// Checks that const expressions have a useful note explaining why they can't be evaluated. +// The note should relate to the fact that it cannot be shown forall N that it maps 1-1 to a new +// type. + +#![feature(const_generics)] +#![allow(incomplete_features)] + +struct Collatz>; + +impl Collatz<{Some(N)}> {} +//~^ ERROR the const parameter + +struct Foo; + +impl Foo {} +//~^ ERROR the const parameter + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-68366.stderr b/src/test/ui/const-generics/issues/issue-68366.stderr new file mode 100644 index 0000000000000..bba16f421535a --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-68366.stderr @@ -0,0 +1,21 @@ +error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates + --> $DIR/issue-68366.rs:10:13 + | +LL | impl Collatz<{Some(N)}> {} + | ^ unconstrained const parameter + | + = note: expressions using a const parameter must map each value to a distinct output value + = note: proving the result of expressions other than the parameter are unique is not supported + +error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates + --> $DIR/issue-68366.rs:15:12 + | +LL | impl Foo {} + | ^ unconstrained const parameter + | + = note: expressions using a const parameter must map each value to a distinct output value + = note: proving the result of expressions other than the parameter are unique is not supported + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0207`.