-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
In working on an example for the Reference related to least upper bound coercions (https://doc.rust-lang.org/1.90.0/reference/type-coercions.html#least-upper-bound-coercions), I notice that the following triggers an internal compiler error.
use core::ops::Deref;
struct A; struct B; struct C;
impl Deref for C {
type Target = B;
fn deref(&self) -> &Self::Target {
&B
}
}
impl Deref for B {
type Target = A;
fn deref(&self) -> &Self::Target {
&A
}
}
fn f(v: u8) {
let _ = match v {
0 => &C,
1 => &B,
_ => &A,
};
}
fn main() {}note: no errors encountered even though delayed bugs were created
note: those delayed bugs will now be shown as internal compiler errors
error: internal compiler error: while adjusting Expr { hir_id: HirId(DefId(0:16 ~ playground_main[5299]::f).11), kind: AddrOf(Ref, Not, Expr { hir_id: HirId(DefId(0:16 ~ playground_main[5299]::f).12), kind: Path(Resolved(None, Path { span: src/main.rs:21:15: 21:16 (#0), res: Def(Ctor(Struct, Const), DefId(0:9 ~ playground_main[5299]::C::{constructor#0})), segments: [PathSegment { ident: C#0, hir_id: HirId(DefId(0:16 ~ playground_main[5299]::f).13), res: Def(Ctor(Struct, Const), DefId(0:9 ~ playground_main[5299]::C::{constructor#0})), args: None, infer_args: true }] })), span: src/main.rs:21:15: 21:16 (#0) }), span: src/main.rs:21:14: 21:16 (#0) }, can't compose [Deref(None) -> C, Deref(Some(OverloadedDeref { mutbl: Not, span: src/main.rs:22:14: 22:16 (#0) })) -> B, Borrow(Ref(Not)) -> &B] and [Deref(None) -> B, Deref(Some(OverloadedDeref { mutbl: Not, span: src/main.rs:23:14: 23:16 (#0) })) -> A, Borrow(Ref(Not)) -> &A]
--> src/main.rs:21:14
|
21 | 0 => &C,
| ^^
|
note: delayed at compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs:343:36 - disabled backtrace
--> src/main.rs:21:14
|
21 | 0 => &C,
| ^^
error: internal compiler error: broken MIR in DefId(0:16 ~ playground_main[5299]::f) (_4 = &(*_5)): bad assignment (&'?20 B = &'?15 C): NoSolution
--> src/main.rs:21:14
|
21 | 0 => &C,
| ^^
|
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:676:21 - disabled backtrace
--> src/main.rs:21:14
|
21 | 0 => &C,
| ^^
This is on latest nightly. I tested back to Rust 1.85 and observed the same behavior.
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.