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

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

Open
marmeladema opened this issue Jun 19, 2024 · 5 comments
Open
Labels
A-inference Area: Type inference C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@marmeladema
Copy link
Contributor

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

@marmeladema marmeladema added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jun 19, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 19, 2024
@marmeladema
Copy link
Contributor Author

Minimized a bit:

pub fn parse(input: &str) -> String {
    input
        .split('\n')
        .map(str::trim_end)
        .collect::<Box<_>>()
        .join("\n")
}

@veera-sivarajan
Copy link
Contributor

@rustbot label -needs-triage -regression-untriaged +regression-from-stable-to-nightly +T-compiler +A-inference

@rustbot rustbot added A-inference Area: Type inference 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. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-untriaged Untriaged performance or correctness regression. labels Jun 19, 2024
@apiraino
Copy link
Contributor

Bisection points to #99969 cc @dtolnay @calebsander

Can this issue be considered an intended or rather an unintended behaviour?

I can reproduce in beta so I'll flip the regression labels

@apiraino apiraino added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Jun 19, 2024
@calebsander
Copy link
Contributor

I think this is expected. With the additional implementation of collect() into Box<str>, it's now ambiguous whether Box<_> means Box<[_]> or Box<str>. It's unfortunate to regress existing code that wasn't being explicit, but I think this is an acceptable cost for the additional functionality.

@marmeladema
Copy link
Contributor Author

Fine by me. Maybe this should be announced as part of the release note to let people know?

@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

5 participants