const generics testing

axes

  • what kinds of expressions are permitted
    • generic const parameters
    • fully evaluatable expressions (whatever is allowed in array lengths) that do not depend on generics
    • expressions only of type bool, integral, char
      • invalid bool and char bit-pattern
    • no expressions of other types
  • where can constant expressions appear
    • expressions calling const fn with turbofish and trying to reference
      • fn test<T>() -> Type<{ const_fn::<T>() }>
      • fn test() -> Type<{ const_fn::<{22}>() }>
      • fn test<'a>() -> Type<{ const_fn::<'a>() }>
      • in-scope generics (early-, late-bound lifetimes, types, constants) errors
      • fully evaluatable expressions ok
    • opaque types
      • fn test() -> impl TraitWithConst<{ whatever_expr() }>
    • associated type bounds
      • trait Foo<const C> { type Bar: Baz<C> }
    • supertraits
    • trait methods trait Foo<const C> { fn bar<const D>() }
    • dyn type upcasting with supertraits
      • dyn Foo<C> and trait Foo<C>: Bar<C>
    • async functions
      • async fn<const C>(x: [u8; C])
      • async fn<const C>() -> [u8; C]
      • async fn<const C>(x: [u8; C]) -> [u8; C]
    • where clauses
      • on methods, inherent and trait
    • cross-crate
  • const equality
    • generic parameter not equal to other generic parameter
    • two distinct expressions that evaluate to the same result
  • const fns
  • default values for const parameters should error
  • ordering of const parameters (only after types)
  • rustdoc
    • test that const generics look ok in various cases above
  • macros
    • #[macro_export] inside of types/repeat exprs
    • macro-hygiene re const params maybe.
    • substituting in the middle of a const expression
      • macro_rules! { $x:expr => [u8; $x] }
        • testing this with $x=C
        • with $x={C}
        • with $x={{C}}
      • similarly macro_rules! { $x:expr => [u8; {$x}] } what happens?
  • cross crate

things that were changed

  • name resolution to error if you encounter non-trivial references to const generic parameter
  • disabled lazy norm when using min const generics
  • during wf checking only allow a subset of types
    • bool, char, integral types
Select a repo