Repository navigation
Description
Code
Minimal reproduction with no dependencies; build with rustc --edition 2021 --crate-type lib repro.rs.
// Minimal reproduction distilled from objc2 0.4.1 (src/declare/ivar.rs and
// src/declare/ivar_forwarding_impls.rs). No dependencies.
use std::marker::PhantomData;
use std::ops::Deref;
pub trait InnerIvarType {
type Output;
}
pub trait IvarType {
type Type: InnerIvarType;
}
pub struct Ivar<I: IvarType> {
item: PhantomData<I>,
}
impl<I: IvarType> Deref for Ivar<I> {
type Target = <I::Type as InnerIvarType>::Output;
fn deref(&self) -> &Self::Target {
unimplemented!()
}
}
impl<I: IvarType> std::ops::DerefMut for Ivar<I> {
fn deref_mut(&mut self) -> &mut Self::Target {
unimplemented!()
}
}
impl<I: IvarType> Iterator for Ivar<I>
where
<Self as Deref>::Target: Iterator,
{
type Item = <<Self as Deref>::Target as Iterator>::Item;
fn next(&mut self) -> Option<<<Self as Deref>::Target as Iterator>::Item> {
(**self).next()
}
fn nth(&mut self, n: usize) -> Option<<<Self as Deref>::Target as Iterator>::Item> {
(**self).nth(n)
}
}
impl<I: IvarType> DoubleEndedIterator for Ivar<I>
where
<Self as Deref>::Target: DoubleEndedIterator,
{
fn next_back(&mut self) -> Option<<<Self as Deref>::Target as Iterator>::Item> {
(**self).next_back()
}
fn nth_back(&mut self, n: usize) -> Option<<<Self as Deref>::Target as Iterator>::Item> {
(**self).nth_back(n)
}
}I expected to see this happen
It compiles, as it does on 1.97.0, 1.98.0 and 1.99.0.
Instead, this happened
On 1.100.0:
error[E0277]: `<<I as IvarType>::Type as InnerIvarType>::Output` is not an iterator
--> /tmp/repro.rs:39:5
|
39 | fn nth(&mut self, n: usize) -> Option<<<Self as Deref>::Target as Iterator>::Item> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<<I as IvarType>::Type as InnerIvarType>::Output` is not an iterator
|
= help: the trait `Iterator` is not implemented for `<<I as IvarType>::Type as InnerIvarType>::Output`
note: required for `Ivar<I>` to implement `Iterator`
--> /tmp/repro.rs:31:19
|
31 | impl<I: IvarType> Iterator for Ivar<I>
| ^^^^^^^^ ^^^^^^^
32 | where
33 | <Self as Deref>::Target: Iterator,
| -------- unsatisfied trait bound introduced here
help: consider further restricting the associated type
|
39 | fn nth(&mut self, n: usize) -> Option<<<Self as Deref>::Target as Iterator>::Item> where <<I as IvarType>::Type as InnerIvarType>::Output: Iterator {
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0277]: `<<I as IvarType>::Type as InnerIvarType>::Output` is not an iterator
--> /tmp/repro.rs:51:5
|
51 | fn nth_back(&mut self, n: usize) -> Option<<<Self as Deref>::Target as Iterator>::Item> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<<I as IvarType>::Type as InnerIvarType>::Output` is not an iterator
|
= help: the trait `Iterator` is not implemented for `<<I as IvarType>::Type as InnerIvarType>::Output`
note: required for `Ivar<I>` to implement `Iterator`
--> /tmp/repro.rs:31:19
|
31 | impl<I: IvarType> Iterator for Ivar<I>
| ^^^^^^^^ ^^^^^^^
32 | where
33 | <Self as Deref>::Target: Iterator,
| -------- unsatisfied trait bound introduced here
help: consider further restricting the associated type
|
51 | fn nth_back(&mut self, n: usize) -> Option<<<Self as Deref>::Target as Iterator>::Item> where <<I as IvarType>::Type as InnerIvarType>::Output: Iterator {
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.
The error is reported only on the overridden nth and nth_back; next and next_back are accepted.
Version it worked on
It most recently worked on: Rust 1.99.0 (also checked 1.97.0 and 1.98.0).
Version with regression
rustc --version --verbose:
rustc 1.100.0 (0ef1bc386 2026-11-09)
binary: rustc
commit-hash: 0ef1bc386059596dada8fb65b50425aab2ea637a
commit-date: 2026-11-09
host: aarch64-apple-darwin
release: 1.100.0
LLVM version: 23.1.5
Likely cause
Not bisected to a nightly yet. Between 1.99.0 and 1.100.0, #156216 ("implement const Iterator for Range", merged via rollup #162853) removed #[rustc_non_const_trait_method] from Iterator::nth and DoubleEndedIterator::nth_back and gave both a new bound:
fn nth(&mut self, n: usize) -> Option<Self::Item>
where
Self::Item: [const] Destruct,That matches the symptom exactly: only the two methods that gained a where-clause fail.
This looks like the same problem as #109632 (2023), where the identical error in objc2 was bisected to #104100, which added a ~const Destruct bound to Iterator::nth. There it was described as a general limitation of the old trait solver, and the code built with the new solver.
It doesn't appear to be const-specific: on 1.97.0, a local trait whose provided nth has a plain where Self::Item: Marker bound (with a blanket impl<T: ?Sized> Marker for T {}) fails the same way with the default solver and compiles with -Znext-solver. The reproduction above also compiles with -Znext-solver on 1.97.0.
Non-const analog (fails on 1.97.0 with the default solver)
use std::marker::PhantomData;
use std::ops::Deref;
pub trait Marker {}
impl<T: ?Sized> Marker for T {}
pub trait MyIter {
type Item;
fn next(&mut self) -> Option<Self::Item>;
fn nth(&mut self, _n: usize) -> Option<Self::Item> where Self::Item: Marker { self.next() }
}
pub trait InnerIvarType { type Output; }
pub trait IvarType { type Type: InnerIvarType; }
pub struct Ivar<I: IvarType> { item: PhantomData<I> }
impl<I: IvarType> Deref for Ivar<I> {
type Target = <I::Type as InnerIvarType>::Output;
fn deref(&self) -> &Self::Target { unimplemented!() }
}
impl<I: IvarType> std::ops::DerefMut for Ivar<I> {
fn deref_mut(&mut self) -> &mut Self::Target { unimplemented!() }
}
impl<I: IvarType> MyIter for Ivar<I>
where
<Self as Deref>::Target: MyIter,
{
type Item = <<Self as Deref>::Target as MyIter>::Item;
fn next(&mut self) -> Option<<<Self as Deref>::Target as MyIter>::Item> { (**self).next() }
fn nth(&mut self, n: usize) -> Option<<<Self as Deref>::Target as MyIter>::Item> { (**self).nth(n) }
}error[E0277]: the trait bound `<<I as IvarType>::Type as InnerIvarType>::Output: MyIter` is not satisfied
Impact
objc2 0.4.1 is a dependency of winit 0.29 and glutin 0.31 on Apple targets, so macOS builds of projects still on winit 0.29 (for example anything using eframe 0.27) fail on 1.100.0. objc2 0.5+ no longer contains this code, so no upstream 0.4.x fix exists. Downstream workarounds: remove the nth/nth_back overrides via [patch.crates-io], or build with 1.99.0 or earlier.
@rustbot label +regression-from-stable-to-stable
Activity
theemathas commentedon Nov 20, 2026
Smaller reproducer (compiles on 1.99, errors on 1.100):
theemathas commentedon Nov 20, 2026
Bisection results:
searched nightlies: from nightly-2026-08-15 to nightly-2026-09-26
regressed nightly: nightly-2026-09-17
searched commit range: 215a8af...923c95c
regressed commit: 92801ed
bisected with cargo-bisect-rustc v0.6.12
Host triple: aarch64-apple-darwin
Reproduce with:
It does in fact appear to be regressed by #156216. cc @Randl (author), @clarfonthey (reviewer)
theemathas commentedon Nov 20, 2026
cc @rust-lang/project-const-traits
theemathas commentedon Nov 20, 2026
Self-contained reproducer:
Error:
Next-solver does not fix this.
2 remaining items
theemathas commentedon Nov 20, 2026
See also: #148028
Types-nominating to decide on what to do with this.
rustbot commentedon Nov 20, 2026
🤖 A dedicated
#t-types/nominatedtopic has been opened for humans to discuss this issue 🤖RalfJung commentedon Nov 22, 2026
Ouch, and #109684 did not add a test.... :/
lcnr commentedon Nov 23, 2026
This is due to
ParamEnvnormalization, fixed by-Zdisable-param-env-normalization-hackhttps://rust.godbolt.org/z/nvdvo4Yh8 with the new solver enabled. Actually changingParamEnvnormalization to support this does feel somewhat far off, unsure when exactly we'll do thathttps://github.com/rust-lang/trait-system-refactor-initiative/blob/main/notes/stabilization-report/aliases-and-type-relations.md#paramenv-normalization-jank
lcnr commentedon Nov 23, 2026
From a Types POV this feels like a bug that's quite hard to avoid. At least I can't think of an immediate fix on our side. I would very much revert this change on stable.
We do have an interesting option to fix this separate from the revert (and requiring a T-types FCP)
rust/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Lines 218 to 220 in 0259d5e
We could normalize the hybrid env in two steps:
That should fix issues like this. It is still rather unprincipled, would be more generally desirable however
clarfonthey commentedon Nov 23, 2026
(Removing prioritize label + libs nomination since we're doing that discussion on the revert PR.)
Rollup merge of rust-lang#166340 - clarfonthey:revert-iter-range, r=J…
Unrolled build for #166340 in rollup 166507