Skip to content

Don't fix builtin index when Where clause is found #100598

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 19, 2022
Merged

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Aug 15, 2022

Where clause shadows blanket impl for Index which causes normalization to not occur, which causes ICE to happen when we typeck.

r? @compiler-errors

Fixes #91633

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 15, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 15, 2022
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Left a few style nits

Comment on lines 2 to 30
fn hey<T> (it: &[T])
where
[T] : std::ops::Index<usize>,
{
let _ = &it[0];
}

// EMIT_MIR issue_91633.bar.mir_map.0.mir
fn bar<T> (it: Box<[T]>)
where
[T] : std::ops::Index<usize>,
{
let _ = it[0];
}

// EMIT_MIR issue_91633.fun.mir_map.0.mir
fn fun<T> (it: &[T])
{
let _ = &it[0];
}

// EMIT_MIR issue_91633.foo.mir_map.0.mir
fn foo<T> (it: Box<[T]>)
{
let _ = it[0];
}
Copy link
Member

@compiler-errors compiler-errors Aug 15, 2022

Choose a reason for hiding this comment

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

nit: the index operation is getting compiled out of some of these, try making these return -> &T or T instead?

Comment on lines 206 to 213
if let Some(elem_ty) = base_ty.builtin_index() {
let exp_ty = typeck_results.expr_ty_adjusted(e);
let resolved_exp_ty = self.resolve(exp_ty, &e.span);

elem_ty == resolved_exp_ty && index_ty == self.fcx.tcx.types.usize
} else {
false
}
Copy link
Member

@compiler-errors compiler-errors Aug 15, 2022

Choose a reason for hiding this comment

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

Actually... it might be wrong to use expr_ty_adjusted here. The un-adjusted expr should be &T, so maybe try:

Suggested change
if let Some(elem_ty) = base_ty.builtin_index() {
let exp_ty = typeck_results.expr_ty_adjusted(e);
let resolved_exp_ty = self.resolve(exp_ty, &e.span);
elem_ty == resolved_exp_ty && index_ty == self.fcx.tcx.types.usize
} else {
false
}
let Some(expected_elem_ty) = base_ty.builtin_index() else { return false; };
let Some(exp_ty) = typeck_results.expr_ty_opt(e) else { return false; };
let ty::Ref(_, found_elem_ty, _) = self.resolve(exp_ty, &e.span).kind() else { return false; };
expected_elem_ty == found_elem_ty && index_ty == self.fcx.tcx.types.usize

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

Thanks so much for this fix! Can you squash this into one or two commits? Then r=me.

@bors delegate+

@bors
Copy link
Collaborator

bors commented Aug 16, 2022

✌️ @ouz-a can now approve this pull request

@ouz-a
Copy link
Contributor Author

ouz-a commented Aug 17, 2022

r? @compiler-errors

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 17, 2022

📌 Commit 7b45718 has been approved by compiler-errors

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 Aug 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2022
Rollup of 9 pull requests

Successful merges:

 - rust-lang#99576 (Do not allow `Drop` impl on foreign fundamental types)
 - rust-lang#100081 (never consider unsafe blocks unused if they would be required with deny(unsafe_op_in_unsafe_fn))
 - rust-lang#100208 (make NOP dyn casts not require anything about the vtable)
 - rust-lang#100494 (Cleanup rustdoc themes)
 - rust-lang#100522 (Only check the `DefId` for the recursion check in MIR inliner.)
 - rust-lang#100592 (Manually implement Debug for ImportKind.)
 - rust-lang#100598 (Don't fix builtin index when Where clause is found)
 - rust-lang#100721 (Add diagnostics lints to `rustc_type_ir` module)
 - rust-lang#100731 (rustdoc: count deref and non-deref as same set of used methods)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 490d04b into rust-lang:master Aug 19, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 19, 2022
@ouz-a ouz-a deleted the 91633 branch November 13, 2022 09:56
# for free to join this conversation on GitHub. Already have an account? # 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.

ICE for broken MIR in 1.57.0, beta and nightly
6 participants