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

Nightly fails to infer the type of iterator collect & impl IntoIterator, and gives confusing error message #93794

Closed
wwylele opened this issue Feb 9, 2022 · 3 comments · Fixed by #93893
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wwylele
Copy link
Contributor

wwylele commented Feb 9, 2022

Code

I tried this code:

fn foo(b: bool) -> impl IntoIterator<Item = ()> {
    if b {
        return vec![()];
    }
    [()].into_iter().collect()
}

I expected to see this happen: The code compiles (as it does on stable and beta). The compiler could infer the return type from the first return statement (Vec<()>), and successfully collect the iterator into it in the second return.

Instead, this happened:
The compiler seems to have trouble to infer the type of the second return, and gives confusing messages. Instead of explaining that it cannot infer the type (which can be understandable given some update in the library), it gives some serious complaint that the given type doesn't support this kind of operation.

error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): a value of type `impl IntoIterator<Item = ()>` cannot be built from an iterator over elements of type `()`
    --> src/lib.rs:5:22
     |
5    |     [()].into_iter().collect()
     |                      ^^^^^^^ value of type `impl IntoIterator<Item = ()>` cannot be built from `std::iter::Iterator<Item=()>`
     |
     = help: the trait `FromIterator<()>` is not implemented for `impl IntoIterator<Item = ()>`
note: required by a bound in `collect`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

Version it worked on

It most recently worked on: Stable version: 1.58.1, 1.59.0-beta.6(2022-02-02 0426998)

Version with regression

rustc --version --verbose:

rustc 1.60.0-nightly (0c292c966 2022-02-08)
binary: rustc
commit-hash: 0c292c9667f1b202a9150d58bdd2e89e3e803996
commit-date: 2022-02-08
host: x86_64-pc-windows-msvc
release: 1.60.0-nightly
LLVM version: 13.0.0

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

@wwylele wwylele added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Feb 9, 2022
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-untriaged Untriaged performance or correctness regression. labels Feb 9, 2022
@wwylele wwylele changed the title Nightly failed to infer the type of iterator collect & impl IntoIterator, and gives confusing error message Nightly fails to infer the type of iterator collect & impl IntoIterator, and gives confusing error message Feb 9, 2022
@compiler-errors
Copy link
Member

cc #92007

@lqd
Copy link
Member

lqd commented Feb 9, 2022

cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Feb 9, 2022

Amazing. Yea I can totally see how this would happen.

@oli-obk oli-obk self-assigned this Feb 9, 2022
@oli-obk oli-obk added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 9, 2022
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 9, 2022
@bors bors closed this as completed in 6499c5e Feb 11, 2022
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Feb 24, 2022
Revert lazy TAIT PR

Revert rust-lang/rust#92306 (sorry `@Aaron1011,` will include your changes in the fix PR)
Revert rust-lang/rust#93783
Revert rust-lang/rust#92007

fixes rust-lang/rust#93788
fixes rust-lang/rust#93794
fixes rust-lang/rust#93821
fixes rust-lang/rust#93831
fixes rust-lang/rust#93841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants