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

Emit alias-eq when equating numeric var and projection #108828

Merged
merged 3 commits into from
Mar 11, 2023

Conversation

compiler-errors
Copy link
Member

This doesn't fix everything having to do with projections and infer vars, but it does fix a common case I saw in HIR typeck.

r? @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 6, 2023
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after nits

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Mar 9, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@@ -148,10 +148,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rhs_ty,
op,
);
self.demand_suptype(expr.span, builtin_return_ty, return_ty);
self.demand_eqtype(expr.span, builtin_return_ty, return_ty);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demand_suptype doesn't matter because the only types we're gonna encounter here are scalars.

@@ -148,10 +148,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rhs_ty,
op,
);
self.demand_suptype(expr.span, builtin_return_ty, return_ty);
self.demand_eqtype(expr.span, builtin_return_ty, return_ty);
builtin_return_ty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But returning builtin_return_ty here means that when we equate _#0i and _#1i, the type we return will be _#0i instead of <#_0i as Add<_#i1>>::Output, which helps guide inference in the solver.

CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Float) },
t,
),
ty::Infer(ty::IntVar(vid)) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also needed to fix the canonicalizer bug for int and float vars as well...

@@ -15,41 +15,65 @@ LL | second == 1
= note: expected fn item `fn() {second}`
found type `{integer}`

error[E0308]: mismatched types
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the changes to typeck, we end up emitting this additional error. I can work around it pretty easily by checking if the output type of the binop references errors before returning builtin_return_ty a few files up, but I also think that it's fine? Like, this is a meaningful error 😅

@lcnr
Copy link
Contributor

lcnr commented Mar 10, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Mar 10, 2023

📌 Commit d4b59a0 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#106921 (Add documentation about the memory layout of `Cell`)
 - rust-lang#108828 (Emit alias-eq when equating numeric var and projection)
 - rust-lang#108834 (Do not ICE when we have fn pointer `Fn` obligations with bound vars in the self type)
 - rust-lang#108900 (fix(lexer): print whitespace warning for \x0c)
 - rust-lang#108930 (feat: implement better error for manual impl of `Fn*` traits)
 - rust-lang#108937 (improve readability of winnowing)
 - rust-lang#108947 (Don't even try to combine consts with incompatible types)
 - rust-lang#108976 (Update triagebot rust-analyzer team mention)
 - rust-lang#108983 (Forbid `#[target_feature]` on safe default implementations)

Failed merges:

 - rust-lang#108950 (Directly construct Inherited in typeck.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 233ed35 into rust-lang:master Mar 11, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 11, 2023
@compiler-errors compiler-errors deleted the new-solver-alias-eq-on-num-var branch August 11, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants