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 ICE if method receiver fails to unify with arbitrary_self_types #111860

Merged
merged 1 commit into from
May 23, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented May 23, 2023

Consider:

struct Foo(u32);
impl Foo {
    fn get<R: Deref<Target=Self>>(self: R) -> u32 {
        self.0
    }
}

fn main() {
    let mut foo = Foo(1);
    foo.get::<&Foo>();
}

The problem here is that with arbitrary_self_types, we're allowed to have a method receiver that mentions generics from the method itself (fn get<R: Deref<Target=Self>>(self: R)). Since we don't actually take into account the user-written turbofish generics when doing method lookup (nor do we check that method predicates hold), method probing will happily infer R = Foo during the probe. When we later confirm the method, we do use the turbofish'd subst and instead now have that R = &Foo. This doesn't unify with the self type we chose during the probe, causing an ICE.

Getting this to work correctly will be difficult. Specifically, we'll need to actually pass in the turbofish generics for the method being probed for and check that the self type unifies considering those generics. This seems like a lot of work, and I'm not actually familiar with the restrictions originally called out for #![feature(arbitrary_self_types)], but I think we should probably instead just deny having receivers that mention (type/const) generics that come from the method itself.

But I mostly just want to turn this ICE into an error, so I'll leave that up for later PRs.

Fixes #111838

@rustbot
Copy link
Collaborator

rustbot commented May 23, 2023

r? @WaffleLapkin

(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 May 23, 2023
Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

as an ICE fix this looks fine

@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 23, 2023

📌 Commit 05c5caa has been approved by WaffleLapkin

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 May 23, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 23, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#111461 (Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic)
 - rust-lang#111579 (Also assume wrap-around discriminants in `as` MIR building)
 - rust-lang#111704 (Remove return type sized check hack from hir typeck)
 - rust-lang#111853 (Check opaques for mismatch during writeback)
 - rust-lang#111854 (rustdoc: clean up `settings.css`)
 - rust-lang#111860 (Don't ICE if method receiver fails to unify with `arbitrary_self_types`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c4f2a62 into rust-lang:master May 23, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 23, 2023
@compiler-errors compiler-errors deleted the issue-111838 branch August 11, 2023 20:05
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.

ICE calling generic method with explicitly provided self parameter
4 participants