about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_ty_utils/src/ty.rs9
-rw-r--r--tests/ui/unsafe-binders/binder-sized-crit.rs18
-rw-r--r--tests/ui/unsafe-binders/binder-sized-crit.stderr11
3 files changed, 35 insertions, 3 deletions
diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs
index 8ed45b4e541..8610c30ab70 100644
--- a/compiler/rustc_ty_utils/src/ty.rs
+++ b/compiler/rustc_ty_utils/src/ty.rs
@@ -37,8 +37,6 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
         | Never
         | Dynamic(_, _, ty::DynStar) => None,
 
-        UnsafeBinder(_) => todo!(),
-
         // these are never sized
         Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty),
 
@@ -52,9 +50,14 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
             sized_constraint_for_ty(tcx, ty)
         }),
 
-        // these can be sized or unsized
+        // these can be sized or unsized.
         Param(..) | Alias(..) | Error(_) => Some(ty),
 
+        // We cannot instantiate the binder, so just return the *original* type back,
+        // but only if the inner type has a sized constraint. Thus we skip the binder,
+        // but don't actually use the result from `sized_constraint_for_ty`.
+        UnsafeBinder(inner_ty) => sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty),
+
         Placeholder(..) | Bound(..) | Infer(..) => {
             bug!("unexpected type `{ty:?}` in sized_constraint_for_ty")
         }
diff --git a/tests/ui/unsafe-binders/binder-sized-crit.rs b/tests/ui/unsafe-binders/binder-sized-crit.rs
new file mode 100644
index 00000000000..37677c0ef69
--- /dev/null
+++ b/tests/ui/unsafe-binders/binder-sized-crit.rs
@@ -0,0 +1,18 @@
+//@ check-pass
+
+#![feature(unsafe_binders)]
+//~^ WARN the feature `unsafe_binders` is incomplete
+
+use std::unsafe_binder::wrap_binder;
+
+struct A {
+    b: unsafe<> (),
+}
+
+fn main() {
+    unsafe {
+        let _ = A {
+            b: wrap_binder!(()),
+        };
+    }
+}
diff --git a/tests/ui/unsafe-binders/binder-sized-crit.stderr b/tests/ui/unsafe-binders/binder-sized-crit.stderr
new file mode 100644
index 00000000000..3ba6cf2ef8c
--- /dev/null
+++ b/tests/ui/unsafe-binders/binder-sized-crit.stderr
@@ -0,0 +1,11 @@
+warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/binder-sized-crit.rs:3:12
+   |
+LL | #![feature(unsafe_binders)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
+   = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+