Avoid ICE when handling const auto traits in the next-gen solver

This commit is contained in:
lapla 2025-11-26 01:02:01 +09:00
parent 3326fbd1f4
commit ae699c8e78
No known key found for this signature in database
GPG key ID: B39C71D9F127FF9F
3 changed files with 27 additions and 4 deletions

View file

@ -189,10 +189,11 @@ where
}
fn consider_auto_trait_candidate(
_ecx: &mut EvalCtxt<'_, D>,
ecx: &mut EvalCtxt<'_, D>,
_goal: Goal<I, Self>,
) -> Result<Candidate<I>, NoSolution> {
unreachable!("auto traits are never const")
ecx.cx().delay_bug("auto traits are never const");
Err(NoSolution)
}
fn consider_trait_alias_candidate(

View file

@ -1,6 +1,15 @@
//@ compile-flags: -Znext-solver
// See rust-lang/rust#149285 for this test
#![feature(auto_traits, const_trait_impl)]
const auto trait Marker {}
//~^ ERROR: auto traits cannot be const
fn scope() {
fn check<T: const Marker>() {}
check::<()>();
//~^ ERROR: the trait bound `(): const Marker` is not satisfied
}
fn main() {}

View file

@ -1,10 +1,23 @@
error: auto traits cannot be const
--> $DIR/const-auto-trait.rs:3:1
--> $DIR/const-auto-trait.rs:6:1
|
LL | const auto trait Marker {}
| ^^^^^
|
= help: remove the `const` keyword
error: aborting due to 1 previous error
error[E0277]: the trait bound `(): const Marker` is not satisfied
--> $DIR/const-auto-trait.rs:11:13
|
LL | check::<()>();
| ^^
|
note: required by a bound in `check`
--> $DIR/const-auto-trait.rs:10:17
|
LL | fn check<T: const Marker>() {}
| ^^^^^^^^^^^^ required by this bound in `check`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.