Add regression test and help note
This commit is contained in:
parent
cdc8f0606d
commit
ee55c1f1d2
3 changed files with 52 additions and 5 deletions
|
@ -187,7 +187,7 @@ fn enforce_impl_params_are_constrained(
|
||||||
}
|
}
|
||||||
|
|
||||||
// (*) This is a horrible concession to reality. I think it'd be
|
// (*) 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:
|
// 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) {
|
fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str) {
|
||||||
struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
span,
|
span,
|
||||||
E0207,
|
E0207,
|
||||||
|
@ -215,9 +215,17 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str)
|
||||||
impl trait, self type, or predicates",
|
impl trait, self type, or predicates",
|
||||||
kind,
|
kind,
|
||||||
name
|
name
|
||||||
)
|
);
|
||||||
.span_label(span, format!("unconstrained {} parameter", kind))
|
err.span_label(span, format!("unconstrained {} parameter", kind));
|
||||||
.emit();
|
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.
|
/// Enforce that we do not have two items in an impl with the same name.
|
||||||
|
|
18
src/test/ui/const-generics/issues/issue-68366.rs
Normal file
18
src/test/ui/const-generics/issues/issue-68366.rs
Normal file
|
@ -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<const N: Option<usize>>;
|
||||||
|
|
||||||
|
impl <const N: usize> Collatz<{Some(N)}> {}
|
||||||
|
//~^ ERROR the const parameter
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl<const N: usize> Foo {}
|
||||||
|
//~^ ERROR the const parameter
|
||||||
|
|
||||||
|
fn main() {}
|
21
src/test/ui/const-generics/issues/issue-68366.stderr
Normal file
21
src/test/ui/const-generics/issues/issue-68366.stderr
Normal file
|
@ -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 <const N: usize> 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<const N: usize> 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`.
|
Loading…
Add table
Reference in a new issue