From 715db45be13ed26ced2d23ef02ab669d85355c0b Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Fri, 6 Feb 2026 17:42:56 +0000 Subject: [PATCH 1/4] implement built-in candidate --- .../src/solve/effect_goals.rs | 20 ++++++-- tests/ui/traits/next-solver/iterator-ice.rs | 11 +++++ .../ui/traits/next-solver/iterator-ice.stderr | 48 +++++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 tests/ui/traits/next-solver/iterator-ice.rs create mode 100644 tests/ui/traits/next-solver/iterator-ice.stderr 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..92d851c3f777f --- /dev/null +++ b/tests/ui/traits/next-solver/iterator-ice.rs @@ -0,0 +1,11 @@ +//@ compile-flags: -Znext-solver=globally + +fn main() { + const { + for _ in 1..5 {} + //~^ ERROR cannot use `for` loop on `std::ops::Range` in constants + //~| ERROR `IntoIterator` is not yet stable as a const trait + //~| ERROR cannot use `for` loop on `std::ops::Range` in constants + //~| ERROR `Iterator` is not yet stable as a const trait + } +} \ No newline at end of file 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..9eaee8e26d6ab --- /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:5: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:5: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:5: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:5: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`. From 67af22f3897d264f395707165388fe6fbf3b11ed Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Fri, 6 Feb 2026 18:14:43 +0000 Subject: [PATCH 2/4] fix tidy --- tests/ui/traits/next-solver/iterator-ice.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/traits/next-solver/iterator-ice.rs b/tests/ui/traits/next-solver/iterator-ice.rs index 92d851c3f777f..3c1cd86685330 100644 --- a/tests/ui/traits/next-solver/iterator-ice.rs +++ b/tests/ui/traits/next-solver/iterator-ice.rs @@ -1,11 +1,11 @@ //@ compile-flags: -Znext-solver=globally fn main() { - const { - for _ in 1..5 {} + const { + for _ in 1..5 {} //~^ ERROR cannot use `for` loop on `std::ops::Range` in constants //~| ERROR `IntoIterator` is not yet stable as a const trait //~| ERROR cannot use `for` loop on `std::ops::Range` in constants //~| ERROR `Iterator` is not yet stable as a const trait } -} \ No newline at end of file +} From 4c1a9cb082ba5e2b7964f448970a7a04f76a0734 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Fri, 6 Feb 2026 18:39:41 +0000 Subject: [PATCH 3/4] trigger CI From b46780feacc2cb20b80a9cc3c3127b67e08a84e6 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Sat, 7 Feb 2026 11:25:47 +0000 Subject: [PATCH 4/4] fix ci --- tests/ui/traits/next-solver/iterator-ice.rs | 9 +++++---- tests/ui/traits/next-solver/iterator-ice.stderr | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/ui/traits/next-solver/iterator-ice.rs b/tests/ui/traits/next-solver/iterator-ice.rs index 3c1cd86685330..d28f2ecc21ff1 100644 --- a/tests/ui/traits/next-solver/iterator-ice.rs +++ b/tests/ui/traits/next-solver/iterator-ice.rs @@ -1,11 +1,12 @@ //@ compile-flags: -Znext-solver=globally +//@ edition: 2021 fn main() { const { for _ in 1..5 {} - //~^ ERROR cannot use `for` loop on `std::ops::Range` in constants - //~| ERROR `IntoIterator` is not yet stable as a const trait - //~| ERROR cannot use `for` loop on `std::ops::Range` in constants - //~| ERROR `Iterator` is not yet stable as a const trait + //~^ 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 index 9eaee8e26d6ab..38dd16ed88402 100644 --- a/tests/ui/traits/next-solver/iterator-ice.stderr +++ b/tests/ui/traits/next-solver/iterator-ice.stderr @@ -1,7 +1,7 @@ error[E0658]: cannot use `for` loop on `std::ops::Range` in constants - --> $DIR/iterator-ice.rs:5:18 + --> $DIR/iterator-ice.rs:6:18 | -LL | for _ in 1..5 {} +LL | for _ in 1..5 {} | ^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants @@ -10,9 +10,9 @@ LL | for _ in 1..5 {} = 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:5:18 + --> $DIR/iterator-ice.rs:6:18 | -LL | for _ in 1..5 {} +LL | for _ in 1..5 {} | ^^^^ | help: add `#![feature(const_iter)]` to the crate attributes to enable @@ -21,9 +21,9 @@ LL + #![feature(const_iter)] | error[E0658]: cannot use `for` loop on `std::ops::Range` in constants - --> $DIR/iterator-ice.rs:5:18 + --> $DIR/iterator-ice.rs:6:18 | -LL | for _ in 1..5 {} +LL | for _ in 1..5 {} | ^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants @@ -33,9 +33,9 @@ LL | for _ in 1..5 {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: `Iterator` is not yet stable as a const trait - --> $DIR/iterator-ice.rs:5:18 + --> $DIR/iterator-ice.rs:6:18 | -LL | for _ in 1..5 {} +LL | for _ in 1..5 {} | ^^^^ | help: add `#![feature(const_iter)]` to the crate attributes to enable