monomorphization recursion limit error should be caught earlier

5628d39
Opened by Jonas Pollok at 2024-12-21 05:10:51

This little program gives a "reached the recursion limit during monomorphization" error.

fn main() {
    go(range(0, 5u));
}

fn go<T>(it: T) where T: Iterator<uint> {
    let mut p = it;
    match p.next() {
        Some(_) => {
            go(p.by_ref());
        }
        None => {}
    }
}

http://is.gd/3iN5Kf

The recursion limit is reached due to wrapping the iterator into ByRefs for every recursion step. IRC suggested that this could be a bug as this should be caught before monomorphization.

  1. This is actually fairly non-trivial to do. Nonetheless we could certainly catch simple instances of it, even though we'd still have to check in trans. This may be worth the effort for the improved user experience.

    Niko Matsakis at 2015-02-11 15:01:46

  2. Traige, no change, but updated code: http://is.gd/ODEW7P

    Steve Klabnik at 2016-03-04 17:49:25

  3. Triage; no change

    Steve Klabnik at 2018-09-24 17:54:03