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 2837b8565f603..850d32e5c0b99 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -352,17 +352,29 @@ where } fn consider_builtin_iterator_candidate( - _ecx: &mut EvalCtxt<'_, D>, + ecx: &mut EvalCtxt<'_, D>, _goal: Goal, ) -> Result, NoSolution> { - todo!("Iterator is not yet const") + let certainty = ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)?; + + Ok(Candidate { + source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), + result: certainty, + head_usages: Default::default(), + }) } fn consider_builtin_fused_iterator_candidate( - _ecx: &mut EvalCtxt<'_, D>, + ecx: &mut EvalCtxt<'_, D>, _goal: Goal, ) -> Result, NoSolution> { - unreachable!("FusedIterator is not const") + let certainty = ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)?; + + Ok(Candidate { + source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), + result: certainty, + head_usages: Default::default(), + }) } fn consider_builtin_async_iterator_candidate( diff --git a/tests/ui/traits/next-solver/iterator-ice.rs b/tests/ui/traits/next-solver/iterator-ice.rs new file mode 100644 index 0000000000000..d28f2ecc21ff1 --- /dev/null +++ b/tests/ui/traits/next-solver/iterator-ice.rs @@ -0,0 +1,12 @@ +//@ compile-flags: -Znext-solver=globally +//@ edition: 2021 + +fn main() { + const { + for _ in 1..5 {} + //~^ ERROR cannot use `for` loop + //~| ERROR `IntoIterator` is not yet stable + //~| ERROR cannot use `for` loop + //~| ERROR `Iterator` is not yet stable + } +} diff --git a/tests/ui/traits/next-solver/iterator-ice.stderr b/tests/ui/traits/next-solver/iterator-ice.stderr new file mode 100644 index 0000000000000..38dd16ed88402 --- /dev/null +++ b/tests/ui/traits/next-solver/iterator-ice.stderr @@ -0,0 +1,48 @@ +error[E0658]: cannot use `for` loop on `std::ops::Range` in constants + --> $DIR/iterator-ice.rs:6:18 + | +LL | for _ in 1..5 {} + | ^^^^ + | + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + = note: see issue #143874 for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: `IntoIterator` is not yet stable as a const trait + --> $DIR/iterator-ice.rs:6:18 + | +LL | for _ in 1..5 {} + | ^^^^ + | +help: add `#![feature(const_iter)]` to the crate attributes to enable + | +LL + #![feature(const_iter)] + | + +error[E0658]: cannot use `for` loop on `std::ops::Range` in constants + --> $DIR/iterator-ice.rs:6:18 + | +LL | for _ in 1..5 {} + | ^^^^ + | + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + = note: see issue #143874 for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: `Iterator` is not yet stable as a const trait + --> $DIR/iterator-ice.rs:6:18 + | +LL | for _ in 1..5 {} + | ^^^^ + | +help: add `#![feature(const_iter)]` to the crate attributes to enable + | +LL + #![feature(const_iter)] + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0658`.