diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 34a3f155baf43..f7faefa240abe 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -153,6 +153,8 @@ fn visit_implementation_of_unpin(checker: &Checker<'_>) -> Result<(), ErrorGuara })); } ty::Adt(_, _) => {} + // `extern type`s have no fields, so they can't be structurally pinned. + ty::Foreign(_) => {} _ => { return Err(tcx.dcx().span_delayed_bug(span, "impl of `Unpin` for a non-adt type")); } diff --git a/tests/crashes/155053.rs b/tests/crashes/155053.rs deleted file mode 100644 index 31b9ccaf20540..0000000000000 --- a/tests/crashes/155053.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ known-bug: #155053 -#![feature(pin_ergonomics)] -#![feature(extern_types)] - -unsafe extern "C" { - type ExternType; -} - -impl Unpin for ExternType {} - -fn main() {} diff --git a/tests/ui/pin-ergonomics/impl-unpin-extern-type.rs b/tests/ui/pin-ergonomics/impl-unpin-extern-type.rs new file mode 100644 index 0000000000000..953c71ea84311 --- /dev/null +++ b/tests/ui/pin-ergonomics/impl-unpin-extern-type.rs @@ -0,0 +1,18 @@ +//! Verify that a local `extern type` can manually implement `Unpin` with `pin_ergonomics` enabled. +//! Unlike a `#[pin_v2]` ADT, an extern type has no fields that could be structually pinned. +//! +//! Regression test for . + +//@ check-pass + +#![feature(pin_ergonomics)] +#![feature(extern_types)] +#![allow(incomplete_features)] + +unsafe extern "C" { + type ExternType; +} + +impl Unpin for ExternType {} + +fn main() {}