Files
rust/tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.rs
Matthias Krüger 36c2b011cb Rollup merge of #139858 - oli-obk:new-const-traits-syntax, r=fee1-dead
New const traits syntax

This PR only affects the AST and doesn't actually change anything semantically.

All occurrences of `~const` outside of libcore have been replaced by `[const]`. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts `~const` into `[const]`. After this we can remove the `~const` support from the parser

Caveat discovered during impl: there is no legacy bare trait object recovery for `[const] Trait` as that snippet in type position goes down the slice /array parsing code and will error

r? ``@fee1-dead``

cc ``@nikomatsakis`` ``@traviscross`` ``@compiler-errors``
2025-06-27 22:13:00 +02:00

33 lines
833 B
Rust

// This test demonstrates an ICE that may occur when we try to resolve the instance
// of a impl that has different generics than the trait it's implementing. This ensures
// we first check that the args are compatible before resolving the body, just like
// we do in projection before substituting a GAT.
//
// Regression test for issue #125877.
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl, effects)]
//~^ ERROR feature has been removed
#[const_trait]
trait Main {
fn compute<T: [const] Aux>() -> u32;
}
impl const Main for () {
fn compute<'x>() -> u32 {
//~^ ERROR associated function `compute` has 0 type parameters but its trait declaration has 1 type parameter
0
}
}
#[const_trait]
trait Aux {}
impl const Aux for () {}
fn main() {
const _: u32 = <()>::compute::<()>();
}