Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintuitive error when recursing with generic Fn closure borrow #99250

Closed
rob9315 opened this issue Jul 14, 2022 · 2 comments
Closed

Unintuitive error when recursing with generic Fn closure borrow #99250

rob9315 opened this issue Jul 14, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rob9315
Copy link

rob9315 commented Jul 14, 2022

i understand why this error happens, it might just be nice to have some sort of system to detect
when this kind of recursion is happening and try to prevent it or at least hint at what the error
could be better.

Given the following code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1974b5d37cb10e1214937db3c0e779dc

The current output is:

   Compiling playground v0.0.1 (/playground)
error: reached the recursion limit while instantiating `<iter::adapters::GenericShunt<Ma...terator>::collect::<Vec<String>>`
     |
note: `collect` defined here
     = note: the full type name has been written to '/playground/target/debug/deps/playground-f30fbb6d88a6f004.long-type.txt'

error: could not compile `playground` due to previous error

/playground/target/debug/deps/playground-f30fbb6d88a6f004.long-type.txt:
<iter::adapters::GenericShunt<Map<std::vec::IntoIter<String>, &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[closure@error/src/main.rs:9:41: 14:6]>, Result<Infallible, ()>> as Iterator>::collect::<Vec<String>>

Ideally the output should look like:

 |
 |    .map(|input| weird_recursive(input, &f))
 |                                        ^^
 = note: borrow of generic argument in loop when recursing,
 = note: consider changing your function signature
@rob9315 rob9315 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 14, 2022
@Chris00
Copy link

Chris00 commented Dec 27, 2022

The error message could also be improved for mutually recursive generic functions: see playground. For this minimal example, the error is still clear but, in my case, the error was:

error[E0275]: overflow evaluating the requirement `[closure@src/bin/compare_damping.rs:47:13: 47:21]: Fn<(Complex<f64>,)>`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`compare_damping`)
  = note: required for `&[closure@src/bin/compare_damping.rs:47:13: 47:21]` to implement `Fn<(Complex<f64>,)>`
  = note: 128 redundant requirements hidden
  = note: required for `&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[closure@src/bin/compare_damping.rs:47:13: 47:21]` to implement `Fn<(Complex<f64>,)>`

For more information about this error, try `rustc --explain E0275`.

which did not even refer to the library function; it only pointed to the call site (which was not the recursive function) and was not giving appropriate advice.

In this case, the advice should be to define a struct holding the generic parameters and define the mutually recursive functions as methods (so they are instantiated once).

@Enselic
Copy link
Member

Enselic commented Aug 17, 2023

Closing as duplicate to #50043

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants