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

Type annotations needed in assertion #113283

Closed
laurmaedje opened this issue Jul 3, 2023 · 7 comments
Closed

Type annotations needed in assertion #113283

laurmaedje opened this issue Jul 3, 2023 · 7 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@laurmaedje
Copy link
Contributor

Code

I tried this code:

fn main() {
    let array: [Box<i32>; 0] = [];
    assert_eq!(array.into_iter().collect::<Vec<_>>(), []);
}

I expected to see this happen: Compiles and assertion passes.

Instead, this happened: Compiler wants type annotation somewhere in assertion. Span is on whole assertion.

Version it worked on

It most recently worked on: 1.70 stable

Version with regression

Recent nightlies (also occurs on Rust playground)

rustc --version --verbose:

rustc 1.72.0-nightly (839e9a6e1 2023-07-02)
binary: rustc
commit-hash: 839e9a6e1210934fd24b15548b811a97c77138fc
commit-date: 2023-07-02
host: aarch64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.5
@laurmaedje laurmaedje added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jul 3, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 3, 2023
@lukas-code
Copy link
Member

probaby caused by #112628

slightly smaller:

fn main() {
    let array: [Box<i32>; 0] = [];
    let _ = array == [];
}
error[[E0282]](https://doc.rust-lang.org/nightly/error_codes/E0282.html): type annotations needed
 --> src/main.rs:4:19
  |
4 |     let _ = array == [];
  |                   ^^ cannot infer type for type parameter `A2`

@rustbot label -regression-untriaged +regression-from-stable-to-nightly +T-libs

@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed regression-untriaged Untriaged performance or correctness regression. labels Jul 3, 2023
@lqd
Copy link
Member

lqd commented Jul 3, 2023

Almost no PRs in the #113105 rollup where it landed have artifacts, but it seems likely indeed. Especially when the PR itself has a comment about a similar regression #112628 (comment)

@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 3, 2023
@lqd
Copy link
Member

lqd commented Jul 3, 2023

For visibility, cc PR author @gootorov, and reviewer @joshtriplett.

@tgross35
Copy link
Contributor

tgross35 commented Jul 4, 2023

I think our best case for now is to revert the commit and figure out what the fix is as time allows. I submitted a PR that adds a regression test and reverts: #113318

The invalid_type_param_default feature might be one way to fix this with a default type, but I'm not sure if this is anywhere near stable enough for indirect public use.

Vec has a similar PartialEq - can it be broken too?

tgross35 added a commit to tgross35/rust that referenced this issue Jul 4, 2023
…st-lang#113283)

Verify that `PartialEq` implementations do not break type inference
when comparing types across different allocators. This catches a
regression in current nightly introduced in 001b081 (alloc: Allow
comparing `Box`s over different allocators")

`Box` is the only type that currently impelements this, but tests are
included for `Rc` and `Arc` to prevent future regresssions.
@m-ou-se m-ou-se added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 6, 2023
@tgross35
Copy link
Contributor

tgross35 commented Jul 6, 2023

The Vec comparison has been stable for a year so I guess that one is fine ee23fd2. I'd still be curious to see a similar situation where Vec fails inference in a similar way, if it is possible.

@lukas-code
Copy link
Member

I'd still be curious to see a similar situation where Vec fails inference in a similar way

If you just replace Box with Vec you also get an inference error:

fn main() {
    let array: [Vec<i32>; 0] = [];
    let _ = array == [];
}
error[[E0282]](https://doc.rust-lang.org/stable/error_codes/E0282.html): type annotations needed
 --> src/main.rs:3:22
  |
3 |     let _ = array == [];
  |                      ^^ cannot infer type

The reason why for type parameter `A2` doesn't show up in the error and ee23fd2 didn't regress inference is because Vec<T> as PartialEq<_> has always been ambiguous between PartialEq<&[T]>, PartialEq<&mut [T]>, and PartialEq<[T]>.

Box<T> as PartialEq<_> used to be unambiguous, inferring Box<T> as PartialEq<Box<T>>. With #112628, the more common case of Box<T> as PartialEq<Box<_>> is still unambiguous, but Box<T> as PartialEq<_> became ambiguous for the allocator of the right-hand side.

compiler-errors added a commit to compiler-errors/rust that referenced this issue Jul 7, 2023
…, r=m-ou-se

Revert "alloc: Allow comparing Boxs over different allocators", add regression test

Temporary fix for rust-lang#113283

Adds a test to fix the regression introduced in 001b081 and revert that commit. The test fails without the revert.
@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jul 11, 2023
@Amanieu
Copy link
Member

Amanieu commented Jul 12, 2023

Closing since the revert has been merged.

@Amanieu Amanieu closed this as completed Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants