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

ICE when pattern matching on &dyn PartialEq. #72565

Closed
lcnr opened this issue May 25, 2020 · 1 comment · Fixed by #77388
Closed

ICE when pattern matching on &dyn PartialEq. #72565

lcnr opened this issue May 25, 2020 · 1 comment · Fixed by #77388
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented May 25, 2020

const F: &'static dyn PartialEq<u32> = &7u32;

fn main() {
    let a: &dyn PartialEq<u32> = &7u32;
    match a {
        F => panic!(),
        _ => {}
    }
}

causes an ICE on the current nightly

error: internal compiler error: src/librustc_mir_build/hair/pattern/_match.rs:363: cannot deref ByRef {
    alloc: Allocation {
        bytes: [
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
        ],
        relocations: Relocations(
            SortedMap {
                data: [
                    (
                        Size {
                            raw: 0,
                        },
                        (
                            (),
                            a2,
                        ),
                    ),
                    (
                        Size {
                            raw: 8,
                        },
                        (
                            (),
                            a4,
                        ),
                    ),
                ],
            },
        ),
        init_mask: InitMask {
            blocks: [
                65535,
            ],
            len: Size {
                raw: 16,
            },
        },
        size: Size {
            raw: 16,
        },
        align: Align {
            pow2: 3,
        },
        mutability: Not,
        extra: (),
    },
    offset: Size {
        raw: 0,
    },
}, dyn std::cmp::PartialEq<u32> -> dyn std::cmp::PartialEq<u32>

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Afaik this is caused by ty_is_partial_eq being slightly too permissive

let ty_is_partial_eq: bool = {
let partial_eq_trait_id =
self.tcx().require_lang_item(EqTraitLangItem, Some(self.span));
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
self.tcx(),
self.param_env,
ObligationCause::misc(self.span, self.id),
partial_eq_trait_id,
0,
cv.ty,
&[],
);
// FIXME: should this call a `predicate_must_hold` variant instead?
self.infcx.predicate_may_hold(&obligation)
};

See #71038 (comment) for more details.

@lcnr lcnr added C-bug Category: This is a bug. A-patterns Relating to patterns and pattern matching I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 29, 2020
@Alexendoo
Copy link
Member

No longer ICEs after #70743, needs a test

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 27, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 3, 2020
Add some regression tests

Closes rust-lang#66501
Closes rust-lang#68951
Closes rust-lang#72565
Closes rust-lang#74244
Closes rust-lang#75299

The first issue is fixed in 1.43.0, other issues are fixed in the recent nightly.
@bors bors closed this as completed in f09c962 Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants