Skip to content
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

Overloaded deref on type Foo is not a projection #19021

Closed
darichey opened this issue Jan 24, 2025 · 2 comments · Fixed by #19111
Closed

Overloaded deref on type Foo is not a projection #19021

darichey opened this issue Jan 24, 2025 · 2 comments · Fixed by #19111
Labels
A-mir C-bug Category: bug

Comments

@darichey
Copy link
Contributor

This can probably be minimized further, but I don't understand the code well enough...

struct Foo {}

fn foo() {
    let x: Box<Foo> = todo!();
    let y: &Foo = todo!();

    || match x {
        ref x => x,
        _ => y,
    }
}
internal error: entered unreachable code: Overloaded deref on type Foo is not a projection
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: hir_ty::mir::ProjectionElem<V,T>::projected_ty
             at /Users/davidrichey/Desktop/test/rust-analyzer/crates/hir-ty/src/mir.rs:162:21
   3: hir_ty::infer::closure::<impl hir_ty::infer::InferenceContext>::restrict_precision_for_unsafe
             at /Users/davidrichey/Desktop/test/rust-analyzer/crates/hir-ty/src/infer/closure.rs:1050:22
   4: hir_ty::infer::closure::<impl hir_ty::infer::InferenceContext>::analyze_closure
             at /Users/davidrichey/Desktop/test/rust-analyzer/crates/hir-ty/src/infer/closure.rs:1299:9
   5: hir_ty::infer::closure::<impl hir_ty::infer::InferenceContext>::infer_closures
             at /Users/davidrichey/Desktop/test/rust-analyzer/crates/hir-ty/src/infer/closure.rs:1339:24
   6: hir_ty::infer::infer_query
             at /Users/davidrichey/Desktop/test/rust-analyzer/crates/hir-ty/src/infer.rs:143:5

ProjectionElem::Deref => match &base.kind(Interner) {
TyKind::Raw(_, inner) | TyKind::Ref(_, _, inner) => inner.clone(),
TyKind::Adt(adt, subst) if is_box(db, adt.0) => {
subst.at(Interner, 0).assert_ty_ref(Interner).clone()
}
_ => {
never!(
"Overloaded deref on type {} is not a projection",
base.display(db, db.crate_graph()[krate].edition)
);
TyKind::Error.intern(Interner)
}
},

@darichey darichey added the C-bug Category: bug label Jan 24, 2025
@ShoyuVanilla
Copy link
Member

Image
Oh, this is strange 🤔

@Veykril Veykril removed the I-panic label Jan 25, 2025
@Veykril
Copy link
Member

Veykril commented Jan 25, 2025

That's a never! check that fails, so not really a panic. It only panics in builds where instructed to do so (usually a manual build, not a github release)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-mir C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants