Change:
The following code does NOT compile: it errors with: However, when using normal generics in the places of the const generics, wrapping the in an and sticking that into the struct does work: Is it intended that const generic dont mimmic this behaviour?
This is probably a decision that has to be made (although if it is disallowed, then we'd want a better error message). However, at present, this is a implementation limitation: we really only properly support const generics of the form at the moment (cc ).
Considering that anon consts are mostly just projections, wouldn't this be similar to which doesn't really make a lot of sense (we have to guarantee that the projection maps each value of to a unique type). While is injective, finding an intuitive subset of expressions for which this is the case is hard and imo not actually desirable rn. Not quite sure what's the best error message though :thinking: probably something like
That's a good point I think adding a note explaining the problem would be the best solution, though the tricky part is working out how to explain it concisely (rather than just stating what the problem is).

Discussion:
} // (*) This is a horrible concession to reality. I think it'd be <del> // better to just ban unconstrianed lifetimes outright, but in </del> <ins> // better to just ban unconstrained lifetimes outright, but in </ins> // practice people do non-hygenic macros like: // // ```

} fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str) { <del> struct_span_err!( </del> <ins> let mut err = struct_span_err!( </ins> tcx.sess, span, E0207,

impl trait, self type, or predicates", kind, name <del> ) .span_label(span, format!("unconstrained {} parameter", kind)) .emit(); </del> <ins> ); 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(); </ins> } /// Enforce that we do not have two items in an impl with the same name.

<ins> // 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() {} </ins>

<ins> 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`. </ins>