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

Don't call query_normalize when reporting similar impls #113005

Merged
merged 2 commits into from
Jul 8, 2023

Conversation

compiler-errors
Copy link
Member

Firstly, It's sketchy to be using query_normalize at all during HIR typeck -- it's asking for an ICE 😅. Secondly, we're normalizing an impl trait ref that potentially has parameter types in ty::ParamEnv::empty(), which is kinda sketchy as well.

The only UI test change from removing this normalization is that we don't evaluate anonymous constants in impls, which end up giving us really ugly suggestions:

error[E0277]: the trait bound `[X; 35]: Default` is not satisfied
 --> /home/gh-compiler-errors/test.rs:4:5
  |
4 |     <[X; 35] as Default>::default();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
  |
  = help: the following other types implement trait `Default`:
            &[T]
            &mut [T]
            [T; 32]
            [T; core::::array::{impl#30}::{constant#0}]
            [T; core::::array::{impl#31}::{constant#0}]
            [T; core::::array::{impl#32}::{constant#0}]
            [T; core::::array::{impl#33}::{constant#0}]
            [T; core::::array::{impl#34}::{constant#0}]
          and 27 others

So just fold the impls with a BottomUpFolder that calls ty::Const::eval. This doesn't work totally correctly with generic-const-exprs, but it's fine for stable code, and this is error reporting after all.

@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2023

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@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 Jun 24, 2023
normalized_impl_candidates_and_similarities.sort();
normalized_impl_candidates_and_similarities.dedup();
let mut impl_candidates = impl_candidates.to_vec();
impl_candidates.sort_by_key(|cand| (cand.similarity, cand.trait_ref));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this useful? report sorts everything again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the sort in report -- that should fix the weird rendering and also actually make this sort meaningful. It does have a lot of fallout, but the changes are either neutral or slightly better suggestions.

@cjgillot
Copy link
Contributor

cjgillot commented Jul 8, 2023

Great!
@bors r+

@bors
Copy link
Contributor

bors commented Jul 8, 2023

📌 Commit 2c33dfe has been approved by cjgillot

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 Jul 8, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 8, 2023
…ze, r=cjgillot

Don't call `query_normalize` when reporting similar impls

Firstly, It's sketchy to be using `query_normalize` at all during HIR typeck -- it's asking for an ICE 😅. Secondly, we're normalizing an impl trait ref that potentially has parameter types in `ty::ParamEnv::empty()`, which is kinda sketchy as well.

The only UI test change from removing this normalization is that we don't evaluate anonymous constants in impls, which end up giving us really ugly suggestions:

```
error[E0277]: the trait bound `[X; 35]: Default` is not satisfied
 --> /home/gh-compiler-errors/test.rs:4:5
  |
4 |     <[X; 35] as Default>::default();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
  |
  = help: the following other types implement trait `Default`:
            &[T]
            &mut [T]
            [T; 32]
            [T; core::::array::{impl#30}::{constant#0}]
            [T; core::::array::{impl#31}::{constant#0}]
            [T; core::::array::{impl#32}::{constant#0}]
            [T; core::::array::{impl#33}::{constant#0}]
            [T; core::::array::{impl#34}::{constant#0}]
          and 27 others
```

So just fold the impls with a `BottomUpFolder` that calls `ty::Const::eval`. This doesn't work totally correctly with generic-const-exprs, but it's fine for stable code, and this is error reporting after all.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 8, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#113005 (Don't call `query_normalize` when reporting similar impls)
 - rust-lang#113064 (std: edit [T]::swap docs)
 - rust-lang#113138 (Add release notes for 1.71.0)
 - rust-lang#113217 (resolve typerelative ctors to adt)
 - rust-lang#113254 (Use consistent formatting in Readme)
 - rust-lang#113482 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 48a0d03 into rust-lang:master Jul 8, 2023
11 checks passed
@rustbot rustbot added this to the 1.72.0 milestone Jul 8, 2023
@compiler-errors compiler-errors deleted the dont-query-normalize branch August 11, 2023 19:59
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants