Skip to content

Regression in type inference between stable 1.79.0 and nightly-2024-06-19 #126685

Closed
@marmeladema

Description

@marmeladema

Code

I tried this code in nightly:

pub fn parse(bytes: &[u8]) -> String {
    std::ffi::CStr::from_bytes_until_nul(bytes)
        .unwrap()
        .to_str()
        .unwrap()
        .split('\n')
        .map(str::trim_end)
        .collect::<Box<_>>()
        .join("\n")
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=be71e0fb8185c11ac3123de70b02cee6

I expected to see this happen: it compiles successfully

Instead, this happened:

error[E0282]: type annotations needed
 --> src/lib.rs:8:10
  |
8 |         .collect::<Box<_>>()
  |          ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect`
9 |         .join("\n")
  |          ---- type must be known at this point
  |
help: consider specifying the generic argument
  |
8 |         .collect::<Vec<_>>()
  |                 ~~~~~~~~~~

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

Version it worked on

It most recently worked on: Rust 1.79.0

Version with regression

nightly-2024-06-19

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.T-releaseRelevant to the release subteam, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions