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

Bad error message for infinite type recursion #121090

Open
pacak opened this issue Feb 14, 2024 · 2 comments
Open

Bad error message for infinite type recursion #121090

pacak opened this issue Feb 14, 2024 · 2 comments
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pacak
Copy link
Contributor

pacak commented Feb 14, 2024

Code

#![recursion_limit = "5"]
#![allow(unconditional_recursion)]

fn quicksort<It, I>(i: I) -> Vec<i32>
where
    It: Iterator<Item = i32>,
    I: IntoIterator<IntoIter = It>,
{
    quicksort(i.into_iter().filter(|_| true))
}

pub fn bar(xs: Vec<i32>) -> Vec<i32> {
    quicksort(xs)
}

Current output

relevant error:

error[E0275]: overflow evaluating the requirement `Filter<Filter<Filter<Filter<Filter<std::vec::IntoIter<i32>, ...>, ...>, ...>, ...>, ...>: Iterator`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`qsort`)
  = note: required for `Filter<Filter<Filter<Filter<Filter<std::vec::IntoIter<i32>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>` to implement `IntoIterator`

Desired output

something-something infinite recursion

Rationale and extra context

Suggestion to increase recursion limit is wrong

Other cases

No response

Rust Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Anything else?

No response

@pacak pacak 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 Feb 14, 2024
@estebank estebank added A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. A-const-prop Area: Constant propagation labels Feb 14, 2024
@oli-obk oli-obk added A-const-eval Area: Constant evaluation (MIR interpretation) and removed A-const-prop Area: Constant propagation labels Feb 14, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 15, 2024
…ow, r=oli-obk

Do not report overflow errors on ConstArgHasType goals

This is 10% of a fix for rust-lang#121090, since it at least means that we no longer mention the `ConstArgHasType` goal as the cause for the overflow. Instead, now we mention:
```
overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
```
which is not much better, but slightly.

r? oli-obk
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 15, 2024
Rollup merge of rust-lang#121105 - compiler-errors:no-const-ty-overflow, r=oli-obk

Do not report overflow errors on ConstArgHasType goals

This is 10% of a fix for rust-lang#121090, since it at least means that we no longer mention the `ConstArgHasType` goal as the cause for the overflow. Instead, now we mention:
```
overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
```
which is not much better, but slightly.

r? oli-obk
@pacak
Copy link
Contributor Author

pacak commented Apr 6, 2024

New error message is as following:

Compiling playground v0.0.1 (/playground)
error[[E0275]](https://doc.rust-lang.org/nightly/error_codes/E0275.html): overflow evaluating the requirement `{closure@src/main.rs:6:41: 6:44}: Sized`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
  = note: required for `Filter<std::array::IntoIter<i32, 11>, {closure@src/main.rs:6:41: 6:44}>` to implement `Iterator`
  = note: 127 redundant requirements hidden
  = note: required for `Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<..., ...>, ...>, ...>, ...>, ...>, ...>, ...>, ...>` to implement `Iterator`
  = note: required for `Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<..., ...>, ...>, ...>, ...>, ...>, ...>, ...>, ...>` to implement `IntoIterator`
  = note: the full name for the type has been written to '/playground/target/debug/deps/playground-22e77209e34c162a.long-type-15773489000561340382.txt'
  = note: consider using `--verbose` to print the full type name to the console
  = note: the full name for the type has been written to '/playground/target/debug/deps/playground-22e77209e34c162a.long-type-15773489000561340382.txt'
  = note: consider using `--verbose` to print the full type name to the console

For more information about this error, try `rustc --explain E0275`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Suggestion to increase recursion limit is wrong.

@pacak pacak changed the title Bad error message for strange looking recursion Bad error message for infinite type recursion Apr 6, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Apr 8, 2024

Under the new solver this gives the following output:

error[E0283]: type annotations needed
 --> <source>:9:5
  |
9 |     quicksort(i.into_iter().filter(|_| true))
  |     ^^^^^^^^^ cannot infer type of the type parameter `It` declared on the function `quicksort`
  |
  = note: cannot satisfy `_: Iterator`
note: required by a bound in `quicksort`
 --> <source>:6:9
  |
4 | fn quicksort<It, I>(i: I) -> Vec<i32>
  |    --------- required by a bound in this function
5 | where
6 |     It: Iterator<Item = i32>,
  |         ^^^^^^^^^^^^^^^^^^^^ required by this bound in `quicksort`
help: consider specifying the generic arguments
  |
9 |     quicksort::<It, _>(i.into_iter().filter(|_| true))
  |              +++++++++

error[E0275]: overflow evaluating the requirement `Filter<It, {closure@<source>:9:36: 9:39}>: IntoIterator`
 --> <source>:9:15
  |
9 |     quicksort(i.into_iter().filter(|_| true))
  |     --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     required by a bound introduced by this call
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`example`)
note: required by a bound in `quicksort`
 --> <source>:7:8
  |
4 | fn quicksort<It, I>(i: I) -> Vec<i32>
  |    --------- required by a bound in this function
...
7 |     I: IntoIterator<IntoIter = It>,
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `quicksort`
help: consider removing this method call, as the receiver has type `<I as IntoIterator>::IntoIter` and `<I as IntoIterator>::IntoIter: IntoIterator` trivially holds
  |
9 -     quicksort(i.into_iter().filter(|_| true))
9 +     quicksort(i.into_iter())
  |

error[E0275]: overflow evaluating the requirement `<Filter<It, {closure@<source>:9:36: 9:39}> as IntoIterator>::IntoIter == It`
 --> <source>:9:15
  |
9 |     quicksort(i.into_iter().filter(|_| true))
  |     --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     required by a bound introduced by this call
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`example`)
note: required by a bound in `quicksort`
 --> <source>:7:21
  |
4 | fn quicksort<It, I>(i: I) -> Vec<i32>
  |    --------- required by a bound in this function
...
7 |     I: IntoIterator<IntoIter = It>,
  |                     ^^^^^^^^^^^^^ required by this bound in `quicksort`

@oli-obk oli-obk added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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