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

fix: skip cast if Ctor has an invalid type #113446

Closed
wants to merge 1 commit into from

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Jul 7, 2023

Fixes #112630

#112630 encounters an ice because it does not report the fn({type error}) -> xxx earlier and eventually causes a panic in mir_cast_kind.

In this PR, I made that type_of returns TyKind::Error to ensure it enters the if let Err(guar) = (t_expr, t_cast).error_reported() { xxxx } branch in check_expr_cast in order to bypass the cast for invalid type.

@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2023

r? @eholk

(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 Jul 7, 2023
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.

I don't think this is the right fix. Similar code (which doesn't use a tuple constructor but just uses a regular function pointer) also ICEs in the exact same way, but I don't think it's fixed by your PR:

fn f(_: B) {}

fn main() {
    let _ = [0; f as usize];
}

I feel like we shouldn't be fixing the issue by modifying the type_of query, feels like the wrong place to put a fix...


This reminds me a lot of the "not correctly tainting bodies with errors during astconv" issue that @davidtwco had been investigating solutions for recently. We ideally wouldn't even be doing const eval here if things are tainted properly.

@compiler-errors compiler-errors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 7, 2023
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jul 7, 2023

Similar code (which doesn't use a tuple constructor but just uses a regular function pointer) also ICEs in the exact same way

Nice catch, I will investigate this.

@davidtwco
Copy link
Member

After changing the approach I'm taking in #113125, it fixes this issue too - apologies for stepping on your toes here.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jul 12, 2023

No problem, and thank you for the message. I have learned a lot from your PR as well.

@bvanjoi bvanjoi closed this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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: Attempting to cast non-castable types fn({type error}) -> Foo {Foo::Bar} and usize
5 participants