Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,29 @@ where
}

fn consider_builtin_iterator_candidate(
_ecx: &mut EvalCtxt<'_, D>,
ecx: &mut EvalCtxt<'_, D>,
_goal: Goal<I, Self>,
) -> Result<Candidate<I>, 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<I, Self>,
) -> Result<Candidate<I>, 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(
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/traits/next-solver/iterator-ice.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
48 changes: 48 additions & 0 deletions tests/ui/traits/next-solver/iterator-ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
error[E0658]: cannot use `for` loop on `std::ops::Range<i32>` 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 <https://github.com/rust-lang/rust/issues/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<i32>` 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 <https://github.com/rust-lang/rust/issues/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`.
Loading