diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index 2cb79a0219f6..2837b8565f60 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -189,10 +189,11 @@ where } fn consider_auto_trait_candidate( - _ecx: &mut EvalCtxt<'_, D>, + ecx: &mut EvalCtxt<'_, D>, _goal: Goal, ) -> Result, NoSolution> { - unreachable!("auto traits are never const") + ecx.cx().delay_bug("auto traits are never const"); + Err(NoSolution) } fn consider_trait_alias_candidate( diff --git a/tests/ui/traits/const-traits/const-auto-trait.rs b/tests/ui/traits/const-traits/const-auto-trait.rs index 06558df4623f..d1745a2ec4c7 100644 --- a/tests/ui/traits/const-traits/const-auto-trait.rs +++ b/tests/ui/traits/const-traits/const-auto-trait.rs @@ -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() {} + check::<()>(); + //~^ ERROR: the trait bound `(): const Marker` is not satisfied +} + fn main() {} diff --git a/tests/ui/traits/const-traits/const-auto-trait.stderr b/tests/ui/traits/const-traits/const-auto-trait.stderr index cb8ff8001ba0..094c334fc289 100644 --- a/tests/ui/traits/const-traits/const-auto-trait.stderr +++ b/tests/ui/traits/const-traits/const-auto-trait.stderr @@ -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() {} + | ^^^^^^^^^^^^ required by this bound in `check` +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`.